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 |
(...skipping 25 matching lines...) Expand all Loading... |
36 class WebRtcVoiceMediaChannel; | 36 class WebRtcVoiceMediaChannel; |
37 | 37 |
38 // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. | 38 // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. |
39 // It uses the WebRtc VoiceEngine library for audio handling. | 39 // It uses the WebRtc VoiceEngine library for audio handling. |
40 class WebRtcVoiceEngine final : public webrtc::TraceCallback { | 40 class WebRtcVoiceEngine final : public webrtc::TraceCallback { |
41 friend class WebRtcVoiceMediaChannel; | 41 friend class WebRtcVoiceMediaChannel; |
42 public: | 42 public: |
43 // Exposed for the WVoE/MC unit test. | 43 // Exposed for the WVoE/MC unit test. |
44 static bool ToCodecInst(const AudioCodec& in, webrtc::CodecInst* out); | 44 static bool ToCodecInst(const AudioCodec& in, webrtc::CodecInst* out); |
45 | 45 |
46 WebRtcVoiceEngine(); | 46 explicit WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm); |
47 // Dependency injection for testing. | 47 // Dependency injection for testing. |
48 explicit WebRtcVoiceEngine(VoEWrapper* voe_wrapper); | 48 WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm, VoEWrapper* voe_wrapper); |
49 ~WebRtcVoiceEngine(); | 49 ~WebRtcVoiceEngine() override; |
50 bool Init(rtc::Thread* worker_thread); | 50 bool Init(); |
51 void Terminate(); | 51 void Terminate(); |
52 | 52 |
53 rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const; | 53 rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const; |
54 VoiceMediaChannel* CreateChannel(webrtc::Call* call, | 54 VoiceMediaChannel* CreateChannel(webrtc::Call* call, |
55 const MediaConfig& config, | 55 const MediaConfig& config, |
56 const AudioOptions& options); | 56 const AudioOptions& options); |
57 | 57 |
58 bool GetOutputVolume(int* level); | 58 bool GetOutputVolume(int* level); |
59 bool SetOutputVolume(int level); | 59 bool SetOutputVolume(int level); |
60 int GetInputLevel(); | 60 int GetInputLevel(); |
61 | 61 |
62 const std::vector<AudioCodec>& codecs(); | 62 const std::vector<AudioCodec>& codecs(); |
63 RtpCapabilities GetCapabilities() const; | 63 RtpCapabilities GetCapabilities() const; |
64 | 64 |
65 // For tracking WebRtc channels. Needed because we have to pause them | 65 // For tracking WebRtc channels. Needed because we have to pause them |
66 // all when switching devices. | 66 // all when switching devices. |
67 // May only be called by WebRtcVoiceMediaChannel. | 67 // May only be called by WebRtcVoiceMediaChannel. |
68 void RegisterChannel(WebRtcVoiceMediaChannel* channel); | 68 void RegisterChannel(WebRtcVoiceMediaChannel* channel); |
69 void UnregisterChannel(WebRtcVoiceMediaChannel* channel); | 69 void UnregisterChannel(WebRtcVoiceMediaChannel* channel); |
70 | 70 |
71 // Called by WebRtcVoiceMediaChannel to set a gain offset from | 71 // Called by WebRtcVoiceMediaChannel to set a gain offset from |
72 // the default AGC target level. | 72 // the default AGC target level. |
73 bool AdjustAgcLevel(int delta); | 73 bool AdjustAgcLevel(int delta); |
74 | 74 |
75 VoEWrapper* voe() { return voe_wrapper_.get(); } | 75 VoEWrapper* voe() { return voe_wrapper_.get(); } |
76 int GetLastEngineError(); | 76 int GetLastEngineError(); |
77 | 77 |
78 // Set the external ADM. This can only be called before Init. | |
79 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm); | |
80 | |
81 // 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 |
82 // 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 |
83 // 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 |
84 // used. | 81 // used. |
85 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); | 82 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
86 | 83 |
87 // Stops AEC dump. | 84 // Stops AEC dump. |
88 void StopAecDump(); | 85 void StopAecDump(); |
89 | 86 |
90 // Starts recording an RtcEventLog using an existing file until 10 minutes | 87 // Starts recording an RtcEventLog using an existing file until 10 minutes |
91 // pass or the StopRtcEventLog function is called. | 88 // pass or the StopRtcEventLog function is called. |
92 bool StartRtcEventLog(rtc::PlatformFile file); | 89 bool StartRtcEventLog(rtc::PlatformFile file); |
93 | 90 |
94 // Stops recording the RtcEventLog. | 91 // Stops recording the RtcEventLog. |
95 void StopRtcEventLog(); | 92 void StopRtcEventLog(); |
96 | 93 |
97 private: | 94 private: |
98 void Construct(); | |
99 bool InitInternal(); | |
100 // 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 |
101 // 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 |
102 // easily at any time. | 97 // easily at any time. |
103 bool ApplyOptions(const AudioOptions& options); | 98 bool ApplyOptions(const AudioOptions& options); |
104 void SetDefaultDevices(); | 99 void SetDefaultDevices(); |
105 | 100 |
106 // webrtc::TraceCallback: | 101 // webrtc::TraceCallback: |
107 void Print(webrtc::TraceLevel level, const char* trace, int length) override; | 102 void Print(webrtc::TraceLevel level, const char* trace, int length) override; |
108 | 103 |
109 void StartAecDump(const std::string& filename); | 104 void StartAecDump(const std::string& filename); |
110 int CreateVoEChannel(); | 105 int CreateVoEChannel(); |
111 | 106 |
112 rtc::ThreadChecker signal_thread_checker_; | 107 rtc::ThreadChecker signal_thread_checker_; |
113 rtc::ThreadChecker worker_thread_checker_; | 108 rtc::ThreadChecker worker_thread_checker_; |
114 | 109 |
115 // The primary instance of WebRtc VoiceEngine. | 110 // The primary instance of WebRtc VoiceEngine. |
116 std::unique_ptr<VoEWrapper> voe_wrapper_; | 111 std::unique_ptr<VoEWrapper> voe_wrapper_; |
117 rtc::scoped_refptr<webrtc::AudioState> audio_state_; | 112 rtc::scoped_refptr<webrtc::AudioState> audio_state_; |
118 // The external audio device manager | 113 // The external audio device manager |
119 webrtc::AudioDeviceModule* adm_ = nullptr; | 114 webrtc::AudioDeviceModule* adm_ = nullptr; |
120 std::vector<AudioCodec> codecs_; | 115 std::vector<AudioCodec> codecs_; |
121 std::vector<WebRtcVoiceMediaChannel*> channels_; | 116 std::vector<WebRtcVoiceMediaChannel*> channels_; |
122 webrtc::Config voe_config_; | 117 webrtc::Config voe_config_; |
123 bool initialized_ = false; | |
124 bool is_dumping_aec_ = false; | 118 bool is_dumping_aec_ = false; |
125 | 119 |
126 webrtc::AgcConfig default_agc_config_; | 120 webrtc::AgcConfig default_agc_config_; |
127 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns | 121 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns |
128 // 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 |
129 // need to do this because SetExtraOptions() will revert to defaults for | 123 // need to do this because SetExtraOptions() will revert to defaults for |
130 // options which are not provided. | 124 // options which are not provided. |
131 rtc::Optional<bool> extended_filter_aec_; | 125 rtc::Optional<bool> extended_filter_aec_; |
132 rtc::Optional<bool> delay_agnostic_aec_; | 126 rtc::Optional<bool> delay_agnostic_aec_; |
133 rtc::Optional<bool> experimental_ns_; | 127 rtc::Optional<bool> experimental_ns_; |
(...skipping 15 matching lines...) Expand all Loading... |
149 const AudioOptions& options() const { return options_; } | 143 const AudioOptions& options() const { return options_; } |
150 | 144 |
151 rtc::DiffServCodePoint PreferredDscp() const override; | 145 rtc::DiffServCodePoint PreferredDscp() const override; |
152 | 146 |
153 bool SetSendParameters(const AudioSendParameters& params) override; | 147 bool SetSendParameters(const AudioSendParameters& params) override; |
154 bool SetRecvParameters(const AudioRecvParameters& params) override; | 148 bool SetRecvParameters(const AudioRecvParameters& params) override; |
155 bool SetPlayout(bool playout) override; | 149 bool SetPlayout(bool playout) override; |
156 bool PausePlayout(); | 150 bool PausePlayout(); |
157 bool ResumePlayout(); | 151 bool ResumePlayout(); |
158 void SetSend(bool send) override; | 152 void SetSend(bool send) override; |
159 bool PauseSend(); | |
160 bool ResumeSend(); | |
161 bool SetAudioSend(uint32_t ssrc, | 153 bool SetAudioSend(uint32_t ssrc, |
162 bool enable, | 154 bool enable, |
163 const AudioOptions* options, | 155 const AudioOptions* options, |
164 AudioSource* source) override; | 156 AudioSource* source) override; |
165 bool AddSendStream(const StreamParams& sp) override; | 157 bool AddSendStream(const StreamParams& sp) override; |
166 bool RemoveSendStream(uint32_t ssrc) override; | 158 bool RemoveSendStream(uint32_t ssrc) override; |
167 bool AddRecvStream(const StreamParams& sp) override; | 159 bool AddRecvStream(const StreamParams& sp) override; |
168 bool RemoveRecvStream(uint32_t ssrc) override; | 160 bool RemoveRecvStream(uint32_t ssrc) override; |
169 bool GetActiveStreams(AudioInfo::StreamList* actives) override; | 161 bool GetActiveStreams(AudioInfo::StreamList* actives) override; |
170 int GetOutputLevel() override; | 162 int GetOutputLevel() override; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 int cng_payload_type = -1; | 274 int cng_payload_type = -1; |
283 int cng_plfreq = -1; | 275 int cng_plfreq = -1; |
284 webrtc::CodecInst codec_inst; | 276 webrtc::CodecInst codec_inst; |
285 } send_codec_spec_; | 277 } send_codec_spec_; |
286 | 278 |
287 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel); | 279 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel); |
288 }; | 280 }; |
289 } // namespace cricket | 281 } // namespace cricket |
290 | 282 |
291 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVOICEENGINE_H_ | 283 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVOICEENGINE_H_ |
OLD | NEW |