Chromium Code Reviews| 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 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1572 const VideoSendParameters& send_params) | 1572 const VideoSendParameters& send_params) |
| 1573 : worker_thread_(rtc::Thread::Current()), | 1573 : worker_thread_(rtc::Thread::Current()), |
| 1574 ssrcs_(sp.ssrcs), | 1574 ssrcs_(sp.ssrcs), |
| 1575 ssrc_groups_(sp.ssrc_groups), | 1575 ssrc_groups_(sp.ssrc_groups), |
| 1576 call_(call), | 1576 call_(call), |
| 1577 cpu_restricted_counter_(0), | 1577 cpu_restricted_counter_(0), |
| 1578 number_of_cpu_adapt_changes_(0), | 1578 number_of_cpu_adapt_changes_(0), |
| 1579 source_(nullptr), | 1579 source_(nullptr), |
| 1580 external_encoder_factory_(external_encoder_factory), | 1580 external_encoder_factory_(external_encoder_factory), |
| 1581 stream_(nullptr), | 1581 stream_(nullptr), |
| 1582 encoder_sink_(nullptr), | |
| 1582 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), | 1583 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), |
| 1583 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1584 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
| 1584 pending_encoder_reconfiguration_(false), | 1585 pending_encoder_reconfiguration_(false), |
| 1585 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 1586 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), |
| 1586 sending_(false), | 1587 sending_(false), |
| 1587 last_frame_timestamp_ms_(0) { | 1588 last_frame_timestamp_ms_(0) { |
| 1588 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1589 parameters_.config.rtp.max_packet_size = kVideoMtu; |
| 1589 parameters_.conference_mode = send_params.conference_mode; | 1590 parameters_.conference_mode = send_params.conference_mode; |
| 1590 | 1591 |
| 1591 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1592 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1639 last_frame_info_.rotation = video_frame.rotation(); | 1640 last_frame_info_.rotation = video_frame.rotation(); |
| 1640 last_frame_info_.is_texture = video_frame.is_texture(); | 1641 last_frame_info_.is_texture = video_frame.is_texture(); |
| 1641 pending_encoder_reconfiguration_ = true; | 1642 pending_encoder_reconfiguration_ = true; |
| 1642 | 1643 |
| 1643 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" | 1644 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" |
| 1644 << last_frame_info_.width << "x" << last_frame_info_.height | 1645 << last_frame_info_.width << "x" << last_frame_info_.height |
| 1645 << ", rotation=" << last_frame_info_.rotation | 1646 << ", rotation=" << last_frame_info_.rotation |
| 1646 << ", texture=" << last_frame_info_.is_texture; | 1647 << ", texture=" << last_frame_info_.is_texture; |
| 1647 } | 1648 } |
| 1648 | 1649 |
| 1649 if (stream_ == NULL) { | 1650 if (encoder_sink_ == NULL) { |
| 1650 // Frame input before send codecs are configured, dropping frame. | 1651 // Frame input before send codecs are configured, dropping frame. |
| 1651 return; | 1652 return; |
| 1652 } | 1653 } |
| 1653 | 1654 |
| 1654 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 1655 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |
| 1655 | 1656 |
| 1656 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 1657 // frame->GetTimeStamp() is essentially a delta, align to webrtc time |
| 1657 if (!first_frame_timestamp_ms_) { | 1658 if (!first_frame_timestamp_ms_) { |
| 1658 first_frame_timestamp_ms_ = | 1659 first_frame_timestamp_ms_ = |
| 1659 rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms); | 1660 rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms); |
|
nisse-webrtc
2016/08/23 10:13:28
We should soon be able to delete this, since all c
perkj_webrtc
2016/09/01 11:46:16
Acknowledged.
| |
| 1660 } | 1661 } |
| 1661 | 1662 |
| 1662 last_frame_timestamp_ms_ = *first_frame_timestamp_ms_ + frame_delta_ms; | 1663 last_frame_timestamp_ms_ = *first_frame_timestamp_ms_ + frame_delta_ms; |
| 1663 | 1664 |
| 1664 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1665 video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
| 1665 | 1666 |
| 1666 if (pending_encoder_reconfiguration_) { | 1667 if (pending_encoder_reconfiguration_) { |
| 1667 ReconfigureEncoder(); | 1668 ReconfigureEncoder(); |
| 1668 pending_encoder_reconfiguration_ = false; | 1669 pending_encoder_reconfiguration_ = false; |
| 1669 } | 1670 } |
| 1670 | 1671 |
| 1671 // Not sending, abort after reconfiguration. Reconfiguration should still | 1672 // Not sending, abort after reconfiguration. Reconfiguration should still |
| 1672 // occur to permit sending this input as quickly as possible once we start | 1673 // occur to permit sending this input as quickly as possible once we start |
| 1673 // sending (without having to reconfigure then). | 1674 // sending (without having to reconfigure then). |
| 1674 if (!sending_) { | 1675 if (!sending_) { |
| 1675 return; | 1676 return; |
| 1676 } | 1677 } |
| 1677 | 1678 |
| 1678 stream_->Input()->IncomingCapturedFrame(video_frame); | 1679 encoder_sink_->OnFrame(video_frame); |
|
nisse-webrtc
2016/08/23 10:13:28
The old IncomingCapturedFrame was responsible for
perkj_webrtc
2016/09/01 11:46:15
That is still done in VieEncoder::OnFrame and is w
| |
| 1679 } | 1680 } |
| 1680 | 1681 |
| 1681 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend( | 1682 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend( |
| 1682 bool enable, | 1683 bool enable, |
| 1683 const VideoOptions* options, | 1684 const VideoOptions* options, |
| 1684 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { | 1685 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { |
| 1685 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend"); | 1686 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetVideoSend"); |
| 1686 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1687 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 1687 | 1688 |
| 1688 // Ignore |options| pointer if |enable| is false. | 1689 // Ignore |options| pointer if |enable| is false. |
| 1689 bool options_present = enable && options; | 1690 bool options_present = enable && options; |
| 1690 bool source_changing = source_ != source; | 1691 bool source_changing = source_ != source; |
| 1691 if (source_changing) { | 1692 if (source_changing) { |
| 1692 DisconnectSource(); | 1693 DisconnectSource(); |
| 1693 } | 1694 } |
| 1694 | 1695 |
| 1695 if (options_present || source_changing) { | 1696 if (options_present || source_changing) { |
| 1696 rtc::CritScope cs(&lock_); | 1697 rtc::CritScope cs(&lock_); |
| 1697 | 1698 |
| 1698 if (options_present) { | 1699 if (options_present) { |
| 1699 VideoOptions old_options = parameters_.options; | 1700 VideoOptions old_options = parameters_.options; |
| 1700 parameters_.options.SetAll(*options); | 1701 parameters_.options.SetAll(*options); |
| 1701 // Reconfigure encoder settings on the naext frame or stream | 1702 // Reconfigure encoder settings on the next frame or stream |
| 1702 // recreation if the options changed. | 1703 // recreation if the options changed. |
| 1703 if (parameters_.options != old_options) { | 1704 if (parameters_.options != old_options) { |
| 1704 pending_encoder_reconfiguration_ = true; | 1705 pending_encoder_reconfiguration_ = true; |
| 1705 } | 1706 } |
| 1706 } | 1707 } |
| 1707 | 1708 |
| 1708 if (source_changing) { | 1709 if (source_changing) { |
| 1709 // Reset timestamps to realign new incoming frames to a webrtc timestamp. | 1710 // Reset timestamps to realign new incoming frames to a webrtc timestamp. |
| 1710 // A new source may have a different timestamp delta than the previous | 1711 // A new source may have a different timestamp delta than the previous |
| 1711 // one. | 1712 // one. |
| 1712 first_frame_timestamp_ms_ = rtc::Optional<int64_t>(); | 1713 first_frame_timestamp_ms_ = rtc::Optional<int64_t>(); |
| 1713 | 1714 |
| 1714 if (source == nullptr && stream_ != nullptr) { | 1715 if (source == nullptr && encoder_sink_ != nullptr) { |
| 1715 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; | 1716 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; |
| 1716 // 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 |
| 1717 // check. As IncomingCapturedFrame will drop the frame if this frame's | 1718 // check. As IncomingCapturedFrame will drop the frame if this frame's |
| 1718 // 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 |
| 1719 // necessary to give this black frame a larger timestamp than the | 1720 // necessary to give this black frame a larger timestamp than the |
| 1720 // previous one. | 1721 // previous one. |
| 1721 last_frame_timestamp_ms_ += 1; | 1722 last_frame_timestamp_ms_ += 1; |
| 1722 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer( | 1723 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer( |
| 1723 webrtc::I420Buffer::Create(last_frame_info_.width, | 1724 webrtc::I420Buffer::Create(last_frame_info_.width, |
| 1724 last_frame_info_.height)); | 1725 last_frame_info_.height)); |
| 1725 black_buffer->SetToBlack(); | 1726 black_buffer->SetToBlack(); |
| 1726 | 1727 |
| 1727 stream_->Input()->IncomingCapturedFrame(webrtc::VideoFrame( | 1728 encoder_sink_->OnFrame(webrtc::VideoFrame( |
| 1728 black_buffer, 0 /* timestamp (90 kHz) */, | 1729 black_buffer, 0 /* timestamp (90 kHz) */, last_frame_timestamp_ms_, |
| 1729 last_frame_timestamp_ms_, last_frame_info_.rotation)); | 1730 last_frame_info_.rotation)); |
| 1730 } | 1731 } |
| 1731 source_ = source; | 1732 source_ = source; |
| 1732 } | 1733 } |
| 1733 } | 1734 } |
| 1734 | 1735 |
| 1735 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since | 1736 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since |
| 1736 // that might cause a lock order inversion. | 1737 // that might cause a lock order inversion. |
| 1737 if (source_changing && source_) { | 1738 if (source_changing && source_) { |
| 1738 source_->AddOrUpdateSink(this, sink_wants_); | 1739 source_->AddOrUpdateSink(this, sink_wants_); |
| 1739 } | 1740 } |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2041 | 2042 |
| 2042 parameters_.encoder_config = std::move(encoder_config); | 2043 parameters_.encoder_config = std::move(encoder_config); |
| 2043 } | 2044 } |
| 2044 | 2045 |
| 2045 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) { | 2046 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) { |
| 2046 rtc::CritScope cs(&lock_); | 2047 rtc::CritScope cs(&lock_); |
| 2047 sending_ = send; | 2048 sending_ = send; |
| 2048 UpdateSendState(); | 2049 UpdateSendState(); |
| 2049 } | 2050 } |
| 2050 | 2051 |
| 2052 void WebRtcVideoChannel2::WebRtcVideoSendStream::AddOrUpdateSink( | |
| 2053 VideoSinkInterface<webrtc::VideoFrame>* sink, | |
| 2054 const rtc::VideoSinkWants& wants) { | |
| 2055 rtc::CritScope cs(&lock_); | |
| 2056 encoder_sink_ = sink; | |
|
nisse-webrtc
2016/08/22 07:20:29
Only one sink supported, right? Add a CHECK that e
perkj_webrtc
2016/09/01 11:46:16
Done.
| |
| 2057 } | |
| 2058 | |
| 2059 void WebRtcVideoChannel2::WebRtcVideoSendStream::RemoveSink( | |
| 2060 VideoSinkInterface<webrtc::VideoFrame>* sink) { | |
| 2061 rtc::CritScope cs(&lock_); | |
| 2062 encoder_sink_ = nullptr; | |
|
nisse-webrtc
2016/08/22 07:20:29
Similarly, add a CHECK that encoder_sink_ == sink?
perkj_webrtc
2016/09/01 11:46:15
Done.
| |
| 2063 } | |
| 2064 | |
| 2051 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { | 2065 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { |
| 2052 if (worker_thread_ != rtc::Thread::Current()) { | 2066 if (worker_thread_ != rtc::Thread::Current()) { |
| 2053 invoker_.AsyncInvoke<void>( | 2067 invoker_.AsyncInvoke<void>( |
| 2054 RTC_FROM_HERE, worker_thread_, | 2068 RTC_FROM_HERE, worker_thread_, |
| 2055 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, | 2069 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, |
| 2056 this, load)); | 2070 this, load)); |
| 2057 return; | 2071 return; |
| 2058 } | 2072 } |
| 2059 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2073 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2060 if (!source_) { | 2074 if (!source_) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2233 ConfigureVideoEncoderSettings(parameters_.codec_settings->codec); | 2247 ConfigureVideoEncoderSettings(parameters_.codec_settings->codec); |
| 2234 | 2248 |
| 2235 webrtc::VideoSendStream::Config config = parameters_.config.Copy(); | 2249 webrtc::VideoSendStream::Config config = parameters_.config.Copy(); |
| 2236 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { | 2250 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { |
| 2237 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " | 2251 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " |
| 2238 "payload type the set codec. Ignoring RTX."; | 2252 "payload type the set codec. Ignoring RTX."; |
| 2239 config.rtp.rtx.ssrcs.clear(); | 2253 config.rtp.rtx.ssrcs.clear(); |
| 2240 } | 2254 } |
| 2241 stream_ = call_->CreateVideoSendStream(std::move(config), | 2255 stream_ = call_->CreateVideoSendStream(std::move(config), |
| 2242 parameters_.encoder_config.Copy()); | 2256 parameters_.encoder_config.Copy()); |
| 2257 stream_->SetSource(this); | |
| 2243 | 2258 |
| 2244 parameters_.encoder_config.encoder_specific_settings = NULL; | 2259 parameters_.encoder_config.encoder_specific_settings = NULL; |
| 2245 pending_encoder_reconfiguration_ = false; | 2260 pending_encoder_reconfiguration_ = false; |
| 2246 | 2261 |
| 2247 if (sending_) { | 2262 if (sending_) { |
| 2248 stream_->Start(); | 2263 stream_->Start(); |
| 2249 } | 2264 } |
| 2250 } | 2265 } |
| 2251 | 2266 |
| 2252 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( | 2267 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2697 rtx_mapping[video_codecs[i].codec.id] != | 2712 rtx_mapping[video_codecs[i].codec.id] != |
| 2698 fec_settings.red_payload_type) { | 2713 fec_settings.red_payload_type) { |
| 2699 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2714 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2700 } | 2715 } |
| 2701 } | 2716 } |
| 2702 | 2717 |
| 2703 return video_codecs; | 2718 return video_codecs; |
| 2704 } | 2719 } |
| 2705 | 2720 |
| 2706 } // namespace cricket | 2721 } // namespace cricket |
| OLD | NEW |