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