va.h 4.7 KB
Newer Older
1
/*****************************************************************************
2
 * va.h: Video Acceleration API for avcodec
3
4
5
6
7
8
 *****************************************************************************
 * Copyright (C) 2009 Laurent Aimar
 * $Id$
 *
 * Authors: Laurent Aimar <fenrir_AT_ videolan _DOT_ org>
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
9
10
11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12
13
14
15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
16
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
19
20
21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22
23
 *****************************************************************************/

24
25
#ifndef VLC_AVCODEC_VA_H
#define VLC_AVCODEC_VA_H 1
26
27

typedef struct vlc_va_t vlc_va_t;
28
29
typedef struct vlc_va_sys_t vlc_va_sys_t;

30
struct vlc_va_t {
31
32
33
    VLC_COMMON_MEMBERS

    vlc_va_sys_t *sys;
34
    module_t *module;
35
    char *description;
36
    int pix_fmt;
37

38
39
    int  (*setup)(vlc_va_t *, void **hw, vlc_fourcc_t *output,
                  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
47
48
49
50
/**
 * Creates an accelerated video decoding back-end for libavcodec.
 * @param obj parent VLC object
 * @param fmt VLC format of the content to decode
 * @return a new VLC object on success, NULL on error.
 */
51
vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *, const es_format_t *fmt);
52
53
54
55
56
57
58
59
60

/**
 * Initializes the acceleration video decoding back-end for libavcodec.
 * @param hw pointer to libavcodec hardware context pointer [OUT]
 * @param output pointer to video chroma output by the back-end [OUT]
 * @param width coded video width in pixels
 * @param height coded video height in pixels
 * @return VLC_SUCCESS on success, otherwise an error code.
 */
61
static inline int vlc_va_Setup(vlc_va_t *va, void **hw, vlc_fourcc_t *output,
62
                               int width, int height)
63
64
65
{
    return va->setup(va, hw, output, width, height);
}
66
67
68
69
70
71

/**
 * Allocates a hardware video surface for a libavcodec frame.
 * The surface will be used as output for the hardware decoder, and possibly
 * also as a reference frame to decode other surfaces.
 *
72
73
74
 * @param opaque pointer to storage space for surface internal data [OUT]
 * @param data pointer to the AVFrame data[0] and data[3] pointers [OUT]
 *
75
76
77
78
79
80
81
 * @note This function needs not be reentrant. However it may be called
 * concurrently with vlc_va_Extract() and/or vlc_va_Release() from other
 * threads and other frames.
 *
 * @param frame libavcodec frame [IN/OUT]
 * @return VLC_SUCCESS on success, otherwise an error code.
 */
82
static inline int vlc_va_Get(vlc_va_t *va, void **opaque, uint8_t **data)
83
{
84
    return va->get(va, opaque, data);
85
}
86
87
88
89
90

/**
 * Releases a hardware surface from a libavcodec frame.
 * 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()
 * @param data data[0] pointer of the AVFrame set by vlc_va_Get()
93
 *
94
95
96
97
98
99
 * @note This function needs not be reentrant. However it may be called
 * concurrently with vlc_va_Get() and/or vlc_va_Extract() from other threads
 * and other frames.
 *
 * @param frame libavcodec frame previously allocated by vlc_va_Get()
 */
100
static inline void vlc_va_Release(vlc_va_t *va, void *opaque, uint8_t *data)
101
{
102
    va->release(opaque, data);
103
}
104
105
106
107
108
109
110
111
112
113
114
115
116

/**
 * Extracts a hardware surface from a libavcodec frame into a VLC picture.
 * The surface has been previously allocated with vlc_va_Get() and decoded
 * by the libavcodec hardware acceleration.
 * The surface may still be used by libavcodec as a reference frame until it is
 * freed with vlc_va_Release().
 *
 * @note This function needs not be reentrant, but it may run concurrently with
 * vlc_va_Get() or vlc_va_Release() in other threads (with distinct frames).
 *
 * @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,
                                 uint8_t *data)
119
{
120
    return va->extract(va, dst, opaque, data);
121
}
122

123
124
125
126
127
128
/**
 * Destroys a libavcodec hardware acceleration back-end.
 * All allocated surfaces shall have been released beforehand.
 */
void vlc_va_Delete(vlc_va_t *);

129
#endif