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

Side by Side 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: Created 4 years, 8 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 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 { 991 {
992 rtc::CritScope stream_lock(&stream_crit_); 992 rtc::CritScope stream_lock(&stream_crit_);
993 for (const auto& kv : send_streams_) { 993 for (const auto& kv : send_streams_) {
994 kv.second->SetSend(send); 994 kv.second->SetSend(send);
995 } 995 }
996 } 996 }
997 sending_ = send; 997 sending_ = send;
998 return true; 998 return true;
999 } 999 }
1000 1000
1001 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, 1001 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc,
1002 const VideoOptions* options) { 1002 bool enable,
1003 const VideoOptions* options,
1004 VideoCapturer* capturer) {
1003 TRACE_EVENT0("webrtc", "SetVideoSend"); 1005 TRACE_EVENT0("webrtc", "SetVideoSend");
1006 RTC_DCHECK(ssrc != 0);
1004 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable 1007 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable
1005 << "options: " << (options ? options->ToString() : "nullptr") 1008 << "options: " << (options ? options->ToString() : "nullptr")
1006 << ")."; 1009 << ", capturer = "
1010 << (capturer != nullptr ? "(capturer)" : "NULL") << ")";
1007 1011
1008 // TODO(solenberg): The state change should be fully rolled back if any one of 1012 // TODO(solenberg): The state change should be fully rolled back if any one of
1009 // these calls fail. 1013 // these calls fail.
1010 if (!MuteStream(ssrc, !enable)) { 1014 rtc::CritScope stream_lock(&stream_crit_);
1015 const auto& kv = send_streams_.find(ssrc);
1016 if (kv == send_streams_.end()) {
1017 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc;
1011 return false; 1018 return false;
1012 } 1019 }
1013 if (enable && options) { 1020
1014 SetOptions(ssrc, *options); 1021 kv->second->SetVideoSend(enable, options, capturer);
1015 }
1016 return true; 1022 return true;
1017 } 1023 }
1018 1024
1019 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( 1025 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability(
1020 const StreamParams& sp) const { 1026 const StreamParams& sp) const {
1021 for (uint32_t ssrc : sp.ssrcs) { 1027 for (uint32_t ssrc : sp.ssrcs) {
1022 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { 1028 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) {
1023 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; 1029 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists.";
1024 return false; 1030 return false;
1025 } 1031 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 // Get send stream bitrate stats. 1311 // Get send stream bitrate stats.
1306 rtc::CritScope stream_lock(&stream_crit_); 1312 rtc::CritScope stream_lock(&stream_crit_);
1307 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator stream = 1313 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator stream =
1308 send_streams_.begin(); 1314 send_streams_.begin();
1309 stream != send_streams_.end(); ++stream) { 1315 stream != send_streams_.end(); ++stream) {
1310 stream->second->FillBandwidthEstimationInfo(&bwe_info); 1316 stream->second->FillBandwidthEstimationInfo(&bwe_info);
1311 } 1317 }
1312 video_media_info->bw_estimations.push_back(bwe_info); 1318 video_media_info->bw_estimations.push_back(bwe_info);
1313 } 1319 }
1314 1320
1315 bool WebRtcVideoChannel2::SetCapturer(uint32_t ssrc, VideoCapturer* capturer) {
1316 LOG(LS_INFO) << "SetCapturer: " << ssrc << " -> "
1317 << (capturer != NULL ? "(capturer)" : "NULL");
1318 RTC_DCHECK(ssrc != 0);
1319 {
1320 rtc::CritScope stream_lock(&stream_crit_);
1321 const auto& kv = send_streams_.find(ssrc);
1322 if (kv == send_streams_.end()) {
1323 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc;
1324 return false;
1325 }
1326 if (!kv->second->SetCapturer(capturer)) {
1327 return false;
1328 }
1329 }
1330 return true;
1331 }
1332
1333 void WebRtcVideoChannel2::OnPacketReceived( 1321 void WebRtcVideoChannel2::OnPacketReceived(
1334 rtc::CopyOnWriteBuffer* packet, 1322 rtc::CopyOnWriteBuffer* packet,
1335 const rtc::PacketTime& packet_time) { 1323 const rtc::PacketTime& packet_time) {
1336 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 1324 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
1337 packet_time.not_before); 1325 packet_time.not_before);
1338 const webrtc::PacketReceiver::DeliveryStatus delivery_result = 1326 const webrtc::PacketReceiver::DeliveryStatus delivery_result =
1339 call_->Receiver()->DeliverPacket( 1327 call_->Receiver()->DeliverPacket(
1340 webrtc::MediaType::VIDEO, 1328 webrtc::MediaType::VIDEO,
1341 packet->cdata(), packet->size(), 1329 packet->cdata(), packet->size(),
1342 webrtc_packet_time); 1330 webrtc_packet_time);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 webrtc_packet_time); 1391 webrtc_packet_time);
1404 } 1392 }
1405 1393
1406 void WebRtcVideoChannel2::OnReadyToSend(bool ready) { 1394 void WebRtcVideoChannel2::OnReadyToSend(bool ready) {
1407 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); 1395 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready.");
1408 call_->SignalChannelNetworkState( 1396 call_->SignalChannelNetworkState(
1409 webrtc::MediaType::VIDEO, 1397 webrtc::MediaType::VIDEO,
1410 ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); 1398 ready ? webrtc::kNetworkUp : webrtc::kNetworkDown);
1411 } 1399 }
1412 1400
1413 bool WebRtcVideoChannel2::MuteStream(uint32_t ssrc, bool mute) {
1414 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> "
1415 << (mute ? "mute" : "unmute");
1416 RTC_DCHECK(ssrc != 0);
1417 rtc::CritScope stream_lock(&stream_crit_);
1418 const auto& kv = send_streams_.find(ssrc);
1419 if (kv == send_streams_.end()) {
1420 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc;
1421 return false;
1422 }
1423
1424 kv->second->MuteStream(mute);
1425 return true;
1426 }
1427
1428 // TODO(pbos): Remove SetOptions in favor of SetSendParameters.
1429 void WebRtcVideoChannel2::SetOptions(uint32_t ssrc,
1430 const VideoOptions& options) {
1431 LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString();
1432
1433 rtc::CritScope stream_lock(&stream_crit_);
1434 const auto& kv = send_streams_.find(ssrc);
1435 if (kv == send_streams_.end()) {
1436 return;
1437 }
1438 kv->second->SetOptions(options);
1439 }
1440
1441 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) { 1401 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) {
1442 MediaChannel::SetInterface(iface); 1402 MediaChannel::SetInterface(iface);
1443 // Set the RTP recv/send buffer to a bigger size 1403 // Set the RTP recv/send buffer to a bigger size
1444 MediaChannel::SetOption(NetworkInterface::ST_RTP, 1404 MediaChannel::SetOption(NetworkInterface::ST_RTP,
1445 rtc::Socket::OPT_RCVBUF, 1405 rtc::Socket::OPT_RCVBUF,
1446 kVideoRtpBufferSize); 1406 kVideoRtpBufferSize);
1447 1407
1448 // Speculative change to increase the outbound socket buffer size. 1408 // Speculative change to increase the outbound socket buffer size.
1449 // In b/15152257, we are seeing a significant number of packets discarded 1409 // In b/15152257, we are seeing a significant number of packets discarded
1450 // due to lack of socket buffer space, although it's not yet clear what the 1410 // due to lack of socket buffer space, although it's not yet clear what the
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 // Not sending, abort after reconfiguration. Reconfiguration should still 1563 // Not sending, abort after reconfiguration. Reconfiguration should still
1604 // occur to permit sending this input as quickly as possible once we start 1564 // occur to permit sending this input as quickly as possible once we start
1605 // sending (without having to reconfigure then). 1565 // sending (without having to reconfigure then).
1606 if (!sending_) { 1566 if (!sending_) {
1607 return; 1567 return;
1608 } 1568 }
1609 1569
1610 stream_->Input()->IncomingCapturedFrame(video_frame); 1570 stream_->Input()->IncomingCapturedFrame(video_frame);
1611 } 1571 }
1612 1572
1613 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( 1573 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend(
1574 bool enable,
1575 const VideoOptions* options,
1614 VideoCapturer* capturer) { 1576 VideoCapturer* capturer) {
1615 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); 1577 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend");
1616 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 1578 RTC_DCHECK(thread_checker_.CalledOnValidThread());
1617 if (!DisconnectCapturer() && capturer == NULL) { 1579
1618 return false; 1580 bool capturer_changing = capturer_ != capturer;
1581 if (capturer_changing) {
1582 if (!DisconnectCapturer() && capturer == nullptr) {
1583 return false;
1584 }
1619 } 1585 }
1620 1586
1621 { 1587 {
1622 rtc::CritScope cs(&lock_); 1588 rtc::CritScope cs(&lock_);
1623 1589
1624 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A 1590 muted_ = !enable;
1625 // new capturer may have a different timestamp delta than the previous one. 1591 if (enable && options) {
1626 first_frame_timestamp_ms_ = 0; 1592 VideoOptions old_options = parameters_.options;
1593 parameters_.options.SetAll(*options);
1594 if (parameters_.options != old_options) {
1595 // Reconfigure encoder settings on the next frame or stream recreation.
1596 pending_encoder_reconfiguration_ = true;
1597 }
1598 }
1627 1599
1628 if (capturer == NULL) { 1600 if (capturer_changing) {
1629 if (stream_ != NULL) { 1601 // Reset timestamps to realign new incoming frames to a webrtc timestamp.
1602 // A new capturer may have a different timestamp delta than the previous
1603 // one.
1604 first_frame_timestamp_ms_ = 0;
1605
1606 if (capturer == nullptr && stream_ != nullptr) {
1630 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; 1607 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame.";
1631 webrtc::VideoFrame black_frame; 1608 webrtc::VideoFrame black_frame;
1632 1609
1633 CreateBlackFrame(&black_frame, last_dimensions_.width, 1610 CreateBlackFrame(&black_frame, last_dimensions_.width,
1634 last_dimensions_.height, last_rotation_); 1611 last_dimensions_.height, last_rotation_);
1635 1612
1636 // Force this black frame not to be dropped due to timestamp order 1613 // Force this black frame not to be dropped due to timestamp order
1637 // check. As IncomingCapturedFrame will drop the frame if this frame's 1614 // check. As IncomingCapturedFrame will drop the frame if this frame's
1638 // timestamp is less than or equal to last frame's timestamp, it is 1615 // timestamp is less than or equal to last frame's timestamp, it is
1639 // necessary to give this black frame a larger timestamp than the 1616 // necessary to give this black frame a larger timestamp than the
1640 // previous one. 1617 // previous one.
1641 last_frame_timestamp_ms_ += 1; 1618 last_frame_timestamp_ms_ += 1;
1642 black_frame.set_render_time_ms(last_frame_timestamp_ms_); 1619 black_frame.set_render_time_ms(last_frame_timestamp_ms_);
1643 stream_->Input()->IncomingCapturedFrame(black_frame); 1620 stream_->Input()->IncomingCapturedFrame(black_frame);
1644 } 1621 }
1645 1622 capturer_ = capturer;
1646 capturer_ = NULL;
1647 return true;
Taylor Brandstetter 2016/03/29 22:30:35 I got rid of this early return and added "if (capt
1648 } 1623 }
1649 } 1624 }
1650 capturer_ = capturer; 1625
1651 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since 1626 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since
1652 // that might cause a lock order inversion. 1627 // that might cause a lock order inversion.
1653 capturer_->AddOrUpdateSink(this, sink_wants_); 1628 if (capturer_changing && capturer_ != nullptr) {
1629 capturer_->AddOrUpdateSink(this, sink_wants_);
1630 }
1654 return true; 1631 return true;
1655 } 1632 }
1656 1633
1657 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) {
1658 rtc::CritScope cs(&lock_);
1659 muted_ = mute;
1660 }
1661
1662 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { 1634 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() {
1663 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 1635 RTC_DCHECK(thread_checker_.CalledOnValidThread());
1664 if (capturer_ == NULL) { 1636 if (capturer_ == NULL) {
1665 return false; 1637 return false;
1666 } 1638 }
1667 1639
1668 // |capturer_->RemoveSink| may not be called while holding |lock_| since 1640 // |capturer_->RemoveSink| may not be called while holding |lock_| since
1669 // that might cause a lock order inversion. 1641 // that might cause a lock order inversion.
1670 capturer_->RemoveSink(this); 1642 capturer_->RemoveSink(this);
1671 capturer_ = NULL; 1643 capturer_ = NULL;
1672 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not 1644 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not
1673 // possible to know if the video resolution is restricted by CPU usage after 1645 // possible to know if the video resolution is restricted by CPU usage after
1674 // the capturer is changed since the next capturer might be screen capture 1646 // the capturer is changed since the next capturer might be screen capture
1675 // with another resolution and frame rate. 1647 // with another resolution and frame rate.
1676 cpu_restricted_counter_ = 0; 1648 cpu_restricted_counter_ = 0;
1677 return true; 1649 return true;
1678 } 1650 }
1679 1651
1680 const std::vector<uint32_t>& 1652 const std::vector<uint32_t>&
1681 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { 1653 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const {
1682 return ssrcs_; 1654 return ssrcs_;
1683 } 1655 }
1684 1656
1685 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions(
1686 const VideoOptions& options) {
1687 rtc::CritScope cs(&lock_);
1688
1689 parameters_.options.SetAll(options);
1690 // Reconfigure encoder settings on the next frame or stream
1691 // recreation.
1692 pending_encoder_reconfiguration_ = true;
1693 }
1694
1695 webrtc::VideoCodecType CodecTypeFromName(const std::string& name) { 1657 webrtc::VideoCodecType CodecTypeFromName(const std::string& name) {
1696 if (CodecNamesEq(name, kVp8CodecName)) { 1658 if (CodecNamesEq(name, kVp8CodecName)) {
1697 return webrtc::kVideoCodecVP8; 1659 return webrtc::kVideoCodecVP8;
1698 } else if (CodecNamesEq(name, kVp9CodecName)) { 1660 } else if (CodecNamesEq(name, kVp9CodecName)) {
1699 return webrtc::kVideoCodecVP9; 1661 return webrtc::kVideoCodecVP9;
1700 } else if (CodecNamesEq(name, kH264CodecName)) { 1662 } else if (CodecNamesEq(name, kH264CodecName)) {
1701 return webrtc::kVideoCodecH264; 1663 return webrtc::kVideoCodecH264;
1702 } 1664 }
1703 return webrtc::kVideoCodecUnknown; 1665 return webrtc::kVideoCodecUnknown;
1704 } 1666 }
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 rtx_mapping[video_codecs[i].codec.id] != 2548 rtx_mapping[video_codecs[i].codec.id] !=
2587 fec_settings.red_payload_type) { 2549 fec_settings.red_payload_type) {
2588 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2550 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2589 } 2551 }
2590 } 2552 }
2591 2553
2592 return video_codecs; 2554 return video_codecs;
2593 } 2555 }
2594 2556
2595 } // namespace cricket 2557 } // 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