Reason for revert: Reverting the revert. This change is not related to the failure on the Windows FYI bots. The cause of the failure has been reverted in Chromium: https://codereview.chromium.org/2081653004/ Original issue's description: > Revert of Split IncomingVideoStream into two implementations, with smoothing and without. (patchset #5 id:340001 of https://codereview.webrtc.org/2078873002/ ) > > Reason for revert: > Breaks chromium.webrtc.fyi > > https://uberchromegw.corp.google.com/i/chromium.webrtc.fyi/builders/Win7%20Tester/builds/4719 > https://uberchromegw.corp.google.com/i/chromium.webrtc.fyi/builders/Win10%20Tester/builds/3120 > > Original issue's description: > > Reland of IncomingVideoStream refactoring. > > This reland does not contain the non-smoothing part of the original implementation. Instead, when smoothing is turned off, frame callbacks run on the decoder thread, as they did before. This code path is used in Chrome. As far as Chrome goes, the difference now is that there won't be an instance of IncomingVideoStream in between the decoder and the callback (i.e. fewer locks). Other than that, no change for Chrome. > > > > Original issue's description (with non-smoothing references removed): > > > > Split IncomingVideoStream into two implementations, with smoothing and without. > > > > * Added TODOs and documentation for VideoReceiveStream::OnFrame, where we today grab 6 locks. > > > > * Removed the Start/Stop methods from the IncomingVideoStream implementations. Now, when an instance is created, it should be considered to be "running" and when it is deleted, it's "not running". This saves on resources and also reduces the amount of locking required and I could remove one critical section altogether. > > > > * Changed the VideoStreamDecoder class to not depend on IncomingVideoStream but rather use the generic rtc::VideoSinkInterface<VideoFrame> interface. This means that any implementation of that interface can be used and the decoder can be made to just use the 'renderer' from the config. Once we do that, we can decouple the IncomingVideoStream implementations from the decoder and VideoReceiveStream implementations and leave it up to the application for how to do smoothing. The app can choose to use the Incoming* classes or roll its own (which may be preferable since applications often have their own scheduling mechanisms). > > > > * The lifetime of the VideoStreamDecoder instance is now bound to Start/Stop in VideoReceiveStream and not all of the lifetime of VideoReceiveStream. > > > > * Fixed VideoStreamDecoder to unregister callbacks in the dtor that were registered in the ctor. (this was open to a use-after-free regression) > > > > * Delay and callback pointers are now passed via the ctors to the IncomingVideoStream classes. The thread primitives in the IncomingVideoStream classes are also constructed/destructed at the same time as the owning object, which allowed me to remove one more lock. > > > > * Removed code in the VideoStreamDecoder that could overwrite the VideoReceiveStream render delay with a fixed value of 10ms on construction. This wasn't a problem with the previous implementation (it would be now though) but seemed to me like the wrong place to be setting that value. > > > > * Made the render delay value in VideoRenderFrames, const. > > > > BUG=chromium:620232 > > R=mflodman@webrtc.org, nisse@webrtc.org > > > > Committed: https://crrev.com/884c336c345d988974c2a69cea402b0fb8b07a63 > > Cr-Commit-Position: refs/heads/master@{#13219} > > TBR=nisse@webrtc.org,philipel@webrtc.org,mflodman@webrtc.org,tommi@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=chromium:620232 > > Committed: https://crrev.com/a536bfe70de38fe877245317a7f0b00bcf69cbd0 > Cr-Commit-Position: refs/heads/master@{#13229} TBR=nisse@webrtc.org,philipel@webrtc.org,mflodman@webrtc.org,sakal@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=chromium:620232 Review-Url: https://codereview.webrtc.org/2089613002 Cr-Commit-Position: refs/heads/master@{#13230}
146 lines
5.5 KiB
C++
146 lines
5.5 KiB
C++
/*
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "webrtc/video/video_stream_decoder.h"
|
|
|
|
#include <algorithm>
|
|
#include <map>
|
|
#include <vector>
|
|
|
|
#include "webrtc/base/checks.h"
|
|
#include "webrtc/base/logging.h"
|
|
#include "webrtc/common_video/include/frame_callback.h"
|
|
#include "webrtc/modules/video_coding/video_coding_impl.h"
|
|
#include "webrtc/modules/video_processing/include/video_processing.h"
|
|
#include "webrtc/system_wrappers/include/metrics.h"
|
|
#include "webrtc/video/call_stats.h"
|
|
#include "webrtc/video/payload_router.h"
|
|
#include "webrtc/video/receive_statistics_proxy.h"
|
|
|
|
namespace webrtc {
|
|
|
|
VideoStreamDecoder::VideoStreamDecoder(
|
|
vcm::VideoReceiver* video_receiver,
|
|
VCMFrameTypeCallback* vcm_frame_type_callback,
|
|
VCMPacketRequestCallback* vcm_packet_request_callback,
|
|
bool enable_nack,
|
|
bool enable_fec,
|
|
ReceiveStatisticsProxy* receive_statistics_proxy,
|
|
rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream,
|
|
I420FrameCallback* pre_render_callback)
|
|
: video_receiver_(video_receiver),
|
|
receive_stats_callback_(receive_statistics_proxy),
|
|
incoming_video_stream_(incoming_video_stream),
|
|
pre_render_callback_(pre_render_callback),
|
|
last_rtt_ms_(0) {
|
|
RTC_DCHECK(video_receiver_);
|
|
|
|
static const int kMaxPacketAgeToNack = 450;
|
|
static const int kMaxNackListSize = 250;
|
|
video_receiver_->SetNackSettings(kMaxNackListSize,
|
|
kMaxPacketAgeToNack, 0);
|
|
video_receiver_->RegisterReceiveCallback(this);
|
|
video_receiver_->RegisterFrameTypeCallback(vcm_frame_type_callback);
|
|
video_receiver_->RegisterReceiveStatisticsCallback(this);
|
|
video_receiver_->RegisterDecoderTimingCallback(this);
|
|
|
|
VCMVideoProtection video_protection =
|
|
enable_nack ? (enable_fec ? kProtectionNackFEC : kProtectionNack)
|
|
: kProtectionNone;
|
|
|
|
VCMDecodeErrorMode decode_error_mode = enable_nack ? kNoErrors : kWithErrors;
|
|
video_receiver_->SetVideoProtection(video_protection, true);
|
|
video_receiver_->SetDecodeErrorMode(decode_error_mode);
|
|
VCMPacketRequestCallback* packet_request_callback =
|
|
enable_nack ? vcm_packet_request_callback : nullptr;
|
|
video_receiver_->RegisterPacketRequestCallback(packet_request_callback);
|
|
}
|
|
|
|
VideoStreamDecoder::~VideoStreamDecoder() {
|
|
// Unset all the callback pointers that we set in the ctor.
|
|
video_receiver_->RegisterPacketRequestCallback(nullptr);
|
|
video_receiver_->RegisterDecoderTimingCallback(nullptr);
|
|
video_receiver_->RegisterReceiveStatisticsCallback(nullptr);
|
|
video_receiver_->RegisterFrameTypeCallback(nullptr);
|
|
video_receiver_->RegisterReceiveCallback(nullptr);
|
|
}
|
|
|
|
// Do not acquire the lock of |video_receiver_| in this function. Decode
|
|
// callback won't necessarily be called from the decoding thread. The decoding
|
|
// thread may have held the lock when calling VideoDecoder::Decode, Reset, or
|
|
// Release. Acquiring the same lock in the path of decode callback can deadlock.
|
|
int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame) { // NOLINT
|
|
if (pre_render_callback_) {
|
|
// Post processing is not supported if the frame is backed by a texture.
|
|
if (!video_frame.video_frame_buffer()->native_handle()) {
|
|
pre_render_callback_->FrameCallback(&video_frame);
|
|
}
|
|
}
|
|
|
|
if (incoming_video_stream_)
|
|
incoming_video_stream_->OnFrame(video_frame);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int32_t VideoStreamDecoder::ReceivedDecodedReferenceFrame(
|
|
const uint64_t picture_id) {
|
|
RTC_NOTREACHED();
|
|
return 0;
|
|
}
|
|
|
|
void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
|
|
receive_stats_callback_->OnIncomingPayloadType(payload_type);
|
|
}
|
|
|
|
void VideoStreamDecoder::OnDecoderImplementationName(
|
|
const char* implementation_name) {
|
|
receive_stats_callback_->OnDecoderImplementationName(implementation_name);
|
|
}
|
|
|
|
void VideoStreamDecoder::OnReceiveRatesUpdated(uint32_t bit_rate,
|
|
uint32_t frame_rate) {
|
|
receive_stats_callback_->OnIncomingRate(frame_rate, bit_rate);
|
|
}
|
|
|
|
void VideoStreamDecoder::OnDiscardedPacketsUpdated(int discarded_packets) {
|
|
receive_stats_callback_->OnDiscardedPacketsUpdated(discarded_packets);
|
|
}
|
|
|
|
void VideoStreamDecoder::OnFrameCountsUpdated(const FrameCounts& frame_counts) {
|
|
receive_stats_callback_->OnFrameCountsUpdated(frame_counts);
|
|
}
|
|
|
|
void VideoStreamDecoder::OnDecoderTiming(int decode_ms,
|
|
int max_decode_ms,
|
|
int current_delay_ms,
|
|
int target_delay_ms,
|
|
int jitter_buffer_ms,
|
|
int min_playout_delay_ms,
|
|
int render_delay_ms) {
|
|
int last_rtt = -1;
|
|
{
|
|
rtc::CritScope lock(&crit_);
|
|
last_rtt = last_rtt_ms_;
|
|
}
|
|
|
|
receive_stats_callback_->OnDecoderTiming(
|
|
decode_ms, max_decode_ms, current_delay_ms, target_delay_ms,
|
|
jitter_buffer_ms, min_playout_delay_ms, render_delay_ms, last_rtt);
|
|
}
|
|
|
|
void VideoStreamDecoder::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
|
|
video_receiver_->SetReceiveChannelParameters(max_rtt_ms);
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
last_rtt_ms_ = avg_rtt_ms;
|
|
}
|
|
} // namespace webrtc
|