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

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

Powered by Google App Engine
This is Rietveld 408576698