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 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.
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
;
51 struct pipe_screen
*screen
;
54 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
56 return VDP_STATUS_INVALID_HANDLE
;
57 screen
= dev
->vscreen
->pscreen
;
59 vmixer
= CALLOC(1, sizeof(vlVdpVideoMixer
));
61 return VDP_STATUS_RESOURCES
;
63 DeviceReference(&vmixer
->device
, dev
);
65 mtx_lock(&dev
->mutex
);
67 if (!vl_compositor_init_state(&vmixer
->cstate
, dev
->context
)) {
68 ret
= VDP_STATUS_ERROR
;
69 goto no_compositor_state
;
72 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_601
, NULL
, true, &vmixer
->csc
);
73 if (!debug_get_bool_option("G3DVL_NO_CSC", FALSE
)) {
74 if (!vl_compositor_set_csc_matrix(&vmixer
->cstate
, (const vl_csc_matrix
*)&vmixer
->csc
, 1.0f
, 0.0f
)) {
75 ret
= VDP_STATUS_ERROR
;
80 *mixer
= vlAddDataHTAB(vmixer
);
82 ret
= VDP_STATUS_ERROR
;
86 ret
= VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE
;
87 for (i
= 0; i
< feature_count
; ++i
) {
88 switch (features
[i
]) {
89 /* they are valid, but we doesn't support them */
90 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
:
91 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2
:
92 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3
:
93 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4
:
94 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5
:
95 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6
:
96 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7
:
97 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8
:
98 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9
:
99 case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
:
102 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
103 vmixer
->deint
.supported
= true;
106 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
107 vmixer
->sharpness
.supported
= true;
110 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
111 vmixer
->noise_reduction
.supported
= true;
114 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
115 vmixer
->luma_key
.supported
= true;
118 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
119 vmixer
->bicubic
.supported
= true;
121 default: goto no_params
;
125 vmixer
->chroma_format
= PIPE_VIDEO_CHROMA_FORMAT_420
;
126 ret
= VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
127 for (i
= 0; i
< parameter_count
; ++i
) {
128 switch (parameters
[i
]) {
129 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
130 vmixer
->video_width
= *(uint32_t*)parameter_values
[i
];
132 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
133 vmixer
->video_height
= *(uint32_t*)parameter_values
[i
];
135 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
136 vmixer
->chroma_format
= ChromaToPipe(*(VdpChromaType
*)parameter_values
[i
]);
138 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
139 vmixer
->max_layers
= *(uint32_t*)parameter_values
[i
];
141 default: goto no_params
;
144 ret
= VDP_STATUS_INVALID_VALUE
;
145 if (vmixer
->max_layers
> 4) {
146 VDPAU_MSG(VDPAU_WARN
, "[VDPAU] Max layers > 4 not supported\n", vmixer
->max_layers
);
150 max_size
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_2D_SIZE
);
151 if (vmixer
->video_width
< 48 || vmixer
->video_width
> max_size
) {
152 VDPAU_MSG(VDPAU_WARN
, "[VDPAU] 48 < %u < %u not valid for width\n",
153 vmixer
->video_width
, max_size
);
156 if (vmixer
->video_height
< 48 || vmixer
->video_height
> max_size
) {
157 VDPAU_MSG(VDPAU_WARN
, "[VDPAU] 48 < %u < %u not valid for height\n",
158 vmixer
->video_height
, max_size
);
161 vmixer
->luma_key
.luma_min
= 1.0f
;
162 vmixer
->luma_key
.luma_max
= 0.0f
;
163 mtx_unlock(&dev
->mutex
);
165 return VDP_STATUS_OK
;
168 vlRemoveDataHTAB(*mixer
);
172 vl_compositor_cleanup_state(&vmixer
->cstate
);
174 mtx_unlock(&dev
->mutex
);
175 DeviceReference(&vmixer
->device
, NULL
);
181 * Destroy a VdpVideoMixer.
184 vlVdpVideoMixerDestroy(VdpVideoMixer mixer
)
186 vlVdpVideoMixer
*vmixer
;
188 vmixer
= vlGetDataHTAB(mixer
);
190 return VDP_STATUS_INVALID_HANDLE
;
192 mtx_lock(&vmixer
->device
->mutex
);
194 vlRemoveDataHTAB(mixer
);
196 vl_compositor_cleanup_state(&vmixer
->cstate
);
198 if (vmixer
->deint
.filter
) {
199 vl_deint_filter_cleanup(vmixer
->deint
.filter
);
200 FREE(vmixer
->deint
.filter
);
203 if (vmixer
->noise_reduction
.filter
) {
204 vl_median_filter_cleanup(vmixer
->noise_reduction
.filter
);
205 FREE(vmixer
->noise_reduction
.filter
);
208 if (vmixer
->sharpness
.filter
) {
209 vl_matrix_filter_cleanup(vmixer
->sharpness
.filter
);
210 FREE(vmixer
->sharpness
.filter
);
213 if (vmixer
->bicubic
.filter
) {
214 vl_bicubic_filter_cleanup(vmixer
->bicubic
.filter
);
215 FREE(vmixer
->bicubic
.filter
);
217 mtx_unlock(&vmixer
->device
->mutex
);
218 DeviceReference(&vmixer
->device
, NULL
);
222 return VDP_STATUS_OK
;
226 * Perform a video post-processing and compositing operation.
228 VdpStatus
vlVdpVideoMixerRender(VdpVideoMixer mixer
,
229 VdpOutputSurface background_surface
,
230 VdpRect
const *background_source_rect
,
231 VdpVideoMixerPictureStructure current_picture_structure
,
232 uint32_t video_surface_past_count
,
233 VdpVideoSurface
const *video_surface_past
,
234 VdpVideoSurface video_surface_current
,
235 uint32_t video_surface_future_count
,
236 VdpVideoSurface
const *video_surface_future
,
237 VdpRect
const *video_source_rect
,
238 VdpOutputSurface destination_surface
,
239 VdpRect
const *destination_rect
,
240 VdpRect
const *destination_video_rect
,
241 uint32_t layer_count
,
242 VdpLayer
const *layers
)
244 enum vl_compositor_deinterlace deinterlace
;
245 struct u_rect rect
, clip
, *prect
, dirty_area
;
246 unsigned i
, layer
= 0;
247 struct pipe_video_buffer
*video_buffer
;
248 struct pipe_sampler_view
*sampler_view
, sv_templ
;
249 struct pipe_surface
*surface
, surf_templ
;
250 struct pipe_context
*pipe
= NULL
;
251 struct pipe_resource res_tmpl
, *res
;
253 vlVdpVideoMixer
*vmixer
;
255 vlVdpOutputSurface
*dst
, *bg
= NULL
;
257 struct vl_compositor
*compositor
;
259 vmixer
= vlGetDataHTAB(mixer
);
261 return VDP_STATUS_INVALID_HANDLE
;
263 compositor
= &vmixer
->device
->compositor
;
265 surf
= vlGetDataHTAB(video_surface_current
);
267 return VDP_STATUS_INVALID_HANDLE
;
268 video_buffer
= surf
->video_buffer
;
270 if (surf
->device
!= vmixer
->device
)
271 return VDP_STATUS_HANDLE_DEVICE_MISMATCH
;
273 if (vmixer
->video_width
> video_buffer
->width
||
274 vmixer
->video_height
> video_buffer
->height
||
275 vmixer
->chroma_format
!= pipe_format_to_chroma_format(video_buffer
->buffer_format
))
276 return VDP_STATUS_INVALID_SIZE
;
278 if (layer_count
> vmixer
->max_layers
)
279 return VDP_STATUS_INVALID_VALUE
;
281 dst
= vlGetDataHTAB(destination_surface
);
283 return VDP_STATUS_INVALID_HANDLE
;
285 if (background_surface
!= VDP_INVALID_HANDLE
) {
286 bg
= vlGetDataHTAB(background_surface
);
288 return VDP_STATUS_INVALID_HANDLE
;
291 mtx_lock(&vmixer
->device
->mutex
);
293 vl_compositor_clear_layers(&vmixer
->cstate
);
296 vl_compositor_set_rgba_layer(&vmixer
->cstate
, compositor
, layer
++, bg
->sampler_view
,
297 RectToPipe(background_source_rect
, &rect
), NULL
, NULL
);
299 switch (current_picture_structure
) {
300 case VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD
:
301 deinterlace
= VL_COMPOSITOR_BOB_TOP
;
304 case VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD
:
305 deinterlace
= VL_COMPOSITOR_BOB_BOTTOM
;
308 case VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME
:
309 deinterlace
= VL_COMPOSITOR_WEAVE
;
313 mtx_unlock(&vmixer
->device
->mutex
);
314 return VDP_STATUS_INVALID_VIDEO_MIXER_PICTURE_STRUCTURE
;
317 if (deinterlace
!= VL_COMPOSITOR_WEAVE
&& vmixer
->deint
.enabled
&&
318 video_surface_past_count
> 1 && video_surface_future_count
> 0) {
319 vlVdpSurface
*prevprev
= vlGetDataHTAB(video_surface_past
[1]);
320 vlVdpSurface
*prev
= vlGetDataHTAB(video_surface_past
[0]);
321 vlVdpSurface
*next
= vlGetDataHTAB(video_surface_future
[0]);
322 if (prevprev
&& prev
&& next
&&
323 vl_deint_filter_check_buffers(vmixer
->deint
.filter
,
324 prevprev
->video_buffer
, prev
->video_buffer
, surf
->video_buffer
, next
->video_buffer
)) {
325 vl_deint_filter_render(vmixer
->deint
.filter
, prevprev
->video_buffer
,
326 prev
->video_buffer
, surf
->video_buffer
,
328 deinterlace
== VL_COMPOSITOR_BOB_BOTTOM
);
329 deinterlace
= VL_COMPOSITOR_WEAVE
;
330 video_buffer
= vmixer
->deint
.filter
->video_buffer
;
334 prect
= RectToPipe(video_source_rect
, &rect
);
338 rect
.x1
= surf
->templat
.width
;
339 rect
.y1
= surf
->templat
.height
;
342 vl_compositor_set_buffer_layer(&vmixer
->cstate
, compositor
, layer
, video_buffer
, prect
, NULL
, deinterlace
);
344 if (vmixer
->bicubic
.filter
|| vmixer
->sharpness
.filter
|| vmixer
->noise_reduction
.filter
) {
345 pipe
= vmixer
->device
->context
;
346 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
348 res_tmpl
.target
= PIPE_TEXTURE_2D
;
349 res_tmpl
.format
= dst
->sampler_view
->format
;
351 res_tmpl
.array_size
= 1;
352 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
353 res_tmpl
.usage
= PIPE_USAGE_DEFAULT
;
355 if (!vmixer
->bicubic
.filter
) {
356 res_tmpl
.width0
= dst
->surface
->width
;
357 res_tmpl
.height0
= dst
->surface
->height
;
359 res_tmpl
.width0
= surf
->templat
.width
;
360 res_tmpl
.height0
= surf
->templat
.height
;
363 res
= pipe
->screen
->resource_create(pipe
->screen
, &res_tmpl
);
365 vlVdpDefaultSamplerViewTemplate(&sv_templ
, res
);
366 sampler_view
= pipe
->create_sampler_view(pipe
, res
, &sv_templ
);
368 memset(&surf_templ
, 0, sizeof(surf_templ
));
369 surf_templ
.format
= res
->format
;
370 surface
= pipe
->create_surface(pipe
, res
, &surf_templ
);
372 vl_compositor_reset_dirty_area(&dirty_area
);
373 pipe_resource_reference(&res
, NULL
);
375 surface
= dst
->surface
;
376 sampler_view
= dst
->sampler_view
;
377 dirty_area
= dst
->dirty_area
;
380 if (!vmixer
->bicubic
.filter
) {
381 vl_compositor_set_layer_dst_area(&vmixer
->cstate
, layer
++, RectToPipe(destination_video_rect
, &rect
));
382 vl_compositor_set_dst_clip(&vmixer
->cstate
, RectToPipe(destination_rect
, &clip
));
385 for (i
= 0; i
< layer_count
; ++i
) {
386 vlVdpOutputSurface
*src
= vlGetDataHTAB(layers
->source_surface
);
388 mtx_unlock(&vmixer
->device
->mutex
);
389 return VDP_STATUS_INVALID_HANDLE
;
392 assert(layers
->struct_version
== VDP_LAYER_VERSION
);
394 vl_compositor_set_rgba_layer(&vmixer
->cstate
, compositor
, layer
, src
->sampler_view
,
395 RectToPipe(layers
->source_rect
, &rect
), NULL
, NULL
);
396 vl_compositor_set_layer_dst_area(&vmixer
->cstate
, layer
++, RectToPipe(layers
->destination_rect
, &rect
));
401 vl_compositor_render(&vmixer
->cstate
, compositor
, surface
, &dirty_area
, true);
403 if (vmixer
->noise_reduction
.filter
) {
404 if (!vmixer
->sharpness
.filter
&& !vmixer
->bicubic
.filter
) {
405 vl_median_filter_render(vmixer
->noise_reduction
.filter
,
406 sampler_view
, dst
->surface
);
408 res
= pipe
->screen
->resource_create(pipe
->screen
, &res_tmpl
);
409 struct pipe_sampler_view
*sampler_view_temp
= pipe
->create_sampler_view(pipe
, res
, &sv_templ
);
410 struct pipe_surface
*surface_temp
= pipe
->create_surface(pipe
, res
, &surf_templ
);
411 pipe_resource_reference(&res
, NULL
);
413 vl_median_filter_render(vmixer
->noise_reduction
.filter
,
414 sampler_view
, surface_temp
);
416 pipe_sampler_view_reference(&sampler_view
, NULL
);
417 pipe_surface_reference(&surface
, NULL
);
419 sampler_view
= sampler_view_temp
;
420 surface
= surface_temp
;
424 if (vmixer
->sharpness
.filter
) {
425 if (!vmixer
->bicubic
.filter
) {
426 vl_matrix_filter_render(vmixer
->sharpness
.filter
,
427 sampler_view
, dst
->surface
);
429 res
= pipe
->screen
->resource_create(pipe
->screen
, &res_tmpl
);
430 struct pipe_sampler_view
*sampler_view_temp
= pipe
->create_sampler_view(pipe
, res
, &sv_templ
);
431 struct pipe_surface
*surface_temp
= pipe
->create_surface(pipe
, res
, &surf_templ
);
432 pipe_resource_reference(&res
, NULL
);
434 vl_matrix_filter_render(vmixer
->sharpness
.filter
,
435 sampler_view
, surface_temp
);
437 pipe_sampler_view_reference(&sampler_view
, NULL
);
438 pipe_surface_reference(&surface
, NULL
);
440 sampler_view
= sampler_view_temp
;
441 surface
= surface_temp
;
445 if (vmixer
->bicubic
.filter
)
446 vl_bicubic_filter_render(vmixer
->bicubic
.filter
,
447 sampler_view
, dst
->surface
,
448 RectToPipe(destination_video_rect
, &rect
),
449 RectToPipe(destination_rect
, &clip
));
451 if(surface
!= dst
->surface
) {
452 pipe_sampler_view_reference(&sampler_view
, NULL
);
453 pipe_surface_reference(&surface
, NULL
);
455 mtx_unlock(&vmixer
->device
->mutex
);
457 return VDP_STATUS_OK
;
461 vlVdpVideoMixerUpdateDeinterlaceFilter(vlVdpVideoMixer
*vmixer
)
463 struct pipe_context
*pipe
= vmixer
->device
->context
;
466 /* remove existing filter */
467 if (vmixer
->deint
.filter
) {
468 vl_deint_filter_cleanup(vmixer
->deint
.filter
);
469 FREE(vmixer
->deint
.filter
);
470 vmixer
->deint
.filter
= NULL
;
473 /* create a new filter if requested */
474 if (vmixer
->deint
.enabled
&& vmixer
->chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
) {
475 vmixer
->deint
.filter
= MALLOC(sizeof(struct vl_deint_filter
));
476 vmixer
->deint
.enabled
= vl_deint_filter_init(vmixer
->deint
.filter
, pipe
,
477 vmixer
->video_width
, vmixer
->video_height
,
478 vmixer
->skip_chroma_deint
, vmixer
->deint
.spatial
);
479 if (!vmixer
->deint
.enabled
) {
480 FREE(vmixer
->deint
.filter
);
486 * Update the noise reduction setting
489 vlVdpVideoMixerUpdateNoiseReductionFilter(vlVdpVideoMixer
*vmixer
)
493 /* if present remove the old filter first */
494 if (vmixer
->noise_reduction
.filter
) {
495 vl_median_filter_cleanup(vmixer
->noise_reduction
.filter
);
496 FREE(vmixer
->noise_reduction
.filter
);
497 vmixer
->noise_reduction
.filter
= NULL
;
500 /* and create a new filter as needed */
501 if (vmixer
->noise_reduction
. enabled
&& vmixer
->noise_reduction
.level
> 0) {
502 vmixer
->noise_reduction
.filter
= MALLOC(sizeof(struct vl_median_filter
));
503 vl_median_filter_init(vmixer
->noise_reduction
.filter
, vmixer
->device
->context
,
504 vmixer
->video_width
, vmixer
->video_height
,
505 vmixer
->noise_reduction
.level
+ 1,
506 VL_MEDIAN_FILTER_CROSS
);
511 vlVdpVideoMixerUpdateSharpnessFilter(vlVdpVideoMixer
*vmixer
)
515 /* if present remove the old filter first */
516 if (vmixer
->sharpness
.filter
) {
517 vl_matrix_filter_cleanup(vmixer
->sharpness
.filter
);
518 FREE(vmixer
->sharpness
.filter
);
519 vmixer
->sharpness
.filter
= NULL
;
522 /* and create a new filter as needed */
523 if (vmixer
->sharpness
.enabled
&& vmixer
->sharpness
.value
!= 0.0f
) {
527 if (vmixer
->sharpness
.value
> 0.0f
) {
528 matrix
[0] = -1.0f
; matrix
[1] = -1.0f
; matrix
[2] = -1.0f
;
529 matrix
[3] = -1.0f
; matrix
[4] = 8.0f
; matrix
[5] = -1.0f
;
530 matrix
[6] = -1.0f
; matrix
[7] = -1.0f
; matrix
[8] = -1.0f
;
532 for (i
= 0; i
< 9; ++i
)
533 matrix
[i
] *= vmixer
->sharpness
.value
;
538 matrix
[0] = 1.0f
; matrix
[1] = 2.0f
; matrix
[2] = 1.0f
;
539 matrix
[3] = 2.0f
; matrix
[4] = 4.0f
; matrix
[5] = 2.0f
;
540 matrix
[6] = 1.0f
; matrix
[7] = 2.0f
; matrix
[8] = 1.0f
;
542 for (i
= 0; i
< 9; ++i
)
543 matrix
[i
] *= fabsf(vmixer
->sharpness
.value
) / 16.0f
;
545 matrix
[4] += 1.0f
- fabsf(vmixer
->sharpness
.value
);
548 vmixer
->sharpness
.filter
= MALLOC(sizeof(struct vl_matrix_filter
));
549 vl_matrix_filter_init(vmixer
->sharpness
.filter
, vmixer
->device
->context
,
550 vmixer
->video_width
, vmixer
->video_height
,
556 * Update the bicubic filter
559 vlVdpVideoMixerUpdateBicubicFilter(vlVdpVideoMixer
*vmixer
)
563 /* if present remove the old filter first */
564 if (vmixer
->bicubic
.filter
) {
565 vl_bicubic_filter_cleanup(vmixer
->bicubic
.filter
);
566 FREE(vmixer
->bicubic
.filter
);
567 vmixer
->bicubic
.filter
= NULL
;
569 /* and create a new filter as needed */
570 if (vmixer
->bicubic
.enabled
) {
571 vmixer
->bicubic
.filter
= MALLOC(sizeof(struct vl_bicubic_filter
));
572 vl_bicubic_filter_init(vmixer
->bicubic
.filter
, vmixer
->device
->context
,
573 vmixer
->video_width
, vmixer
->video_height
);
578 * Retrieve whether features were requested at creation time.
581 vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer
,
582 uint32_t feature_count
,
583 VdpVideoMixerFeature
const *features
,
584 VdpBool
*feature_supports
)
586 vlVdpVideoMixer
*vmixer
;
589 if (!(features
&& feature_supports
))
590 return VDP_STATUS_INVALID_POINTER
;
592 vmixer
= vlGetDataHTAB(mixer
);
594 return VDP_STATUS_INVALID_HANDLE
;
596 for (i
= 0; i
< feature_count
; ++i
) {
597 switch (features
[i
]) {
598 /* they are valid, but we doesn't support them */
599 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
:
600 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2
:
601 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3
:
602 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4
:
603 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5
:
604 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6
:
605 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7
:
606 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8
:
607 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9
:
608 case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
:
609 feature_supports
[i
] = false;
612 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
613 feature_supports
[i
] = vmixer
->deint
.supported
;
616 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
617 feature_supports
[i
] = vmixer
->sharpness
.supported
;
620 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
621 feature_supports
[i
] = vmixer
->noise_reduction
.supported
;
624 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
625 feature_supports
[i
] = vmixer
->luma_key
.supported
;
628 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
629 feature_supports
[i
] = vmixer
->bicubic
.supported
;
633 return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE
;
637 return VDP_STATUS_OK
;
641 * Enable or disable features.
644 vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer
,
645 uint32_t feature_count
,
646 VdpVideoMixerFeature
const *features
,
647 VdpBool
const *feature_enables
)
649 vlVdpVideoMixer
*vmixer
;
652 if (!(features
&& feature_enables
))
653 return VDP_STATUS_INVALID_POINTER
;
655 vmixer
= vlGetDataHTAB(mixer
);
657 return VDP_STATUS_INVALID_HANDLE
;
659 mtx_lock(&vmixer
->device
->mutex
);
660 for (i
= 0; i
< feature_count
; ++i
) {
661 switch (features
[i
]) {
662 /* they are valid, but we doesn't support them */
663 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
:
664 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2
:
665 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3
:
666 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4
:
667 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5
:
668 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6
:
669 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7
:
670 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8
:
671 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9
:
672 case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
:
675 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
676 vmixer
->deint
.enabled
= feature_enables
[i
];
677 vlVdpVideoMixerUpdateDeinterlaceFilter(vmixer
);
680 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
681 vmixer
->sharpness
.enabled
= feature_enables
[i
];
682 vlVdpVideoMixerUpdateSharpnessFilter(vmixer
);
685 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
686 vmixer
->noise_reduction
.enabled
= feature_enables
[i
];
687 vlVdpVideoMixerUpdateNoiseReductionFilter(vmixer
);
690 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
691 vmixer
->luma_key
.enabled
= feature_enables
[i
];
692 if (!debug_get_bool_option("G3DVL_NO_CSC", FALSE
))
693 if (!vl_compositor_set_csc_matrix(&vmixer
->cstate
, (const vl_csc_matrix
*)&vmixer
->csc
,
694 vmixer
->luma_key
.luma_min
, vmixer
->luma_key
.luma_max
)) {
695 mtx_unlock(&vmixer
->device
->mutex
);
696 return VDP_STATUS_ERROR
;
700 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
701 vmixer
->bicubic
.enabled
= feature_enables
[i
];
702 vlVdpVideoMixerUpdateBicubicFilter(vmixer
);
706 mtx_unlock(&vmixer
->device
->mutex
);
707 return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE
;
710 mtx_unlock(&vmixer
->device
->mutex
);
712 return VDP_STATUS_OK
;
716 * Retrieve whether features are enabled.
719 vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer
,
720 uint32_t feature_count
,
721 VdpVideoMixerFeature
const *features
,
722 VdpBool
*feature_enables
)
724 vlVdpVideoMixer
*vmixer
;
727 if (!(features
&& feature_enables
))
728 return VDP_STATUS_INVALID_POINTER
;
730 vmixer
= vlGetDataHTAB(mixer
);
732 return VDP_STATUS_INVALID_HANDLE
;
734 for (i
= 0; i
< feature_count
; ++i
) {
735 switch (features
[i
]) {
736 /* they are valid, but we doesn't support them */
737 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
738 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
:
739 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2
:
740 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3
:
741 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4
:
742 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5
:
743 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6
:
744 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7
:
745 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8
:
746 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9
:
747 case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
:
750 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
751 feature_enables
[i
] = vmixer
->sharpness
.enabled
;
754 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
755 feature_enables
[i
] = vmixer
->noise_reduction
.enabled
;
758 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
759 feature_enables
[i
] = vmixer
->luma_key
.enabled
;
762 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
763 feature_enables
[i
] = vmixer
->bicubic
.enabled
;
767 return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE
;
771 return VDP_STATUS_OK
;
775 * Set attribute values.
778 vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer
,
779 uint32_t attribute_count
,
780 VdpVideoMixerAttribute
const *attributes
,
781 void const *const *attribute_values
)
783 const VdpColor
*background_color
;
784 union pipe_color_union color
;
785 const float *vdp_csc
;
790 if (!(attributes
&& attribute_values
))
791 return VDP_STATUS_INVALID_POINTER
;
793 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
795 return VDP_STATUS_INVALID_HANDLE
;
797 mtx_lock(&vmixer
->device
->mutex
);
798 for (i
= 0; i
< attribute_count
; ++i
) {
799 switch (attributes
[i
]) {
800 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
801 background_color
= attribute_values
[i
];
802 color
.f
[0] = background_color
->red
;
803 color
.f
[1] = background_color
->green
;
804 color
.f
[2] = background_color
->blue
;
805 color
.f
[3] = background_color
->alpha
;
806 vl_compositor_set_clear_color(&vmixer
->cstate
, &color
);
808 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
809 vdp_csc
= attribute_values
[i
];
810 vmixer
->custom_csc
= !!vdp_csc
;
812 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_601
, NULL
, 1, &vmixer
->csc
);
814 memcpy(vmixer
->csc
, vdp_csc
, sizeof(vl_csc_matrix
));
815 if (!debug_get_bool_option("G3DVL_NO_CSC", FALSE
))
816 if (!vl_compositor_set_csc_matrix(&vmixer
->cstate
, (const vl_csc_matrix
*)&vmixer
->csc
,
817 vmixer
->luma_key
.luma_min
, vmixer
->luma_key
.luma_max
)) {
818 ret
= VDP_STATUS_ERROR
;
823 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
825 val
= *(float*)attribute_values
[i
];
826 if (val
< 0.0f
|| val
> 1.0f
) {
827 ret
= VDP_STATUS_INVALID_VALUE
;
831 vmixer
->noise_reduction
.level
= val
* 10;
832 vlVdpVideoMixerUpdateNoiseReductionFilter(vmixer
);
835 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
836 val
= *(float*)attribute_values
[i
];
837 if (val
< 0.0f
|| val
> 1.0f
) {
838 ret
= VDP_STATUS_INVALID_VALUE
;
841 vmixer
->luma_key
.luma_min
= val
;
842 if (!debug_get_bool_option("G3DVL_NO_CSC", FALSE
))
843 if (!vl_compositor_set_csc_matrix(&vmixer
->cstate
, (const vl_csc_matrix
*)&vmixer
->csc
,
844 vmixer
->luma_key
.luma_min
, vmixer
->luma_key
.luma_max
)) {
845 ret
= VDP_STATUS_ERROR
;
850 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
851 val
= *(float*)attribute_values
[i
];
852 if (val
< 0.0f
|| val
> 1.0f
) {
853 ret
= VDP_STATUS_INVALID_VALUE
;
856 vmixer
->luma_key
.luma_max
= val
;
857 if (!debug_get_bool_option("G3DVL_NO_CSC", FALSE
))
858 if (!vl_compositor_set_csc_matrix(&vmixer
->cstate
, (const vl_csc_matrix
*)&vmixer
->csc
,
859 vmixer
->luma_key
.luma_min
, vmixer
->luma_key
.luma_max
)) {
860 ret
= VDP_STATUS_ERROR
;
865 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
867 val
= *(float*)attribute_values
[i
];
868 if (val
< -1.0f
|| val
> 1.0f
) {
869 ret
= VDP_STATUS_INVALID_VALUE
;
873 vmixer
->sharpness
.value
= val
;
874 vlVdpVideoMixerUpdateSharpnessFilter(vmixer
);
877 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
878 if (*(uint8_t*)attribute_values
[i
] > 1) {
879 ret
= VDP_STATUS_INVALID_VALUE
;
882 vmixer
->skip_chroma_deint
= *(uint8_t*)attribute_values
[i
];
883 vlVdpVideoMixerUpdateDeinterlaceFilter(vmixer
);
886 ret
= VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
890 mtx_unlock(&vmixer
->device
->mutex
);
892 return VDP_STATUS_OK
;
894 mtx_unlock(&vmixer
->device
->mutex
);
899 * Retrieve parameter values given at creation time.
902 vlVdpVideoMixerGetParameterValues(VdpVideoMixer mixer
,
903 uint32_t parameter_count
,
904 VdpVideoMixerParameter
const *parameters
,
905 void *const *parameter_values
)
907 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
910 return VDP_STATUS_INVALID_HANDLE
;
912 if (!parameter_count
)
913 return VDP_STATUS_OK
;
914 if (!(parameters
&& parameter_values
))
915 return VDP_STATUS_INVALID_POINTER
;
916 for (i
= 0; i
< parameter_count
; ++i
) {
917 switch (parameters
[i
]) {
918 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
919 *(uint32_t*)parameter_values
[i
] = vmixer
->video_width
;
921 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
922 *(uint32_t*)parameter_values
[i
] = vmixer
->video_height
;
924 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
925 *(VdpChromaType
*)parameter_values
[i
] = PipeToChroma(vmixer
->chroma_format
);
927 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
928 *(uint32_t*)parameter_values
[i
] = vmixer
->max_layers
;
931 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
934 return VDP_STATUS_OK
;
938 * Retrieve current attribute values.
941 vlVdpVideoMixerGetAttributeValues(VdpVideoMixer mixer
,
942 uint32_t attribute_count
,
943 VdpVideoMixerAttribute
const *attributes
,
944 void *const *attribute_values
)
947 VdpCSCMatrix
**vdp_csc
;
949 if (!(attributes
&& attribute_values
))
950 return VDP_STATUS_INVALID_POINTER
;
952 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
954 return VDP_STATUS_INVALID_HANDLE
;
956 mtx_lock(&vmixer
->device
->mutex
);
957 for (i
= 0; i
< attribute_count
; ++i
) {
958 switch (attributes
[i
]) {
959 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
960 vl_compositor_get_clear_color(&vmixer
->cstate
, attribute_values
[i
]);
962 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
963 vdp_csc
= attribute_values
[i
];
964 if (!vmixer
->custom_csc
) {
968 memcpy(*vdp_csc
, vmixer
->csc
, sizeof(float)*12);
971 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
972 *(float*)attribute_values
[i
] = (float)vmixer
->noise_reduction
.level
/ 10.0f
;
975 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
976 *(float*)attribute_values
[i
] = vmixer
->luma_key
.luma_min
;
978 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
979 *(float*)attribute_values
[i
] = vmixer
->luma_key
.luma_max
;
981 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
982 *(float*)attribute_values
[i
] = vmixer
->sharpness
.value
;
984 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
985 *(uint8_t*)attribute_values
[i
] = vmixer
->skip_chroma_deint
;
988 mtx_unlock(&vmixer
->device
->mutex
);
989 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
992 mtx_unlock(&vmixer
->device
->mutex
);
993 return VDP_STATUS_OK
;
997 * Generate a color space conversion matrix.
1000 vlVdpGenerateCSCMatrix(VdpProcamp
*procamp
,
1001 VdpColorStandard standard
,
1002 VdpCSCMatrix
*csc_matrix
)
1004 enum VL_CSC_COLOR_STANDARD vl_std
;
1005 struct vl_procamp camp
;
1008 return VDP_STATUS_INVALID_POINTER
;
1011 case VDP_COLOR_STANDARD_ITUR_BT_601
: vl_std
= VL_CSC_COLOR_STANDARD_BT_601
; break;
1012 case VDP_COLOR_STANDARD_ITUR_BT_709
: vl_std
= VL_CSC_COLOR_STANDARD_BT_709
; break;
1013 case VDP_COLOR_STANDARD_SMPTE_240M
: vl_std
= VL_CSC_COLOR_STANDARD_SMPTE_240M
; break;
1014 default: return VDP_STATUS_INVALID_COLOR_STANDARD
;
1018 if (procamp
->struct_version
> VDP_PROCAMP_VERSION
)
1019 return VDP_STATUS_INVALID_STRUCT_VERSION
;
1020 camp
.brightness
= procamp
->brightness
;
1021 camp
.contrast
= procamp
->contrast
;
1022 camp
.saturation
= procamp
->saturation
;
1023 camp
.hue
= procamp
->hue
;
1026 vl_csc_get_matrix(vl_std
, procamp
? &camp
: NULL
, true, csc_matrix
);
1027 return VDP_STATUS_OK
;