diff options
Diffstat (limited to 'talk/media/webrtc/webrtcvoiceengine.h')
-rw-r--r-- | talk/media/webrtc/webrtcvoiceengine.h | 145 |
1 files changed, 43 insertions, 102 deletions
diff --git a/talk/media/webrtc/webrtcvoiceengine.h b/talk/media/webrtc/webrtcvoiceengine.h index 1cf05e71a2..0f2f59e492 100644 --- a/talk/media/webrtc/webrtcvoiceengine.h +++ b/talk/media/webrtc/webrtcvoiceengine.h @@ -29,7 +29,6 @@ #define TALK_MEDIA_WEBRTCVOICEENGINE_H_ #include <map> -#include <set> #include <string> #include <vector> @@ -37,9 +36,8 @@ #include "talk/media/webrtc/webrtccommon.h" #include "talk/media/webrtc/webrtcvoe.h" #include "talk/session/media/channel.h" +#include "webrtc/audio_state.h" #include "webrtc/base/buffer.h" -#include "webrtc/base/byteorder.h" -#include "webrtc/base/logging.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/base/stream.h" #include "webrtc/base/thread_checker.h" @@ -51,43 +49,34 @@ namespace cricket { class AudioDeviceModule; class AudioRenderer; -class VoETraceWrapper; class VoEWrapper; class WebRtcVoiceMediaChannel; // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. // It uses the WebRtc VoiceEngine library for audio handling. -class WebRtcVoiceEngine - : public webrtc::VoiceEngineObserver, - public webrtc::TraceCallback { +class WebRtcVoiceEngine final : public webrtc::TraceCallback { friend class WebRtcVoiceMediaChannel; - public: + // Exposed for the WVoE/MC unit test. + static bool ToCodecInst(const AudioCodec& in, webrtc::CodecInst* out); + WebRtcVoiceEngine(); // Dependency injection for testing. - WebRtcVoiceEngine(VoEWrapper* voe_wrapper, VoETraceWrapper* tracing); + explicit WebRtcVoiceEngine(VoEWrapper* voe_wrapper); ~WebRtcVoiceEngine(); bool Init(rtc::Thread* worker_thread); void Terminate(); - webrtc::VoiceEngine* GetVoE() { return voe()->engine(); } + rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const; VoiceMediaChannel* CreateChannel(webrtc::Call* call, const AudioOptions& options); - AudioOptions GetOptions() const { return options_; } - bool SetOptions(const AudioOptions& options); - bool SetDevices(const Device* in_device, const Device* out_device); bool GetOutputVolume(int* level); bool SetOutputVolume(int level); int GetInputLevel(); const std::vector<AudioCodec>& codecs(); - bool FindCodec(const AudioCodec& codec); - bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec); - - const std::vector<RtpHeaderExtension>& rtp_header_extensions() const; - - void SetLogging(int min_sev, const char* filter); + RtpCapabilities GetCapabilities() const; // For tracking WebRtc channels. Needed because we have to pause them // all when switching devices. @@ -120,68 +109,49 @@ class WebRtcVoiceEngine private: void Construct(); - void ConstructCodecs(); - bool GetVoeCodec(int index, webrtc::CodecInst* codec); bool InitInternal(); - void SetTraceFilter(int filter); - void SetTraceOptions(const std::string& options); // Every option that is "set" will be applied. Every option not "set" will be // ignored. This allows us to selectively turn on and off different options // easily at any time. bool ApplyOptions(const AudioOptions& options); + void SetDefaultDevices(); // webrtc::TraceCallback: void Print(webrtc::TraceLevel level, const char* trace, int length) override; - // webrtc::VoiceEngineObserver: - void CallbackOnError(int channel_id, int errCode) override; - - // Given the device type, name, and id, find device id. Return true and - // set the output parameter rtc_id if successful. - bool FindWebRtcAudioDeviceId( - bool is_input, const std::string& dev_name, int dev_id, int* rtc_id); - void StartAecDump(const std::string& filename); int CreateVoEChannel(); - static const int kDefaultLogSeverity = rtc::LS_WARNING; + rtc::ThreadChecker signal_thread_checker_; + rtc::ThreadChecker worker_thread_checker_; // The primary instance of WebRtc VoiceEngine. rtc::scoped_ptr<VoEWrapper> voe_wrapper_; - rtc::scoped_ptr<VoETraceWrapper> tracing_; + rtc::scoped_refptr<webrtc::AudioState> audio_state_; // The external audio device manager - webrtc::AudioDeviceModule* adm_; - int log_filter_; - std::string log_options_; - bool is_dumping_aec_; + webrtc::AudioDeviceModule* adm_ = nullptr; std::vector<AudioCodec> codecs_; - std::vector<RtpHeaderExtension> rtp_header_extensions_; std::vector<WebRtcVoiceMediaChannel*> channels_; - // channels_ can be read from WebRtc callback thread. We need a lock on that - // callback as well as the RegisterChannel/UnregisterChannel. - rtc::CriticalSection channels_cs_; - webrtc::AgcConfig default_agc_config_; - webrtc::Config voe_config_; + bool initialized_ = false; + bool is_dumping_aec_ = false; - bool initialized_; - AudioOptions options_; - + webrtc::AgcConfig default_agc_config_; // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns // values, and apply them in case they are missing in the audio options. We // need to do this because SetExtraOptions() will revert to defaults for // options which are not provided. - Settable<bool> extended_filter_aec_; - Settable<bool> delay_agnostic_aec_; - Settable<bool> experimental_ns_; + rtc::Optional<bool> extended_filter_aec_; + rtc::Optional<bool> delay_agnostic_aec_; + rtc::Optional<bool> experimental_ns_; RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcVoiceEngine); }; // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses // WebRtc Voice Engine. -class WebRtcVoiceMediaChannel : public VoiceMediaChannel, - public webrtc::Transport { +class WebRtcVoiceMediaChannel final : public VoiceMediaChannel, + public webrtc::Transport { public: WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine, const AudioOptions& options, @@ -217,7 +187,7 @@ class WebRtcVoiceMediaChannel : public VoiceMediaChannel, bool SetOutputVolume(uint32_t ssrc, double volume) override; bool CanInsertDtmf() override; - bool InsertDtmf(uint32_t ssrc, int event, int duration, int flags) override; + bool InsertDtmf(uint32_t ssrc, int event, int duration) override; void OnPacketReceived(rtc::Buffer* packet, const rtc::PacketTime& packet_time) override; @@ -226,6 +196,10 @@ class WebRtcVoiceMediaChannel : public VoiceMediaChannel, void OnReadyToSend(bool ready) override {} bool GetStats(VoiceMediaInfo* info) override; + void SetRawAudioSink( + uint32_t ssrc, + rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) override; + // implements Transport interface bool SendRtp(const uint8_t* data, size_t len, @@ -243,20 +217,14 @@ class WebRtcVoiceMediaChannel : public VoiceMediaChannel, return VoiceMediaChannel::SendRtcp(&packet, rtc::PacketOptions()); } - void OnError(int error); - int GetReceiveChannelId(uint32_t ssrc) const; int GetSendChannelId(uint32_t ssrc) const; private: bool SetSendCodecs(const std::vector<AudioCodec>& codecs); - bool SetSendRtpHeaderExtensions( - const std::vector<RtpHeaderExtension>& extensions); bool SetOptions(const AudioOptions& options); bool SetMaxSendBandwidth(int bps); bool SetRecvCodecs(const std::vector<AudioCodec>& codecs); - bool SetRecvRtpHeaderExtensions( - const std::vector<RtpHeaderExtension>& extensions); bool SetLocalRenderer(uint32_t ssrc, AudioRenderer* renderer); bool MuteStream(uint32_t ssrc, bool mute); @@ -267,82 +235,55 @@ class WebRtcVoiceMediaChannel : public VoiceMediaChannel, const std::vector<AudioCodec>& all_codecs, webrtc::CodecInst* send_codec); bool SetPlayout(int channel, bool playout); - static Error WebRtcErrorToChannelError(int err_code); - - typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool, - unsigned char); - void SetNack(int channel, bool nack_enabled); bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec); bool ChangePlayout(bool playout); bool ChangeSend(SendFlags send); bool ChangeSend(int channel, SendFlags send); - bool ConfigureRecvChannel(int channel); int CreateVoEChannel(); - bool DeleteChannel(int channel); + bool DeleteVoEChannel(int channel); bool IsDefaultRecvStream(uint32_t ssrc) { return default_recv_ssrc_ == static_cast<int64_t>(ssrc); } bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs); bool SetSendBitrateInternal(int bps); - bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id, - const RtpHeaderExtension* extension); - void RecreateAudioReceiveStreams(); - void AddAudioReceiveStream(uint32_t ssrc); - void RemoveAudioReceiveStream(uint32_t ssrc); - bool SetRecvCodecsInternal(const std::vector<AudioCodec>& new_codecs); - - bool SetChannelRecvRtpHeaderExtensions( - int channel_id, - const std::vector<RtpHeaderExtension>& extensions); - bool SetChannelSendRtpHeaderExtensions( - int channel_id, - const std::vector<RtpHeaderExtension>& extensions); + rtc::ThreadChecker worker_thread_checker_; - rtc::ThreadChecker thread_checker_; - - WebRtcVoiceEngine* const engine_; + WebRtcVoiceEngine* const engine_ = nullptr; std::vector<AudioCodec> recv_codecs_; std::vector<AudioCodec> send_codecs_; rtc::scoped_ptr<webrtc::CodecInst> send_codec_; - bool send_bitrate_setting_; - int send_bitrate_bps_; + bool send_bitrate_setting_ = false; + int send_bitrate_bps_ = 0; AudioOptions options_; - bool dtmf_allowed_; - bool desired_playout_; - bool nack_enabled_; - bool playout_; - bool typing_noise_detected_; - SendFlags desired_send_; - SendFlags send_; - webrtc::Call* const call_; + rtc::Optional<int> dtmf_payload_type_; + bool desired_playout_ = false; + bool nack_enabled_ = false; + bool playout_ = false; + SendFlags desired_send_ = SEND_NOTHING; + SendFlags send_ = SEND_NOTHING; + webrtc::Call* const call_ = nullptr; // SSRC of unsignalled receive stream, or -1 if there isn't one. int64_t default_recv_ssrc_ = -1; // Volume for unsignalled stream, which may be set before the stream exists. double default_recv_volume_ = 1.0; - // SSRC to use for RTCP receiver reports; default to 1 in case of no signaled + // Default SSRC to use for RTCP receiver reports in case of no signaled // send streams. See: https://code.google.com/p/webrtc/issues/detail?id=4740 - uint32_t receiver_reports_ssrc_ = 1; + // and https://code.google.com/p/chromium/issues/detail?id=547661 + uint32_t receiver_reports_ssrc_ = 0xFA17FA17u; class WebRtcAudioSendStream; std::map<uint32_t, WebRtcAudioSendStream*> send_streams_; - std::vector<RtpHeaderExtension> send_extensions_; + std::vector<webrtc::RtpExtension> send_rtp_extensions_; class WebRtcAudioReceiveStream; - std::map<uint32_t, WebRtcAudioReceiveStream*> receive_channels_; - std::map<uint32_t, webrtc::AudioReceiveStream*> receive_streams_; - std::map<uint32_t, StreamParams> receive_stream_params_; - // receive_channels_ can be read from WebRtc callback thread. Access from - // the WebRtc thread must be synchronized with edits on the worker thread. - // Reads on the worker thread are ok. - std::vector<RtpHeaderExtension> receive_extensions_; + std::map<uint32_t, WebRtcAudioReceiveStream*> recv_streams_; std::vector<webrtc::RtpExtension> recv_rtp_extensions_; RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceMediaChannel); }; - } // namespace cricket #endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_ |