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