Lavd: Add videotoolbox decoding

This commit is contained in:
Martin Piatka
2021-08-05 14:35:10 +02:00
parent 8f557a97d6
commit 7d2c836d9a
4 changed files with 56 additions and 2 deletions

View File

@@ -1674,6 +1674,10 @@ then
lavc_hwacc_common=yes
fi
if test $system = MacOSX; then
lavc_hwacc_common=yes
fi
if test $lavc_hwacc_common = yes
then
LAVC_HWACC_FLAGS="${LAVC_HWACC_FLAGS} -DHWACC_COMMON"

View File

@@ -110,7 +110,8 @@ int create_hw_frame_ctx(AVBufferRef *device_ref,
if (ret < 0) {
av_buffer_unref(ctx);
*ctx = NULL;
log_msg(LOG_LEVEL_ERROR, "[hw accel] Unable to init hwframe_ctx!!\n\n");
log_msg(LOG_LEVEL_ERROR, "[hw accel] Unable to init hwframe_ctx: %s\n\n",
av_err2str(ret));
return ret;
}

View File

@@ -64,7 +64,8 @@ struct hw_accel_state {
enum {
HWACCEL_NONE,
HWACCEL_VDPAU,
HWACCEL_VAAPI
HWACCEL_VAAPI,
HWACCEL_VIDEOTOOLBOX
} type;
bool copy; ///< Specifies whether to use the copy mode

View File

@@ -448,6 +448,51 @@ static bool has_conversion(enum AVPixelFormat pix_fmt, codec_t *ug_pix_fmt) {
return false;
}
#if HAVE_MACOSX
int videotoolbox_init(struct AVCodecContext *s,
struct hw_accel_state *state,
codec_t out_codec)
{
AVBufferRef *device_ref = NULL;
int ret = create_hw_device_ctx(AV_HWDEVICE_TYPE_VIDEOTOOLBOX, &device_ref);
if(ret < 0)
return ret;
AVBufferRef *hw_frames_ctx = NULL;
ret = create_hw_frame_ctx(device_ref,
s->coded_width,
s->coded_height,
AV_PIX_FMT_VIDEOTOOLBOX,
s->sw_pix_fmt,
0, //has to be 0, ffmpeg can't allocate frames by itself
&hw_frames_ctx);
if(ret < 0)
goto fail;
AVFrame *frame = av_frame_alloc();
if(!frame){
ret = -1;
goto fail;
}
state->type = HWACCEL_VIDEOTOOLBOX;
state->copy = true;
state->tmp_frame = frame;
s->hw_frames_ctx = hw_frames_ctx;
s->hw_device_ctx = device_ref;
return 0;
fail:
av_frame_free(&state->tmp_frame);
av_buffer_unref(&device_ref);
av_buffer_unref(&hw_frames_ctx);
return ret;
}
#endif
static enum AVPixelFormat get_format_callback(struct AVCodecContext *s __attribute__((unused)), const enum AVPixelFormat *fmt)
{
if (log_level >= LOG_LEVEL_VERBOSE) {
@@ -474,6 +519,9 @@ static enum AVPixelFormat get_format_callback(struct AVCodecContext *s __attribu
#endif
#ifdef HWACC_VAAPI
{AV_PIX_FMT_VAAPI, vaapi_init}
#endif
#ifdef HAVE_MACOSX
{AV_PIX_FMT_VIDEOTOOLBOX, videotoolbox_init}
#endif
};