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