chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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 {

// from ITU-T REC H.264 spec
// section 8.5.6
// "Inverse scanning process for 4x4 transform coefficients and scaling lists"
static constexpr int kZigzagScan4x4[16] =;

// section 8.5.7
// "Inverse scanning process for 8x8 transform coefficients and scaling lists"
static constexpr uint8_t kZigzagScan8x8[64] =;

#if BUILDFLAG(IS_CHROMEOS_ASH)
int GetSliceHeaderCounter() {
  // Needs to be static in case there are multiple active at once, in which case
  // they all need unique values.
  static base::AtomicSequenceNumber parsed_slice_hdr_counter;
  return parsed_slice_hdr_counter.GetNext();
}
#endif

}  // namespace

// This is the size of the data block which the AMD_SLICE_PARAMS is stored in.
constexpr size_t kAmdEncryptedSliceHeaderSize =;
#if BUILDFLAG(IS_CHROMEOS_ASH)
// These structures match what AMD uses to pass back the extra slice header
// parameters we need for CENCv1. This is stored in the first 1KB of the
// encrypted subsample returned by the cdm-oemcrypto daemon on ChromeOS.
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  // BUILDFLAG(IS_CHROMEOS_ASH)

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() {}

// Fill |va_pic| with default/neutral values.
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 /*secure_handle*/,
    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> /*stream*/,
    const DecryptConfig* decrypt_config) {}

bool H264VaapiVideoDecoderDelegate::RequiresRefLists() {}

void H264VaapiVideoDecoderDelegate::FillVAPicture(
    VAPictureH264* va_pic,
    scoped_refptr<H264Picture> pic) {}

}  // namespace media