OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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_MEDIA_ENGINE_WEBRTCVOICEENGINE_H_ | 11 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVOICEENGINE_H_ |
12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVOICEENGINE_H_ | 12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVOICEENGINE_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/audio_state.h" | 19 #include "webrtc/audio_state.h" |
20 #include "webrtc/base/buffer.h" | 20 #include "webrtc/base/buffer.h" |
21 #include "webrtc/base/networkroute.h" | 21 #include "webrtc/base/networkroute.h" |
| 22 #include "webrtc/base/scoped_ref_ptr.h" |
22 #include "webrtc/base/stream.h" | 23 #include "webrtc/base/stream.h" |
23 #include "webrtc/base/thread_checker.h" | 24 #include "webrtc/base/thread_checker.h" |
24 #include "webrtc/call.h" | 25 #include "webrtc/call.h" |
25 #include "webrtc/common.h" | 26 #include "webrtc/common.h" |
26 #include "webrtc/config.h" | 27 #include "webrtc/config.h" |
27 #include "webrtc/media/base/rtputils.h" | 28 #include "webrtc/media/base/rtputils.h" |
28 #include "webrtc/media/engine/webrtccommon.h" | 29 #include "webrtc/media/engine/webrtccommon.h" |
29 #include "webrtc/media/engine/webrtcvoe.h" | 30 #include "webrtc/media/engine/webrtcvoe.h" |
30 #include "webrtc/pc/channel.h" | 31 #include "webrtc/pc/channel.h" |
31 | 32 |
32 namespace cricket { | 33 namespace cricket { |
33 | 34 |
34 class AudioDeviceModule; | 35 class AudioDeviceModule; |
35 class AudioSource; | 36 class AudioSource; |
36 class VoEWrapper; | 37 class VoEWrapper; |
37 class WebRtcVoiceMediaChannel; | 38 class WebRtcVoiceMediaChannel; |
38 | 39 |
39 // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. | 40 // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. |
40 // It uses the WebRtc VoiceEngine library for audio handling. | 41 // It uses the WebRtc VoiceEngine library for audio handling. |
41 class WebRtcVoiceEngine final : public webrtc::TraceCallback { | 42 class WebRtcVoiceEngine final : public webrtc::TraceCallback { |
42 friend class WebRtcVoiceMediaChannel; | 43 friend class WebRtcVoiceMediaChannel; |
43 public: | 44 public: |
44 // Exposed for the WVoE/MC unit test. | 45 // Exposed for the WVoE/MC unit test. |
45 static bool ToCodecInst(const AudioCodec& in, webrtc::CodecInst* out); | 46 static bool ToCodecInst(const AudioCodec& in, webrtc::CodecInst* out); |
46 | 47 |
47 WebRtcVoiceEngine(); | 48 explicit WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm); |
48 // Dependency injection for testing. | 49 // Dependency injection for testing. |
49 explicit WebRtcVoiceEngine(VoEWrapper* voe_wrapper); | 50 WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm, VoEWrapper* voe_wrapper); |
50 ~WebRtcVoiceEngine(); | 51 ~WebRtcVoiceEngine() override; |
51 bool Init(rtc::Thread* worker_thread); | |
52 void Terminate(); | |
53 | 52 |
54 rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const; | 53 rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const; |
55 VoiceMediaChannel* CreateChannel(webrtc::Call* call, | 54 VoiceMediaChannel* CreateChannel(webrtc::Call* call, |
56 const MediaConfig& config, | 55 const MediaConfig& config, |
57 const AudioOptions& options); | 56 const AudioOptions& options); |
58 | 57 |
59 bool GetOutputVolume(int* level); | 58 bool GetOutputVolume(int* level); |
60 bool SetOutputVolume(int level); | 59 bool SetOutputVolume(int level); |
61 int GetInputLevel(); | 60 int GetInputLevel(); |
62 | 61 |
63 const std::vector<AudioCodec>& codecs(); | 62 const std::vector<AudioCodec>& codecs(); |
64 RtpCapabilities GetCapabilities() const; | 63 RtpCapabilities GetCapabilities() const; |
65 | 64 |
66 // For tracking WebRtc channels. Needed because we have to pause them | 65 // For tracking WebRtc channels. Needed because we have to pause them |
67 // all when switching devices. | 66 // all when switching devices. |
68 // May only be called by WebRtcVoiceMediaChannel. | 67 // May only be called by WebRtcVoiceMediaChannel. |
69 void RegisterChannel(WebRtcVoiceMediaChannel* channel); | 68 void RegisterChannel(WebRtcVoiceMediaChannel* channel); |
70 void UnregisterChannel(WebRtcVoiceMediaChannel* channel); | 69 void UnregisterChannel(WebRtcVoiceMediaChannel* channel); |
71 | 70 |
72 // Called by WebRtcVoiceMediaChannel to set a gain offset from | 71 // Called by WebRtcVoiceMediaChannel to set a gain offset from |
73 // the default AGC target level. | 72 // the default AGC target level. |
74 bool AdjustAgcLevel(int delta); | 73 bool AdjustAgcLevel(int delta); |
75 | 74 |
76 VoEWrapper* voe() { return voe_wrapper_.get(); } | 75 VoEWrapper* voe() { return voe_wrapper_.get(); } |
77 int GetLastEngineError(); | 76 int GetLastEngineError(); |
78 | 77 |
79 // Set the external ADM. This can only be called before Init. | |
80 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm); | |
81 | |
82 // Starts AEC dump using an existing file. A maximum file size in bytes can be | 78 // Starts AEC dump using an existing file. A maximum file size in bytes can be |
83 // specified. When the maximum file size is reached, logging is stopped and | 79 // specified. When the maximum file size is reached, logging is stopped and |
84 // the file is closed. If max_size_bytes is set to <= 0, no limit will be | 80 // the file is closed. If max_size_bytes is set to <= 0, no limit will be |
85 // used. | 81 // used. |
86 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); | 82 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
87 | 83 |
88 // Stops AEC dump. | 84 // Stops AEC dump. |
89 void StopAecDump(); | 85 void StopAecDump(); |
90 | 86 |
91 // Starts recording an RtcEventLog using an existing file until 10 minutes | 87 // Starts recording an RtcEventLog using an existing file until 10 minutes |
92 // pass or the StopRtcEventLog function is called. | 88 // pass or the StopRtcEventLog function is called. |
93 bool StartRtcEventLog(rtc::PlatformFile file); | 89 bool StartRtcEventLog(rtc::PlatformFile file); |
94 | 90 |
95 // Stops recording the RtcEventLog. | 91 // Stops recording the RtcEventLog. |
96 void StopRtcEventLog(); | 92 void StopRtcEventLog(); |
97 | 93 |
98 private: | 94 private: |
99 void Construct(); | |
100 bool InitInternal(); | |
101 // Every option that is "set" will be applied. Every option not "set" will be | 95 // Every option that is "set" will be applied. Every option not "set" will be |
102 // ignored. This allows us to selectively turn on and off different options | 96 // ignored. This allows us to selectively turn on and off different options |
103 // easily at any time. | 97 // easily at any time. |
104 bool ApplyOptions(const AudioOptions& options); | 98 bool ApplyOptions(const AudioOptions& options); |
105 void SetDefaultDevices(); | 99 void SetDefaultDevices(); |
106 | 100 |
107 // webrtc::TraceCallback: | 101 // webrtc::TraceCallback: |
108 void Print(webrtc::TraceLevel level, const char* trace, int length) override; | 102 void Print(webrtc::TraceLevel level, const char* trace, int length) override; |
109 | 103 |
110 void StartAecDump(const std::string& filename); | 104 void StartAecDump(const std::string& filename); |
111 int CreateVoEChannel(); | 105 int CreateVoEChannel(); |
112 | 106 |
113 rtc::ThreadChecker signal_thread_checker_; | 107 rtc::ThreadChecker signal_thread_checker_; |
114 rtc::ThreadChecker worker_thread_checker_; | 108 rtc::ThreadChecker worker_thread_checker_; |
115 | 109 |
| 110 // The audio device manager. |
| 111 rtc::scoped_refptr<webrtc::AudioDeviceModule> adm_; |
116 // The primary instance of WebRtc VoiceEngine. | 112 // The primary instance of WebRtc VoiceEngine. |
117 std::unique_ptr<VoEWrapper> voe_wrapper_; | 113 std::unique_ptr<VoEWrapper> voe_wrapper_; |
118 rtc::scoped_refptr<webrtc::AudioState> audio_state_; | 114 rtc::scoped_refptr<webrtc::AudioState> audio_state_; |
119 // The external audio device manager | |
120 webrtc::AudioDeviceModule* adm_ = nullptr; | |
121 std::vector<AudioCodec> codecs_; | 115 std::vector<AudioCodec> codecs_; |
122 std::vector<WebRtcVoiceMediaChannel*> channels_; | 116 std::vector<WebRtcVoiceMediaChannel*> channels_; |
123 webrtc::Config voe_config_; | 117 webrtc::Config voe_config_; |
124 bool initialized_ = false; | |
125 bool is_dumping_aec_ = false; | 118 bool is_dumping_aec_ = false; |
126 | 119 |
127 webrtc::AgcConfig default_agc_config_; | 120 webrtc::AgcConfig default_agc_config_; |
128 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns | 121 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns |
129 // values, and apply them in case they are missing in the audio options. We | 122 // values, and apply them in case they are missing in the audio options. We |
130 // need to do this because SetExtraOptions() will revert to defaults for | 123 // need to do this because SetExtraOptions() will revert to defaults for |
131 // options which are not provided. | 124 // options which are not provided. |
132 rtc::Optional<bool> extended_filter_aec_; | 125 rtc::Optional<bool> extended_filter_aec_; |
133 rtc::Optional<bool> delay_agnostic_aec_; | 126 rtc::Optional<bool> delay_agnostic_aec_; |
134 rtc::Optional<bool> experimental_ns_; | 127 rtc::Optional<bool> experimental_ns_; |
135 | 128 |
136 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcVoiceEngine); | 129 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceEngine); |
137 }; | 130 }; |
138 | 131 |
139 // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses | 132 // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses |
140 // WebRtc Voice Engine. | 133 // WebRtc Voice Engine. |
141 class WebRtcVoiceMediaChannel final : public VoiceMediaChannel, | 134 class WebRtcVoiceMediaChannel final : public VoiceMediaChannel, |
142 public webrtc::Transport { | 135 public webrtc::Transport { |
143 public: | 136 public: |
144 WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine, | 137 WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine, |
145 const MediaConfig& config, | 138 const MediaConfig& config, |
146 const AudioOptions& options, | 139 const AudioOptions& options, |
147 webrtc::Call* call); | 140 webrtc::Call* call); |
148 ~WebRtcVoiceMediaChannel() override; | 141 ~WebRtcVoiceMediaChannel() override; |
149 | 142 |
150 const AudioOptions& options() const { return options_; } | 143 const AudioOptions& options() const { return options_; } |
151 | 144 |
152 rtc::DiffServCodePoint PreferredDscp() const override; | 145 rtc::DiffServCodePoint PreferredDscp() const override; |
153 | 146 |
154 bool SetSendParameters(const AudioSendParameters& params) override; | 147 bool SetSendParameters(const AudioSendParameters& params) override; |
155 bool SetRecvParameters(const AudioRecvParameters& params) override; | 148 bool SetRecvParameters(const AudioRecvParameters& params) override; |
156 bool SetPlayout(bool playout) override; | 149 bool SetPlayout(bool playout) override; |
157 bool PausePlayout(); | 150 bool PausePlayout(); |
158 bool ResumePlayout(); | 151 bool ResumePlayout(); |
159 void SetSend(bool send) override; | 152 void SetSend(bool send) override; |
160 bool PauseSend(); | |
161 bool ResumeSend(); | |
162 bool SetAudioSend(uint32_t ssrc, | 153 bool SetAudioSend(uint32_t ssrc, |
163 bool enable, | 154 bool enable, |
164 const AudioOptions* options, | 155 const AudioOptions* options, |
165 AudioSource* source) override; | 156 AudioSource* source) override; |
166 bool AddSendStream(const StreamParams& sp) override; | 157 bool AddSendStream(const StreamParams& sp) override; |
167 bool RemoveSendStream(uint32_t ssrc) override; | 158 bool RemoveSendStream(uint32_t ssrc) override; |
168 bool AddRecvStream(const StreamParams& sp) override; | 159 bool AddRecvStream(const StreamParams& sp) override; |
169 bool RemoveRecvStream(uint32_t ssrc) override; | 160 bool RemoveRecvStream(uint32_t ssrc) override; |
170 bool GetActiveStreams(AudioInfo::StreamList* actives) override; | 161 bool GetActiveStreams(AudioInfo::StreamList* actives) override; |
171 int GetOutputLevel() override; | 162 int GetOutputLevel() override; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 int cng_payload_type = -1; | 276 int cng_payload_type = -1; |
286 int cng_plfreq = -1; | 277 int cng_plfreq = -1; |
287 webrtc::CodecInst codec_inst; | 278 webrtc::CodecInst codec_inst; |
288 } send_codec_spec_; | 279 } send_codec_spec_; |
289 | 280 |
290 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel); | 281 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel); |
291 }; | 282 }; |
292 } // namespace cricket | 283 } // namespace cricket |
293 | 284 |
294 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVOICEENGINE_H_ | 285 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVOICEENGINE_H_ |
OLD | NEW |