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