OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/utility/source/file_player_impl.h" | 11 #include "webrtc/modules/utility/source/file_player_impl.h" |
12 #include "webrtc/system_wrappers/include/logging.h" | 12 #include "webrtc/system_wrappers/include/logging.h" |
13 | 13 |
14 namespace webrtc { | 14 namespace webrtc { |
15 FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID, | 15 FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID, |
16 FileFormats fileFormat) | 16 FileFormats fileFormat) { |
17 { | 17 switch (fileFormat) { |
18 switch(fileFormat) | |
19 { | |
20 case kFileFormatWavFile: | 18 case kFileFormatWavFile: |
21 case kFileFormatCompressedFile: | 19 case kFileFormatCompressedFile: |
22 case kFileFormatPreencodedFile: | 20 case kFileFormatPreencodedFile: |
23 case kFileFormatPcm16kHzFile: | 21 case kFileFormatPcm16kHzFile: |
24 case kFileFormatPcm8kHzFile: | 22 case kFileFormatPcm8kHzFile: |
25 case kFileFormatPcm32kHzFile: | 23 case kFileFormatPcm32kHzFile: |
26 // audio formats | 24 // audio formats |
27 return new FilePlayerImpl(instanceID, fileFormat); | 25 return new FilePlayerImpl(instanceID, fileFormat); |
28 default: | 26 default: |
29 assert(false); | 27 assert(false); |
30 return NULL; | 28 return NULL; |
31 } | 29 } |
32 } | 30 } |
33 | 31 |
34 void FilePlayer::DestroyFilePlayer(FilePlayer* player) | 32 void FilePlayer::DestroyFilePlayer(FilePlayer* player) { |
35 { | 33 delete player; |
36 delete player; | |
37 } | 34 } |
38 | 35 |
39 FilePlayerImpl::FilePlayerImpl(const uint32_t instanceID, | 36 FilePlayerImpl::FilePlayerImpl(const uint32_t instanceID, |
40 const FileFormats fileFormat) | 37 const FileFormats fileFormat) |
41 : _instanceID(instanceID), | 38 : _instanceID(instanceID), |
42 _fileFormat(fileFormat), | 39 _fileFormat(fileFormat), |
43 _fileModule(*MediaFile::CreateMediaFile(instanceID)), | 40 _fileModule(*MediaFile::CreateMediaFile(instanceID)), |
44 _decodedLengthInMS(0), | 41 _decodedLengthInMS(0), |
45 _audioDecoder(instanceID), | 42 _audioDecoder(instanceID), |
46 _codec(), | 43 _codec(), |
47 _numberOf10MsPerFrame(0), | 44 _numberOf10MsPerFrame(0), |
48 _numberOf10MsInDecoder(0), | 45 _numberOf10MsInDecoder(0), |
49 _resampler(), | 46 _resampler(), |
50 _scaling(1.0) | 47 _scaling(1.0) { |
51 { | 48 _codec.plfreq = 0; |
52 _codec.plfreq = 0; | |
53 } | 49 } |
54 | 50 |
55 FilePlayerImpl::~FilePlayerImpl() | 51 FilePlayerImpl::~FilePlayerImpl() { |
56 { | 52 MediaFile::DestroyMediaFile(&_fileModule); |
57 MediaFile::DestroyMediaFile(&_fileModule); | |
58 } | 53 } |
59 | 54 |
60 int32_t FilePlayerImpl::Frequency() const | 55 int32_t FilePlayerImpl::Frequency() const { |
61 { | 56 if (_codec.plfreq == 0) { |
62 if(_codec.plfreq == 0) | 57 return -1; |
63 { | 58 } |
64 return -1; | 59 // Make sure that sample rate is 8,16 or 32 kHz. E.g. WAVE files may have |
65 } | 60 // other sampling rates. |
66 // Make sure that sample rate is 8,16 or 32 kHz. E.g. WAVE files may have | 61 if (_codec.plfreq == 11000) { |
67 // other sampling rates. | 62 return 16000; |
68 if(_codec.plfreq == 11000) | 63 } else if (_codec.plfreq == 22000) { |
69 { | 64 return 32000; |
70 return 16000; | 65 } else if (_codec.plfreq == 44000) { |
71 } | 66 return 32000; |
72 else if(_codec.plfreq == 22000) | 67 } else if (_codec.plfreq == 48000) { |
73 { | 68 return 32000; |
74 return 32000; | 69 } else { |
75 } | 70 return _codec.plfreq; |
76 else if(_codec.plfreq == 44000) | 71 } |
77 { | |
78 return 32000; | |
79 } | |
80 else if(_codec.plfreq == 48000) | |
81 { | |
82 return 32000; | |
83 } | |
84 else | |
85 { | |
86 return _codec.plfreq; | |
87 } | |
88 } | 72 } |
89 | 73 |
90 int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const | 74 int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const { |
91 { | 75 audioCodec = _codec; |
92 audioCodec = _codec; | 76 return 0; |
93 return 0; | |
94 } | 77 } |
95 | 78 |
96 int32_t FilePlayerImpl::Get10msAudioFromFile( | 79 int32_t FilePlayerImpl::Get10msAudioFromFile(int16_t* outBuffer, |
97 int16_t* outBuffer, | 80 size_t& lengthInSamples, |
98 size_t& lengthInSamples, | 81 int frequencyInHz) { |
99 int frequencyInHz) | 82 if (_codec.plfreq == 0) { |
100 { | 83 LOG(LS_WARNING) << "Get10msAudioFromFile() playing not started!" |
101 if(_codec.plfreq == 0) | 84 << " codec freq = " << _codec.plfreq |
102 { | 85 << ", wanted freq = " << frequencyInHz; |
103 LOG(LS_WARNING) << "Get10msAudioFromFile() playing not started!" | 86 return -1; |
104 << " codec freq = " << _codec.plfreq | 87 } |
105 << ", wanted freq = " << frequencyInHz; | 88 |
| 89 AudioFrame unresampledAudioFrame; |
| 90 if (STR_CASE_CMP(_codec.plname, "L16") == 0) { |
| 91 unresampledAudioFrame.sample_rate_hz_ = _codec.plfreq; |
| 92 |
| 93 // L16 is un-encoded data. Just pull 10 ms. |
| 94 size_t lengthInBytes = sizeof(unresampledAudioFrame.data_); |
| 95 if (_fileModule.PlayoutAudioData((int8_t*)unresampledAudioFrame.data_, |
| 96 lengthInBytes) == -1) { |
| 97 // End of file reached. |
| 98 return -1; |
| 99 } |
| 100 if (lengthInBytes == 0) { |
| 101 lengthInSamples = 0; |
| 102 return 0; |
| 103 } |
| 104 // One sample is two bytes. |
| 105 unresampledAudioFrame.samples_per_channel_ = lengthInBytes >> 1; |
| 106 |
| 107 } else { |
| 108 // Decode will generate 10 ms of audio data. PlayoutAudioData(..) |
| 109 // expects a full frame. If the frame size is larger than 10 ms, |
| 110 // PlayoutAudioData(..) data should be called proportionally less often. |
| 111 int16_t encodedBuffer[MAX_AUDIO_BUFFER_IN_SAMPLES]; |
| 112 size_t encodedLengthInBytes = 0; |
| 113 if (++_numberOf10MsInDecoder >= _numberOf10MsPerFrame) { |
| 114 _numberOf10MsInDecoder = 0; |
| 115 size_t bytesFromFile = sizeof(encodedBuffer); |
| 116 if (_fileModule.PlayoutAudioData((int8_t*)encodedBuffer, bytesFromFile) == |
| 117 -1) { |
| 118 // End of file reached. |
106 return -1; | 119 return -1; |
| 120 } |
| 121 encodedLengthInBytes = bytesFromFile; |
107 } | 122 } |
| 123 if (_audioDecoder.Decode(unresampledAudioFrame, frequencyInHz, |
| 124 (int8_t*)encodedBuffer, |
| 125 encodedLengthInBytes) == -1) { |
| 126 return -1; |
| 127 } |
| 128 } |
108 | 129 |
109 AudioFrame unresampledAudioFrame; | 130 size_t outLen = 0; |
110 if(STR_CASE_CMP(_codec.plname, "L16") == 0) | 131 if (_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_, |
111 { | 132 frequencyInHz, 1)) { |
112 unresampledAudioFrame.sample_rate_hz_ = _codec.plfreq; | 133 LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec."; |
113 | 134 |
114 // L16 is un-encoded data. Just pull 10 ms. | 135 // New sampling frequency. Update state. |
115 size_t lengthInBytes = | 136 outLen = static_cast<size_t>(frequencyInHz / 100); |
116 sizeof(unresampledAudioFrame.data_); | 137 memset(outBuffer, 0, outLen * sizeof(int16_t)); |
117 if (_fileModule.PlayoutAudioData( | 138 return 0; |
118 (int8_t*)unresampledAudioFrame.data_, | 139 } |
119 lengthInBytes) == -1) | 140 _resampler.Push(unresampledAudioFrame.data_, |
120 { | 141 unresampledAudioFrame.samples_per_channel_, outBuffer, |
121 // End of file reached. | 142 MAX_AUDIO_BUFFER_IN_SAMPLES, outLen); |
122 return -1; | |
123 } | |
124 if(lengthInBytes == 0) | |
125 { | |
126 lengthInSamples = 0; | |
127 return 0; | |
128 } | |
129 // One sample is two bytes. | |
130 unresampledAudioFrame.samples_per_channel_ = lengthInBytes >> 1; | |
131 | 143 |
132 } else { | 144 lengthInSamples = outLen; |
133 // Decode will generate 10 ms of audio data. PlayoutAudioData(..) | 145 |
134 // expects a full frame. If the frame size is larger than 10 ms, | 146 if (_scaling != 1.0) { |
135 // PlayoutAudioData(..) data should be called proportionally less often. | 147 for (size_t i = 0; i < outLen; i++) { |
136 int16_t encodedBuffer[MAX_AUDIO_BUFFER_IN_SAMPLES]; | 148 outBuffer[i] = (int16_t)(outBuffer[i] * _scaling); |
137 size_t encodedLengthInBytes = 0; | |
138 if(++_numberOf10MsInDecoder >= _numberOf10MsPerFrame) | |
139 { | |
140 _numberOf10MsInDecoder = 0; | |
141 size_t bytesFromFile = sizeof(encodedBuffer); | |
142 if (_fileModule.PlayoutAudioData((int8_t*)encodedBuffer, | |
143 bytesFromFile) == -1) | |
144 { | |
145 // End of file reached. | |
146 return -1; | |
147 } | |
148 encodedLengthInBytes = bytesFromFile; | |
149 } | |
150 if(_audioDecoder.Decode(unresampledAudioFrame,frequencyInHz, | |
151 (int8_t*)encodedBuffer, | |
152 encodedLengthInBytes) == -1) | |
153 { | |
154 return -1; | |
155 } | |
156 } | 149 } |
157 | 150 } |
158 size_t outLen = 0; | 151 _decodedLengthInMS += 10; |
159 if(_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_, | 152 return 0; |
160 frequencyInHz, 1)) | |
161 { | |
162 LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec."; | |
163 | |
164 // New sampling frequency. Update state. | |
165 outLen = static_cast<size_t>(frequencyInHz / 100); | |
166 memset(outBuffer, 0, outLen * sizeof(int16_t)); | |
167 return 0; | |
168 } | |
169 _resampler.Push(unresampledAudioFrame.data_, | |
170 unresampledAudioFrame.samples_per_channel_, | |
171 outBuffer, | |
172 MAX_AUDIO_BUFFER_IN_SAMPLES, | |
173 outLen); | |
174 | |
175 lengthInSamples = outLen; | |
176 | |
177 if(_scaling != 1.0) | |
178 { | |
179 for (size_t i = 0;i < outLen; i++) | |
180 { | |
181 outBuffer[i] = (int16_t)(outBuffer[i] * _scaling); | |
182 } | |
183 } | |
184 _decodedLengthInMS += 10; | |
185 return 0; | |
186 } | 153 } |
187 | 154 |
188 int32_t FilePlayerImpl::RegisterModuleFileCallback(FileCallback* callback) | 155 int32_t FilePlayerImpl::RegisterModuleFileCallback(FileCallback* callback) { |
189 { | 156 return _fileModule.SetModuleFileCallback(callback); |
190 return _fileModule.SetModuleFileCallback(callback); | |
191 } | 157 } |
192 | 158 |
193 int32_t FilePlayerImpl::SetAudioScaling(float scaleFactor) | 159 int32_t FilePlayerImpl::SetAudioScaling(float scaleFactor) { |
194 { | 160 if ((scaleFactor >= 0) && (scaleFactor <= 2.0)) { |
195 if((scaleFactor >= 0)&&(scaleFactor <= 2.0)) | 161 _scaling = scaleFactor; |
196 { | 162 return 0; |
197 _scaling = scaleFactor; | 163 } |
198 return 0; | 164 LOG(LS_WARNING) << "SetAudioScaling() non-allowed scale factor."; |
199 } | 165 return -1; |
200 LOG(LS_WARNING) << "SetAudioScaling() non-allowed scale factor."; | |
201 return -1; | |
202 } | 166 } |
203 | 167 |
204 int32_t FilePlayerImpl::StartPlayingFile(const char* fileName, | 168 int32_t FilePlayerImpl::StartPlayingFile(const char* fileName, |
205 bool loop, | 169 bool loop, |
206 uint32_t startPosition, | 170 uint32_t startPosition, |
207 float volumeScaling, | 171 float volumeScaling, |
208 uint32_t notification, | 172 uint32_t notification, |
209 uint32_t stopPosition, | 173 uint32_t stopPosition, |
210 const CodecInst* codecInst) | 174 const CodecInst* codecInst) { |
211 { | 175 if (_fileFormat == kFileFormatPcm16kHzFile || |
212 if (_fileFormat == kFileFormatPcm16kHzFile || | 176 _fileFormat == kFileFormatPcm8kHzFile || |
213 _fileFormat == kFileFormatPcm8kHzFile|| | 177 _fileFormat == kFileFormatPcm32kHzFile) { |
214 _fileFormat == kFileFormatPcm32kHzFile ) | 178 CodecInst codecInstL16; |
215 { | 179 strncpy(codecInstL16.plname, "L16", 32); |
216 CodecInst codecInstL16; | 180 codecInstL16.pltype = 93; |
217 strncpy(codecInstL16.plname,"L16",32); | 181 codecInstL16.channels = 1; |
218 codecInstL16.pltype = 93; | |
219 codecInstL16.channels = 1; | |
220 | 182 |
221 if (_fileFormat == kFileFormatPcm8kHzFile) | 183 if (_fileFormat == kFileFormatPcm8kHzFile) { |
222 { | 184 codecInstL16.rate = 128000; |
223 codecInstL16.rate = 128000; | 185 codecInstL16.plfreq = 8000; |
224 codecInstL16.plfreq = 8000; | 186 codecInstL16.pacsize = 80; |
225 codecInstL16.pacsize = 80; | |
226 | 187 |
227 } else if(_fileFormat == kFileFormatPcm16kHzFile) | 188 } else if (_fileFormat == kFileFormatPcm16kHzFile) { |
228 { | 189 codecInstL16.rate = 256000; |
229 codecInstL16.rate = 256000; | 190 codecInstL16.plfreq = 16000; |
230 codecInstL16.plfreq = 16000; | 191 codecInstL16.pacsize = 160; |
231 codecInstL16.pacsize = 160; | |
232 | 192 |
233 }else if(_fileFormat == kFileFormatPcm32kHzFile) | 193 } else if (_fileFormat == kFileFormatPcm32kHzFile) { |
234 { | 194 codecInstL16.rate = 512000; |
235 codecInstL16.rate = 512000; | 195 codecInstL16.plfreq = 32000; |
236 codecInstL16.plfreq = 32000; | 196 codecInstL16.pacsize = 160; |
237 codecInstL16.pacsize = 160; | 197 } else { |
238 } else | 198 LOG(LS_ERROR) << "StartPlayingFile() sample frequency not " |
239 { | 199 << "supported for PCM format."; |
240 LOG(LS_ERROR) << "StartPlayingFile() sample frequency not " | 200 return -1; |
241 << "supported for PCM format."; | 201 } |
242 return -1; | |
243 } | |
244 | 202 |
245 if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, | 203 if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, |
246 _fileFormat, &codecInstL16, | 204 _fileFormat, &codecInstL16, |
247 startPosition, | 205 startPosition, stopPosition) == -1) { |
248 stopPosition) == -1) | 206 LOG(LS_WARNING) << "StartPlayingFile() failed to initialize " |
249 { | 207 << "pcm file " << fileName; |
250 LOG(LS_WARNING) << "StartPlayingFile() failed to initialize " | 208 return -1; |
251 << "pcm file " << fileName; | |
252 return -1; | |
253 } | |
254 SetAudioScaling(volumeScaling); | |
255 }else if(_fileFormat == kFileFormatPreencodedFile) | |
256 { | |
257 if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, | |
258 _fileFormat, codecInst) == -1) | |
259 { | |
260 LOG(LS_WARNING) << "StartPlayingFile() failed to initialize " | |
261 << "pre-encoded file " << fileName; | |
262 return -1; | |
263 } | |
264 } else | |
265 { | |
266 CodecInst* no_inst = NULL; | |
267 if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, | |
268 _fileFormat, no_inst, | |
269 startPosition, | |
270 stopPosition) == -1) | |
271 { | |
272 LOG(LS_WARNING) << "StartPlayingFile() failed to initialize file " | |
273 << fileName; | |
274 return -1; | |
275 } | |
276 SetAudioScaling(volumeScaling); | |
277 } | 209 } |
278 if (SetUpAudioDecoder() == -1) | 210 SetAudioScaling(volumeScaling); |
279 { | 211 } else if (_fileFormat == kFileFormatPreencodedFile) { |
280 StopPlayingFile(); | 212 if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, |
281 return -1; | 213 _fileFormat, codecInst) == -1) { |
| 214 LOG(LS_WARNING) << "StartPlayingFile() failed to initialize " |
| 215 << "pre-encoded file " << fileName; |
| 216 return -1; |
282 } | 217 } |
283 return 0; | 218 } else { |
| 219 CodecInst* no_inst = NULL; |
| 220 if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, |
| 221 _fileFormat, no_inst, startPosition, |
| 222 stopPosition) == -1) { |
| 223 LOG(LS_WARNING) << "StartPlayingFile() failed to initialize file " |
| 224 << fileName; |
| 225 return -1; |
| 226 } |
| 227 SetAudioScaling(volumeScaling); |
| 228 } |
| 229 if (SetUpAudioDecoder() == -1) { |
| 230 StopPlayingFile(); |
| 231 return -1; |
| 232 } |
| 233 return 0; |
284 } | 234 } |
285 | 235 |
286 int32_t FilePlayerImpl::StartPlayingFile(InStream& sourceStream, | 236 int32_t FilePlayerImpl::StartPlayingFile(InStream& sourceStream, |
287 uint32_t startPosition, | 237 uint32_t startPosition, |
288 float volumeScaling, | 238 float volumeScaling, |
289 uint32_t notification, | 239 uint32_t notification, |
290 uint32_t stopPosition, | 240 uint32_t stopPosition, |
291 const CodecInst* codecInst) | 241 const CodecInst* codecInst) { |
292 { | 242 if (_fileFormat == kFileFormatPcm16kHzFile || |
293 if (_fileFormat == kFileFormatPcm16kHzFile || | 243 _fileFormat == kFileFormatPcm32kHzFile || |
294 _fileFormat == kFileFormatPcm32kHzFile || | 244 _fileFormat == kFileFormatPcm8kHzFile) { |
295 _fileFormat == kFileFormatPcm8kHzFile) | 245 CodecInst codecInstL16; |
296 { | 246 strncpy(codecInstL16.plname, "L16", 32); |
297 CodecInst codecInstL16; | 247 codecInstL16.pltype = 93; |
298 strncpy(codecInstL16.plname,"L16",32); | 248 codecInstL16.channels = 1; |
299 codecInstL16.pltype = 93; | |
300 codecInstL16.channels = 1; | |
301 | 249 |
302 if (_fileFormat == kFileFormatPcm8kHzFile) | 250 if (_fileFormat == kFileFormatPcm8kHzFile) { |
303 { | 251 codecInstL16.rate = 128000; |
304 codecInstL16.rate = 128000; | 252 codecInstL16.plfreq = 8000; |
305 codecInstL16.plfreq = 8000; | 253 codecInstL16.pacsize = 80; |
306 codecInstL16.pacsize = 80; | |
307 | 254 |
308 }else if (_fileFormat == kFileFormatPcm16kHzFile) | 255 } else if (_fileFormat == kFileFormatPcm16kHzFile) { |
309 { | 256 codecInstL16.rate = 256000; |
310 codecInstL16.rate = 256000; | 257 codecInstL16.plfreq = 16000; |
311 codecInstL16.plfreq = 16000; | 258 codecInstL16.pacsize = 160; |
312 codecInstL16.pacsize = 160; | |
313 | 259 |
314 }else if (_fileFormat == kFileFormatPcm32kHzFile) | 260 } else if (_fileFormat == kFileFormatPcm32kHzFile) { |
315 { | 261 codecInstL16.rate = 512000; |
316 codecInstL16.rate = 512000; | 262 codecInstL16.plfreq = 32000; |
317 codecInstL16.plfreq = 32000; | 263 codecInstL16.pacsize = 160; |
318 codecInstL16.pacsize = 160; | 264 } else { |
319 }else | 265 LOG(LS_ERROR) << "StartPlayingFile() sample frequency not " |
320 { | 266 << "supported for PCM format."; |
321 LOG(LS_ERROR) << "StartPlayingFile() sample frequency not " | 267 return -1; |
322 << "supported for PCM format."; | 268 } |
323 return -1; | 269 if (_fileModule.StartPlayingAudioStream( |
324 } | 270 sourceStream, notification, _fileFormat, &codecInstL16, |
325 if (_fileModule.StartPlayingAudioStream(sourceStream, notification, | 271 startPosition, stopPosition) == -1) { |
326 _fileFormat, &codecInstL16, | 272 LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " |
327 startPosition, | 273 << "playout."; |
328 stopPosition) == -1) | 274 return -1; |
329 { | 275 } |
330 LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " | |
331 << "playout."; | |
332 return -1; | |
333 } | |
334 | 276 |
335 }else if(_fileFormat == kFileFormatPreencodedFile) | 277 } else if (_fileFormat == kFileFormatPreencodedFile) { |
336 { | 278 if (_fileModule.StartPlayingAudioStream(sourceStream, notification, |
337 if (_fileModule.StartPlayingAudioStream(sourceStream, notification, | 279 _fileFormat, codecInst) == -1) { |
338 _fileFormat, codecInst) == -1) | 280 LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " |
339 { | 281 << "playout."; |
340 LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " | 282 return -1; |
341 << "playout."; | |
342 return -1; | |
343 } | |
344 } else { | |
345 CodecInst* no_inst = NULL; | |
346 if (_fileModule.StartPlayingAudioStream(sourceStream, notification, | |
347 _fileFormat, no_inst, | |
348 startPosition, | |
349 stopPosition) == -1) | |
350 { | |
351 LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " | |
352 << "playout."; | |
353 return -1; | |
354 } | |
355 } | 283 } |
356 SetAudioScaling(volumeScaling); | 284 } else { |
| 285 CodecInst* no_inst = NULL; |
| 286 if (_fileModule.StartPlayingAudioStream(sourceStream, notification, |
| 287 _fileFormat, no_inst, startPosition, |
| 288 stopPosition) == -1) { |
| 289 LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " |
| 290 << "playout."; |
| 291 return -1; |
| 292 } |
| 293 } |
| 294 SetAudioScaling(volumeScaling); |
357 | 295 |
358 if (SetUpAudioDecoder() == -1) | 296 if (SetUpAudioDecoder() == -1) { |
359 { | 297 StopPlayingFile(); |
360 StopPlayingFile(); | 298 return -1; |
361 return -1; | 299 } |
362 } | 300 return 0; |
363 return 0; | |
364 } | 301 } |
365 | 302 |
366 int32_t FilePlayerImpl::StopPlayingFile() | 303 int32_t FilePlayerImpl::StopPlayingFile() { |
367 { | 304 memset(&_codec, 0, sizeof(CodecInst)); |
368 memset(&_codec, 0, sizeof(CodecInst)); | 305 _numberOf10MsPerFrame = 0; |
369 _numberOf10MsPerFrame = 0; | 306 _numberOf10MsInDecoder = 0; |
370 _numberOf10MsInDecoder = 0; | 307 return _fileModule.StopPlaying(); |
371 return _fileModule.StopPlaying(); | |
372 } | 308 } |
373 | 309 |
374 bool FilePlayerImpl::IsPlayingFile() const | 310 bool FilePlayerImpl::IsPlayingFile() const { |
375 { | 311 return _fileModule.IsPlaying(); |
376 return _fileModule.IsPlaying(); | |
377 } | 312 } |
378 | 313 |
379 int32_t FilePlayerImpl::GetPlayoutPosition(uint32_t& durationMs) | 314 int32_t FilePlayerImpl::GetPlayoutPosition(uint32_t& durationMs) { |
380 { | 315 return _fileModule.PlayoutPositionMs(durationMs); |
381 return _fileModule.PlayoutPositionMs(durationMs); | |
382 } | 316 } |
383 | 317 |
384 int32_t FilePlayerImpl::SetUpAudioDecoder() | 318 int32_t FilePlayerImpl::SetUpAudioDecoder() { |
385 { | 319 if ((_fileModule.codec_info(_codec) == -1)) { |
386 if ((_fileModule.codec_info(_codec) == -1)) | 320 LOG(LS_WARNING) << "Failed to retrieve codec info of file data."; |
387 { | 321 return -1; |
388 LOG(LS_WARNING) << "Failed to retrieve codec info of file data."; | 322 } |
389 return -1; | 323 if (STR_CASE_CMP(_codec.plname, "L16") != 0 && |
390 } | 324 _audioDecoder.SetDecodeCodec(_codec) == -1) { |
391 if( STR_CASE_CMP(_codec.plname, "L16") != 0 && | 325 LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname |
392 _audioDecoder.SetDecodeCodec(_codec) == -1) | 326 << " not supported."; |
393 { | 327 return -1; |
394 LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname | 328 } |
395 << " not supported."; | 329 _numberOf10MsPerFrame = _codec.pacsize / (_codec.plfreq / 100); |
396 return -1; | 330 _numberOf10MsInDecoder = 0; |
397 } | 331 return 0; |
398 _numberOf10MsPerFrame = _codec.pacsize / (_codec.plfreq / 100); | |
399 _numberOf10MsInDecoder = 0; | |
400 return 0; | |
401 } | 332 } |
402 } // namespace webrtc | 333 } // namespace webrtc |
OLD | NEW |