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
34extern "C" {
35#endif
36
37struct pipe_screen;
38struct pipe_surface;
39struct pipe_macroblock;
40struct pipe_picture_desc;
41struct pipe_fence_handle;
42
43/**
44 * Gallium video codec for a specific format/profile
45 */
46struct 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, void *feedback, unsigned *size);
122};
123
124/**
125 * output for decoding / input for displaying
126 */
127struct pipe_video_buffer
128{
129   struct pipe_context *context;
130
131   enum pipe_format buffer_format;
132   unsigned width;
133   unsigned height;
134   bool interlaced;
135   unsigned bind;
136
137   /**
138    * destroy this video buffer
139    */
140   void (*destroy)(struct pipe_video_buffer *buffer);
141
142   /**
143    * get an individual sampler view for each plane
144    */
145   struct pipe_sampler_view **(*get_sampler_view_planes)(struct pipe_video_buffer *buffer);
146
147   /**
148    * get an individual sampler view for each component
149    */
150   struct pipe_sampler_view **(*get_sampler_view_components)(struct pipe_video_buffer *buffer);
151
152   /**
153    * get an individual surfaces for each plane
154    */
155   struct pipe_surface **(*get_surfaces)(struct pipe_video_buffer *buffer);
156
157   /*
158    * auxiliary associated data
159    */
160   void *associated_data;
161
162   /*
163    * codec where the associated data came from
164    */
165   struct pipe_video_codec *codec;
166
167   /*
168    * destroy the associated data
169    */
170   void (*destroy_associated_data)(void *associated_data);
171};
172
173#ifdef __cplusplus
174}
175#endif
176
177#endif /* PIPE_VIDEO_CONTEXT_H */
178