mixer.c revision 9e51c200a78b8be8be195e0d82d69e952afd1343
1/************************************************************************** 2 * 3 * Copyright 2010 Thomas Balling Sørensen. 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 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. 25 * 26 **************************************************************************/ 27 28#include <vdpau/vdpau.h> 29 30#include "util/u_memory.h" 31#include "util/u_debug.h" 32 33#include "vl/vl_csc.h" 34 35#include "vdpau_private.h" 36 37/** 38 * Create a VdpVideoMixer. 39 */ 40VdpStatus 41vlVdpVideoMixerCreate(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, 47 VdpVideoMixer *mixer) 48{ 49 vlVdpVideoMixer *vmixer = NULL; 50 VdpStatus ret; 51 float csc[16]; 52 53 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating VideoMixer\n"); 54 55 vlVdpDevice *dev = vlGetDataHTAB(device); 56 if (!dev) 57 return VDP_STATUS_INVALID_HANDLE; 58 59 vmixer = CALLOC(1, sizeof(vlVdpVideoMixer)); 60 if (!vmixer) 61 return VDP_STATUS_RESOURCES; 62 63 vmixer->device = dev; 64 vl_compositor_init(&vmixer->compositor, dev->context->pipe); 65 66 vl_csc_get_matrix 67 ( 68 debug_get_bool_option("G3DVL_NO_CSC", FALSE) ? 69 VL_CSC_COLOR_STANDARD_IDENTITY : VL_CSC_COLOR_STANDARD_BT_601, 70 NULL, true, csc 71 ); 72 vl_compositor_set_csc_matrix(&vmixer->compositor, csc); 73 74 /* 75 * TODO: Handle features and parameters 76 */ 77 78 *mixer = vlAddDataHTAB(vmixer); 79 if (*mixer == 0) { 80 ret = VDP_STATUS_ERROR; 81 goto no_handle; 82 } 83 84 return VDP_STATUS_OK; 85 86no_handle: 87 return ret; 88} 89 90/** 91 * Destroy a VdpVideoMixer. 92 */ 93VdpStatus 94vlVdpVideoMixerDestroy(VdpVideoMixer mixer) 95{ 96 vlVdpVideoMixer *vmixer; 97 98 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying VideoMixer\n"); 99 100 vmixer = vlGetDataHTAB(mixer); 101 if (!vmixer) 102 return VDP_STATUS_INVALID_HANDLE; 103 104 vl_compositor_cleanup(&vmixer->compositor); 105 106 FREE(vmixer); 107 108 return VDP_STATUS_OK; 109} 110 111/** 112 * Enable or disable features. 113 */ 114VdpStatus 115vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer, 116 uint32_t feature_count, 117 VdpVideoMixerFeature const *features, 118 VdpBool const *feature_enables) 119{ 120 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Setting VideoMixer features\n"); 121 122 if (!(features && feature_enables)) 123 return VDP_STATUS_INVALID_POINTER; 124 125 vlVdpVideoMixer *vmixer = vlGetDataHTAB(mixer); 126 if (!vmixer) 127 return VDP_STATUS_INVALID_HANDLE; 128 129 /* 130 * TODO: Set features 131 */ 132 133 return VDP_STATUS_OK; 134} 135 136/** 137 * Perform a video post-processing and compositing operation. 138 */ 139VdpStatus 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) 154{ 155 struct pipe_video_rect src_rect, dst_rect, dst_clip; 156 157 vlVdpVideoMixer *vmixer; 158 vlVdpSurface *surf; 159 vlVdpOutputSurface *dst; 160 161 vmixer = vlGetDataHTAB(mixer); 162 if (!vmixer) 163 return VDP_STATUS_INVALID_HANDLE; 164 165 surf = vlGetDataHTAB(video_surface_current); 166 if (!surf) 167 return VDP_STATUS_INVALID_HANDLE; 168 169 dst = vlGetDataHTAB(destination_surface); 170 if (!dst) 171 return VDP_STATUS_INVALID_HANDLE; 172 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, 177 RectToPipe(destination_video_rect, &dst_rect), 178 RectToPipe(destination_rect, &dst_clip), 179 &dst->dirty_area); 180 181 return VDP_STATUS_OK; 182} 183 184/** 185 * Set attribute values. 186 */ 187VdpStatus 188vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer, 189 uint32_t attribute_count, 190 VdpVideoMixerAttribute const *attributes, 191 void const *const *attribute_values) 192{ 193 if (!(attributes && attribute_values)) 194 return VDP_STATUS_INVALID_POINTER; 195 196 vlVdpVideoMixer *vmixer = vlGetDataHTAB(mixer); 197 if (!vmixer) 198 return VDP_STATUS_INVALID_HANDLE; 199 200 /* 201 * TODO: Implement the function 202 */ 203 204 return VDP_STATUS_OK; 205} 206 207/** 208 * Retrieve whether features were requested at creation time. 209 */ 210VdpStatus 211vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer, 212 uint32_t feature_count, 213 VdpVideoMixerFeature const *features, 214 VdpBool *feature_supports) 215{ 216 return VDP_STATUS_NO_IMPLEMENTATION; 217} 218 219/** 220 * Retrieve whether features are enabled. 221 */ 222VdpStatus 223vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer, 224 uint32_t feature_count, 225 VdpVideoMixerFeature const *features, 226 VdpBool *feature_enables) 227{ 228 return VDP_STATUS_NO_IMPLEMENTATION; 229} 230 231/** 232 * Retrieve parameter values given at creation time. 233 */ 234VdpStatus 235vlVdpVideoMixerGetParameterValues(VdpVideoMixer mixer, 236 uint32_t parameter_count, 237 VdpVideoMixerParameter const *parameters, 238 void *const *parameter_values) 239{ 240 return VDP_STATUS_NO_IMPLEMENTATION; 241} 242 243/** 244 * Retrieve current attribute values. 245 */ 246VdpStatus 247vlVdpVideoMixerGetAttributeValues(VdpVideoMixer mixer, 248 uint32_t attribute_count, 249 VdpVideoMixerAttribute const *attributes, 250 void *const *attribute_values) 251{ 252 return VDP_STATUS_NO_IMPLEMENTATION; 253} 254 255/** 256 * Generate a color space conversion matrix. 257 */ 258VdpStatus 259vlVdpGenerateCSCMatrix(VdpProcamp *procamp, 260 VdpColorStandard standard, 261 VdpCSCMatrix *csc_matrix) 262{ 263 float matrix[16]; 264 enum VL_CSC_COLOR_STANDARD vl_std; 265 struct vl_procamp camp; 266 267 if (!(csc_matrix && procamp)) 268 return VDP_STATUS_INVALID_POINTER; 269 270 if (procamp->struct_version > VDP_PROCAMP_VERSION) 271 return VDP_STATUS_INVALID_STRUCT_VERSION; 272 273 switch (standard) { 274 case VDP_COLOR_STANDARD_ITUR_BT_601: vl_std = VL_CSC_COLOR_STANDARD_BT_601; break; 275 case VDP_COLOR_STANDARD_ITUR_BT_709: vl_std = VL_CSC_COLOR_STANDARD_BT_709; break; 276 case VDP_COLOR_STANDARD_SMPTE_240M: vl_std = VL_CSC_COLOR_STANDARD_SMPTE_240M; break; 277 default: return VDP_STATUS_INVALID_COLOR_STANDARD; 278 } 279 camp.brightness = procamp->brightness; 280 camp.contrast = procamp->contrast; 281 camp.saturation = procamp->saturation; 282 camp.hue = procamp->hue; 283 vl_csc_get_matrix(vl_std, &camp, 1, matrix); 284 memcpy(csc_matrix, matrix, sizeof(float)*12); 285 return VDP_STATUS_OK; 286} 287