#ifndef MEDIA_GPU_VAAPI_TEST_H265_VAAPI_WRAPPER_H_
#define MEDIA_GPU_VAAPI_TEST_H265_VAAPI_WRAPPER_H_
#include "base/containers/span.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "media/gpu/vaapi/test/h265_dpb.h"
#include "media/gpu/vaapi/test/scoped_va_config.h"
#include "media/gpu/vaapi/test/scoped_va_context.h"
#include "media/gpu/vaapi/test/vaapi_device.h"
#include "media/parsers/h265_parser.h"
namespace media::vaapi_test {
class H265VaapiWrapper {
public:
explicit H265VaapiWrapper(const VaapiDevice& va_device);
H265VaapiWrapper(const H265VaapiWrapper&) = delete;
H265VaapiWrapper& operator=(const H265VaapiWrapper&) = delete;
~H265VaapiWrapper();
scoped_refptr<H265Picture> CreateH265Picture(const H265SPS* sps);
bool SubmitFrameMetadata(const H265SPS* sps,
const H265PPS* pps,
const H265SliceHeader* slice_hdr,
const H265Picture::Vector& ref_pic_list,
scoped_refptr<H265Picture> pic);
bool SubmitSlice(const H265SPS* sps,
const H265PPS* pps,
const H265SliceHeader* slice_hdr,
const H265Picture::Vector& ref_pic_list0,
const H265Picture::Vector& ref_pic_list1,
const H265Picture::Vector& ref_pic_set_lt_curr,
const H265Picture::Vector& ref_pic_set_st_curr_after,
const H265Picture::Vector& ref_pic_set_st_curr_before,
scoped_refptr<H265Picture> pic,
const uint8_t* data,
size_t size,
const std::vector<SubsampleEntry>& subsamples);
bool SubmitDecode(scoped_refptr<H265Picture> pic);
void Reset();
bool IsChromaSamplingSupported(VideoChromaSampling chroma_sampling);
private:
void FillVAPicture(VAPictureHEVC* va_pic, scoped_refptr<H265Picture> pic);
void FillVARefFramesFromRefList(const H265Picture::Vector& ref_pic_list,
base::span<VAPictureHEVC> va_pics);
int GetRefPicIndex(int poc);
bool SubmitPriorSliceDataIfPresent(bool last_slice);
static VAProfile GetProfile(const H265SPS* sps);
unsigned int GetFormatForProfile(const VAProfile& profile);
[[nodiscard]] bool SubmitBuffer(VABufferType va_buffer_type,
size_t size,
const void* data);
template <typename T>
[[nodiscard]] bool SubmitBuffer(VABufferType va_buffer_type, const T* data) {
return SubmitBuffer(va_buffer_type, sizeof(T), data);
}
struct VABufferDescriptor {
VABufferType type;
size_t size;
raw_ptr<const void> data;
};
[[nodiscard]] bool SubmitBuffers(
const std::vector<VABufferDescriptor>& va_buffers);
void DestroyPendingBuffers();
[[nodiscard]] bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id);
std::vector<int> ref_pic_list_pocs_;
VASliceParameterBufferHEVC slice_param_;
std::vector<uint8_t> last_slice_data_;
std::vector<VABufferID> pending_buffers_;
const raw_ref<const VaapiDevice> va_device_;
std::unique_ptr<ScopedVAConfig> va_config_;
std::unique_ptr<ScopedVAContext> va_context_;
};
}
#endif