#ifndef MEDIA_GPU_VAAPI_TEST_AV1_DECODER_H_
#define MEDIA_GPU_VAAPI_TEST_AV1_DECODER_H_
#include <memory>
#include <optional>
#include <vector>
#include "base/memory/raw_ptr_exclusion.h"
#include "media/gpu/vaapi/test/video_decoder.h"
#include "media/parsers/ivf_parser.h"
#include "third_party/libgav1/src/src/obu_parser.h"
namespace media {
namespace vaapi_test {
class ScopedVAConfig;
class ScopedVAContext;
class SharedVASurface;
class VaapiDevice;
constexpr size_t kAv1NumRefFrames = libgav1::kNumReferenceFrameTypes;
class Av1Decoder : public VideoDecoder {
public:
Av1Decoder(std::unique_ptr<IvfParser> ivf_parser,
const VaapiDevice& va_device,
SharedVASurface::FetchPolicy fetch_policy);
Av1Decoder(const Av1Decoder&) = delete;
Av1Decoder& operator=(const Av1Decoder&) = delete;
~Av1Decoder() override;
VideoDecoder::Result DecodeNextFrame() override;
private:
enum class ParsingResult {
kFailed,
kOk,
kEOStream,
};
ParsingResult ReadNextFrame(libgav1::RefCountedBufferPtr& current_frame);
void RefreshReferenceSlots(uint8_t refresh_frame_flags,
scoped_refptr<SharedVASurface> surface,
libgav1::RefCountedBufferPtr current_frame,
scoped_refptr<SharedVASurface> display_surface);
IvfFrameHeader ivf_frame_header_{};
raw_ptr<const uint8_t> ivf_frame_data_ = nullptr;
std::unique_ptr<ScopedVAConfig> va_config_;
std::unique_ptr<ScopedVAContext> va_context_;
std::unique_ptr<libgav1::ObuParser> obu_parser_;
std::unique_ptr<libgav1::BufferPool> buffer_pool_;
std::unique_ptr<libgav1::DecoderState> state_;
std::optional<libgav1::ObuSequenceHeader> current_sequence_header_;
std::vector<scoped_refptr<SharedVASurface>> ref_frames_;
std::vector<scoped_refptr<SharedVASurface>> display_surfaces_;
const std::unique_ptr<IvfParser> ivf_parser_;
};
}
}
#endif