]> git.sesse.net Git - ffmpeg/blob - libavcodec/vda.h
vda: Make output CVPixelBuffer format configurable
[ffmpeg] / 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
157     /**
158      * CVPixelBuffer Format Type that VDA will use for decoded frames; set by
159      * the caller.
160      */
161     OSType cv_pix_fmt_type;
162 } AVVDAContext;
163
164 /**
165  * Allocate and initialize a VDA context.
166  *
167  * This function should be called from the get_format() callback when the caller
168  * selects the AV_PIX_FMT_VDA format. The caller must then create the decoder
169  * object (using the output callback provided by libavcodec) that will be used
170  * for VDA-accelerated decoding.
171  *
172  * When decoding with VDA is finished, the caller must destroy the decoder
173  * object and free the VDA context using av_free().
174  *
175  * @return the newly allocated context or NULL on failure
176  */
177 AVVDAContext *av_vda_alloc_context(void);
178
179 /**
180  * This is a convenience function that creates and sets up the VDA context using
181  * an internal implementation.
182  *
183  * @param avctx the corresponding codec context
184  *
185  * @return >= 0 on success, a negative AVERROR code on failure
186  */
187 int av_vda_default_init(AVCodecContext *avctx);
188
189 /**
190  * This is a convenience function that creates and sets up the VDA context using
191  * an internal implementation.
192  *
193  * @param avctx the corresponding codec context
194  * @param vdactx the VDA context to use
195  *
196  * @return >= 0 on success, a negative AVERROR code on failure
197  */
198 int av_vda_default_init2(AVCodecContext *avctx, AVVDAContext *vdactx);
199
200 /**
201  * This function must be called to free the VDA context initialized with
202  * av_vda_default_init().
203  *
204  * @param avctx the corresponding codec context
205  */
206 void av_vda_default_free(AVCodecContext *avctx);
207
208 /**
209  * @}
210  */
211
212 #endif /* AVCODEC_VDA_H */