Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: talk/media/webrtc/webrtcvoiceengine.h

Issue 1403363003: Move VoiceEngineObserver into AudioSendStream so that we detect typing noises and return properly i… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: missing file Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 19 matching lines...) Expand all
30 30
31 #include <map> 31 #include <map>
32 #include <set> 32 #include <set>
33 #include <string> 33 #include <string>
34 #include <vector> 34 #include <vector>
35 35
36 #include "talk/media/base/rtputils.h" 36 #include "talk/media/base/rtputils.h"
37 #include "talk/media/webrtc/webrtccommon.h" 37 #include "talk/media/webrtc/webrtccommon.h"
38 #include "talk/media/webrtc/webrtcvoe.h" 38 #include "talk/media/webrtc/webrtcvoe.h"
39 #include "talk/session/media/channel.h" 39 #include "talk/session/media/channel.h"
40 #include "webrtc/audio_state.h"
40 #include "webrtc/base/buffer.h" 41 #include "webrtc/base/buffer.h"
41 #include "webrtc/base/byteorder.h" 42 #include "webrtc/base/byteorder.h"
42 #include "webrtc/base/logging.h" 43 #include "webrtc/base/logging.h"
43 #include "webrtc/base/scoped_ptr.h" 44 #include "webrtc/base/scoped_ptr.h"
44 #include "webrtc/base/stream.h" 45 #include "webrtc/base/stream.h"
45 #include "webrtc/base/thread_checker.h" 46 #include "webrtc/base/thread_checker.h"
46 #include "webrtc/call.h" 47 #include "webrtc/call.h"
47 #include "webrtc/common.h" 48 #include "webrtc/common.h"
48 #include "webrtc/config.h" 49 #include "webrtc/config.h"
49 50
50 namespace cricket { 51 namespace cricket {
51 52
52 class AudioDeviceModule; 53 class AudioDeviceModule;
53 class AudioRenderer; 54 class AudioRenderer;
54 class VoETraceWrapper; 55 class VoETraceWrapper;
55 class VoEWrapper; 56 class VoEWrapper;
56 class WebRtcVoiceMediaChannel; 57 class WebRtcVoiceMediaChannel;
57 58
58 // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. 59 // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine.
59 // It uses the WebRtc VoiceEngine library for audio handling. 60 // It uses the WebRtc VoiceEngine library for audio handling.
60 class WebRtcVoiceEngine 61 class WebRtcVoiceEngine final : public webrtc::TraceCallback {
61 : public webrtc::VoiceEngineObserver,
62 public webrtc::TraceCallback {
63 friend class WebRtcVoiceMediaChannel; 62 friend class WebRtcVoiceMediaChannel;
64 63
65 public: 64 public:
66 WebRtcVoiceEngine(); 65 WebRtcVoiceEngine();
67 // Dependency injection for testing. 66 // Dependency injection for testing.
68 WebRtcVoiceEngine(VoEWrapper* voe_wrapper, VoETraceWrapper* tracing); 67 WebRtcVoiceEngine(VoEWrapper* voe_wrapper,
68 VoETraceWrapper* tracing,
69 webrtc::AudioState* audio_state);
tommi 2015/11/02 13:46:53 if we were using linked_ptr, we'd have to pass tha
the sun 2015/11/03 12:41:07 Indeed. Turns out we don't need the AudioState for
69 ~WebRtcVoiceEngine(); 70 ~WebRtcVoiceEngine();
70 bool Init(rtc::Thread* worker_thread); 71 bool Init(rtc::Thread* worker_thread);
71 void Terminate(); 72 void Terminate();
72 73
73 webrtc::VoiceEngine* GetVoE() { return voe()->engine(); } 74 rtc::linked_ptr<webrtc::AudioState> GetAudioState() const {
tommi 2015/11/02 13:46:53 It would be nice to have a thread check here. or c
the sun 2015/11/03 12:41:07 No, it has the same life span as WVoE and VoE. Nev
75 return audio_state_;
76 }
74 VoiceMediaChannel* CreateChannel(webrtc::Call* call, 77 VoiceMediaChannel* CreateChannel(webrtc::Call* call,
75 const AudioOptions& options); 78 const AudioOptions& options);
76 79
77 AudioOptions GetOptions() const { return options_; } 80 AudioOptions GetOptions() const { return options_; }
78 bool SetOptions(const AudioOptions& options); 81 bool SetOptions(const AudioOptions& options);
79 bool SetDevices(const Device* in_device, const Device* out_device); 82 bool SetDevices(const Device* in_device, const Device* out_device);
80 bool GetOutputVolume(int* level); 83 bool GetOutputVolume(int* level);
81 bool SetOutputVolume(int level); 84 bool SetOutputVolume(int level);
82 int GetInputLevel(); 85 int GetInputLevel();
83 86
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 void SetTraceFilter(int filter); 129 void SetTraceFilter(int filter);
127 void SetTraceOptions(const std::string& options); 130 void SetTraceOptions(const std::string& options);
128 // Every option that is "set" will be applied. Every option not "set" will be 131 // Every option that is "set" will be applied. Every option not "set" will be
129 // ignored. This allows us to selectively turn on and off different options 132 // ignored. This allows us to selectively turn on and off different options
130 // easily at any time. 133 // easily at any time.
131 bool ApplyOptions(const AudioOptions& options); 134 bool ApplyOptions(const AudioOptions& options);
132 135
133 // webrtc::TraceCallback: 136 // webrtc::TraceCallback:
134 void Print(webrtc::TraceLevel level, const char* trace, int length) override; 137 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
135 138
136 // webrtc::VoiceEngineObserver:
137 void CallbackOnError(int channel_id, int errCode) override;
138
139 // Given the device type, name, and id, find device id. Return true and 139 // Given the device type, name, and id, find device id. Return true and
140 // set the output parameter rtc_id if successful. 140 // set the output parameter rtc_id if successful.
141 bool FindWebRtcAudioDeviceId( 141 bool FindWebRtcAudioDeviceId(
142 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id); 142 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
143 143
144 void StartAecDump(const std::string& filename); 144 void StartAecDump(const std::string& filename);
145 int CreateVoEChannel(); 145 int CreateVoEChannel();
146 146
147 static const int kDefaultLogSeverity = rtc::LS_WARNING; 147 static const int kDefaultLogSeverity = rtc::LS_WARNING;
148 148
149 // The primary instance of WebRtc VoiceEngine. 149 // The primary instance of WebRtc VoiceEngine.
150 rtc::scoped_ptr<VoEWrapper> voe_wrapper_; 150 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
151 rtc::scoped_ptr<VoETraceWrapper> tracing_; 151 rtc::scoped_ptr<VoETraceWrapper> tracing_;
152 rtc::linked_ptr<webrtc::AudioState> audio_state_;
152 // The external audio device manager 153 // The external audio device manager
153 webrtc::AudioDeviceModule* adm_; 154 webrtc::AudioDeviceModule* adm_ = nullptr;
154 int log_filter_; 155 int log_filter_;
155 std::string log_options_; 156 std::string log_options_;
156 bool is_dumping_aec_; 157 bool is_dumping_aec_ = false;
157 std::vector<AudioCodec> codecs_; 158 std::vector<AudioCodec> codecs_;
158 std::vector<RtpHeaderExtension> rtp_header_extensions_; 159 std::vector<RtpHeaderExtension> rtp_header_extensions_;
159 std::vector<WebRtcVoiceMediaChannel*> channels_; 160 std::vector<WebRtcVoiceMediaChannel*> channels_;
160 // channels_ can be read from WebRtc callback thread. We need a lock on that
161 // callback as well as the RegisterChannel/UnregisterChannel.
162 rtc::CriticalSection channels_cs_;
163 webrtc::AgcConfig default_agc_config_; 161 webrtc::AgcConfig default_agc_config_;
164 162
165 webrtc::Config voe_config_; 163 webrtc::Config voe_config_;
166 164
167 bool initialized_; 165 bool initialized_ = false;
168 AudioOptions options_; 166 AudioOptions options_;
169 167
170 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns 168 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns
171 // values, and apply them in case they are missing in the audio options. We 169 // values, and apply them in case they are missing in the audio options. We
172 // need to do this because SetExtraOptions() will revert to defaults for 170 // need to do this because SetExtraOptions() will revert to defaults for
173 // options which are not provided. 171 // options which are not provided.
174 Settable<bool> extended_filter_aec_; 172 Settable<bool> extended_filter_aec_;
175 Settable<bool> delay_agnostic_aec_; 173 Settable<bool> delay_agnostic_aec_;
176 Settable<bool> experimental_ns_; 174 Settable<bool> experimental_ns_;
177 175
178 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcVoiceEngine); 176 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcVoiceEngine);
179 }; 177 };
180 178
181 // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses 179 // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
182 // WebRtc Voice Engine. 180 // WebRtc Voice Engine.
183 class WebRtcVoiceMediaChannel : public VoiceMediaChannel, 181 class WebRtcVoiceMediaChannel final : public VoiceMediaChannel,
184 public webrtc::Transport { 182 public webrtc::Transport {
185 public: 183 public:
186 WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine, 184 WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine,
187 const AudioOptions& options, 185 const AudioOptions& options,
188 webrtc::Call* call); 186 webrtc::Call* call);
189 ~WebRtcVoiceMediaChannel() override; 187 ~WebRtcVoiceMediaChannel() override;
190 188
191 const AudioOptions& options() const { return options_; } 189 const AudioOptions& options() const { return options_; }
192 190
193 bool SetSendParameters(const AudioSendParameters& params) override; 191 bool SetSendParameters(const AudioSendParameters& params) override;
194 bool SetRecvParameters(const AudioRecvParameters& params) override; 192 bool SetRecvParameters(const AudioRecvParameters& params) override;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 rtc_options.packet_id = options.packet_id; 234 rtc_options.packet_id = options.packet_id;
237 return VoiceMediaChannel::SendPacket(&packet, rtc_options); 235 return VoiceMediaChannel::SendPacket(&packet, rtc_options);
238 } 236 }
239 237
240 bool SendRtcp(const uint8_t* data, size_t len) override { 238 bool SendRtcp(const uint8_t* data, size_t len) override {
241 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len, 239 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
242 kMaxRtpPacketLen); 240 kMaxRtpPacketLen);
243 return VoiceMediaChannel::SendRtcp(&packet, rtc::PacketOptions()); 241 return VoiceMediaChannel::SendRtcp(&packet, rtc::PacketOptions());
244 } 242 }
245 243
246 void OnError(int error);
247
248 int GetReceiveChannelId(uint32_t ssrc) const; 244 int GetReceiveChannelId(uint32_t ssrc) const;
249 int GetSendChannelId(uint32_t ssrc) const; 245 int GetSendChannelId(uint32_t ssrc) const;
250 246
251 private: 247 private:
252 bool SetSendCodecs(const std::vector<AudioCodec>& codecs); 248 bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
253 bool SetSendRtpHeaderExtensions( 249 bool SetSendRtpHeaderExtensions(
254 const std::vector<RtpHeaderExtension>& extensions); 250 const std::vector<RtpHeaderExtension>& extensions);
255 bool SetOptions(const AudioOptions& options); 251 bool SetOptions(const AudioOptions& options);
256 bool SetMaxSendBandwidth(int bps); 252 bool SetMaxSendBandwidth(int bps);
257 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs); 253 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs);
258 bool SetRecvRtpHeaderExtensions( 254 bool SetRecvRtpHeaderExtensions(
259 const std::vector<RtpHeaderExtension>& extensions); 255 const std::vector<RtpHeaderExtension>& extensions);
260 bool SetLocalRenderer(uint32_t ssrc, AudioRenderer* renderer); 256 bool SetLocalRenderer(uint32_t ssrc, AudioRenderer* renderer);
261 bool MuteStream(uint32_t ssrc, bool mute); 257 bool MuteStream(uint32_t ssrc, bool mute);
262 258
263 WebRtcVoiceEngine* engine() { return engine_; } 259 WebRtcVoiceEngine* engine() { return engine_; }
264 int GetLastEngineError() { return engine()->GetLastEngineError(); } 260 int GetLastEngineError() { return engine()->GetLastEngineError(); }
265 int GetOutputLevel(int channel); 261 int GetOutputLevel(int channel);
266 bool GetRedSendCodec(const AudioCodec& red_codec, 262 bool GetRedSendCodec(const AudioCodec& red_codec,
267 const std::vector<AudioCodec>& all_codecs, 263 const std::vector<AudioCodec>& all_codecs,
268 webrtc::CodecInst* send_codec); 264 webrtc::CodecInst* send_codec);
269 bool SetPlayout(int channel, bool playout); 265 bool SetPlayout(int channel, bool playout);
270 static Error WebRtcErrorToChannelError(int err_code);
271 266
272 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool, 267 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
273 unsigned char); 268 unsigned char);
274 269
275 void SetNack(int channel, bool nack_enabled); 270 void SetNack(int channel, bool nack_enabled);
276 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec); 271 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
277 bool ChangePlayout(bool playout); 272 bool ChangePlayout(bool playout);
278 bool ChangeSend(SendFlags send); 273 bool ChangeSend(SendFlags send);
279 bool ChangeSend(int channel, SendFlags send); 274 bool ChangeSend(int channel, SendFlags send);
280 bool ConfigureRecvChannel(int channel); 275 bool ConfigureRecvChannel(int channel);
(...skipping 14 matching lines...) Expand all
295 290
296 bool SetChannelRecvRtpHeaderExtensions( 291 bool SetChannelRecvRtpHeaderExtensions(
297 int channel_id, 292 int channel_id,
298 const std::vector<RtpHeaderExtension>& extensions); 293 const std::vector<RtpHeaderExtension>& extensions);
299 bool SetChannelSendRtpHeaderExtensions( 294 bool SetChannelSendRtpHeaderExtensions(
300 int channel_id, 295 int channel_id,
301 const std::vector<RtpHeaderExtension>& extensions); 296 const std::vector<RtpHeaderExtension>& extensions);
302 297
303 rtc::ThreadChecker thread_checker_; 298 rtc::ThreadChecker thread_checker_;
304 299
305 WebRtcVoiceEngine* const engine_; 300 WebRtcVoiceEngine* const engine_ = nullptr;
306 std::vector<AudioCodec> recv_codecs_; 301 std::vector<AudioCodec> recv_codecs_;
307 std::vector<AudioCodec> send_codecs_; 302 std::vector<AudioCodec> send_codecs_;
308 rtc::scoped_ptr<webrtc::CodecInst> send_codec_; 303 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
309 bool send_bitrate_setting_; 304 bool send_bitrate_setting_ = false;
310 int send_bitrate_bps_; 305 int send_bitrate_bps_ = 0;
311 AudioOptions options_; 306 AudioOptions options_;
312 bool dtmf_allowed_; 307 bool dtmf_allowed_ = false;
313 bool desired_playout_; 308 bool desired_playout_ = false;
314 bool nack_enabled_; 309 bool nack_enabled_ = false;
315 bool playout_; 310 bool playout_ = false;
316 bool typing_noise_detected_; 311 SendFlags desired_send_ = SEND_NOTHING;
317 SendFlags desired_send_; 312 SendFlags send_ = SEND_NOTHING;
318 SendFlags send_; 313 webrtc::Call* const call_ = nullptr;
319 webrtc::Call* const call_;
320 314
321 // SSRC of unsignalled receive stream, or -1 if there isn't one. 315 // SSRC of unsignalled receive stream, or -1 if there isn't one.
322 int64_t default_recv_ssrc_ = -1; 316 int64_t default_recv_ssrc_ = -1;
323 // Volume for unsignalled stream, which may be set before the stream exists. 317 // Volume for unsignalled stream, which may be set before the stream exists.
324 double default_recv_volume_ = 1.0; 318 double default_recv_volume_ = 1.0;
325 // SSRC to use for RTCP receiver reports; default to 1 in case of no signaled 319 // SSRC to use for RTCP receiver reports; default to 1 in case of no signaled
326 // send streams. See: https://code.google.com/p/webrtc/issues/detail?id=4740 320 // send streams. See: https://code.google.com/p/webrtc/issues/detail?id=4740
327 uint32_t receiver_reports_ssrc_ = 1; 321 uint32_t receiver_reports_ssrc_ = 1;
328 322
329 class WebRtcAudioSendStream; 323 class WebRtcAudioSendStream;
330 std::map<uint32_t, WebRtcAudioSendStream*> send_streams_; 324 std::map<uint32_t, WebRtcAudioSendStream*> send_streams_;
331 std::vector<RtpHeaderExtension> send_extensions_; 325 std::vector<RtpHeaderExtension> send_extensions_;
332 326
333 class WebRtcAudioReceiveStream; 327 class WebRtcAudioReceiveStream;
334 std::map<uint32_t, WebRtcAudioReceiveStream*> receive_channels_; 328 std::map<uint32_t, WebRtcAudioReceiveStream*> receive_channels_;
335 std::map<uint32_t, webrtc::AudioReceiveStream*> receive_streams_; 329 std::map<uint32_t, webrtc::AudioReceiveStream*> receive_streams_;
336 std::map<uint32_t, StreamParams> receive_stream_params_; 330 std::map<uint32_t, StreamParams> receive_stream_params_;
337 // receive_channels_ can be read from WebRtc callback thread. Access from 331 // receive_channels_ can be read from WebRtc callback thread. Access from
338 // the WebRtc thread must be synchronized with edits on the worker thread. 332 // the WebRtc thread must be synchronized with edits on the worker thread.
339 // Reads on the worker thread are ok. 333 // Reads on the worker thread are ok.
340 std::vector<RtpHeaderExtension> receive_extensions_; 334 std::vector<RtpHeaderExtension> receive_extensions_;
341 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; 335 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
342 336
343 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel); 337 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel);
344 }; 338 };
345
346 } // namespace cricket 339 } // namespace cricket
347 340
348 #endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_ 341 #endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698