1 #ifndef AVHwDecoder_HEADER_GUARD
2 #define AVHwDecoder_HEADER_GUARD
38 #include <libavutil/hwcontext.h>
42 static enum AVPixelFormat find_fmt_by_hw_type(
const enum AVHWDeviceType type)
44 enum AVPixelFormat fmt;
46 case AV_HWDEVICE_TYPE_VAAPI:
47 fmt = AV_PIX_FMT_VAAPI;
49 case AV_HWDEVICE_TYPE_DXVA2:
50 fmt = AV_PIX_FMT_DXVA2_VLD;
52 case AV_HWDEVICE_TYPE_D3D11VA:
53 fmt = AV_PIX_FMT_D3D11;
55 case AV_HWDEVICE_TYPE_VDPAU:
56 fmt = AV_PIX_FMT_VDPAU;
58 case AV_HWDEVICE_TYPE_VIDEOTOOLBOX:
59 fmt = AV_PIX_FMT_VIDEOTOOLBOX;
62 fmt = AV_PIX_FMT_NONE;
68 static enum AVPixelFormat get_vaapi_format(AVCodecContext *ctx,
69 const enum AVPixelFormat *pix_fmts)
74 const enum AVPixelFormat *p;
76 for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
79 case AV_PIX_FMT_VAAPI_MOCO:
82 case AV_PIX_FMT_VAAPI_IDCT:
91 case AV_PIX_FMT_YUVJ420P:
98 case AV_PIX_FMT_VAAPI:
103 avthreadlogger.log(LogLevel::fatal) <<
"hwdecoder.h : get_vaapi_format : Unable to decode this stream using VA-API" << std::endl;
106 return AV_PIX_FMT_NONE;
143 AVPixelFormat hw_pix_format;
147 virtual void flush();
163 AVFrame *aux_av_frame;
164 AVPixelFormat current_pixel_format;
166 float secs_per_frame;
180 av_always_inline std::string av_err2string(
int errnum) {
181 char str[AV_ERROR_MAX_STRING_SIZE];
182 return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum);
184 #define av_err2str(err) av_err2string(err).c_str()
Decoded YUV/RGB frame in FFMpeg format.
Definition: frame.h:361
Video decoder using FFmpeg/libav with VAAPI.
Definition: hwdecoder.h:126
AVPacket * av_packet
FFmpeg internal data structure; encoded frame (say, H264)
Definition: hwdecoder.h:138
AVCodec * av_codec
FFmpeg internal data structure.
Definition: hwdecoder.h:140
AVBufferRef * hw_device_ctx
FFmpeg/libav hardware context.
Definition: hwdecoder.h:141
virtual ~AVHwDecoder()
Default destructor.
Definition: hwdecoder.cpp:145
AVCodecID av_codec_id
FFmpeg AVCodecId, identifying the codec.
Definition: hwdecoder.h:137
virtual void flush()
Reset decoder state. How to flush depends on the decoder library.
Definition: hwdecoder.cpp:162
AVCodecContext * av_codec_context
FFmpeg internal data structure.
Definition: hwdecoder.h:139
AVHwDecoder(AVCodecID av_codec_id, AVHWDeviceType hwtype, int n_threads=1)
Default constructor.
Definition: hwdecoder.cpp:52
virtual bool isOk()
The thread that uses this decoder can check if it has gone sour.
Definition: hwdecoder.cpp:167
A Virtual class for decoders.
Definition: decoder.h:62
Frame: An abstract queueable class.
Definition: frame.h:112
Definition: hwdecoder.h:153
HwVideoDecoder(AVCodecID av_codec_id, AVHWDeviceType hwtype, int n_threads=1)
Default constructor.
Definition: hwdecoder.cpp:172
virtual Frame * output()
Return a reference to the internal storage of the decoder where the decoded frame is.
Definition: hwdecoder.cpp:189
virtual ~HwVideoDecoder()
Default destructor.
Definition: hwdecoder.cpp:178
virtual bool pull()
Decode in_frame to out_frame. Return true if decoder returned a new frame (into out_frame),...
Definition: hwdecoder.cpp:194