From 7ea4f24ea56689ebce64ada8e3394152e192c23d Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Wed, 2 Oct 2013 13:34:26 +0000 Subject: [PATCH] Piping AutoMuter interface through to ViE API This is a piece of the AutoMuter effort. A second CL will follow containing modifications to the new API, and tests. BUG=2436 R=mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2331004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4899 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/video_engine/include/vie_codec.h | 13 +++++++++++++ .../auto_test/source/vie_autotest_codec.cc | 8 +++++++- .../source/vie_autotest_custom_call.cc | 4 ++++ webrtc/video_engine/vie_codec_impl.cc | 13 +++++++++++++ webrtc/video_engine/vie_codec_impl.h | 2 ++ webrtc/video_engine/vie_encoder.cc | 19 ++++++++++++++++++- webrtc/video_engine/vie_encoder.h | 6 ++++++ 7 files changed, 63 insertions(+), 2 deletions(-) diff --git a/webrtc/video_engine/include/vie_codec.h b/webrtc/video_engine/include/vie_codec.h index 47bc6861cb..017bedf188 100644 --- a/webrtc/video_engine/include/vie_codec.h +++ b/webrtc/video_engine/include/vie_codec.h @@ -35,6 +35,12 @@ class WEBRTC_DLLEXPORT ViEEncoderObserver { virtual void OutgoingRate(const int video_channel, const unsigned int framerate, const unsigned int bitrate) = 0; + + // This method is called whenever the state of the AutoMuter changes, i.e., + // when |is_muted| toggles. + // TODO(hlundin): Remove the default implementation when possible. + virtual void VideoAutoMuted(bool is_muted) {}; + protected: virtual ~ViEEncoderObserver() {} }; @@ -177,6 +183,13 @@ class WEBRTC_DLLEXPORT ViECodec { // Disables recording of debugging information. virtual int StopDebugRecording(int video_channel) = 0; + // Enables AutoMuter to turn off video when the rate drops below + // |threshold_bps|, and turns back on when the rate goes back up above + // |threshold_bps| + |window_bps|. + // This is under development; not tested. + virtual void EnableAutoMuting(int video_channel, int threshold_bps, + int window_bps) = 0; + protected: ViECodec() {} virtual ~ViECodec() {} diff --git a/webrtc/video_engine/test/auto_test/source/vie_autotest_codec.cc b/webrtc/video_engine/test/auto_test/source/vie_autotest_codec.cc index df950c6a38..d242831ad8 100644 --- a/webrtc/video_engine/test/auto_test/source/vie_autotest_codec.cc +++ b/webrtc/video_engine/test/auto_test/source/vie_autotest_codec.cc @@ -44,6 +44,7 @@ class TestCodecObserver unsigned int last_outgoing_bitrate_; unsigned int last_incoming_framerate_; unsigned int last_incoming_bitrate_; + unsigned int video_auto_muted_called_; webrtc::VideoCodec incoming_codec_; @@ -57,7 +58,8 @@ class TestCodecObserver last_outgoing_framerate_(0), last_outgoing_bitrate_(0), last_incoming_framerate_(0), - last_incoming_bitrate_(0) { + last_incoming_bitrate_(0), + video_auto_muted_called_(0) { memset(&incoming_codec_, 0, sizeof(incoming_codec_)); } virtual void IncomingCodecChanged(const int video_channel, @@ -86,6 +88,10 @@ class TestCodecObserver last_outgoing_bitrate_ += bitrate; } + virtual void VideoAutoMuted(bool is_muted) { + video_auto_muted_called_++; + } + virtual void RequestNewKeyFrame(const int video_channel) { } }; diff --git a/webrtc/video_engine/test/auto_test/source/vie_autotest_custom_call.cc b/webrtc/video_engine/test/auto_test/source/vie_autotest_custom_call.cc index cbccf6fe67..5d2ecfc5bd 100644 --- a/webrtc/video_engine/test/auto_test/source/vie_autotest_custom_call.cc +++ b/webrtc/video_engine/test/auto_test/source/vie_autotest_custom_call.cc @@ -72,6 +72,10 @@ class ViEAutotestEncoderObserver : public webrtc::ViEEncoderObserver { std::cout << "Send FR: " << framerate << " BR: " << bitrate << std::endl; } + + virtual void VideoAutoMuted(bool is_muted) { + std::cout << "VideoAutoMuted: " << is_muted << std::endl; + } }; class ViEAutotestDecoderObserver : public webrtc::ViEDecoderObserver { diff --git a/webrtc/video_engine/vie_codec_impl.cc b/webrtc/video_engine/vie_codec_impl.cc index 61449db091..bf845d9553 100644 --- a/webrtc/video_engine/vie_codec_impl.cc +++ b/webrtc/video_engine/vie_codec_impl.cc @@ -715,6 +715,19 @@ int ViECodecImpl::StopDebugRecording(int video_channel) { return vie_encoder->StopDebugRecording(); } +void ViECodecImpl::EnableAutoMuting(int video_channel, int threshold_bps, + int window_bps) { + ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); + ViEEncoder* vie_encoder = cs.Encoder(video_channel); + if (!vie_encoder) { + WEBRTC_TRACE(kTraceError, kTraceVideo, + ViEId(shared_data_->instance_id(), video_channel), + "%s: No encoder %d", __FUNCTION__, video_channel); + return; + } + return vie_encoder->EnableAutoMuting(threshold_bps, window_bps); +} + bool ViECodecImpl::CodecValid(const VideoCodec& video_codec) { // Check pl_name matches codec_type. if (video_codec.codecType == kVideoCodecRED) { diff --git a/webrtc/video_engine/vie_codec_impl.h b/webrtc/video_engine/vie_codec_impl.h index aa5cc71dfc..5a998c8177 100644 --- a/webrtc/video_engine/vie_codec_impl.h +++ b/webrtc/video_engine/vie_codec_impl.h @@ -70,6 +70,8 @@ class ViECodecImpl virtual int StartDebugRecording(int video_channel, const char* file_name_utf8); virtual int StopDebugRecording(int video_channel); + virtual void EnableAutoMuting(int video_channel, int threshold_bps, + int window_bps); protected: explicit ViECodecImpl(ViESharedData* shared_data); diff --git a/webrtc/video_engine/vie_encoder.cc b/webrtc/video_engine/vie_encoder.cc index e0d9a43503..99154cdc39 100644 --- a/webrtc/video_engine/vie_encoder.cc +++ b/webrtc/video_engine/vie_encoder.cc @@ -158,7 +158,8 @@ ViEEncoder::ViEEncoder(int32_t engine_id, picture_id_sli_(0), has_received_rpsi_(false), picture_id_rpsi_(0), - qm_callback_(NULL) { + qm_callback_(NULL), + video_auto_muted_(false) { WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, ViEId(engine_id, channel_id), "%s(engine_id: %d) 0x%p - Constructor", __FUNCTION__, engine_id, @@ -1034,6 +1035,7 @@ void ViEEncoder::OnNetworkChanged(const uint32_t bitrate_bps, __FUNCTION__, bitrate_bps, fraction_lost, round_trip_time_ms); vcm_.SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms); + bool video_is_muted = vcm_.VideoMuted(); int bitrate_kbps = bitrate_bps / 1000; VideoCodec send_codec; if (vcm_.SendCodec(&send_codec) != 0) { @@ -1069,6 +1071,17 @@ void ViEEncoder::OnNetworkChanged(const uint32_t bitrate_bps, max_padding_bitrate_kbps, pad_up_to_bitrate_kbps); default_rtp_rtcp_->SetTargetSendBitrate(stream_bitrates); + if (video_is_muted != video_auto_muted_) { + // State changed now. Send callback to inform about that. + video_auto_muted_ = video_is_muted; + if (codec_observer_) { + WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, + ViEId(engine_id_, channel_id_), + "%s: video_auto_muted_ changed to %i", + __FUNCTION__, video_auto_muted_); + codec_observer_->VideoAutoMuted(video_auto_muted_); + } + } } PacedSender* ViEEncoder::GetPacedSender() { @@ -1110,6 +1123,10 @@ int ViEEncoder::StopDebugRecording() { return vcm_.StopDebugRecording(); } +void ViEEncoder::EnableAutoMuting(int threshold_bps, int window_bps) { + vcm_.EnableAutoMuting(threshold_bps, window_bps); +} + QMVideoSettingsCallback::QMVideoSettingsCallback(VideoProcessingModule* vpm) : vpm_(vpm) { } diff --git a/webrtc/video_engine/vie_encoder.h b/webrtc/video_engine/vie_encoder.h index cbadcd7c4f..8d18bb6525 100644 --- a/webrtc/video_engine/vie_encoder.h +++ b/webrtc/video_engine/vie_encoder.h @@ -162,6 +162,11 @@ class ViEEncoder // Disables recording of debugging information. virtual int StopDebugRecording(); + // Enables AutoMuter to turn off video when the rate drops below + // |threshold_bps|, and turns back on when the rate goes back up above + // |threshold_bps| + |window_bps|. + virtual void EnableAutoMuting(int threshold_bps, int window_bps); + int channel_id() const { return channel_id_; } protected: // Called by BitrateObserver. @@ -216,6 +221,7 @@ class ViEEncoder // Quality modes callback QMVideoSettingsCallback* qm_callback_; + bool video_auto_muted_; }; } // namespace webrtc