mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-22 06:40:26 +00:00
Lavd: Add videotoolbox decoding
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user