comparison rtp.c @ 65:a58a8a53eb46 libavformat

* UINTX -> uintx_t INTX -> intx_t
author kabi
date Tue, 11 Feb 2003 16:35:48 +0000
parents 05318cf2e886
children 25062c9b1f86
comparison
equal deleted inserted replaced
64:b0e0eb595e29 65:a58a8a53eb46
88 RTP_PT_PRIVATE = 96, 88 RTP_PT_PRIVATE = 96,
89 }; 89 };
90 90
91 typedef struct RTPContext { 91 typedef struct RTPContext {
92 int payload_type; 92 int payload_type;
93 UINT32 ssrc; 93 uint32_t ssrc;
94 UINT16 seq; 94 uint16_t seq;
95 UINT32 timestamp; 95 uint32_t timestamp;
96 UINT32 base_timestamp; 96 uint32_t base_timestamp;
97 UINT32 cur_timestamp; 97 uint32_t cur_timestamp;
98 int max_payload_size; 98 int max_payload_size;
99 /* rtcp sender statistics receive */ 99 /* rtcp sender statistics receive */
100 INT64 last_rtcp_ntp_time; 100 int64_t last_rtcp_ntp_time;
101 UINT32 last_rtcp_timestamp; 101 uint32_t last_rtcp_timestamp;
102 /* rtcp sender statistics */ 102 /* rtcp sender statistics */
103 unsigned int packet_count; 103 unsigned int packet_count;
104 unsigned int octet_count; 104 unsigned int octet_count;
105 unsigned int last_octet_count; 105 unsigned int last_octet_count;
106 int first_packet; 106 int first_packet;
107 /* buffer for output */ 107 /* buffer for output */
108 UINT8 buf[RTP_MAX_PACKET_LENGTH]; 108 uint8_t buf[RTP_MAX_PACKET_LENGTH];
109 UINT8 *buf_ptr; 109 uint8_t *buf_ptr;
110 } RTPContext; 110 } RTPContext;
111 111
112 int rtp_get_codec_info(AVCodecContext *codec, int payload_type) 112 int rtp_get_codec_info(AVCodecContext *codec, int payload_type)
113 { 113 {
114 switch(payload_type) { 114 switch(payload_type) {
182 break; 182 break;
183 } 183 }
184 return payload_type; 184 return payload_type;
185 } 185 }
186 186
187 static inline UINT32 decode_be32(const UINT8 *p) 187 static inline uint32_t decode_be32(const uint8_t *p)
188 { 188 {
189 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 189 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
190 } 190 }
191 191
192 static inline UINT32 decode_be64(const UINT8 *p) 192 static inline uint32_t decode_be64(const uint8_t *p)
193 { 193 {
194 return ((UINT64)decode_be32(p) << 32) | decode_be32(p + 4); 194 return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4);
195 } 195 }
196 196
197 static int rtcp_parse_packet(AVFormatContext *s1, const unsigned char *buf, int len) 197 static int rtcp_parse_packet(AVFormatContext *s1, const unsigned char *buf, int len)
198 { 198 {
199 RTPContext *s = s1->priv_data; 199 RTPContext *s = s1->priv_data;
219 { 219 {
220 RTPContext *s = s1->priv_data; 220 RTPContext *s = s1->priv_data;
221 unsigned int ssrc, h; 221 unsigned int ssrc, h;
222 int payload_type, seq, delta_timestamp; 222 int payload_type, seq, delta_timestamp;
223 AVStream *st; 223 AVStream *st;
224 UINT32 timestamp; 224 uint32_t timestamp;
225 225
226 if (len < 12) 226 if (len < 12)
227 return -1; 227 return -1;
228 228
229 if ((buf[0] & 0xc0) != (RTP_VERSION << 6)) 229 if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
388 388
389 return 0; 389 return 0;
390 } 390 }
391 391
392 /* send an rtcp sender report packet */ 392 /* send an rtcp sender report packet */
393 static void rtcp_send_sr(AVFormatContext *s1, INT64 ntp_time) 393 static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
394 { 394 {
395 RTPContext *s = s1->priv_data; 395 RTPContext *s = s1->priv_data;
396 #if defined(DEBUG) 396 #if defined(DEBUG)
397 printf("RTCP: %02x %Lx %x\n", s->payload_type, ntp_time, s->timestamp); 397 printf("RTCP: %02x %Lx %x\n", s->payload_type, ntp_time, s->timestamp);
398 #endif 398 #endif
407 put_flush_packet(&s1->pb); 407 put_flush_packet(&s1->pb);
408 } 408 }
409 409
410 /* send an rtp packet. sequence number is incremented, but the caller 410 /* send an rtp packet. sequence number is incremented, but the caller
411 must update the timestamp itself */ 411 must update the timestamp itself */
412 static void rtp_send_data(AVFormatContext *s1, UINT8 *buf1, int len) 412 static void rtp_send_data(AVFormatContext *s1, uint8_t *buf1, int len)
413 { 413 {
414 RTPContext *s = s1->priv_data; 414 RTPContext *s = s1->priv_data;
415 415
416 #ifdef DEBUG 416 #ifdef DEBUG
417 printf("rtp_send_data size=%d\n", len); 417 printf("rtp_send_data size=%d\n", len);
433 } 433 }
434 434
435 /* send an integer number of samples and compute time stamp and fill 435 /* send an integer number of samples and compute time stamp and fill
436 the rtp send buffer before sending. */ 436 the rtp send buffer before sending. */
437 static void rtp_send_samples(AVFormatContext *s1, 437 static void rtp_send_samples(AVFormatContext *s1,
438 UINT8 *buf1, int size, int sample_size) 438 uint8_t *buf1, int size, int sample_size)
439 { 439 {
440 RTPContext *s = s1->priv_data; 440 RTPContext *s = s1->priv_data;
441 int len, max_packet_size, n; 441 int len, max_packet_size, n;
442 442
443 max_packet_size = (s->max_payload_size / sample_size) * sample_size; 443 max_packet_size = (s->max_payload_size / sample_size) * sample_size;
466 } 466 }
467 467
468 /* NOTE: we suppose that exactly one frame is given as argument here */ 468 /* NOTE: we suppose that exactly one frame is given as argument here */
469 /* XXX: test it */ 469 /* XXX: test it */
470 static void rtp_send_mpegaudio(AVFormatContext *s1, 470 static void rtp_send_mpegaudio(AVFormatContext *s1,
471 UINT8 *buf1, int size) 471 uint8_t *buf1, int size)
472 { 472 {
473 RTPContext *s = s1->priv_data; 473 RTPContext *s = s1->priv_data;
474 AVStream *st = s1->streams[0]; 474 AVStream *st = s1->streams[0];
475 int len, count, max_packet_size; 475 int len, count, max_packet_size;
476 476
522 } 522 }
523 523
524 /* NOTE: a single frame must be passed with sequence header if 524 /* NOTE: a single frame must be passed with sequence header if
525 needed. XXX: use slices. */ 525 needed. XXX: use slices. */
526 static void rtp_send_mpegvideo(AVFormatContext *s1, 526 static void rtp_send_mpegvideo(AVFormatContext *s1,
527 UINT8 *buf1, int size) 527 uint8_t *buf1, int size)
528 { 528 {
529 RTPContext *s = s1->priv_data; 529 RTPContext *s = s1->priv_data;
530 AVStream *st = s1->streams[0]; 530 AVStream *st = s1->streams[0];
531 int len, h, max_packet_size; 531 int len, h, max_packet_size;
532 UINT8 *q; 532 uint8_t *q;
533 533
534 max_packet_size = s->max_payload_size; 534 max_packet_size = s->max_payload_size;
535 535
536 while (size > 0) { 536 while (size > 0) {
537 /* XXX: more correct headers */ 537 /* XXX: more correct headers */
570 } 570 }
571 s->cur_timestamp++; 571 s->cur_timestamp++;
572 } 572 }
573 573
574 static void rtp_send_raw(AVFormatContext *s1, 574 static void rtp_send_raw(AVFormatContext *s1,
575 UINT8 *buf1, int size) 575 uint8_t *buf1, int size)
576 { 576 {
577 RTPContext *s = s1->priv_data; 577 RTPContext *s = s1->priv_data;
578 AVStream *st = s1->streams[0]; 578 AVStream *st = s1->streams[0];
579 int len, max_packet_size; 579 int len, max_packet_size;
580 580
597 s->cur_timestamp++; 597 s->cur_timestamp++;
598 } 598 }
599 599
600 /* write an RTP packet. 'buf1' must contain a single specific frame. */ 600 /* write an RTP packet. 'buf1' must contain a single specific frame. */
601 static int rtp_write_packet(AVFormatContext *s1, int stream_index, 601 static int rtp_write_packet(AVFormatContext *s1, int stream_index,
602 UINT8 *buf1, int size, int force_pts) 602 uint8_t *buf1, int size, int force_pts)
603 { 603 {
604 RTPContext *s = s1->priv_data; 604 RTPContext *s = s1->priv_data;
605 AVStream *st = s1->streams[0]; 605 AVStream *st = s1->streams[0];
606 int rtcp_bytes; 606 int rtcp_bytes;
607 INT64 ntp_time; 607 int64_t ntp_time;
608 608
609 #ifdef DEBUG 609 #ifdef DEBUG
610 printf("%d: write len=%d\n", stream_index, size); 610 printf("%d: write len=%d\n", stream_index, size);
611 #endif 611 #endif
612 612
613 /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */ 613 /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */
614 rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / 614 rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
615 RTCP_TX_RATIO_DEN; 615 RTCP_TX_RATIO_DEN;
616 if (s->first_packet || rtcp_bytes >= 28) { 616 if (s->first_packet || rtcp_bytes >= 28) {
617 /* compute NTP time */ 617 /* compute NTP time */
618 ntp_time = force_pts; // ((INT64)force_pts << 28) / 5625 618 ntp_time = force_pts; // ((int64_t)force_pts << 28) / 5625
619 rtcp_send_sr(s1, ntp_time); 619 rtcp_send_sr(s1, ntp_time);
620 s->last_octet_count = s->octet_count; 620 s->last_octet_count = s->octet_count;
621 s->first_packet = 0; 621 s->first_packet = 0;
622 } 622 }
623 623