Mercurial > mplayer.hg
annotate libmpdemux/demux_rtp_codec.cpp @ 29528:2a3b942fce09
Use lookup_keymap_table function with data structure instead of huge switch-case
for mapping OSX keys onto MPlayer keys in vo_quartz.
author | reimar |
---|---|
date | Thu, 27 Aug 2009 23:13:37 +0000 |
parents | 3a154fb8f85c |
children | ecf6cbab0b8d |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
2 * codec-specific routines used to interface between MPlayer |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
3 * and the "LIVE555 Streaming Media" libraries |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
4 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
5 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
6 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
7 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
10 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
11 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
12 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
15 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
16 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
18 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27417
diff
changeset
|
20 */ |
9250 | 21 |
22 #include "demux_rtp_internal.h" | |
23 extern "C" { | |
21911
e86bb13ec44b
demux_rtp_codec.cpp:100: `INT_MAX' undeclared (first use this function)
diego
parents:
21871
diff
changeset
|
24 #include <limits.h> |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
25 #include <math.h> |
9250 | 26 #include "stheader.h" |
26486 | 27 #include "libavutil/base64.h" |
22852 | 28 } |
29 | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26486
diff
changeset
|
30 #ifdef CONFIG_LIBAVCODEC |
22852 | 31 AVCodecParserContext * h264parserctx; |
29453 | 32 AVCodecContext *avcctx; |
22852 | 33 #endif |
34 | |
35 // Copied from vlc | |
36 static unsigned char* parseH264ConfigStr( char const* configStr, | |
37 unsigned int& configSize ) | |
38 { | |
39 | |
40 char *dup, *psz; | |
41 int i, i_records = 1; | |
42 | |
43 if( configSize ) | |
44 configSize = 0; | |
45 if( configStr == NULL || *configStr == '\0' ) | |
46 return NULL; | |
47 psz = dup = strdup( configStr ); | |
48 | |
49 /* Count the number of comma's */ | |
50 for( psz = dup; *psz != '\0'; ++psz ) | |
51 { | |
52 if( *psz == ',') | |
53 { | |
54 ++i_records; | |
55 *psz = '\0'; | |
56 } | |
57 } | |
58 | |
59 unsigned char *cfg = new unsigned char[5 * strlen(dup)]; | |
60 psz = dup; | |
61 for( i = 0; i < i_records; i++ ) | |
62 { | |
63 | |
64 cfg[configSize++] = 0x00; | |
65 cfg[configSize++] = 0x00; | |
66 cfg[configSize++] = 0x01; | |
67 configSize += av_base64_decode( (uint8_t*)&cfg[configSize], | |
68 psz, | |
69 5 * strlen(dup) - 3 ); | |
70 | |
71 psz += strlen(psz)+1; | |
72 } | |
73 if( dup ) free( dup ); | |
74 | |
75 return cfg; | |
9250 | 76 } |
77 | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
78 static void |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
79 needVideoFrameRate(demuxer_t* demuxer, MediaSubsession* subsession); // forward |
9250 | 80 static Boolean |
81 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState, | |
82 unsigned& fourcc); // forward | |
83 static Boolean | |
84 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState, | |
85 unsigned& fourcc, unsigned& numChannels); // forward | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
86 |
22278
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
87 static BITMAPINFOHEADER * insertVideoExtradata(BITMAPINFOHEADER *bih, |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
88 unsigned char * extraData, |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
89 unsigned size) |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
90 { |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
91 BITMAPINFOHEADER * original = bih; |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
92 if (!size || size > INT_MAX - sizeof(BITMAPINFOHEADER)) |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
93 return bih; |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
94 bih = (BITMAPINFOHEADER*)realloc(bih, sizeof(BITMAPINFOHEADER) + size); |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
95 if (!bih) |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
96 return original; |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
97 bih->biSize = sizeof(BITMAPINFOHEADER) + size; |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
98 memcpy(bih+1, extraData, size); |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
99 return bih; |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
100 } |
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
101 |
9250 | 102 void rtpCodecInitialize_video(demuxer_t* demuxer, |
103 MediaSubsession* subsession, | |
104 unsigned& flags) { | |
105 flags = 0; | |
106 // Create a dummy video stream header | |
107 // to make the main MPlayer code happy: | |
108 sh_video_t* sh_video = new_sh_video(demuxer,0); | |
109 BITMAPINFOHEADER* bih | |
110 = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER)); | |
111 bih->biSize = sizeof(BITMAPINFOHEADER); | |
112 sh_video->bih = bih; | |
113 demux_stream_t* d_video = demuxer->video; | |
114 d_video->sh = sh_video; sh_video->ds = d_video; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
115 |
9250 | 116 // Map known video MIME types to the BITMAPINFOHEADER parameters |
117 // that this program uses. (Note that not all types need all | |
118 // of the parameters to be set.) | |
10478
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
119 if (strcmp(subsession->codecName(), "MPV") == 0) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
120 flags |= RTPSTATE_IS_MPEG12_VIDEO; |
10478
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
121 } else if (strcmp(subsession->codecName(), "MP1S") == 0 || |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
122 strcmp(subsession->codecName(), "MP2T") == 0) { |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
123 flags |= RTPSTATE_IS_MPEG12_VIDEO|RTPSTATE_IS_MULTIPLEXED; |
9250 | 124 } else if (strcmp(subsession->codecName(), "H263") == 0 || |
22211 | 125 strcmp(subsession->codecName(), "H263-2000") == 0 || |
9250 | 126 strcmp(subsession->codecName(), "H263-1998") == 0) { |
127 bih->biCompression = sh_video->format | |
128 = mmioFOURCC('H','2','6','3'); | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
129 needVideoFrameRate(demuxer, subsession); |
19415 | 130 } else if (strcmp(subsession->codecName(), "H264") == 0) { |
131 bih->biCompression = sh_video->format | |
132 = mmioFOURCC('H','2','6','4'); | |
22852 | 133 unsigned int configLen = 0; |
134 unsigned char* configData | |
135 = parseH264ConfigStr(subsession->fmtp_spropparametersets(), configLen); | |
136 sh_video->bih = bih = insertVideoExtradata(bih, configData, configLen); | |
137 delete[] configData; | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26486
diff
changeset
|
138 #ifdef CONFIG_LIBAVCODEC |
24103
d44e23b469a3
Fix compilation of live555 support after FFmpegs r10173.
cehoyos
parents:
22852
diff
changeset
|
139 avcodec_register_all(); |
22852 | 140 h264parserctx = av_parser_init(CODEC_ID_H264); |
29451
6aca83f5ba73
Fix a crash when playing some H264 over rtsp streams: Do pass an
cehoyos
parents:
29448
diff
changeset
|
141 avcctx = avcodec_alloc_context(); |
22852 | 142 #endif |
19415 | 143 needVideoFrameRate(demuxer, subsession); |
9250 | 144 } else if (strcmp(subsession->codecName(), "H261") == 0) { |
145 bih->biCompression = sh_video->format | |
146 = mmioFOURCC('H','2','6','1'); | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
147 needVideoFrameRate(demuxer, subsession); |
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
148 } else if (strcmp(subsession->codecName(), "JPEG") == 0) { |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
149 bih->biCompression = sh_video->format |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
150 = mmioFOURCC('M','J','P','G'); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
151 needVideoFrameRate(demuxer, subsession); |
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
152 } else if (strcmp(subsession->codecName(), "MP4V-ES") == 0) { |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
153 bih->biCompression = sh_video->format |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
154 = mmioFOURCC('m','p','4','v'); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
155 // For the codec to work correctly, it may need a 'VOL Header' to be |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
156 // inserted at the front of the data stream. Construct this from the |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
157 // "config" MIME parameter, which was present (hopefully) in the |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
158 // session's SDP description: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
159 unsigned configLen; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
160 unsigned char* configData |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
161 = parseGeneralConfigStr(subsession->fmtp_config(), configLen); |
22278
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
162 sh_video->bih = bih = insertVideoExtradata(bih, configData, configLen); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
163 needVideoFrameRate(demuxer, subsession); |
9250 | 164 } else if (strcmp(subsession->codecName(), "X-QT") == 0 || |
165 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) { | |
166 // QuickTime generic RTP format, as described in | |
167 // http://developer.apple.com/quicktime/icefloe/dispatch026.html | |
168 | |
169 // We can't initialize this stream until we've received the first packet | |
170 // that has QuickTime "sdAtom" information in the header. So, keep | |
171 // reading packets until we get one: | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
172 unsigned char* packetData; unsigned packetDataLen; float pts; |
9250 | 173 QuickTimeGenericRTPSource* qtRTPSource |
174 = (QuickTimeGenericRTPSource*)(subsession->rtpSource()); | |
175 unsigned fourcc; | |
176 do { | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
177 if (!awaitRTPPacket(demuxer, demuxer->video, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
178 packetData, packetDataLen, pts)) { |
9250 | 179 return; |
180 } | |
181 } while (!parseQTState_video(qtRTPSource->qtState, fourcc)); | |
182 | |
183 bih->biCompression = sh_video->format = fourcc; | |
21871 | 184 bih->biWidth = qtRTPSource->qtState.width; |
185 bih->biHeight = qtRTPSource->qtState.height; | |
29435 | 186 if (qtRTPSource->qtState.sdAtomSize > 83) |
187 bih->biBitCount = qtRTPSource->qtState.sdAtom[83]; | |
21871 | 188 uint8_t *pos = (uint8_t*)qtRTPSource->qtState.sdAtom + 86; |
189 uint8_t *endpos = (uint8_t*)qtRTPSource->qtState.sdAtom | |
190 + qtRTPSource->qtState.sdAtomSize; | |
191 while (pos+8 < endpos) { | |
192 unsigned atomLength = pos[0]<<24 | pos[1]<<16 | pos[2]<<8 | pos[3]; | |
193 if (atomLength == 0 || atomLength > endpos-pos) break; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
194 if ((!memcmp(pos+4, "avcC", 4) && fourcc==mmioFOURCC('a','v','c','1') || |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
195 !memcmp(pos+4, "esds", 4) || |
22809
09f97d0161ba
Handle X-QT extradata in a slightly more correct way
cehoyos
parents:
22756
diff
changeset
|
196 !memcmp(pos+4, "SMI ", 4) && fourcc==mmioFOURCC('S','V','Q','3')) && |
22278
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
197 atomLength > 8) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
198 sh_video->bih = bih = |
22278
ac8ac9e3761d
insert extradata in sh_video->bih+1 instead of pushing it to demuxer->video as separate packet; patch by C.E.Hoyos
nicodvb
parents:
22235
diff
changeset
|
199 insertVideoExtradata(bih, pos+8, atomLength-8); |
21871 | 200 break; |
201 } | |
202 pos += atomLength; | |
203 } | |
22756
3d6a64f3d28f
Every X-QT stream needs video frame rate (not just avc, mpeg4 and svq3)
cehoyos
parents:
22463
diff
changeset
|
204 needVideoFrameRate(demuxer, subsession); |
9250 | 205 } else { |
206 fprintf(stderr, | |
207 "Unknown MPlayer format code for MIME type \"video/%s\"\n", | |
208 subsession->codecName()); | |
209 } | |
210 } | |
211 | |
212 void rtpCodecInitialize_audio(demuxer_t* demuxer, | |
213 MediaSubsession* subsession, | |
214 unsigned& flags) { | |
215 flags = 0; | |
216 // Create a dummy audio stream header | |
217 // to make the main MPlayer code happy: | |
218 sh_audio_t* sh_audio = new_sh_audio(demuxer,0); | |
219 WAVEFORMATEX* wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)); | |
220 sh_audio->wf = wf; | |
221 demux_stream_t* d_audio = demuxer->audio; | |
222 d_audio->sh = sh_audio; sh_audio->ds = d_audio; | |
27417 | 223 d_audio->id = sh_audio->aid; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
224 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
225 wf->nChannels = subsession->numChannels(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
226 |
9250 | 227 // Map known audio MIME types to the WAVEFORMATEX parameters |
228 // that this program uses. (Note that not all types need all | |
229 // of the parameters to be set.) | |
230 wf->nSamplesPerSec | |
231 = subsession->rtpSource()->timestampFrequency(); // by default | |
232 if (strcmp(subsession->codecName(), "MPA") == 0 || | |
233 strcmp(subsession->codecName(), "MPA-ROBUST") == 0 || | |
234 strcmp(subsession->codecName(), "X-MP3-DRAFT-00") == 0) { | |
235 wf->wFormatTag = sh_audio->format = 0x55; | |
236 // Note: 0x55 is for layer III, but should work for I,II also | |
237 wf->nSamplesPerSec = 0; // sample rate is deduced from the data | |
238 } else if (strcmp(subsession->codecName(), "AC3") == 0) { | |
239 wf->wFormatTag = sh_audio->format = 0x2000; | |
240 wf->nSamplesPerSec = 0; // sample rate is deduced from the data | |
10478
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
241 } else if (strcmp(subsession->codecName(), "L16") == 0) { |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
242 wf->wFormatTag = sh_audio->format = 0x736f7774; // "twos" |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
243 wf->nBlockAlign = 1; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
244 wf->wBitsPerSample = 16; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
245 wf->cbSize = 0; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
246 } else if (strcmp(subsession->codecName(), "L8") == 0) { |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
247 wf->wFormatTag = sh_audio->format = 0x20776172; // "raw " |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
248 wf->nBlockAlign = 1; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
249 wf->wBitsPerSample = 8; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
250 wf->cbSize = 0; |
9250 | 251 } else if (strcmp(subsession->codecName(), "PCMU") == 0) { |
252 wf->wFormatTag = sh_audio->format = 0x7; | |
253 wf->nAvgBytesPerSec = 8000; | |
254 wf->nBlockAlign = 1; | |
255 wf->wBitsPerSample = 8; | |
256 wf->cbSize = 0; | |
257 } else if (strcmp(subsession->codecName(), "PCMA") == 0) { | |
258 wf->wFormatTag = sh_audio->format = 0x6; | |
259 wf->nAvgBytesPerSec = 8000; | |
260 wf->nBlockAlign = 1; | |
261 wf->wBitsPerSample = 8; | |
262 wf->cbSize = 0; | |
22463
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22354
diff
changeset
|
263 } else if (strcmp(subsession->codecName(), "AMR") == 0) { |
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22354
diff
changeset
|
264 wf->wFormatTag = sh_audio->format = mmioFOURCC('s','a','m','r'); |
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22354
diff
changeset
|
265 } else if (strcmp(subsession->codecName(), "AMR-WB") == 0) { |
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22354
diff
changeset
|
266 wf->wFormatTag = sh_audio->format = mmioFOURCC('s','a','w','b'); |
9250 | 267 } else if (strcmp(subsession->codecName(), "GSM") == 0) { |
268 wf->wFormatTag = sh_audio->format = mmioFOURCC('a','g','s','m'); | |
269 wf->nAvgBytesPerSec = 1650; | |
270 wf->nBlockAlign = 33; | |
271 wf->wBitsPerSample = 16; | |
272 wf->cbSize = 0; | |
273 } else if (strcmp(subsession->codecName(), "QCELP") == 0) { | |
274 wf->wFormatTag = sh_audio->format = mmioFOURCC('Q','c','l','p'); | |
275 wf->nAvgBytesPerSec = 1750; | |
276 wf->nBlockAlign = 35; | |
277 wf->wBitsPerSample = 16; | |
278 wf->cbSize = 0; | |
279 } else if (strcmp(subsession->codecName(), "MP4A-LATM") == 0) { | |
280 wf->wFormatTag = sh_audio->format = mmioFOURCC('m','p','4','a'); | |
281 // For the codec to work correctly, it needs "AudioSpecificConfig" | |
282 // data, which is parsed from the "StreamMuxConfig" string that | |
283 // was present (hopefully) in the SDP description: | |
284 unsigned codecdata_len; | |
285 sh_audio->codecdata | |
286 = parseStreamMuxConfigStr(subsession->fmtp_config(), | |
287 codecdata_len); | |
288 sh_audio->codecdata_len = codecdata_len; | |
22235
583926af08ac
omit length field of AAC-LATM audio streams; fixes decoding by faad. Patch by Carl Eugen Hoyos (cehoyos ag or at)
nicodvb
parents:
22211
diff
changeset
|
289 //faad doesn't understand LATM's data length field, so omit it |
583926af08ac
omit length field of AAC-LATM audio streams; fixes decoding by faad. Patch by Carl Eugen Hoyos (cehoyos ag or at)
nicodvb
parents:
22211
diff
changeset
|
290 ((MPEG4LATMAudioRTPSource*)subsession->rtpSource())->omitLATMDataLengthField(); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
291 } else if (strcmp(subsession->codecName(), "MPEG4-GENERIC") == 0) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
292 wf->wFormatTag = sh_audio->format = mmioFOURCC('m','p','4','a'); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
293 // For the codec to work correctly, it needs "AudioSpecificConfig" |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
294 // data, which was present (hopefully) in the SDP description: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
295 unsigned codecdata_len; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
296 sh_audio->codecdata |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
297 = parseGeneralConfigStr(subsession->fmtp_config(), |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
298 codecdata_len); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
299 sh_audio->codecdata_len = codecdata_len; |
9250 | 300 } else if (strcmp(subsession->codecName(), "X-QT") == 0 || |
301 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) { | |
302 // QuickTime generic RTP format, as described in | |
303 // http://developer.apple.com/quicktime/icefloe/dispatch026.html | |
304 | |
305 // We can't initialize this stream until we've received the first packet | |
306 // that has QuickTime "sdAtom" information in the header. So, keep | |
307 // reading packets until we get one: | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
308 unsigned char* packetData; unsigned packetDataLen; float pts; |
9250 | 309 QuickTimeGenericRTPSource* qtRTPSource |
310 = (QuickTimeGenericRTPSource*)(subsession->rtpSource()); | |
311 unsigned fourcc, numChannels; | |
312 do { | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
313 if (!awaitRTPPacket(demuxer, demuxer->audio, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
314 packetData, packetDataLen, pts)) { |
9250 | 315 return; |
316 } | |
317 } while (!parseQTState_audio(qtRTPSource->qtState, fourcc, numChannels)); | |
318 | |
319 wf->wFormatTag = sh_audio->format = fourcc; | |
320 wf->nChannels = numChannels; | |
22336
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
321 |
29448
80c6dd85f7f8
Parse BitsPerSample and SamplesPerSec when playing PCM in X-QT over
cehoyos
parents:
29435
diff
changeset
|
322 if (qtRTPSource->qtState.sdAtomSize > 33) { |
80c6dd85f7f8
Parse BitsPerSample and SamplesPerSec when playing PCM in X-QT over
cehoyos
parents:
29435
diff
changeset
|
323 wf->wBitsPerSample = qtRTPSource->qtState.sdAtom[27]; |
80c6dd85f7f8
Parse BitsPerSample and SamplesPerSec when playing PCM in X-QT over
cehoyos
parents:
29435
diff
changeset
|
324 wf->nSamplesPerSec = qtRTPSource->qtState.sdAtom[32]<<8|qtRTPSource->qtState.sdAtom[33]; |
80c6dd85f7f8
Parse BitsPerSample and SamplesPerSec when playing PCM in X-QT over
cehoyos
parents:
29435
diff
changeset
|
325 } |
22336
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
326 uint8_t *pos = (uint8_t*)qtRTPSource->qtState.sdAtom + 52; |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
327 uint8_t *endpos = (uint8_t*)qtRTPSource->qtState.sdAtom |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
328 + qtRTPSource->qtState.sdAtomSize; |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
329 while (pos+8 < endpos) { |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
330 unsigned atomLength = pos[0]<<24 | pos[1]<<16 | pos[2]<<8 | pos[3]; |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
331 if (atomLength == 0 || atomLength > endpos-pos) break; |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
332 if (!memcmp(pos+4, "wave", 4) && fourcc==mmioFOURCC('Q','D','M','2') && |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
333 atomLength > 8 && |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
334 atomLength <= INT_MAX) { |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
335 sh_audio->codecdata = (unsigned char*) malloc(atomLength-8); |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
336 if (sh_audio->codecdata) { |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
337 memcpy(sh_audio->codecdata, pos+8, atomLength-8); |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
338 sh_audio->codecdata_len = atomLength-8; |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
339 } |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
340 break; |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
341 } |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
342 pos += atomLength; |
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
343 } |
9250 | 344 } else { |
345 fprintf(stderr, | |
346 "Unknown MPlayer format code for MIME type \"audio/%s\"\n", | |
347 subsession->codecName()); | |
348 } | |
349 } | |
350 | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
351 static void needVideoFrameRate(demuxer_t* demuxer, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
352 MediaSubsession* subsession) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
353 // For some codecs, MPlayer's decoding software can't (or refuses to :-) |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
354 // figure out the frame rate by itself, so (unless the user specifies |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
355 // it manually, using "-fps") we figure it out ourselves here, using the |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
356 // presentation timestamps in successive packets, |
25965 | 357 extern double force_fps; if (force_fps != 0.0) return; // user used "-fps" |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
358 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
359 demux_stream_t* d_video = demuxer->video; |
9910 | 360 sh_video_t* sh_video = (sh_video_t*)(d_video->sh); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
361 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
362 // If we already know the subsession's video frame rate, use it: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
363 int fps = (int)(subsession->videoFPS()); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
364 if (fps != 0) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
365 sh_video->fps = fps; |
22354
b465e5be1a53
assign missing frametime as 1.0/fps; patch by Carl Eigen Hoyos
nicodvb
parents:
22336
diff
changeset
|
366 sh_video->frametime = 1.0f/fps; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
367 return; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
368 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
369 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
370 // Keep looking at incoming frames until we see two with different, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
371 // non-zero "pts" timestamps: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
372 unsigned char* packetData; unsigned packetDataLen; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
373 float lastPTS = 0.0, curPTS; |
11397
d0db11b74e82
Increased the threshold for how many incoming frames to look at while guessing
rsf
parents:
10478
diff
changeset
|
374 unsigned const maxNumFramesToWaitFor = 300; |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
375 int lastfps = 0; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
376 for (unsigned i = 0; i < maxNumFramesToWaitFor; ++i) { |
9910 | 377 if (!awaitRTPPacket(demuxer, d_video, packetData, packetDataLen, curPTS)) { |
378 break; | |
379 } | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
380 |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
381 if (curPTS != lastPTS && lastPTS != 0.0) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
382 // Use the difference between these two "pts"s to guess the frame rate. |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
383 // (should really check that there were no missing frames inbetween)##### |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
384 // Guess the frame rate as an integer. If it's not, use "-fps" instead. |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
385 fps = (int)(1/fabs(curPTS-lastPTS) + 0.5); // rounding |
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
386 if (fps == lastfps) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
387 fprintf(stderr, "demux_rtp: Guessed the video frame rate as %d frames-per-second.\n\t(If this is wrong, use the \"-fps <frame-rate>\" option instead.)\n", fps); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
388 sh_video->fps = fps; |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
389 sh_video->frametime=1.0f/fps; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
390 return; |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
391 } |
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
392 if (fps>lastfps) lastfps = fps; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
393 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
394 lastPTS = curPTS; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
395 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
396 fprintf(stderr, "demux_rtp: Failed to guess the video frame rate\n"); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
397 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
398 |
9250 | 399 static Boolean |
400 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState, | |
401 unsigned& fourcc) { | |
402 // qtState's "sdAtom" field is supposed to contain a QuickTime video | |
403 // 'sample description' atom. This atom's name is the 'fourcc' that we want: | |
404 char const* sdAtom = qtState.sdAtom; | |
405 if (sdAtom == NULL || qtState.sdAtomSize < 2*4) return False; | |
406 | |
407 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order | |
408 return True; | |
409 } | |
410 | |
411 static Boolean | |
412 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState, | |
413 unsigned& fourcc, unsigned& numChannels) { | |
414 // qtState's "sdAtom" field is supposed to contain a QuickTime audio | |
415 // 'sample description' atom. This atom's name is the 'fourcc' that we want. | |
416 // Also, the top half of the 5th word following the atom name should | |
417 // contain the number of channels ("numChannels") that we want: | |
418 char const* sdAtom = qtState.sdAtom; | |
419 if (sdAtom == NULL || qtState.sdAtomSize < 7*4) return False; | |
420 | |
421 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order | |
422 | |
423 char const* word7Ptr = &sdAtom[6*4]; | |
424 numChannels = (word7Ptr[0]<<8)|(word7Ptr[1]); | |
425 return True; | |
426 } |