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/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" |
12 #include "webrtc/system_wrappers/include/logging.h" | 20 #include "webrtc/system_wrappers/include/logging.h" |
| 21 #include "webrtc/typedefs.h" |
13 | 22 |
14 namespace webrtc { | 23 namespace webrtc { |
15 FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID, | |
16 FileFormats fileFormat) { | |
17 switch (fileFormat) { | |
18 case kFileFormatWavFile: | |
19 case kFileFormatCompressedFile: | |
20 case kFileFormatPreencodedFile: | |
21 case kFileFormatPcm16kHzFile: | |
22 case kFileFormatPcm8kHzFile: | |
23 case kFileFormatPcm32kHzFile: | |
24 // audio formats | |
25 return new FilePlayerImpl(instanceID, fileFormat); | |
26 default: | |
27 assert(false); | |
28 return NULL; | |
29 } | |
30 } | |
31 | 24 |
32 void FilePlayer::DestroyFilePlayer(FilePlayer* player) { | 25 namespace { |
33 delete player; | 26 |
34 } | 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, |
| 41 uint32_t stopPosition = 0, |
| 42 const CodecInst* codecInst = NULL); |
| 43 virtual int32_t StartPlayingFile(InStream& sourceStream, |
| 44 uint32_t startPosition, |
| 45 float volumeScaling, |
| 46 uint32_t notification, |
| 47 uint32_t stopPosition = 0, |
| 48 const CodecInst* codecInst = NULL); |
| 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 |
| 56 protected: |
| 57 int32_t SetUpAudioDecoder(); |
| 58 |
| 59 uint32_t _instanceID; |
| 60 const FileFormats _fileFormat; |
| 61 MediaFile& _fileModule; |
| 62 |
| 63 uint32_t _decodedLengthInMS; |
| 64 |
| 65 private: |
| 66 AudioCoder _audioDecoder; |
| 67 |
| 68 CodecInst _codec; |
| 69 int32_t _numberOf10MsPerFrame; |
| 70 int32_t _numberOf10MsInDecoder; |
| 71 |
| 72 Resampler _resampler; |
| 73 float _scaling; |
| 74 }; |
35 | 75 |
36 FilePlayerImpl::FilePlayerImpl(const uint32_t instanceID, | 76 FilePlayerImpl::FilePlayerImpl(const uint32_t instanceID, |
37 const FileFormats fileFormat) | 77 const FileFormats fileFormat) |
38 : _instanceID(instanceID), | 78 : _instanceID(instanceID), |
39 _fileFormat(fileFormat), | 79 _fileFormat(fileFormat), |
40 _fileModule(*MediaFile::CreateMediaFile(instanceID)), | 80 _fileModule(*MediaFile::CreateMediaFile(instanceID)), |
41 _decodedLengthInMS(0), | 81 _decodedLengthInMS(0), |
42 _audioDecoder(instanceID), | 82 _audioDecoder(instanceID), |
43 _codec(), | 83 _codec(), |
44 _numberOf10MsPerFrame(0), | 84 _numberOf10MsPerFrame(0), |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 if (STR_CASE_CMP(_codec.plname, "L16") != 0 && | 363 if (STR_CASE_CMP(_codec.plname, "L16") != 0 && |
324 _audioDecoder.SetDecodeCodec(_codec) == -1) { | 364 _audioDecoder.SetDecodeCodec(_codec) == -1) { |
325 LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname | 365 LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname |
326 << " not supported."; | 366 << " not supported."; |
327 return -1; | 367 return -1; |
328 } | 368 } |
329 _numberOf10MsPerFrame = _codec.pacsize / (_codec.plfreq / 100); | 369 _numberOf10MsPerFrame = _codec.pacsize / (_codec.plfreq / 100); |
330 _numberOf10MsInDecoder = 0; | 370 _numberOf10MsInDecoder = 0; |
331 return 0; | 371 return 0; |
332 } | 372 } |
| 373 |
| 374 } // namespace |
| 375 |
| 376 FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID, |
| 377 FileFormats fileFormat) { |
| 378 switch (fileFormat) { |
| 379 case kFileFormatWavFile: |
| 380 case kFileFormatCompressedFile: |
| 381 case kFileFormatPreencodedFile: |
| 382 case kFileFormatPcm16kHzFile: |
| 383 case kFileFormatPcm8kHzFile: |
| 384 case kFileFormatPcm32kHzFile: |
| 385 // audio formats |
| 386 return new FilePlayerImpl(instanceID, fileFormat); |
| 387 default: |
| 388 assert(false); |
| 389 return NULL; |
| 390 } |
| 391 } |
| 392 |
| 393 void FilePlayer::DestroyFilePlayer(FilePlayer* player) { |
| 394 delete player; |
| 395 } |
| 396 |
333 } // namespace webrtc | 397 } // namespace webrtc |
OLD | NEW |