#include "media/gpu/vaapi/vaapi_video_decoder.h"
#include <vulkan/vulkan.h>
#include <limits>
#include <vector>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_map.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "gpu/ipc/common/gpu_memory_buffer_support.h"
#include "media/base/format_utils.h"
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
#include "media/gpu/av1_decoder.h"
#include "media/gpu/chromeos/dmabuf_video_frame_pool.h"
#include "media/gpu/chromeos/native_pixmap_frame_resource.h"
#include "media/gpu/chromeos/platform_video_frame_utils.h"
#include "media/gpu/gpu_video_decode_accelerator_helpers.h"
#include "media/gpu/macros.h"
#include "media/gpu/vaapi/av1_vaapi_video_decoder_delegate.h"
#include "media/gpu/vaapi/h264_vaapi_video_decoder_delegate.h"
#include "media/gpu/vaapi/vaapi_utils.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.h"
#include "media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.h"
#include "media/media_buildflags.h"
#include "ui/gfx/buffer_format_util.h"
#if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
#include "media/gpu/vaapi/h265_vaapi_video_decoder_delegate.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/components/cdm_factory_daemon/chromeos_cdm_context.h"
#include "chromeos/components/cdm_factory_daemon/chromeos_cdm_factory.h"
#endif
namespace media {
namespace {
constexpr size_t kTimestampCacheSize = …;
std::optional<VideoPixelFormat> GetPixelFormatForBitDepth(uint8_t bit_depth) { … }
inline int RoundDownToEven(int x) { … }
inline int RoundUpToEven(int x) { … }
}
VaapiVideoDecoder::DecodeTask::DecodeTask(scoped_refptr<DecoderBuffer> buffer,
int32_t buffer_id,
DecodeCB decode_done_cb)
: … { … }
VaapiVideoDecoder::DecodeTask::~DecodeTask() = default;
VaapiVideoDecoder::DecodeTask::DecodeTask(DecodeTask&&) = default;
std::unique_ptr<VideoDecoderMixin> VaapiVideoDecoder::Create(
std::unique_ptr<MediaLog> media_log,
scoped_refptr<base::SequencedTaskRunner> decoder_task_runner,
base::WeakPtr<VideoDecoderMixin::Client> client) { … }
std::optional<SupportedVideoDecoderConfigs>
VaapiVideoDecoder::GetSupportedConfigs() { … }
VaapiVideoDecoder::VaapiVideoDecoder(
std::unique_ptr<MediaLog> media_log,
scoped_refptr<base::SequencedTaskRunner> decoder_task_runner,
base::WeakPtr<VideoDecoderMixin::Client> client)
: … { … }
VaapiVideoDecoder::~VaapiVideoDecoder() { … }
void VaapiVideoDecoder::Initialize(const VideoDecoderConfig& config,
bool ,
CdmContext* cdm_context,
InitCB init_cb,
const PipelineOutputCB& output_cb,
const WaitingCB& waiting_cb) { … }
void VaapiVideoDecoder::OnCdmContextEvent(CdmContext::Event event) { … }
void VaapiVideoDecoder::Decode(scoped_refptr<DecoderBuffer> buffer,
DecodeCB decode_cb) { … }
void VaapiVideoDecoder::ScheduleNextDecodeTask() { … }
void VaapiVideoDecoder::HandleDecodeTask() { … }
void VaapiVideoDecoder::ClearDecodeTaskQueue(DecoderStatus status) { … }
std::unique_ptr<VASurfaceHandle> VaapiVideoDecoder::CreateSurface() { … }
void VaapiVideoDecoder::SurfaceReady(VASurfaceID va_surface_id,
int32_t buffer_id,
const gfx::Rect& visible_rect,
const VideoColorSpace& color_space) { … }
void VaapiVideoDecoder::
set_ignore_resolution_changes_to_smaller_vp9_for_testing(bool value) { … }
void VaapiVideoDecoder::ApplyResolutionChange() { … }
void VaapiVideoDecoder::ApplyResolutionChangeWithScreenSizes(
const std::vector<gfx::Size>& screen_resolutions) { … }
CroStatus::Or<scoped_refptr<FrameResource>>
VaapiVideoDecoder::AllocateCustomFrameProxy(
base::WeakPtr<VaapiVideoDecoder> decoder,
VideoPixelFormat format,
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const gfx::Size& natural_size,
bool use_protected,
bool use_linear_buffers,
bool needs_detiling,
base::TimeDelta timestamp) { … }
CroStatus::Or<scoped_refptr<FrameResource>>
VaapiVideoDecoder::AllocateCustomFrame(VideoPixelFormat format,
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const gfx::Size& natural_size,
bool ,
bool use_linear_buffers,
bool needs_detiling,
base::TimeDelta timestamp) { … }
bool VaapiVideoDecoder::NeedsBitstreamConversion() const { … }
bool VaapiVideoDecoder::CanReadWithoutStalling() const { … }
int VaapiVideoDecoder::GetMaxDecodeRequests() const { … }
VideoDecoderType VaapiVideoDecoder::GetDecoderType() const { … }
bool VaapiVideoDecoder::IsPlatformDecoder() const { … }
bool VaapiVideoDecoder::NeedsTranscryption() { … }
void VaapiVideoDecoder::ReleaseVideoFrame(VASurfaceID surface_id) { … }
void VaapiVideoDecoder::NotifyFrameAvailable() { … }
void VaapiVideoDecoder::ProtectedSessionUpdate(bool success) { … }
void VaapiVideoDecoder::Flush() { … }
void VaapiVideoDecoder::Reset(base::OnceClosure reset_cb) { … }
VaapiStatus VaapiVideoDecoder::CreateAcceleratedVideoDecoder() { … }
void VaapiVideoDecoder::ResetDone(base::OnceClosure reset_cb) { … }
void VaapiVideoDecoder::SetState(State state) { … }
void VaapiVideoDecoder::SetErrorState(std::string message) { … }
}