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

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: Addressed 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 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 ssrcs_(sp.ssrcs), 1575 ssrcs_(sp.ssrcs),
1576 ssrc_groups_(sp.ssrc_groups), 1576 ssrc_groups_(sp.ssrc_groups),
1577 call_(call), 1577 call_(call),
1578 cpu_restricted_counter_(0), 1578 cpu_restricted_counter_(0),
1579 number_of_cpu_adapt_changes_(0), 1579 number_of_cpu_adapt_changes_(0),
1580 frame_count_(0), 1580 frame_count_(0),
1581 cpu_restricted_frame_count_(0), 1581 cpu_restricted_frame_count_(0),
1582 source_(nullptr), 1582 source_(nullptr),
1583 external_encoder_factory_(external_encoder_factory), 1583 external_encoder_factory_(external_encoder_factory),
1584 stream_(nullptr), 1584 stream_(nullptr),
1585 encoder_sink_(nullptr),
1585 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), 1586 parameters_(std::move(config), options, max_bitrate_bps, codec_settings),
1586 rtp_parameters_(CreateRtpParametersWithOneEncoding()), 1587 rtp_parameters_(CreateRtpParametersWithOneEncoding()),
1587 pending_encoder_reconfiguration_(false), 1588 pending_encoder_reconfiguration_(false),
1588 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), 1589 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false),
1589 sending_(false), 1590 sending_(false),
1590 last_frame_timestamp_ms_(0) { 1591 last_frame_timestamp_ms_(0) {
1591 parameters_.config.rtp.max_packet_size = kVideoMtu; 1592 parameters_.config.rtp.max_packet_size = kVideoMtu;
1592 parameters_.conference_mode = send_params.conference_mode; 1593 parameters_.conference_mode = send_params.conference_mode;
1593 1594
1594 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs); 1595 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs);
(...skipping 57 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 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; 1668 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec;
1668 1669
1669 // frame->GetTimeStamp() is essentially a delta, align to webrtc time 1670 // frame->GetTimeStamp() is essentially a delta, align to webrtc time
1670 if (!first_frame_timestamp_ms_) { 1671 if (!first_frame_timestamp_ms_) {
1671 first_frame_timestamp_ms_ = 1672 first_frame_timestamp_ms_ =
1672 rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms); 1673 rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms);
(...skipping 12 matching lines...) Expand all
1685 // occur to permit sending this input as quickly as possible once we start 1686 // occur to permit sending this input as quickly as possible once we start
1686 // sending (without having to reconfigure then). 1687 // sending (without having to reconfigure then).
1687 if (!sending_) { 1688 if (!sending_) {
1688 return; 1689 return;
1689 } 1690 }
1690 1691
1691 ++frame_count_; 1692 ++frame_count_;
1692 if (cpu_restricted_counter_ > 0) 1693 if (cpu_restricted_counter_ > 0)
1693 ++cpu_restricted_frame_count_; 1694 ++cpu_restricted_frame_count_;
1694 1695
1695 stream_->Input()->IncomingCapturedFrame(video_frame); 1696 encoder_sink_->OnFrame(video_frame);
1696 } 1697 }
1697 1698
1698 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend( 1699 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend(
1699 bool enable, 1700 bool enable,
1700 const VideoOptions* options, 1701 const VideoOptions* options,
1701 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { 1702 rtc::VideoSourceInterface<cricket::VideoFrame>* source) {
1702 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend"); 1703 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend");
1703 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 1704 RTC_DCHECK(thread_checker_.CalledOnValidThread());
1704 1705
1705 // Ignore |options| pointer if |enable| is false. 1706 // Ignore |options| pointer if |enable| is false.
1706 bool options_present = enable && options; 1707 bool options_present = enable && options;
1707 bool source_changing = source_ != source; 1708 bool source_changing = source_ != source;
1708 if (source_changing) { 1709 if (source_changing) {
1709 DisconnectSource(); 1710 DisconnectSource();
1710 } 1711 }
1711 1712
1712 if (options_present || source_changing) { 1713 if (options_present || source_changing) {
1713 rtc::CritScope cs(&lock_); 1714 rtc::CritScope cs(&lock_);
1714 1715
1715 if (options_present) { 1716 if (options_present) {
1716 VideoOptions old_options = parameters_.options; 1717 VideoOptions old_options = parameters_.options;
1717 parameters_.options.SetAll(*options); 1718 parameters_.options.SetAll(*options);
1718 // Reconfigure encoder settings on the naext frame or stream 1719 // Reconfigure encoder settings on the next frame or stream
1719 // recreation if the options changed. 1720 // recreation if the options changed.
1720 if (parameters_.options != old_options) { 1721 if (parameters_.options != old_options) {
1721 pending_encoder_reconfiguration_ = true; 1722 pending_encoder_reconfiguration_ = true;
1722 } 1723 }
1723 } 1724 }
1724 1725
1725 if (source_changing) { 1726 if (source_changing) {
1726 // Reset timestamps to realign new incoming frames to a webrtc timestamp. 1727 // Reset timestamps to realign new incoming frames to a webrtc timestamp.
1727 // A new source may have a different timestamp delta than the previous 1728 // A new source may have a different timestamp delta than the previous
1728 // one. 1729 // one.
1729 first_frame_timestamp_ms_ = rtc::Optional<int64_t>(); 1730 first_frame_timestamp_ms_ = rtc::Optional<int64_t>();
1730 1731
1731 if (source == nullptr && stream_ != nullptr) { 1732 if (source == nullptr && encoder_sink_ != nullptr) {
1732 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; 1733 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame.";
1733 // Force this black frame not to be dropped due to timestamp order 1734 // Force this black frame not to be dropped due to timestamp order
1734 // check. As IncomingCapturedFrame will drop the frame if this frame's 1735 // check. As IncomingCapturedFrame will drop the frame if this frame's
1735 // timestamp is less than or equal to last frame's timestamp, it is 1736 // timestamp is less than or equal to last frame's timestamp, it is
1736 // necessary to give this black frame a larger timestamp than the 1737 // necessary to give this black frame a larger timestamp than the
1737 // previous one. 1738 // previous one.
1738 last_frame_timestamp_ms_ += 1; 1739 last_frame_timestamp_ms_ += 1;
1739 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer( 1740 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer(
1740 webrtc::I420Buffer::Create(last_frame_info_.width, 1741 webrtc::I420Buffer::Create(last_frame_info_.width,
1741 last_frame_info_.height)); 1742 last_frame_info_.height));
1742 black_buffer->SetToBlack(); 1743 black_buffer->SetToBlack();
1743 1744
1744 stream_->Input()->IncomingCapturedFrame(webrtc::VideoFrame( 1745 encoder_sink_->OnFrame(webrtc::VideoFrame(
1745 black_buffer, 0 /* timestamp (90 kHz) */, 1746 black_buffer, 0 /* timestamp (90 kHz) */, last_frame_timestamp_ms_,
1746 last_frame_timestamp_ms_, last_frame_info_.rotation)); 1747 last_frame_info_.rotation));
1747 } 1748 }
1748 source_ = source; 1749 source_ = source;
1749 } 1750 }
1750 } 1751 }
1751 1752
1752 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since 1753 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since
1753 // that might cause a lock order inversion. 1754 // that might cause a lock order inversion.
1754 if (source_changing && source_) { 1755 if (source_changing && source_) {
1755 source_->AddOrUpdateSink(this, sink_wants_); 1756 source_->AddOrUpdateSink(this, sink_wants_);
1756 } 1757 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 2059
2059 parameters_.encoder_config = std::move(encoder_config); 2060 parameters_.encoder_config = std::move(encoder_config);
2060 } 2061 }
2061 2062
2062 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) { 2063 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) {
2063 rtc::CritScope cs(&lock_); 2064 rtc::CritScope cs(&lock_);
2064 sending_ = send; 2065 sending_ = send;
2065 UpdateSendState(); 2066 UpdateSendState();
2066 } 2067 }
2067 2068
2069 void WebRtcVideoChannel2::WebRtcVideoSendStream::AddOrUpdateSink(
2070 VideoSinkInterface<webrtc::VideoFrame>* sink,
2071 const rtc::VideoSinkWants& wants) {
2072 // TODO(perkj): Actually consider the encoder |wants| and remove
2073 // WebRtcVideoSendStream::OnLoadUpdate(Load load).
2074 rtc::CritScope cs(&lock_);
2075 RTC_DCHECK(!encoder_sink_ || encoder_sink_ == sink);
2076 encoder_sink_ = sink;
2077 }
2078
2079 void WebRtcVideoChannel2::WebRtcVideoSendStream::RemoveSink(
2080 VideoSinkInterface<webrtc::VideoFrame>* sink) {
2081 rtc::CritScope cs(&lock_);
2082 RTC_DCHECK(encoder_sink_&& encoder_sink_ = sink);
sprang_webrtc 2016/09/02 07:19:31 You don't need to check encoder_sink_ != nullptr i
nisse-webrtc 2016/09/02 08:10:18 I think it is desirable to fail this DCHECK in the
sprang_webrtc 2016/09/02 09:07:04 Sure, but then I'd rather check that sink != nullp
perkj_webrtc 2016/09/02 12:18:21 Prefer just DCHECK(sink_ == sink);
2083 encoder_sink_ = nullptr;
2084 }
2085
2068 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { 2086 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) {
2069 if (worker_thread_ != rtc::Thread::Current()) { 2087 if (worker_thread_ != rtc::Thread::Current()) {
2070 invoker_.AsyncInvoke<void>( 2088 invoker_.AsyncInvoke<void>(
2071 RTC_FROM_HERE, worker_thread_, 2089 RTC_FROM_HERE, worker_thread_,
2072 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, 2090 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate,
2073 this, load)); 2091 this, load));
2074 return; 2092 return;
2075 } 2093 }
2076 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 2094 RTC_DCHECK(thread_checker_.CalledOnValidThread());
2077 if (!source_) { 2095 if (!source_) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 ConfigureVideoEncoderSettings(parameters_.codec_settings->codec); 2268 ConfigureVideoEncoderSettings(parameters_.codec_settings->codec);
2251 2269
2252 webrtc::VideoSendStream::Config config = parameters_.config.Copy(); 2270 webrtc::VideoSendStream::Config config = parameters_.config.Copy();
2253 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { 2271 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) {
2254 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " 2272 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX "
2255 "payload type the set codec. Ignoring RTX."; 2273 "payload type the set codec. Ignoring RTX.";
2256 config.rtp.rtx.ssrcs.clear(); 2274 config.rtp.rtx.ssrcs.clear();
2257 } 2275 }
2258 stream_ = call_->CreateVideoSendStream(std::move(config), 2276 stream_ = call_->CreateVideoSendStream(std::move(config),
2259 parameters_.encoder_config.Copy()); 2277 parameters_.encoder_config.Copy());
2278 stream_->SetSource(this);
2260 2279
2261 parameters_.encoder_config.encoder_specific_settings = NULL; 2280 parameters_.encoder_config.encoder_specific_settings = NULL;
2262 pending_encoder_reconfiguration_ = false; 2281 pending_encoder_reconfiguration_ = false;
2263 2282
2264 if (sending_) { 2283 if (sending_) {
2265 stream_->Start(); 2284 stream_->Start();
2266 } 2285 }
2267 } 2286 }
2268 2287
2269 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( 2288 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream(
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
2709 rtx_mapping[video_codecs[i].codec.id] != 2728 rtx_mapping[video_codecs[i].codec.id] !=
2710 fec_settings.red_payload_type) { 2729 fec_settings.red_payload_type) {
2711 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2730 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2712 } 2731 }
2713 } 2732 }
2714 2733
2715 return video_codecs; 2734 return video_codecs;
2716 } 2735 }
2717 2736
2718 } // namespace cricket 2737 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698