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