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