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 <algorithm> | 13 #include <algorithm> |
14 #include <set> | 14 #include <set> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "webrtc/base/buffer.h" | 17 #include "webrtc/base/buffer.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/stringutils.h" | 19 #include "webrtc/base/stringutils.h" |
20 #include "webrtc/base/timeutils.h" | 20 #include "webrtc/base/timeutils.h" |
21 #include "webrtc/base/trace_event.h" | 21 #include "webrtc/base/trace_event.h" |
22 #include "webrtc/call.h" | 22 #include "webrtc/call.h" |
23 #include "webrtc/media/base/videocapturer.h" | |
24 #include "webrtc/media/base/videorenderer.h" | |
25 #include "webrtc/media/engine/constants.h" | 23 #include "webrtc/media/engine/constants.h" |
26 #include "webrtc/media/engine/simulcast.h" | 24 #include "webrtc/media/engine/simulcast.h" |
27 #include "webrtc/media/engine/webrtcmediaengine.h" | 25 #include "webrtc/media/engine/webrtcmediaengine.h" |
28 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" | 26 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" |
29 #include "webrtc/media/engine/webrtcvideoframe.h" | 27 #include "webrtc/media/engine/webrtcvideoframe.h" |
30 #include "webrtc/media/engine/webrtcvoiceengine.h" | 28 #include "webrtc/media/engine/webrtcvoiceengine.h" |
31 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | 29 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
32 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" | 30 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" |
33 #include "webrtc/system_wrappers/include/field_trial.h" | 31 #include "webrtc/system_wrappers/include/field_trial.h" |
34 #include "webrtc/video_decoder.h" | 32 #include "webrtc/video_decoder.h" |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 } | 948 } |
951 if (send) { | 949 if (send) { |
952 StartAllSendStreams(); | 950 StartAllSendStreams(); |
953 } else { | 951 } else { |
954 StopAllSendStreams(); | 952 StopAllSendStreams(); |
955 } | 953 } |
956 sending_ = send; | 954 sending_ = send; |
957 return true; | 955 return true; |
958 } | 956 } |
959 | 957 |
| 958 // TODO(nisse): Delete enable argument, was used for mute logic which |
| 959 // has been moved elsewhere. |
960 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, | 960 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, |
961 const VideoOptions* options) { | 961 const VideoOptions* options) { |
962 TRACE_EVENT0("webrtc", "SetVideoSend"); | 962 TRACE_EVENT0("webrtc", "SetVideoSend"); |
963 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable | 963 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable |
964 << "options: " << (options ? options->ToString() : "nullptr") | 964 << "options: " << (options ? options->ToString() : "nullptr") |
965 << ")."; | 965 << ")."; |
966 | 966 |
967 // TODO(solenberg): The state change should be fully rolled back if any one of | |
968 // these calls fail. | |
969 if (!MuteStream(ssrc, !enable)) { | |
970 return false; | |
971 } | |
972 if (enable && options) { | 967 if (enable && options) { |
973 SetOptions(ssrc, *options); | 968 SetOptions(ssrc, *options); |
974 } | 969 } |
975 return true; | 970 return true; |
976 } | 971 } |
977 | 972 |
978 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( | 973 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( |
979 const StreamParams& sp) const { | 974 const StreamParams& sp) const { |
980 for (uint32_t ssrc : sp.ssrcs) { | 975 for (uint32_t ssrc : sp.ssrcs) { |
981 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { | 976 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 // Get send stream bitrate stats. | 1269 // Get send stream bitrate stats. |
1275 rtc::CritScope stream_lock(&stream_crit_); | 1270 rtc::CritScope stream_lock(&stream_crit_); |
1276 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator stream = | 1271 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator stream = |
1277 send_streams_.begin(); | 1272 send_streams_.begin(); |
1278 stream != send_streams_.end(); ++stream) { | 1273 stream != send_streams_.end(); ++stream) { |
1279 stream->second->FillBandwidthEstimationInfo(&bwe_info); | 1274 stream->second->FillBandwidthEstimationInfo(&bwe_info); |
1280 } | 1275 } |
1281 video_media_info->bw_estimations.push_back(bwe_info); | 1276 video_media_info->bw_estimations.push_back(bwe_info); |
1282 } | 1277 } |
1283 | 1278 |
1284 bool WebRtcVideoChannel2::SetCapturer(uint32_t ssrc, VideoCapturer* capturer) { | 1279 void WebRtcVideoChannel2::SetSource( |
1285 LOG(LS_INFO) << "SetCapturer: " << ssrc << " -> " | 1280 uint32_t ssrc, |
1286 << (capturer != NULL ? "(capturer)" : "NULL"); | 1281 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { |
1287 RTC_DCHECK(ssrc != 0); | 1282 LOG(LS_INFO) << "SetSource: " << ssrc << " -> " |
1288 { | 1283 << (source ? "(source)" : "NULL"); |
1289 rtc::CritScope stream_lock(&stream_crit_); | 1284 RTC_CHECK(ssrc != 0); |
1290 const auto& kv = send_streams_.find(ssrc); | 1285 |
1291 if (kv == send_streams_.end()) { | 1286 rtc::CritScope stream_lock(&stream_crit_); |
1292 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | 1287 const auto& kv = send_streams_.find(ssrc); |
1293 return false; | 1288 if (kv == send_streams_.end()) { |
1294 } | 1289 // Allow unknown ssrc only if source is null. |
1295 if (!kv->second->SetCapturer(capturer)) { | 1290 RTC_CHECK(source == nullptr); |
1296 return false; | |
1297 } | |
1298 } | 1291 } |
1299 return true; | 1292 else { |
| 1293 kv->second->SetSource(source); |
| 1294 } |
1300 } | 1295 } |
1301 | 1296 |
1302 void WebRtcVideoChannel2::OnPacketReceived( | 1297 void WebRtcVideoChannel2::OnPacketReceived( |
1303 rtc::Buffer* packet, | 1298 rtc::Buffer* packet, |
1304 const rtc::PacketTime& packet_time) { | 1299 const rtc::PacketTime& packet_time) { |
1305 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 1300 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
1306 packet_time.not_before); | 1301 packet_time.not_before); |
1307 const webrtc::PacketReceiver::DeliveryStatus delivery_result = | 1302 const webrtc::PacketReceiver::DeliveryStatus delivery_result = |
1308 call_->Receiver()->DeliverPacket( | 1303 call_->Receiver()->DeliverPacket( |
1309 webrtc::MediaType::VIDEO, | 1304 webrtc::MediaType::VIDEO, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 webrtc::MediaType::VIDEO, | 1365 webrtc::MediaType::VIDEO, |
1371 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 1366 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
1372 webrtc_packet_time); | 1367 webrtc_packet_time); |
1373 } | 1368 } |
1374 | 1369 |
1375 void WebRtcVideoChannel2::OnReadyToSend(bool ready) { | 1370 void WebRtcVideoChannel2::OnReadyToSend(bool ready) { |
1376 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); | 1371 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); |
1377 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); | 1372 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); |
1378 } | 1373 } |
1379 | 1374 |
1380 bool WebRtcVideoChannel2::MuteStream(uint32_t ssrc, bool mute) { | |
1381 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> " | |
1382 << (mute ? "mute" : "unmute"); | |
1383 RTC_DCHECK(ssrc != 0); | |
1384 rtc::CritScope stream_lock(&stream_crit_); | |
1385 const auto& kv = send_streams_.find(ssrc); | |
1386 if (kv == send_streams_.end()) { | |
1387 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | |
1388 return false; | |
1389 } | |
1390 | |
1391 kv->second->MuteStream(mute); | |
1392 return true; | |
1393 } | |
1394 | |
1395 // TODO(pbos): Remove SetOptions in favor of SetSendParameters. | 1375 // TODO(pbos): Remove SetOptions in favor of SetSendParameters. |
1396 void WebRtcVideoChannel2::SetOptions(uint32_t ssrc, | 1376 void WebRtcVideoChannel2::SetOptions(uint32_t ssrc, |
1397 const VideoOptions& options) { | 1377 const VideoOptions& options) { |
1398 LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString(); | 1378 LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString(); |
1399 | 1379 |
1400 rtc::CritScope stream_lock(&stream_crit_); | 1380 rtc::CritScope stream_lock(&stream_crit_); |
1401 const auto& kv = send_streams_.find(ssrc); | 1381 const auto& kv = send_streams_.find(ssrc); |
1402 if (kv == send_streams_.end()) { | 1382 if (kv == send_streams_.end()) { |
1403 return; | 1383 return; |
1404 } | 1384 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 1471 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
1492 // TODO(deadbeef): Don't duplicate information between send_params, | 1472 // TODO(deadbeef): Don't duplicate information between send_params, |
1493 // rtp_extensions, options, etc. | 1473 // rtp_extensions, options, etc. |
1494 const VideoSendParameters& send_params) | 1474 const VideoSendParameters& send_params) |
1495 : worker_thread_(rtc::Thread::Current()), | 1475 : worker_thread_(rtc::Thread::Current()), |
1496 ssrcs_(sp.ssrcs), | 1476 ssrcs_(sp.ssrcs), |
1497 ssrc_groups_(sp.ssrc_groups), | 1477 ssrc_groups_(sp.ssrc_groups), |
1498 call_(call), | 1478 call_(call), |
1499 cpu_restricted_counter_(0), | 1479 cpu_restricted_counter_(0), |
1500 number_of_cpu_adapt_changes_(0), | 1480 number_of_cpu_adapt_changes_(0), |
1501 capturer_(nullptr), | 1481 source_(nullptr), |
1502 external_encoder_factory_(external_encoder_factory), | 1482 external_encoder_factory_(external_encoder_factory), |
1503 stream_(nullptr), | 1483 stream_(nullptr), |
1504 parameters_(config, options, max_bitrate_bps, codec_settings), | 1484 parameters_(config, options, max_bitrate_bps, codec_settings), |
1505 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1485 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
1506 pending_encoder_reconfiguration_(false), | 1486 pending_encoder_reconfiguration_(false), |
1507 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 1487 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), |
1508 sending_(false), | 1488 sending_(false), |
1509 muted_(false), | |
1510 first_frame_timestamp_ms_(0), | 1489 first_frame_timestamp_ms_(0), |
1511 last_frame_timestamp_ms_(0) { | 1490 last_frame_timestamp_ms_(0) { |
1512 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1491 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1513 parameters_.conference_mode = send_params.conference_mode; | 1492 parameters_.conference_mode = send_params.conference_mode; |
1514 | 1493 |
1515 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1494 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
1516 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1495 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
1517 ¶meters_.config.rtp.rtx.ssrcs); | 1496 ¶meters_.config.rtp.rtx.ssrcs); |
1518 parameters_.config.rtp.c_name = sp.cname; | 1497 parameters_.config.rtp.c_name = sp.cname; |
1519 parameters_.config.rtp.extensions = rtp_extensions; | 1498 parameters_.config.rtp.extensions = rtp_extensions; |
1520 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 1499 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size |
1521 ? webrtc::RtcpMode::kReducedSize | 1500 ? webrtc::RtcpMode::kReducedSize |
1522 : webrtc::RtcpMode::kCompound; | 1501 : webrtc::RtcpMode::kCompound; |
1523 parameters_.config.overuse_callback = | 1502 parameters_.config.overuse_callback = |
1524 enable_cpu_overuse_detection ? this : nullptr; | 1503 enable_cpu_overuse_detection ? this : nullptr; |
1525 | 1504 |
1526 sink_wants_.rotation_applied = !ContainsHeaderExtension( | 1505 sink_wants_.rotation_applied = !ContainsHeaderExtension( |
1527 rtp_extensions, kRtpVideoRotationHeaderExtension); | 1506 rtp_extensions, kRtpVideoRotationHeaderExtension); |
1528 | 1507 |
1529 if (codec_settings) { | 1508 if (codec_settings) { |
1530 SetCodec(*codec_settings); | 1509 SetCodec(*codec_settings); |
1531 } | 1510 } |
1532 } | 1511 } |
1533 | 1512 |
1534 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 1513 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
1535 DisconnectCapturer(); | 1514 DisconnectSource(); |
1536 if (stream_ != NULL) { | 1515 if (stream_ != NULL) { |
1537 call_->DestroyVideoSendStream(stream_); | 1516 call_->DestroyVideoSendStream(stream_); |
1538 } | 1517 } |
1539 DestroyVideoEncoder(&allocated_encoder_); | 1518 DestroyVideoEncoder(&allocated_encoder_); |
1540 } | 1519 } |
1541 | 1520 |
1542 static void CreateBlackFrame(webrtc::VideoFrame* video_frame, | 1521 static void CreateBlackFrame(webrtc::VideoFrame* video_frame, |
1543 int width, | 1522 int width, |
1544 int height, | 1523 int height, |
1545 webrtc::VideoRotation rotation) { | 1524 webrtc::VideoRotation rotation) { |
(...skipping 12 matching lines...) Expand all Loading... |
1558 const VideoFrame& frame) { | 1537 const VideoFrame& frame) { |
1559 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); | 1538 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); |
1560 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0, | 1539 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0, |
1561 frame.GetVideoRotation()); | 1540 frame.GetVideoRotation()); |
1562 rtc::CritScope cs(&lock_); | 1541 rtc::CritScope cs(&lock_); |
1563 if (stream_ == NULL) { | 1542 if (stream_ == NULL) { |
1564 // Frame input before send codecs are configured, dropping frame. | 1543 // Frame input before send codecs are configured, dropping frame. |
1565 return; | 1544 return; |
1566 } | 1545 } |
1567 | 1546 |
1568 if (muted_) { | |
1569 // Create a black frame to transmit instead. | |
1570 CreateBlackFrame(&video_frame, | |
1571 static_cast<int>(frame.GetWidth()), | |
1572 static_cast<int>(frame.GetHeight()), | |
1573 video_frame.rotation()); | |
1574 } | |
1575 | |
1576 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 1547 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |
1577 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 1548 // frame->GetTimeStamp() is essentially a delta, align to webrtc time |
1578 if (first_frame_timestamp_ms_ == 0) { | 1549 if (first_frame_timestamp_ms_ == 0) { |
1579 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; | 1550 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; |
1580 } | 1551 } |
1581 | 1552 |
1582 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; | 1553 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; |
1583 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1554 video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
1584 // Reconfigure codec if necessary. | 1555 // Reconfigure codec if necessary. |
1585 SetDimensions(video_frame.width(), video_frame.height()); | 1556 SetDimensions(video_frame.width(), video_frame.height()); |
1586 last_rotation_ = video_frame.rotation(); | 1557 last_rotation_ = video_frame.rotation(); |
1587 | 1558 |
1588 // Not sending, abort after reconfiguration. Reconfiguration should still | 1559 // Not sending, abort after reconfiguration. Reconfiguration should still |
1589 // occur to permit sending this input as quickly as possible once we start | 1560 // occur to permit sending this input as quickly as possible once we start |
1590 // sending (without having to reconfigure then). | 1561 // sending (without having to reconfigure then). |
1591 if (!sending_) { | 1562 if (!sending_) { |
1592 return; | 1563 return; |
1593 } | 1564 } |
1594 | 1565 |
1595 stream_->Input()->IncomingCapturedFrame(video_frame); | 1566 stream_->Input()->IncomingCapturedFrame(video_frame); |
1596 } | 1567 } |
1597 | 1568 |
1598 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( | 1569 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSource( |
1599 VideoCapturer* capturer) { | 1570 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { |
1600 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); | 1571 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetSource"); |
1601 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1572 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1602 if (!DisconnectCapturer() && capturer == NULL) { | 1573 |
1603 return false; | 1574 if (!source && !source_) |
1604 } | 1575 return; |
| 1576 DisconnectSource(); |
1605 | 1577 |
1606 { | 1578 { |
1607 rtc::CritScope cs(&lock_); | 1579 rtc::CritScope cs(&lock_); |
1608 | 1580 |
1609 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A | 1581 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A |
1610 // new capturer may have a different timestamp delta than the previous one. | 1582 // new capturer may have a different timestamp delta than the previous one. |
1611 first_frame_timestamp_ms_ = 0; | 1583 first_frame_timestamp_ms_ = 0; |
1612 | 1584 |
1613 if (capturer == NULL) { | 1585 if (source == NULL) { |
1614 if (stream_ != NULL) { | 1586 if (stream_ != NULL) { |
1615 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; | 1587 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; |
1616 webrtc::VideoFrame black_frame; | 1588 webrtc::VideoFrame black_frame; |
1617 | 1589 |
1618 CreateBlackFrame(&black_frame, last_dimensions_.width, | 1590 CreateBlackFrame(&black_frame, last_dimensions_.width, |
1619 last_dimensions_.height, last_rotation_); | 1591 last_dimensions_.height, last_rotation_); |
1620 | 1592 |
1621 // Force this black frame not to be dropped due to timestamp order | 1593 // Force this black frame not to be dropped due to timestamp order |
1622 // check. As IncomingCapturedFrame will drop the frame if this frame's | 1594 // check. As IncomingCapturedFrame will drop the frame if this frame's |
1623 // timestamp is less than or equal to last frame's timestamp, it is | 1595 // timestamp is less than or equal to last frame's timestamp, it is |
1624 // necessary to give this black frame a larger timestamp than the | 1596 // necessary to give this black frame a larger timestamp than the |
1625 // previous one. | 1597 // previous one. |
1626 last_frame_timestamp_ms_ += 1; | 1598 last_frame_timestamp_ms_ += 1; |
1627 black_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1599 black_frame.set_render_time_ms(last_frame_timestamp_ms_); |
1628 stream_->Input()->IncomingCapturedFrame(black_frame); | 1600 stream_->Input()->IncomingCapturedFrame(black_frame); |
1629 } | 1601 } |
1630 | |
1631 capturer_ = NULL; | |
1632 return true; | |
1633 } | 1602 } |
1634 } | 1603 } |
1635 capturer_ = capturer; | 1604 source_ = source; |
1636 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since | 1605 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since |
1637 // that might cause a lock order inversion. | 1606 // that might cause a lock order inversion. |
1638 capturer_->AddOrUpdateSink(this, sink_wants_); | 1607 if (source_) { |
1639 return true; | 1608 source_->AddOrUpdateSink(this, sink_wants_); |
| 1609 } |
1640 } | 1610 } |
1641 | 1611 |
1642 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { | 1612 void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() { |
1643 rtc::CritScope cs(&lock_); | |
1644 muted_ = mute; | |
1645 } | |
1646 | |
1647 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { | |
1648 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1613 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1649 if (capturer_ == NULL) { | 1614 if (source_ == NULL) { |
1650 return false; | 1615 return; |
1651 } | 1616 } |
1652 | 1617 |
1653 // |capturer_->RemoveSink| may not be called while holding |lock_| since | 1618 // |source_->RemoveSink| may not be called while holding |lock_| since |
1654 // that might cause a lock order inversion. | 1619 // that might cause a lock order inversion. |
1655 capturer_->RemoveSink(this); | 1620 source_->RemoveSink(this); |
1656 capturer_ = NULL; | 1621 source_ = NULL; |
1657 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not | 1622 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not |
1658 // possible to know if the video resolution is restricted by CPU usage after | 1623 // possible to know if the video resolution is restricted by CPU usage after |
1659 // the capturer is changed since the next capturer might be screen capture | 1624 // the capturer is changed since the next capturer might be screen capture |
1660 // with another resolution and frame rate. | 1625 // with another resolution and frame rate. |
1661 cpu_restricted_counter_ = 0; | 1626 cpu_restricted_counter_ = 0; |
1662 return true; | |
1663 } | 1627 } |
1664 | 1628 |
1665 const std::vector<uint32_t>& | 1629 const std::vector<uint32_t>& |
1666 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1630 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
1667 return ssrcs_; | 1631 return ssrcs_; |
1668 } | 1632 } |
1669 | 1633 |
1670 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1634 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
1671 const VideoOptions& options) { | 1635 const VideoOptions& options) { |
1672 rtc::CritScope cs(&lock_); | 1636 rtc::CritScope cs(&lock_); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 << "RecreateWebRtcStream (send) because of SetSendParameters"; | 1774 << "RecreateWebRtcStream (send) because of SetSendParameters"; |
1811 RecreateWebRtcStream(); | 1775 RecreateWebRtcStream(); |
1812 } | 1776 } |
1813 } // release |lock_| | 1777 } // release |lock_| |
1814 | 1778 |
1815 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since | 1779 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since |
1816 // that might cause a lock order inversion. | 1780 // that might cause a lock order inversion. |
1817 if (params.rtp_header_extensions) { | 1781 if (params.rtp_header_extensions) { |
1818 sink_wants_.rotation_applied = !ContainsHeaderExtension( | 1782 sink_wants_.rotation_applied = !ContainsHeaderExtension( |
1819 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); | 1783 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); |
1820 if (capturer_) { | 1784 if (source_) { |
1821 capturer_->AddOrUpdateSink(this, sink_wants_); | 1785 source_->AddOrUpdateSink(this, sink_wants_); |
1822 } | 1786 } |
1823 } | 1787 } |
1824 } | 1788 } |
1825 | 1789 |
1826 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpParameters( | 1790 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpParameters( |
1827 const webrtc::RtpParameters& new_parameters) { | 1791 const webrtc::RtpParameters& new_parameters) { |
1828 if (!ValidateRtpParameters(new_parameters)) { | 1792 if (!ValidateRtpParameters(new_parameters)) { |
1829 return false; | 1793 return false; |
1830 } | 1794 } |
1831 | 1795 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1959 | 1923 |
1960 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { | 1924 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { |
1961 if (worker_thread_ != rtc::Thread::Current()) { | 1925 if (worker_thread_ != rtc::Thread::Current()) { |
1962 invoker_.AsyncInvoke<void>( | 1926 invoker_.AsyncInvoke<void>( |
1963 worker_thread_, | 1927 worker_thread_, |
1964 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, | 1928 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, |
1965 this, load)); | 1929 this, load)); |
1966 return; | 1930 return; |
1967 } | 1931 } |
1968 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1932 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1969 if (!capturer_) { | 1933 if (!source_) { |
1970 return; | 1934 return; |
1971 } | 1935 } |
1972 { | 1936 { |
1973 rtc::CritScope cs(&lock_); | 1937 rtc::CritScope cs(&lock_); |
1974 LOG(LS_INFO) << "OnLoadUpdate " << load << ", is_screencast: " | 1938 LOG(LS_INFO) << "OnLoadUpdate " << load << ", is_screencast: " |
1975 << (parameters_.options.is_screencast | 1939 << (parameters_.options.is_screencast |
1976 ? (*parameters_.options.is_screencast ? "true" | 1940 ? (*parameters_.options.is_screencast ? "true" |
1977 : "false") | 1941 : "false") |
1978 : "unset"); | 1942 : "unset"); |
1979 // Do not adapt resolution for screen content as this will likely result in | 1943 // Do not adapt resolution for screen content as this will likely result in |
(...skipping 26 matching lines...) Expand all Loading... |
2006 if (sink_wants_.max_pixel_count || | 1970 if (sink_wants_.max_pixel_count || |
2007 (sink_wants_.max_pixel_count_step_up && | 1971 (sink_wants_.max_pixel_count_step_up && |
2008 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { | 1972 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { |
2009 ++number_of_cpu_adapt_changes_; | 1973 ++number_of_cpu_adapt_changes_; |
2010 --cpu_restricted_counter_; | 1974 --cpu_restricted_counter_; |
2011 } | 1975 } |
2012 } | 1976 } |
2013 sink_wants_.max_pixel_count = max_pixel_count; | 1977 sink_wants_.max_pixel_count = max_pixel_count; |
2014 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up; | 1978 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up; |
2015 } | 1979 } |
2016 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since | 1980 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since |
2017 // that might cause a lock order inversion. | 1981 // that might cause a lock order inversion. |
2018 capturer_->AddOrUpdateSink(this, sink_wants_); | 1982 source_->AddOrUpdateSink(this, sink_wants_); |
2019 } | 1983 } |
2020 | 1984 |
2021 VideoSenderInfo | 1985 VideoSenderInfo |
2022 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { | 1986 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { |
2023 VideoSenderInfo info; | 1987 VideoSenderInfo info; |
2024 webrtc::VideoSendStream::Stats stats; | 1988 webrtc::VideoSendStream::Stats stats; |
2025 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1989 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2026 { | 1990 { |
2027 rtc::CritScope cs(&lock_); | 1991 rtc::CritScope cs(&lock_); |
2028 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) | 1992 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) |
(...skipping 14 matching lines...) Expand all Loading... |
2043 if (stream_ == NULL) | 2007 if (stream_ == NULL) |
2044 return info; | 2008 return info; |
2045 | 2009 |
2046 stats = stream_->GetStats(); | 2010 stats = stream_->GetStats(); |
2047 } | 2011 } |
2048 info.adapt_changes = number_of_cpu_adapt_changes_; | 2012 info.adapt_changes = number_of_cpu_adapt_changes_; |
2049 info.adapt_reason = cpu_restricted_counter_ <= 0 | 2013 info.adapt_reason = cpu_restricted_counter_ <= 0 |
2050 ? CoordinatedVideoAdapter::ADAPTREASON_NONE | 2014 ? CoordinatedVideoAdapter::ADAPTREASON_NONE |
2051 : CoordinatedVideoAdapter::ADAPTREASON_CPU; | 2015 : CoordinatedVideoAdapter::ADAPTREASON_CPU; |
2052 | 2016 |
2053 if (capturer_) { | 2017 if (source_) { |
2054 VideoFormat last_captured_frame_format; | 2018 rtc::VideoSourceInfo source_info; |
2055 capturer_->GetStats(&last_captured_frame_format); | 2019 source_->GetInfo(&source_info); |
2056 info.input_frame_width = last_captured_frame_format.width; | 2020 info.input_frame_width = source_info.orig_width; |
2057 info.input_frame_height = last_captured_frame_format.height; | 2021 info.input_frame_height = source_info.orig_height; |
2058 } | 2022 } |
2059 | 2023 |
2060 // Get bandwidth limitation info from stream_->GetStats(). | 2024 // Get bandwidth limitation info from stream_->GetStats(). |
2061 // Input resolution (output from video_adapter) can be further scaled down or | 2025 // Input resolution (output from video_adapter) can be further scaled down or |
2062 // higher video layer(s) can be dropped due to bitrate constraints. | 2026 // higher video layer(s) can be dropped due to bitrate constraints. |
2063 // Note, adapt_changes only include changes from the video_adapter. | 2027 // Note, adapt_changes only include changes from the video_adapter. |
2064 if (stats.bw_limited_resolution) | 2028 if (stats.bw_limited_resolution) |
2065 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; | 2029 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; |
2066 | 2030 |
2067 info.encoder_implementation_name = stats.encoder_implementation_name; | 2031 info.encoder_implementation_name = stats.encoder_implementation_name; |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2567 rtx_mapping[video_codecs[i].codec.id] != | 2531 rtx_mapping[video_codecs[i].codec.id] != |
2568 fec_settings.red_payload_type) { | 2532 fec_settings.red_payload_type) { |
2569 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2533 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2570 } | 2534 } |
2571 } | 2535 } |
2572 | 2536 |
2573 return video_codecs; | 2537 return video_codecs; |
2574 } | 2538 } |
2575 | 2539 |
2576 } // namespace cricket | 2540 } // namespace cricket |
OLD | NEW |