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