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

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: that's all folks! (incl rebase), or is it? 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
« no previous file with comments | « talk/media/webrtc/fakewebrtccall.h ('k') | talk/media/webrtc/webrtcvoiceengine.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, VoETraceWrapper* tracing);
69 ~WebRtcVoiceEngine(); 68 ~WebRtcVoiceEngine();
70 bool Init(rtc::Thread* worker_thread); 69 bool Init(rtc::Thread* worker_thread);
71 void Terminate(); 70 void Terminate();
72 71
73 webrtc::VoiceEngine* GetVoE() { return voe()->engine(); } 72 rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const;
74 VoiceMediaChannel* CreateChannel(webrtc::Call* call, 73 VoiceMediaChannel* CreateChannel(webrtc::Call* call,
75 const AudioOptions& options); 74 const AudioOptions& options);
76 75
77 AudioOptions GetOptions() const { return options_; } 76 AudioOptions GetOptions() const { return options_; }
78 bool SetOptions(const AudioOptions& options); 77 bool SetOptions(const AudioOptions& options);
79 bool SetDevices(const Device* in_device, const Device* out_device); 78 bool SetDevices(const Device* in_device, const Device* out_device);
80 bool GetOutputVolume(int* level); 79 bool GetOutputVolume(int* level);
81 bool SetOutputVolume(int level); 80 bool SetOutputVolume(int level);
82 int GetInputLevel(); 81 int GetInputLevel();
83 82
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 void SetTraceFilter(int filter); 125 void SetTraceFilter(int filter);
127 void SetTraceOptions(const std::string& options); 126 void SetTraceOptions(const std::string& options);
128 // Every option that is "set" will be applied. Every option not "set" will be 127 // 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 128 // ignored. This allows us to selectively turn on and off different options
130 // easily at any time. 129 // easily at any time.
131 bool ApplyOptions(const AudioOptions& options); 130 bool ApplyOptions(const AudioOptions& options);
132 131
133 // webrtc::TraceCallback: 132 // webrtc::TraceCallback:
134 void Print(webrtc::TraceLevel level, const char* trace, int length) override; 133 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
135 134
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 135 // Given the device type, name, and id, find device id. Return true and
140 // set the output parameter rtc_id if successful. 136 // set the output parameter rtc_id if successful.
141 bool FindWebRtcAudioDeviceId( 137 bool FindWebRtcAudioDeviceId(
142 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id); 138 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
143 139
144 void StartAecDump(const std::string& filename); 140 void StartAecDump(const std::string& filename);
145 int CreateVoEChannel(); 141 int CreateVoEChannel();
146 142
147 static const int kDefaultLogSeverity = rtc::LS_WARNING; 143 static const int kDefaultLogSeverity = rtc::LS_WARNING;
148 144
145 rtc::ThreadChecker signal_thread_checker_;
146 rtc::ThreadChecker worker_thread_checker_;
147
149 // The primary instance of WebRtc VoiceEngine. 148 // The primary instance of WebRtc VoiceEngine.
150 rtc::scoped_ptr<VoEWrapper> voe_wrapper_; 149 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
151 rtc::scoped_ptr<VoETraceWrapper> tracing_; 150 rtc::scoped_ptr<VoETraceWrapper> tracing_;
151 rtc::scoped_refptr<webrtc::AudioState> audio_state_;
152 // The external audio device manager 152 // The external audio device manager
153 webrtc::AudioDeviceModule* adm_; 153 webrtc::AudioDeviceModule* adm_ = nullptr;
154 int log_filter_; 154 int log_filter_;
155 std::string log_options_; 155 std::string log_options_;
156 bool is_dumping_aec_; 156 bool is_dumping_aec_ = false;
157 std::vector<AudioCodec> codecs_; 157 std::vector<AudioCodec> codecs_;
158 std::vector<RtpHeaderExtension> rtp_header_extensions_; 158 std::vector<RtpHeaderExtension> rtp_header_extensions_;
159 std::vector<WebRtcVoiceMediaChannel*> channels_; 159 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_; 160 webrtc::AgcConfig default_agc_config_;
164 161
165 webrtc::Config voe_config_; 162 webrtc::Config voe_config_;
166 163
167 bool initialized_; 164 bool initialized_ = false;
168 AudioOptions options_; 165 AudioOptions options_;
169 166
170 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns 167 // 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 168 // 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 169 // need to do this because SetExtraOptions() will revert to defaults for
173 // options which are not provided. 170 // options which are not provided.
174 rtc::Maybe<bool> extended_filter_aec_; 171 rtc::Maybe<bool> extended_filter_aec_;
175 rtc::Maybe<bool> delay_agnostic_aec_; 172 rtc::Maybe<bool> delay_agnostic_aec_;
176 rtc::Maybe<bool> experimental_ns_; 173 rtc::Maybe<bool> experimental_ns_;
177 174
178 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcVoiceEngine); 175 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcVoiceEngine);
179 }; 176 };
180 177
181 // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses 178 // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
182 // WebRtc Voice Engine. 179 // WebRtc Voice Engine.
183 class WebRtcVoiceMediaChannel : public VoiceMediaChannel, 180 class WebRtcVoiceMediaChannel final : public VoiceMediaChannel,
184 public webrtc::Transport { 181 public webrtc::Transport {
185 public: 182 public:
186 WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine, 183 WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine,
187 const AudioOptions& options, 184 const AudioOptions& options,
188 webrtc::Call* call); 185 webrtc::Call* call);
189 ~WebRtcVoiceMediaChannel() override; 186 ~WebRtcVoiceMediaChannel() override;
190 187
191 const AudioOptions& options() const { return options_; } 188 const AudioOptions& options() const { return options_; }
192 189
193 bool SetSendParameters(const AudioSendParameters& params) override; 190 bool SetSendParameters(const AudioSendParameters& params) override;
194 bool SetRecvParameters(const AudioRecvParameters& params) override; 191 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; 233 rtc_options.packet_id = options.packet_id;
237 return VoiceMediaChannel::SendPacket(&packet, rtc_options); 234 return VoiceMediaChannel::SendPacket(&packet, rtc_options);
238 } 235 }
239 236
240 bool SendRtcp(const uint8_t* data, size_t len) override { 237 bool SendRtcp(const uint8_t* data, size_t len) override {
241 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len, 238 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
242 kMaxRtpPacketLen); 239 kMaxRtpPacketLen);
243 return VoiceMediaChannel::SendRtcp(&packet, rtc::PacketOptions()); 240 return VoiceMediaChannel::SendRtcp(&packet, rtc::PacketOptions());
244 } 241 }
245 242
246 void OnError(int error);
247
248 int GetReceiveChannelId(uint32_t ssrc) const; 243 int GetReceiveChannelId(uint32_t ssrc) const;
249 int GetSendChannelId(uint32_t ssrc) const; 244 int GetSendChannelId(uint32_t ssrc) const;
250 245
251 private: 246 private:
252 bool SetSendCodecs(const std::vector<AudioCodec>& codecs); 247 bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
253 bool SetSendRtpHeaderExtensions( 248 bool SetSendRtpHeaderExtensions(
254 const std::vector<RtpHeaderExtension>& extensions); 249 const std::vector<RtpHeaderExtension>& extensions);
255 bool SetOptions(const AudioOptions& options); 250 bool SetOptions(const AudioOptions& options);
256 bool SetMaxSendBandwidth(int bps); 251 bool SetMaxSendBandwidth(int bps);
257 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs); 252 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs);
258 bool SetRecvRtpHeaderExtensions( 253 bool SetRecvRtpHeaderExtensions(
259 const std::vector<RtpHeaderExtension>& extensions); 254 const std::vector<RtpHeaderExtension>& extensions);
260 bool SetLocalRenderer(uint32_t ssrc, AudioRenderer* renderer); 255 bool SetLocalRenderer(uint32_t ssrc, AudioRenderer* renderer);
261 bool MuteStream(uint32_t ssrc, bool mute); 256 bool MuteStream(uint32_t ssrc, bool mute);
262 257
263 WebRtcVoiceEngine* engine() { return engine_; } 258 WebRtcVoiceEngine* engine() { return engine_; }
264 int GetLastEngineError() { return engine()->GetLastEngineError(); } 259 int GetLastEngineError() { return engine()->GetLastEngineError(); }
265 int GetOutputLevel(int channel); 260 int GetOutputLevel(int channel);
266 bool GetRedSendCodec(const AudioCodec& red_codec, 261 bool GetRedSendCodec(const AudioCodec& red_codec,
267 const std::vector<AudioCodec>& all_codecs, 262 const std::vector<AudioCodec>& all_codecs,
268 webrtc::CodecInst* send_codec); 263 webrtc::CodecInst* send_codec);
269 bool SetPlayout(int channel, bool playout); 264 bool SetPlayout(int channel, bool playout);
270 static Error WebRtcErrorToChannelError(int err_code);
271 265
272 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool, 266 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
273 unsigned char); 267 unsigned char);
274 268
275 void SetNack(int channel, bool nack_enabled); 269 void SetNack(int channel, bool nack_enabled);
276 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec); 270 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
277 bool ChangePlayout(bool playout); 271 bool ChangePlayout(bool playout);
278 bool ChangeSend(SendFlags send); 272 bool ChangeSend(SendFlags send);
279 bool ChangeSend(int channel, SendFlags send); 273 bool ChangeSend(int channel, SendFlags send);
280 bool ConfigureRecvChannel(int channel); 274 bool ConfigureRecvChannel(int channel);
(...skipping 12 matching lines...) Expand all
293 void RemoveAudioReceiveStream(uint32_t ssrc); 287 void RemoveAudioReceiveStream(uint32_t ssrc);
294 bool SetRecvCodecsInternal(const std::vector<AudioCodec>& new_codecs); 288 bool SetRecvCodecsInternal(const std::vector<AudioCodec>& new_codecs);
295 289
296 bool SetChannelRecvRtpHeaderExtensions( 290 bool SetChannelRecvRtpHeaderExtensions(
297 int channel_id, 291 int channel_id,
298 const std::vector<RtpHeaderExtension>& extensions); 292 const std::vector<RtpHeaderExtension>& extensions);
299 bool SetChannelSendRtpHeaderExtensions( 293 bool SetChannelSendRtpHeaderExtensions(
300 int channel_id, 294 int channel_id,
301 const std::vector<RtpHeaderExtension>& extensions); 295 const std::vector<RtpHeaderExtension>& extensions);
302 296
303 rtc::ThreadChecker thread_checker_; 297 rtc::ThreadChecker worker_thread_checker_;
304 298
305 WebRtcVoiceEngine* const engine_; 299 WebRtcVoiceEngine* const engine_ = nullptr;
306 std::vector<AudioCodec> recv_codecs_; 300 std::vector<AudioCodec> recv_codecs_;
307 std::vector<AudioCodec> send_codecs_; 301 std::vector<AudioCodec> send_codecs_;
308 rtc::scoped_ptr<webrtc::CodecInst> send_codec_; 302 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
309 bool send_bitrate_setting_; 303 bool send_bitrate_setting_ = false;
310 int send_bitrate_bps_; 304 int send_bitrate_bps_ = 0;
311 AudioOptions options_; 305 AudioOptions options_;
312 bool dtmf_allowed_; 306 bool dtmf_allowed_ = false;
313 bool desired_playout_; 307 bool desired_playout_ = false;
314 bool nack_enabled_; 308 bool nack_enabled_ = false;
315 bool playout_; 309 bool playout_ = false;
316 bool typing_noise_detected_; 310 SendFlags desired_send_ = SEND_NOTHING;
317 SendFlags desired_send_; 311 SendFlags send_ = SEND_NOTHING;
318 SendFlags send_; 312 webrtc::Call* const call_ = nullptr;
319 webrtc::Call* const call_;
320 313
321 // SSRC of unsignalled receive stream, or -1 if there isn't one. 314 // SSRC of unsignalled receive stream, or -1 if there isn't one.
322 int64_t default_recv_ssrc_ = -1; 315 int64_t default_recv_ssrc_ = -1;
323 // Volume for unsignalled stream, which may be set before the stream exists. 316 // Volume for unsignalled stream, which may be set before the stream exists.
324 double default_recv_volume_ = 1.0; 317 double default_recv_volume_ = 1.0;
325 // SSRC to use for RTCP receiver reports; default to 1 in case of no signaled 318 // 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 319 // send streams. See: https://code.google.com/p/webrtc/issues/detail?id=4740
327 uint32_t receiver_reports_ssrc_ = 1; 320 uint32_t receiver_reports_ssrc_ = 1;
328 321
329 class WebRtcAudioSendStream; 322 class WebRtcAudioSendStream;
330 std::map<uint32_t, WebRtcAudioSendStream*> send_streams_; 323 std::map<uint32_t, WebRtcAudioSendStream*> send_streams_;
331 std::vector<RtpHeaderExtension> send_extensions_; 324 std::vector<RtpHeaderExtension> send_extensions_;
332 325
333 class WebRtcAudioReceiveStream; 326 class WebRtcAudioReceiveStream;
334 std::map<uint32_t, WebRtcAudioReceiveStream*> receive_channels_; 327 std::map<uint32_t, WebRtcAudioReceiveStream*> receive_channels_;
335 std::map<uint32_t, webrtc::AudioReceiveStream*> receive_streams_; 328 std::map<uint32_t, webrtc::AudioReceiveStream*> receive_streams_;
336 std::map<uint32_t, StreamParams> receive_stream_params_; 329 std::map<uint32_t, StreamParams> receive_stream_params_;
337 // receive_channels_ can be read from WebRtc callback thread. Access from 330 // receive_channels_ can be read from WebRtc callback thread. Access from
338 // the WebRtc thread must be synchronized with edits on the worker thread. 331 // the WebRtc thread must be synchronized with edits on the worker thread.
339 // Reads on the worker thread are ok. 332 // Reads on the worker thread are ok.
340 std::vector<RtpHeaderExtension> receive_extensions_; 333 std::vector<RtpHeaderExtension> receive_extensions_;
341 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; 334 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
342 335
343 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel); 336 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel);
344 }; 337 };
345
346 } // namespace cricket 338 } // namespace cricket
347 339
348 #endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_ 340 #endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_
OLDNEW
« no previous file with comments | « talk/media/webrtc/fakewebrtccall.h ('k') | talk/media/webrtc/webrtcvoiceengine.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698