#include "third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_stream_adapter.h"
#include <algorithm>
#include <functional>
#include <utility>
#include "base/atomic_ref_count.h"
#include "base/containers/circular_deque.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/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/synchronization/waitable_event.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/video_types.h"
#include "media/renderers/default_decoder_factory.h"
#include "media/video/gpu_video_accelerator_factories.h"
#include "media/video/video_decode_accelerator.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_adapter.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/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"
namespace WTF {
template <>
struct CrossThreadCopier<media::VideoDecoderConfig>
: public CrossThreadCopierPassThrough<media::VideoDecoderConfig> { … };
}
namespace blink {
namespace {
constexpr gfx::Size kDefaultSize(640, 480);
constexpr int32_t kMaxFramesWhilePausedBeforeFallback = …;
constexpr int32_t kMaxKeyFrameIntervalWhilePaused = …;
constexpr int32_t kMaxPendingBuffers = …;
constexpr int32_t kAbsoluteMaxPendingBuffers = …;
constexpr const char* kExternalDecoderName = …;
class DecoderCounter { … };
DecoderCounter* GetDecoderCounter() { … }
void RecordInitializationLatency(base::TimeDelta latency) { … }
}
constexpr gfx::Size RTCVideoDecoderStreamAdapter::kMinResolution;
class RTCVideoDecoderStreamAdapter::InternalDemuxerStream
: public media::DemuxerStream { … };
std::unique_ptr<RTCVideoDecoderStreamAdapter>
RTCVideoDecoderStreamAdapter::Create(
media::GpuVideoAcceleratorFactories* gpu_factories,
base::WeakPtr<media::DecoderFactory> decoder_factory,
scoped_refptr<base::SequencedTaskRunner> media_task_runner,
const gfx::ColorSpace& render_color_space,
const webrtc::SdpVideoFormat& format) { … }
RTCVideoDecoderStreamAdapter::RTCVideoDecoderStreamAdapter(
media::GpuVideoAcceleratorFactories* gpu_factories,
base::WeakPtr<media::DecoderFactory> decoder_factory,
scoped_refptr<base::SequencedTaskRunner> media_task_runner,
const gfx::ColorSpace& render_color_space,
const media::VideoDecoderConfig& config,
const webrtc::SdpVideoFormat& format)
: … { … }
RTCVideoDecoderStreamAdapter::~RTCVideoDecoderStreamAdapter() { … }
void RTCVideoDecoderStreamAdapter::InitializeOrReinitializeSync() { … }
bool RTCVideoDecoderStreamAdapter::Configure(const Settings& settings) { … }
void RTCVideoDecoderStreamAdapter::AttemptLogInitializationState_Locked() { … }
int32_t RTCVideoDecoderStreamAdapter::Decode(
const webrtc::EncodedImage& input_image,
bool missing_frames,
int64_t render_time_ms) { … }
int32_t RTCVideoDecoderStreamAdapter::RegisterDecodeCompleteCallback(
webrtc::DecodedImageCallback* callback) { … }
int32_t RTCVideoDecoderStreamAdapter::Release() { … }
webrtc::VideoDecoder::DecoderInfo RTCVideoDecoderStreamAdapter::GetDecoderInfo()
const { … }
void RTCVideoDecoderStreamAdapter::InitializeOnMediaThread(
const media::VideoDecoderConfig& config,
InitCB init_cb) { … }
void RTCVideoDecoderStreamAdapter::OnInitializeDone(base::TimeTicks start_time,
bool success) { … }
void RTCVideoDecoderStreamAdapter::DecodeOnMediaThread(
std::unique_ptr<PendingBuffer> pending_buffer) { … }
void RTCVideoDecoderStreamAdapter::OnFrameReady(
media::VideoDecoderStream::ReadResult result) { … }
void RTCVideoDecoderStreamAdapter::AttemptRead() { … }
bool RTCVideoDecoderStreamAdapter::ShouldReinitializeForSettingHDRColorSpace(
const webrtc::EncodedImage& input_image) const { … }
void RTCVideoDecoderStreamAdapter::ResetOnMediaThread() { … }
void RTCVideoDecoderStreamAdapter::OnResetCompleteOnMediaThread() { … }
void RTCVideoDecoderStreamAdapter::AdjustQueueLength_Locked() { … }
void RTCVideoDecoderStreamAdapter::ShutdownOnMediaThread() { … }
void RTCVideoDecoderStreamAdapter::OnDecoderChanged(
media::VideoDecoder* decoder) { … }
void RTCVideoDecoderStreamAdapter::RecordMaxInFlightDecodesLockedOnMedia() { … }
void RTCVideoDecoderStreamAdapter::RestartDecoderStreamOnMedia() { … }
int32_t RTCVideoDecoderStreamAdapter::FallBackToSoftware_Locked() { … }
bool RTCVideoDecoderStreamAdapter::IsDecodingPaused_Locked() const { … }
}