| 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 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 ssrcs_(sp.ssrcs), | 1573 ssrcs_(sp.ssrcs), |
| 1574 ssrc_groups_(sp.ssrc_groups), | 1574 ssrc_groups_(sp.ssrc_groups), |
| 1575 call_(call), | 1575 call_(call), |
| 1576 cpu_restricted_counter_(0), | 1576 cpu_restricted_counter_(0), |
| 1577 number_of_cpu_adapt_changes_(0), | 1577 number_of_cpu_adapt_changes_(0), |
| 1578 frame_count_(0), | 1578 frame_count_(0), |
| 1579 cpu_restricted_frame_count_(0), | 1579 cpu_restricted_frame_count_(0), |
| 1580 source_(nullptr), | 1580 source_(nullptr), |
| 1581 external_encoder_factory_(external_encoder_factory), | 1581 external_encoder_factory_(external_encoder_factory), |
| 1582 stream_(nullptr), | 1582 stream_(nullptr), |
| 1583 encoder_sink_(nullptr), |
| 1583 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), | 1584 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), |
| 1584 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1585 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
| 1585 pending_encoder_reconfiguration_(false), | 1586 pending_encoder_reconfiguration_(false), |
| 1586 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 1587 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), |
| 1587 sending_(false), | 1588 sending_(false), |
| 1588 last_frame_timestamp_us_(0) { | 1589 last_frame_timestamp_us_(0) { |
| 1589 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1590 parameters_.config.rtp.max_packet_size = kVideoMtu; |
| 1590 parameters_.conference_mode = send_params.conference_mode; | 1591 parameters_.conference_mode = send_params.conference_mode; |
| 1591 | 1592 |
| 1592 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1593 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1651 last_frame_info_.rotation = video_frame.rotation(); | 1652 last_frame_info_.rotation = video_frame.rotation(); |
| 1652 last_frame_info_.is_texture = video_frame.is_texture(); | 1653 last_frame_info_.is_texture = video_frame.is_texture(); |
| 1653 pending_encoder_reconfiguration_ = true; | 1654 pending_encoder_reconfiguration_ = true; |
| 1654 | 1655 |
| 1655 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" | 1656 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" |
| 1656 << last_frame_info_.width << "x" << last_frame_info_.height | 1657 << last_frame_info_.width << "x" << last_frame_info_.height |
| 1657 << ", rotation=" << last_frame_info_.rotation | 1658 << ", rotation=" << last_frame_info_.rotation |
| 1658 << ", texture=" << last_frame_info_.is_texture; | 1659 << ", texture=" << last_frame_info_.is_texture; |
| 1659 } | 1660 } |
| 1660 | 1661 |
| 1661 if (stream_ == NULL) { | 1662 if (encoder_sink_ == NULL) { |
| 1662 // Frame input before send codecs are configured, dropping frame. | 1663 // Frame input before send codecs are configured, dropping frame. |
| 1663 return; | 1664 return; |
| 1664 } | 1665 } |
| 1665 | 1666 |
| 1666 last_frame_timestamp_us_ = video_frame.timestamp_us(); | 1667 last_frame_timestamp_us_ = video_frame.timestamp_us(); |
| 1667 | 1668 |
| 1668 if (pending_encoder_reconfiguration_) { | 1669 if (pending_encoder_reconfiguration_) { |
| 1669 ReconfigureEncoder(); | 1670 ReconfigureEncoder(); |
| 1670 pending_encoder_reconfiguration_ = false; | 1671 pending_encoder_reconfiguration_ = false; |
| 1671 } | 1672 } |
| 1672 | 1673 |
| 1673 // Not sending, abort after reconfiguration. Reconfiguration should still | 1674 // Not sending, abort after reconfiguration. Reconfiguration should still |
| 1674 // occur to permit sending this input as quickly as possible once we start | 1675 // occur to permit sending this input as quickly as possible once we start |
| 1675 // sending (without having to reconfigure then). | 1676 // sending (without having to reconfigure then). |
| 1676 if (!sending_) { | 1677 if (!sending_) { |
| 1677 return; | 1678 return; |
| 1678 } | 1679 } |
| 1679 | 1680 |
| 1680 ++frame_count_; | 1681 ++frame_count_; |
| 1681 if (cpu_restricted_counter_ > 0) | 1682 if (cpu_restricted_counter_ > 0) |
| 1682 ++cpu_restricted_frame_count_; | 1683 ++cpu_restricted_frame_count_; |
| 1683 | 1684 |
| 1684 stream_->Input()->IncomingCapturedFrame(video_frame); | 1685 encoder_sink_->OnFrame(video_frame); |
| 1685 } | 1686 } |
| 1686 | 1687 |
| 1687 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend( | 1688 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend( |
| 1688 bool enable, | 1689 bool enable, |
| 1689 const VideoOptions* options, | 1690 const VideoOptions* options, |
| 1690 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { | 1691 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { |
| 1691 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend"); | 1692 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend"); |
| 1692 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1693 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 1693 | 1694 |
| 1694 // Ignore |options| pointer if |enable| is false. | 1695 // Ignore |options| pointer if |enable| is false. |
| 1695 bool options_present = enable && options; | 1696 bool options_present = enable && options; |
| 1696 bool source_changing = source_ != source; | 1697 bool source_changing = source_ != source; |
| 1697 if (source_changing) { | 1698 if (source_changing) { |
| 1698 DisconnectSource(); | 1699 DisconnectSource(); |
| 1699 } | 1700 } |
| 1700 | 1701 |
| 1701 if (options_present || source_changing) { | 1702 if (options_present || source_changing) { |
| 1702 rtc::CritScope cs(&lock_); | 1703 rtc::CritScope cs(&lock_); |
| 1703 | 1704 |
| 1704 if (options_present) { | 1705 if (options_present) { |
| 1705 VideoOptions old_options = parameters_.options; | 1706 VideoOptions old_options = parameters_.options; |
| 1706 parameters_.options.SetAll(*options); | 1707 parameters_.options.SetAll(*options); |
| 1707 // Reconfigure encoder settings on the naext frame or stream | 1708 // Reconfigure encoder settings on the next frame or stream |
| 1708 // recreation if the options changed. | 1709 // recreation if the options changed. |
| 1709 if (parameters_.options != old_options) { | 1710 if (parameters_.options != old_options) { |
| 1710 pending_encoder_reconfiguration_ = true; | 1711 pending_encoder_reconfiguration_ = true; |
| 1711 } | 1712 } |
| 1712 } | 1713 } |
| 1713 | 1714 |
| 1714 if (source_changing) { | 1715 if (source_changing) { |
| 1715 if (source == nullptr && stream_ != nullptr) { | 1716 if (source == nullptr && encoder_sink_ != nullptr) { |
| 1716 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; | 1717 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; |
| 1717 // Force this black frame not to be dropped due to timestamp order | 1718 // Force this black frame not to be dropped due to timestamp order |
| 1718 // check. As IncomingCapturedFrame will drop the frame if this frame's | 1719 // check. As IncomingCapturedFrame will drop the frame if this frame's |
| 1719 // timestamp is less than or equal to last frame's timestamp, it is | 1720 // timestamp is less than or equal to last frame's timestamp, it is |
| 1720 // necessary to give this black frame a larger timestamp than the | 1721 // necessary to give this black frame a larger timestamp than the |
| 1721 // previous one. | 1722 // previous one. |
| 1722 last_frame_timestamp_us_ += rtc::kNumMicrosecsPerMillisec; | 1723 last_frame_timestamp_us_ += rtc::kNumMicrosecsPerMillisec; |
| 1723 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer( | 1724 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer( |
| 1724 webrtc::I420Buffer::Create(last_frame_info_.width, | 1725 webrtc::I420Buffer::Create(last_frame_info_.width, |
| 1725 last_frame_info_.height)); | 1726 last_frame_info_.height)); |
| 1726 black_buffer->SetToBlack(); | 1727 black_buffer->SetToBlack(); |
| 1727 | 1728 |
| 1728 stream_->Input()->IncomingCapturedFrame(webrtc::VideoFrame( | 1729 encoder_sink_->OnFrame(webrtc::VideoFrame( |
| 1729 black_buffer, last_frame_info_.rotation, | 1730 black_buffer, last_frame_info_.rotation, last_frame_timestamp_us_)); |
| 1730 last_frame_timestamp_us_)); | |
| 1731 } | 1731 } |
| 1732 source_ = source; | 1732 source_ = source; |
| 1733 } | 1733 } |
| 1734 } | 1734 } |
| 1735 | 1735 |
| 1736 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since | 1736 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since |
| 1737 // that might cause a lock order inversion. | 1737 // that might cause a lock order inversion. |
| 1738 if (source_changing && source_) { | 1738 if (source_changing && source_) { |
| 1739 source_->AddOrUpdateSink(this, sink_wants_); | 1739 source_->AddOrUpdateSink(this, sink_wants_); |
| 1740 } | 1740 } |
| 1741 return true; | 1741 return true; |
| 1742 } | 1742 } |
| 1743 | 1743 |
| 1744 void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() { | 1744 void WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectSource() { |
| 1745 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1745 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 1746 if (source_ == NULL) { | 1746 if (source_ == nullptr) { |
| 1747 return; | 1747 return; |
| 1748 } | 1748 } |
| 1749 | 1749 |
| 1750 // |source_->RemoveSink| may not be called while holding |lock_| since | 1750 // |source_->RemoveSink| may not be called while holding |lock_| since |
| 1751 // that might cause a lock order inversion. | 1751 // that might cause a lock order inversion. |
| 1752 source_->RemoveSink(this); | 1752 source_->RemoveSink(this); |
| 1753 source_ = nullptr; | 1753 source_ = nullptr; |
| 1754 // Reset |cpu_restricted_counter_| if the source is changed. It is not | 1754 // Reset |cpu_restricted_counter_| if the source is changed. It is not |
| 1755 // possible to know if the video resolution is restricted by CPU usage after | 1755 // possible to know if the video resolution is restricted by CPU usage after |
| 1756 // the source is changed since the next source might be screen capture | 1756 // the source is changed since the next source might be screen capture |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 | 2042 |
| 2043 parameters_.encoder_config = std::move(encoder_config); | 2043 parameters_.encoder_config = std::move(encoder_config); |
| 2044 } | 2044 } |
| 2045 | 2045 |
| 2046 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) { | 2046 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) { |
| 2047 rtc::CritScope cs(&lock_); | 2047 rtc::CritScope cs(&lock_); |
| 2048 sending_ = send; | 2048 sending_ = send; |
| 2049 UpdateSendState(); | 2049 UpdateSendState(); |
| 2050 } | 2050 } |
| 2051 | 2051 |
| 2052 void WebRtcVideoChannel2::WebRtcVideoSendStream::AddOrUpdateSink( |
| 2053 VideoSinkInterface<webrtc::VideoFrame>* sink, |
| 2054 const rtc::VideoSinkWants& wants) { |
| 2055 // TODO(perkj): Actually consider the encoder |wants| and remove |
| 2056 // WebRtcVideoSendStream::OnLoadUpdate(Load load). |
| 2057 rtc::CritScope cs(&lock_); |
| 2058 RTC_DCHECK(!encoder_sink_ || encoder_sink_ == sink); |
| 2059 encoder_sink_ = sink; |
| 2060 } |
| 2061 |
| 2062 void WebRtcVideoChannel2::WebRtcVideoSendStream::RemoveSink( |
| 2063 VideoSinkInterface<webrtc::VideoFrame>* sink) { |
| 2064 rtc::CritScope cs(&lock_); |
| 2065 RTC_DCHECK_EQ(encoder_sink_, sink); |
| 2066 encoder_sink_ = nullptr; |
| 2067 } |
| 2068 |
| 2052 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { | 2069 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { |
| 2053 if (worker_thread_ != rtc::Thread::Current()) { | 2070 if (worker_thread_ != rtc::Thread::Current()) { |
| 2054 invoker_.AsyncInvoke<void>( | 2071 invoker_.AsyncInvoke<void>( |
| 2055 RTC_FROM_HERE, worker_thread_, | 2072 RTC_FROM_HERE, worker_thread_, |
| 2056 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, | 2073 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, |
| 2057 this, load)); | 2074 this, load)); |
| 2058 return; | 2075 return; |
| 2059 } | 2076 } |
| 2060 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2077 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2061 if (!source_) { | 2078 if (!source_) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2234 ConfigureVideoEncoderSettings(parameters_.codec_settings->codec); | 2251 ConfigureVideoEncoderSettings(parameters_.codec_settings->codec); |
| 2235 | 2252 |
| 2236 webrtc::VideoSendStream::Config config = parameters_.config.Copy(); | 2253 webrtc::VideoSendStream::Config config = parameters_.config.Copy(); |
| 2237 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { | 2254 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { |
| 2238 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " | 2255 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " |
| 2239 "payload type the set codec. Ignoring RTX."; | 2256 "payload type the set codec. Ignoring RTX."; |
| 2240 config.rtp.rtx.ssrcs.clear(); | 2257 config.rtp.rtx.ssrcs.clear(); |
| 2241 } | 2258 } |
| 2242 stream_ = call_->CreateVideoSendStream(std::move(config), | 2259 stream_ = call_->CreateVideoSendStream(std::move(config), |
| 2243 parameters_.encoder_config.Copy()); | 2260 parameters_.encoder_config.Copy()); |
| 2261 stream_->SetSource(this); |
| 2244 | 2262 |
| 2245 parameters_.encoder_config.encoder_specific_settings = NULL; | 2263 parameters_.encoder_config.encoder_specific_settings = NULL; |
| 2246 pending_encoder_reconfiguration_ = false; | 2264 pending_encoder_reconfiguration_ = false; |
| 2247 | 2265 |
| 2248 // Call stream_->Start() if necessary conditions are met. | 2266 // Call stream_->Start() if necessary conditions are met. |
| 2249 UpdateSendState(); | 2267 UpdateSendState(); |
| 2250 } | 2268 } |
| 2251 | 2269 |
| 2252 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( | 2270 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( |
| 2253 webrtc::Call* call, | 2271 webrtc::Call* call, |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2692 rtx_mapping[video_codecs[i].codec.id] != | 2710 rtx_mapping[video_codecs[i].codec.id] != |
| 2693 fec_settings.red_payload_type) { | 2711 fec_settings.red_payload_type) { |
| 2694 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2712 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2695 } | 2713 } |
| 2696 } | 2714 } |
| 2697 | 2715 |
| 2698 return video_codecs; | 2716 return video_codecs; |
| 2699 } | 2717 } |
| 2700 | 2718 |
| 2701 } // namespace cricket | 2719 } // namespace cricket |
| OLD | NEW |