niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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 | |
| 11 | // This sub-API supports the following functionalities: |
| 12 | // |
| 13 | // - File playback. |
| 14 | // - File recording. |
| 15 | // - File conversion. |
| 16 | // |
| 17 | // Usage example, omitting error checking: |
| 18 | // |
| 19 | // using namespace webrtc; |
| 20 | // VoiceEngine* voe = VoiceEngine::Create(); |
| 21 | // VoEBase* base = VoEBase::GetInterface(voe); |
| 22 | // VoEFile* file = VoEFile::GetInterface(voe); |
| 23 | // base->Init(); |
| 24 | // int ch = base->CreateChannel(); |
| 25 | // ... |
| 26 | // base->StartPlayout(ch); |
| 27 | // file->StartPlayingFileAsMicrophone(ch, "data_file_16kHz.pcm", true); |
| 28 | // ... |
| 29 | // file->StopPlayingFileAsMicrophone(ch); |
| 30 | // base->StopPlayout(ch); |
| 31 | // ... |
| 32 | // base->DeleteChannel(ch); |
| 33 | // base->Terminate(); |
| 34 | // base->Release(); |
| 35 | // file->Release(); |
| 36 | // VoiceEngine::Delete(voe); |
| 37 | // |
| 38 | #ifndef WEBRTC_VOICE_ENGINE_VOE_FILE_H |
| 39 | #define WEBRTC_VOICE_ENGINE_VOE_FILE_H |
| 40 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 41 | #include "webrtc/common_types.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
| 43 | namespace webrtc { |
| 44 | |
| 45 | class VoiceEngine; |
| 46 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 47 | class WEBRTC_DLLEXPORT VoEFile { |
| 48 | public: |
| 49 | // Factory for the VoEFile sub-API. Increases an internal |
| 50 | // reference counter if successful. Returns NULL if the API is not |
| 51 | // supported or if construction fails. |
| 52 | static VoEFile* GetInterface(VoiceEngine* voiceEngine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 54 | // Releases the VoEFile sub-API and decreases an internal |
| 55 | // reference counter. Returns the new reference count. This value should |
| 56 | // be zero for all sub-API:s before the VoiceEngine object can be safely |
| 57 | // deleted. |
| 58 | virtual int Release() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 60 | // Starts playing and mixing files with the local speaker signal for |
| 61 | // playout. |
| 62 | virtual int StartPlayingFileLocally( |
| 63 | int channel, |
| 64 | const char fileNameUTF8[1024], |
| 65 | bool loop = false, |
| 66 | FileFormats format = kFileFormatPcm16kHzFile, |
| 67 | float volumeScaling = 1.0, |
| 68 | int startPointMs = 0, |
| 69 | int stopPointMs = 0) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 71 | // Starts playing and mixing streams with the local speaker signal for |
| 72 | // playout. |
| 73 | virtual int StartPlayingFileLocally( |
| 74 | int channel, |
| 75 | InStream* stream, |
| 76 | FileFormats format = kFileFormatPcm16kHzFile, |
| 77 | float volumeScaling = 1.0, |
| 78 | int startPointMs = 0, |
| 79 | int stopPointMs = 0) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 81 | // Stops playback of a file on a specific |channel|. |
| 82 | virtual int StopPlayingFileLocally(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 84 | // Returns the current file playing state for a specific |channel|. |
| 85 | virtual int IsPlayingFileLocally(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 87 | // Starts reading data from a file and transmits the data either |
| 88 | // mixed with or instead of the microphone signal. |
| 89 | virtual int StartPlayingFileAsMicrophone( |
| 90 | int channel, |
| 91 | const char fileNameUTF8[1024], |
| 92 | bool loop = false, |
| 93 | bool mixWithMicrophone = false, |
| 94 | FileFormats format = kFileFormatPcm16kHzFile, |
| 95 | float volumeScaling = 1.0) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 97 | // Starts reading data from a stream and transmits the data either |
| 98 | // mixed with or instead of the microphone signal. |
| 99 | virtual int StartPlayingFileAsMicrophone( |
| 100 | int channel, |
| 101 | InStream* stream, |
| 102 | bool mixWithMicrophone = false, |
| 103 | FileFormats format = kFileFormatPcm16kHzFile, |
| 104 | float volumeScaling = 1.0) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 106 | // Stops playing of a file as microphone signal for a specific |channel|. |
| 107 | virtual int StopPlayingFileAsMicrophone(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 109 | // Returns whether the |channel| is currently playing a file as microphone. |
| 110 | virtual int IsPlayingFileAsMicrophone(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 112 | // Starts recording the mixed playout audio. |
| 113 | virtual int StartRecordingPlayout(int channel, |
| 114 | const char* fileNameUTF8, |
| 115 | CodecInst* compression = NULL, |
| 116 | int maxSizeBytes = -1) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 118 | // Stops recording the mixed playout audio. |
| 119 | virtual int StopRecordingPlayout(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 121 | virtual int StartRecordingPlayout(int channel, |
| 122 | OutStream* stream, |
| 123 | CodecInst* compression = NULL) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 124 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 125 | // Starts recording the microphone signal to a file. |
| 126 | virtual int StartRecordingMicrophone(const char* fileNameUTF8, |
| 127 | CodecInst* compression = NULL, |
| 128 | int maxSizeBytes = -1) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 130 | // Starts recording the microphone signal to a stream. |
| 131 | virtual int StartRecordingMicrophone(OutStream* stream, |
| 132 | CodecInst* compression = NULL) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 134 | // Stops recording the microphone signal. |
| 135 | virtual int StopRecordingMicrophone() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame^] | 137 | // Don't use. To be removed. |
| 138 | virtual int ScaleLocalFilePlayout(int channel, float scale) { return -1; } |
| 139 | virtual int ScaleFileAsMicrophonePlayout(int channel, float scale) { |
| 140 | return -1; |
| 141 | } |
| 142 | virtual int GetFileDuration(const char* fileNameUTF8, |
| 143 | int& durationMs, |
| 144 | FileFormats format = kFileFormatPcm16kHzFile) { |
| 145 | return -1; |
| 146 | } |
| 147 | virtual int GetPlaybackPosition(int channel, int& positionMs) { return -1; } |
| 148 | virtual int ConvertPCMToWAV(const char* fileNameInUTF8, |
| 149 | const char* fileNameOutUTF8) { |
| 150 | return -1; |
| 151 | } |
| 152 | virtual int ConvertPCMToWAV(InStream* streamIn, OutStream* streamOut) { |
| 153 | return -1; |
| 154 | } |
| 155 | virtual int ConvertWAVToPCM(const char* fileNameInUTF8, |
| 156 | const char* fileNameOutUTF8) { |
| 157 | return -1; |
| 158 | } |
| 159 | virtual int ConvertWAVToPCM(InStream* streamIn, OutStream* streamOut) { |
| 160 | return -1; |
| 161 | } |
| 162 | virtual int ConvertPCMToCompressed(const char* fileNameInUTF8, |
| 163 | const char* fileNameOutUTF8, |
| 164 | CodecInst* compression) { |
| 165 | return -1; |
| 166 | } |
| 167 | virtual int ConvertPCMToCompressed(InStream* streamIn, |
| 168 | OutStream* streamOut, |
| 169 | CodecInst* compression) { |
| 170 | return -1; |
| 171 | } |
| 172 | virtual int ConvertCompressedToPCM(const char* fileNameInUTF8, |
| 173 | const char* fileNameOutUTF8) { |
| 174 | return -1; |
| 175 | } |
| 176 | virtual int ConvertCompressedToPCM(InStream* streamIn, OutStream* streamOut) { |
| 177 | return -1; |
| 178 | } |
| 179 | |
| 180 | protected: |
| 181 | VoEFile() {} |
| 182 | virtual ~VoEFile() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | } // namespace webrtc |
| 186 | |
| 187 | #endif // WEBRTC_VOICE_ENGINE_VOE_FILE_H |