added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
[libav.git] / libavformat / rtp.c
1 /*
2 * RTP input/output format
3 * Copyright (c) 2002 Fabrice Bellard.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #include "avformat.h"
20 #include "mpegts.h"
21
22 #include <unistd.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
26 #ifndef __BEOS__
27 # include <arpa/inet.h>
28 #else
29 # include "barpainet.h"
30 #endif
31 #include <netdb.h>
32
33 //#define DEBUG
34
35
36 /* TODO: - add RTCP statistics reporting (should be optional).
37
38 - add support for h263/mpeg4 packetized output : IDEA: send a
39 buffer to 'rtp_write_packet' contains all the packets for ONE
40 frame. Each packet should have a four byte header containing
41 the length in big endian format (same trick as
42 'url_open_dyn_packet_buf')
43 */
44
45 #define RTP_VERSION 2
46
47 #define RTP_MAX_SDES 256 /* maximum text length for SDES */
48
49 /* RTCP paquets use 0.5 % of the bandwidth */
50 #define RTCP_TX_RATIO_NUM 5
51 #define RTCP_TX_RATIO_DEN 1000
52
53 typedef enum {
54 RTCP_SR = 200,
55 RTCP_RR = 201,
56 RTCP_SDES = 202,
57 RTCP_BYE = 203,
58 RTCP_APP = 204
59 } rtcp_type_t;
60
61 typedef enum {
62 RTCP_SDES_END = 0,
63 RTCP_SDES_CNAME = 1,
64 RTCP_SDES_NAME = 2,
65 RTCP_SDES_EMAIL = 3,
66 RTCP_SDES_PHONE = 4,
67 RTCP_SDES_LOC = 5,
68 RTCP_SDES_TOOL = 6,
69 RTCP_SDES_NOTE = 7,
70 RTCP_SDES_PRIV = 8,
71 RTCP_SDES_IMG = 9,
72 RTCP_SDES_DOOR = 10,
73 RTCP_SDES_SOURCE = 11
74 } rtcp_sdes_type_t;
75
76 struct RTPDemuxContext {
77 AVFormatContext *ic;
78 AVStream *st;
79 int payload_type;
80 uint32_t ssrc;
81 uint16_t seq;
82 uint32_t timestamp;
83 uint32_t base_timestamp;
84 uint32_t cur_timestamp;
85 int max_payload_size;
86 MpegTSContext *ts; /* only used for RTP_PT_MPEG2TS payloads */
87 int read_buf_index;
88 int read_buf_size;
89
90 /* rtcp sender statistics receive */
91 int64_t last_rtcp_ntp_time;
92 int64_t first_rtcp_ntp_time;
93 uint32_t last_rtcp_timestamp;
94 /* rtcp sender statistics */
95 unsigned int packet_count;
96 unsigned int octet_count;
97 unsigned int last_octet_count;
98 int first_packet;
99 /* buffer for output */
100 uint8_t buf[RTP_MAX_PACKET_LENGTH];
101 uint8_t *buf_ptr;
102 };
103
104 int rtp_get_codec_info(AVCodecContext *codec, int payload_type)
105 {
106 switch(payload_type) {
107 case RTP_PT_ULAW:
108 codec->codec_type = CODEC_TYPE_AUDIO;
109 codec->codec_id = CODEC_ID_PCM_MULAW;
110 codec->channels = 1;
111 codec->sample_rate = 8000;
112 break;
113 case RTP_PT_ALAW:
114 codec->codec_type = CODEC_TYPE_AUDIO;
115 codec->codec_id = CODEC_ID_PCM_ALAW;
116 codec->channels = 1;
117 codec->sample_rate = 8000;
118 break;
119 case RTP_PT_S16BE_STEREO:
120 codec->codec_type = CODEC_TYPE_AUDIO;
121 codec->codec_id = CODEC_ID_PCM_S16BE;
122 codec->channels = 2;
123 codec->sample_rate = 44100;
124 break;
125 case RTP_PT_S16BE_MONO:
126 codec->codec_type = CODEC_TYPE_AUDIO;
127 codec->codec_id = CODEC_ID_PCM_S16BE;
128 codec->channels = 1;
129 codec->sample_rate = 44100;
130 break;
131 case RTP_PT_MPEGAUDIO:
132 codec->codec_type = CODEC_TYPE_AUDIO;
133 codec->codec_id = CODEC_ID_MP2;
134 break;
135 case RTP_PT_JPEG:
136 codec->codec_type = CODEC_TYPE_VIDEO;
137 codec->codec_id = CODEC_ID_MJPEG;
138 break;
139 case RTP_PT_MPEGVIDEO:
140 codec->codec_type = CODEC_TYPE_VIDEO;
141 codec->codec_id = CODEC_ID_MPEG1VIDEO;
142 break;
143 case RTP_PT_MPEG2TS:
144 codec->codec_type = CODEC_TYPE_DATA;
145 codec->codec_id = CODEC_ID_MPEG2TS;
146 break;
147 default:
148 return -1;
149 }
150 return 0;
151 }
152
153 /* return < 0 if unknown payload type */
154 int rtp_get_payload_type(AVCodecContext *codec)
155 {
156 int payload_type;
157
158 /* compute the payload type */
159 payload_type = -1;
160 switch(codec->codec_id) {
161 case CODEC_ID_PCM_MULAW:
162 payload_type = RTP_PT_ULAW;
163 break;
164 case CODEC_ID_PCM_ALAW:
165 payload_type = RTP_PT_ALAW;
166 break;
167 case CODEC_ID_PCM_S16BE:
168 if (codec->channels == 1) {
169 payload_type = RTP_PT_S16BE_MONO;
170 } else if (codec->channels == 2) {
171 payload_type = RTP_PT_S16BE_STEREO;
172 }
173 break;
174 case CODEC_ID_MP2:
175 case CODEC_ID_MP3:
176 payload_type = RTP_PT_MPEGAUDIO;
177 break;
178 case CODEC_ID_MJPEG:
179 payload_type = RTP_PT_JPEG;
180 break;
181 case CODEC_ID_MPEG1VIDEO:
182 payload_type = RTP_PT_MPEGVIDEO;
183 break;
184 case CODEC_ID_MPEG2TS:
185 payload_type = RTP_PT_MPEG2TS;
186 break;
187 default:
188 break;
189 }
190 return payload_type;
191 }
192
193 static inline uint32_t decode_be32(const uint8_t *p)
194 {
195 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
196 }
197
198 static inline uint64_t decode_be64(const uint8_t *p)
199 {
200 return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4);
201 }
202
203 static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len)
204 {
205 if (buf[1] != 200)
206 return -1;
207 s->last_rtcp_ntp_time = decode_be64(buf + 8);
208 if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE)
209 s->first_rtcp_ntp_time = s->last_rtcp_ntp_time;
210 s->last_rtcp_timestamp = decode_be32(buf + 16);
211 return 0;
212 }
213
214 /**
215 * open a new RTP parse context for stream 'st'. 'st' can be NULL for
216 * MPEG2TS streams to indicate that they should be demuxed inside the
217 * rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned)
218 */
219 RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, int payload_type)
220 {
221 RTPDemuxContext *s;
222
223 s = av_mallocz(sizeof(RTPDemuxContext));
224 if (!s)
225 return NULL;
226 s->payload_type = payload_type;
227 s->last_rtcp_ntp_time = AV_NOPTS_VALUE;
228 s->first_rtcp_ntp_time = AV_NOPTS_VALUE;
229 s->ic = s1;
230 s->st = st;
231 if (payload_type == RTP_PT_MPEG2TS) {
232 s->ts = mpegts_parse_open(s->ic);
233 if (s->ts == NULL) {
234 av_free(s);
235 return NULL;
236 }
237 }
238 return s;
239 }
240
241 /**
242 * Parse an RTP or RTCP packet directly sent as a buffer.
243 * @param s RTP parse context.
244 * @param pkt returned packet
245 * @param buf input buffer or NULL to read the next packets
246 * @param len buffer len
247 * @return 0 if a packet is returned, 1 if a packet is returned and more can follow
248 * (use buf as NULL to read the next). -1 if no packet (error or no more packet).
249 */
250 int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
251 const uint8_t *buf, int len)
252 {
253 unsigned int ssrc, h;
254 int payload_type, seq, delta_timestamp, ret;
255 AVStream *st;
256 uint32_t timestamp;
257
258 if (!buf) {
259 /* return the next packets, if any */
260 if (s->read_buf_index >= s->read_buf_size)
261 return -1;
262 ret = mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index,
263 s->read_buf_size - s->read_buf_index);
264 if (ret < 0)
265 return -1;
266 s->read_buf_index += ret;
267 if (s->read_buf_index < s->read_buf_size)
268 return 1;
269 else
270 return 0;
271 }
272
273 if (len < 12)
274 return -1;
275
276 if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
277 return -1;
278 if (buf[1] >= 200 && buf[1] <= 204) {
279 rtcp_parse_packet(s, buf, len);
280 return -1;
281 }
282 payload_type = buf[1] & 0x7f;
283 seq = (buf[2] << 8) | buf[3];
284 timestamp = decode_be32(buf + 4);
285 ssrc = decode_be32(buf + 8);
286
287 /* NOTE: we can handle only one payload type */
288 if (s->payload_type != payload_type)
289 return -1;
290 #if defined(DEBUG) || 1
291 if (seq != ((s->seq + 1) & 0xffff)) {
292 printf("RTP: PT=%02x: bad cseq %04x expected=%04x\n",
293 payload_type, seq, ((s->seq + 1) & 0xffff));
294 }
295 s->seq = seq;
296 #endif
297 len -= 12;
298 buf += 12;
299
300 st = s->st;
301 if (!st) {
302 /* specific MPEG2TS demux support */
303 ret = mpegts_parse_packet(s->ts, pkt, buf, len);
304 if (ret < 0)
305 return -1;
306 if (ret < len) {
307 s->read_buf_size = len - ret;
308 memcpy(s->buf, buf + ret, s->read_buf_size);
309 s->read_buf_index = 0;
310 return 1;
311 }
312 } else {
313 switch(st->codec.codec_id) {
314 case CODEC_ID_MP2:
315 /* better than nothing: skip mpeg audio RTP header */
316 if (len <= 4)
317 return -1;
318 h = decode_be32(buf);
319 len -= 4;
320 buf += 4;
321 av_new_packet(pkt, len);
322 memcpy(pkt->data, buf, len);
323 break;
324 case CODEC_ID_MPEG1VIDEO:
325 /* better than nothing: skip mpeg audio RTP header */
326 if (len <= 4)
327 return -1;
328 h = decode_be32(buf);
329 buf += 4;
330 len -= 4;
331 if (h & (1 << 26)) {
332 /* mpeg2 */
333 if (len <= 4)
334 return -1;
335 buf += 4;
336 len -= 4;
337 }
338 av_new_packet(pkt, len);
339 memcpy(pkt->data, buf, len);
340 break;
341 default:
342 av_new_packet(pkt, len);
343 memcpy(pkt->data, buf, len);
344 break;
345 }
346
347 switch(st->codec.codec_id) {
348 case CODEC_ID_MP2:
349 case CODEC_ID_MPEG1VIDEO:
350 if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) {
351 int64_t addend;
352 /* XXX: is it really necessary to unify the timestamp base ? */
353 /* compute pts from timestamp with received ntp_time */
354 delta_timestamp = timestamp - s->last_rtcp_timestamp;
355 /* convert to 90 kHz without overflow */
356 addend = (s->last_rtcp_ntp_time - s->first_rtcp_ntp_time) >> 14;
357 addend = (addend * 5625) >> 14;
358 pkt->pts = addend + delta_timestamp;
359 }
360 break;
361 default:
362 /* no timestamp info yet */
363 break;
364 }
365 pkt->stream_index = s->st->index;
366 }
367 return 0;
368 }
369
370 void rtp_parse_close(RTPDemuxContext *s)
371 {
372 if (s->payload_type == RTP_PT_MPEG2TS) {
373 mpegts_parse_close(s->ts);
374 }
375 av_free(s);
376 }
377
378 /* rtp output */
379
380 static int rtp_write_header(AVFormatContext *s1)
381 {
382 RTPDemuxContext *s = s1->priv_data;
383 int payload_type, max_packet_size, n;
384 AVStream *st;
385
386 if (s1->nb_streams != 1)
387 return -1;
388 st = s1->streams[0];
389
390 payload_type = rtp_get_payload_type(&st->codec);
391 if (payload_type < 0)
392 payload_type = RTP_PT_PRIVATE; /* private payload type */
393 s->payload_type = payload_type;
394
395 s->base_timestamp = random();
396 s->timestamp = s->base_timestamp;
397 s->ssrc = random();
398 s->first_packet = 1;
399
400 max_packet_size = url_fget_max_packet_size(&s1->pb);
401 if (max_packet_size <= 12)
402 return AVERROR_IO;
403 s->max_payload_size = max_packet_size - 12;
404
405 switch(st->codec.codec_id) {
406 case CODEC_ID_MP2:
407 case CODEC_ID_MP3:
408 s->buf_ptr = s->buf + 4;
409 s->cur_timestamp = 0;
410 break;
411 case CODEC_ID_MPEG1VIDEO:
412 s->cur_timestamp = 0;
413 break;
414 case CODEC_ID_MPEG2TS:
415 n = s->max_payload_size / TS_PACKET_SIZE;
416 if (n < 1)
417 n = 1;
418 s->max_payload_size = n * TS_PACKET_SIZE;
419 s->buf_ptr = s->buf;
420 break;
421 default:
422 s->buf_ptr = s->buf;
423 break;
424 }
425
426 return 0;
427 }
428
429 /* send an rtcp sender report packet */
430 static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
431 {
432 RTPDemuxContext *s = s1->priv_data;
433 #if defined(DEBUG)
434 printf("RTCP: %02x %Lx %x\n", s->payload_type, ntp_time, s->timestamp);
435 #endif
436 put_byte(&s1->pb, (RTP_VERSION << 6));
437 put_byte(&s1->pb, 200);
438 put_be16(&s1->pb, 6); /* length in words - 1 */
439 put_be32(&s1->pb, s->ssrc);
440 put_be64(&s1->pb, ntp_time);
441 put_be32(&s1->pb, s->timestamp);
442 put_be32(&s1->pb, s->packet_count);
443 put_be32(&s1->pb, s->octet_count);
444 put_flush_packet(&s1->pb);
445 }
446
447 /* send an rtp packet. sequence number is incremented, but the caller
448 must update the timestamp itself */
449 static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len)
450 {
451 RTPDemuxContext *s = s1->priv_data;
452
453 #ifdef DEBUG
454 printf("rtp_send_data size=%d\n", len);
455 #endif
456
457 /* build the RTP header */
458 put_byte(&s1->pb, (RTP_VERSION << 6));
459 put_byte(&s1->pb, s->payload_type & 0x7f);
460 put_be16(&s1->pb, s->seq);
461 put_be32(&s1->pb, s->timestamp);
462 put_be32(&s1->pb, s->ssrc);
463
464 put_buffer(&s1->pb, buf1, len);
465 put_flush_packet(&s1->pb);
466
467 s->seq++;
468 s->octet_count += len;
469 s->packet_count++;
470 }
471
472 /* send an integer number of samples and compute time stamp and fill
473 the rtp send buffer before sending. */
474 static void rtp_send_samples(AVFormatContext *s1,
475 const uint8_t *buf1, int size, int sample_size)
476 {
477 RTPDemuxContext *s = s1->priv_data;
478 int len, max_packet_size, n;
479
480 max_packet_size = (s->max_payload_size / sample_size) * sample_size;
481 /* not needed, but who nows */
482 if ((size % sample_size) != 0)
483 av_abort();
484 while (size > 0) {
485 len = (max_packet_size - (s->buf_ptr - s->buf));
486 if (len > size)
487 len = size;
488
489 /* copy data */
490 memcpy(s->buf_ptr, buf1, len);
491 s->buf_ptr += len;
492 buf1 += len;
493 size -= len;
494 n = (s->buf_ptr - s->buf);
495 /* if buffer full, then send it */
496 if (n >= max_packet_size) {
497 rtp_send_data(s1, s->buf, n);
498 s->buf_ptr = s->buf;
499 /* update timestamp */
500 s->timestamp += n / sample_size;
501 }
502 }
503 }
504
505 /* NOTE: we suppose that exactly one frame is given as argument here */
506 /* XXX: test it */
507 static void rtp_send_mpegaudio(AVFormatContext *s1,
508 const uint8_t *buf1, int size)
509 {
510 RTPDemuxContext *s = s1->priv_data;
511 AVStream *st = s1->streams[0];
512 int len, count, max_packet_size;
513
514 max_packet_size = s->max_payload_size;
515
516 /* test if we must flush because not enough space */
517 len = (s->buf_ptr - s->buf);
518 if ((len + size) > max_packet_size) {
519 if (len > 4) {
520 rtp_send_data(s1, s->buf, s->buf_ptr - s->buf);
521 s->buf_ptr = s->buf + 4;
522 /* 90 KHz time stamp */
523 s->timestamp = s->base_timestamp +
524 (s->cur_timestamp * 90000LL) / st->codec.sample_rate;
525 }
526 }
527
528 /* add the packet */
529 if (size > max_packet_size) {
530 /* big packet: fragment */
531 count = 0;
532 while (size > 0) {
533 len = max_packet_size - 4;
534 if (len > size)
535 len = size;
536 /* build fragmented packet */
537 s->buf[0] = 0;
538 s->buf[1] = 0;
539 s->buf[2] = count >> 8;
540 s->buf[3] = count;
541 memcpy(s->buf + 4, buf1, len);
542 rtp_send_data(s1, s->buf, len + 4);
543 size -= len;
544 buf1 += len;
545 count += len;
546 }
547 } else {
548 if (s->buf_ptr == s->buf + 4) {
549 /* no fragmentation possible */
550 s->buf[0] = 0;
551 s->buf[1] = 0;
552 s->buf[2] = 0;
553 s->buf[3] = 0;
554 }
555 memcpy(s->buf_ptr, buf1, size);
556 s->buf_ptr += size;
557 }
558 s->cur_timestamp += st->codec.frame_size;
559 }
560
561 /* NOTE: a single frame must be passed with sequence header if
562 needed. XXX: use slices. */
563 static void rtp_send_mpegvideo(AVFormatContext *s1,
564 const uint8_t *buf1, int size)
565 {
566 RTPDemuxContext *s = s1->priv_data;
567 AVStream *st = s1->streams[0];
568 int len, h, max_packet_size;
569 uint8_t *q;
570
571 max_packet_size = s->max_payload_size;
572
573 while (size > 0) {
574 /* XXX: more correct headers */
575 h = 0;
576 if (st->codec.sub_id == 2)
577 h |= 1 << 26; /* mpeg 2 indicator */
578 q = s->buf;
579 *q++ = h >> 24;
580 *q++ = h >> 16;
581 *q++ = h >> 8;
582 *q++ = h;
583
584 if (st->codec.sub_id == 2) {
585 h = 0;
586 *q++ = h >> 24;
587 *q++ = h >> 16;
588 *q++ = h >> 8;
589 *q++ = h;
590 }
591
592 len = max_packet_size - (q - s->buf);
593 if (len > size)
594 len = size;
595
596 memcpy(q, buf1, len);
597 q += len;
598
599 /* 90 KHz time stamp */
600 s->timestamp = s->base_timestamp +
601 av_rescale((int64_t)s->cur_timestamp * st->codec.frame_rate_base, 90000, st->codec.frame_rate);
602 rtp_send_data(s1, s->buf, q - s->buf);
603
604 buf1 += len;
605 size -= len;
606 }
607 s->cur_timestamp++;
608 }
609
610 static void rtp_send_raw(AVFormatContext *s1,
611 const uint8_t *buf1, int size)
612 {
613 RTPDemuxContext *s = s1->priv_data;
614 AVStream *st = s1->streams[0];
615 int len, max_packet_size;
616
617 max_packet_size = s->max_payload_size;
618
619 while (size > 0) {
620 len = max_packet_size;
621 if (len > size)
622 len = size;
623
624 /* 90 KHz time stamp */
625 s->timestamp = s->base_timestamp +
626 av_rescale((int64_t)s->cur_timestamp * st->codec.frame_rate_base, 90000, st->codec.frame_rate);
627 rtp_send_data(s1, buf1, len);
628
629 buf1 += len;
630 size -= len;
631 }
632 s->cur_timestamp++;
633 }
634
635 /* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */
636 static void rtp_send_mpegts_raw(AVFormatContext *s1,
637 const uint8_t *buf1, int size)
638 {
639 RTPDemuxContext *s = s1->priv_data;
640 int len, out_len;
641
642 while (size >= TS_PACKET_SIZE) {
643 len = s->max_payload_size - (s->buf_ptr - s->buf);
644 if (len > size)
645 len = size;
646 memcpy(s->buf_ptr, buf1, len);
647 buf1 += len;
648 size -= len;
649 s->buf_ptr += len;
650
651 out_len = s->buf_ptr - s->buf;
652 if (out_len >= s->max_payload_size) {
653 rtp_send_data(s1, s->buf, out_len);
654 s->buf_ptr = s->buf;
655 }
656 }
657 }
658
659 /* write an RTP packet. 'buf1' must contain a single specific frame. */
660 static int rtp_write_packet(AVFormatContext *s1, int stream_index,
661 const uint8_t *buf1, int size, int64_t pts)
662 {
663 RTPDemuxContext *s = s1->priv_data;
664 AVStream *st = s1->streams[0];
665 int rtcp_bytes;
666 int64_t ntp_time;
667
668 #ifdef DEBUG
669 printf("%d: write len=%d\n", stream_index, size);
670 #endif
671
672 /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */
673 rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
674 RTCP_TX_RATIO_DEN;
675 if (s->first_packet || rtcp_bytes >= 28) {
676 /* compute NTP time */
677 /* XXX: 90 kHz timestamp hardcoded */
678 ntp_time = (pts << 28) / 5625;
679 rtcp_send_sr(s1, ntp_time);
680 s->last_octet_count = s->octet_count;
681 s->first_packet = 0;
682 }
683
684 switch(st->codec.codec_id) {
685 case CODEC_ID_PCM_MULAW:
686 case CODEC_ID_PCM_ALAW:
687 case CODEC_ID_PCM_U8:
688 case CODEC_ID_PCM_S8:
689 rtp_send_samples(s1, buf1, size, 1 * st->codec.channels);
690 break;
691 case CODEC_ID_PCM_U16BE:
692 case CODEC_ID_PCM_U16LE:
693 case CODEC_ID_PCM_S16BE:
694 case CODEC_ID_PCM_S16LE:
695 rtp_send_samples(s1, buf1, size, 2 * st->codec.channels);
696 break;
697 case CODEC_ID_MP2:
698 case CODEC_ID_MP3:
699 rtp_send_mpegaudio(s1, buf1, size);
700 break;
701 case CODEC_ID_MPEG1VIDEO:
702 rtp_send_mpegvideo(s1, buf1, size);
703 break;
704 case CODEC_ID_MPEG2TS:
705 rtp_send_mpegts_raw(s1, buf1, size);
706 break;
707 default:
708 /* better than nothing : send the codec raw data */
709 rtp_send_raw(s1, buf1, size);
710 break;
711 }
712 return 0;
713 }
714
715 static int rtp_write_trailer(AVFormatContext *s1)
716 {
717 // RTPDemuxContext *s = s1->priv_data;
718 return 0;
719 }
720
721 AVOutputFormat rtp_mux = {
722 "rtp",
723 "RTP output format",
724 NULL,
725 NULL,
726 sizeof(RTPDemuxContext),
727 CODEC_ID_PCM_MULAW,
728 CODEC_ID_NONE,
729 rtp_write_header,
730 rtp_write_packet,
731 rtp_write_trailer,
732 };
733
734 int rtp_init(void)
735 {
736 av_register_output_format(&rtp_mux);
737 return 0;
738 }