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 |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 webrtc::RtpParameters WebRtcVideoChannel2::GetRtpParameters( | 870 webrtc::RtpParameters WebRtcVideoChannel2::GetRtpParameters( |
871 uint32_t ssrc) const { | 871 uint32_t ssrc) const { |
872 rtc::CritScope stream_lock(&stream_crit_); | 872 rtc::CritScope stream_lock(&stream_crit_); |
873 auto it = send_streams_.find(ssrc); | 873 auto it = send_streams_.find(ssrc); |
874 if (it == send_streams_.end()) { | 874 if (it == send_streams_.end()) { |
875 LOG(LS_WARNING) << "Attempting to get RTP parameters for stream with ssrc " | 875 LOG(LS_WARNING) << "Attempting to get RTP parameters for stream with ssrc " |
876 << ssrc << " which doesn't exist."; | 876 << ssrc << " which doesn't exist."; |
877 return webrtc::RtpParameters(); | 877 return webrtc::RtpParameters(); |
878 } | 878 } |
879 | 879 |
880 return it->second->rtp_parameters(); | 880 return it->second->GetRtpParameters(); |
881 } | 881 } |
882 | 882 |
883 bool WebRtcVideoChannel2::SetRtpParameters( | 883 bool WebRtcVideoChannel2::SetRtpParameters( |
884 uint32_t ssrc, | 884 uint32_t ssrc, |
885 const webrtc::RtpParameters& parameters) { | 885 const webrtc::RtpParameters& parameters) { |
886 rtc::CritScope stream_lock(&stream_crit_); | 886 rtc::CritScope stream_lock(&stream_crit_); |
887 auto it = send_streams_.find(ssrc); | 887 auto it = send_streams_.find(ssrc); |
888 if (it == send_streams_.end()) { | 888 if (it == send_streams_.end()) { |
889 LOG(LS_ERROR) << "Attempting to set RTP parameters for stream with ssrc " | 889 LOG(LS_ERROR) << "Attempting to set RTP parameters for stream with ssrc " |
890 << ssrc << " which doesn't exist."; | 890 << ssrc << " which doesn't exist."; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 *codec = send_codec_->codec; | 983 *codec = send_codec_->codec; |
984 return true; | 984 return true; |
985 } | 985 } |
986 | 986 |
987 bool WebRtcVideoChannel2::SetSend(bool send) { | 987 bool WebRtcVideoChannel2::SetSend(bool send) { |
988 LOG(LS_VERBOSE) << "SetSend: " << (send ? "true" : "false"); | 988 LOG(LS_VERBOSE) << "SetSend: " << (send ? "true" : "false"); |
989 if (send && !send_codec_) { | 989 if (send && !send_codec_) { |
990 LOG(LS_ERROR) << "SetSend(true) called before setting codec."; | 990 LOG(LS_ERROR) << "SetSend(true) called before setting codec."; |
991 return false; | 991 return false; |
992 } | 992 } |
993 if (send) { | 993 { |
994 StartAllSendStreams(); | 994 rtc::CritScope stream_lock(&stream_crit_); |
995 } else { | 995 for (const auto& kv : send_streams_) { |
996 StopAllSendStreams(); | 996 kv.second->SetSend(send); |
997 } | |
997 } | 998 } |
998 sending_ = send; | 999 sending_ = send; |
999 return true; | 1000 return true; |
1000 } | 1001 } |
1001 | 1002 |
1002 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, | 1003 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, |
1003 const VideoOptions* options) { | 1004 const VideoOptions* options) { |
1004 TRACE_EVENT0("webrtc", "SetVideoSend"); | 1005 TRACE_EVENT0("webrtc", "SetVideoSend"); |
1005 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable | 1006 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable |
1006 << "options: " << (options ? options->ToString() : "nullptr") | 1007 << "options: " << (options ? options->ToString() : "nullptr") |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 rtcp_receiver_report_ssrc_ = ssrc; | 1070 rtcp_receiver_report_ssrc_ = ssrc; |
1070 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " | 1071 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " |
1071 "a send stream."; | 1072 "a send stream."; |
1072 for (auto& kv : receive_streams_) | 1073 for (auto& kv : receive_streams_) |
1073 kv.second->SetLocalSsrc(ssrc); | 1074 kv.second->SetLocalSsrc(ssrc); |
1074 } | 1075 } |
1075 if (default_send_ssrc_ == 0) { | 1076 if (default_send_ssrc_ == 0) { |
1076 default_send_ssrc_ = ssrc; | 1077 default_send_ssrc_ = ssrc; |
1077 } | 1078 } |
1078 if (sending_) { | 1079 if (sending_) { |
1079 stream->Start(); | 1080 stream->SetSend(true); |
1080 } | 1081 } |
1081 | 1082 |
1082 return true; | 1083 return true; |
1083 } | 1084 } |
1084 | 1085 |
1085 bool WebRtcVideoChannel2::RemoveSendStream(uint32_t ssrc) { | 1086 bool WebRtcVideoChannel2::RemoveSendStream(uint32_t ssrc) { |
1086 LOG(LS_INFO) << "RemoveSendStream: " << ssrc; | 1087 LOG(LS_INFO) << "RemoveSendStream: " << ssrc; |
1087 | 1088 |
1088 if (ssrc == 0) { | 1089 if (ssrc == 0) { |
1089 if (default_send_ssrc_ == 0) { | 1090 if (default_send_ssrc_ == 0) { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1475 rtc::PacketOptions rtc_options; | 1476 rtc::PacketOptions rtc_options; |
1476 rtc_options.packet_id = options.packet_id; | 1477 rtc_options.packet_id = options.packet_id; |
1477 return MediaChannel::SendPacket(&packet, rtc_options); | 1478 return MediaChannel::SendPacket(&packet, rtc_options); |
1478 } | 1479 } |
1479 | 1480 |
1480 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { | 1481 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { |
1481 rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen); | 1482 rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen); |
1482 return MediaChannel::SendRtcp(&packet, rtc::PacketOptions()); | 1483 return MediaChannel::SendRtcp(&packet, rtc::PacketOptions()); |
1483 } | 1484 } |
1484 | 1485 |
1485 void WebRtcVideoChannel2::StartAllSendStreams() { | |
1486 rtc::CritScope stream_lock(&stream_crit_); | |
1487 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = | |
1488 send_streams_.begin(); | |
1489 it != send_streams_.end(); ++it) { | |
1490 it->second->Start(); | |
1491 } | |
1492 } | |
1493 | |
1494 void WebRtcVideoChannel2::StopAllSendStreams() { | |
1495 rtc::CritScope stream_lock(&stream_crit_); | |
1496 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = | |
1497 send_streams_.begin(); | |
1498 it != send_streams_.end(); ++it) { | |
1499 it->second->Stop(); | |
1500 } | |
1501 } | |
1502 | |
1503 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: | 1486 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: |
1504 VideoSendStreamParameters( | 1487 VideoSendStreamParameters( |
1505 const webrtc::VideoSendStream::Config& config, | 1488 const webrtc::VideoSendStream::Config& config, |
1506 const VideoOptions& options, | 1489 const VideoOptions& options, |
1507 int max_bitrate_bps, | 1490 int max_bitrate_bps, |
1508 const rtc::Optional<VideoCodecSettings>& codec_settings) | 1491 const rtc::Optional<VideoCodecSettings>& codec_settings) |
1509 : config(config), | 1492 : config(config), |
1510 options(options), | 1493 options(options), |
1511 max_bitrate_bps(max_bitrate_bps), | 1494 max_bitrate_bps(max_bitrate_bps), |
1512 codec_settings(codec_settings) {} | 1495 codec_settings(codec_settings) {} |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1875 if (!ValidateRtpParameters(new_parameters)) { | 1858 if (!ValidateRtpParameters(new_parameters)) { |
1876 return false; | 1859 return false; |
1877 } | 1860 } |
1878 | 1861 |
1879 rtc::CritScope cs(&lock_); | 1862 rtc::CritScope cs(&lock_); |
1880 if (new_parameters.encodings[0].max_bitrate_bps != | 1863 if (new_parameters.encodings[0].max_bitrate_bps != |
1881 rtp_parameters_.encodings[0].max_bitrate_bps) { | 1864 rtp_parameters_.encodings[0].max_bitrate_bps) { |
1882 pending_encoder_reconfiguration_ = true; | 1865 pending_encoder_reconfiguration_ = true; |
1883 } | 1866 } |
1884 rtp_parameters_ = new_parameters; | 1867 rtp_parameters_ = new_parameters; |
1868 // Encoding may have been activated/deactivated. | |
1869 UpdateSendState(); | |
1885 return true; | 1870 return true; |
1886 } | 1871 } |
1887 | 1872 |
1873 webrtc::RtpParameters | |
1874 WebRtcVideoChannel2::WebRtcVideoSendStream::GetRtpParameters() const { | |
1875 rtc::CritScope cs(&lock_); | |
1876 return rtp_parameters_; | |
1877 } | |
1878 | |
1888 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters( | 1879 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters( |
1889 const webrtc::RtpParameters& rtp_parameters) { | 1880 const webrtc::RtpParameters& rtp_parameters) { |
1890 if (rtp_parameters.encodings.size() != 1) { | 1881 if (rtp_parameters.encodings.size() != 1) { |
1891 LOG(LS_ERROR) | 1882 LOG(LS_ERROR) |
1892 << "Attempted to set RtpParameters without exactly one encoding"; | 1883 << "Attempted to set RtpParameters without exactly one encoding"; |
1893 return false; | 1884 return false; |
1894 } | 1885 } |
1895 return true; | 1886 return true; |
1896 } | 1887 } |
1897 | 1888 |
1889 void WebRtcVideoChannel2::WebRtcVideoSendStream::UpdateSendState() { | |
1890 // TODO(deadbeef): Need to handle more than one encoding in the future. | |
1891 if (sending_ && rtp_parameters_.encodings[0].active) { | |
pbos-webrtc
2016/03/22 18:35:45
Can you also DCHECK that !encodings.empty()?
Taylor Brandstetter
2016/03/22 19:05:38
Done.
| |
1892 RTC_DCHECK(stream_ != nullptr); | |
1893 stream_->Start(); | |
1894 } else { | |
1895 if (stream_ != nullptr) { | |
1896 stream_->Stop(); | |
1897 } | |
1898 } | |
1899 } | |
1900 | |
1898 webrtc::VideoEncoderConfig | 1901 webrtc::VideoEncoderConfig |
1899 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( | 1902 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
1900 const Dimensions& dimensions, | 1903 const Dimensions& dimensions, |
1901 const VideoCodec& codec) const { | 1904 const VideoCodec& codec) const { |
1902 webrtc::VideoEncoderConfig encoder_config; | 1905 webrtc::VideoEncoderConfig encoder_config; |
1903 bool is_screencast = parameters_.options.is_screencast.value_or(false); | 1906 bool is_screencast = parameters_.options.is_screencast.value_or(false); |
1904 if (is_screencast) { | 1907 if (is_screencast) { |
1905 encoder_config.min_transmit_bitrate_bps = | 1908 encoder_config.min_transmit_bitrate_bps = |
1906 1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0); | 1909 1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0); |
1907 encoder_config.content_type = | 1910 encoder_config.content_type = |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1987 codec_settings.codec); | 1990 codec_settings.codec); |
1988 | 1991 |
1989 stream_->ReconfigureVideoEncoder(encoder_config); | 1992 stream_->ReconfigureVideoEncoder(encoder_config); |
1990 | 1993 |
1991 encoder_config.encoder_specific_settings = NULL; | 1994 encoder_config.encoder_specific_settings = NULL; |
1992 pending_encoder_reconfiguration_ = false; | 1995 pending_encoder_reconfiguration_ = false; |
1993 | 1996 |
1994 parameters_.encoder_config = encoder_config; | 1997 parameters_.encoder_config = encoder_config; |
1995 } | 1998 } |
1996 | 1999 |
1997 void WebRtcVideoChannel2::WebRtcVideoSendStream::Start() { | 2000 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) { |
1998 rtc::CritScope cs(&lock_); | 2001 rtc::CritScope cs(&lock_); |
1999 RTC_DCHECK(stream_ != NULL); | 2002 RTC_DCHECK(stream_ != nullptr); |
2000 stream_->Start(); | 2003 sending_ = send; |
2001 sending_ = true; | 2004 UpdateSendState(); |
2002 } | |
2003 | |
2004 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { | |
2005 rtc::CritScope cs(&lock_); | |
2006 if (stream_ != NULL) { | |
2007 stream_->Stop(); | |
2008 } | |
2009 sending_ = false; | |
2010 } | 2005 } |
2011 | 2006 |
2012 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { | 2007 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { |
2013 if (worker_thread_ != rtc::Thread::Current()) { | 2008 if (worker_thread_ != rtc::Thread::Current()) { |
2014 invoker_.AsyncInvoke<void>( | 2009 invoker_.AsyncInvoke<void>( |
2015 worker_thread_, | 2010 worker_thread_, |
2016 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, | 2011 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, |
2017 this, load)); | 2012 this, load)); |
2018 return; | 2013 return; |
2019 } | 2014 } |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2613 rtx_mapping[video_codecs[i].codec.id] != | 2608 rtx_mapping[video_codecs[i].codec.id] != |
2614 fec_settings.red_payload_type) { | 2609 fec_settings.red_payload_type) { |
2615 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2610 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2616 } | 2611 } |
2617 } | 2612 } |
2618 | 2613 |
2619 return video_codecs; | 2614 return video_codecs; |
2620 } | 2615 } |
2621 | 2616 |
2622 } // namespace cricket | 2617 } // namespace cricket |
OLD | NEW |