Mercurial > mplayer.hg
annotate libmpdemux/demux_rtp_codec.cpp @ 9423:36637ef379f1
sync
author | nicolas |
---|---|
date | Fri, 14 Feb 2003 15:00:22 +0000 |
parents | 88bd19564b64 |
children | e74916774667 |
rev | line source |
---|---|
9250 | 1 ////////// Codec-specific routines used to interface between "MPlayer" |
2 ////////// and the "LIVE.COM Streaming Media" libraries: | |
3 | |
4 #include "demux_rtp_internal.h" | |
5 extern "C" { | |
6 #include "stheader.h" | |
7 } | |
8 | |
9 static Boolean | |
10 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState, | |
11 unsigned& fourcc); // forward | |
12 static Boolean | |
13 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState, | |
14 unsigned& fourcc, unsigned& numChannels); // forward | |
15 | |
16 void rtpCodecInitialize_video(demuxer_t* demuxer, | |
17 MediaSubsession* subsession, | |
18 unsigned& flags) { | |
19 flags = 0; | |
20 // Create a dummy video stream header | |
21 // to make the main MPlayer code happy: | |
22 sh_video_t* sh_video = new_sh_video(demuxer,0); | |
23 BITMAPINFOHEADER* bih | |
24 = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER)); | |
25 bih->biSize = sizeof(BITMAPINFOHEADER); | |
26 sh_video->bih = bih; | |
27 demux_stream_t* d_video = demuxer->video; | |
28 d_video->sh = sh_video; sh_video->ds = d_video; | |
29 | |
30 // If we happen to know the subsession's video frame rate, set it, | |
31 // so that the user doesn't have to give the "-fps" option instead. | |
32 int fps = (int)(subsession->videoFPS()); | |
33 if (fps != 0) sh_video->fps = fps; | |
34 | |
35 // Map known video MIME types to the BITMAPINFOHEADER parameters | |
36 // that this program uses. (Note that not all types need all | |
37 // of the parameters to be set.) | |
38 if (strcmp(subsession->codecName(), "MPV") == 0 || | |
39 strcmp(subsession->codecName(), "MP1S") == 0 || | |
40 strcmp(subsession->codecName(), "MP2T") == 0) { | |
41 flags |= RTPSTATE_IS_MPEG; | |
42 } else if (strcmp(subsession->codecName(), "H263") == 0 || | |
43 strcmp(subsession->codecName(), "H263-1998") == 0) { | |
44 bih->biCompression = sh_video->format | |
45 = mmioFOURCC('H','2','6','3'); | |
46 } else if (strcmp(subsession->codecName(), "H261") == 0) { | |
47 bih->biCompression = sh_video->format | |
48 = mmioFOURCC('H','2','6','1'); | |
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
49 } 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
|
50 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
|
51 = mmioFOURCC('M','J','P','G'); |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
52 #if (LIVEMEDIA_LIBRARY_VERSION_INT < 1044662400) |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
53 fprintf(stderr, "WARNING: This video stream might not play correctly. Please upgrade to version \"2003.02.08\" or later of the \"LIVE.COM Streaming Media\" libraries.\n"); |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
54 #endif |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
55 } 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
|
56 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
|
57 = mmioFOURCC('m','p','4','v'); |
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
58 //flags |= RTPSTATE_IS_MPEG; // MPEG hdr checking in video.c doesn't work! |
9250 | 59 } else if (strcmp(subsession->codecName(), "X-QT") == 0 || |
60 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) { | |
61 // QuickTime generic RTP format, as described in | |
62 // http://developer.apple.com/quicktime/icefloe/dispatch026.html | |
63 | |
64 // We can't initialize this stream until we've received the first packet | |
65 // that has QuickTime "sdAtom" information in the header. So, keep | |
66 // reading packets until we get one: | |
67 unsigned char* packetData; unsigned packetDataLen; | |
68 QuickTimeGenericRTPSource* qtRTPSource | |
69 = (QuickTimeGenericRTPSource*)(subsession->rtpSource()); | |
70 unsigned fourcc; | |
71 do { | |
72 if (!awaitRTPPacket(demuxer, 0 /*video*/, packetData, packetDataLen)) { | |
73 return; | |
74 } | |
75 } while (!parseQTState_video(qtRTPSource->qtState, fourcc)); | |
76 | |
77 bih->biCompression = sh_video->format = fourcc; | |
78 } else { | |
79 fprintf(stderr, | |
80 "Unknown MPlayer format code for MIME type \"video/%s\"\n", | |
81 subsession->codecName()); | |
82 } | |
83 } | |
84 | |
85 void rtpCodecInitialize_audio(demuxer_t* demuxer, | |
86 MediaSubsession* subsession, | |
87 unsigned& flags) { | |
88 flags = 0; | |
89 // Create a dummy audio stream header | |
90 // to make the main MPlayer code happy: | |
91 sh_audio_t* sh_audio = new_sh_audio(demuxer,0); | |
92 WAVEFORMATEX* wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)); | |
93 sh_audio->wf = wf; | |
94 demux_stream_t* d_audio = demuxer->audio; | |
95 d_audio->sh = sh_audio; sh_audio->ds = d_audio; | |
96 | |
97 // Map known audio MIME types to the WAVEFORMATEX parameters | |
98 // that this program uses. (Note that not all types need all | |
99 // of the parameters to be set.) | |
100 wf->nSamplesPerSec | |
101 = subsession->rtpSource()->timestampFrequency(); // by default | |
102 if (strcmp(subsession->codecName(), "MPA") == 0 || | |
103 strcmp(subsession->codecName(), "MPA-ROBUST") == 0 || | |
104 strcmp(subsession->codecName(), "X-MP3-DRAFT-00") == 0) { | |
105 wf->wFormatTag = sh_audio->format = 0x55; | |
106 // Note: 0x55 is for layer III, but should work for I,II also | |
107 wf->nSamplesPerSec = 0; // sample rate is deduced from the data | |
108 flags |= RTPSTATE_IS_MPEG; | |
109 } else if (strcmp(subsession->codecName(), "AC3") == 0) { | |
110 wf->wFormatTag = sh_audio->format = 0x2000; | |
111 wf->nSamplesPerSec = 0; // sample rate is deduced from the data | |
112 } else if (strcmp(subsession->codecName(), "PCMU") == 0) { | |
113 wf->wFormatTag = sh_audio->format = 0x7; | |
114 wf->nChannels = 1; | |
115 wf->nAvgBytesPerSec = 8000; | |
116 wf->nBlockAlign = 1; | |
117 wf->wBitsPerSample = 8; | |
118 wf->cbSize = 0; | |
119 } else if (strcmp(subsession->codecName(), "PCMA") == 0) { | |
120 wf->wFormatTag = sh_audio->format = 0x6; | |
121 wf->nChannels = 1; | |
122 wf->nAvgBytesPerSec = 8000; | |
123 wf->nBlockAlign = 1; | |
124 wf->wBitsPerSample = 8; | |
125 wf->cbSize = 0; | |
126 } else if (strcmp(subsession->codecName(), "GSM") == 0) { | |
127 wf->wFormatTag = sh_audio->format = mmioFOURCC('a','g','s','m'); | |
128 wf->nChannels = 1; | |
129 wf->nAvgBytesPerSec = 1650; | |
130 wf->nBlockAlign = 33; | |
131 wf->wBitsPerSample = 16; | |
132 wf->cbSize = 0; | |
133 } else if (strcmp(subsession->codecName(), "QCELP") == 0) { | |
134 wf->wFormatTag = sh_audio->format = mmioFOURCC('Q','c','l','p'); | |
135 // The following settings for QCELP don't quite work right ##### | |
136 wf->nChannels = 1; | |
137 wf->nAvgBytesPerSec = 1750; | |
138 wf->nBlockAlign = 35; | |
139 wf->wBitsPerSample = 16; | |
140 wf->cbSize = 0; | |
141 } else if (strcmp(subsession->codecName(), "MP4A-LATM") == 0) { | |
142 wf->wFormatTag = sh_audio->format = mmioFOURCC('m','p','4','a'); | |
143 #if (LIVEMEDIA_LIBRARY_VERSION_INT < 1042761600) | |
144 fprintf(stderr, "WARNING: This audio stream might not play correctly. Please upgrade to version \"2003.01.17\" or later of the \"LIVE.COM Streaming Media\" libraries.\n"); | |
145 #else | |
146 // For the codec to work correctly, it needs "AudioSpecificConfig" | |
147 // data, which is parsed from the "StreamMuxConfig" string that | |
148 // was present (hopefully) in the SDP description: | |
149 unsigned codecdata_len; | |
150 sh_audio->codecdata | |
151 = parseStreamMuxConfigStr(subsession->fmtp_config(), | |
152 codecdata_len); | |
153 sh_audio->codecdata_len = codecdata_len; | |
154 #endif | |
155 flags |= RTPSTATE_IS_MPEG; | |
156 } else if (strcmp(subsession->codecName(), "X-QT") == 0 || | |
157 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) { | |
158 // QuickTime generic RTP format, as described in | |
159 // http://developer.apple.com/quicktime/icefloe/dispatch026.html | |
160 | |
161 // We can't initialize this stream until we've received the first packet | |
162 // that has QuickTime "sdAtom" information in the header. So, keep | |
163 // reading packets until we get one: | |
164 unsigned char* packetData; unsigned packetDataLen; | |
165 QuickTimeGenericRTPSource* qtRTPSource | |
166 = (QuickTimeGenericRTPSource*)(subsession->rtpSource()); | |
167 unsigned fourcc, numChannels; | |
168 do { | |
169 if (!awaitRTPPacket(demuxer, 1 /*audio*/, packetData, packetDataLen)) { | |
170 return; | |
171 } | |
172 } while (!parseQTState_audio(qtRTPSource->qtState, fourcc, numChannels)); | |
173 | |
174 wf->wFormatTag = sh_audio->format = fourcc; | |
175 wf->nChannels = numChannels; | |
176 } else { | |
177 fprintf(stderr, | |
178 "Unknown MPlayer format code for MIME type \"audio/%s\"\n", | |
179 subsession->codecName()); | |
180 } | |
181 } | |
182 | |
183 static Boolean | |
184 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState, | |
185 unsigned& fourcc) { | |
186 // qtState's "sdAtom" field is supposed to contain a QuickTime video | |
187 // 'sample description' atom. This atom's name is the 'fourcc' that we want: | |
188 char const* sdAtom = qtState.sdAtom; | |
189 if (sdAtom == NULL || qtState.sdAtomSize < 2*4) return False; | |
190 | |
191 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order | |
192 return True; | |
193 } | |
194 | |
195 static Boolean | |
196 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState, | |
197 unsigned& fourcc, unsigned& numChannels) { | |
198 // qtState's "sdAtom" field is supposed to contain a QuickTime audio | |
199 // 'sample description' atom. This atom's name is the 'fourcc' that we want. | |
200 // Also, the top half of the 5th word following the atom name should | |
201 // contain the number of channels ("numChannels") that we want: | |
202 char const* sdAtom = qtState.sdAtom; | |
203 if (sdAtom == NULL || qtState.sdAtomSize < 7*4) return False; | |
204 | |
205 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order | |
206 | |
207 char const* word7Ptr = &sdAtom[6*4]; | |
208 numChannels = (word7Ptr[0]<<8)|(word7Ptr[1]); | |
209 return True; | |
210 } |