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
;
52 unsigned max_width
, max_height
, i
;
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 pipe_mutex_lock(dev
->mutex
);
67 vl_compositor_init_state(&vmixer
->cstate
, dev
->context
);
69 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_601
, NULL
, true, &vmixer
->csc
);
70 if (!debug_get_bool_option("G3DVL_NO_CSC", FALSE
))
71 vl_compositor_set_csc_matrix(&vmixer
->cstate
, (const vl_csc_matrix
*)&vmixer
->csc
);
73 *mixer
= vlAddDataHTAB(vmixer
);
75 ret
= VDP_STATUS_ERROR
;
79 ret
= VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE
;
80 for (i
= 0; i
< feature_count
; ++i
) {
81 switch (features
[i
]) {
82 /* they are valid, but we doesn't support them */
83 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
:
84 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
85 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2
:
86 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3
:
87 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4
:
88 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5
:
89 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6
:
90 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7
:
91 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8
:
92 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9
:
93 case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
:
94 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
97 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
98 vmixer
->deint
.supported
= true;
101 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
102 vmixer
->sharpness
.supported
= true;
105 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
106 vmixer
->noise_reduction
.supported
= true;
109 default: goto no_params
;
113 vmixer
->chroma_format
= PIPE_VIDEO_CHROMA_FORMAT_420
;
114 ret
= VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
115 for (i
= 0; i
< parameter_count
; ++i
) {
116 switch (parameters
[i
]) {
117 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
118 vmixer
->video_width
= *(uint32_t*)parameter_values
[i
];
120 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
121 vmixer
->video_height
= *(uint32_t*)parameter_values
[i
];
123 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
124 vmixer
->chroma_format
= ChromaToPipe(*(VdpChromaType
*)parameter_values
[i
]);
126 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
127 vmixer
->max_layers
= *(uint32_t*)parameter_values
[i
];
129 default: goto no_params
;
132 ret
= VDP_STATUS_INVALID_VALUE
;
133 if (vmixer
->max_layers
> 4) {
134 VDPAU_MSG(VDPAU_WARN
, "[VDPAU] Max layers > 4 not supported\n", vmixer
->max_layers
);
137 max_width
= screen
->get_video_param(screen
, PIPE_VIDEO_PROFILE_UNKNOWN
,
138 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
, PIPE_VIDEO_CAP_MAX_WIDTH
);
139 max_height
= screen
->get_video_param(screen
, PIPE_VIDEO_PROFILE_UNKNOWN
,
140 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
, PIPE_VIDEO_CAP_MAX_HEIGHT
);
141 if (vmixer
->video_width
< 48 ||
142 vmixer
->video_width
> max_width
) {
143 VDPAU_MSG(VDPAU_WARN
, "[VDPAU] 48 < %u < %u not valid for width\n", vmixer
->video_width
, max_width
);
146 if (vmixer
->video_height
< 48 ||
147 vmixer
->video_height
> max_height
) {
148 VDPAU_MSG(VDPAU_WARN
, "[VDPAU] 48 < %u < %u not valid for height\n", vmixer
->video_height
, max_height
);
151 vmixer
->luma_key_min
= 0.f
;
152 vmixer
->luma_key_max
= 1.f
;
153 pipe_mutex_unlock(dev
->mutex
);
155 return VDP_STATUS_OK
;
158 vlRemoveDataHTAB(*mixer
);
161 vl_compositor_cleanup_state(&vmixer
->cstate
);
162 pipe_mutex_unlock(dev
->mutex
);
163 DeviceReference(&vmixer
->device
, NULL
);
169 * Destroy a VdpVideoMixer.
172 vlVdpVideoMixerDestroy(VdpVideoMixer mixer
)
174 vlVdpVideoMixer
*vmixer
;
176 vmixer
= vlGetDataHTAB(mixer
);
178 return VDP_STATUS_INVALID_HANDLE
;
180 pipe_mutex_lock(vmixer
->device
->mutex
);
182 vlVdpResolveDelayedRendering(vmixer
->device
, NULL
, NULL
);
184 vlRemoveDataHTAB(mixer
);
186 vl_compositor_cleanup_state(&vmixer
->cstate
);
188 if (vmixer
->deint
.filter
) {
189 vl_deint_filter_cleanup(vmixer
->deint
.filter
);
190 FREE(vmixer
->deint
.filter
);
193 if (vmixer
->noise_reduction
.filter
) {
194 vl_median_filter_cleanup(vmixer
->noise_reduction
.filter
);
195 FREE(vmixer
->noise_reduction
.filter
);
198 if (vmixer
->sharpness
.filter
) {
199 vl_matrix_filter_cleanup(vmixer
->sharpness
.filter
);
200 FREE(vmixer
->sharpness
.filter
);
202 pipe_mutex_unlock(vmixer
->device
->mutex
);
203 DeviceReference(&vmixer
->device
, NULL
);
207 return VDP_STATUS_OK
;
211 * Perform a video post-processing and compositing operation.
213 VdpStatus
vlVdpVideoMixerRender(VdpVideoMixer mixer
,
214 VdpOutputSurface background_surface
,
215 VdpRect
const *background_source_rect
,
216 VdpVideoMixerPictureStructure current_picture_structure
,
217 uint32_t video_surface_past_count
,
218 VdpVideoSurface
const *video_surface_past
,
219 VdpVideoSurface video_surface_current
,
220 uint32_t video_surface_future_count
,
221 VdpVideoSurface
const *video_surface_future
,
222 VdpRect
const *video_source_rect
,
223 VdpOutputSurface destination_surface
,
224 VdpRect
const *destination_rect
,
225 VdpRect
const *destination_video_rect
,
226 uint32_t layer_count
,
227 VdpLayer
const *layers
)
229 enum vl_compositor_deinterlace deinterlace
;
230 struct u_rect rect
, clip
, *prect
;
231 unsigned i
, layer
= 0;
232 struct pipe_video_buffer
*video_buffer
;
234 vlVdpVideoMixer
*vmixer
;
236 vlVdpOutputSurface
*dst
, *bg
= NULL
;
238 struct vl_compositor
*compositor
;
240 vmixer
= vlGetDataHTAB(mixer
);
242 return VDP_STATUS_INVALID_HANDLE
;
244 compositor
= &vmixer
->device
->compositor
;
246 surf
= vlGetDataHTAB(video_surface_current
);
248 return VDP_STATUS_INVALID_HANDLE
;
249 video_buffer
= surf
->video_buffer
;
251 if (surf
->device
!= vmixer
->device
)
252 return VDP_STATUS_HANDLE_DEVICE_MISMATCH
;
254 if (vmixer
->video_width
> video_buffer
->width
||
255 vmixer
->video_height
> video_buffer
->height
||
256 vmixer
->chroma_format
!= video_buffer
->chroma_format
)
257 return VDP_STATUS_INVALID_SIZE
;
259 if (layer_count
> vmixer
->max_layers
)
260 return VDP_STATUS_INVALID_VALUE
;
262 dst
= vlGetDataHTAB(destination_surface
);
264 return VDP_STATUS_INVALID_HANDLE
;
266 if (background_surface
!= VDP_INVALID_HANDLE
) {
267 bg
= vlGetDataHTAB(background_surface
);
269 return VDP_STATUS_INVALID_HANDLE
;
272 pipe_mutex_lock(vmixer
->device
->mutex
);
273 vlVdpResolveDelayedRendering(vmixer
->device
, NULL
, NULL
);
275 vl_compositor_clear_layers(&vmixer
->cstate
);
278 vl_compositor_set_rgba_layer(&vmixer
->cstate
, compositor
, layer
++, bg
->sampler_view
,
279 RectToPipe(background_source_rect
, &rect
), NULL
, NULL
);
281 switch (current_picture_structure
) {
282 case VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD
:
283 deinterlace
= VL_COMPOSITOR_BOB_TOP
;
286 case VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD
:
287 deinterlace
= VL_COMPOSITOR_BOB_BOTTOM
;
290 case VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME
:
291 deinterlace
= VL_COMPOSITOR_WEAVE
;
295 pipe_mutex_unlock(vmixer
->device
->mutex
);
296 return VDP_STATUS_INVALID_VIDEO_MIXER_PICTURE_STRUCTURE
;
299 if (deinterlace
!= VL_COMPOSITOR_WEAVE
&& vmixer
->deint
.enabled
&&
300 video_surface_past_count
> 1 && video_surface_future_count
> 0) {
301 vlVdpSurface
*prevprev
= vlGetDataHTAB(video_surface_past
[1]);
302 vlVdpSurface
*prev
= vlGetDataHTAB(video_surface_past
[0]);
303 vlVdpSurface
*next
= vlGetDataHTAB(video_surface_future
[0]);
304 if (prevprev
&& prev
&& next
&&
305 vl_deint_filter_check_buffers(vmixer
->deint
.filter
,
306 prevprev
->video_buffer
, prev
->video_buffer
, surf
->video_buffer
, next
->video_buffer
)) {
307 vl_deint_filter_render(vmixer
->deint
.filter
, prevprev
->video_buffer
,
308 prev
->video_buffer
, surf
->video_buffer
,
310 deinterlace
== VL_COMPOSITOR_BOB_BOTTOM
);
311 deinterlace
= VL_COMPOSITOR_WEAVE
;
312 video_buffer
= vmixer
->deint
.filter
->video_buffer
;
316 prect
= RectToPipe(video_source_rect
, &rect
);
320 rect
.x1
= surf
->templat
.width
;
321 rect
.y1
= surf
->templat
.height
;
324 vl_compositor_set_buffer_layer(&vmixer
->cstate
, compositor
, layer
, video_buffer
, prect
, NULL
, deinterlace
);
325 vl_compositor_set_layer_dst_area(&vmixer
->cstate
, layer
++, RectToPipe(destination_video_rect
, &rect
));
327 for (i
= 0; i
< layer_count
; ++i
) {
328 vlVdpOutputSurface
*src
= vlGetDataHTAB(layers
->source_surface
);
330 pipe_mutex_unlock(vmixer
->device
->mutex
);
331 return VDP_STATUS_INVALID_HANDLE
;
334 assert(layers
->struct_version
== VDP_LAYER_VERSION
);
336 vl_compositor_set_rgba_layer(&vmixer
->cstate
, compositor
, layer
, src
->sampler_view
,
337 RectToPipe(layers
->source_rect
, &rect
), NULL
, NULL
);
338 vl_compositor_set_layer_dst_area(&vmixer
->cstate
, layer
++, RectToPipe(layers
->destination_rect
, &rect
));
343 vl_compositor_set_dst_clip(&vmixer
->cstate
, RectToPipe(destination_rect
, &clip
));
344 if (!vmixer
->noise_reduction
.filter
&& !vmixer
->sharpness
.filter
)
345 vlVdpSave4DelayedRendering(vmixer
->device
, destination_surface
, &vmixer
->cstate
);
347 vl_compositor_render(&vmixer
->cstate
, compositor
, dst
->surface
, &dst
->dirty_area
, true);
349 /* applying the noise reduction after scaling is actually not very
350 clever, but currently we should avoid to copy around the image
352 if (vmixer
->noise_reduction
.filter
)
353 vl_median_filter_render(vmixer
->noise_reduction
.filter
,
354 dst
->sampler_view
, dst
->surface
);
356 if (vmixer
->sharpness
.filter
)
357 vl_matrix_filter_render(vmixer
->sharpness
.filter
,
358 dst
->sampler_view
, dst
->surface
);
360 pipe_mutex_unlock(vmixer
->device
->mutex
);
362 return VDP_STATUS_OK
;
366 vlVdpVideoMixerUpdateDeinterlaceFilter(vlVdpVideoMixer
*vmixer
)
368 struct pipe_context
*pipe
= vmixer
->device
->context
;
371 /* remove existing filter */
372 if (vmixer
->deint
.filter
) {
373 vl_deint_filter_cleanup(vmixer
->deint
.filter
);
374 FREE(vmixer
->deint
.filter
);
375 vmixer
->deint
.filter
= NULL
;
378 /* create a new filter if requested */
379 if (vmixer
->deint
.enabled
&& vmixer
->chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
) {
380 vmixer
->deint
.filter
= MALLOC(sizeof(struct vl_deint_filter
));
381 vmixer
->deint
.enabled
= vl_deint_filter_init(vmixer
->deint
.filter
, pipe
,
382 vmixer
->video_width
, vmixer
->video_height
,
383 vmixer
->skip_chroma_deint
, vmixer
->deint
.spatial
);
384 if (!vmixer
->deint
.enabled
) {
385 FREE(vmixer
->deint
.filter
);
391 * Update the noise reduction setting
394 vlVdpVideoMixerUpdateNoiseReductionFilter(vlVdpVideoMixer
*vmixer
)
398 /* if present remove the old filter first */
399 if (vmixer
->noise_reduction
.filter
) {
400 vl_median_filter_cleanup(vmixer
->noise_reduction
.filter
);
401 FREE(vmixer
->noise_reduction
.filter
);
402 vmixer
->noise_reduction
.filter
= NULL
;
405 /* and create a new filter as needed */
406 if (vmixer
->noise_reduction
. enabled
&& vmixer
->noise_reduction
.level
> 0) {
407 vmixer
->noise_reduction
.filter
= MALLOC(sizeof(struct vl_median_filter
));
408 vl_median_filter_init(vmixer
->noise_reduction
.filter
, vmixer
->device
->context
,
409 vmixer
->video_width
, vmixer
->video_height
,
410 vmixer
->noise_reduction
.level
+ 1,
411 VL_MEDIAN_FILTER_CROSS
);
416 vlVdpVideoMixerUpdateSharpnessFilter(vlVdpVideoMixer
*vmixer
)
420 /* if present remove the old filter first */
421 if (vmixer
->sharpness
.filter
) {
422 vl_matrix_filter_cleanup(vmixer
->sharpness
.filter
);
423 FREE(vmixer
->sharpness
.filter
);
424 vmixer
->sharpness
.filter
= NULL
;
427 /* and create a new filter as needed */
428 if (vmixer
->sharpness
.enabled
&& vmixer
->sharpness
.value
!= 0.0f
) {
432 if (vmixer
->sharpness
.value
> 0.0f
) {
433 matrix
[0] = -1.0f
; matrix
[1] = -1.0f
; matrix
[2] = -1.0f
;
434 matrix
[3] = -1.0f
; matrix
[4] = 8.0f
; matrix
[5] = -1.0f
;
435 matrix
[6] = -1.0f
; matrix
[7] = -1.0f
; matrix
[8] = -1.0f
;
437 for (i
= 0; i
< 9; ++i
)
438 matrix
[i
] *= vmixer
->sharpness
.value
;
443 matrix
[0] = 1.0f
; matrix
[1] = 2.0f
; matrix
[2] = 1.0f
;
444 matrix
[3] = 2.0f
; matrix
[4] = 4.0f
; matrix
[5] = 2.0f
;
445 matrix
[6] = 1.0f
; matrix
[7] = 2.0f
; matrix
[8] = 1.0f
;
447 for (i
= 0; i
< 9; ++i
)
448 matrix
[i
] *= fabsf(vmixer
->sharpness
.value
) / 16.0f
;
450 matrix
[4] += 1.0f
- fabsf(vmixer
->sharpness
.value
);
453 vmixer
->sharpness
.filter
= MALLOC(sizeof(struct vl_matrix_filter
));
454 vl_matrix_filter_init(vmixer
->sharpness
.filter
, vmixer
->device
->context
,
455 vmixer
->video_width
, vmixer
->video_height
,
461 * Retrieve whether features were requested at creation time.
464 vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer
,
465 uint32_t feature_count
,
466 VdpVideoMixerFeature
const *features
,
467 VdpBool
*feature_supports
)
469 vlVdpVideoMixer
*vmixer
;
472 if (!(features
&& feature_supports
))
473 return VDP_STATUS_INVALID_POINTER
;
475 vmixer
= vlGetDataHTAB(mixer
);
477 return VDP_STATUS_INVALID_HANDLE
;
479 for (i
= 0; i
< feature_count
; ++i
) {
480 switch (features
[i
]) {
481 /* they are valid, but we doesn't support them */
482 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
:
483 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
484 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2
:
485 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3
:
486 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4
:
487 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5
:
488 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6
:
489 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7
:
490 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8
:
491 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9
:
492 case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
:
493 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
494 feature_supports
[i
] = false;
497 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
498 feature_supports
[i
] = vmixer
->deint
.supported
;
501 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
502 feature_supports
[i
] = vmixer
->sharpness
.supported
;
505 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
506 feature_supports
[i
] = vmixer
->noise_reduction
.supported
;
510 return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE
;
514 return VDP_STATUS_OK
;
518 * Enable or disable features.
521 vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer
,
522 uint32_t feature_count
,
523 VdpVideoMixerFeature
const *features
,
524 VdpBool
const *feature_enables
)
526 vlVdpVideoMixer
*vmixer
;
529 if (!(features
&& feature_enables
))
530 return VDP_STATUS_INVALID_POINTER
;
532 vmixer
= vlGetDataHTAB(mixer
);
534 return VDP_STATUS_INVALID_HANDLE
;
536 pipe_mutex_lock(vmixer
->device
->mutex
);
537 for (i
= 0; i
< feature_count
; ++i
) {
538 switch (features
[i
]) {
539 /* they are valid, but we doesn't support them */
540 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
:
541 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
542 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2
:
543 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3
:
544 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4
:
545 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5
:
546 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6
:
547 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7
:
548 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8
:
549 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9
:
550 case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
:
551 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
554 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
555 vmixer
->deint
.enabled
= feature_enables
[i
];
556 vlVdpVideoMixerUpdateDeinterlaceFilter(vmixer
);
559 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
560 vmixer
->sharpness
.enabled
= feature_enables
[i
];
561 vlVdpVideoMixerUpdateSharpnessFilter(vmixer
);
564 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
565 vmixer
->noise_reduction
.enabled
= feature_enables
[i
];
566 vlVdpVideoMixerUpdateNoiseReductionFilter(vmixer
);
570 pipe_mutex_unlock(vmixer
->device
->mutex
);
571 return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE
;
574 pipe_mutex_unlock(vmixer
->device
->mutex
);
576 return VDP_STATUS_OK
;
580 * Retrieve whether features are enabled.
583 vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer
,
584 uint32_t feature_count
,
585 VdpVideoMixerFeature
const *features
,
586 VdpBool
*feature_enables
)
588 vlVdpVideoMixer
*vmixer
;
591 if (!(features
&& feature_enables
))
592 return VDP_STATUS_INVALID_POINTER
;
594 vmixer
= vlGetDataHTAB(mixer
);
596 return VDP_STATUS_INVALID_HANDLE
;
598 for (i
= 0; i
< feature_count
; ++i
) {
599 switch (features
[i
]) {
600 /* they are valid, but we doesn't support them */
601 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
602 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
:
603 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
604 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2
:
605 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3
:
606 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4
:
607 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5
:
608 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6
:
609 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7
:
610 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8
:
611 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9
:
612 case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
:
613 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
616 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
617 feature_enables
[i
] = vmixer
->sharpness
.enabled
;
620 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
621 feature_enables
[i
] = vmixer
->noise_reduction
.enabled
;
625 return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE
;
629 return VDP_STATUS_OK
;
633 * Set attribute values.
636 vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer
,
637 uint32_t attribute_count
,
638 VdpVideoMixerAttribute
const *attributes
,
639 void const *const *attribute_values
)
641 const VdpColor
*background_color
;
642 union pipe_color_union color
;
643 const float *vdp_csc
;
648 if (!(attributes
&& attribute_values
))
649 return VDP_STATUS_INVALID_POINTER
;
651 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
653 return VDP_STATUS_INVALID_HANDLE
;
655 pipe_mutex_lock(vmixer
->device
->mutex
);
656 for (i
= 0; i
< attribute_count
; ++i
) {
657 switch (attributes
[i
]) {
658 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
659 background_color
= attribute_values
[i
];
660 color
.f
[0] = background_color
->red
;
661 color
.f
[1] = background_color
->green
;
662 color
.f
[2] = background_color
->blue
;
663 color
.f
[3] = background_color
->alpha
;
664 vl_compositor_set_clear_color(&vmixer
->cstate
, &color
);
666 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
667 vdp_csc
= attribute_values
[i
];
668 vmixer
->custom_csc
= !!vdp_csc
;
670 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_601
, NULL
, 1, &vmixer
->csc
);
672 memcpy(vmixer
->csc
, vdp_csc
, sizeof(vl_csc_matrix
));
673 if (!debug_get_bool_option("G3DVL_NO_CSC", FALSE
))
674 vl_compositor_set_csc_matrix(&vmixer
->cstate
, (const vl_csc_matrix
*)&vmixer
->csc
);
677 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
679 val
= *(float*)attribute_values
[i
];
680 if (val
< 0.f
|| val
> 1.f
) {
681 ret
= VDP_STATUS_INVALID_VALUE
;
685 vmixer
->noise_reduction
.level
= val
* 10;
686 vlVdpVideoMixerUpdateNoiseReductionFilter(vmixer
);
689 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
690 val
= *(float*)attribute_values
[i
];
691 if (val
< 0.f
|| val
> 1.f
) {
692 ret
= VDP_STATUS_INVALID_VALUE
;
695 vmixer
->luma_key_min
= val
;
697 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
698 val
= *(float*)attribute_values
[i
];
699 if (val
< 0.f
|| val
> 1.f
) {
700 ret
= VDP_STATUS_INVALID_VALUE
;
703 vmixer
->luma_key_max
= val
;
706 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
708 val
= *(float*)attribute_values
[i
];
709 if (val
< -1.f
|| val
> 1.f
) {
710 ret
= VDP_STATUS_INVALID_VALUE
;
714 vmixer
->sharpness
.value
= val
;
715 vlVdpVideoMixerUpdateSharpnessFilter(vmixer
);
718 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
719 if (*(uint8_t*)attribute_values
[i
] > 1) {
720 ret
= VDP_STATUS_INVALID_VALUE
;
723 vmixer
->skip_chroma_deint
= *(uint8_t*)attribute_values
[i
];
724 vlVdpVideoMixerUpdateDeinterlaceFilter(vmixer
);
727 ret
= VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
731 pipe_mutex_unlock(vmixer
->device
->mutex
);
733 return VDP_STATUS_OK
;
735 pipe_mutex_unlock(vmixer
->device
->mutex
);
740 * Retrieve parameter values given at creation time.
743 vlVdpVideoMixerGetParameterValues(VdpVideoMixer mixer
,
744 uint32_t parameter_count
,
745 VdpVideoMixerParameter
const *parameters
,
746 void *const *parameter_values
)
748 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
751 return VDP_STATUS_INVALID_HANDLE
;
753 if (!parameter_count
)
754 return VDP_STATUS_OK
;
755 if (!(parameters
&& parameter_values
))
756 return VDP_STATUS_INVALID_POINTER
;
757 for (i
= 0; i
< parameter_count
; ++i
) {
758 switch (parameters
[i
]) {
759 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
760 *(uint32_t*)parameter_values
[i
] = vmixer
->video_width
;
762 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
763 *(uint32_t*)parameter_values
[i
] = vmixer
->video_height
;
765 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
766 *(VdpChromaType
*)parameter_values
[i
] = PipeToChroma(vmixer
->chroma_format
);
768 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
769 *(uint32_t*)parameter_values
[i
] = vmixer
->max_layers
;
772 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
775 return VDP_STATUS_OK
;
779 * Retrieve current attribute values.
782 vlVdpVideoMixerGetAttributeValues(VdpVideoMixer mixer
,
783 uint32_t attribute_count
,
784 VdpVideoMixerAttribute
const *attributes
,
785 void *const *attribute_values
)
788 VdpCSCMatrix
**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 pipe_mutex_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 vl_compositor_get_clear_color(&vmixer
->cstate
, attribute_values
[i
]);
803 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
804 vdp_csc
= attribute_values
[i
];
805 if (!vmixer
->custom_csc
) {
809 memcpy(*vdp_csc
, vmixer
->csc
, sizeof(float)*12);
812 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
813 *(float*)attribute_values
[i
] = (float)vmixer
->noise_reduction
.level
/ 10.0f
;
816 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
817 *(float*)attribute_values
[i
] = vmixer
->luma_key_min
;
819 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
820 *(float*)attribute_values
[i
] = vmixer
->luma_key_max
;
822 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
823 *(float*)attribute_values
[i
] = vmixer
->sharpness
.value
;
825 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
826 *(uint8_t*)attribute_values
[i
] = vmixer
->skip_chroma_deint
;
829 pipe_mutex_unlock(vmixer
->device
->mutex
);
830 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
833 pipe_mutex_unlock(vmixer
->device
->mutex
);
834 return VDP_STATUS_OK
;
838 * Generate a color space conversion matrix.
841 vlVdpGenerateCSCMatrix(VdpProcamp
*procamp
,
842 VdpColorStandard standard
,
843 VdpCSCMatrix
*csc_matrix
)
845 enum VL_CSC_COLOR_STANDARD vl_std
;
846 struct vl_procamp camp
;
849 return VDP_STATUS_INVALID_POINTER
;
852 case VDP_COLOR_STANDARD_ITUR_BT_601
: vl_std
= VL_CSC_COLOR_STANDARD_BT_601
; break;
853 case VDP_COLOR_STANDARD_ITUR_BT_709
: vl_std
= VL_CSC_COLOR_STANDARD_BT_709
; break;
854 case VDP_COLOR_STANDARD_SMPTE_240M
: vl_std
= VL_CSC_COLOR_STANDARD_SMPTE_240M
; break;
855 default: return VDP_STATUS_INVALID_COLOR_STANDARD
;
859 if (procamp
->struct_version
> VDP_PROCAMP_VERSION
)
860 return VDP_STATUS_INVALID_STRUCT_VERSION
;
861 camp
.brightness
= procamp
->brightness
;
862 camp
.contrast
= procamp
->contrast
;
863 camp
.saturation
= procamp
->saturation
;
864 camp
.hue
= procamp
->hue
;
867 vl_csc_get_matrix(vl_std
, procamp
? &camp
: NULL
, true, csc_matrix
);
868 return VDP_STATUS_OK
;