]> git.sesse.net Git - vlc/blob - modules/codec/avcodec/va.h
mediacodec: change type of internal variables to bool.
[vlc] / modules / codec / avcodec / va.h
1 /*****************************************************************************
2  * va.h: Video Acceleration API for avcodec
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir_AT_ videolan _DOT_ org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifndef VLC_AVCODEC_VA_H
25 #define VLC_AVCODEC_VA_H 1
26
27 typedef struct vlc_va_t vlc_va_t;
28 typedef struct vlc_va_sys_t vlc_va_sys_t;
29
30 struct vlc_va_t {
31     VLC_COMMON_MEMBERS
32
33     vlc_va_sys_t *sys;
34     module_t *module;
35     char *description;
36     int pix_fmt;
37
38     int  (*setup)(vlc_va_t *, void **hw, vlc_fourcc_t *output,
39                   int width, int height);
40     int  (*get)(vlc_va_t *, void **opaque, uint8_t **data);
41     void (*release)(void *opaque, uint8_t *surface);
42     int  (*extract)(vlc_va_t *, picture_t *dst, void *opaque, uint8_t *data);
43 };
44
45 /**
46  * Creates an accelerated video decoding back-end for libavcodec.
47  * @param obj parent VLC object
48  * @param codec_id libavcodec codec ID of the content to decode
49  * @param fmt VLC format of the content to decode
50  * @return a new VLC object on success, NULL on error.
51  */
52 vlc_va_t *vlc_va_New(vlc_object_t *obj, int codec_id, const es_format_t *fmt);
53
54 /**
55  * Initializes the acceleration video decoding back-end for libavcodec.
56  * @param hw pointer to libavcodec hardware context pointer [OUT]
57  * @param output pointer to video chroma output by the back-end [OUT]
58  * @param width coded video width in pixels
59  * @param height coded video height in pixels
60  * @return VLC_SUCCESS on success, otherwise an error code.
61  */
62 static inline int vlc_va_Setup(vlc_va_t *va, void **hw, vlc_fourcc_t *output,
63                                int width, int height)
64 {
65     return va->setup(va, hw, output, width, height);
66 }
67
68 /**
69  * Allocates a hardware video surface for a libavcodec frame.
70  * The surface will be used as output for the hardware decoder, and possibly
71  * also as a reference frame to decode other surfaces.
72  *
73  * @param opaque pointer to storage space for surface internal data [OUT]
74  * @param data pointer to the AVFrame data[0] and data[3] pointers [OUT]
75  *
76  * @note This function needs not be reentrant. However it may be called
77  * concurrently with vlc_va_Extract() and/or vlc_va_Release() from other
78  * threads and other frames.
79  *
80  * @param frame libavcodec frame [IN/OUT]
81  * @return VLC_SUCCESS on success, otherwise an error code.
82  */
83 static inline int vlc_va_Get(vlc_va_t *va, void **opaque, uint8_t **data)
84 {
85     return va->get(va, opaque, data);
86 }
87
88 /**
89  * Releases a hardware surface from a libavcodec frame.
90  * The surface has been previously allocated with vlc_va_Get().
91  *
92  * @param opaque opaque data pointer of the AVFrame set by vlc_va_Get()
93  * @param data data[0] pointer of the AVFrame set by vlc_va_Get()
94  *
95  * @note This function needs not be reentrant. However it may be called
96  * concurrently with vlc_va_Get() and/or vlc_va_Extract() from other threads
97  * and other frames.
98  *
99  * @param frame libavcodec frame previously allocated by vlc_va_Get()
100  */
101 static inline void vlc_va_Release(vlc_va_t *va, void *opaque, uint8_t *data)
102 {
103     va->release(opaque, data);
104 }
105
106 /**
107  * Extracts a hardware surface from a libavcodec frame into a VLC picture.
108  * The surface has been previously allocated with vlc_va_Get() and decoded
109  * by the libavcodec hardware acceleration.
110  * The surface may still be used by libavcodec as a reference frame until it is
111  * freed with vlc_va_Release().
112  *
113  * @note This function needs not be reentrant, but it may run concurrently with
114  * vlc_va_Get() or vlc_va_Release() in other threads (with distinct frames).
115  *
116  * @param frame libavcodec frame previously allocated by vlc_va_Get()
117  */
118 static inline int vlc_va_Extract(vlc_va_t *va, picture_t *dst, void *opaque,
119                                  uint8_t *data)
120 {
121     return va->extract(va, dst, opaque, data);
122 }
123
124 /**
125  * Destroys a libavcodec hardware acceleration back-end.
126  * All allocated surfaces shall have been released beforehand.
127  */
128 void vlc_va_Delete(vlc_va_t *);
129
130 #endif