Add hardware decoding support

This commit is contained in:
2026-07-13 10:19:30 +08:00
parent f6211f97a5
commit 68c0477715
6 changed files with 404 additions and 38 deletions
+25
View File
@@ -29,6 +29,7 @@ extern "C" {
#include <libavcodec/avcodec.h>
#include <libavfilter/avfilter.h>
#include <libavformat/avformat.h>
#include <libavutil/hwcontext.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
}
@@ -131,11 +132,33 @@ private:
return codec_ctx_;
}
bool hwaccel_enabled() const
{
return hwaccel_enabled_;
}
AVPixelFormat hw_pix_fmt() const
{
return hw_pix_fmt_;
}
private:
static AVHWDeviceType ChooseHardwareDevice();
static AVPixelFormat GetHardwareFormat(AVCodecContext *ctx,
const AVPixelFormat *pix_fmts);
bool InitHardwareAcceleration(const AVCodec *codec);
void CleanupHardwareAcceleration();
AVFormatContext *fmt_ctx_;
AVCodecContext *codec_ctx_;
AVStream *avstream_;
AVDictionary *opts_;
AVBufferRef *hw_device_ctx_;
AVHWDeviceType hw_device_type_;
AVPixelFormat hw_pix_fmt_;
bool hwaccel_enabled_;
};
/**
@@ -150,6 +173,8 @@ private:
void FreeScaler();
AVFramePtr TransferHardwareFrame(AVFramePtr f);
static PixelFormat GetNativePixelFormat(AVPixelFormat pix_fmt);
static int GetNativeChannelCount(AVPixelFormat pix_fmt);