lavc: Add new VDA hwaccel
[libav.git] / libavcodec / vda.h
1 /*
2 * VDA HW acceleration
3 *
4 * copyright (c) 2011 Sebastien Zwickert
5 *
6 * This file is part of Libav.
7 *
8 * Libav is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * Libav is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef AVCODEC_VDA_H
24 #define AVCODEC_VDA_H
25
26 /**
27 * @file
28 * @ingroup lavc_codec_hwaccel_vda
29 * Public libavcodec VDA header.
30 */
31
32 #include "libavcodec/avcodec.h"
33 #include "libavcodec/version.h"
34
35 #include <stdint.h>
36
37 // emmintrin.h is unable to compile with -std=c99 -Werror=missing-prototypes
38 // http://openradar.appspot.com/8026390
39 #undef __GNUC_STDC_INLINE__
40
41 #define Picture QuickdrawPicture
42 #include <VideoDecodeAcceleration/VDADecoder.h>
43 #undef Picture
44
45 /**
46 * @defgroup lavc_codec_hwaccel_vda VDA
47 * @ingroup lavc_codec_hwaccel
48 *
49 * @{
50 */
51
52 /**
53 * This structure is used to provide the necessary configurations and data
54 * to the VDA Libav HWAccel implementation.
55 *
56 * The application must make it available as AVCodecContext.hwaccel_context.
57 */
58 struct vda_context {
59 /**
60 * VDA decoder object.
61 *
62 * - encoding: unused
63 * - decoding: Set/Unset by libavcodec.
64 */
65 VDADecoder decoder;
66
67 /**
68 * The Core Video pixel buffer that contains the current image data.
69 *
70 * encoding: unused
71 * decoding: Set by libavcodec. Unset by user.
72 */
73 CVPixelBufferRef cv_buffer;
74
75 /**
76 * Use the hardware decoder in synchronous mode.
77 *
78 * encoding: unused
79 * decoding: Set by user.
80 */
81 int use_sync_decoding;
82
83 /**
84 * The frame width.
85 *
86 * - encoding: unused
87 * - decoding: Set/Unset by user.
88 */
89 int width;
90
91 /**
92 * The frame height.
93 *
94 * - encoding: unused
95 * - decoding: Set/Unset by user.
96 */
97 int height;
98
99 /**
100 * The frame format.
101 *
102 * - encoding: unused
103 * - decoding: Set/Unset by user.
104 */
105 int format;
106
107 /**
108 * The pixel format for output image buffers.
109 *
110 * - encoding: unused
111 * - decoding: Set/Unset by user.
112 */
113 OSType cv_pix_fmt_type;
114
115 /**
116 * unused
117 */
118 uint8_t *priv_bitstream;
119
120 /**
121 * unused
122 */
123 int priv_bitstream_size;
124
125 /**
126 * unused
127 */
128 int priv_allocated_size;
129 };
130
131 /** Create the video decoder. */
132 int ff_vda_create_decoder(struct vda_context *vda_ctx,
133 uint8_t *extradata,
134 int extradata_size);
135
136 /** Destroy the video decoder. */
137 int ff_vda_destroy_decoder(struct vda_context *vda_ctx);
138
139 /**
140 * This struct holds all the information that needs to be passed
141 * between the caller and libavcodec for initializing VDA decoding.
142 * Its size is not a part of the public ABI, it must be allocated with
143 * av_vda_alloc_context() and freed with av_free().
144 */
145 typedef struct AVVDAContext {
146 /**
147 * VDA decoder object. Created and freed by the caller.
148 */
149 VDADecoder decoder;
150
151 /**
152 * The output callback that must be passed to VDADecoderCreate.
153 * Set by av_vda_alloc_context().
154 */
155 VDADecoderOutputCallback output_callback;
156 } AVVDAContext;
157
158 /**
159 * Allocate and initialize a VDA context.
160 *
161 * This function should be called from the get_format() callback when the caller
162 * selects the AV_PIX_FMT_VDA format. The caller must then create the decoder
163 * object (using the output callback provided by libavcodec) that will be used
164 * for VDA-accelerated decoding.
165 *
166 * When decoding with VDA is finished, the caller must destroy the decoder
167 * object and free the VDA context using av_free().
168 *
169 * @return the newly allocated context or NULL on failure
170 */
171 AVVDAContext *av_vda_alloc_context(void);
172
173 /**
174 * This is a convenience function that creates and sets up the VDA context using
175 * an internal implementation.
176 *
177 * @param avctx the corresponding codec context
178 *
179 * @return >= 0 on success, a negative AVERROR code on failure
180 */
181 int av_vda_default_init(AVCodecContext *avctx);
182
183 /**
184 * This function must be called to free the VDA context initialized with
185 * av_vda_default_init().
186 *
187 * @param avctx the corresponding codec context
188 */
189 void av_vda_default_free(AVCodecContext *avctx);
190
191 /**
192 * @}
193 */
194
195 #endif /* AVCODEC_VDA_H */