[vlc-commits] [Git][videolan/vlc][master] avcodec: fix av1 hardware decoding not being used even when it is available
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Jul 24 13:20:55 UTC 2026
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
903ff616 by Wassim Lalaoui at 2026-07-24T13:11:12+00:00
avcodec: fix av1 hardware decoding not being used even when it is available
- - - - -
5 changed files:
- modules/codec/avcodec/audio.c
- modules/codec/avcodec/avcodec.c
- modules/codec/avcodec/avcodec.h
- modules/codec/avcodec/subtitle.c
- modules/codec/avcodec/video.c
Changes:
=====================================
modules/codec/avcodec/audio.c
=====================================
@@ -243,7 +243,7 @@ int InitAudioDec( vlc_object_t *obj )
{
decoder_t *p_dec = (decoder_t *)obj;
const AVCodec *codec;
- AVCodecContext *avctx = ffmpeg_AllocContext( p_dec, &codec );
+ AVCodecContext *avctx = ffmpeg_AllocContext( p_dec, &codec, false );
if( avctx == NULL )
return VLC_EGENERIC;
=====================================
modules/codec/avcodec/avcodec.c
=====================================
@@ -221,8 +221,26 @@ vlc_module_begin ()
#endif
vlc_module_end ()
+static const AVCodec *FindHwCapableDecoder(enum AVCodecID codec_id)
+{
+ void *iter = NULL;
+
+ const AVCodec *codec = av_codec_iterate(&iter);
+ while (codec != NULL)
+ {
+ if (codec->id == codec_id && av_codec_is_decoder(codec))
+ {
+ if (avcodec_get_hw_config(codec, 0) != NULL)
+ return codec;
+ }
+ codec = av_codec_iterate(&iter);
+ }
+ return NULL;
+}
+
AVCodecContext *ffmpeg_AllocContext( decoder_t *p_dec,
- const AVCodec **restrict codecp )
+ const AVCodec **restrict codecp,
+ bool b_require_hw_codec)
{
enum AVCodecID i_codec_id;
const char *psz_namecodec;
@@ -253,7 +271,9 @@ AVCodecContext *ffmpeg_AllocContext( decoder_t *p_dec,
}
free( psz_decoder );
}
- if( !p_codec )
+ if( !p_codec && b_require_hw_codec )
+ p_codec = FindHwCapableDecoder( i_codec_id );
+ else if ( !p_codec )
p_codec = avcodec_find_decoder( i_codec_id );
if( !p_codec )
{
=====================================
modules/codec/avcodec/avcodec.h
=====================================
@@ -47,7 +47,7 @@ int InitSubtitleDec( vlc_object_t * );
void EndSubtitleDec( vlc_object_t * );
/* Initialize decoder */
-AVCodecContext *ffmpeg_AllocContext( decoder_t *, const AVCodec ** );
+AVCodecContext *ffmpeg_AllocContext( decoder_t *, const AVCodec **, bool );
int ffmpeg_OpenCodec( decoder_t *p_dec, AVCodecContext *, const AVCodec * );
/*****************************************************************************
=====================================
modules/codec/avcodec/subtitle.c
=====================================
@@ -57,7 +57,7 @@ int InitSubtitleDec(vlc_object_t *obj)
{
decoder_t *dec = (decoder_t *)obj;
const AVCodec *codec;
- AVCodecContext *context = ffmpeg_AllocContext(dec, &codec);
+ AVCodecContext *context = ffmpeg_AllocContext(dec, &codec, false);
if (context == NULL)
return VLC_EGENERIC;
=====================================
modules/codec/avcodec/video.c
=====================================
@@ -916,7 +916,7 @@ int InitVideoHwDec( vlc_object_t *obj )
return VLC_ENOMEM;
const AVCodec *p_codec;
- AVCodecContext *p_context = ffmpeg_AllocContext( p_dec, &p_codec );
+ AVCodecContext *p_context = ffmpeg_AllocContext( p_dec, &p_codec, true );
if( unlikely(p_context == NULL) )
{
free(p_sys);
@@ -974,7 +974,7 @@ int InitVideoDec( vlc_object_t *obj )
{
decoder_t *p_dec = (decoder_t *)obj;
const AVCodec *p_codec;
- AVCodecContext *p_context = ffmpeg_AllocContext( p_dec, &p_codec );
+ AVCodecContext *p_context = ffmpeg_AllocContext( p_dec, &p_codec, false );
if( p_context == NULL )
return VLC_EGENERIC;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/903ff61665479c3901e2438c572488ed7c85498e
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/903ff61665479c3901e2438c572488ed7c85498e
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list