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

Unified Diff: webrtc/media/engine/webrtcvideoengine2.cc

Issue 1838413002: Combining SetVideoSend and SetSource into one method. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing comments and other minor things Created 4 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2.h ('k') | webrtc/media/engine/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/media/engine/webrtcvideoengine2.cc
diff --git a/webrtc/media/engine/webrtcvideoengine2.cc b/webrtc/media/engine/webrtcvideoengine2.cc
index 00b17c1a9d538cd67e232abb7018bd1fb3d237ab..0fc9544cea200655fb3e0b62b542c5a2abb41619 100644
--- a/webrtc/media/engine/webrtcvideoengine2.cc
+++ b/webrtc/media/engine/webrtcvideoengine2.cc
@@ -1019,19 +1019,30 @@ bool WebRtcVideoChannel2::SetSend(bool send) {
}
// TODO(nisse): The enable argument was used for mute logic which has
-// been moved to VideoBroadcaster. So delete this method, and use
-// SetOptions instead.
-bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable,
- const VideoOptions* options) {
+// been moved to VideoBroadcaster. So remove the argument from this
+// method.
+bool WebRtcVideoChannel2::SetVideoSend(
+ uint32_t ssrc,
+ bool enable,
+ const VideoOptions* options,
+ rtc::VideoSourceInterface<cricket::VideoFrame>* source) {
TRACE_EVENT0("webrtc", "SetVideoSend");
+ RTC_DCHECK(ssrc != 0);
LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable
- << "options: " << (options ? options->ToString() : "nullptr")
- << ").";
+ << ", options: " << (options ? options->ToString() : "nullptr")
+ << ", source = " << (source != nullptr ? "(source)" : "NULL")
pbos-webrtc 2016/05/14 00:42:39 "nullptr"
Taylor Brandstetter 2016/05/16 19:03:00 Done.
+ << ")";
- if (enable && options) {
- SetOptions(ssrc, *options);
+ rtc::CritScope stream_lock(&stream_crit_);
+ const auto& kv = send_streams_.find(ssrc);
+ if (kv == send_streams_.end()) {
+ // Allow unknown ssrc only if source is null.
+ RTC_CHECK(source == nullptr);
+ LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc;
pbos-webrtc 2016/05/14 00:42:39 This log will never happen, do RTC_CHECK(...) <<
Taylor Brandstetter 2016/05/16 19:03:00 I believe it actually can happen due to this issue
pbos-webrtc 2016/05/16 19:04:50 Oh, totally misread this. Carry on. :)
+ return false;
}
- return true;
+
+ return kv->second->SetVideoSend(enable, options, source);
}
bool WebRtcVideoChannel2::ValidateSendSsrcAvailability(
@@ -1330,23 +1341,6 @@ void WebRtcVideoChannel2::FillBandwidthEstimationStats(
video_media_info->bw_estimations.push_back(bwe_info);
}
-void WebRtcVideoChannel2::SetSource(
- uint32_t ssrc,
- rtc::VideoSourceInterface<cricket::VideoFrame>* source) {
- LOG(LS_INFO) << "SetSource: " << ssrc << " -> "
- << (source ? "(source)" : "NULL");
- RTC_DCHECK(ssrc != 0);
-
- rtc::CritScope stream_lock(&stream_crit_);
- const auto& kv = send_streams_.find(ssrc);
- if (kv == send_streams_.end()) {
- // Allow unknown ssrc only if source is null.
- RTC_CHECK(source == nullptr);
- } else {
- kv->second->SetSource(source);
- }
-}
-
void WebRtcVideoChannel2::OnPacketReceived(
rtc::CopyOnWriteBuffer* packet,
const rtc::PacketTime& packet_time) {
@@ -1433,19 +1427,6 @@ void WebRtcVideoChannel2::OnNetworkRouteChanged(
call_->OnNetworkRouteChanged(transport_name, network_route);
}
-// TODO(pbos): Remove SetOptions in favor of SetSendParameters.
-void WebRtcVideoChannel2::SetOptions(uint32_t ssrc,
- const VideoOptions& options) {
- LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString();
-
- rtc::CritScope stream_lock(&stream_crit_);
- const auto& kv = send_streams_.find(ssrc);
- if (kv == send_streams_.end()) {
- return;
- }
- kv->second->SetOptions(options);
-}
-
void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) {
MediaChannel::SetInterface(iface);
// Set the RTP recv/send buffer to a bigger size
@@ -1614,24 +1595,38 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame(
stream_->Input()->IncomingCapturedFrame(video_frame);
}
-void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSource(
+bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend(
+ bool enable,
+ const VideoOptions* options,
rtc::VideoSourceInterface<cricket::VideoFrame>* source) {
- TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetSource");
+ TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
- if (!source && !source_)
- return;
- DisconnectSource();
+ bool source_changing = source_ != source;
+ if (source_changing) {
+ DisconnectSource();
+ }
{
rtc::CritScope cs(&lock_);
- // Reset timestamps to realign new incoming frames to a webrtc timestamp. A
- // new capturer may have a different timestamp delta than the previous one.
- first_frame_timestamp_ms_ = rtc::Optional<int64_t>();
+ if (enable && options) {
+ VideoOptions old_options = parameters_.options;
+ parameters_.options.SetAll(*options);
+ // Reconfigure encoder settings on the naext frame or stream
+ // recreation if the options changed.
+ if (parameters_.options != old_options) {
+ pending_encoder_reconfiguration_ = true;
+ }
+ }
+
+ if (source_changing) {
+ // Reset timestamps to realign new incoming frames to a webrtc timestamp.
+ // A new source may have a different timestamp delta than the previous
+ // one.
+ first_frame_timestamp_ms_ = rtc::Optional<int64_t>();
- if (source == NULL) {
- if (stream_ != NULL) {
+ if (source == nullptr && stream_ != nullptr) {
LOG(LS_VERBOSE) << "Disabling capturer, sending black frame.";
// Force this black frame not to be dropped due to timestamp order
// check. As IncomingCapturedFrame will drop the frame if this frame's
@@ -1642,17 +1637,17 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSource(
stream_->Input()->IncomingCapturedFrame(
CreateBlackFrame(last_dimensions_.width, last_dimensions_.height,
last_frame_timestamp_ms_, last_rotation_));
-
-
}
+ source_ = source;
}
}
- source_ = source;
+
// |source_->AddOrUpdateSink| may not be called while holding |lock_| since
// that might cause a lock order inversion.
- if (source_) {
+ if (source_changing && source_ != nullptr) {
pbos-webrtc 2016/05/14 00:42:39 && source_
Taylor Brandstetter 2016/05/16 19:03:00 Done.
source_->AddOrUpdateSink(this, sink_wants_);
}
+ return true;
}
void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() {
@@ -1665,9 +1660,9 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() {
// that might cause a lock order inversion.
source_->RemoveSink(this);
source_ = nullptr;
- // Reset |cpu_restricted_counter_| if the capturer is changed. It is not
+ // Reset |cpu_restricted_counter_| if the source is changed. It is not
// possible to know if the video resolution is restricted by CPU usage after
- // the capturer is changed since the next capturer might be screen capture
+ // the source is changed since the next source might be screen capture
// with another resolution and frame rate.
cpu_restricted_counter_ = 0;
}
@@ -1677,19 +1672,6 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const {
return ssrcs_;
}
-void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions(
- const VideoOptions& options) {
- rtc::CritScope cs(&lock_);
-
- VideoOptions old_options = parameters_.options;
- parameters_.options.SetAll(options);
- // Reconfigure encoder settings on the next frame or stream
- // recreation if the options changed.
- if (parameters_.options != old_options) {
- pending_encoder_reconfiguration_ = true;
- }
-}
-
webrtc::VideoCodecType CodecTypeFromName(const std::string& name) {
if (CodecNamesEq(name, kVp8CodecName)) {
return webrtc::kVideoCodecVP8;
@@ -1825,7 +1807,7 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSendParameters(
}
} // release |lock_|
- // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since
+ // |source_->AddOrUpdateSink| may not be called while holding |lock_| since
// that might cause a lock order inversion.
if (params.rtp_header_extensions) {
sink_wants_.rotation_applied = !ContainsHeaderExtension(
@@ -2020,14 +2002,14 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) {
return;
}
// The input video frame size will have a resolution with less than or
- // equal to |max_pixel_count| depending on how the capturer can scale the
+ // equal to |max_pixel_count| depending on how the source can scale the
// input frame size.
max_pixel_count = rtc::Optional<int>(
(last_dimensions_.height * last_dimensions_.width * 3) / 5);
// Increase |number_of_cpu_adapt_changes_| if
// sink_wants_.max_pixel_count will be changed since
- // last time |capturer_->AddOrUpdateSink| was called. That is, this will
- // result in a new request for the capturer to change resolution.
+ // last time |source_->AddOrUpdateSink| was called. That is, this will
+ // result in a new request for the source to change resolution.
if (!sink_wants_.max_pixel_count ||
*sink_wants_.max_pixel_count > *max_pixel_count) {
++number_of_cpu_adapt_changes_;
@@ -2037,13 +2019,13 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) {
RTC_DCHECK(load == kUnderuse);
// The input video frame size will have a resolution with "one step up"
// pixels than |max_pixel_count_step_up| where "one step up" depends on
- // how the capturer can scale the input frame size.
+ // how the source can scale the input frame size.
max_pixel_count_step_up = rtc::Optional<int>(last_dimensions_.height *
last_dimensions_.width);
// Increase |number_of_cpu_adapt_changes_| if
// sink_wants_.max_pixel_count_step_up will be changed since
- // last time |capturer_->AddOrUpdateSink| was called. That is, this will
- // result in a new request for the capturer to change resolution.
+ // last time |source_->AddOrUpdateSink| was called. That is, this will
+ // result in a new request for the source to change resolution.
if (sink_wants_.max_pixel_count ||
(sink_wants_.max_pixel_count_step_up &&
*sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) {
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2.h ('k') | webrtc/media/engine/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698