1 /*****************************************************************************
2 * va.c: hardware acceleration plugins for avcodec
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
5 * Copyright (C) 2012-2013 RĂ©mi Denis-Courmont
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
26 #include <vlc_common.h>
27 #include <vlc_modules.h>
28 #include <vlc_fourcc.h>
29 #include <libavutil/pixfmt.h>
30 #include <libavcodec/avcodec.h>
33 vlc_fourcc_t
vlc_va_GetChroma(enum PixelFormat hwfmt
, enum PixelFormat swfmt
)
35 /* NOTE: At the time of writing this comment, the return value was only
36 * used to probe support as decoder output. So incorrect values were not
37 * fatal, especially not if a software format. */
40 case AV_PIX_FMT_VAAPI_VLD
:
41 return VLC_CODEC_YV12
;
43 case AV_PIX_FMT_DXVA2_VLD
:
46 case AV_PIX_FMT_YUV420P10LE
:
47 return VLC_CODEC_D3D9_OPAQUE_10B
;
49 return VLC_CODEC_D3D9_OPAQUE
;
53 #if LIBAVUTIL_VERSION_CHECK(54, 13, 1, 24, 100)
54 case AV_PIX_FMT_D3D11VA_VLD
:
57 case AV_PIX_FMT_YUV420P10LE
:
58 return VLC_CODEC_D3D11_OPAQUE_10B
;
60 return VLC_CODEC_D3D11_OPAQUE
;
64 #if (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(53, 14, 0))
66 return VLC_CODEC_I420
;
68 #if (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(52, 4, 0))
69 case AV_PIX_FMT_VDPAU
:
72 case AV_PIX_FMT_YUVJ444P
:
73 case AV_PIX_FMT_YUV444P
:
74 return VLC_CODEC_VDPAU_VIDEO_444
;
75 case AV_PIX_FMT_YUVJ422P
:
76 case AV_PIX_FMT_YUV422P
:
77 return VLC_CODEC_VDPAU_VIDEO_422
;
78 case AV_PIX_FMT_YUVJ420P
:
79 case AV_PIX_FMT_YUV420P
:
80 return VLC_CODEC_VDPAU_VIDEO_420
;
91 static int vlc_va_Start(void *func
, va_list ap
)
93 vlc_va_t
*va
= va_arg(ap
, vlc_va_t
*);
94 AVCodecContext
*ctx
= va_arg(ap
, AVCodecContext
*);
95 enum PixelFormat pix_fmt
= va_arg(ap
, enum PixelFormat
);
96 const es_format_t
*fmt
= va_arg(ap
, const es_format_t
*);
97 picture_sys_t
*p_sys
= va_arg(ap
, picture_sys_t
*);
98 int (*open
)(vlc_va_t
*, AVCodecContext
*, enum PixelFormat
,
99 const es_format_t
*, picture_sys_t
*) = func
;
101 return open(va
, ctx
, pix_fmt
, fmt
, p_sys
);
104 static void vlc_va_Stop(void *func
, va_list ap
)
106 vlc_va_t
*va
= va_arg(ap
, vlc_va_t
*);
107 AVCodecContext
*ctx
= va_arg(ap
, AVCodecContext
*);
108 void (*close
)(vlc_va_t
*, AVCodecContext
*) = func
;
113 vlc_va_t
*vlc_va_New(vlc_object_t
*obj
, AVCodecContext
*avctx
,
114 enum PixelFormat pix_fmt
, const es_format_t
*fmt
,
115 picture_sys_t
*p_sys
)
117 vlc_va_t
*va
= vlc_object_create(obj
, sizeof (*va
));
118 if (unlikely(va
== NULL
))
121 va
->module
= vlc_module_load(va
, "hw decoder", "$avcodec-hw", true,
122 vlc_va_Start
, va
, avctx
, pix_fmt
, fmt
, p_sys
);
123 if (va
->module
== NULL
)
125 vlc_object_release(va
);
131 vlc_fourcc_t expected
= vlc_va_GetChroma( pix_fmt
, avctx
->sw_pix_fmt
);
132 va
->setup(va
, &chroma
);
133 if (chroma
!= expected
)
134 { /* Mismatch, cannot work, fail */
135 msg_Dbg( obj
, "chroma mismatch %4.4s expected %4.4s",
136 (const char*)&chroma
, (const char*) &expected
);
137 vlc_va_Delete(va
, avctx
);
144 void vlc_va_Delete(vlc_va_t
*va
, AVCodecContext
*avctx
)
146 vlc_module_unload(va
->module
, vlc_va_Stop
, va
, avctx
);
147 vlc_object_release(va
);