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 int (*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 * returns 0 on success 108 */ 109 int (*end_frame)(struct pipe_video_codec *codec, 110 struct pipe_video_buffer *target, 111 struct pipe_picture_desc *picture); 112 113 /** 114 * flush any outstanding command buffers to the hardware 115 * should be called before a video_buffer is acessed by the gallium frontend again 116 */ 117 void (*flush)(struct pipe_video_codec *codec); 118 119 /** 120 * get encoder feedback 121 */ 122 void (*get_feedback)(struct pipe_video_codec *codec, 123 void *feedback, 124 unsigned *size, 125 struct pipe_enc_feedback_metadata* metadata /* opt NULL */); 126 127 /** 128 * Wait for fence. 129 * 130 * Can be used to query the status of the previous job denoted by 131 * 'fence' given 'timeout'. 132 * 133 * A pointer to a fence pointer can be passed to the codecs before the 134 * end_frame vfunc and the codec should then be responsible for allocating a 135 * fence on command stream submission. 136 */ 137 int (*fence_wait)(struct pipe_video_codec *codec, 138 struct pipe_fence_handle *fence, 139 uint64_t timeout); 140 141 /** 142 * Destroy fence. 143 */ 144 void (*destroy_fence)(struct pipe_video_codec *codec, 145 struct pipe_fence_handle *fence); 146 147 /** 148 * Gets the bitstream headers for a given pipe_picture_desc 149 * of an encode operation 150 * 151 * User passes a buffer and its allocated size and 152 * driver writes the bitstream headers in the buffer, 153 * updating the size parameter as well. 154 * 155 * Returns 0 on success or an errno error code otherwise. 156 * such as ENOMEM if the buffer passed was not big enough 157 */ 158 int (*get_encode_headers)(struct pipe_video_codec *codec, 159 struct pipe_picture_desc *picture, 160 void* bitstream_buf, 161 unsigned *size); 162 163 /** 164 * Creates a DPB buffer used for a single reconstructed picture. 165 */ 166 struct pipe_video_buffer *(*create_dpb_buffer)(struct pipe_video_codec *codec, 167 struct pipe_picture_desc *picture, 168 const struct pipe_video_buffer *templat); 169 }; 170 171 /** 172 * output for decoding / input for displaying 173 */ 174 struct pipe_video_buffer 175 { 176 struct pipe_context *context; 177 178 enum pipe_format buffer_format; 179 unsigned width; 180 unsigned height; 181 bool interlaced; 182 unsigned bind; 183 unsigned flags; 184 bool contiguous_planes; 185 186 /** 187 * destroy this video buffer 188 */ 189 void (*destroy)(struct pipe_video_buffer *buffer); 190 191 /** 192 * get an individual resource for each plane, 193 * only returns existing resources by reference 194 */ 195 void (*get_resources)(struct pipe_video_buffer *buffer, struct pipe_resource **resources); 196 197 /** 198 * get an individual sampler view for each plane 199 */ 200 struct pipe_sampler_view **(*get_sampler_view_planes)(struct pipe_video_buffer *buffer); 201 202 /** 203 * get an individual sampler view for each component 204 */ 205 struct pipe_sampler_view **(*get_sampler_view_components)(struct pipe_video_buffer *buffer); 206 207 /** 208 * get an individual surfaces for each plane 209 */ 210 struct pipe_surface **(*get_surfaces)(struct pipe_video_buffer *buffer); 211 212 /* 213 * auxiliary associated data 214 */ 215 void *associated_data; 216 217 /* 218 * codec where the associated data came from 219 */ 220 struct pipe_video_codec *codec; 221 222 /* 223 * destroy the associated data 224 */ 225 void (*destroy_associated_data)(void *associated_data); 226 227 /* 228 * encoded frame statistics for this particular picture 229 */ 230 void *statistics_data; 231 }; 232 233 #ifdef __cplusplus 234 } 235 #endif 236 237 #endif /* PIPE_VIDEO_CONTEXT_H */ 238