[vlc-devel] [PATCH 2/8] avcodec: va: move the picture query in the va creation
Steve Lhomme
robux4 at videolabs.io
Fri May 5 18:42:18 CEST 2017
Theoretically we could not pick a picture and assume in the VA module that the
parent is always a decoder_t and pick it when needed.
---
modules/codec/avcodec/va.c | 24 ++++++++++++++++--------
modules/codec/avcodec/va.h | 7 +++----
modules/codec/avcodec/video.c | 8 +-------
3 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/modules/codec/avcodec/va.c b/modules/codec/avcodec/va.c
index de10736013..7f7f192933 100644
--- a/modules/codec/avcodec/va.c
+++ b/modules/codec/avcodec/va.c
@@ -26,6 +26,7 @@
#include <vlc_common.h>
#include <vlc_modules.h>
#include <vlc_fourcc.h>
+#include <vlc_codec.h>
#include <libavutil/pixfmt.h>
#include <libavcodec/avcodec.h>
#include "va.h"
@@ -106,21 +107,25 @@ static void vlc_va_Stop(void *func, va_list ap)
close(va, ctx);
}
-vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
- enum PixelFormat pix_fmt, const es_format_t *fmt,
- picture_sys_t *p_sys)
+vlc_va_t *vlc_va_New(decoder_t *p_dec, AVCodecContext *avctx,
+ enum PixelFormat pix_fmt, const es_format_t *fmt)
{
- vlc_va_t *va = vlc_object_create(obj, sizeof (*va));
+ picture_t *test_pic = decoder_NewPicture(p_dec);
+ assert(!test_pic || test_pic->format.i_chroma == p_dec->fmt_out.video.i_chroma);
+
+ vlc_va_t *va = vlc_object_create(p_dec, sizeof (*va));
if (unlikely(va == NULL))
- return NULL;
+ goto done;
va->module = vlc_module_load(va, "hw decoder", "$avcodec-hw", true,
- vlc_va_Start, va, avctx, pix_fmt, fmt, p_sys);
+ vlc_va_Start, va, avctx, pix_fmt, fmt,
+ test_pic ? test_pic->p_sys : NULL);
if (va->module == NULL)
{
vlc_object_release(va);
+ va = NULL;
#ifdef _WIN32
- return NULL;
+ goto done;
}
vlc_fourcc_t chroma;
@@ -128,12 +133,15 @@ vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
va->setup(va, &chroma);
if (chroma != expected)
{ /* Mismatch, cannot work, fail */
- msg_Dbg( obj, "chroma mismatch %4.4s expected %4.4s",
+ msg_Dbg( p_dec, "chroma mismatch %4.4s expected %4.4s",
(const char*)&chroma, (const char*) &expected );
vlc_va_Delete(va, avctx);
#endif
va = NULL;
}
+done:
+ if (test_pic)
+ picture_Release(test_pic);
return va;
}
diff --git a/modules/codec/avcodec/va.h b/modules/codec/avcodec/va.h
index ec70e389ba..4e5b683f21 100644
--- a/modules/codec/avcodec/va.h
+++ b/modules/codec/avcodec/va.h
@@ -56,13 +56,12 @@ vlc_fourcc_t vlc_va_GetChroma(enum PixelFormat hwfmt, enum PixelFormat swfmt);
/**
* Creates an accelerated video decoding back-end for libavcodec.
- * @param obj parent VLC object
+ * @param dec decoder object it will belong to
* @param fmt VLC format of the content to decode
* @return a new VLC object on success, NULL on error.
*/
-vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *,
- enum PixelFormat, const es_format_t *fmt,
- picture_sys_t *p_sys);
+vlc_va_t *vlc_va_New(decoder_t *dec, AVCodecContext *,
+ enum PixelFormat, const es_format_t *fmt);
/**
* Allocates a hardware video surface for a libavcodec frame.
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index e487c22d1d..e5640d4cd7 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -420,13 +420,7 @@ static int SetupHardwareFormat(decoder_t *p_dec, AVCodecContext *p_context,
post_mt(p_dec->p_sys);
- picture_t *test_pic = decoder_NewPicture(p_dec);
- assert(!test_pic || test_pic->format.i_chroma == p_dec->fmt_out.video.i_chroma);
- vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, hwfmt,
- &p_dec->fmt_in,
- test_pic ? test_pic->p_sys : NULL);
- if ( test_pic )
- picture_Release( test_pic );
+ vlc_va_t *va = vlc_va_New(p_dec, p_context, hwfmt, &p_dec->fmt_in);
if (va == NULL)
{
wait_mt(p_dec->p_sys);
--
2.12.1
More information about the vlc-devel
mailing list