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

Side by Side Diff: webrtc/media/engine/webrtcvideoengine2.cc

Issue 2257413002: Replace interface VideoCapturerInput with VideoSinkInterface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed code review comments. Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 ssrcs_(sp.ssrcs), 1573 ssrcs_(sp.ssrcs),
1574 ssrc_groups_(sp.ssrc_groups), 1574 ssrc_groups_(sp.ssrc_groups),
1575 call_(call), 1575 call_(call),
1576 cpu_restricted_counter_(0), 1576 cpu_restricted_counter_(0),
1577 number_of_cpu_adapt_changes_(0), 1577 number_of_cpu_adapt_changes_(0),
1578 frame_count_(0), 1578 frame_count_(0),
1579 cpu_restricted_frame_count_(0), 1579 cpu_restricted_frame_count_(0),
1580 source_(nullptr), 1580 source_(nullptr),
1581 external_encoder_factory_(external_encoder_factory), 1581 external_encoder_factory_(external_encoder_factory),
1582 stream_(nullptr), 1582 stream_(nullptr),
1583 encoder_sink_(nullptr),
1583 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), 1584 parameters_(std::move(config), options, max_bitrate_bps, codec_settings),
1584 rtp_parameters_(CreateRtpParametersWithOneEncoding()), 1585 rtp_parameters_(CreateRtpParametersWithOneEncoding()),
1585 pending_encoder_reconfiguration_(false), 1586 pending_encoder_reconfiguration_(false),
1586 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), 1587 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false),
1587 sending_(false), 1588 sending_(false),
1588 last_frame_timestamp_us_(0) { 1589 last_frame_timestamp_us_(0) {
1589 parameters_.config.rtp.max_packet_size = kVideoMtu; 1590 parameters_.config.rtp.max_packet_size = kVideoMtu;
1590 parameters_.conference_mode = send_params.conference_mode; 1591 parameters_.conference_mode = send_params.conference_mode;
1591 1592
1592 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs); 1593 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 last_frame_info_.rotation = video_frame.rotation(); 1653 last_frame_info_.rotation = video_frame.rotation();
1653 last_frame_info_.is_texture = video_frame.is_texture(); 1654 last_frame_info_.is_texture = video_frame.is_texture();
1654 pending_encoder_reconfiguration_ = true; 1655 pending_encoder_reconfiguration_ = true;
1655 1656
1656 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" 1657 LOG(LS_INFO) << "Video frame parameters changed: dimensions="
1657 << last_frame_info_.width << "x" << last_frame_info_.height 1658 << last_frame_info_.width << "x" << last_frame_info_.height
1658 << ", rotation=" << last_frame_info_.rotation 1659 << ", rotation=" << last_frame_info_.rotation
1659 << ", texture=" << last_frame_info_.is_texture; 1660 << ", texture=" << last_frame_info_.is_texture;
1660 } 1661 }
1661 1662
1662 if (stream_ == NULL) { 1663 if (encoder_sink_ == NULL) {
1663 // Frame input before send codecs are configured, dropping frame. 1664 // Frame input before send codecs are configured, dropping frame.
1664 return; 1665 return;
1665 } 1666 }
1666 1667
1667 last_frame_timestamp_us_ = video_frame.timestamp_us(); 1668 last_frame_timestamp_us_ = video_frame.timestamp_us();
1668 1669
1669 if (pending_encoder_reconfiguration_) { 1670 if (pending_encoder_reconfiguration_) {
1670 ReconfigureEncoder(); 1671 ReconfigureEncoder();
1671 pending_encoder_reconfiguration_ = false; 1672 pending_encoder_reconfiguration_ = false;
1672 } 1673 }
1673 1674
1674 // Not sending, abort after reconfiguration. Reconfiguration should still 1675 // Not sending, abort after reconfiguration. Reconfiguration should still
1675 // occur to permit sending this input as quickly as possible once we start 1676 // occur to permit sending this input as quickly as possible once we start
1676 // sending (without having to reconfigure then). 1677 // sending (without having to reconfigure then).
1677 if (!sending_) { 1678 if (!sending_) {
1678 return; 1679 return;
1679 } 1680 }
1680 1681
1681 ++frame_count_; 1682 ++frame_count_;
1682 if (cpu_restricted_counter_ > 0) 1683 if (cpu_restricted_counter_ > 0)
1683 ++cpu_restricted_frame_count_; 1684 ++cpu_restricted_frame_count_;
1684 1685
1685 stream_->Input()->IncomingCapturedFrame(video_frame); 1686 encoder_sink_->OnFrame(video_frame);
1686 } 1687 }
1687 1688
1688 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend( 1689 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend(
1689 bool enable, 1690 bool enable,
1690 const VideoOptions* options, 1691 const VideoOptions* options,
1691 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { 1692 rtc::VideoSourceInterface<cricket::VideoFrame>* source) {
1692 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend"); 1693 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend");
1693 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 1694 RTC_DCHECK(thread_checker_.CalledOnValidThread());
1694 1695
1695 // Ignore |options| pointer if |enable| is false. 1696 // Ignore |options| pointer if |enable| is false.
1696 bool options_present = enable && options; 1697 bool options_present = enable && options;
1697 bool source_changing = source_ != source; 1698 bool source_changing = source_ != source;
1698 if (source_changing) { 1699 if (source_changing) {
1699 DisconnectSource(); 1700 DisconnectSource();
1700 } 1701 }
1701 1702
1702 if (options_present || source_changing) { 1703 if (options_present || source_changing) {
1703 rtc::CritScope cs(&lock_); 1704 rtc::CritScope cs(&lock_);
1704 1705
1705 if (options_present) { 1706 if (options_present) {
1706 VideoOptions old_options = parameters_.options; 1707 VideoOptions old_options = parameters_.options;
1707 parameters_.options.SetAll(*options); 1708 parameters_.options.SetAll(*options);
1708 // Reconfigure encoder settings on the naext frame or stream 1709 // Reconfigure encoder settings on the next frame or stream
1709 // recreation if the options changed. 1710 // recreation if the options changed.
1710 if (parameters_.options != old_options) { 1711 if (parameters_.options != old_options) {
1711 pending_encoder_reconfiguration_ = true; 1712 pending_encoder_reconfiguration_ = true;
1712 } 1713 }
1713 } 1714 }
1714 1715
1715 if (source_changing) { 1716 if (source_changing) {
1716 if (source == nullptr && stream_ != nullptr) { 1717 if (source == nullptr && encoder_sink_ != nullptr) {
1717 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; 1718 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame.";
1718 // Force this black frame not to be dropped due to timestamp order 1719 // Force this black frame not to be dropped due to timestamp order
1719 // check. As IncomingCapturedFrame will drop the frame if this frame's 1720 // check. As IncomingCapturedFrame will drop the frame if this frame's
1720 // timestamp is less than or equal to last frame's timestamp, it is 1721 // timestamp is less than or equal to last frame's timestamp, it is
1721 // necessary to give this black frame a larger timestamp than the 1722 // necessary to give this black frame a larger timestamp than the
1722 // previous one. 1723 // previous one.
1723 last_frame_timestamp_us_ += rtc::kNumMicrosecsPerMillisec; 1724 last_frame_timestamp_us_ += rtc::kNumMicrosecsPerMillisec;
1724 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer( 1725 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer(
1725 webrtc::I420Buffer::Create(last_frame_info_.width, 1726 webrtc::I420Buffer::Create(last_frame_info_.width,
1726 last_frame_info_.height)); 1727 last_frame_info_.height));
1727 black_buffer->SetToBlack(); 1728 black_buffer->SetToBlack();
1728 1729
1729 stream_->Input()->IncomingCapturedFrame(webrtc::VideoFrame( 1730 encoder_sink_->OnFrame(webrtc::VideoFrame(
1730 black_buffer, last_frame_info_.rotation, 1731 black_buffer, last_frame_info_.rotation, last_frame_timestamp_us_));
1731 last_frame_timestamp_us_));
1732 } 1732 }
1733 source_ = source; 1733 source_ = source;
1734 } 1734 }
1735 } 1735 }
1736 1736
1737 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since 1737 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since
1738 // that might cause a lock order inversion. 1738 // that might cause a lock order inversion.
1739 if (source_changing && source_) { 1739 if (source_changing && source_) {
1740 source_->AddOrUpdateSink(this, sink_wants_); 1740 source_->AddOrUpdateSink(this, sink_wants_);
1741 } 1741 }
1742 return true; 1742 return true;
1743 } 1743 }
1744 1744
1745 void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() { 1745 void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() {
1746 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 1746 RTC_DCHECK(thread_checker_.CalledOnValidThread());
1747 if (source_ == NULL) { 1747 if (source_ == nullptr) {
1748 return; 1748 return;
1749 } 1749 }
1750 1750
1751 // |source_->RemoveSink| may not be called while holding |lock_| since 1751 // |source_->RemoveSink| may not be called while holding |lock_| since
1752 // that might cause a lock order inversion. 1752 // that might cause a lock order inversion.
1753 source_->RemoveSink(this); 1753 source_->RemoveSink(this);
1754 source_ = nullptr; 1754 source_ = nullptr;
1755 // Reset |cpu_restricted_counter_| if the source is changed. It is not 1755 // Reset |cpu_restricted_counter_| if the source is changed. It is not
1756 // possible to know if the video resolution is restricted by CPU usage after 1756 // possible to know if the video resolution is restricted by CPU usage after
1757 // the source is changed since the next source might be screen capture 1757 // the source is changed since the next source might be screen capture
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 2043
2044 parameters_.encoder_config = std::move(encoder_config); 2044 parameters_.encoder_config = std::move(encoder_config);
2045 } 2045 }
2046 2046
2047 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) { 2047 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) {
2048 rtc::CritScope cs(&lock_); 2048 rtc::CritScope cs(&lock_);
2049 sending_ = send; 2049 sending_ = send;
2050 UpdateSendState(); 2050 UpdateSendState();
2051 } 2051 }
2052 2052
2053 void WebRtcVideoChannel2::WebRtcVideoSendStream::AddOrUpdateSink(
stefan-webrtc 2016/09/13 09:26:43 Add sounds like several sinks are supported, which
perkj_webrtc 2016/09/14 14:20:22 Nope- there is a 1-1 mapping between sendstream an
2054 VideoSinkInterface<webrtc::VideoFrame>* sink,
2055 const rtc::VideoSinkWants& wants) {
2056 // TODO(perkj): Actually consider the encoder |wants| and remove
2057 // WebRtcVideoSendStream::OnLoadUpdate(Load load).
2058 rtc::CritScope cs(&lock_);
2059 RTC_DCHECK(!encoder_sink_ || encoder_sink_ == sink);
stefan-webrtc 2016/09/13 09:26:43 It looks error prone to allow adding the same sink
perkj_webrtc 2016/09/14 14:20:22 For updating the wants. Will be done in a follow u
2060 encoder_sink_ = sink;
2061 }
2062
2063 void WebRtcVideoChannel2::WebRtcVideoSendStream::RemoveSink(
2064 VideoSinkInterface<webrtc::VideoFrame>* sink) {
2065 rtc::CritScope cs(&lock_);
2066 RTC_DCHECK(encoder_sink_ == sink);
stefan-webrtc 2016/09/13 09:26:43 DCHECK_EQ
perkj_webrtc 2016/09/14 14:20:22 Done.
2067 encoder_sink_ = nullptr;
2068 }
2069
2053 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { 2070 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) {
2054 if (worker_thread_ != rtc::Thread::Current()) { 2071 if (worker_thread_ != rtc::Thread::Current()) {
2055 invoker_.AsyncInvoke<void>( 2072 invoker_.AsyncInvoke<void>(
2056 RTC_FROM_HERE, worker_thread_, 2073 RTC_FROM_HERE, worker_thread_,
2057 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, 2074 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate,
2058 this, load)); 2075 this, load));
2059 return; 2076 return;
2060 } 2077 }
2061 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 2078 RTC_DCHECK(thread_checker_.CalledOnValidThread());
2062 if (!source_) { 2079 if (!source_) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 ConfigureVideoEncoderSettings(parameters_.codec_settings->codec); 2252 ConfigureVideoEncoderSettings(parameters_.codec_settings->codec);
2236 2253
2237 webrtc::VideoSendStream::Config config = parameters_.config.Copy(); 2254 webrtc::VideoSendStream::Config config = parameters_.config.Copy();
2238 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { 2255 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) {
2239 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " 2256 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX "
2240 "payload type the set codec. Ignoring RTX."; 2257 "payload type the set codec. Ignoring RTX.";
2241 config.rtp.rtx.ssrcs.clear(); 2258 config.rtp.rtx.ssrcs.clear();
2242 } 2259 }
2243 stream_ = call_->CreateVideoSendStream(std::move(config), 2260 stream_ = call_->CreateVideoSendStream(std::move(config),
2244 parameters_.encoder_config.Copy()); 2261 parameters_.encoder_config.Copy());
2262 stream_->SetSource(this);
2245 2263
2246 parameters_.encoder_config.encoder_specific_settings = NULL; 2264 parameters_.encoder_config.encoder_specific_settings = NULL;
2247 pending_encoder_reconfiguration_ = false; 2265 pending_encoder_reconfiguration_ = false;
2248 2266
2249 if (sending_) { 2267 if (sending_) {
2250 stream_->Start(); 2268 stream_->Start();
2251 } 2269 }
2252 } 2270 }
2253 2271
2254 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( 2272 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream(
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
2694 rtx_mapping[video_codecs[i].codec.id] != 2712 rtx_mapping[video_codecs[i].codec.id] !=
2695 fec_settings.red_payload_type) { 2713 fec_settings.red_payload_type) {
2696 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2714 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2697 } 2715 }
2698 } 2716 }
2699 2717
2700 return video_codecs; 2718 return video_codecs;
2701 } 2719 }
2702 2720
2703 } // namespace cricket 2721 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698