lavc: Add new VDA hwaccel
[libav.git] / libavcodec / vda.h
CommitLineData
ac3dbb4d
SZ
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
7c59b5c2
AK
26/**
27 * @file
28 * @ingroup lavc_codec_hwaccel_vda
29 * Public libavcodec VDA header.
30 */
31
67afcefb 32#include "libavcodec/avcodec.h"
3c379706
SZ
33#include "libavcodec/version.h"
34
ac3dbb4d
SZ
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/**
7c59b5c2
AK
46 * @defgroup lavc_codec_hwaccel_vda VDA
47 * @ingroup lavc_codec_hwaccel
48 *
49 * @{
50 */
51
ac3dbb4d
SZ
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 */
58struct vda_context {
59 /**
063910f5
SZ
60 * VDA decoder object.
61 *
62 * - encoding: unused
63 * - decoding: Set/Unset by libavcodec.
64 */
ac3dbb4d
SZ
65 VDADecoder decoder;
66
67 /**
063910f5
SZ
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 */
3c379706
SZ
73 CVPixelBufferRef cv_buffer;
74
75 /**
063910f5
SZ
76 * Use the hardware decoder in synchronous mode.
77 *
78 * encoding: unused
79 * decoding: Set by user.
80 */
3c379706
SZ
81 int use_sync_decoding;
82
ac3dbb4d 83 /**
063910f5
SZ
84 * The frame width.
85 *
86 * - encoding: unused
87 * - decoding: Set/Unset by user.
88 */
ac3dbb4d
SZ
89 int width;
90
91 /**
063910f5
SZ
92 * The frame height.
93 *
94 * - encoding: unused
95 * - decoding: Set/Unset by user.
96 */
ac3dbb4d
SZ
97 int height;
98
99 /**
063910f5
SZ
100 * The frame format.
101 *
102 * - encoding: unused
103 * - decoding: Set/Unset by user.
104 */
ac3dbb4d
SZ
105 int format;
106
107 /**
063910f5
SZ
108 * The pixel format for output image buffers.
109 *
110 * - encoding: unused
111 * - decoding: Set/Unset by user.
112 */
ac3dbb4d 113 OSType cv_pix_fmt_type;
cfc680ab
SZ
114
115 /**
31a46750 116 * unused
063910f5 117 */
cfc680ab
SZ
118 uint8_t *priv_bitstream;
119
120 /**
31a46750 121 * unused
063910f5 122 */
cfc680ab
SZ
123 int priv_bitstream_size;
124
125 /**
31a46750 126 * unused
063910f5 127 */
cfc680ab 128 int priv_allocated_size;
ac3dbb4d
SZ
129};
130
131/** Create the video decoder. */
132int ff_vda_create_decoder(struct vda_context *vda_ctx,
133 uint8_t *extradata,
134 int extradata_size);
135
136/** Destroy the video decoder. */
137int ff_vda_destroy_decoder(struct vda_context *vda_ctx);
138
7c59b5c2 139/**
67afcefb
AK
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 */
145typedef 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 */
171AVVDAContext *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 */
181int 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 */
189void av_vda_default_free(AVCodecContext *avctx);
190
191/**
7c59b5c2
AK
192 * @}
193 */
194
ac3dbb4d 195#endif /* AVCODEC_VDA_H */