chromium/third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_adapter.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_adapter.h"

#include <algorithm>
#include <atomic>
#include <functional>
#include <utility>

#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/trace_event/base_tracing.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "media/base/media_util.h"
#include "media/base/overlay_info.h"
#include "media/base/platform_features.h"
#include "media/base/supported_types.h"
#include "media/base/video_decoder.h"
#include "media/base/video_types.h"
#include "media/video/gpu_video_accelerator_factories.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_fallback_recorder.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/webrtc/webrtc_video_frame_adapter.h"
#include "third_party/blink/renderer/platform/webrtc/webrtc_video_utils.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/webrtc/api/video/video_frame.h"
#include "third_party/webrtc/api/video_codecs/vp9_profile.h"
#include "third_party/webrtc/modules/video_coding/codecs/h264/include/h264.h"
#include "third_party/webrtc/rtc_base/ref_count.h"
#include "third_party/webrtc/rtc_base/ref_counted_object.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/size.h"

namespace WTF {

template <>
struct CrossThreadCopier<media::VideoDecoderConfig>
    : public CrossThreadCopierPassThrough<media::VideoDecoderConfig> {};

}  // namespace WTF

namespace blink {

namespace {

// Any reasonable size, will be overridden by the decoder anyway.
constexpr gfx::Size kDefaultSize(640, 480);

// Maximum number of buffers that we will queue in |pending_buffers_|.
constexpr int32_t kMaxPendingBuffers =;

// Maximum number of timestamps that will be maintained in |decode_timestamps_|.
// Really only needs to be a bit larger than the maximum reorder distance (which
// is presumably 0 for WebRTC), but being larger doesn't hurt much.
constexpr int32_t kMaxDecodeHistory =;

// Maximum number of consecutive frames that can fail to decode before
// requesting fallback to software decode.
constexpr int32_t kMaxConsecutiveErrors =;

void FinishWait(base::WaitableEvent* waiter, bool* result_out, bool result) {}

void OnRequestOverlayInfo(bool decoder_requires_restart_for_overlay,
                          media::ProvideOverlayInfoCB overlay_info_cb) {}

void RecordInitializationLatency(base::TimeDelta latency) {}

void RecordReinitializationLatency(base::TimeDelta latency) {}

bool HasSoftwareFallback(media::VideoCodec video_codec) {}

struct EncodedImageExternalMemory
    : public media::DecoderBuffer::ExternalMemory {};

scoped_refptr<media::DecoderBuffer> ConvertToDecoderBuffer(
    const webrtc::EncodedImage& input_image) {}

std::optional<RTCVideoDecoderFallbackReason> NeedSoftwareFallback(
    const media::VideoCodec codec,
    const media::DecoderBuffer& buffer,
    const media::VideoDecoderType decoder_type) {}
}  // namespace

// This class is created in the webrtc decoder thread and destroyed on the media
// thread. All the functions except constructor are executed on the media thread
// too.
class RTCVideoDecoderAdapter::Impl {};

void RTCVideoDecoderAdapter::Impl::Initialize(
    const media::VideoDecoderConfig& config,
    CrossThreadOnceFunction<void(bool)> init_cb,
    base::TimeTicks start_time,
    media::VideoDecoderType* decoder_type) {}

void RTCVideoDecoderAdapter::Impl::Decode(
    scoped_refptr<media::DecoderBuffer> buffer,
    base::WaitableEvent* waiter,
    std::optional<RTCVideoDecoderAdapter::DecodeResult>* result) {}

absl::variant<RTCVideoDecoderAdapter::DecodeResult,
              RTCVideoDecoderFallbackReason>
RTCVideoDecoderAdapter::Impl::EnqueueBuffer(
    scoped_refptr<media::DecoderBuffer> buffer) {}

void RTCVideoDecoderAdapter::Impl::DecodePendingBuffers() {}

void RTCVideoDecoderAdapter::Impl::Flush(
    WTF::CrossThreadOnceClosure flush_success_cb,
    WTF::CrossThreadOnceClosure flush_fail_cb) {}

void RTCVideoDecoderAdapter::Impl::RegisterDecodeCompleteCallback(
    webrtc::DecodedImageCallback* callback) {}

void RTCVideoDecoderAdapter::Impl::OnDecodeDone(media::DecoderStatus status) {}

void RTCVideoDecoderAdapter::Impl::OnOutput(
    scoped_refptr<media::VideoFrame> frame) {}

// static
std::atomic_int RTCVideoDecoderAdapter::g_num_decoders_{};

// static
std::unique_ptr<RTCVideoDecoderAdapter> RTCVideoDecoderAdapter::Create(
    media::GpuVideoAcceleratorFactories* gpu_factories,
    const webrtc::SdpVideoFormat& format,
    std::unique_ptr<ResolutionMonitor> resolution_monitor) {}

RTCVideoDecoderAdapter::RTCVideoDecoderAdapter(
    media::GpuVideoAcceleratorFactories* gpu_factories,
    const media::VideoDecoderConfig& config,
    std::unique_ptr<ResolutionMonitor> resolution_monitor)
    :{}

RTCVideoDecoderAdapter::~RTCVideoDecoderAdapter() {}

bool RTCVideoDecoderAdapter::InitializeSync(
    const media::VideoDecoderConfig& config) {}

bool RTCVideoDecoderAdapter::Configure(const Settings& settings) {}

int32_t RTCVideoDecoderAdapter::Decode(const webrtc::EncodedImage& input_image,
                                       bool missing_frames,
                                       int64_t render_time_ms) {}

std::optional<RTCVideoDecoderAdapter::DecodeResult>
RTCVideoDecoderAdapter::DecodeInternal(const webrtc::EncodedImage& input_image,
                                       bool missing_frames,
                                       int64_t render_time_ms) {}

bool RTCVideoDecoderAdapter::CheckResolutionAndNumInstances(
    const media::DecoderBuffer& buffer) {}

int32_t RTCVideoDecoderAdapter::RegisterDecodeCompleteCallback(
    webrtc::DecodedImageCallback* callback) {}

int32_t RTCVideoDecoderAdapter::Release() {}

bool RTCVideoDecoderAdapter::ShouldReinitializeForSettingColorSpace(
    const webrtc::EncodedImage& input_image) const {}

bool RTCVideoDecoderAdapter::ReinitializeSync(
    const media::VideoDecoderConfig& config) {}

void RTCVideoDecoderAdapter::ChangeStatus(Status new_status) {}

int RTCVideoDecoderAdapter::GetCurrentDecoderCountForTesting() {}

void RTCVideoDecoderAdapter::IncrementCurrentDecoderCountForTesting() {}

void RTCVideoDecoderAdapter::DecrementCurrentDecoderCountForTesting() {}

}  // namespace blink