Mercurial > mplayer.hg
annotate libmpdemux/demux_rtp_codec.cpp @ 22235:583926af08ac
omit length field of AAC-LATM audio streams; fixes decoding by faad. Patch by Carl Eugen Hoyos (cehoyos ag or at)
author | nicodvb |
---|---|
date | Sat, 17 Feb 2007 21:45:16 +0000 |
parents | 7c9d838fc788 |
children | ac8ac9e3761d |
rev | line source |
---|---|
9250 | 1 ////////// Codec-specific routines used to interface between "MPlayer" |
16572
56a5f69e9b35
"LIVE.COM Streaming Media" is now called "LIVE555 Streaming Media".
rsf
parents:
11398
diff
changeset
|
2 ////////// and the "LIVE555 Streaming Media" libraries: |
9250 | 3 |
4 #include "demux_rtp_internal.h" | |
5 extern "C" { | |
21911
e86bb13ec44b
demux_rtp_codec.cpp:100: `INT_MAX' undeclared (first use this function)
diego
parents:
21871
diff
changeset
|
6 #include <limits.h> |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
7 #include <math.h> |
9250 | 8 #include "stheader.h" |
9 } | |
10 | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
11 static void |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
12 needVideoFrameRate(demuxer_t* demuxer, MediaSubsession* subsession); // forward |
9250 | 13 static Boolean |
14 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState, | |
15 unsigned& fourcc); // forward | |
16 static Boolean | |
17 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState, | |
18 unsigned& fourcc, unsigned& numChannels); // forward | |
19 | |
20 void rtpCodecInitialize_video(demuxer_t* demuxer, | |
21 MediaSubsession* subsession, | |
22 unsigned& flags) { | |
23 flags = 0; | |
24 // Create a dummy video stream header | |
25 // to make the main MPlayer code happy: | |
26 sh_video_t* sh_video = new_sh_video(demuxer,0); | |
27 BITMAPINFOHEADER* bih | |
28 = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER)); | |
29 bih->biSize = sizeof(BITMAPINFOHEADER); | |
30 sh_video->bih = bih; | |
31 demux_stream_t* d_video = demuxer->video; | |
32 d_video->sh = sh_video; sh_video->ds = d_video; | |
33 | |
34 // Map known video MIME types to the BITMAPINFOHEADER parameters | |
35 // that this program uses. (Note that not all types need all | |
36 // 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
|
37 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
|
38 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
|
39 } 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
|
40 strcmp(subsession->codecName(), "MP2T") == 0) { |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
41 flags |= RTPSTATE_IS_MPEG12_VIDEO|RTPSTATE_IS_MULTIPLEXED; |
9250 | 42 } else if (strcmp(subsession->codecName(), "H263") == 0 || |
22211 | 43 strcmp(subsession->codecName(), "H263-2000") == 0 || |
9250 | 44 strcmp(subsession->codecName(), "H263-1998") == 0) { |
45 bih->biCompression = sh_video->format | |
46 = mmioFOURCC('H','2','6','3'); | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
47 needVideoFrameRate(demuxer, subsession); |
19415 | 48 } else if (strcmp(subsession->codecName(), "H264") == 0) { |
49 bih->biCompression = sh_video->format | |
50 = mmioFOURCC('H','2','6','4'); | |
51 needVideoFrameRate(demuxer, subsession); | |
9250 | 52 } else if (strcmp(subsession->codecName(), "H261") == 0) { |
53 bih->biCompression = sh_video->format | |
54 = mmioFOURCC('H','2','6','1'); | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
55 needVideoFrameRate(demuxer, subsession); |
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
56 } 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
|
57 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
|
58 = mmioFOURCC('M','J','P','G'); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
59 needVideoFrameRate(demuxer, subsession); |
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
60 } 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
|
61 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
|
62 = mmioFOURCC('m','p','4','v'); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
63 // 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
|
64 // 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
|
65 // "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
|
66 // session's SDP description: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
67 unsigned configLen; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
68 unsigned char* configData |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
69 = parseGeneralConfigStr(subsession->fmtp_config(), configLen); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
70 insertRTPData(demuxer, demuxer->video, configData, configLen); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
71 needVideoFrameRate(demuxer, subsession); |
9250 | 72 } else if (strcmp(subsession->codecName(), "X-QT") == 0 || |
73 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) { | |
74 // QuickTime generic RTP format, as described in | |
75 // http://developer.apple.com/quicktime/icefloe/dispatch026.html | |
76 | |
77 // We can't initialize this stream until we've received the first packet | |
78 // that has QuickTime "sdAtom" information in the header. So, keep | |
79 // 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
|
80 unsigned char* packetData; unsigned packetDataLen; float pts; |
9250 | 81 QuickTimeGenericRTPSource* qtRTPSource |
82 = (QuickTimeGenericRTPSource*)(subsession->rtpSource()); | |
83 unsigned fourcc; | |
84 do { | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
85 if (!awaitRTPPacket(demuxer, demuxer->video, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
86 packetData, packetDataLen, pts)) { |
9250 | 87 return; |
88 } | |
89 } while (!parseQTState_video(qtRTPSource->qtState, fourcc)); | |
90 | |
91 bih->biCompression = sh_video->format = fourcc; | |
21871 | 92 bih->biWidth = qtRTPSource->qtState.width; |
93 bih->biHeight = qtRTPSource->qtState.height; | |
22112
c9214f2c30c4
support for SVQ3 in X-QT; patch by Carl Eugen Hoyos (cehoyos ag or at) approved by Ross
nicodvb
parents:
21983
diff
changeset
|
94 if (bih->biCompression == 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
|
95 bih->biCompression == mmioFOURCC('m','p','4','v') || |
22112
c9214f2c30c4
support for SVQ3 in X-QT; patch by Carl Eugen Hoyos (cehoyos ag or at) approved by Ross
nicodvb
parents:
21983
diff
changeset
|
96 bih->biCompression == mmioFOURCC('S','V','Q','3')) { |
21871 | 97 uint8_t *pos = (uint8_t*)qtRTPSource->qtState.sdAtom + 86; |
98 uint8_t *endpos = (uint8_t*)qtRTPSource->qtState.sdAtom | |
99 + qtRTPSource->qtState.sdAtomSize; | |
100 while (pos+8 < endpos) { | |
101 unsigned atomLength = pos[0]<<24 | pos[1]<<16 | pos[2]<<8 | pos[3]; | |
102 if (atomLength == 0 || atomLength > endpos-pos) break; | |
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
|
103 if ((!memcmp(pos+4, "avcC", 4) || |
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
|
104 !memcmp(pos+4, "esds", 4) || |
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
|
105 !memcmp(pos+4, "SMI ", 4)) && |
21871 | 106 atomLength > 8 && |
107 atomLength <= INT_MAX-sizeof(BITMAPINFOHEADER)) { | |
108 bih->biSize = sizeof(BITMAPINFOHEADER)+atomLength-8; | |
109 sh_video->bih = bih = (BITMAPINFOHEADER*)realloc(bih, bih->biSize); | |
110 memcpy(bih+1, pos+8, atomLength-8); | |
111 break; | |
112 } | |
113 pos += atomLength; | |
114 } | |
115 needVideoFrameRate(demuxer, subsession); | |
116 } | |
9250 | 117 } else { |
118 fprintf(stderr, | |
119 "Unknown MPlayer format code for MIME type \"video/%s\"\n", | |
120 subsession->codecName()); | |
121 } | |
122 } | |
123 | |
124 void rtpCodecInitialize_audio(demuxer_t* demuxer, | |
125 MediaSubsession* subsession, | |
126 unsigned& flags) { | |
127 flags = 0; | |
128 // Create a dummy audio stream header | |
129 // to make the main MPlayer code happy: | |
130 sh_audio_t* sh_audio = new_sh_audio(demuxer,0); | |
131 WAVEFORMATEX* wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)); | |
132 sh_audio->wf = wf; | |
133 demux_stream_t* d_audio = demuxer->audio; | |
134 d_audio->sh = sh_audio; sh_audio->ds = d_audio; | |
135 | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
136 wf->nChannels = subsession->numChannels(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
137 |
9250 | 138 // Map known audio MIME types to the WAVEFORMATEX parameters |
139 // that this program uses. (Note that not all types need all | |
140 // of the parameters to be set.) | |
141 wf->nSamplesPerSec | |
142 = subsession->rtpSource()->timestampFrequency(); // by default | |
143 if (strcmp(subsession->codecName(), "MPA") == 0 || | |
144 strcmp(subsession->codecName(), "MPA-ROBUST") == 0 || | |
145 strcmp(subsession->codecName(), "X-MP3-DRAFT-00") == 0) { | |
146 wf->wFormatTag = sh_audio->format = 0x55; | |
147 // Note: 0x55 is for layer III, but should work for I,II also | |
148 wf->nSamplesPerSec = 0; // sample rate is deduced from the data | |
149 } else if (strcmp(subsession->codecName(), "AC3") == 0) { | |
150 wf->wFormatTag = sh_audio->format = 0x2000; | |
151 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
|
152 } 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
|
153 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
|
154 wf->nBlockAlign = 1; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
155 wf->wBitsPerSample = 16; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
156 wf->cbSize = 0; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
157 } 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
|
158 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
|
159 wf->nBlockAlign = 1; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
160 wf->wBitsPerSample = 8; |
b0d0aa726417
Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents:
9910
diff
changeset
|
161 wf->cbSize = 0; |
9250 | 162 } else if (strcmp(subsession->codecName(), "PCMU") == 0) { |
163 wf->wFormatTag = sh_audio->format = 0x7; | |
164 wf->nAvgBytesPerSec = 8000; | |
165 wf->nBlockAlign = 1; | |
166 wf->wBitsPerSample = 8; | |
167 wf->cbSize = 0; | |
168 } else if (strcmp(subsession->codecName(), "PCMA") == 0) { | |
169 wf->wFormatTag = sh_audio->format = 0x6; | |
170 wf->nAvgBytesPerSec = 8000; | |
171 wf->nBlockAlign = 1; | |
172 wf->wBitsPerSample = 8; | |
173 wf->cbSize = 0; | |
174 } else if (strcmp(subsession->codecName(), "GSM") == 0) { | |
175 wf->wFormatTag = sh_audio->format = mmioFOURCC('a','g','s','m'); | |
176 wf->nAvgBytesPerSec = 1650; | |
177 wf->nBlockAlign = 33; | |
178 wf->wBitsPerSample = 16; | |
179 wf->cbSize = 0; | |
180 } else if (strcmp(subsession->codecName(), "QCELP") == 0) { | |
181 wf->wFormatTag = sh_audio->format = mmioFOURCC('Q','c','l','p'); | |
182 wf->nAvgBytesPerSec = 1750; | |
183 wf->nBlockAlign = 35; | |
184 wf->wBitsPerSample = 16; | |
185 wf->cbSize = 0; | |
186 } else if (strcmp(subsession->codecName(), "MP4A-LATM") == 0) { | |
187 wf->wFormatTag = sh_audio->format = mmioFOURCC('m','p','4','a'); | |
188 // For the codec to work correctly, it needs "AudioSpecificConfig" | |
189 // data, which is parsed from the "StreamMuxConfig" string that | |
190 // was present (hopefully) in the SDP description: | |
191 unsigned codecdata_len; | |
192 sh_audio->codecdata | |
193 = parseStreamMuxConfigStr(subsession->fmtp_config(), | |
194 codecdata_len); | |
195 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
|
196 //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
|
197 ((MPEG4LATMAudioRTPSource*)subsession->rtpSource())->omitLATMDataLengthField(); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
198 } 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
|
199 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
|
200 // 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
|
201 // 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
|
202 unsigned codecdata_len; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
203 sh_audio->codecdata |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
204 = parseGeneralConfigStr(subsession->fmtp_config(), |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
205 codecdata_len); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
206 sh_audio->codecdata_len = codecdata_len; |
9250 | 207 } else if (strcmp(subsession->codecName(), "X-QT") == 0 || |
208 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) { | |
209 // QuickTime generic RTP format, as described in | |
210 // http://developer.apple.com/quicktime/icefloe/dispatch026.html | |
211 | |
212 // We can't initialize this stream until we've received the first packet | |
213 // that has QuickTime "sdAtom" information in the header. So, keep | |
214 // 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
|
215 unsigned char* packetData; unsigned packetDataLen; float pts; |
9250 | 216 QuickTimeGenericRTPSource* qtRTPSource |
217 = (QuickTimeGenericRTPSource*)(subsession->rtpSource()); | |
218 unsigned fourcc, numChannels; | |
219 do { | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
220 if (!awaitRTPPacket(demuxer, demuxer->audio, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
221 packetData, packetDataLen, pts)) { |
9250 | 222 return; |
223 } | |
224 } while (!parseQTState_audio(qtRTPSource->qtState, fourcc, numChannels)); | |
225 | |
226 wf->wFormatTag = sh_audio->format = fourcc; | |
227 wf->nChannels = numChannels; | |
228 } else { | |
229 fprintf(stderr, | |
230 "Unknown MPlayer format code for MIME type \"audio/%s\"\n", | |
231 subsession->codecName()); | |
232 } | |
233 } | |
234 | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
235 static void needVideoFrameRate(demuxer_t* demuxer, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
236 MediaSubsession* subsession) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
237 // 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
|
238 // 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
|
239 // 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
|
240 // presentation timestamps in successive packets, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
241 extern float force_fps; if (force_fps != 0.0) return; // user used "-fps" |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
242 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
243 demux_stream_t* d_video = demuxer->video; |
9910 | 244 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
|
245 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
246 // 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
|
247 int fps = (int)(subsession->videoFPS()); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
248 if (fps != 0) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
249 sh_video->fps = fps; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
250 return; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
251 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
252 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
253 // 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
|
254 // non-zero "pts" timestamps: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
255 unsigned char* packetData; unsigned packetDataLen; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
256 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
|
257 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
|
258 int lastfps = 0; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
259 for (unsigned i = 0; i < maxNumFramesToWaitFor; ++i) { |
9910 | 260 if (!awaitRTPPacket(demuxer, d_video, packetData, packetDataLen, curPTS)) { |
261 break; | |
262 } | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
263 |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
264 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
|
265 // 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
|
266 // (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
|
267 // 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
|
268 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
|
269 if (fps == lastfps) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 return; |
21983
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
274 } |
a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents:
21911
diff
changeset
|
275 if (fps>lastfps) lastfps = fps; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
276 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
277 lastPTS = curPTS; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
278 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
279 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
|
280 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9370
diff
changeset
|
281 |
9250 | 282 static Boolean |
283 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState, | |
284 unsigned& fourcc) { | |
285 // qtState's "sdAtom" field is supposed to contain a QuickTime video | |
286 // 'sample description' atom. This atom's name is the 'fourcc' that we want: | |
287 char const* sdAtom = qtState.sdAtom; | |
288 if (sdAtom == NULL || qtState.sdAtomSize < 2*4) return False; | |
289 | |
290 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order | |
291 return True; | |
292 } | |
293 | |
294 static Boolean | |
295 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState, | |
296 unsigned& fourcc, unsigned& numChannels) { | |
297 // qtState's "sdAtom" field is supposed to contain a QuickTime audio | |
298 // 'sample description' atom. This atom's name is the 'fourcc' that we want. | |
299 // Also, the top half of the 5th word following the atom name should | |
300 // contain the number of channels ("numChannels") that we want: | |
301 char const* sdAtom = qtState.sdAtom; | |
302 if (sdAtom == NULL || qtState.sdAtomSize < 7*4) return False; | |
303 | |
304 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order | |
305 | |
306 char const* word7Ptr = &sdAtom[6*4]; | |
307 numChannels = (word7Ptr[0]<<8)|(word7Ptr[1]); | |
308 return True; | |
309 } |