Mercurial > libavformat.hg
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 |
rev | line source |
---|---|
0 | 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 | 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 | 9 * modify it under the terms of the GNU Lesser General Public |
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 | 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 | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
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 | 21 */ |
3286 | 22 |
23 #include "libavcodec/mpegvideo.h" | |
0 | 24 #include "avformat.h" |
4388 | 25 #include "rtpenc.h" |
0 | 26 |
27 /* NOTE: a single frame must be passed with sequence header if | |
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 | 30 { |
4388 | 31 RTPMuxContext *s = s1->priv_data; |
0 | 32 int len, h, max_packet_size; |
65 | 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 | 35 int begin_of_slice, end_of_slice, frame_type, temporal_reference; |
0 | 36 |
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 | 40 frame_type = 0; |
2419 | 41 temporal_reference = 0; |
0 | 42 |
43 while (size > 0) { | |
2420 | 44 int begin_of_sequence; |
45 | |
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 | 62 if (start_code == 0x100) { |
63 frame_type = (r[1] & 0x38) >> 3; | |
2419 | 64 temporal_reference = (int)r[0] << 2 | r[1] >> 6; |
2418 | 65 } |
2420 | 66 if (start_code == 0x1B8) { |
67 begin_of_sequence = 1; | |
68 } | |
2418 | 69 |
3557 | 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 | 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 | 92 h = 0; |
2419 | 93 h |= temporal_reference << 16; |
2420 | 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 | 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 | 99 q = s->buf; |
100 *q++ = h >> 24; | |
101 *q++ = h >> 16; | |
102 *q++ = h >> 8; | |
103 *q++ = h; | |
104 | |
105 memcpy(q, buf1, len); | |
106 q += len; | |
107 | |
3968 | 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 | 111 |
112 buf1 += len; | |
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 | 116 } |
117 } | |
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 |