2 * Copyright (c) 2007-2011 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \brief The video processing API
29 * This file contains the \ref api_vpp "Video processing API".
40 * \defgroup api_vpp Video processing API
44 * The video processing API uses the same paradigm as for decoding:
45 * - Query for supported capabilities;
46 * - Set up a video processing pipeline;
47 * - Send video processing parameters through VA buffers.
49 * \section api_vpp_caps Query for supported capabilities
51 * Checking whether video processing is supported can be performed
52 * with vaQueryConfigEntrypoints() and the profile argument set to
56 * VAEntrypoint *entrypoints;
57 * int i, num_entrypoints, supportsVideoProcessing = 0;
59 * num_entrypoints = vaMaxNumEntrypoints();
60 * entrypoints = malloc(num_entrypoints * sizeof(entrypoints[0]);
61 * vaQueryConfigEntrypoints(va_dpy, VAProfileNone,
62 * entrypoints, &num_entrypoints);
64 * for (i = 0; !supportsVideoProcessing && i < num_entrypoints; i++) {
65 * if (entrypoints[i] == VAEntrypointVideoProc)
66 * supportsVideoProcessing = 1;
70 * Then, video processing pipeline capabilities, i.e. which video
71 * filters does the driver support, can be checked with the
72 * vaQueryVideoProcPipelineCaps() function.
75 * VAProcPipelineCap pipeline_caps[VAProcFilterCount];
76 * unsigned int num_pipeline_caps = VAProcFilterCount;
78 * // num_pipeline_caps shall be initialized to the length of the array
79 * vaQueryVideoProcPipelineCaps(va_dpy, vpp_ctx, &pipe_caps, &num_pipeline_caps);
82 * Finally, individual filter capabilities can be checked with
83 * vaQueryVideoProcFilterCaps().
86 * VAProcFilterCap denoise_caps;
87 * unsigned int num_denoise_caps = 1;
88 * vaQueryVideoProcFilterCaps(va_dpy, vpp_ctx,
89 * VAProcFilterNoiseReduction,
90 * &denoise_caps, &num_denoise_caps
93 * VAProcFilterCapDeinterlacing deinterlacing_caps[VAProcDeinterlacingCount];
94 * unsigned int num_deinterlacing_caps = VAProcDeinterlacingCount;
95 * vaQueryVideoProcFilterCaps(va_dpy, vpp_ctx,
96 * VAProcFilterDeinterlacing,
97 * &deinterlacing_caps, &num_deinterlacing_caps
101 * \section api_vpp_setup Set up a video processing pipeline
103 * A video processing pipeline buffer is created for each source
104 * surface we want to process. However, buffers holding filter
105 * parameters can be created once and for all. Rationale is to avoid
106 * multiple creation/destruction chains of filter buffers and also
107 * because filter parameters generally won't change frame after
108 * frame. e.g. this makes it possible to implement a checkerboard of
109 * videos where the same filters are applied to each video source.
111 * The general control flow is demonstrated by the following pseudo-code:
114 * VABufferID denoise_filter, deint_filter;
115 * VABufferID filter_bufs[VAProcFilterCount];
116 * unsigned int num_filter_bufs;
118 * for (i = 0; i < num_pipeline_caps; i++) {
119 * VAProcPipelineCap * const pipeline_cap = &pipeline_caps[i];
120 * switch (pipeline_cap->type) {
121 * case VAProcFilterNoiseReduction: { // Noise reduction filter
122 * VAProcFilterParameterBuffer denoise;
123 * denoise.type = VAProcFilterNoiseReduction;
124 * denoise.value = 0.5;
125 * vaCreateBuffer(va_dpy, vpp_ctx,
126 * VAProcFilterParameterBufferType, sizeof(denoise), 1,
127 * &denoise, &denoise_filter
129 * filter_bufs[num_filter_bufs++] = denoise_filter;
133 * case VAProcFilterDeinterlacing: // Motion-adaptive deinterlacing
134 * for (j = 0; j < num_deinterlacing_caps; j++) {
135 * VAProcFilterCapDeinterlacing * const cap = &deinterlacing_caps[j];
136 * if (cap->type != VAProcDeinterlacingMotionAdaptive)
139 * VAProcFilterParameterBufferDeinterlacing deint;
140 * deint.type = VAProcFilterDeinterlacing;
141 * deint.algorithm = VAProcDeinterlacingMotionAdaptive;
142 * deint.forward_references =
143 * malloc(cap->num_forward_references * sizeof(VASurfaceID));
144 * deint.num_forward_references = 0; // none for now
145 * deint.backward_references =
146 * malloc(cap->num_backward_references * sizeof(VASurfaceID));
147 * deint.num_backward_references = 0; // none for now
148 * vaCreateBuffer(va_dpy, vpp_ctx,
149 * VAProcFilterParameterBufferType, sizeof(deint), 1,
150 * &deint, &deint_filter
152 * filter_bufs[num_filter_bufs++] = deint_filter;
158 * \section api_vpp_submit Send video processing parameters through VA buffers
160 * Video processing pipeline parameters are submitted for each source
161 * surface to process. Video filter parameters can also change, per-surface.
162 * e.g. the list of reference frames used for deinterlacing.
165 * foreach (iteration) {
166 * vaBeginPicture(va_dpy, vpp_ctx, vpp_surface);
167 * foreach (surface) {
168 * VARectangle output_region;
169 * VABufferID pipeline_buf;
170 * VAProcPipelineParameterBuffer *pipeline_param;
172 * vaCreateBuffer(va_dpy, vpp_ctx,
173 * VAProcPipelineParameterBuffer, sizeof(*pipeline_param), 1,
174 * NULL, &pipeline_param
177 * // Setup output region for this surface
178 * // e.g. upper left corner for the first surface
179 * output_region.x = BORDER;
180 * output_region.y = BORDER;
181 * output_region.width =
182 * (vpp_surface_width - (Nx_surfaces + 1) * BORDER) / Nx_surfaces;
183 * output_region.height =
184 * (vpp_surface_height - (Ny_surfaces + 1) * BORDER) / Ny_surfaces;
186 * vaMapBuffer(va_dpy, pipeline_buf, &pipeline_param);
187 * pipeline_param->surface = surface;
188 * pipeline_param->surface_region = NULL;
189 * pipeline_param->output_region = &output_region;
190 * pipeline_param->output_background_color = 0;
191 * if (first surface to render)
192 * pipeline_param->output_background_color = 0xff000000; // black
193 * pipeline_param->flags = VA_FILTER_SCALING_HQ;
194 * pipeline_param->filters = filter_bufs;
195 * pipeline_param->num_filters = num_filter_bufs;
196 * vaUnmapBuffer(va_dpy, pipeline_buf);
198 * VAProcFilterParameterBufferDeinterlacing *deint_param;
199 * vaMapBuffer(va_dpy, deint_filter, &deint_param);
200 * // Update deinterlacing parameters, if necessary
202 * vaUnmapBuffer(va_dpy, deint_filter);
205 * vaRenderPicture(va_dpy, vpp_ctx, &pipeline_buf, 1);
207 * vaEndPicture(va_dpy, vpp_ctx);
213 /* Surfaces composition */
214 VAProcPipelineParameterBuffer *pipeline_param;
215 pipeline_param->surface = VA_INVALID_SURFACE;
216 pipeline_param->surface_region = surface_region;
217 pipeline_param->output_region = output_region;
218 pipeline_param->output_background_color = output_background_color;
219 pipeline_param->flags = VA_FILTER_SCALING_HQ;
220 pipeline_param->filters = filters;
221 pipeline_param->num_filters = num_filters;
223 VAProcPipelineID vpp_proc;
224 VAProcPipelineParameterBuffer
226 VAProcFilterParameterBuffer filter;
228 vaBeginPicture(va_dpy, vpp_context, vpp_surface);
230 vaRenderPicture(va_dpy,
232 vaEndPicture(va_dpy, vpp_context);
235 /** \brief Video filter types. */
236 typedef enum _VAProcFilterType {
237 VAProcFilterNone = 0,
238 /** \brief Noise reduction filter. */
239 VAProcFilterNoiseReduction,
240 /** \brief Deinterlacing filter. */
241 VAProcFilterDeinterlacing,
242 /** \brief Sharpening filter. */
243 VAProcFilterSharpening,
244 /** \brief Color balance parameters. */
245 VAProcFilterColorBalance,
246 /** \brief Color standard conversion. */
247 VAProcFilterColorStandard,
248 /** \brief Max number of video filters. */
252 /** \brief Deinterlacing types. */
253 typedef enum _VAProcDeinterlacingType {
254 VAProcDeinterlacingNone = 0,
255 /** \brief Bob deinterlacing algorithm. */
256 VAProcDeinterlacingBob,
257 /** \brief Weave deinterlacing algorithm. */
258 VAProcDeinterlacingWeave,
259 /** \brief Motion adaptive deinterlacing algorithm. */
260 VAProcDeinterlacingMotionAdaptive,
261 /** \brief Motion compensated deinterlacing algorithm. */
262 VAProcDeinterlacingMotionCompensated,
263 /** \brief Max number of deinterlacing algorithms. */
264 VAProcDeinterlacingCount
265 } VAProcDeinterlacingType;
267 /** \brief Color balance types. */
268 typedef enum _VAProcColorBalanceType {
269 VAProcColorBalanceNone = 0,
271 VAProcColorBalanceHue,
272 /** \brief Saturation. */
273 VAProcColorBalanceSaturation,
274 /** \brief Brightness. */
275 VAProcColorBalanceBrightness,
276 /** \brief Contrast. */
277 VAProcColorBalanceContrast,
278 /** \brief Max number of color balance operations. */
279 VAProcColorBalanceCount
280 } VAProcColorBalanceType;
282 /** \brief Color standard types. */
283 typedef enum _VAProcColorStandardType {
284 VAProcColorStandardNone = 0,
285 /** \brief ITU-R BT.601. */
286 VAProcColorStandardBT601,
287 /** \brief ITU-R BT.709. */
288 VAProcColorStandardBT709,
289 /** \brief ITU-R BT.470-2 System M. */
290 VAProcColorStandardBT470M,
291 /** \brief ITU-R BT.470-2 System B, G. */
292 VAProcColorStandardBT470BG,
293 /** \brief SMPTE-170M. */
294 VAProcColorStandardSMPTE170M,
295 /** \brief SMPTE-240M. */
296 VAProcColorStandardSMPTE240M,
297 /** \brief Generic film. */
298 VAProcColorStandardGenericFilm,
299 } VAProcColorStandardType;
301 /** @name Video filter flags */
303 /** \brief Specifies whether the filter shall be present in the pipeline. */
304 #define VA_PROC_FILTER_MANDATORY 0x00000001
307 /** \brief Video processing pipeline capabilities. */
308 typedef struct _VAProcPipelineCap {
309 /** \brief Video filter type. */
310 VAProcFilterType type;
311 /** \brief Video filter flags. See video filter flags. */
315 /** \brief Specification of values supported by the filter. */
316 typedef struct _VAProcFilterValueRange {
317 /** \brief Minimum value supported, inclusive. */
319 /** \brief Maximum value supported, inclusive. */
321 /** \brief Default value. */
323 /** \brief Step value that alters the filter behaviour in a sensible way. */
325 } VAProcFilterValueRange;
327 /** \brief Video processing pipeline configuration. */
328 struct _VAProcPipelineParameterBuffer {
329 /** \brief Source surface ID. */
332 * \brief Region within the source surface to be processed.
334 * Pointer to a #VARectangle defining the region within the source
335 * surface to be processed. If NULL, \c surface_region implies the
338 const VARectangle *surface_region;
340 * \brief Region within the output surface.
342 * Pointer to a #VARectangle defining the region within the output
343 * surface that receives the processed pixels. If NULL, \c output_region
344 * implies the whole surface.
346 * Note that any pixels residing outside the specified region will
347 * be filled in with the \ref output_background_color.
349 const VARectangle *output_region;
351 * \brief Background color.
353 * Background color used to fill in pixels that reside outside of the
354 * specified \ref output_region. The color is specified in ARGB format:
355 * [31:24] alpha, [23:16] red, [15:8] green, [7:0] blue.
357 unsigned int output_background_color;
359 * \brief Pipeline flags. See vaPutSurface() flags.
362 * - Bob-deinterlacing: \c VA_FRAME_PICTURE, \c VA_TOP_FIELD,
363 * \c VA_BOTTOM_FIELD. Note that any deinterlacing filter
364 * (#VAProcFilterDeinterlacing) will override those flags.
365 * - Color space conversion: \c VA_SRC_BT601, \c VA_SRC_BT709,
366 * \c VA_SRC_SMPTE_240. Note that any color standard filter
367 * (#VAProcFilterColorStandard) will override those flags.
368 * - Scaling: \c VA_FILTER_SCALING_DEFAULT, \c VA_FILTER_SCALING_FAST,
369 * \c VA_FILTER_SCALING_HQ, \c VA_FILTER_SCALING_NL_ANAMORPHIC.
373 * \brief Array of filters to apply to the surface.
375 * The list of filters shall be ordered in the same way the driver expects
376 * them. i.e. as was returned from vaQueryVideoProcPipelineCaps().
377 * Otherwise, a #VA_STATUS_ERROR_INVALID_FILTER_CHAIN is returned
378 * from vaRenderPicture() with this buffer.
380 * #VA_STATUS_ERROR_UNSUPPORTED_FILTER is returned if the list
381 * contains an unsupported filter.
383 * Note: no filter buffer is destroyed after a call to vaRenderPicture(),
384 * only this pipeline buffer will be destroyed as per the core API
385 * specification. This allows for flexibility in re-using the filter for
386 * other surfaces to be processed.
389 /** \brief Actual number of filters. */
390 unsigned int num_filters;
391 } VAProcPipelineParameterBuffer;
394 * \brief Filter parameter buffer base.
396 * This is a helper structure used by driver implementations only.
397 * Users are not supposed to allocate filter parameter buffers of this
400 typedef struct _VAProcFilterParameterBufferBase {
401 /** \brief Filter type. */
402 VAProcFilterType type;
403 } VAProcFilterParameterBufferBase;
406 * \brief Default filter parametrization.
408 * Unless there is a filter-specific parameter buffer,
409 * #VAProcFilterParameterBuffer is the default type to use.
411 typedef struct _VAProcFilterParameterBuffer {
412 /** \brief Filter type. */
413 VAProcFilterType type;
415 /* XXX: use VAGenericValue? */
417 } VAProcFilterParameterBuffer;
419 /** \brief Deinterlacing filter parametrization. */
420 typedef struct _VAProcFilterParameterBufferDeinterlacing {
421 /** \brief Filter type. Shall be set to #VAProcFilterDeinterlacing. */
422 VAProcFilterType type;
423 /** \brief Deinterlacing algorithm. */
424 VAProcDeinterlacingType algorithm;
425 /** \brief Array of forward reference frames. */
426 VASurfaceID *forward_references;
427 /** \brief Number of forward reference frames that were supplied. */
428 unsigned int num_forward_references;
429 /** \brief Array of backward reference frames. */
430 VASurfaceID *backward_references;
431 /** \brief Number of backward reference frames that were supplied. */
432 unsigned int num_backward_references;
433 } VAProcFilterParameterBufferDeinterlacing;
436 * \brief Color balance filter parametrization.
438 * This buffer defines color balance attributes. A VA buffer can hold
439 * several color balance attributes by creating a VA buffer of desired
440 * number of elements. This can be achieved by the following pseudo-code:
443 * enum { kHue, kSaturation, kBrightness, kContrast };
445 * // Initial color balance parameters
446 * static const VAProcFilterParameterBufferColorBalance colorBalanceParams[4] =
449 * { VAProcFilterColorBalance, VAProcColorBalanceHue, 0.5 },
451 * { VAProcFilterColorBalance, VAProcColorBalanceSaturation, 0.5 },
453 * { VAProcFilterColorBalance, VAProcColorBalanceBrightness, 0.5 },
455 * { VAProcFilterColorBalance, VAProcColorBalanceSaturation, 0.5 }
459 * VABufferID colorBalanceBuffer;
460 * vaCreateBuffer(va_dpy, vpp_ctx,
461 * VAProcFilterParameterBufferType, sizeof(*pColorBalanceParam), 4,
462 * colorBalanceParams,
463 * &colorBalanceBuffer
466 * VAProcFilterParameterBufferColorBalance *pColorBalanceParam;
467 * vaMapBuffer(va_dpy, colorBalanceBuffer, &pColorBalanceParam);
469 * // Change brightness only
470 * pColorBalanceBuffer[kBrightness].value = 0.75;
472 * vaUnmapBuffer(va_dpy, colorBalanceBuffer);
475 typedef struct _VAProcFilterParameterBufferColorBalance {
476 /** \brief Filter type. Shall be set to #VAProcFilterColorBalance. */
477 VAProcFilterType type;
478 /** \brief Color balance attribute. */
479 VAProcColorBalanceType attrib;
480 /** \brief Color balance value. */
482 } VAProcFilterParameterBufferColorBalance;
484 /** \brief Color standard filter parametrization. */
485 typedef struct _VAProcFilterParameterBufferColorStandard {
486 /** \brief Filter type. Shall be set to #VAProcFilterColorStandard. */
487 VAProcFilterType type;
488 /** \brief Color standard to use. */
489 VAProcColorStandardType standard;
490 } VAProcFilterParameterBufferColorStandard;
493 * \brief Default filter cap specification (single range value).
495 * Unless there is a filter-specific cap structure, #VAProcFilterCap is the
496 * default type to use for output caps from vaQueryVideoProcFilterCaps().
498 typedef struct _VAProcFilterCap {
499 /** \brief Range of supported values for the filter. */
500 VAProcFilterValueRange range;
503 /** \brief Capabilities specification for the deinterlacing filter. */
504 typedef struct _VAProcFilterCapDeinterlacing {
505 /** \brief Deinterlacing algorithm. */
506 VAProcDeinterlacingType type;
507 /** \brief Number of forward references needed for deinterlacing. */
508 unsigned int num_forward_references;
509 /** \brief Number of backward references needed for deinterlacing. */
510 unsigned int num_backward_references;
511 } VAProcFilterCapDeinterlacing;
513 /** \brief Capabilities specification for the color balance filter. */
514 typedef struct _VAProcFilterCapColorBalance {
515 /** \brief Color balance operation. */
516 VAProcColorBalanceType type;
517 /** \brief Range of supported values for the specified operation. */
518 VAProcFilterValueRange range;
519 } VAProcFilterCapColorBalance;
521 /** \brief Capabilities specification for the color standard filter. */
522 typedef struct _VAProcFilterCapColorStandard {
523 /** \brief Color standard type. */
524 VAProcColorStandardType type;
525 } VAProcFilterCapColorStandard;
528 * \brief Queries video processing pipeline capabilities.
530 * This function returns the list of video processing filters supported
531 * by the driver. The \c pipeline_caps array is allocated by the user and
532 * \c num_pipeline_caps shall be initialized to the number of allocated
533 * elements in that array. Upon successful return, the actual number
534 * of filters will be overwritten into \c num_pipeline_caps. Otherwise,
535 * \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned and \c num_pipeline_caps
536 * is adjusted to the number of elements that would be returned if enough
537 * space was available.
539 * The list of video processing filters supported by the driver shall
540 * be ordered in the way they can be iteratively applied. This is needed
541 * for both correctness, i.e. some filters would not mean anything if
542 * applied at the beginning of the pipeline; but also for performance
543 * since some filters can be applied in a single pass (e.g. noise
544 * reduction + deinterlacing).
546 * @param[in] dpy the VA display
547 * @param[in] context the video processing context
548 * @param[out] pipeline_caps the output array of #VAProcPipelineCap elements
549 * @param[in,out] num_pipeline_caps the number of elements allocated on input,
550 * the number of elements actually filled in on output
553 vaQueryVideoProcPipelineCaps(
556 VAProcPipelineCap *pipeline_caps,
557 unsigned int *num_pipeline_caps
561 * \brief Queries video filter capabilities.
563 * This function returns the list of capabilities supported by the driver
564 * for a specific video filter. The \c filter_caps array is allocated by
565 * the user and \c num_filter_caps shall be initialized to the number
566 * of allocated elements in that array. Upon successful return, the
567 * actual number of filters will be overwritten into \c num_filter_caps.
568 * Otherwise, \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned and
569 * \c num_filter_caps is adjusted to the number of elements that would be
570 * returned if enough space was available.
572 * @param[in] dpy the VA display
573 * @param[in] context the video processing context
574 * @param[in] type the video filter type
575 * @param[out] filter_caps the output array of #VAProcFilterCap elements
576 * @param[in,out] num_filter_caps the number of elements allocated on input,
577 * the number of elements actually filled in output
580 vaQueryVideoProcFilterCaps(
583 VAProcFilterType type,
585 unsigned int num_filter_caps
594 #endif /* VA_VPP_H */