Skip to content

Commit

Permalink
lavd: Add drm-prime hwaccel support
Browse files Browse the repository at this point in the history
Currently only in copy mode. This works for the Raspberry Pi 4 HEVC decoder when using a fork of ffmpeg that supports v4l2-request hwaccel.
  • Loading branch information
mpiatka committed Mar 6, 2024
1 parent 30eab46 commit 27f552c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/hwaccel_libav_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ static const struct {
{ "vaapi", HWACCEL_VAAPI, AV_PIX_FMT_VAAPI, 0 },
{ "videotoolbox", HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX, 0 },
{ "cuda", HWACCEL_CUDA, AV_PIX_FMT_CUDA, 0 },
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 75, 100)
{ "drm-prime", HWACCEL_DRM_PRIME, AV_PIX_FMT_DRM_PRIME, 0 },
#endif
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 39, 100)
{ "vulkan", HWACCEL_VULKAN, AV_PIX_FMT_VULKAN, 0 },
#endif
Expand Down
1 change: 1 addition & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ enum hw_accel_type {
HWACCEL_VIDEOTOOLBOX,
HWACCEL_CUDA,
HWACCEL_VULKAN,
HWACCEL_DRM_PRIME,
HWACCEL_COUNT
};

Expand Down
26 changes: 26 additions & 0 deletions src/video_decompress/libavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,29 @@ static int libavcodec_decompress_reconfigure(void *state, struct video_desc desc
return configure_with(s, desc, NULL, 0);
}

#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 75, 100)
static int drm_prime_init(struct AVCodecContext *s,
struct hw_accel_state *state,
codec_t out_codec)
{
UNUSED(s), UNUSED(out_codec);
state->type = HWACCEL_DRM_PRIME;
AVBufferRef *ref = NULL;
int ret = create_hw_device_ctx(AV_HWDEVICE_TYPE_DRM, &ref);
if(ret < 0)
return ret;

s->hw_device_ctx = ref;
state->copy = true;
state->tmp_frame = av_frame_alloc();
if(!state->tmp_frame){
av_buffer_unref(&ref);
return -1;
}
return 0;
}
#endif

#if defined HWACC_COMMON_IMPL && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 39, 100)
static int vulkan_init(struct AVCodecContext *s,
struct hw_accel_state *state,
Expand Down Expand Up @@ -596,6 +619,9 @@ static enum AVPixelFormat get_format_callback(struct AVCodecContext *s, const en
#endif
#ifdef HAVE_MACOSX
{AV_PIX_FMT_VIDEOTOOLBOX, videotoolbox_init},
#endif
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 75, 100)
{AV_PIX_FMT_DRM_PRIME, drm_prime_init},
#endif
{AV_PIX_FMT_NONE, NULL}
};
Expand Down

0 comments on commit 27f552c

Please sign in to comment.