Mercurial > mplayer.hg
annotate libmpdemux/demux_rtp_codec.cpp @ 29238:d643e4643313
Add standard license header to all files in libmpdemux.
| author | diego |
|---|---|
| date | Fri, 08 May 2009 21:51:13 +0000 |
| parents | b7548ba58efe |
| children | 0f1b5b68af32 |
| 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; |
| 32 #endif | |
| 33 | |
| 34 // Copied from vlc | |
| 35 static unsigned char* parseH264ConfigStr( char const* configStr, | |
| 36 unsigned int& configSize ) | |
| 37 { | |
| 38 | |
| 39 char *dup, *psz; | |
| 40 int i, i_records = 1; | |
| 41 | |
| 42 if( configSize ) | |
| 43 configSize = 0; | |
| 44 if( configStr == NULL || *configStr == '\0' ) | |
| 45 return NULL; | |
| 46 psz = dup = strdup( configStr ); | |
| 47 | |
| 48 /* Count the number of comma's */ | |
| 49 for( psz = dup; *psz != '\0'; ++psz ) | |
| 50 { | |
| 51 if( *psz == ',') | |
| 52 { | |
| 53 ++i_records; | |
| 54 *psz = '\0'; | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 unsigned char *cfg = new unsigned char[5 * strlen(dup)]; | |
| 59 psz = dup; | |
| 60 for( i = 0; i < i_records; i++ ) | |
| 61 { | |
| 62 | |
| 63 cfg[configSize++] = 0x00; | |
| 64 cfg[configSize++] = 0x00; | |
| 65 cfg[configSize++] = 0x01; | |
| 66 configSize += av_base64_decode( (uint8_t*)&cfg[configSize], | |
| 67 psz, | |
| 68 5 * strlen(dup) - 3 ); | |
| 69 | |
| 70 psz += strlen(psz)+1; | |
| 71 } | |
| 72 if( dup ) free( dup ); | |
| 73 | |
| 74 return cfg; | |
| 9250 | 75 } |
| 76 | |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
77 static void |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
78 needVideoFrameRate(demuxer_t* demuxer, MediaSubsession* subsession); // forward |
| 9250 | 79 static Boolean |
| 80 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState, | |
| 81 unsigned& fourcc); // forward | |
| 82 static Boolean | |
| 83 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState, | |
| 84 unsigned& fourcc, unsigned& numChannels); // forward | |
| 85 | |
|
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
|
86 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
|
87 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
|
88 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
|
89 { |
|
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 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 } |
|
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 |
| 9250 | 101 void rtpCodecInitialize_video(demuxer_t* demuxer, |
| 102 MediaSubsession* subsession, | |
| 103 unsigned& flags) { | |
| 104 flags = 0; | |
| 105 // Create a dummy video stream header | |
| 106 // to make the main MPlayer code happy: | |
| 107 sh_video_t* sh_video = new_sh_video(demuxer,0); | |
| 108 BITMAPINFOHEADER* bih | |
| 109 = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER)); | |
| 110 bih->biSize = sizeof(BITMAPINFOHEADER); | |
| 111 sh_video->bih = bih; | |
| 112 demux_stream_t* d_video = demuxer->video; | |
| 113 d_video->sh = sh_video; sh_video->ds = d_video; | |
| 114 | |
| 115 // Map known video MIME types to the BITMAPINFOHEADER parameters | |
| 116 // that this program uses. (Note that not all types need all | |
| 117 // 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
|
118 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
|
119 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
|
120 } 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
|
121 strcmp(subsession->codecName(), "MP2T") == 0) { |
|
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
122 flags |= RTPSTATE_IS_MPEG12_VIDEO|RTPSTATE_IS_MULTIPLEXED; |
| 9250 | 123 } else if (strcmp(subsession->codecName(), "H263") == 0 || |
| 22211 | 124 strcmp(subsession->codecName(), "H263-2000") == 0 || |
| 9250 | 125 strcmp(subsession->codecName(), "H263-1998") == 0) { |
| 126 bih->biCompression = sh_video->format | |
| 127 = mmioFOURCC('H','2','6','3'); | |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
128 needVideoFrameRate(demuxer, subsession); |
| 19415 | 129 } else if (strcmp(subsession->codecName(), "H264") == 0) { |
| 130 bih->biCompression = sh_video->format | |
| 131 = mmioFOURCC('H','2','6','4'); | |
| 22852 | 132 unsigned int configLen = 0; |
| 133 unsigned char* configData | |
| 134 = parseH264ConfigStr(subsession->fmtp_spropparametersets(), configLen); | |
| 135 sh_video->bih = bih = insertVideoExtradata(bih, configData, configLen); | |
| 136 delete[] configData; | |
|
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26486
diff
changeset
|
137 #ifdef CONFIG_LIBAVCODEC |
|
24103
d44e23b469a3
Fix compilation of live555 support after FFmpegs r10173.
cehoyos
parents:
22852
diff
changeset
|
138 avcodec_register_all(); |
| 22852 | 139 h264parserctx = av_parser_init(CODEC_ID_H264); |
| 140 #endif | |
| 19415 | 141 needVideoFrameRate(demuxer, subsession); |
| 9250 | 142 } else if (strcmp(subsession->codecName(), "H261") == 0) { |
| 143 bih->biCompression = sh_video->format | |
| 144 = mmioFOURCC('H','2','6','1'); | |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
145 needVideoFrameRate(demuxer, subsession); |
|
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
146 } 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
|
147 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
|
148 = mmioFOURCC('M','J','P','G'); |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
149 needVideoFrameRate(demuxer, subsession); |
|
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
150 } 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
|
151 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
|
152 = mmioFOURCC('m','p','4','v'); |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
153 // 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
|
154 // 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
|
155 // "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
|
156 // session's SDP description: |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
157 unsigned configLen; |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
158 unsigned char* configData |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
159 = 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
|
160 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
|
161 needVideoFrameRate(demuxer, subsession); |
| 9250 | 162 } else if (strcmp(subsession->codecName(), "X-QT") == 0 || |
| 163 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) { | |
| 164 // QuickTime generic RTP format, as described in | |
| 165 // http://developer.apple.com/quicktime/icefloe/dispatch026.html | |
| 166 | |
| 167 // We can't initialize this stream until we've received the first packet | |
| 168 // that has QuickTime "sdAtom" information in the header. So, keep | |
| 169 // 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
|
170 unsigned char* packetData; unsigned packetDataLen; float pts; |
| 9250 | 171 QuickTimeGenericRTPSource* qtRTPSource |
| 172 = (QuickTimeGenericRTPSource*)(subsession->rtpSource()); | |
| 173 unsigned fourcc; | |
| 174 do { | |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
175 if (!awaitRTPPacket(demuxer, demuxer->video, |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
176 packetData, packetDataLen, pts)) { |
| 9250 | 177 return; |
| 178 } | |
| 179 } while (!parseQTState_video(qtRTPSource->qtState, fourcc)); | |
| 180 | |
| 181 bih->biCompression = sh_video->format = fourcc; | |
| 21871 | 182 bih->biWidth = qtRTPSource->qtState.width; |
| 183 bih->biHeight = qtRTPSource->qtState.height; | |
| 184 uint8_t *pos = (uint8_t*)qtRTPSource->qtState.sdAtom + 86; | |
| 185 uint8_t *endpos = (uint8_t*)qtRTPSource->qtState.sdAtom | |
| 186 + qtRTPSource->qtState.sdAtomSize; | |
| 187 while (pos+8 < endpos) { | |
| 188 unsigned atomLength = pos[0]<<24 | pos[1]<<16 | pos[2]<<8 | pos[3]; | |
| 189 if (atomLength == 0 || atomLength > endpos-pos) break; | |
|
22809
09f97d0161ba
Handle X-QT extradata in a slightly more correct way
cehoyos
parents:
22756
diff
changeset
|
190 if ((!memcmp(pos+4, "avcC", 4) && fourcc==mmioFOURCC('a','v','c','1') || |
|
22154
1dc228327c55
when the video codec is mpeg4video copy the content of the esds in extradata; patch by ceyes ag or at
nicodvb
parents:
22112
diff
changeset
|
191 !memcmp(pos+4, "esds", 4) || |
|
22809
09f97d0161ba
Handle X-QT extradata in a slightly more correct way
cehoyos
parents:
22756
diff
changeset
|
192 !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
|
193 atomLength > 8) { |
|
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
|
194 sh_video->bih = 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
|
195 insertVideoExtradata(bih, pos+8, atomLength-8); |
| 21871 | 196 break; |
| 197 } | |
| 198 pos += atomLength; | |
| 199 } | |
|
22756
3d6a64f3d28f
Every X-QT stream needs video frame rate (not just avc, mpeg4 and svq3)
cehoyos
parents:
22463
diff
changeset
|
200 needVideoFrameRate(demuxer, subsession); |
| 9250 | 201 } else { |
| 202 fprintf(stderr, | |
| 203 "Unknown MPlayer format code for MIME type \"video/%s\"\n", | |
| 204 subsession->codecName()); | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 void rtpCodecInitialize_audio(demuxer_t* demuxer, | |
| 209 MediaSubsession* subsession, | |
| 210 unsigned& flags) { | |
| 211 flags = 0; | |
| 212 // Create a dummy audio stream header | |
| 213 // to make the main MPlayer code happy: | |
| 214 sh_audio_t* sh_audio = new_sh_audio(demuxer,0); | |
| 215 WAVEFORMATEX* wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)); | |
| 216 sh_audio->wf = wf; | |
| 217 demux_stream_t* d_audio = demuxer->audio; | |
| 218 d_audio->sh = sh_audio; sh_audio->ds = d_audio; | |
| 27417 | 219 d_audio->id = sh_audio->aid; |
| 9250 | 220 |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
221 wf->nChannels = subsession->numChannels(); |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
222 |
| 9250 | 223 // Map known audio MIME types to the WAVEFORMATEX parameters |
| 224 // that this program uses. (Note that not all types need all | |
| 225 // of the parameters to be set.) | |
| 226 wf->nSamplesPerSec | |
| 227 = subsession->rtpSource()->timestampFrequency(); // by default | |
| 228 if (strcmp(subsession->codecName(), "MPA") == 0 || | |
| 229 strcmp(subsession->codecName(), "MPA-ROBUST") == 0 || | |
| 230 strcmp(subsession->codecName(), "X-MP3-DRAFT-00") == 0) { | |
| 231 wf->wFormatTag = sh_audio->format = 0x55; | |
| 232 // Note: 0x55 is for layer III, but should work for I,II also | |
| 233 wf->nSamplesPerSec = 0; // sample rate is deduced from the data | |
| 234 } else if (strcmp(subsession->codecName(), "AC3") == 0) { | |
| 235 wf->wFormatTag = sh_audio->format = 0x2000; | |
| 236 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
|
237 } 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
|
238 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
|
239 wf->nBlockAlign = 1; |
|
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
240 wf->wBitsPerSample = 16; |
|
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
241 wf->cbSize = 0; |
|
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
242 } 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
|
243 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
|
244 wf->nBlockAlign = 1; |
|
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
245 wf->wBitsPerSample = 8; |
|
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
246 wf->cbSize = 0; |
| 9250 | 247 } else if (strcmp(subsession->codecName(), "PCMU") == 0) { |
| 248 wf->wFormatTag = sh_audio->format = 0x7; | |
| 249 wf->nAvgBytesPerSec = 8000; | |
| 250 wf->nBlockAlign = 1; | |
| 251 wf->wBitsPerSample = 8; | |
| 252 wf->cbSize = 0; | |
| 253 } else if (strcmp(subsession->codecName(), "PCMA") == 0) { | |
| 254 wf->wFormatTag = sh_audio->format = 0x6; | |
| 255 wf->nAvgBytesPerSec = 8000; | |
| 256 wf->nBlockAlign = 1; | |
| 257 wf->wBitsPerSample = 8; | |
| 258 wf->cbSize = 0; | |
|
22463
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22354
diff
changeset
|
259 } 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
|
260 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
|
261 } 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
|
262 wf->wFormatTag = sh_audio->format = mmioFOURCC('s','a','w','b'); |
| 9250 | 263 } else if (strcmp(subsession->codecName(), "GSM") == 0) { |
| 264 wf->wFormatTag = sh_audio->format = mmioFOURCC('a','g','s','m'); | |
| 265 wf->nAvgBytesPerSec = 1650; | |
| 266 wf->nBlockAlign = 33; | |
| 267 wf->wBitsPerSample = 16; | |
| 268 wf->cbSize = 0; | |
| 269 } else if (strcmp(subsession->codecName(), "QCELP") == 0) { | |
| 270 wf->wFormatTag = sh_audio->format = mmioFOURCC('Q','c','l','p'); | |
| 271 wf->nAvgBytesPerSec = 1750; | |
| 272 wf->nBlockAlign = 35; | |
| 273 wf->wBitsPerSample = 16; | |
| 274 wf->cbSize = 0; | |
| 275 } else if (strcmp(subsession->codecName(), "MP4A-LATM") == 0) { | |
| 276 wf->wFormatTag = sh_audio->format = mmioFOURCC('m','p','4','a'); | |
| 277 // For the codec to work correctly, it needs "AudioSpecificConfig" | |
| 278 // data, which is parsed from the "StreamMuxConfig" string that | |
| 279 // was present (hopefully) in the SDP description: | |
| 280 unsigned codecdata_len; | |
| 281 sh_audio->codecdata | |
| 282 = parseStreamMuxConfigStr(subsession->fmtp_config(), | |
| 283 codecdata_len); | |
| 284 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
|
285 //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
|
286 ((MPEG4LATMAudioRTPSource*)subsession->rtpSource())->omitLATMDataLengthField(); |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
287 } 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
|
288 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
|
289 // 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
|
290 // 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
|
291 unsigned codecdata_len; |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
292 sh_audio->codecdata |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
293 = parseGeneralConfigStr(subsession->fmtp_config(), |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
294 codecdata_len); |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
295 sh_audio->codecdata_len = codecdata_len; |
| 9250 | 296 } else if (strcmp(subsession->codecName(), "X-QT") == 0 || |
| 297 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) { | |
| 298 // QuickTime generic RTP format, as described in | |
| 299 // http://developer.apple.com/quicktime/icefloe/dispatch026.html | |
| 300 | |
| 301 // We can't initialize this stream until we've received the first packet | |
| 302 // that has QuickTime "sdAtom" information in the header. So, keep | |
| 303 // 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
|
304 unsigned char* packetData; unsigned packetDataLen; float pts; |
| 9250 | 305 QuickTimeGenericRTPSource* qtRTPSource |
| 306 = (QuickTimeGenericRTPSource*)(subsession->rtpSource()); | |
| 307 unsigned fourcc, numChannels; | |
| 308 do { | |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
309 if (!awaitRTPPacket(demuxer, demuxer->audio, |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
310 packetData, packetDataLen, pts)) { |
| 9250 | 311 return; |
| 312 } | |
| 313 } while (!parseQTState_audio(qtRTPSource->qtState, fourcc, numChannels)); | |
| 314 | |
| 315 wf->wFormatTag = sh_audio->format = fourcc; | |
| 316 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
|
317 |
|
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
318 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
|
319 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
|
320 + 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 atomLength > 8 && |
|
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 } |
|
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
332 break; |
|
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
333 } |
|
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
334 pos += atomLength; |
|
760c74c078ce
copy the content of QDM2 atom as extradata for ffqdm2 playback; patch by Carl Eugen Hoyos
nicodvb
parents:
22278
diff
changeset
|
335 } |
| 9250 | 336 } else { |
| 337 fprintf(stderr, | |
| 338 "Unknown MPlayer format code for MIME type \"audio/%s\"\n", | |
| 339 subsession->codecName()); | |
| 340 } | |
| 341 } | |
| 342 | |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
343 static void needVideoFrameRate(demuxer_t* demuxer, |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
344 MediaSubsession* subsession) { |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
345 // 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
|
346 // 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
|
347 // 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
|
348 // presentation timestamps in successive packets, |
| 25965 | 349 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
|
350 |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
351 demux_stream_t* d_video = demuxer->video; |
| 9910 | 352 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
|
353 |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
354 // 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
|
355 int fps = (int)(subsession->videoFPS()); |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
356 if (fps != 0) { |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
357 sh_video->fps = fps; |
|
22354
b465e5be1a53
assign missing frametime as 1.0/fps; patch by Carl Eigen Hoyos
nicodvb
parents:
22336
diff
changeset
|
358 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
|
359 return; |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
360 } |
|
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 // 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
|
363 // non-zero "pts" timestamps: |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
364 unsigned char* packetData; unsigned packetDataLen; |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
365 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
|
366 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
|
367 int lastfps = 0; |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
368 for (unsigned i = 0; i < maxNumFramesToWaitFor; ++i) { |
| 9910 | 369 if (!awaitRTPPacket(demuxer, d_video, packetData, packetDataLen, curPTS)) { |
| 370 break; | |
| 371 } | |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
372 |
|
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
373 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
|
374 // 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
|
375 // (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
|
376 // 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
|
377 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
|
378 if (fps == lastfps) { |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 return; |
|
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
383 } |
|
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
384 if (fps>lastfps) lastfps = fps; |
|
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
385 } |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
386 lastPTS = curPTS; |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
387 } |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
388 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
|
389 } |
|
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
390 |
| 9250 | 391 static Boolean |
| 392 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState, | |
| 393 unsigned& fourcc) { | |
| 394 // qtState's "sdAtom" field is supposed to contain a QuickTime video | |
| 395 // 'sample description' atom. This atom's name is the 'fourcc' that we want: | |
| 396 char const* sdAtom = qtState.sdAtom; | |
| 397 if (sdAtom == NULL || qtState.sdAtomSize < 2*4) return False; | |
| 398 | |
| 399 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order | |
| 400 return True; | |
| 401 } | |
| 402 | |
| 403 static Boolean | |
| 404 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState, | |
| 405 unsigned& fourcc, unsigned& numChannels) { | |
| 406 // qtState's "sdAtom" field is supposed to contain a QuickTime audio | |
| 407 // 'sample description' atom. This atom's name is the 'fourcc' that we want. | |
| 408 // Also, the top half of the 5th word following the atom name should | |
| 409 // contain the number of channels ("numChannels") that we want: | |
| 410 char const* sdAtom = qtState.sdAtom; | |
| 411 if (sdAtom == NULL || qtState.sdAtomSize < 7*4) return False; | |
| 412 | |
| 413 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order | |
| 414 | |
| 415 char const* word7Ptr = &sdAtom[6*4]; | |
| 416 numChannels = (word7Ptr[0]<<8)|(word7Ptr[1]); | |
| 417 return True; | |
| 418 } |
