[vlc-devel] [PATCH 1/5] va: try to output an opaque chroma first, then a plane-based one
Steve Lhomme
robux4 at gmail.com
Mon Jun 1 15:58:04 CEST 2015
---
modules/codec/avcodec/dxva2.c | 2 +-
modules/codec/avcodec/va.h | 7 ++++---
modules/codec/avcodec/vaapi.c | 3 ++-
modules/codec/avcodec/vda.c | 3 ++-
modules/codec/avcodec/video.c | 32 ++++++++++++++++++++++++++------
modules/hw/vdpau/avcodec.c | 3 ++-
6 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 9b002c3..3db903f 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -153,7 +153,7 @@ static int DxResetVideoDecoder(vlc_va_t *);
static void SetupAVCodecContext(vlc_va_t *);
/* */
-static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chroma)
+static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chroma, bool b_opaque)
{
vlc_va_sys_t *sys = va->sys;
if (directx_va_Setup(va, &sys->dx_sys, avctx, chroma)!=VLC_SUCCESS)
diff --git a/modules/codec/avcodec/va.h b/modules/codec/avcodec/va.h
index 5c4b11d..5a7ba7e 100644
--- a/modules/codec/avcodec/va.h
+++ b/modules/codec/avcodec/va.h
@@ -36,7 +36,7 @@ struct vlc_va_t {
module_t *module;
const char *description;
- int (*setup)(vlc_va_t *, AVCodecContext *, vlc_fourcc_t *output);
+ int (*setup)(vlc_va_t *, AVCodecContext *, vlc_fourcc_t *output, bool b_opaque);
int (*get)(vlc_va_t *, picture_t *pic, uint8_t **data);
void (*release)(void *pic, uint8_t *surface);
int (*extract)(vlc_va_t *, picture_t *pic, uint8_t *data);
@@ -65,12 +65,13 @@ vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *,
* Initializes the acceleration video decoding back-end for libavcodec.
* @param avctx libavcodec codec context
* @param output pointer to video chroma output by the back-end [OUT]
+ * @param b_opaque whether an opaque chroma output is allowed or not[IN]
* @return VLC_SUCCESS on success, otherwise an error code.
*/
static inline int vlc_va_Setup(vlc_va_t *va, AVCodecContext *avctx,
- vlc_fourcc_t *output)
+ vlc_fourcc_t *output, bool b_opaque)
{
- return va->setup(va, avctx, output);
+ return va->setup(va, avctx, output, b_opaque);
}
/**
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index 4683648..1f09616 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -187,8 +187,9 @@ static void Release( void *opaque, uint8_t *data )
(void) data;
}
-static int Setup( vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *pi_chroma )
+static int Setup( vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *pi_chroma, bool b_opaque )
{
+ VLC_UNUSED(b_opaque);
vlc_va_sys_t *sys = va->sys;
if (sys->width != avctx->coded_width || sys->height != avctx->coded_height)
diff --git a/modules/codec/avcodec/vda.c b/modules/codec/avcodec/vda.c
index 6f8105d..a4d67db 100644
--- a/modules/codec/avcodec/vda.c
+++ b/modules/codec/avcodec/vda.c
@@ -169,8 +169,9 @@ static void Close( vlc_va_t *va, AVCodecContext *ctx )
(void) ctx;
}
-static int Setup( vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *pi_chroma )
+static int Setup( vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *pi_chroma, bool b_opaque )
{
+ VLC_UNUSED(b_opaque);
vlc_va_vda_t *p_vda = vlc_va_vda_Get( va );
if( p_vda->hw_ctx.width == avctx->coded_width
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index b603457..62a1afa 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -77,6 +77,8 @@ struct decoder_sys_t
/* VA API */
vlc_va_t *p_va;
+ /* using an opaque output */
+ bool b_opaque;
vlc_sem_t sem_mt;
};
@@ -1055,7 +1057,7 @@ static int lavc_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, int flags)
wait_mt(sys);
if (sys->p_va != NULL)
{ /* TODO: Move this to get_format(). We are screwed if it fails here. */
- if (vlc_va_Setup(sys->p_va, ctx, &dec->fmt_out.video.i_chroma))
+ if (vlc_va_Setup(sys->p_va, ctx, &dec->fmt_out.video.i_chroma, sys->b_opaque))
{
post_mt(sys);
msg_Err(dec, "hardware acceleration setup failed");
@@ -1122,11 +1124,29 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
for( size_t i = 0; pi_fmt[i] != PIX_FMT_NONE; i++ )
{
enum PixelFormat hwfmt = pi_fmt[i];
+ bool b_found = false;
- p_dec->fmt_out.video.i_chroma = vlc_va_GetChroma(hwfmt, swfmt);
- if (p_dec->fmt_out.video.i_chroma == 0)
- continue; /* Unknown brand of hardware acceleration */
- if (lavc_UpdateVideoFormat(p_dec, p_context, true))
+ /* first try full hardware */
+ p_sys->b_opaque = true;
+ p_dec->fmt_out.video.i_chroma = vlc_va_GetChroma(hwfmt, hwfmt);
+ if (p_dec->fmt_out.video.i_chroma != 0)
+ {
+ if (!lavc_UpdateVideoFormat(p_dec, p_context, true))
+ b_found = true;
+ }
+
+ if (!b_found)
+ {
+ p_sys->b_opaque = false;
+ p_dec->fmt_out.video.i_chroma = vlc_va_GetChroma(hwfmt, swfmt);
+ if (p_dec->fmt_out.video.i_chroma != 0)
+ {
+ if (!lavc_UpdateVideoFormat(p_dec, p_context, true))
+ b_found = true;
+ }
+ }
+
+ if (!b_found)
continue; /* Unsupported brand of hardware acceleration */
picture_t *test_pic = decoder_NewPicture(p_dec);
@@ -1142,7 +1162,7 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
/* We try to call vlc_va_Setup when possible to detect errors when
* possible (later is too late) */
if( p_context->width > 0 && p_context->height > 0
- && vlc_va_Setup(va, p_context, &p_dec->fmt_out.video.i_chroma))
+ && vlc_va_Setup(va, p_context, &p_dec->fmt_out.video.i_chroma, p_sys->b_opaque))
{
msg_Err( p_dec, "acceleration setup failure" );
vlc_va_Delete(va, p_context);
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index 6a3b67e..072971c 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -140,8 +140,9 @@ static int Copy(vlc_va_t *va, picture_t *pic, uint8_t *data)
return VLC_SUCCESS;
}
-static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chromap)
+static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chromap, bool b_opaque)
{
+ VLC_UNUSED(b_opaque);
vlc_va_sys_t *sys = va->sys;
VdpChromaType type;
uint32_t width, height;
--
2.4.0
More information about the vlc-devel
mailing list