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

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

Issue 1766653002: Replace SetCapturer and SetCaptureDevice by SetSource. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Delete VideoCapturer::frame_stats_crit_ Created 4 years, 9 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
11 #include "webrtc/media/engine/webrtcvideoengine2.h" 11 #include "webrtc/media/engine/webrtcvideoengine2.h"
12 12
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <algorithm> 14 #include <algorithm>
15 #include <set> 15 #include <set>
16 #include <string> 16 #include <string>
17 17
18 #include "webrtc/base/copyonwritebuffer.h" 18 #include "webrtc/base/copyonwritebuffer.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/stringutils.h" 20 #include "webrtc/base/stringutils.h"
21 #include "webrtc/base/timeutils.h" 21 #include "webrtc/base/timeutils.h"
22 #include "webrtc/base/trace_event.h" 22 #include "webrtc/base/trace_event.h"
23 #include "webrtc/call.h" 23 #include "webrtc/call.h"
24 #include "webrtc/media/base/videocapturer.h"
25 #include "webrtc/media/base/videorenderer.h"
26 #include "webrtc/media/engine/constants.h" 24 #include "webrtc/media/engine/constants.h"
27 #include "webrtc/media/engine/simulcast.h" 25 #include "webrtc/media/engine/simulcast.h"
28 #include "webrtc/media/engine/webrtcmediaengine.h" 26 #include "webrtc/media/engine/webrtcmediaengine.h"
29 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" 27 #include "webrtc/media/engine/webrtcvideoencoderfactory.h"
30 #include "webrtc/media/engine/webrtcvideoframe.h" 28 #include "webrtc/media/engine/webrtcvideoframe.h"
31 #include "webrtc/media/engine/webrtcvoiceengine.h" 29 #include "webrtc/media/engine/webrtcvoiceengine.h"
32 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" 30 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
33 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" 31 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h"
34 #include "webrtc/system_wrappers/include/field_trial.h" 32 #include "webrtc/system_wrappers/include/field_trial.h"
35 #include "webrtc/video_decoder.h" 33 #include "webrtc/video_decoder.h"
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 } 990 }
993 if (send) { 991 if (send) {
994 StartAllSendStreams(); 992 StartAllSendStreams();
995 } else { 993 } else {
996 StopAllSendStreams(); 994 StopAllSendStreams();
997 } 995 }
998 sending_ = send; 996 sending_ = send;
999 return true; 997 return true;
1000 } 998 }
1001 999
1000 // TODO(nisse): Delete enable argument, was used for mute logic which
1001 // has been moved elsewhere.
pthatcher1 2016/03/22 21:47:11 In that case, you can just remove this whole metho
nisse-webrtc 2016/03/23 08:28:10 Good idea, but I think I'd prefer to do that in a
1002 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, 1002 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable,
1003 const VideoOptions* options) { 1003 const VideoOptions* options) {
1004 TRACE_EVENT0("webrtc", "SetVideoSend"); 1004 TRACE_EVENT0("webrtc", "SetVideoSend");
1005 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable 1005 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable
1006 << "options: " << (options ? options->ToString() : "nullptr") 1006 << "options: " << (options ? options->ToString() : "nullptr")
1007 << ")."; 1007 << ").";
1008 1008
1009 // TODO(solenberg): The state change should be fully rolled back if any one of
1010 // these calls fail.
1011 if (!MuteStream(ssrc, !enable)) {
1012 return false;
1013 }
1014 if (enable && options) { 1009 if (enable && options) {
1015 SetOptions(ssrc, *options); 1010 SetOptions(ssrc, *options);
1016 } 1011 }
1017 return true; 1012 return true;
1018 } 1013 }
1019 1014
1020 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( 1015 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability(
1021 const StreamParams& sp) const { 1016 const StreamParams& sp) const {
1022 for (uint32_t ssrc : sp.ssrcs) { 1017 for (uint32_t ssrc : sp.ssrcs) {
1023 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { 1018 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 // Get send stream bitrate stats. 1316 // Get send stream bitrate stats.
1322 rtc::CritScope stream_lock(&stream_crit_); 1317 rtc::CritScope stream_lock(&stream_crit_);
1323 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator stream = 1318 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator stream =
1324 send_streams_.begin(); 1319 send_streams_.begin();
1325 stream != send_streams_.end(); ++stream) { 1320 stream != send_streams_.end(); ++stream) {
1326 stream->second->FillBandwidthEstimationInfo(&bwe_info); 1321 stream->second->FillBandwidthEstimationInfo(&bwe_info);
1327 } 1322 }
1328 video_media_info->bw_estimations.push_back(bwe_info); 1323 video_media_info->bw_estimations.push_back(bwe_info);
1329 } 1324 }
1330 1325
1331 bool WebRtcVideoChannel2::SetCapturer(uint32_t ssrc, VideoCapturer* capturer) { 1326 void WebRtcVideoChannel2::SetSource(
1332 LOG(LS_INFO) << "SetCapturer: " << ssrc << " -> " 1327 uint32_t ssrc,
1333 << (capturer != NULL ? "(capturer)" : "NULL"); 1328 rtc::VideoSourceInterface<cricket::VideoFrame>* source) {
1329 LOG(LS_INFO) << "SetSource: " << ssrc << " -> "
1330 << (source ? "(source)" : "NULL");
1334 RTC_DCHECK(ssrc != 0); 1331 RTC_DCHECK(ssrc != 0);
1335 { 1332
1336 rtc::CritScope stream_lock(&stream_crit_); 1333 rtc::CritScope stream_lock(&stream_crit_);
1337 const auto& kv = send_streams_.find(ssrc); 1334 const auto& kv = send_streams_.find(ssrc);
1338 if (kv == send_streams_.end()) { 1335 if (kv == send_streams_.end()) {
1339 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; 1336 // Allow unknown ssrc only if source is null.
1340 return false; 1337 RTC_CHECK(source == nullptr);
1341 }
1342 if (!kv->second->SetCapturer(capturer)) {
1343 return false;
1344 }
1345 } 1338 }
1346 return true; 1339 else {
pthatcher1 2016/03/22 21:47:11 } else {
nisse-webrtc 2016/03/23 08:28:10 Done.
1340 kv->second->SetSource(source);
1341 }
1347 } 1342 }
1348 1343
1349 void WebRtcVideoChannel2::OnPacketReceived( 1344 void WebRtcVideoChannel2::OnPacketReceived(
1350 rtc::CopyOnWriteBuffer* packet, 1345 rtc::CopyOnWriteBuffer* packet,
1351 const rtc::PacketTime& packet_time) { 1346 const rtc::PacketTime& packet_time) {
1352 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 1347 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
1353 packet_time.not_before); 1348 packet_time.not_before);
1354 const webrtc::PacketReceiver::DeliveryStatus delivery_result = 1349 const webrtc::PacketReceiver::DeliveryStatus delivery_result =
1355 call_->Receiver()->DeliverPacket( 1350 call_->Receiver()->DeliverPacket(
1356 webrtc::MediaType::VIDEO, 1351 webrtc::MediaType::VIDEO,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 webrtc::MediaType::VIDEO, 1412 webrtc::MediaType::VIDEO,
1418 packet->cdata(), packet->size(), 1413 packet->cdata(), packet->size(),
1419 webrtc_packet_time); 1414 webrtc_packet_time);
1420 } 1415 }
1421 1416
1422 void WebRtcVideoChannel2::OnReadyToSend(bool ready) { 1417 void WebRtcVideoChannel2::OnReadyToSend(bool ready) {
1423 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); 1418 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready.");
1424 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); 1419 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown);
1425 } 1420 }
1426 1421
1427 bool WebRtcVideoChannel2::MuteStream(uint32_t ssrc, bool mute) {
1428 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> "
1429 << (mute ? "mute" : "unmute");
1430 RTC_DCHECK(ssrc != 0);
1431 rtc::CritScope stream_lock(&stream_crit_);
1432 const auto& kv = send_streams_.find(ssrc);
1433 if (kv == send_streams_.end()) {
1434 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc;
1435 return false;
1436 }
1437
1438 kv->second->MuteStream(mute);
1439 return true;
1440 }
1441
1442 // TODO(pbos): Remove SetOptions in favor of SetSendParameters. 1422 // TODO(pbos): Remove SetOptions in favor of SetSendParameters.
1443 void WebRtcVideoChannel2::SetOptions(uint32_t ssrc, 1423 void WebRtcVideoChannel2::SetOptions(uint32_t ssrc,
1444 const VideoOptions& options) { 1424 const VideoOptions& options) {
1445 LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString(); 1425 LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString();
1446 1426
1447 rtc::CritScope stream_lock(&stream_crit_); 1427 rtc::CritScope stream_lock(&stream_crit_);
1448 const auto& kv = send_streams_.find(ssrc); 1428 const auto& kv = send_streams_.find(ssrc);
1449 if (kv == send_streams_.end()) { 1429 if (kv == send_streams_.end()) {
1450 return; 1430 return;
1451 } 1431 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 const std::vector<webrtc::RtpExtension>& rtp_extensions, 1518 const std::vector<webrtc::RtpExtension>& rtp_extensions,
1539 // TODO(deadbeef): Don't duplicate information between send_params, 1519 // TODO(deadbeef): Don't duplicate information between send_params,
1540 // rtp_extensions, options, etc. 1520 // rtp_extensions, options, etc.
1541 const VideoSendParameters& send_params) 1521 const VideoSendParameters& send_params)
1542 : worker_thread_(rtc::Thread::Current()), 1522 : worker_thread_(rtc::Thread::Current()),
1543 ssrcs_(sp.ssrcs), 1523 ssrcs_(sp.ssrcs),
1544 ssrc_groups_(sp.ssrc_groups), 1524 ssrc_groups_(sp.ssrc_groups),
1545 call_(call), 1525 call_(call),
1546 cpu_restricted_counter_(0), 1526 cpu_restricted_counter_(0),
1547 number_of_cpu_adapt_changes_(0), 1527 number_of_cpu_adapt_changes_(0),
1548 capturer_(nullptr), 1528 source_(nullptr),
1549 external_encoder_factory_(external_encoder_factory), 1529 external_encoder_factory_(external_encoder_factory),
1550 stream_(nullptr), 1530 stream_(nullptr),
1551 parameters_(config, options, max_bitrate_bps, codec_settings), 1531 parameters_(config, options, max_bitrate_bps, codec_settings),
1552 rtp_parameters_(CreateRtpParametersWithOneEncoding()), 1532 rtp_parameters_(CreateRtpParametersWithOneEncoding()),
1553 pending_encoder_reconfiguration_(false), 1533 pending_encoder_reconfiguration_(false),
1554 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), 1534 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false),
1555 sending_(false), 1535 sending_(false),
1556 muted_(false),
1557 first_frame_timestamp_ms_(0), 1536 first_frame_timestamp_ms_(0),
1558 last_frame_timestamp_ms_(0) { 1537 last_frame_timestamp_ms_(0) {
1559 parameters_.config.rtp.max_packet_size = kVideoMtu; 1538 parameters_.config.rtp.max_packet_size = kVideoMtu;
1560 parameters_.conference_mode = send_params.conference_mode; 1539 parameters_.conference_mode = send_params.conference_mode;
1561 1540
1562 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs); 1541 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs);
1563 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, 1542 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs,
1564 &parameters_.config.rtp.rtx.ssrcs); 1543 &parameters_.config.rtp.rtx.ssrcs);
1565 parameters_.config.rtp.c_name = sp.cname; 1544 parameters_.config.rtp.c_name = sp.cname;
1566 parameters_.config.rtp.extensions = rtp_extensions; 1545 parameters_.config.rtp.extensions = rtp_extensions;
1567 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size 1546 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size
1568 ? webrtc::RtcpMode::kReducedSize 1547 ? webrtc::RtcpMode::kReducedSize
1569 : webrtc::RtcpMode::kCompound; 1548 : webrtc::RtcpMode::kCompound;
1570 parameters_.config.overuse_callback = 1549 parameters_.config.overuse_callback =
1571 enable_cpu_overuse_detection ? this : nullptr; 1550 enable_cpu_overuse_detection ? this : nullptr;
1572 1551
1573 sink_wants_.rotation_applied = !ContainsHeaderExtension( 1552 sink_wants_.rotation_applied = !ContainsHeaderExtension(
1574 rtp_extensions, kRtpVideoRotationHeaderExtension); 1553 rtp_extensions, kRtpVideoRotationHeaderExtension);
1575 1554
1576 if (codec_settings) { 1555 if (codec_settings) {
1577 SetCodec(*codec_settings); 1556 SetCodec(*codec_settings);
1578 } 1557 }
1579 } 1558 }
1580 1559
1581 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { 1560 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() {
1582 DisconnectCapturer(); 1561 DisconnectSource();
1583 if (stream_ != NULL) { 1562 if (stream_ != NULL) {
1584 call_->DestroyVideoSendStream(stream_); 1563 call_->DestroyVideoSendStream(stream_);
1585 } 1564 }
1586 DestroyVideoEncoder(&allocated_encoder_); 1565 DestroyVideoEncoder(&allocated_encoder_);
1587 } 1566 }
1588 1567
1589 static void CreateBlackFrame(webrtc::VideoFrame* video_frame, 1568 static void CreateBlackFrame(webrtc::VideoFrame* video_frame,
1590 int width, 1569 int width,
1591 int height, 1570 int height,
1592 webrtc::VideoRotation rotation) { 1571 webrtc::VideoRotation rotation) {
(...skipping 12 matching lines...) Expand all
1605 const VideoFrame& frame) { 1584 const VideoFrame& frame) {
1606 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); 1585 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame");
1607 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0, 1586 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0,
1608 frame.GetVideoRotation()); 1587 frame.GetVideoRotation());
1609 rtc::CritScope cs(&lock_); 1588 rtc::CritScope cs(&lock_);
1610 if (stream_ == NULL) { 1589 if (stream_ == NULL) {
1611 // Frame input before send codecs are configured, dropping frame. 1590 // Frame input before send codecs are configured, dropping frame.
1612 return; 1591 return;
1613 } 1592 }
1614 1593
1615 if (muted_) {
1616 // Create a black frame to transmit instead.
1617 CreateBlackFrame(&video_frame,
1618 static_cast<int>(frame.GetWidth()),
1619 static_cast<int>(frame.GetHeight()),
1620 video_frame.rotation());
1621 }
1622
1623 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; 1594 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec;
1624 // frame->GetTimeStamp() is essentially a delta, align to webrtc time 1595 // frame->GetTimeStamp() is essentially a delta, align to webrtc time
1625 if (first_frame_timestamp_ms_ == 0) { 1596 if (first_frame_timestamp_ms_ == 0) {
1626 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; 1597 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms;
1627 } 1598 }
1628 1599
1629 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; 1600 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms;
1630 video_frame.set_render_time_ms(last_frame_timestamp_ms_); 1601 video_frame.set_render_time_ms(last_frame_timestamp_ms_);
1631 // Reconfigure codec if necessary. 1602 // Reconfigure codec if necessary.
1632 SetDimensions(video_frame.width(), video_frame.height()); 1603 SetDimensions(video_frame.width(), video_frame.height());
1633 last_rotation_ = video_frame.rotation(); 1604 last_rotation_ = video_frame.rotation();
1634 1605
1635 // Not sending, abort after reconfiguration. Reconfiguration should still 1606 // Not sending, abort after reconfiguration. Reconfiguration should still
1636 // occur to permit sending this input as quickly as possible once we start 1607 // occur to permit sending this input as quickly as possible once we start
1637 // sending (without having to reconfigure then). 1608 // sending (without having to reconfigure then).
1638 if (!sending_) { 1609 if (!sending_) {
1639 return; 1610 return;
1640 } 1611 }
1641 1612
1642 stream_->Input()->IncomingCapturedFrame(video_frame); 1613 stream_->Input()->IncomingCapturedFrame(video_frame);
1643 } 1614 }
1644 1615
1645 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( 1616 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSource(
1646 VideoCapturer* capturer) { 1617 rtc::VideoSourceInterface<cricket::VideoFrame>* source) {
1647 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); 1618 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetSource");
1648 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 1619 RTC_DCHECK(thread_checker_.CalledOnValidThread());
1649 if (!DisconnectCapturer() && capturer == NULL) { 1620
1650 return false; 1621 if (!source && !source_)
1651 } 1622 return;
1623 DisconnectSource();
1652 1624
1653 { 1625 {
1654 rtc::CritScope cs(&lock_); 1626 rtc::CritScope cs(&lock_);
1655 1627
1656 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A 1628 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A
1657 // new capturer may have a different timestamp delta than the previous one. 1629 // new capturer may have a different timestamp delta than the previous one.
1658 first_frame_timestamp_ms_ = 0; 1630 first_frame_timestamp_ms_ = 0;
1659 1631
1660 if (capturer == NULL) { 1632 if (source == NULL) {
1661 if (stream_ != NULL) { 1633 if (stream_ != NULL) {
1662 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; 1634 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame.";
1663 webrtc::VideoFrame black_frame; 1635 webrtc::VideoFrame black_frame;
1664 1636
1665 CreateBlackFrame(&black_frame, last_dimensions_.width, 1637 CreateBlackFrame(&black_frame, last_dimensions_.width,
1666 last_dimensions_.height, last_rotation_); 1638 last_dimensions_.height, last_rotation_);
1667 1639
1668 // Force this black frame not to be dropped due to timestamp order 1640 // Force this black frame not to be dropped due to timestamp order
1669 // check. As IncomingCapturedFrame will drop the frame if this frame's 1641 // check. As IncomingCapturedFrame will drop the frame if this frame's
1670 // timestamp is less than or equal to last frame's timestamp, it is 1642 // timestamp is less than or equal to last frame's timestamp, it is
1671 // necessary to give this black frame a larger timestamp than the 1643 // necessary to give this black frame a larger timestamp than the
1672 // previous one. 1644 // previous one.
1673 last_frame_timestamp_ms_ += 1; 1645 last_frame_timestamp_ms_ += 1;
1674 black_frame.set_render_time_ms(last_frame_timestamp_ms_); 1646 black_frame.set_render_time_ms(last_frame_timestamp_ms_);
1675 stream_->Input()->IncomingCapturedFrame(black_frame); 1647 stream_->Input()->IncomingCapturedFrame(black_frame);
1676 } 1648 }
1677
1678 capturer_ = NULL;
1679 return true;
1680 } 1649 }
1650 // Clear the original dimensions, set it from first frame.
1651 input_dimensions_.width = input_dimensions_.height = 0;
1681 } 1652 }
1682 capturer_ = capturer; 1653 source_ = source;
1683 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since 1654 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since
1684 // that might cause a lock order inversion. 1655 // that might cause a lock order inversion.
1685 capturer_->AddOrUpdateSink(this, sink_wants_); 1656 if (source_) {
1686 return true; 1657 source_->AddOrUpdateSink(this, sink_wants_);
1658 }
1687 } 1659 }
1688 1660
1689 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { 1661 void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() {
1690 rtc::CritScope cs(&lock_);
1691 muted_ = mute;
1692 }
1693
1694 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() {
1695 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 1662 RTC_DCHECK(thread_checker_.CalledOnValidThread());
1696 if (capturer_ == NULL) { 1663 if (source_ == NULL) {
1697 return false; 1664 return;
1698 } 1665 }
1699 1666
1700 // |capturer_->RemoveSink| may not be called while holding |lock_| since 1667 // |source_->RemoveSink| may not be called while holding |lock_| since
1701 // that might cause a lock order inversion. 1668 // that might cause a lock order inversion.
1702 capturer_->RemoveSink(this); 1669 source_->RemoveSink(this);
1703 capturer_ = NULL; 1670 source_ = NULL;
1704 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not 1671 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not
1705 // possible to know if the video resolution is restricted by CPU usage after 1672 // possible to know if the video resolution is restricted by CPU usage after
1706 // the capturer is changed since the next capturer might be screen capture 1673 // the capturer is changed since the next capturer might be screen capture
1707 // with another resolution and frame rate. 1674 // with another resolution and frame rate.
1708 cpu_restricted_counter_ = 0; 1675 cpu_restricted_counter_ = 0;
1709 return true;
1710 } 1676 }
1711 1677
1712 const std::vector<uint32_t>& 1678 const std::vector<uint32_t>&
1713 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { 1679 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const {
1714 return ssrcs_; 1680 return ssrcs_;
1715 } 1681 }
1716 1682
1717 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( 1683 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions(
1718 const VideoOptions& options) { 1684 const VideoOptions& options) {
1719 rtc::CritScope cs(&lock_); 1685 rtc::CritScope cs(&lock_);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 << "RecreateWebRtcStream (send) because of SetSendParameters"; 1823 << "RecreateWebRtcStream (send) because of SetSendParameters";
1858 RecreateWebRtcStream(); 1824 RecreateWebRtcStream();
1859 } 1825 }
1860 } // release |lock_| 1826 } // release |lock_|
1861 1827
1862 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since 1828 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since
1863 // that might cause a lock order inversion. 1829 // that might cause a lock order inversion.
1864 if (params.rtp_header_extensions) { 1830 if (params.rtp_header_extensions) {
1865 sink_wants_.rotation_applied = !ContainsHeaderExtension( 1831 sink_wants_.rotation_applied = !ContainsHeaderExtension(
1866 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); 1832 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension);
1867 if (capturer_) { 1833 if (source_) {
1868 capturer_->AddOrUpdateSink(this, sink_wants_); 1834 source_->AddOrUpdateSink(this, sink_wants_);
1869 } 1835 }
1870 } 1836 }
1871 } 1837 }
1872 1838
1873 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpParameters( 1839 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpParameters(
1874 const webrtc::RtpParameters& new_parameters) { 1840 const webrtc::RtpParameters& new_parameters) {
1875 if (!ValidateRtpParameters(new_parameters)) { 1841 if (!ValidateRtpParameters(new_parameters)) {
1876 return false; 1842 return false;
1877 } 1843 }
1878 1844
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 encoder_config.streams.size() == 1) { 1925 encoder_config.streams.size() == 1) {
1960 encoder_config.streams[0].temporal_layer_thresholds_bps.resize( 1926 encoder_config.streams[0].temporal_layer_thresholds_bps.resize(
1961 GetDefaultVp9TemporalLayers() - 1); 1927 GetDefaultVp9TemporalLayers() - 1);
1962 } 1928 }
1963 return encoder_config; 1929 return encoder_config;
1964 } 1930 }
1965 1931
1966 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( 1932 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions(
1967 int width, 1933 int width,
1968 int height) { 1934 int height) {
1935 if (input_dimensions_.width == 0 && input_dimensions_.height == 0) {
1936 input_dimensions_.width = width;
1937 input_dimensions_.height = height;
1938 }
1969 if (last_dimensions_.width == width && last_dimensions_.height == height && 1939 if (last_dimensions_.width == width && last_dimensions_.height == height &&
1970 !pending_encoder_reconfiguration_) { 1940 !pending_encoder_reconfiguration_) {
1971 // Configured using the same parameters, do not reconfigure. 1941 // Configured using the same parameters, do not reconfigure.
1972 return; 1942 return;
1973 } 1943 }
1974 1944
1975 last_dimensions_.width = width; 1945 last_dimensions_.width = width;
1976 last_dimensions_.height = height; 1946 last_dimensions_.height = height;
1977 1947
1978 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); 1948 RTC_DCHECK(!parameters_.encoder_config.streams.empty());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 1981
2012 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { 1982 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) {
2013 if (worker_thread_ != rtc::Thread::Current()) { 1983 if (worker_thread_ != rtc::Thread::Current()) {
2014 invoker_.AsyncInvoke<void>( 1984 invoker_.AsyncInvoke<void>(
2015 worker_thread_, 1985 worker_thread_,
2016 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, 1986 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate,
2017 this, load)); 1987 this, load));
2018 return; 1988 return;
2019 } 1989 }
2020 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 1990 RTC_DCHECK(thread_checker_.CalledOnValidThread());
2021 if (!capturer_) { 1991 if (!source_) {
2022 return; 1992 return;
2023 } 1993 }
2024 { 1994 {
2025 rtc::CritScope cs(&lock_); 1995 rtc::CritScope cs(&lock_);
2026 LOG(LS_INFO) << "OnLoadUpdate " << load << ", is_screencast: " 1996 LOG(LS_INFO) << "OnLoadUpdate " << load << ", is_screencast: "
2027 << (parameters_.options.is_screencast 1997 << (parameters_.options.is_screencast
2028 ? (*parameters_.options.is_screencast ? "true" 1998 ? (*parameters_.options.is_screencast ? "true"
2029 : "false") 1999 : "false")
2030 : "unset"); 2000 : "unset");
2031 // Do not adapt resolution for screen content as this will likely result in 2001 // Do not adapt resolution for screen content as this will likely result in
(...skipping 26 matching lines...) Expand all
2058 if (sink_wants_.max_pixel_count || 2028 if (sink_wants_.max_pixel_count ||
2059 (sink_wants_.max_pixel_count_step_up && 2029 (sink_wants_.max_pixel_count_step_up &&
2060 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { 2030 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) {
2061 ++number_of_cpu_adapt_changes_; 2031 ++number_of_cpu_adapt_changes_;
2062 --cpu_restricted_counter_; 2032 --cpu_restricted_counter_;
2063 } 2033 }
2064 } 2034 }
2065 sink_wants_.max_pixel_count = max_pixel_count; 2035 sink_wants_.max_pixel_count = max_pixel_count;
2066 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up; 2036 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up;
2067 } 2037 }
2068 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since 2038 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since
2069 // that might cause a lock order inversion. 2039 // that might cause a lock order inversion.
2070 capturer_->AddOrUpdateSink(this, sink_wants_); 2040 source_->AddOrUpdateSink(this, sink_wants_);
2071 } 2041 }
2072 2042
2073 VideoSenderInfo 2043 VideoSenderInfo
2074 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { 2044 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() {
2075 VideoSenderInfo info; 2045 VideoSenderInfo info;
2076 webrtc::VideoSendStream::Stats stats; 2046 webrtc::VideoSendStream::Stats stats;
2077 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 2047 RTC_DCHECK(thread_checker_.CalledOnValidThread());
2078 { 2048 {
2079 rtc::CritScope cs(&lock_); 2049 rtc::CritScope cs(&lock_);
2080 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) 2050 for (uint32_t ssrc : parameters_.config.rtp.ssrcs)
2081 info.add_ssrc(ssrc); 2051 info.add_ssrc(ssrc);
2082 2052
2083 if (parameters_.codec_settings) 2053 if (parameters_.codec_settings)
2084 info.codec_name = parameters_.codec_settings->codec.name; 2054 info.codec_name = parameters_.codec_settings->codec.name;
2085 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { 2055 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) {
2086 if (i == parameters_.encoder_config.streams.size() - 1) { 2056 if (i == parameters_.encoder_config.streams.size() - 1) {
2087 info.preferred_bitrate += 2057 info.preferred_bitrate +=
2088 parameters_.encoder_config.streams[i].max_bitrate_bps; 2058 parameters_.encoder_config.streams[i].max_bitrate_bps;
2089 } else { 2059 } else {
2090 info.preferred_bitrate += 2060 info.preferred_bitrate +=
2091 parameters_.encoder_config.streams[i].target_bitrate_bps; 2061 parameters_.encoder_config.streams[i].target_bitrate_bps;
2092 } 2062 }
2093 } 2063 }
2094 2064
2095 if (stream_ == NULL) 2065 if (stream_ == NULL)
2096 return info; 2066 return info;
2097 2067
2098 stats = stream_->GetStats(); 2068 stats = stream_->GetStats();
2069
2070 info.input_frame_width = input_dimensions_.width;
2071 info.input_frame_height = input_dimensions_.height;
2099 } 2072 }
2100 info.adapt_changes = number_of_cpu_adapt_changes_; 2073 info.adapt_changes = number_of_cpu_adapt_changes_;
2101 info.adapt_reason = cpu_restricted_counter_ <= 0 2074 info.adapt_reason = cpu_restricted_counter_ <= 0
2102 ? CoordinatedVideoAdapter::ADAPTREASON_NONE 2075 ? CoordinatedVideoAdapter::ADAPTREASON_NONE
2103 : CoordinatedVideoAdapter::ADAPTREASON_CPU; 2076 : CoordinatedVideoAdapter::ADAPTREASON_CPU;
2104 2077
2105 if (capturer_) {
2106 VideoFormat last_captured_frame_format;
2107 capturer_->GetStats(&last_captured_frame_format);
2108 info.input_frame_width = last_captured_frame_format.width;
2109 info.input_frame_height = last_captured_frame_format.height;
2110 }
2111
2112 // Get bandwidth limitation info from stream_->GetStats(). 2078 // Get bandwidth limitation info from stream_->GetStats().
2113 // Input resolution (output from video_adapter) can be further scaled down or 2079 // Input resolution (output from video_adapter) can be further scaled down or
2114 // higher video layer(s) can be dropped due to bitrate constraints. 2080 // higher video layer(s) can be dropped due to bitrate constraints.
2115 // Note, adapt_changes only include changes from the video_adapter. 2081 // Note, adapt_changes only include changes from the video_adapter.
2116 if (stats.bw_limited_resolution) 2082 if (stats.bw_limited_resolution)
2117 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; 2083 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH;
2118 2084
2119 info.encoder_implementation_name = stats.encoder_implementation_name; 2085 info.encoder_implementation_name = stats.encoder_implementation_name;
2120 info.ssrc_groups = ssrc_groups_; 2086 info.ssrc_groups = ssrc_groups_;
2121 info.framerate_input = stats.input_frame_rate; 2087 info.framerate_input = stats.input_frame_rate;
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 rtx_mapping[video_codecs[i].codec.id] != 2579 rtx_mapping[video_codecs[i].codec.id] !=
2614 fec_settings.red_payload_type) { 2580 fec_settings.red_payload_type) {
2615 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2581 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2616 } 2582 }
2617 } 2583 }
2618 2584
2619 return video_codecs; 2585 return video_codecs;
2620 } 2586 }
2621 2587
2622 } // namespace cricket 2588 } // namespace cricket
OLDNEW
« 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