GNU Radio's RTP Package
source_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2026 Franco Venturi.
4 *
5 * based on:
6 * - pcmcat in ka9q-radio
7 * - wavfile_source block in GNU Radio
8 *
9 * SPDX-License-Identifier: GPL-3.0-or-later
10 */
11
12#ifndef INCLUDED_RTP_SOURCE_IMPL_H
13#define INCLUDED_RTP_SOURCE_IMPL_H
14
15#include <gnuradio/rtp/source.h>
16
17extern "C" {
18#include "multicast.h"
19#include "rtp.h"
20}
21
22#define FULL_SAMPRATE (48000)
23
24namespace gr {
25namespace rtp {
26
27struct pcmstream {
28 uint32_t ssrc; // RTP Sending Source ID
29 int type; // RTP type (10,11,20)
30
31 struct sockaddr sender;
32 char const *source;
33 int framesize; // Bytes per timestamp increment
34
35 long long bytes_received;
38};
39
40template <class T>
41class source_impl : public source<T>
42{
43private:
44 int mcast_fd;
45 struct pcmstream pcmstream;
46 unsigned int ssrc; // Requested SSRC
47 int channels;
48 bool quiet;
49
50public:
51 source_impl(const std::string& mcast_address,
52 unsigned int ssrc,
53 int in_channels=1,
54 int out_channels=1,
55 bool quiet=false);
57
58 int get_bits_per_sample() const override {
59 return sizeof(std::int16_t) * 8;
60 }
61
62 int get_channels() const override { return channels; };
63
64 void set_ssrc(unsigned int ssrc) override {
65 this->ssrc = ssrc;
66 pcmstream.ssrc = 0;
67 };
68
69 unsigned int get_ssrc() const override { return ssrc; };
70
71 int work(int noutput_items,
72 gr_vector_const_void_star& input_items,
73 gr_vector_void_star& output_items);
74
75private:
76 void check_out_channels(int channels) const { return; }
77 int get_output_items(int sampcount, int channels, int noutput_channels, int time_step) const {
78 return time_step + sampcount / channels; // == sampcount for mono, sampcount/2 for stereo
79 }
80 int output_zeroes(int nzeroes, int channels, T** outs,
81 int noutput_items, int noutput_channels,
82 int offset = 0) const;
83 int output_samples(const void *dp, int size, int channels, T** outs,
84 int noutput_items, int noutput_channels,
85 int offset = 0) const;
86
87};
88
89} // namespace rtp
90} // namespace gr
91
92#endif /* INCLUDED_RTP_SOURCE_IMPL_H */
int get_bits_per_sample() const override
Return the number of bits per sample. the RTP stream.
Definition source_impl.h:58
unsigned int get_ssrc() const override
Definition source_impl.h:69
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
int get_channels() const override
Return the number of input channels.
Definition source_impl.h:62
void set_ssrc(unsigned int ssrc) override
Definition source_impl.h:64
source_impl(const std::string &mcast_address, unsigned int ssrc, int in_channels=1, int out_channels=1, bool quiet=false)
Read stream from an RTP PCM stream, output gr_complex or interleaved shorts.
Definition source.h:31
Definition source.h:18
Definition source_impl.h:27
long long bytes_received
Definition source_impl.h:35
char const * source
Definition source_impl.h:32
int type
Definition source_impl.h:29
uint32_t ssrc
Definition source_impl.h:28
int last_size
Definition source_impl.h:37
struct rtp_header last_header
Definition source_impl.h:36
int framesize
Definition source_impl.h:33
struct sockaddr sender
Definition source_impl.h:31
Definition rtp.h:49