Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 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 | #ifndef WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_ |
| 12 | #define WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_ |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 13 | |
| 14 | #include "webrtc/common_types.h" |
| 15 | #include "webrtc/engine_configurations.h" |
| 16 | #include "webrtc/modules/include/module_common_types.h" |
| 17 | #include "webrtc/typedefs.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | class FileCallback; |
| 21 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 22 | class FilePlayer { |
| 23 | public: |
| 24 | // The largest decoded frame size in samples (60ms with 32kHz sample rate). |
| 25 | enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 32 }; |
| 26 | enum { MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES * 2 }; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 27 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 28 | // Note: will return NULL for unsupported formats. |
| 29 | static FilePlayer* CreateFilePlayer(const uint32_t instanceID, |
| 30 | const FileFormats fileFormat); |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 31 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 32 | static void DestroyFilePlayer(FilePlayer* player); |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 33 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 34 | // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples| |
| 35 | // will be set to the number of samples read (not the number of samples per |
| 36 | // channel). |
| 37 | virtual int Get10msAudioFromFile(int16_t* outBuffer, |
| 38 | size_t& lengthInSamples, |
| 39 | int frequencyInHz) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 40 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 41 | // Register callback for receiving file playing notifications. |
| 42 | virtual int32_t RegisterModuleFileCallback(FileCallback* callback) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 43 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 44 | // API for playing audio from fileName to channel. |
| 45 | // Note: codecInst is used for pre-encoded files. |
| 46 | virtual int32_t StartPlayingFile(const char* fileName, |
| 47 | bool loop, |
| 48 | uint32_t startPosition, |
| 49 | float volumeScaling, |
| 50 | uint32_t notification, |
| 51 | uint32_t stopPosition = 0, |
| 52 | const CodecInst* codecInst = NULL) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 53 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 54 | // Note: codecInst is used for pre-encoded files. |
| 55 | virtual int32_t StartPlayingFile(InStream& sourceStream, |
| 56 | uint32_t startPosition, |
| 57 | float volumeScaling, |
| 58 | uint32_t notification, |
| 59 | uint32_t stopPosition = 0, |
| 60 | const CodecInst* codecInst = NULL) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 61 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 62 | virtual int32_t StopPlayingFile() = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 63 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 64 | virtual bool IsPlayingFile() const = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 65 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 66 | virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 67 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 68 | // Set audioCodec to the currently used audio codec. |
| 69 | virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 70 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 71 | virtual int32_t Frequency() const = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 72 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 73 | // Note: scaleFactor is in the range [0.0 - 2.0] |
| 74 | virtual int32_t SetAudioScaling(float scaleFactor) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 75 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 76 | protected: |
| 77 | virtual ~FilePlayer() {} |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 78 | }; |
| 79 | } // namespace webrtc |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 80 | #endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_ |