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 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 16 | #include "webrtc/common_types.h" |
| 17 | #include "webrtc/engine_configurations.h" |
| 18 | #include "webrtc/modules/include/module_common_types.h" |
| 19 | #include "webrtc/typedefs.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 22 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 23 | class FileCallback; |
| 24 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 25 | class FilePlayer { |
| 26 | public: |
| 27 | // The largest decoded frame size in samples (60ms with 32kHz sample rate). |
| 28 | enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 32 }; |
| 29 | enum { MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES * 2 }; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 30 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 31 | // Note: will return NULL for unsupported formats. |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 32 | static std::unique_ptr<FilePlayer> NewFilePlayer( |
| 33 | const uint32_t instanceID, |
| 34 | const FileFormats fileFormat); |
| 35 | |
| 36 | // Deprecated creation/destruction functions. Use NewFilePlayer instead. |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 37 | static FilePlayer* CreateFilePlayer(const uint32_t instanceID, |
| 38 | const FileFormats fileFormat); |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 39 | static void DestroyFilePlayer(FilePlayer* player); |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 40 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 41 | virtual ~FilePlayer() = default; |
| 42 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 43 | // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples| |
| 44 | // will be set to the number of samples read (not the number of samples per |
| 45 | // channel). |
| 46 | virtual int Get10msAudioFromFile(int16_t* outBuffer, |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 47 | size_t* lengthInSamples, |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 48 | int frequencyInHz) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 49 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 50 | // Register callback for receiving file playing notifications. |
| 51 | virtual int32_t RegisterModuleFileCallback(FileCallback* callback) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 52 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 53 | // API for playing audio from fileName to channel. |
| 54 | // Note: codecInst is used for pre-encoded files. |
| 55 | virtual int32_t StartPlayingFile(const char* fileName, |
| 56 | bool loop, |
| 57 | uint32_t startPosition, |
| 58 | float volumeScaling, |
| 59 | uint32_t notification, |
kwiberg | d22854b | 2016-08-17 09:27:02 -0700 | [diff] [blame] | 60 | uint32_t stopPosition, |
| 61 | const CodecInst* codecInst) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 62 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 63 | // Note: codecInst is used for pre-encoded files. |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 64 | virtual int32_t StartPlayingFile(InStream* sourceStream, |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 65 | uint32_t startPosition, |
| 66 | float volumeScaling, |
| 67 | uint32_t notification, |
kwiberg | d22854b | 2016-08-17 09:27:02 -0700 | [diff] [blame] | 68 | uint32_t stopPosition, |
| 69 | const CodecInst* codecInst) = 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 StopPlayingFile() = 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 | virtual bool IsPlayingFile() const = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 74 | |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 75 | virtual int32_t GetPlayoutPosition(uint32_t* durationMs) = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 76 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 77 | // Set audioCodec to the currently used audio codec. |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 78 | virtual int32_t AudioCodec(CodecInst* audioCodec) const = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 79 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 80 | virtual int32_t Frequency() const = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 81 | |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 82 | // Note: scaleFactor is in the range [0.0 - 2.0] |
| 83 | virtual int32_t SetAudioScaling(float scaleFactor) = 0; |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 84 | |
| 85 | // Deprecated functions. Use the functions above with the same name instead. |
| 86 | int Get10msAudioFromFile(int16_t* outBuffer, |
| 87 | size_t& lengthInSamples, |
| 88 | int frequencyInHz) { |
| 89 | return Get10msAudioFromFile(outBuffer, &lengthInSamples, frequencyInHz); |
| 90 | } |
| 91 | int32_t StartPlayingFile(InStream& sourceStream, |
| 92 | uint32_t startPosition, |
| 93 | float volumeScaling, |
| 94 | uint32_t notification, |
| 95 | uint32_t stopPosition, |
| 96 | const CodecInst* codecInst) { |
| 97 | return StartPlayingFile(&sourceStream, startPosition, volumeScaling, |
| 98 | notification, stopPosition, codecInst); |
| 99 | } |
| 100 | int32_t GetPlayoutPosition(uint32_t& durationMs) { |
| 101 | return GetPlayoutPosition(&durationMs); |
| 102 | } |
| 103 | int32_t AudioCodec(CodecInst& audioCodec) const { |
| 104 | return AudioCodec(&audioCodec); |
| 105 | } |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 106 | }; |
| 107 | } // namespace webrtc |
kwiberg | a06ce49 | 2016-08-16 05:35:24 -0700 | [diff] [blame] | 108 | #endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_ |