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