• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2009 Younes Manton.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #ifndef PIPE_VIDEO_CONTEXT_H
29 #define PIPE_VIDEO_CONTEXT_H
30 
31 #include "pipe/p_video_state.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 struct pipe_screen;
38 struct pipe_surface;
39 struct pipe_macroblock;
40 struct pipe_picture_desc;
41 struct pipe_fence_handle;
42 
43 /**
44  * Gallium video codec for a specific format/profile
45  */
46 struct pipe_video_codec
47 {
48    struct pipe_context *context;
49 
50    enum pipe_video_profile profile;
51    unsigned level;
52    enum pipe_video_entrypoint entrypoint;
53    enum pipe_video_chroma_format chroma_format;
54    unsigned width;
55    unsigned height;
56    unsigned max_references;
57    bool expect_chunked_decode;
58 
59    /**
60     * destroy this video decoder
61     */
62    void (*destroy)(struct pipe_video_codec *codec);
63 
64    /**
65     * start decoding of a new frame
66     */
67    void (*begin_frame)(struct pipe_video_codec *codec,
68                        struct pipe_video_buffer *target,
69                        struct pipe_picture_desc *picture);
70 
71    /**
72     * decode a macroblock
73     */
74    void (*decode_macroblock)(struct pipe_video_codec *codec,
75                              struct pipe_video_buffer *target,
76                              struct pipe_picture_desc *picture,
77                              const struct pipe_macroblock *macroblocks,
78                              unsigned num_macroblocks);
79 
80    /**
81     * decode a bitstream
82     */
83    void (*decode_bitstream)(struct pipe_video_codec *codec,
84                             struct pipe_video_buffer *target,
85                             struct pipe_picture_desc *picture,
86                             unsigned num_buffers,
87                             const void * const *buffers,
88                             const unsigned *sizes);
89 
90    /**
91     * encode to a bitstream
92     */
93    void (*encode_bitstream)(struct pipe_video_codec *codec,
94                             struct pipe_video_buffer *source,
95                             struct pipe_resource *destination,
96                             void **feedback);
97 
98    /**
99     * Perform post-process effect
100     */
101    void (*process_frame)(struct pipe_video_codec *codec,
102                          struct pipe_video_buffer *source,
103                          const struct pipe_vpp_desc *process_properties);
104 
105    /**
106     * end decoding of the current frame
107     */
108    void (*end_frame)(struct pipe_video_codec *codec,
109                      struct pipe_video_buffer *target,
110                      struct pipe_picture_desc *picture);
111 
112    /**
113     * flush any outstanding command buffers to the hardware
114     * should be called before a video_buffer is acessed by the gallium frontend again
115     */
116    void (*flush)(struct pipe_video_codec *codec);
117 
118    /**
119     * get encoder feedback
120     */
121    void (*get_feedback)(struct pipe_video_codec *codec,
122                         void *feedback,
123                         unsigned *size,
124                         struct pipe_enc_feedback_metadata* metadata /* opt NULL */);
125 
126    /**
127     * Get decoder fence.
128     *
129     * Can be used to query the status of the previous decode job denoted by
130     * 'fence' given 'timeout'.
131     *
132     * A pointer to a fence pointer can be passed to the codecs before the
133     * end_frame vfunc and the codec should then be responsible for allocating a
134     * fence on command stream submission.
135     */
136    int (*get_decoder_fence)(struct pipe_video_codec *codec,
137                             struct pipe_fence_handle *fence,
138                             uint64_t timeout);
139 
140    /**
141     * Get processor fence.
142     *
143     * Can be used to query the status of the previous process job denoted by
144     * 'fence' given 'timeout'.
145     *
146     * A pointer to a fence pointer can be passed to the codecs before the
147     * end_frame vfunc and the codec should then be responsible for allocating a
148     * fence on command stream submission.
149     */
150    int (*get_processor_fence)(struct pipe_video_codec *codec,
151                               struct pipe_fence_handle *fence,
152                               uint64_t timeout);
153 
154    /**
155     * Gets a weak reference to a feedback fence.
156     *
157     * Can be used to wait on the pipe_fence_handle directly instead
158     * of waiting on the get_feedback blocking call.
159     *
160     * Returns NULL if the feedback parameter does not have
161     * a valid in-flight submitted frame
162     */
163    struct pipe_fence_handle* (*get_feedback_fence)(struct pipe_video_codec *codec,
164                                                    void *feedback);
165 
166    /**
167     * Destroy fence.
168     */
169    void (*destroy_fence)(struct pipe_video_codec *codec,
170                          struct pipe_fence_handle *fence);
171 
172    /**
173     * Update target buffer address.
174     *
175     * Due to reallocation, target buffer address has changed, and the
176     * changed buffer will need to update to decoder so that when this buffer
177     * used as a reference frame, decoder can obtain its recorded information.
178     * Failed updating this buffer will miss reference frames and
179     * cause image corruption in the sebsequent output.
180     * If no target buffer change, this call is not necessary.
181     */
182    void (*update_decoder_target)(struct pipe_video_codec *codec,
183                                  struct pipe_video_buffer *old,
184                                  struct pipe_video_buffer *updated);
185 
186    /**
187     * Gets the bitstream headers for a given pipe_picture_desc
188     * of an encode operation
189     *
190     * User passes a buffer and its allocated size and
191     * driver writes the bitstream headers in the buffer,
192     * updating the size parameter as well.
193     *
194     * Returns 0 on success or an errno error code otherwise.
195     * such as ENOMEM if the buffer passed was not big enough
196     */
197    int (*get_encode_headers)(struct pipe_video_codec *codec,
198                               struct pipe_picture_desc *picture,
199                               void* bitstream_buf,
200                               unsigned *size);
201 };
202 
203 /**
204  * output for decoding / input for displaying
205  */
206 struct pipe_video_buffer
207 {
208    struct pipe_context *context;
209 
210    enum pipe_format buffer_format;
211    unsigned width;
212    unsigned height;
213    bool interlaced;
214    unsigned bind;
215 
216    /**
217     * destroy this video buffer
218     */
219    void (*destroy)(struct pipe_video_buffer *buffer);
220 
221    /**
222     * get an individual resource for each plane,
223     * only returns existing resources by reference
224     */
225    void (*get_resources)(struct pipe_video_buffer *buffer, struct pipe_resource **resources);
226 
227    /**
228     * get an individual sampler view for each plane
229     */
230    struct pipe_sampler_view **(*get_sampler_view_planes)(struct pipe_video_buffer *buffer);
231 
232    /**
233     * get an individual sampler view for each component
234     */
235    struct pipe_sampler_view **(*get_sampler_view_components)(struct pipe_video_buffer *buffer);
236 
237    /**
238     * get an individual surfaces for each plane
239     */
240    struct pipe_surface **(*get_surfaces)(struct pipe_video_buffer *buffer);
241 
242    /*
243     * auxiliary associated data
244     */
245    void *associated_data;
246 
247    /*
248     * codec where the associated data came from
249     */
250    struct pipe_video_codec *codec;
251 
252    /*
253     * destroy the associated data
254     */
255    void (*destroy_associated_data)(void *associated_data);
256 
257    /*
258     * encoded frame statistics for this particular picture
259     */
260    void *statistics_data;
261 };
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /* PIPE_VIDEO_CONTEXT_H */
268