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