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