comparison rtp.c @ 1425:00d9393a126f libavformat

make ffmpeg able to send back a RTCP receiver report. Patch by Thijs thijsvermeir A telenet P be Original thread: Date: Oct 27, 2006 12:58 PM Subject: [Ffmpeg-devel] [PATCH proposal] RTCP receiver report
author gpoirier
date Fri, 27 Oct 2006 18:19:29 +0000
parents 1c39ce5c6a5d
children f1614c754d5b
comparison
equal deleted inserted replaced
1424:1c39ce5c6a5d 1425:00d9393a126f
257 s->last_rtcp_timestamp = decode_be32(buf + 16); 257 s->last_rtcp_timestamp = decode_be32(buf + 16);
258 return 0; 258 return 0;
259 } 259 }
260 260
261 /** 261 /**
262 * some rtp servers assume client is dead if they don't hear from them...
263 * so we send a Receiver Report to the provided ByteIO context
264 * (we don't have access to the rtcp handle from here)
265 */
266 int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)
267 {
268 ByteIOContext pb;
269 uint8_t *buf;
270 int len;
271 int rtcp_bytes;
272
273 if (!s->rtp_ctx || (count < 1))
274 return -1;
275
276 /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */
277 s->octet_count += count;
278 rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
279 RTCP_TX_RATIO_DEN;
280 rtcp_bytes /= 50; // mmu_man: that's enough for me... VLC sends much less btw !?
281 if (rtcp_bytes < 28)
282 return -1;
283 s->last_octet_count = s->octet_count;
284
285 if (url_open_dyn_buf(&pb) < 0)
286 return -1;
287
288 // Receiver Report
289 put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */
290 put_byte(&pb, 201);
291 put_be16(&pb, 7); /* length in words - 1 */
292 put_be32(&pb, s->ssrc); // our own SSRC
293 put_be32(&pb, s->ssrc); // XXX: should be the server's here!
294 // some placeholders we should really fill...
295 put_be32(&pb, ((0 << 24) | (0 & 0x0ffffff))); /* 0% lost, total 0 lost */
296 put_be32(&pb, (0 << 16) | s->seq);
297 put_be32(&pb, 0x68); /* jitter */
298 put_be32(&pb, -1); /* last SR timestamp */
299 put_be32(&pb, 1); /* delay since last SR */
300
301 // CNAME
302 put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */
303 put_byte(&pb, 202);
304 len = strlen(s->hostname);
305 put_be16(&pb, (6 + len + 3) / 4); /* length in words - 1 */
306 put_be32(&pb, s->ssrc);
307 put_byte(&pb, 0x01);
308 put_byte(&pb, len);
309 put_buffer(&pb, s->hostname, len);
310 // padding
311 for (len = (6 + len) % 4; len % 4; len++) {
312 put_byte(&pb, 0);
313 }
314
315 put_flush_packet(&pb);
316 len = url_close_dyn_buf(&pb, &buf);
317 if ((len > 0) && buf) {
318 #if defined(DEBUG)
319 printf("sending %d bytes of RR\n", len);
320 #endif
321 url_write(s->rtp_ctx, buf, len);
322 av_free(buf);
323 }
324 return 0;
325 }
326
327 /**
262 * open a new RTP parse context for stream 'st'. 'st' can be NULL for 328 * open a new RTP parse context for stream 'st'. 'st' can be NULL for
263 * MPEG2TS streams to indicate that they should be demuxed inside the 329 * MPEG2TS streams to indicate that they should be demuxed inside the
264 * rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned) 330 * rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned)
265 * TODO: change this to not take rtp_payload data, and use the new dynamic payload system.
266 */ 331 */
267 RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, int payload_type, rtp_payload_data_t *rtp_payload_data) 332 RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, rtp_payload_data_t *rtp_payload_data)
268 { 333 {
269 RTPDemuxContext *s; 334 RTPDemuxContext *s;
270 335
271 s = av_mallocz(sizeof(RTPDemuxContext)); 336 s = av_mallocz(sizeof(RTPDemuxContext));
272 if (!s) 337 if (!s)
297 break; 362 break;
298 default: 363 default:
299 break; 364 break;
300 } 365 }
301 } 366 }
367 // needed to send back RTCP RR in RTSP sessions
368 s->rtp_ctx = rtpc;
369 gethostname(s->hostname, sizeof(s->hostname));
302 return s; 370 return s;
303 } 371 }
304 372
305 static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf) 373 static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf)
306 { 374 {
397 } 465 }
398 payload_type = buf[1] & 0x7f; 466 payload_type = buf[1] & 0x7f;
399 seq = (buf[2] << 8) | buf[3]; 467 seq = (buf[2] << 8) | buf[3];
400 timestamp = decode_be32(buf + 4); 468 timestamp = decode_be32(buf + 4);
401 ssrc = decode_be32(buf + 8); 469 ssrc = decode_be32(buf + 8);
470 /* store the ssrc in the RTPDemuxContext */
471 s->ssrc = ssrc;
402 472
403 /* NOTE: we can handle only one payload type */ 473 /* NOTE: we can handle only one payload type */
404 if (s->payload_type != payload_type) 474 if (s->payload_type != payload_type)
405 return -1; 475 return -1;
406 476