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 11#ifndef WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H 12#define WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H 13 14#include "webrtc/voice_engine/include/voe_base.h" 15 16#include "webrtc/modules/interface/module_common_types.h" 17#include "webrtc/voice_engine/shared_data.h" 18 19namespace webrtc 20{ 21 22class ProcessThread; 23 24class VoEBaseImpl: public VoEBase, 25 public AudioTransport, 26 public AudioDeviceObserver 27{ 28public: 29 virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer); 30 31 virtual int DeRegisterVoiceEngineObserver(); 32 33 virtual int Init(AudioDeviceModule* external_adm = NULL, 34 AudioProcessing* audioproc = NULL); 35 virtual AudioProcessing* audio_processing() { 36 return _shared->audio_processing(); 37 } 38 39 virtual int Terminate(); 40 41 virtual int CreateChannel(); 42 virtual int CreateChannel(const Config& config); 43 44 virtual int DeleteChannel(int channel); 45 46 virtual int StartReceive(int channel); 47 48 virtual int StartPlayout(int channel); 49 50 virtual int StartSend(int channel); 51 52 virtual int StopReceive(int channel); 53 54 virtual int StopPlayout(int channel); 55 56 virtual int StopSend(int channel); 57 58 virtual int GetVersion(char version[1024]); 59 60 virtual int LastError(); 61 62 virtual AudioTransport* audio_transport() { return this; } 63 64 // AudioTransport 65 virtual int32_t 66 RecordedDataIsAvailable(const void* audioSamples, 67 uint32_t nSamples, 68 uint8_t nBytesPerSample, 69 uint8_t nChannels, 70 uint32_t samplesPerSec, 71 uint32_t totalDelayMS, 72 int32_t clockDrift, 73 uint32_t micLevel, 74 bool keyPressed, 75 uint32_t& newMicLevel); 76 77 virtual int32_t NeedMorePlayData(uint32_t nSamples, 78 uint8_t nBytesPerSample, 79 uint8_t nChannels, 80 uint32_t samplesPerSec, 81 void* audioSamples, 82 uint32_t& nSamplesOut, 83 int64_t* elapsed_time_ms, 84 int64_t* ntp_time_ms); 85 86 virtual int OnDataAvailable(const int voe_channels[], 87 int number_of_voe_channels, 88 const int16_t* audio_data, 89 int sample_rate, 90 int number_of_channels, 91 int number_of_frames, 92 int audio_delay_milliseconds, 93 int volume, 94 bool key_pressed, 95 bool need_audio_processing); 96 97 virtual void OnData(int voe_channel, const void* audio_data, 98 int bits_per_sample, int sample_rate, 99 int number_of_channels, int number_of_frames); 100 101 virtual void PushCaptureData(int voe_channel, const void* audio_data, 102 int bits_per_sample, int sample_rate, 103 int number_of_channels, int number_of_frames); 104 105 virtual void PullRenderData(int bits_per_sample, int sample_rate, 106 int number_of_channels, int number_of_frames, 107 void* audio_data, 108 int64_t* elapsed_time_ms, 109 int64_t* ntp_time_ms); 110 111 // AudioDeviceObserver 112 virtual void OnErrorIsReported(ErrorCode error); 113 virtual void OnWarningIsReported(WarningCode warning); 114 115protected: 116 VoEBaseImpl(voe::SharedData* shared); 117 virtual ~VoEBaseImpl(); 118 119private: 120 int32_t StartPlayout(); 121 int32_t StopPlayout(); 122 int32_t StartSend(); 123 int32_t StopSend(); 124 int32_t TerminateInternal(); 125 126 // Helper function to process the recorded data with AudioProcessing Module, 127 // demultiplex the data to specific voe channels, encode and send to the 128 // network. When |number_of_VoE_channels| is 0, it will demultiplex the 129 // data to all the existing VoE channels. 130 // It returns new AGC microphone volume or 0 if no volume changes 131 // should be done. 132 int ProcessRecordedDataWithAPM(const int voe_channels[], 133 int number_of_voe_channels, 134 const void* audio_data, 135 uint32_t sample_rate, 136 uint8_t number_of_channels, 137 uint32_t number_of_frames, 138 uint32_t audio_delay_milliseconds, 139 int32_t clock_drift, 140 uint32_t volume, 141 bool key_pressed); 142 143 void GetPlayoutData(int sample_rate, int number_of_channels, 144 int number_of_frames, bool feed_data_to_apm, 145 void* audio_data, 146 int64_t* elapsed_time_ms, 147 int64_t* ntp_time_ms); 148 149 int32_t AddBuildInfo(char* str) const; 150 int32_t AddVoEVersion(char* str) const; 151 152 // Initialize channel by setting Engine Information then initializing 153 // channel. 154 int InitializeChannel(voe::ChannelOwner* channel_owner); 155#ifdef WEBRTC_EXTERNAL_TRANSPORT 156 int32_t AddExternalTransportBuild(char* str) const; 157#endif 158 VoiceEngineObserver* _voiceEngineObserverPtr; 159 CriticalSectionWrapper& _callbackCritSect; 160 161 bool _voiceEngineObserver; 162 AudioFrame _audioFrame; 163 voe::SharedData* _shared; 164}; 165 166} // namespace webrtc 167 168#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H 169