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