#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/gpu/vaapi/h264_vaapi_video_decoder_delegate.h"
#include <va/va.h>
#include "base/memory/aligned_memory.h"
#include "base/trace_event/trace_event.h"
#include "media/base/cdm_context.h"
#include "media/gpu/h264_dpb.h"
#include "media/gpu/macros.h"
#include "media/gpu/vaapi/vaapi_common.h"
#include "media/gpu/vaapi/vaapi_decode_surface_handler.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
namespace media {
DecodeStatus;
namespace {
static constexpr int kZigzagScan4x4[16] = …;
static constexpr uint8_t kZigzagScan8x8[64] = …;
#if BUILDFLAG(IS_CHROMEOS_ASH)
int GetSliceHeaderCounter() {
static base::AtomicSequenceNumber parsed_slice_hdr_counter;
return parsed_slice_hdr_counter.GetNext();
}
#endif
}
constexpr size_t kAmdEncryptedSliceHeaderSize = …;
#if BUILDFLAG(IS_CHROMEOS_ASH)
typedef struct AMD_EXTRA_SLICE_PARAMS {
uint8_t bottom_field_flag;
uint8_t num_ref_idx_l0_active_minus1;
uint8_t num_ref_idx_l1_active_minus1;
} AMD_EXTRA_SLICE_PARAMS;
typedef struct AMD_SLICE_PARAMS {
AMD_EXTRA_SLICE_PARAMS va_param;
uint8_t reserved[64 - sizeof(AMD_EXTRA_SLICE_PARAMS)];
VACencSliceParameterBufferH264 cenc_param;
} AMD_SLICE_PARAMS;
static_assert(sizeof(AMD_SLICE_PARAMS) <= kAmdEncryptedSliceHeaderSize,
"Invalid size for AMD_SLICE_PARAMS");
#endif
H264VaapiVideoDecoderDelegate::H264VaapiVideoDecoderDelegate(
VaapiDecodeSurfaceHandler* const vaapi_dec,
scoped_refptr<VaapiWrapper> vaapi_wrapper,
ProtectedSessionUpdateCB on_protected_session_update_cb,
CdmContext* cdm_context,
EncryptionScheme encryption_scheme)
: … { … }
H264VaapiVideoDecoderDelegate::~H264VaapiVideoDecoderDelegate() = default;
scoped_refptr<H264Picture> H264VaapiVideoDecoderDelegate::CreateH264Picture() { … }
static void InitVAPicture(VAPictureH264* va_pic) { … }
void H264VaapiVideoDecoderDelegate::ProcessSPS(
const H264SPS* sps,
base::span<const uint8_t> sps_nalu_data) { … }
void H264VaapiVideoDecoderDelegate::ProcessPPS(
const H264PPS* pps,
base::span<const uint8_t> pps_nalu_data) { … }
DecodeStatus H264VaapiVideoDecoderDelegate::SubmitFrameMetadata(
const H264SPS* sps,
const H264PPS* pps,
const H264DPB& dpb,
const H264Picture::Vector& ref_pic_listp0,
const H264Picture::Vector& ref_pic_listb0,
const H264Picture::Vector& ref_pic_listb1,
scoped_refptr<H264Picture> pic) { … }
DecodeStatus H264VaapiVideoDecoderDelegate::ParseEncryptedSliceHeader(
const std::vector<base::span<const uint8_t>>& data,
const std::vector<SubsampleEntry>& subsamples,
uint64_t ,
H264SliceHeader* slice_header_out) { … }
DecodeStatus H264VaapiVideoDecoderDelegate::SubmitSlice(
const H264PPS* pps,
const H264SliceHeader* slice_hdr,
const H264Picture::Vector& ref_pic_list0,
const H264Picture::Vector& ref_pic_list1,
scoped_refptr<H264Picture> pic,
const uint8_t* data,
size_t size,
const std::vector<SubsampleEntry>& subsamples) { … }
DecodeStatus H264VaapiVideoDecoderDelegate::SubmitDecode(
scoped_refptr<H264Picture> pic) { … }
bool H264VaapiVideoDecoderDelegate::OutputPicture(
scoped_refptr<H264Picture> pic) { … }
void H264VaapiVideoDecoderDelegate::Reset() { … }
DecodeStatus H264VaapiVideoDecoderDelegate::SetStream(
base::span<const uint8_t> ,
const DecryptConfig* decrypt_config) { … }
bool H264VaapiVideoDecoderDelegate::RequiresRefLists() { … }
void H264VaapiVideoDecoderDelegate::FillVAPicture(
VAPictureH264* va_pic,
scoped_refptr<H264Picture> pic) { … }
}