1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 TUNGSTEN GRAPHICS 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.
26 **************************************************************************/
28 #include <vdpau/vdpau.h>
30 #include "util/u_memory.h"
31 #include "util/u_debug.h"
33 #include "vl/vl_csc.h"
35 #include "vdpau_private.h"
38 * Create a VdpVideoMixer.
41 vlVdpVideoMixerCreate(VdpDevice device
,
42 uint32_t feature_count
,
43 VdpVideoMixerFeature
const *features
,
44 uint32_t parameter_count
,
45 VdpVideoMixerParameter
const *parameters
,
46 void const *const *parameter_values
,
49 vlVdpVideoMixer
*vmixer
= NULL
;
53 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Creating VideoMixer\n");
55 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
57 return VDP_STATUS_INVALID_HANDLE
;
59 vmixer
= CALLOC(1, sizeof(vlVdpVideoMixer
));
61 return VDP_STATUS_RESOURCES
;
64 vl_compositor_init(&vmixer
->compositor
, dev
->context
->pipe
);
68 debug_get_bool_option("G3DVL_NO_CSC", FALSE
) ?
69 VL_CSC_COLOR_STANDARD_IDENTITY
: VL_CSC_COLOR_STANDARD_BT_601
,
72 vl_compositor_set_csc_matrix(&vmixer
->compositor
, csc
);
75 * TODO: Handle features and parameters
78 *mixer
= vlAddDataHTAB(vmixer
);
80 ret
= VDP_STATUS_ERROR
;
91 * Destroy a VdpVideoMixer.
94 vlVdpVideoMixerDestroy(VdpVideoMixer mixer
)
96 vlVdpVideoMixer
*vmixer
;
98 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Destroying VideoMixer\n");
100 vmixer
= vlGetDataHTAB(mixer
);
102 return VDP_STATUS_INVALID_HANDLE
;
104 vl_compositor_cleanup(&vmixer
->compositor
);
108 return VDP_STATUS_OK
;
112 * Enable or disable features.
115 vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer
,
116 uint32_t feature_count
,
117 VdpVideoMixerFeature
const *features
,
118 VdpBool
const *feature_enables
)
120 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Setting VideoMixer features\n");
122 if (!(features
&& feature_enables
))
123 return VDP_STATUS_INVALID_POINTER
;
125 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
127 return VDP_STATUS_INVALID_HANDLE
;
133 return VDP_STATUS_OK
;
137 * Perform a video post-processing and compositing operation.
139 VdpStatus
vlVdpVideoMixerRender(VdpVideoMixer mixer
,
140 VdpOutputSurface background_surface
,
141 VdpRect
const *background_source_rect
,
142 VdpVideoMixerPictureStructure current_picture_structure
,
143 uint32_t video_surface_past_count
,
144 VdpVideoSurface
const *video_surface_past
,
145 VdpVideoSurface video_surface_current
,
146 uint32_t video_surface_future_count
,
147 VdpVideoSurface
const *video_surface_future
,
148 VdpRect
const *video_source_rect
,
149 VdpOutputSurface destination_surface
,
150 VdpRect
const *destination_rect
,
151 VdpRect
const *destination_video_rect
,
152 uint32_t layer_count
,
153 VdpLayer
const *layers
)
155 struct pipe_video_rect src_rect
;
157 vlVdpVideoMixer
*vmixer
;
159 vlVdpOutputSurface
*dst
;
161 vmixer
= vlGetDataHTAB(mixer
);
163 return VDP_STATUS_INVALID_HANDLE
;
165 surf
= vlGetDataHTAB(video_surface_current
);
167 return VDP_STATUS_INVALID_HANDLE
;
169 dst
= vlGetDataHTAB(destination_surface
);
171 return VDP_STATUS_INVALID_HANDLE
;
173 vl_compositor_clear_layers(&vmixer
->compositor
);
174 vl_compositor_set_buffer_layer(&vmixer
->compositor
, 0, surf
->video_buffer
,
175 RectToPipe(video_source_rect
, &src_rect
), NULL
);
176 vl_compositor_render(&vmixer
->compositor
, dst
->surface
, NULL
, NULL
, false);
178 return VDP_STATUS_OK
;
182 * Set attribute values.
185 vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer
,
186 uint32_t attribute_count
,
187 VdpVideoMixerAttribute
const *attributes
,
188 void const *const *attribute_values
)
190 if (!(attributes
&& attribute_values
))
191 return VDP_STATUS_INVALID_POINTER
;
193 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
195 return VDP_STATUS_INVALID_HANDLE
;
198 * TODO: Implement the function
201 return VDP_STATUS_OK
;
205 * Retrieve whether features were requested at creation time.
208 vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer
,
209 uint32_t feature_count
,
210 VdpVideoMixerFeature
const *features
,
211 VdpBool
*feature_supports
)
213 return VDP_STATUS_NO_IMPLEMENTATION
;
217 * Retrieve whether features are enabled.
220 vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer
,
221 uint32_t feature_count
,
222 VdpVideoMixerFeature
const *features
,
223 VdpBool
*feature_enables
)
225 return VDP_STATUS_NO_IMPLEMENTATION
;
229 * Retrieve parameter values given at creation time.
232 vlVdpVideoMixerGetParameterValues(VdpVideoMixer mixer
,
233 uint32_t parameter_count
,
234 VdpVideoMixerParameter
const *parameters
,
235 void *const *parameter_values
)
237 return VDP_STATUS_NO_IMPLEMENTATION
;
241 * Retrieve current attribute values.
244 vlVdpVideoMixerGetAttributeValues(VdpVideoMixer mixer
,
245 uint32_t attribute_count
,
246 VdpVideoMixerAttribute
const *attributes
,
247 void *const *attribute_values
)
249 return VDP_STATUS_NO_IMPLEMENTATION
;
253 * Generate a color space conversion matrix.
256 vlVdpGenerateCSCMatrix(VdpProcamp
*procamp
,
257 VdpColorStandard standard
,
258 VdpCSCMatrix
*csc_matrix
)
261 enum VL_CSC_COLOR_STANDARD vl_std
;
262 struct vl_procamp camp
;
264 if (!(csc_matrix
&& procamp
))
265 return VDP_STATUS_INVALID_POINTER
;
267 if (procamp
->struct_version
> VDP_PROCAMP_VERSION
)
268 return VDP_STATUS_INVALID_STRUCT_VERSION
;
271 case VDP_COLOR_STANDARD_ITUR_BT_601
: vl_std
= VL_CSC_COLOR_STANDARD_BT_601
; break;
272 case VDP_COLOR_STANDARD_ITUR_BT_709
: vl_std
= VL_CSC_COLOR_STANDARD_BT_709
; break;
273 case VDP_COLOR_STANDARD_SMPTE_240M
: vl_std
= VL_CSC_COLOR_STANDARD_SMPTE_240M
; break;
274 default: return VDP_STATUS_INVALID_COLOR_STANDARD
;
276 camp
.brightness
= procamp
->brightness
;
277 camp
.contrast
= procamp
->contrast
;
278 camp
.saturation
= procamp
->saturation
;
279 camp
.hue
= procamp
->hue
;
280 vl_csc_get_matrix(vl_std
, &camp
, 1, matrix
);
281 memcpy(csc_matrix
, matrix
, sizeof(float)*12);
282 return VDP_STATUS_OK
;