| 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 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 frame_count_(0), | 1580 frame_count_(0), |
| 1581 cpu_restricted_frame_count_(0), | 1581 cpu_restricted_frame_count_(0), |
| 1582 source_(nullptr), | 1582 source_(nullptr), |
| 1583 external_encoder_factory_(external_encoder_factory), | 1583 external_encoder_factory_(external_encoder_factory), |
| 1584 stream_(nullptr), | 1584 stream_(nullptr), |
| 1585 parameters_(config, options, max_bitrate_bps, codec_settings), | 1585 parameters_(config, options, max_bitrate_bps, codec_settings), |
| 1586 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1586 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
| 1587 pending_encoder_reconfiguration_(false), | 1587 pending_encoder_reconfiguration_(false), |
| 1588 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 1588 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), |
| 1589 sending_(false), | 1589 sending_(false), |
| 1590 last_frame_timestamp_ms_(0) { | 1590 last_frame_timestamp_us_(0) { |
| 1591 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1591 parameters_.config.rtp.max_packet_size = kVideoMtu; |
| 1592 parameters_.conference_mode = send_params.conference_mode; | 1592 parameters_.conference_mode = send_params.conference_mode; |
| 1593 | 1593 |
| 1594 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1594 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
| 1595 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1595 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
| 1596 ¶meters_.config.rtp.rtx.ssrcs); | 1596 ¶meters_.config.rtp.rtx.ssrcs); |
| 1597 parameters_.config.rtp.c_name = sp.cname; | 1597 parameters_.config.rtp.c_name = sp.cname; |
| 1598 if (rtp_extensions) { | 1598 if (rtp_extensions) { |
| 1599 parameters_.config.rtp.extensions = *rtp_extensions; | 1599 parameters_.config.rtp.extensions = *rtp_extensions; |
| 1600 } | 1600 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 if (frame_count_ > kMinRequiredFrames) { | 1632 if (frame_count_ > kMinRequiredFrames) { |
| 1633 RTC_LOGGED_HISTOGRAM_PERCENTAGE( | 1633 RTC_LOGGED_HISTOGRAM_PERCENTAGE( |
| 1634 "WebRTC.Video.CpuLimitedResolutionInPercent", | 1634 "WebRTC.Video.CpuLimitedResolutionInPercent", |
| 1635 cpu_restricted_frame_count_ * 100 / frame_count_); | 1635 cpu_restricted_frame_count_ * 100 / frame_count_); |
| 1636 } | 1636 } |
| 1637 } | 1637 } |
| 1638 | 1638 |
| 1639 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( | 1639 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( |
| 1640 const VideoFrame& frame) { | 1640 const VideoFrame& frame) { |
| 1641 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); | 1641 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); |
| 1642 webrtc::VideoFrame video_frame(frame.video_frame_buffer(), 0, 0, | 1642 webrtc::VideoFrame video_frame(frame.video_frame_buffer(), |
| 1643 frame.rotation()); | 1643 frame.rotation(), |
| 1644 frame.timestamp_us()); |
| 1645 |
| 1644 rtc::CritScope cs(&lock_); | 1646 rtc::CritScope cs(&lock_); |
| 1645 | 1647 |
| 1646 if (video_frame.width() != last_frame_info_.width || | 1648 if (video_frame.width() != last_frame_info_.width || |
| 1647 video_frame.height() != last_frame_info_.height || | 1649 video_frame.height() != last_frame_info_.height || |
| 1648 video_frame.rotation() != last_frame_info_.rotation || | 1650 video_frame.rotation() != last_frame_info_.rotation || |
| 1649 video_frame.is_texture() != last_frame_info_.is_texture) { | 1651 video_frame.is_texture() != last_frame_info_.is_texture) { |
| 1650 last_frame_info_.width = video_frame.width(); | 1652 last_frame_info_.width = video_frame.width(); |
| 1651 last_frame_info_.height = video_frame.height(); | 1653 last_frame_info_.height = video_frame.height(); |
| 1652 last_frame_info_.rotation = video_frame.rotation(); | 1654 last_frame_info_.rotation = video_frame.rotation(); |
| 1653 last_frame_info_.is_texture = video_frame.is_texture(); | 1655 last_frame_info_.is_texture = video_frame.is_texture(); |
| 1654 pending_encoder_reconfiguration_ = true; | 1656 pending_encoder_reconfiguration_ = true; |
| 1655 | 1657 |
| 1656 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" | 1658 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" |
| 1657 << last_frame_info_.width << "x" << last_frame_info_.height | 1659 << last_frame_info_.width << "x" << last_frame_info_.height |
| 1658 << ", rotation=" << last_frame_info_.rotation | 1660 << ", rotation=" << last_frame_info_.rotation |
| 1659 << ", texture=" << last_frame_info_.is_texture; | 1661 << ", texture=" << last_frame_info_.is_texture; |
| 1660 } | 1662 } |
| 1661 | 1663 |
| 1662 if (stream_ == NULL) { | 1664 if (stream_ == NULL) { |
| 1663 // Frame input before send codecs are configured, dropping frame. | 1665 // Frame input before send codecs are configured, dropping frame. |
| 1664 return; | 1666 return; |
| 1665 } | 1667 } |
| 1666 | 1668 |
| 1667 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 1669 last_frame_timestamp_us_ = video_frame.timestamp_us(); |
| 1668 | |
| 1669 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | |
| 1670 if (!first_frame_timestamp_ms_) { | |
| 1671 first_frame_timestamp_ms_ = | |
| 1672 rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms); | |
| 1673 } | |
| 1674 | |
| 1675 last_frame_timestamp_ms_ = *first_frame_timestamp_ms_ + frame_delta_ms; | |
| 1676 | |
| 1677 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | |
| 1678 | 1670 |
| 1679 if (pending_encoder_reconfiguration_) { | 1671 if (pending_encoder_reconfiguration_) { |
| 1680 ReconfigureEncoder(); | 1672 ReconfigureEncoder(); |
| 1681 pending_encoder_reconfiguration_ = false; | 1673 pending_encoder_reconfiguration_ = false; |
| 1682 } | 1674 } |
| 1683 | 1675 |
| 1684 // Not sending, abort after reconfiguration. Reconfiguration should still | 1676 // Not sending, abort after reconfiguration. Reconfiguration should still |
| 1685 // occur to permit sending this input as quickly as possible once we start | 1677 // occur to permit sending this input as quickly as possible once we start |
| 1686 // sending (without having to reconfigure then). | 1678 // sending (without having to reconfigure then). |
| 1687 if (!sending_) { | 1679 if (!sending_) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1716 VideoOptions old_options = parameters_.options; | 1708 VideoOptions old_options = parameters_.options; |
| 1717 parameters_.options.SetAll(*options); | 1709 parameters_.options.SetAll(*options); |
| 1718 // Reconfigure encoder settings on the naext frame or stream | 1710 // Reconfigure encoder settings on the naext frame or stream |
| 1719 // recreation if the options changed. | 1711 // recreation if the options changed. |
| 1720 if (parameters_.options != old_options) { | 1712 if (parameters_.options != old_options) { |
| 1721 pending_encoder_reconfiguration_ = true; | 1713 pending_encoder_reconfiguration_ = true; |
| 1722 } | 1714 } |
| 1723 } | 1715 } |
| 1724 | 1716 |
| 1725 if (source_changing) { | 1717 if (source_changing) { |
| 1726 // Reset timestamps to realign new incoming frames to a webrtc timestamp. | |
| 1727 // A new source may have a different timestamp delta than the previous | |
| 1728 // one. | |
| 1729 first_frame_timestamp_ms_ = rtc::Optional<int64_t>(); | |
| 1730 | |
| 1731 if (source == nullptr && stream_ != nullptr) { | 1718 if (source == nullptr && stream_ != nullptr) { |
| 1732 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; | 1719 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; |
| 1733 // Force this black frame not to be dropped due to timestamp order | 1720 // Force this black frame not to be dropped due to timestamp order |
| 1734 // check. As IncomingCapturedFrame will drop the frame if this frame's | 1721 // check. As IncomingCapturedFrame will drop the frame if this frame's |
| 1735 // timestamp is less than or equal to last frame's timestamp, it is | 1722 // timestamp is less than or equal to last frame's timestamp, it is |
| 1736 // necessary to give this black frame a larger timestamp than the | 1723 // necessary to give this black frame a larger timestamp than the |
| 1737 // previous one. | 1724 // previous one. |
| 1738 last_frame_timestamp_ms_ += 1; | 1725 last_frame_timestamp_us_ += rtc::kNumMicrosecsPerMillisec; |
| 1739 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer( | 1726 rtc::scoped_refptr<webrtc::I420Buffer> black_buffer( |
| 1740 webrtc::I420Buffer::Create(last_frame_info_.width, | 1727 webrtc::I420Buffer::Create(last_frame_info_.width, |
| 1741 last_frame_info_.height)); | 1728 last_frame_info_.height)); |
| 1742 black_buffer->SetToBlack(); | 1729 black_buffer->SetToBlack(); |
| 1743 | 1730 |
| 1744 stream_->Input()->IncomingCapturedFrame(webrtc::VideoFrame( | 1731 stream_->Input()->IncomingCapturedFrame(webrtc::VideoFrame( |
| 1745 black_buffer, 0 /* timestamp (90 kHz) */, | 1732 black_buffer, last_frame_info_.rotation, |
| 1746 last_frame_timestamp_ms_, last_frame_info_.rotation)); | 1733 last_frame_timestamp_us_)); |
| 1747 } | 1734 } |
| 1748 source_ = source; | 1735 source_ = source; |
| 1749 } | 1736 } |
| 1750 } | 1737 } |
| 1751 | 1738 |
| 1752 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since | 1739 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since |
| 1753 // that might cause a lock order inversion. | 1740 // that might cause a lock order inversion. |
| 1754 if (source_changing && source_) { | 1741 if (source_changing && source_) { |
| 1755 source_->AddOrUpdateSink(this, sink_wants_); | 1742 source_->AddOrUpdateSink(this, sink_wants_); |
| 1756 } | 1743 } |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2713 rtx_mapping[video_codecs[i].codec.id] != | 2700 rtx_mapping[video_codecs[i].codec.id] != |
| 2714 fec_settings.red_payload_type) { | 2701 fec_settings.red_payload_type) { |
| 2715 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2702 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2716 } | 2703 } |
| 2717 } | 2704 } |
| 2718 | 2705 |
| 2719 return video_codecs; | 2706 return video_codecs; |
| 2720 } | 2707 } |
| 2721 | 2708 |
| 2722 } // namespace cricket | 2709 } // namespace cricket |
| OLD | NEW |