UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
rtp_callback.c File Reference
#include "config.h"
#include "config_unix.h"
#include "config_win32.h"
#include <inttypes.h>
#include <stdint.h>
#include "debug.h"
#include "host.h"
#include "pdb.h"
#include "video_display.h"
#include "video_codec.h"
#include "ntp.h"
#include "tv.h"
#include "rtp/rtp.h"
#include "rtp/pbuf.h"
#include "rtp/rtp_callback.h"
#include "tfrc.h"
Include dependency graph for rtp_callback.c:

Go to the source code of this file.

Functions

static void process_rr (struct rtp *session, rtp_event *e)
 
static void process_sdes (struct pdb *participants, uint32_t ssrc, rtcp_sdes_item *d)
 
void rtp_recv_callback (struct rtp *session, rtp_event *e)
 

Variables

char * frame
 
char hdr_buf [100]
 
struct iovec iov [10]
 
struct msghdr msg
 
uint32_t RTT
 

Function Documentation

◆ process_rr()

static void process_rr ( struct rtp * session,
rtp_event * e )
static

Definition at line 85 of file rtp_callback.c.

86{
87 float fract_lost, tmp;
88 uint32_t ntp_sec, ntp_frac, now;
89 rtcp_rr *r = (rtcp_rr *) e->data;
90
91 if (e->ssrc == rtp_my_ssrc(session)) {
92 /* Filter out loopback reports */
93 return;
94 }
95
96 if (r->ssrc == rtp_my_ssrc(session)) {
97 /* Received a reception quality report for data we are sending. */
98 /* */
99 /* Check for excessive congestion: exit if it occurs, to protect */
100 /* other users of the network. */
101 fract_lost = (r->fract_lost * 100.0) / 256.0; /* percentage lost packets */
102 if (fract_lost > 20) {
103 printf("Receiver 0x%08x reports excessive congestion\n",
104 e->ssrc);
105 }
106
107 /* Compute network round-trip time: */
108 if (r->lsr != 0) {
109 ntp64_time(&ntp_sec, &ntp_frac);
110 now = ntp64_to_ntp32(ntp_sec, ntp_frac);
111
112 if ((now < r->lsr) || (now - r->lsr < r->dlsr)) {
113 /* Packet arrived before it was sent, ignore. This represents */
114 /* a bug in the remote: either our timestamp was incorrectly */
115 /* echoed back to us, or the remote miscalculated in time for */
116 /* which it held the packet. */
117 debug_msg("Bogus RTT from 0x%08x ignored\n",
118 e->ssrc);
119 } else {
120 tmp = ((float)(now - r->lsr - r->dlsr)) / 65536.0; /* RTT in seconds */
121 RTT = tmp * 1000000; /* RTT in usec */
122 }
123 //debug_msg(" RTT=%d usec\n", RTT);
124 }
125
126 int packet_count = 1;
127 const rtcp_rr *last_rr = rtp_get_rr(session, e->ssrc, r->ssrc);
128 if(last_rr){
129 packet_count = (r->last_seq - last_rr->last_seq);
130 }
131 if(packet_count < 1) packet_count = 1;
132
134 "RR of 0x%08x: RTT=%d usec, loss %.2f%% (of %d pkts)\n",
135 r->ssrc, RTT, fract_lost, packet_count);
136 }
137}
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_INFO
normal reporting
Definition debug.h:62
#define debug_msg(...)
#define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, "[pid/%d +%d %s] ", getpid(), LINE,...
Definition debug.h:92
void ntp64_time(uint32_t *ntp_sec, uint32_t *ntp_frac)
Definition ntp.c:26
#define ntp64_to_ntp32(ntp_sec, ntp_frac)
Definition ntp.h:23
const rtcp_rr * rtp_get_rr(struct rtp *session, uint32_t reporter, uint32_t reportee)
Definition rtp.c:2707
uint32_t rtp_my_ssrc(struct rtp *session)
Definition rtp.c:1401
uint32_t RTT
Definition host.cpp:171
Definition rtp.h:139
uint32_t last_seq
Definition rtp.h:148
uint32_t ssrc
Definition rtp.h:198
void * data
Definition rtp.h:200

References rtp_event::data, debug_msg, rtcp_rr::dlsr, rtcp_rr::fract_lost, rtcp_rr::last_seq, LOG_LEVEL_INFO, log_msg(), rtcp_rr::lsr, ntp64_time(), ntp64_to_ntp32, rtp_get_rr(), rtp_my_ssrc(), RTT, rtcp_rr::ssrc, and rtp_event::ssrc.

Referenced by rtp_recv_callback().

Here is the call graph for this function:

◆ process_sdes()

static void process_sdes ( struct pdb * participants,
uint32_t ssrc,
rtcp_sdes_item * d )
static

Definition at line 140 of file rtp_callback.c.

141{
142 struct pdb_e *e;
143 char *sdes_item;
144
145 e = pdb_get(participants, ssrc);
146 if (e == NULL) {
147 /* We got an SDES packet for a participant we haven't previously seen. */
148 /* This can happen, for example, in a partitioned multicast group. Log */
149 /* the event, and add the new participant to the database. */
151 ("Added previously unseen participant 0x%08" PRIx32 " due to receipt of SDES\n",
152 ssrc);
153 pdb_add(participants, ssrc);
154 e = pdb_get(participants, ssrc);
155 }
156
157 sdes_item = calloc(d->length + 1, 1);
158 strncpy(sdes_item, d->data, d->length);
159
160 switch (d->type) {
161 case RTCP_SDES_END:
162 free(sdes_item);
163 /* This is the end of the SDES list of a packet. */
164 /* Nothing for us to deal with. */
165 break;
166 case RTCP_SDES_CNAME:
167 if (e->sdes_cname != NULL)
168 free(e->sdes_cname);
169 e->sdes_cname = sdes_item;
170 break;
171 case RTCP_SDES_NAME:
172 if (e->sdes_name != NULL)
173 free(e->sdes_name);
174 e->sdes_name = sdes_item;
175 break;
176 case RTCP_SDES_EMAIL:
177 if (e->sdes_email != NULL)
178 free(e->sdes_email);
179 e->sdes_email = sdes_item;
180 break;
181 case RTCP_SDES_PHONE:
182 if (e->sdes_phone != NULL)
183 free(e->sdes_phone);
184 e->sdes_phone = sdes_item;
185 break;
186 case RTCP_SDES_LOC:
187 if (e->sdes_loc != NULL)
188 free(e->sdes_loc);
189 e->sdes_loc = sdes_item;
190 break;
191 case RTCP_SDES_TOOL:
192 if (e->sdes_tool != NULL)
193 free(e->sdes_tool);
194 e->sdes_tool = sdes_item;
195 break;
196 case RTCP_SDES_NOTE:
197 if (e->sdes_note != NULL)
198 free(e->sdes_note);
199 e->sdes_note = sdes_item;
200 break;
201 case RTCP_SDES_PRIV:
202 free(sdes_item);
203 break; /* Ignore private extensions */
204 default:
205 free(sdes_item);
207 ("Ignored unknown SDES item (type=0x%02" PRIx32 ") from 0x%08" PRIx32"\n",
208 d->type, ssrc);
209 }
210}
int pdb_add(struct pdb *db, uint32_t ssrc)
Definition pdb.c:299
struct pdb_e * pdb_get(struct pdb *db, uint32_t ssrc)
Definition pdb.c:332
@ RTCP_SDES_NOTE
Definition rtp.h:216
@ RTCP_SDES_CNAME
Definition rtp.h:210
@ RTCP_SDES_PHONE
Definition rtp.h:213
@ RTCP_SDES_TOOL
Definition rtp.h:215
@ RTCP_SDES_LOC
Definition rtp.h:214
@ RTCP_SDES_EMAIL
Definition rtp.h:212
@ RTCP_SDES_END
Definition rtp.h:209
@ RTCP_SDES_NAME
Definition rtp.h:211
@ RTCP_SDES_PRIV
Definition rtp.h:217
Definition pdb.h:72
char * sdes_name
Definition pdb.h:75
char * sdes_loc
Definition pdb.h:78
char * sdes_note
Definition pdb.h:80
char * sdes_tool
Definition pdb.h:79
char * sdes_email
Definition pdb.h:76
uint32_t ssrc
Definition pdb.h:73
char * sdes_phone
Definition pdb.h:77
char * sdes_cname
Definition pdb.h:74
uint8_t type
Definition rtp.h:221
uint8_t length
Definition rtp.h:222
char data[1]
Definition rtp.h:223

References rtcp_sdes_item::data, debug_msg, rtcp_sdes_item::length, pdb_add(), pdb_get(), RTCP_SDES_CNAME, RTCP_SDES_EMAIL, RTCP_SDES_END, RTCP_SDES_LOC, RTCP_SDES_NAME, RTCP_SDES_NOTE, RTCP_SDES_PHONE, RTCP_SDES_PRIV, RTCP_SDES_TOOL, pdb_e::sdes_cname, pdb_e::sdes_email, pdb_e::sdes_loc, pdb_e::sdes_name, pdb_e::sdes_note, pdb_e::sdes_phone, pdb_e::sdes_tool, pdb_e::ssrc, and rtcp_sdes_item::type.

Referenced by rtp_recv_callback().

Here is the call graph for this function:

◆ rtp_recv_callback()

void rtp_recv_callback ( struct rtp * session,
rtp_event * e )

Definition at line 212 of file rtp_callback.c.

213{
214 rtcp_app *pckt_app = (rtcp_app *) e->data;
215 rtp_packet *pckt_rtp = (rtp_packet *) e->data;
216 struct pdb *participants = (struct pdb *)rtp_get_userdata(session);
217 struct pdb_e *state = pdb_get(participants, e->ssrc);
218
219 switch (e->type) {
220 case RX_RTP:
221 tfrc_recv_data(state->tfrc_state, get_time_in_ns(), pckt_rtp->seq,
222 pckt_rtp->data_len + 40);
223 if (pckt_rtp->data_len > 0) { /* Only process packets that contain data... */
224 pbuf_insert(state->playout_buffer, pckt_rtp);
225 }
226 break;
227 case RX_TFRC_RX:
228 /* compute TCP friendly data rate */
229 break;
230 case RX_RTCP_START:
231 break;
232 case RX_RTCP_FINISH:
233 break;
234 case RX_SR:
235 break;
236 case RX_RR:
237 process_rr(session, e);
238 break;
239 case RX_RR_EMPTY:
240 break;
241 case RX_SDES:
242 process_sdes(participants, e->ssrc, (rtcp_sdes_item *) e->data);
243 break;
244 case RX_APP:
245 if (strncmp(pckt_app->name, "RTT_", 4) == 0) {
246 assert(pckt_app->length == 3);
247 assert(pckt_app->subtype == 0);
248// tfrc_recv_rtt(state->tfrc_state, get_time_in_ns(), ntohl(*((int *) pckt_app->data)));
249 }
250 break;
251 case RX_BYE:
252 break;
253 case SOURCE_DELETED:
254 {
255 struct pdb_e *pdb_item = NULL;
256 if(pdb_remove(participants, e->ssrc, &pdb_item) == 0) {
257 pdb_destroy_item(pdb_item);
258 }
259 }
260 break;
261 case SOURCE_CREATED:
262 pdb_add(participants, e->ssrc);
263 break;
264 case RR_TIMEOUT:
265 break;
266 default:
267 debug_msg("Unknown RTP event (type=%d)\n", e->type);
268 }
269}
void ** state
void pbuf_insert(struct pbuf *playout_buf, rtp_packet *pkt)
Definition pbuf.c:420
void pdb_destroy_item(struct pdb_e *item)
Definition pdb.c:370
int pdb_remove(struct pdb *db, uint32_t ssrc, struct pdb_e **item)
Definition pdb.c:346
uint8_t * rtp_get_userdata(struct rtp *session)
Definition rtp.c:1386
rtp_packet
Definition rtp.h:126
@ RX_RTP
Definition rtp.h:180
@ RR_TIMEOUT
Definition rtp.h:192
@ RX_SDES
Definition rtp.h:185
@ RX_APP
Definition rtp.h:193
@ RX_RTCP_START
Definition rtp.h:190
@ RX_TFRC_RX
Definition rtp.h:184
@ RX_SR
Definition rtp.h:182
@ SOURCE_CREATED
Definition rtp.h:187
@ RX_RTCP_FINISH
Definition rtp.h:191
@ SOURCE_DELETED
Definition rtp.h:188
@ RX_RR_EMPTY
Definition rtp.h:189
@ RX_BYE
Definition rtp.h:186
@ RX_RR
Definition rtp.h:183
static void process_sdes(struct pdb *participants, uint32_t ssrc, rtcp_sdes_item *d)
static void process_rr(struct rtp *session, rtp_event *e)
Definition pdb.c:84
rtp_event_type type
Definition rtp.h:199
void tfrc_recv_data(struct tfrc *state, time_ns_t curr_time, uint16_t seqnum, unsigned length)
Definition tfrc.c:436
static time_ns_t get_time_in_ns()
Definition tv.h:101

References rtp_event::data, debug_msg, get_time_in_ns(), rtcp_app::length, rtcp_app::name, pbuf_insert(), pdb_add(), pdb_destroy_item(), pdb_get(), pdb_remove(), process_rr(), process_sdes(), RR_TIMEOUT, rtp_get_userdata(), rtp_packet, RX_APP, RX_BYE, RX_RR, RX_RR_EMPTY, RX_RTCP_FINISH, RX_RTCP_START, RX_RTP, RX_SDES, RX_SR, RX_TFRC_RX, SOURCE_CREATED, SOURCE_DELETED, rtp_event::ssrc, state, rtcp_app::subtype, tfrc_recv_data(), and rtp_event::type.

Referenced by initialize_audio_network(), rtp_video_rxtx::initialize_network(), and vidcap_rtsp_init().

Here is the call graph for this function:

Variable Documentation

◆ frame

char* frame
extern

Definition at line 75 of file aja_win32_stub.cpp.

Referenced by state_blend_common::~state_blend_common(), append_audio_frame(), audio_append_pcm(), audio_cap_jack_init(), audio_channel_demux(), audio_codec_compress(), audio_codec_decompress(), audio_desc_from_frame(), audio_export(), audio_filter(), audio_frame_multiply_channel(), audio_play_alsa_put_frame(), audio_play_alsa_write_frame(), audio_play_ca_put_frame(), audio_play_jack_put_frame(), audio_play_mixer_put_frame(), audio_play_none_put_frame(), audio_play_pw_put_frame(), audio_play_sdi_put_frame(), audio_playback_put_frame(), audio_sdi_send(), calculate_rms(), calculate_rms(), capture_filter(), capture_thread(), change_pixfmt(), check_mixer(), cineform_compress_pop(), display_bluefish444_state::cleanup(), compress_frame(), compress_frame_tiles(), vulkan_display::VulkanDisplay::copy_and_queue_image(), audio_frame2::copy_with_bps_change(), create_jpeg_frame(), video_frame_pool::impl::deallocate_frame(), ldgm::decode(), decode_frame_h264(), decode_frame_jpeg(), decode_nal_unit(), decode_video_frame(), decode_yuri_audio_frame(), delete_frame(), display_aggregate_getf(), display_aggregate_put_audio_frame(), display_aggregate_putf(), display_aja_put_audio_frame(), display_aja_putf(), display_blend_put_audio_frame(), display_blend_putf(), display_blend_run(), display_bluefish444_getf(), display_bluefish444_put_audio_frame(), display_bluefish444_putf(), display_caca_putf(), display_conference_put_audio_frame(), display_conference_putf(), display_conference_worker(), display_decklink_getf(), display_decklink_put_audio_frame(), display_decklink_putf(), display_deltacast_put_audio_frame(), display_deltacast_putf(), display_drm_getf(), display_drm_putf(), display_dummy_putf(), display_dump_putf(), display_dvs_put_audio_frame(), display_dvs_putf(), display_file_getf(), display_file_put_audio_frame(), display_file_putf(), display_frame(), display_frame(), display_frame_helper(), display_gl_putf(), display_multiplier_put_audio_frame(), display_multiplier_putf(), display_multiplier_worker(), display_ndi_put_audio_frame(), display_ndi_putf(), display_null_put_audio_frame(), display_null_putf(), display_panogl_putf(), display_pipe_put_audio_frame(), display_pipe_putf(), display_put_audio_frame(), display_put_frame(), display_pw_putf(), display_sage_put_audio_frame(), display_sage_putf(), display_sdl2_putf(), display_sdl_put_audio_frame(), display_sdl_putf(), display_unix_sock_put_audio_frame(), display_unix_sock_putf(), display_unix_sock_run(), display_v4l2_putf(), display_xrgl_putf(), drm_fb_from_frame(), echo_cancel(), echo_play(), ldgm::encode(), rs::encode(), LDGM_session::encode_frame(), LDGM_session::encode_hdr_frame(), export_audio(), export_video(), fec_thread(), filter(), filter(), filter(), filter(), filter(), filter(), filter(), Filter_chain::filter(), format_audio_header(), format_video_header(), frame_complete(), gbrap_to_rgb(), gbrap_to_rgb_rgba(), gbrap_to_rgba(), gbrp10le_to_r10k(), gbrp10le_to_rg48(), gbrp10le_to_rgb(), gbrp10le_to_rgba(), gbrp12le_to_r10k(), gbrp12le_to_r12l(), gbrp12le_to_rg48(), gbrp12le_to_rgb(), gbrp12le_to_rgba(), gbrp16le_to_r10k(), gbrp16le_to_r12l(), gbrp16le_to_rg48(), gbrp16le_to_rgb(), gbrp16le_to_rgba(), gbrp_to_rgb(), gbrp_to_rgba(), gbrpXXle_to_r10k(), gbrpXXle_to_r12l(), gbrpXXle_to_rg48(), gbrpXXle_to_rgb(), gbrpXXle_to_rgba(), get_16_bit_pnm_data(), get_copy(), get_copy(), video_frame_pool::impl::get_disposable_frame(), video_frame_pool::impl::get_frame(), get_packet_rate(), get_packet_sizes(), video_frame_pool::impl::get_pod_frame(), get_splashscreen(), get_sps_pps_frame(), gl_load_splashscreen(), gl_process_frames(), grab_worker(), handle_user_event(), audio_frame2::has_same_prop_as(), hw_drm_recycle_callback(), hw_vdpau_copy_callback(), hw_vdpau_frame_copy(), hw_vdpau_frame_init(), hw_vdpau_frame_unref(), hw_vdpau_recycle_callback(), ipc_frame_free(), ipc_frame_new(), ipc_frame_reserve(), j2k_compressed_frame_dispose(), jack_send(), lavd_flush(), loadSplashscreen(), loadSplashscreen(), master_worker(), memcpy_data(), display_bluefish444_state::playback_loop(), ultragrid::aja::display::process_frames(), process_nal(), process_video_pkt(), ultragrid::aja::display::Putf(), display_bluefish444_state::putf(), loopback_video_rxtx::receiver_loop(), recompress_port_write(), recompress_process_async(), recompress_worker(), recycle_frame(), recycle_prime_frame(), video_frame_pool::impl::remove_free_frames(), rgb24_to_rgb32(), rgb24_to_uyvy(), rgb48le_to_r12l(), rgb48le_to_rgba(), same_linesizes(), save_video_frame(), save_video_frame_as_pnm(), save_video_frame_as_y4m(), screenshot(), sdi_capture_new_incoming_frame(), video_rxtx::send(), sage_video_rxtx::send_frame(), serialize_video_avframe(), slave_worker(), to_lavc_vid_conv(), tx_send(), tx_send_base(), tx_send_h264(), tx_send_jpeg(), tx_update(), upload_tiles(), vf_merge_tiles(), vf_separate_tiles(), vidcap_aggregate_grab(), vidcap_bluefish444_grab(), vidcap_file_process_audio_pkt(), vidcap_file_worker(), vidcap_file_write_audio(), vidcap_grab(), vidcap_import_dispose_video_frame(), vidcap_rtsp_grab(), vidcap_rtsp_thread(), vidcap_screen_osx_grab(), vidcap_switcher_grab(), vidcap_testcard2_grab(), vidcap_ug_input_grab(), vidcap_v4l2_dispose_video_frame(), video_desc_from_frame(), video_export(), videotoolbox_init(), hd_rum_decompress::state_transcoder_decompress::worker(), worker(), worker(), worker(), write_frame(), write_sps_pps(), write_video_frame(), yuv444p10le_to_r10k(), yuv444p10le_to_r12l(), yuv444p10le_to_rg48(), yuv444p12le_to_r10k(), yuv444p12le_to_r12l(), yuv444p12le_to_rg48(), yuv444p16le_to_r10k(), yuv444p16le_to_r12l(), yuv444p16le_to_rg48(), yuv444pXXle_to_r10k(), yuv444pXXle_to_r12l(), yuv444pXXle_to_rg48(), and yuvp10le_to_rgb().

◆ hdr_buf

char hdr_buf[100]

Definition at line 79 of file rtp_callback.c.

◆ iov

struct iovec iov[10]

Definition at line 81 of file rtp_callback.c.

◆ msg

◆ RTT

uint32_t RTT
extern

Definition at line 171 of file host.cpp.

Referenced by process_rr().