OLD | NEW |
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/engine/constants.h" | 24 #include "webrtc/media/engine/constants.h" |
26 #include "webrtc/media/engine/simulcast.h" | 25 #include "webrtc/media/engine/simulcast.h" |
27 #include "webrtc/media/engine/webrtcmediaengine.h" | 26 #include "webrtc/media/engine/webrtcmediaengine.h" |
28 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" | 27 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" |
29 #include "webrtc/media/engine/webrtcvideoframe.h" | 28 #include "webrtc/media/engine/webrtcvideoframe.h" |
30 #include "webrtc/media/engine/webrtcvoiceengine.h" | 29 #include "webrtc/media/engine/webrtcvoiceengine.h" |
31 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | 30 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
32 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" | 31 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" |
33 #include "webrtc/system_wrappers/include/field_trial.h" | 32 #include "webrtc/system_wrappers/include/field_trial.h" |
34 #include "webrtc/video_decoder.h" | 33 #include "webrtc/video_decoder.h" |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 { | 990 { |
992 rtc::CritScope stream_lock(&stream_crit_); | 991 rtc::CritScope stream_lock(&stream_crit_); |
993 for (const auto& kv : send_streams_) { | 992 for (const auto& kv : send_streams_) { |
994 kv.second->SetSend(send); | 993 kv.second->SetSend(send); |
995 } | 994 } |
996 } | 995 } |
997 sending_ = send; | 996 sending_ = send; |
998 return true; | 997 return true; |
999 } | 998 } |
1000 | 999 |
| 1000 // TODO(nisse): The enable argument was used for mute logic which has |
| 1001 // been moved to VideoBroadcaster. So delete this method, and use |
| 1002 // SetOptions instead. |
1001 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, | 1003 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, |
1002 const VideoOptions* options) { | 1004 const VideoOptions* options) { |
1003 TRACE_EVENT0("webrtc", "SetVideoSend"); | 1005 TRACE_EVENT0("webrtc", "SetVideoSend"); |
1004 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable | 1006 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable |
1005 << "options: " << (options ? options->ToString() : "nullptr") | 1007 << "options: " << (options ? options->ToString() : "nullptr") |
1006 << ")."; | 1008 << ")."; |
1007 | 1009 |
1008 // TODO(solenberg): The state change should be fully rolled back if any one of | |
1009 // these calls fail. | |
1010 if (!MuteStream(ssrc, !enable)) { | |
1011 return false; | |
1012 } | |
1013 if (enable && options) { | 1010 if (enable && options) { |
1014 SetOptions(ssrc, *options); | 1011 SetOptions(ssrc, *options); |
1015 } | 1012 } |
1016 return true; | 1013 return true; |
1017 } | 1014 } |
1018 | 1015 |
1019 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( | 1016 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( |
1020 const StreamParams& sp) const { | 1017 const StreamParams& sp) const { |
1021 for (uint32_t ssrc : sp.ssrcs) { | 1018 for (uint32_t ssrc : sp.ssrcs) { |
1022 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { | 1019 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 // Get send stream bitrate stats. | 1302 // Get send stream bitrate stats. |
1306 rtc::CritScope stream_lock(&stream_crit_); | 1303 rtc::CritScope stream_lock(&stream_crit_); |
1307 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator stream = | 1304 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator stream = |
1308 send_streams_.begin(); | 1305 send_streams_.begin(); |
1309 stream != send_streams_.end(); ++stream) { | 1306 stream != send_streams_.end(); ++stream) { |
1310 stream->second->FillBandwidthEstimationInfo(&bwe_info); | 1307 stream->second->FillBandwidthEstimationInfo(&bwe_info); |
1311 } | 1308 } |
1312 video_media_info->bw_estimations.push_back(bwe_info); | 1309 video_media_info->bw_estimations.push_back(bwe_info); |
1313 } | 1310 } |
1314 | 1311 |
1315 bool WebRtcVideoChannel2::SetCapturer(uint32_t ssrc, VideoCapturer* capturer) { | 1312 void WebRtcVideoChannel2::SetSource( |
1316 LOG(LS_INFO) << "SetCapturer: " << ssrc << " -> " | 1313 uint32_t ssrc, |
1317 << (capturer != NULL ? "(capturer)" : "NULL"); | 1314 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { |
| 1315 LOG(LS_INFO) << "SetSource: " << ssrc << " -> " |
| 1316 << (source ? "(source)" : "NULL"); |
1318 RTC_DCHECK(ssrc != 0); | 1317 RTC_DCHECK(ssrc != 0); |
1319 { | 1318 |
1320 rtc::CritScope stream_lock(&stream_crit_); | 1319 rtc::CritScope stream_lock(&stream_crit_); |
1321 const auto& kv = send_streams_.find(ssrc); | 1320 const auto& kv = send_streams_.find(ssrc); |
1322 if (kv == send_streams_.end()) { | 1321 if (kv == send_streams_.end()) { |
1323 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | 1322 // Allow unknown ssrc only if source is null. |
1324 return false; | 1323 RTC_CHECK(source == nullptr); |
1325 } | 1324 } else { |
1326 if (!kv->second->SetCapturer(capturer)) { | 1325 kv->second->SetSource(source); |
1327 return false; | |
1328 } | |
1329 } | 1326 } |
1330 return true; | |
1331 } | 1327 } |
1332 | 1328 |
1333 void WebRtcVideoChannel2::OnPacketReceived( | 1329 void WebRtcVideoChannel2::OnPacketReceived( |
1334 rtc::CopyOnWriteBuffer* packet, | 1330 rtc::CopyOnWriteBuffer* packet, |
1335 const rtc::PacketTime& packet_time) { | 1331 const rtc::PacketTime& packet_time) { |
1336 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 1332 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
1337 packet_time.not_before); | 1333 packet_time.not_before); |
1338 const webrtc::PacketReceiver::DeliveryStatus delivery_result = | 1334 const webrtc::PacketReceiver::DeliveryStatus delivery_result = |
1339 call_->Receiver()->DeliverPacket( | 1335 call_->Receiver()->DeliverPacket( |
1340 webrtc::MediaType::VIDEO, | 1336 webrtc::MediaType::VIDEO, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); | 1406 ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); |
1411 } | 1407 } |
1412 | 1408 |
1413 void WebRtcVideoChannel2::OnNetworkRouteChanged( | 1409 void WebRtcVideoChannel2::OnNetworkRouteChanged( |
1414 const std::string& transport_name, | 1410 const std::string& transport_name, |
1415 const NetworkRoute& network_route) { | 1411 const NetworkRoute& network_route) { |
1416 // TODO(honghaiz): uncomment this once the function in call is implemented. | 1412 // TODO(honghaiz): uncomment this once the function in call is implemented. |
1417 // call_->OnNetworkRouteChanged(transport_name, network_route); | 1413 // call_->OnNetworkRouteChanged(transport_name, network_route); |
1418 } | 1414 } |
1419 | 1415 |
1420 bool WebRtcVideoChannel2::MuteStream(uint32_t ssrc, bool mute) { | |
1421 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> " | |
1422 << (mute ? "mute" : "unmute"); | |
1423 RTC_DCHECK(ssrc != 0); | |
1424 rtc::CritScope stream_lock(&stream_crit_); | |
1425 const auto& kv = send_streams_.find(ssrc); | |
1426 if (kv == send_streams_.end()) { | |
1427 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | |
1428 return false; | |
1429 } | |
1430 | |
1431 kv->second->MuteStream(mute); | |
1432 return true; | |
1433 } | |
1434 | |
1435 // TODO(pbos): Remove SetOptions in favor of SetSendParameters. | 1416 // TODO(pbos): Remove SetOptions in favor of SetSendParameters. |
1436 void WebRtcVideoChannel2::SetOptions(uint32_t ssrc, | 1417 void WebRtcVideoChannel2::SetOptions(uint32_t ssrc, |
1437 const VideoOptions& options) { | 1418 const VideoOptions& options) { |
1438 LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString(); | 1419 LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString(); |
1439 | 1420 |
1440 rtc::CritScope stream_lock(&stream_crit_); | 1421 rtc::CritScope stream_lock(&stream_crit_); |
1441 const auto& kv = send_streams_.find(ssrc); | 1422 const auto& kv = send_streams_.find(ssrc); |
1442 if (kv == send_streams_.end()) { | 1423 if (kv == send_streams_.end()) { |
1443 return; | 1424 return; |
1444 } | 1425 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 1494 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
1514 // TODO(deadbeef): Don't duplicate information between send_params, | 1495 // TODO(deadbeef): Don't duplicate information between send_params, |
1515 // rtp_extensions, options, etc. | 1496 // rtp_extensions, options, etc. |
1516 const VideoSendParameters& send_params) | 1497 const VideoSendParameters& send_params) |
1517 : worker_thread_(rtc::Thread::Current()), | 1498 : worker_thread_(rtc::Thread::Current()), |
1518 ssrcs_(sp.ssrcs), | 1499 ssrcs_(sp.ssrcs), |
1519 ssrc_groups_(sp.ssrc_groups), | 1500 ssrc_groups_(sp.ssrc_groups), |
1520 call_(call), | 1501 call_(call), |
1521 cpu_restricted_counter_(0), | 1502 cpu_restricted_counter_(0), |
1522 number_of_cpu_adapt_changes_(0), | 1503 number_of_cpu_adapt_changes_(0), |
1523 capturer_(nullptr), | 1504 source_(nullptr), |
1524 external_encoder_factory_(external_encoder_factory), | 1505 external_encoder_factory_(external_encoder_factory), |
1525 stream_(nullptr), | 1506 stream_(nullptr), |
1526 parameters_(config, options, max_bitrate_bps, codec_settings), | 1507 parameters_(config, options, max_bitrate_bps, codec_settings), |
1527 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1508 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
1528 pending_encoder_reconfiguration_(false), | 1509 pending_encoder_reconfiguration_(false), |
1529 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 1510 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), |
1530 sending_(false), | 1511 sending_(false), |
1531 muted_(false), | |
1532 first_frame_timestamp_ms_(0), | 1512 first_frame_timestamp_ms_(0), |
1533 last_frame_timestamp_ms_(0) { | 1513 last_frame_timestamp_ms_(0) { |
1534 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1514 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1535 parameters_.conference_mode = send_params.conference_mode; | 1515 parameters_.conference_mode = send_params.conference_mode; |
1536 | 1516 |
1537 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1517 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
1538 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1518 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
1539 ¶meters_.config.rtp.rtx.ssrcs); | 1519 ¶meters_.config.rtp.rtx.ssrcs); |
1540 parameters_.config.rtp.c_name = sp.cname; | 1520 parameters_.config.rtp.c_name = sp.cname; |
1541 parameters_.config.rtp.extensions = rtp_extensions; | 1521 parameters_.config.rtp.extensions = rtp_extensions; |
1542 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 1522 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size |
1543 ? webrtc::RtcpMode::kReducedSize | 1523 ? webrtc::RtcpMode::kReducedSize |
1544 : webrtc::RtcpMode::kCompound; | 1524 : webrtc::RtcpMode::kCompound; |
1545 parameters_.config.overuse_callback = | 1525 parameters_.config.overuse_callback = |
1546 enable_cpu_overuse_detection ? this : nullptr; | 1526 enable_cpu_overuse_detection ? this : nullptr; |
1547 | 1527 |
1548 sink_wants_.rotation_applied = !ContainsHeaderExtension( | 1528 sink_wants_.rotation_applied = !ContainsHeaderExtension( |
1549 rtp_extensions, kRtpVideoRotationHeaderExtension); | 1529 rtp_extensions, kRtpVideoRotationHeaderExtension); |
1550 | 1530 |
1551 if (codec_settings) { | 1531 if (codec_settings) { |
1552 SetCodec(*codec_settings); | 1532 SetCodec(*codec_settings); |
1553 } | 1533 } |
1554 } | 1534 } |
1555 | 1535 |
1556 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 1536 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
1557 DisconnectCapturer(); | 1537 DisconnectSource(); |
1558 if (stream_ != NULL) { | 1538 if (stream_ != NULL) { |
1559 call_->DestroyVideoSendStream(stream_); | 1539 call_->DestroyVideoSendStream(stream_); |
1560 } | 1540 } |
1561 DestroyVideoEncoder(&allocated_encoder_); | 1541 DestroyVideoEncoder(&allocated_encoder_); |
1562 } | 1542 } |
1563 | 1543 |
1564 static void CreateBlackFrame(webrtc::VideoFrame* video_frame, | 1544 static void CreateBlackFrame(webrtc::VideoFrame* video_frame, |
1565 int width, | 1545 int width, |
1566 int height, | 1546 int height, |
1567 webrtc::VideoRotation rotation) { | 1547 webrtc::VideoRotation rotation) { |
(...skipping 12 matching lines...) Expand all Loading... |
1580 const VideoFrame& frame) { | 1560 const VideoFrame& frame) { |
1581 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); | 1561 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); |
1582 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0, | 1562 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0, |
1583 frame.GetVideoRotation()); | 1563 frame.GetVideoRotation()); |
1584 rtc::CritScope cs(&lock_); | 1564 rtc::CritScope cs(&lock_); |
1585 if (stream_ == NULL) { | 1565 if (stream_ == NULL) { |
1586 // Frame input before send codecs are configured, dropping frame. | 1566 // Frame input before send codecs are configured, dropping frame. |
1587 return; | 1567 return; |
1588 } | 1568 } |
1589 | 1569 |
1590 if (muted_) { | |
1591 // Create a black frame to transmit instead. | |
1592 CreateBlackFrame(&video_frame, | |
1593 frame.width(), | |
1594 frame.height(), | |
1595 video_frame.rotation()); | |
1596 } | |
1597 | |
1598 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 1570 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |
1599 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 1571 // frame->GetTimeStamp() is essentially a delta, align to webrtc time |
1600 if (first_frame_timestamp_ms_ == 0) { | 1572 if (first_frame_timestamp_ms_ == 0) { |
1601 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; | 1573 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; |
1602 } | 1574 } |
1603 | 1575 |
1604 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; | 1576 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; |
1605 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1577 video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
1606 // Reconfigure codec if necessary. | 1578 // Reconfigure codec if necessary. |
1607 SetDimensions(video_frame.width(), video_frame.height()); | 1579 SetDimensions(video_frame.width(), video_frame.height()); |
1608 last_rotation_ = video_frame.rotation(); | 1580 last_rotation_ = video_frame.rotation(); |
1609 | 1581 |
1610 // Not sending, abort after reconfiguration. Reconfiguration should still | 1582 // Not sending, abort after reconfiguration. Reconfiguration should still |
1611 // occur to permit sending this input as quickly as possible once we start | 1583 // occur to permit sending this input as quickly as possible once we start |
1612 // sending (without having to reconfigure then). | 1584 // sending (without having to reconfigure then). |
1613 if (!sending_) { | 1585 if (!sending_) { |
1614 return; | 1586 return; |
1615 } | 1587 } |
1616 | 1588 |
1617 stream_->Input()->IncomingCapturedFrame(video_frame); | 1589 stream_->Input()->IncomingCapturedFrame(video_frame); |
1618 } | 1590 } |
1619 | 1591 |
1620 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( | 1592 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSource( |
1621 VideoCapturer* capturer) { | 1593 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { |
1622 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); | 1594 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetSource"); |
1623 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1595 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1624 if (!DisconnectCapturer() && capturer == NULL) { | 1596 |
1625 return false; | 1597 if (!source && !source_) |
1626 } | 1598 return; |
| 1599 DisconnectSource(); |
1627 | 1600 |
1628 { | 1601 { |
1629 rtc::CritScope cs(&lock_); | 1602 rtc::CritScope cs(&lock_); |
1630 | 1603 |
1631 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A | 1604 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A |
1632 // new capturer may have a different timestamp delta than the previous one. | 1605 // new capturer may have a different timestamp delta than the previous one. |
1633 first_frame_timestamp_ms_ = 0; | 1606 first_frame_timestamp_ms_ = 0; |
1634 | 1607 |
1635 if (capturer == NULL) { | 1608 if (source == NULL) { |
1636 if (stream_ != NULL) { | 1609 if (stream_ != NULL) { |
1637 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; | 1610 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; |
1638 webrtc::VideoFrame black_frame; | 1611 webrtc::VideoFrame black_frame; |
1639 | 1612 |
1640 CreateBlackFrame(&black_frame, last_dimensions_.width, | 1613 CreateBlackFrame(&black_frame, last_dimensions_.width, |
1641 last_dimensions_.height, last_rotation_); | 1614 last_dimensions_.height, last_rotation_); |
1642 | 1615 |
1643 // Force this black frame not to be dropped due to timestamp order | 1616 // Force this black frame not to be dropped due to timestamp order |
1644 // check. As IncomingCapturedFrame will drop the frame if this frame's | 1617 // check. As IncomingCapturedFrame will drop the frame if this frame's |
1645 // timestamp is less than or equal to last frame's timestamp, it is | 1618 // timestamp is less than or equal to last frame's timestamp, it is |
1646 // necessary to give this black frame a larger timestamp than the | 1619 // necessary to give this black frame a larger timestamp than the |
1647 // previous one. | 1620 // previous one. |
1648 last_frame_timestamp_ms_ += 1; | 1621 last_frame_timestamp_ms_ += 1; |
1649 black_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1622 black_frame.set_render_time_ms(last_frame_timestamp_ms_); |
1650 stream_->Input()->IncomingCapturedFrame(black_frame); | 1623 stream_->Input()->IncomingCapturedFrame(black_frame); |
1651 } | 1624 } |
1652 | |
1653 capturer_ = NULL; | |
1654 return true; | |
1655 } | 1625 } |
1656 } | 1626 } |
1657 capturer_ = capturer; | 1627 source_ = source; |
1658 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since | 1628 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since |
1659 // that might cause a lock order inversion. | 1629 // that might cause a lock order inversion. |
1660 capturer_->AddOrUpdateSink(this, sink_wants_); | 1630 if (source_) { |
1661 return true; | 1631 source_->AddOrUpdateSink(this, sink_wants_); |
| 1632 } |
1662 } | 1633 } |
1663 | 1634 |
1664 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { | 1635 void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() { |
1665 rtc::CritScope cs(&lock_); | |
1666 muted_ = mute; | |
1667 } | |
1668 | |
1669 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { | |
1670 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1636 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1671 if (capturer_ == NULL) { | 1637 if (source_ == NULL) { |
1672 return false; | 1638 return; |
1673 } | 1639 } |
1674 | 1640 |
1675 // |capturer_->RemoveSink| may not be called while holding |lock_| since | 1641 // |source_->RemoveSink| may not be called while holding |lock_| since |
1676 // that might cause a lock order inversion. | 1642 // that might cause a lock order inversion. |
1677 capturer_->RemoveSink(this); | 1643 source_->RemoveSink(this); |
1678 capturer_ = NULL; | 1644 source_ = nullptr; |
1679 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not | 1645 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not |
1680 // possible to know if the video resolution is restricted by CPU usage after | 1646 // possible to know if the video resolution is restricted by CPU usage after |
1681 // the capturer is changed since the next capturer might be screen capture | 1647 // the capturer is changed since the next capturer might be screen capture |
1682 // with another resolution and frame rate. | 1648 // with another resolution and frame rate. |
1683 cpu_restricted_counter_ = 0; | 1649 cpu_restricted_counter_ = 0; |
1684 return true; | |
1685 } | 1650 } |
1686 | 1651 |
1687 const std::vector<uint32_t>& | 1652 const std::vector<uint32_t>& |
1688 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1653 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
1689 return ssrcs_; | 1654 return ssrcs_; |
1690 } | 1655 } |
1691 | 1656 |
1692 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1657 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
1693 const VideoOptions& options) { | 1658 const VideoOptions& options) { |
1694 rtc::CritScope cs(&lock_); | 1659 rtc::CritScope cs(&lock_); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 << "RecreateWebRtcStream (send) because of SetSendParameters"; | 1800 << "RecreateWebRtcStream (send) because of SetSendParameters"; |
1836 RecreateWebRtcStream(); | 1801 RecreateWebRtcStream(); |
1837 } | 1802 } |
1838 } // release |lock_| | 1803 } // release |lock_| |
1839 | 1804 |
1840 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since | 1805 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since |
1841 // that might cause a lock order inversion. | 1806 // that might cause a lock order inversion. |
1842 if (params.rtp_header_extensions) { | 1807 if (params.rtp_header_extensions) { |
1843 sink_wants_.rotation_applied = !ContainsHeaderExtension( | 1808 sink_wants_.rotation_applied = !ContainsHeaderExtension( |
1844 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); | 1809 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); |
1845 if (capturer_) { | 1810 if (source_) { |
1846 capturer_->AddOrUpdateSink(this, sink_wants_); | 1811 source_->AddOrUpdateSink(this, sink_wants_); |
1847 } | 1812 } |
1848 } | 1813 } |
1849 } | 1814 } |
1850 | 1815 |
1851 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpParameters( | 1816 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpParameters( |
1852 const webrtc::RtpParameters& new_parameters) { | 1817 const webrtc::RtpParameters& new_parameters) { |
1853 if (!ValidateRtpParameters(new_parameters)) { | 1818 if (!ValidateRtpParameters(new_parameters)) { |
1854 return false; | 1819 return false; |
1855 } | 1820 } |
1856 | 1821 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 | 1966 |
2002 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { | 1967 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { |
2003 if (worker_thread_ != rtc::Thread::Current()) { | 1968 if (worker_thread_ != rtc::Thread::Current()) { |
2004 invoker_.AsyncInvoke<void>( | 1969 invoker_.AsyncInvoke<void>( |
2005 worker_thread_, | 1970 worker_thread_, |
2006 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, | 1971 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, |
2007 this, load)); | 1972 this, load)); |
2008 return; | 1973 return; |
2009 } | 1974 } |
2010 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1975 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2011 if (!capturer_) { | 1976 if (!source_) { |
2012 return; | 1977 return; |
2013 } | 1978 } |
2014 { | 1979 { |
2015 rtc::CritScope cs(&lock_); | 1980 rtc::CritScope cs(&lock_); |
2016 LOG(LS_INFO) << "OnLoadUpdate " << load << ", is_screencast: " | 1981 LOG(LS_INFO) << "OnLoadUpdate " << load << ", is_screencast: " |
2017 << (parameters_.options.is_screencast | 1982 << (parameters_.options.is_screencast |
2018 ? (*parameters_.options.is_screencast ? "true" | 1983 ? (*parameters_.options.is_screencast ? "true" |
2019 : "false") | 1984 : "false") |
2020 : "unset"); | 1985 : "unset"); |
2021 // Do not adapt resolution for screen content as this will likely result in | 1986 // Do not adapt resolution for screen content as this will likely result in |
(...skipping 26 matching lines...) Expand all Loading... |
2048 if (sink_wants_.max_pixel_count || | 2013 if (sink_wants_.max_pixel_count || |
2049 (sink_wants_.max_pixel_count_step_up && | 2014 (sink_wants_.max_pixel_count_step_up && |
2050 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { | 2015 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { |
2051 ++number_of_cpu_adapt_changes_; | 2016 ++number_of_cpu_adapt_changes_; |
2052 --cpu_restricted_counter_; | 2017 --cpu_restricted_counter_; |
2053 } | 2018 } |
2054 } | 2019 } |
2055 sink_wants_.max_pixel_count = max_pixel_count; | 2020 sink_wants_.max_pixel_count = max_pixel_count; |
2056 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up; | 2021 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up; |
2057 } | 2022 } |
2058 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since | 2023 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since |
2059 // that might cause a lock order inversion. | 2024 // that might cause a lock order inversion. |
2060 capturer_->AddOrUpdateSink(this, sink_wants_); | 2025 source_->AddOrUpdateSink(this, sink_wants_); |
2061 } | 2026 } |
2062 | 2027 |
2063 VideoSenderInfo | 2028 VideoSenderInfo |
2064 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { | 2029 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { |
2065 VideoSenderInfo info; | 2030 VideoSenderInfo info; |
2066 webrtc::VideoSendStream::Stats stats; | 2031 webrtc::VideoSendStream::Stats stats; |
2067 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2032 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2068 { | 2033 { |
2069 rtc::CritScope cs(&lock_); | 2034 rtc::CritScope cs(&lock_); |
2070 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) | 2035 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2589 rtx_mapping[video_codecs[i].codec.id] != | 2554 rtx_mapping[video_codecs[i].codec.id] != |
2590 fec_settings.red_payload_type) { | 2555 fec_settings.red_payload_type) { |
2591 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2556 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2592 } | 2557 } |
2593 } | 2558 } |
2594 | 2559 |
2595 return video_codecs; | 2560 return video_codecs; |
2596 } | 2561 } |
2597 | 2562 |
2598 } // namespace cricket | 2563 } // namespace cricket |
OLD | NEW |