annotate rtpenc_mpv.c @ 5912:10f577d87c71 libavformat

Probe aac codecs for CODEC_ID_PROBE. Patch by Joakim Plate, elupus ecce se
author cehoyos
date Wed, 31 Mar 2010 10:45:15 +0000
parents e09092917f7e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
2406
18e94e5989d8 Move the RTP packetization code for MPEG12 video in its own file (rtp_mpv.c)
lucabe
parents: 2274
diff changeset
2 * RTP packetization for MPEG video
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 3968
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 3968
diff changeset
4 * Copyright (c) 2007 Luca Abeni
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
6 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
7 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 */
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 2570
diff changeset
22
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 2570
diff changeset
23 #include "libavcodec/mpegvideo.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include "avformat.h"
4388
80f21f72d7d6 Split rtp.h in rtp.h, rtpdec.h, and rtpenc.h
lucabe
parents: 4291
diff changeset
25 #include "rtpenc.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 /* NOTE: a single frame must be passed with sequence header if
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 needed. XXX: use slices. */
2406
18e94e5989d8 Move the RTP packetization code for MPEG12 video in its own file (rtp_mpv.c)
lucabe
parents: 2274
diff changeset
29 void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 {
4388
80f21f72d7d6 Split rtp.h in rtp.h, rtpdec.h, and rtpenc.h
lucabe
parents: 4291
diff changeset
31 RTPMuxContext *s = s1->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 int len, h, max_packet_size;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
33 uint8_t *q;
5012
7734b5d0fc6c Make sure buffer end remains constant within the loop
lu_zero
parents: 4388
diff changeset
34 const uint8_t *end = buf1 + size;
2419
584898b8189e Set the "TR" field in the payload header
lucabe
parents: 2418
diff changeset
35 int begin_of_slice, end_of_slice, frame_type, temporal_reference;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 max_packet_size = s->max_payload_size;
2413
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
38 begin_of_slice = 1;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
39 end_of_slice = 0;
2418
c13c82994800 Correctly set the "P" field in the payload header
lucabe
parents: 2413
diff changeset
40 frame_type = 0;
2419
584898b8189e Set the "TR" field in the payload header
lucabe
parents: 2418
diff changeset
41 temporal_reference = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 while (size > 0) {
2420
4ca7ed628eff Set the "B" flag in the payload header
lucabe
parents: 2419
diff changeset
44 int begin_of_sequence;
4ca7ed628eff Set the "B" flag in the payload header
lucabe
parents: 2419
diff changeset
45
4ca7ed628eff Set the "B" flag in the payload header
lucabe
parents: 2419
diff changeset
46 begin_of_sequence = 0;
2411
9134c5f663bd Backport fix for mpegvideo rtp, fixes Issue119, original fix from Dario Gallucci <dariodotgallucciatpolito.it> in feng
lu_zero
parents: 2406
diff changeset
47 len = max_packet_size - 4;
9134c5f663bd Backport fix for mpegvideo rtp, fixes Issue119, original fix from Dario Gallucci <dariodotgallucciatpolito.it> in feng
lu_zero
parents: 2406
diff changeset
48
9134c5f663bd Backport fix for mpegvideo rtp, fixes Issue119, original fix from Dario Gallucci <dariodotgallucciatpolito.it> in feng
lu_zero
parents: 2406
diff changeset
49 if (len >= size) {
9134c5f663bd Backport fix for mpegvideo rtp, fixes Issue119, original fix from Dario Gallucci <dariodotgallucciatpolito.it> in feng
lu_zero
parents: 2406
diff changeset
50 len = size;
2413
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
51 end_of_slice = 1;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
52 } else {
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
53 const uint8_t *r, *r1;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
54 int start_code;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
55
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
56 r1 = buf1;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
57 while (1) {
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
58 start_code = -1;
5012
7734b5d0fc6c Make sure buffer end remains constant within the loop
lu_zero
parents: 4388
diff changeset
59 r = ff_find_start_code(r1, end, &start_code);
2413
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
60 if((start_code & 0xFFFFFF00) == 0x100) {
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
61 /* New start code found */
2418
c13c82994800 Correctly set the "P" field in the payload header
lucabe
parents: 2413
diff changeset
62 if (start_code == 0x100) {
c13c82994800 Correctly set the "P" field in the payload header
lucabe
parents: 2413
diff changeset
63 frame_type = (r[1] & 0x38) >> 3;
2419
584898b8189e Set the "TR" field in the payload header
lucabe
parents: 2418
diff changeset
64 temporal_reference = (int)r[0] << 2 | r[1] >> 6;
2418
c13c82994800 Correctly set the "P" field in the payload header
lucabe
parents: 2413
diff changeset
65 }
2420
4ca7ed628eff Set the "B" flag in the payload header
lucabe
parents: 2419
diff changeset
66 if (start_code == 0x1B8) {
4ca7ed628eff Set the "B" flag in the payload header
lucabe
parents: 2419
diff changeset
67 begin_of_sequence = 1;
4ca7ed628eff Set the "B" flag in the payload header
lucabe
parents: 2419
diff changeset
68 }
2418
c13c82994800 Correctly set the "P" field in the payload header
lucabe
parents: 2413
diff changeset
69
3557
1489d89efd77 Fix MPEG video packetization for RTP
lucabe
parents: 3480
diff changeset
70 if (r - buf1 - 4 <= len) {
2413
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
71 /* The current slice fits in the packet */
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
72 if (begin_of_slice == 0) {
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
73 /* no slice at the beginning of the packet... */
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
74 end_of_slice = 1;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
75 len = r - buf1 - 4;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
76 break;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
77 }
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
78 r1 = r;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
79 } else {
3557
1489d89efd77 Fix MPEG video packetization for RTP
lucabe
parents: 3480
diff changeset
80 if ((r1 - buf1 > 4) && (r - r1 < max_packet_size)) {
2413
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
81 len = r1 - buf1 - 4;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
82 end_of_slice = 1;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
83 }
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
84 break;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
85 }
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
86 } else {
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
87 break;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
88 }
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
89 }
2411
9134c5f663bd Backport fix for mpegvideo rtp, fixes Issue119, original fix from Dario Gallucci <dariodotgallucciatpolito.it> in feng
lu_zero
parents: 2406
diff changeset
90 }
9134c5f663bd Backport fix for mpegvideo rtp, fixes Issue119, original fix from Dario Gallucci <dariodotgallucciatpolito.it> in feng
lu_zero
parents: 2406
diff changeset
91
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 h = 0;
2419
584898b8189e Set the "TR" field in the payload header
lucabe
parents: 2418
diff changeset
93 h |= temporal_reference << 16;
2420
4ca7ed628eff Set the "B" flag in the payload header
lucabe
parents: 2419
diff changeset
94 h |= begin_of_sequence << 13;
2413
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
95 h |= begin_of_slice << 12;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
96 h |= end_of_slice << 11;
2418
c13c82994800 Correctly set the "P" field in the payload header
lucabe
parents: 2413
diff changeset
97 h |= frame_type << 8;
2411
9134c5f663bd Backport fix for mpegvideo rtp, fixes Issue119, original fix from Dario Gallucci <dariodotgallucciatpolito.it> in feng
lu_zero
parents: 2406
diff changeset
98
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 q = s->buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 *q++ = h >> 24;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 *q++ = h >> 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 *q++ = h >> 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 *q++ = h;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 memcpy(q, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 q += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107
3968
bf1b4748cd2e spelling cosmetics
diego
parents: 3557
diff changeset
108 /* 90kHz time stamp */
2540
ca3cba9c641f Fix timestamps in RTP packets (now, MPEG1 video with B frames works correctly)
lucabe
parents: 2420
diff changeset
109 s->timestamp = s->cur_timestamp;
2406
18e94e5989d8 Move the RTP packetization code for MPEG12 video in its own file (rtp_mpv.c)
lucabe
parents: 2274
diff changeset
110 ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 buf1 += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 size -= len;
2413
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
114 begin_of_slice = end_of_slice;
0b5863b939d3 Correct packetization for MPEG video frames, and correct setting of the
lucabe
parents: 2412
diff changeset
115 end_of_slice = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118
294
6091b76cfc2a added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents: 241
diff changeset
119