1 /*****************************************************************************
2 * va.h: Video Acceleration API for avcodec
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
7 * Authors: Laurent Aimar <fenrir_AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_AVCODEC_VA_H
25 #define VLC_AVCODEC_VA_H 1
27 typedef struct vlc_va_t vlc_va_t;
28 typedef struct vlc_va_sys_t vlc_va_sys_t;
35 const char *description;
38 int (*setup)(vlc_va_t *, AVCodecContext *, vlc_fourcc_t *output);
39 int (*get)(vlc_va_t *, void **opaque, uint8_t **data);
40 void (*release)(void *opaque, uint8_t *surface);
41 int (*extract)(vlc_va_t *, picture_t *dst, void *opaque, uint8_t *data);
45 * Creates an accelerated video decoding back-end for libavcodec.
46 * @param obj parent VLC object
47 * @param fmt VLC format of the content to decode
48 * @return a new VLC object on success, NULL on error.
50 vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *, const es_format_t *fmt);
53 * Initializes the acceleration video decoding back-end for libavcodec.
54 * @param avctx libavcodec codec context
55 * @param output pointer to video chroma output by the back-end [OUT]
56 * @return VLC_SUCCESS on success, otherwise an error code.
58 static inline int vlc_va_Setup(vlc_va_t *va, AVCodecContext *avctx,
61 return va->setup(va, avctx, output);
65 * Allocates a hardware video surface for a libavcodec frame.
66 * The surface will be used as output for the hardware decoder, and possibly
67 * also as a reference frame to decode other surfaces.
69 * @param opaque pointer to storage space for surface internal data [OUT]
70 * @param data pointer to the AVFrame data[0] and data[3] pointers [OUT]
72 * @note This function needs not be reentrant. However it may be called
73 * concurrently with vlc_va_Extract() and/or vlc_va_Release() from other
74 * threads and other frames.
76 * @param frame libavcodec frame [IN/OUT]
77 * @return VLC_SUCCESS on success, otherwise an error code.
79 static inline int vlc_va_Get(vlc_va_t *va, void **opaque, uint8_t **data)
81 return va->get(va, opaque, data);
85 * Releases a hardware surface from a libavcodec frame.
86 * The surface has been previously allocated with vlc_va_Get().
88 * @param opaque opaque data pointer of the AVFrame set by vlc_va_Get()
89 * @param data data[0] pointer of the AVFrame set by vlc_va_Get()
91 * @note This function needs not be reentrant. However it may be called
92 * concurrently with vlc_va_Get() and/or vlc_va_Extract() from other threads
95 * @param frame libavcodec frame previously allocated by vlc_va_Get()
97 static inline void vlc_va_Release(vlc_va_t *va, void *opaque, uint8_t *data)
99 va->release(opaque, data);
103 * Extracts a hardware surface from a libavcodec frame into a VLC picture.
104 * The surface has been previously allocated with vlc_va_Get() and decoded
105 * by the libavcodec hardware acceleration.
106 * The surface may still be used by libavcodec as a reference frame until it is
107 * freed with vlc_va_Release().
109 * @note This function needs not be reentrant, but it may run concurrently with
110 * vlc_va_Get() or vlc_va_Release() in other threads (with distinct frames).
112 * @param frame libavcodec frame previously allocated by vlc_va_Get()
114 static inline int vlc_va_Extract(vlc_va_t *va, picture_t *dst, void *opaque,
117 return va->extract(va, dst, opaque, data);
121 * Destroys a libavcodec hardware acceleration back-end.
122 * All allocated surfaces shall have been released beforehand.
124 void vlc_va_Delete(vlc_va_t *, AVCodecContext *);