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 filters;
46 * - Set up a video processing pipeline;
47 * - Send video processing parameters through VA buffers.
49 * \section api_vpp_caps Query for supported filters
51 * Checking whether video processing is supported can be performed
52 * with vaQueryConfigEntrypoints() and the profile argument set to
53 * #VAProfileNone. If video processing is supported, then the list of
54 * returned entry-points will include #VAEntrypointVideoProc.
57 * VAEntrypoint *entrypoints;
58 * int i, num_entrypoints, supportsVideoProcessing = 0;
60 * num_entrypoints = vaMaxNumEntrypoints();
61 * entrypoints = malloc(num_entrypoints * sizeof(entrypoints[0]);
62 * vaQueryConfigEntrypoints(va_dpy, VAProfileNone,
63 * entrypoints, &num_entrypoints);
65 * for (i = 0; !supportsVideoProcessing && i < num_entrypoints; i++) {
66 * if (entrypoints[i] == VAEntrypointVideoProc)
67 * supportsVideoProcessing = 1;
71 * Then, the vaQueryVideoProcFilters() function is used to query the
72 * list of video processing filters.
75 * VAProcFilterType filters[VAProcFilterCount];
76 * unsigned int num_filters = VAProcFilterCount;
78 * // num_filters shall be initialized to the length of the array
79 * vaQueryVideoProcFilters(va_dpy, vpp_ctx, &pipe_caps, &num_filters);
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_filters; i++) {
119 * switch (filters[i]) {
120 * case VAProcFilterNoiseReduction: { // Noise reduction filter
121 * VAProcFilterParameterBuffer denoise;
122 * denoise.type = VAProcFilterNoiseReduction;
123 * denoise.value = 0.5;
124 * vaCreateBuffer(va_dpy, vpp_ctx,
125 * VAProcFilterParameterBufferType, sizeof(denoise), 1,
126 * &denoise, &denoise_filter
128 * filter_bufs[num_filter_bufs++] = denoise_filter;
132 * case VAProcFilterDeinterlacing: // Motion-adaptive deinterlacing
133 * for (j = 0; j < num_deinterlacing_caps; j++) {
134 * VAProcFilterCapDeinterlacing * const cap = &deinterlacing_caps[j];
135 * if (cap->type != VAProcDeinterlacingMotionAdaptive)
138 * VAProcFilterParameterBufferDeinterlacing deint;
139 * deint.type = VAProcFilterDeinterlacing;
140 * deint.algorithm = VAProcDeinterlacingMotionAdaptive;
141 * deint.forward_references =
142 * malloc(cap->num_forward_references * sizeof(VASurfaceID));
143 * deint.num_forward_references = 0; // none for now
144 * deint.backward_references =
145 * malloc(cap->num_backward_references * sizeof(VASurfaceID));
146 * deint.num_backward_references = 0; // none for now
147 * vaCreateBuffer(va_dpy, vpp_ctx,
148 * VAProcFilterParameterBufferType, sizeof(deint), 1,
149 * &deint, &deint_filter
151 * filter_bufs[num_filter_bufs++] = deint_filter;
157 * \section api_vpp_submit Send video processing parameters through VA buffers
159 * Video processing pipeline parameters are submitted for each source
160 * surface to process. Video filter parameters can also change, per-surface.
161 * e.g. the list of reference frames used for deinterlacing.
164 * foreach (iteration) {
165 * vaBeginPicture(va_dpy, vpp_ctx, vpp_surface);
166 * foreach (surface) {
167 * VARectangle output_region;
168 * VABufferID pipeline_buf;
169 * VAProcPipelineParameterBuffer *pipeline_param;
171 * vaCreateBuffer(va_dpy, vpp_ctx,
172 * VAProcPipelineParameterBuffer, sizeof(*pipeline_param), 1,
173 * NULL, &pipeline_param
176 * // Setup output region for this surface
177 * // e.g. upper left corner for the first surface
178 * output_region.x = BORDER;
179 * output_region.y = BORDER;
180 * output_region.width =
181 * (vpp_surface_width - (Nx_surfaces + 1) * BORDER) / Nx_surfaces;
182 * output_region.height =
183 * (vpp_surface_height - (Ny_surfaces + 1) * BORDER) / Ny_surfaces;
185 * vaMapBuffer(va_dpy, pipeline_buf, &pipeline_param);
186 * pipeline_param->surface = surface;
187 * pipeline_param->surface_region = NULL;
188 * pipeline_param->output_region = &output_region;
189 * pipeline_param->output_background_color = 0;
190 * if (first surface to render)
191 * pipeline_param->output_background_color = 0xff000000; // black
192 * pipeline_param->flags = VA_FILTER_SCALING_HQ;
193 * pipeline_param->filters = filter_bufs;
194 * pipeline_param->num_filters = num_filter_bufs;
195 * vaUnmapBuffer(va_dpy, pipeline_buf);
197 * VAProcFilterParameterBufferDeinterlacing *deint_param;
198 * vaMapBuffer(va_dpy, deint_filter, &deint_param);
199 * // Update deinterlacing parameters, if necessary
201 * vaUnmapBuffer(va_dpy, deint_filter);
204 * vaRenderPicture(va_dpy, vpp_ctx, &pipeline_buf, 1);
206 * vaEndPicture(va_dpy, vpp_ctx);
211 /** \brief Video filter types. */
212 typedef enum _VAProcFilterType {
213 VAProcFilterNone = 0,
214 /** \brief Noise reduction filter. */
215 VAProcFilterNoiseReduction,
216 /** \brief Deinterlacing filter. */
217 VAProcFilterDeinterlacing,
218 /** \brief Sharpening filter. */
219 VAProcFilterSharpening,
220 /** \brief Color balance parameters. */
221 VAProcFilterColorBalance,
222 /** \brief Color standard conversion. */
223 VAProcFilterColorStandard,
224 /** \brief Max number of video filters. */
228 /** \brief Deinterlacing types. */
229 typedef enum _VAProcDeinterlacingType {
230 VAProcDeinterlacingNone = 0,
231 /** \brief Bob deinterlacing algorithm. */
232 VAProcDeinterlacingBob,
233 /** \brief Weave deinterlacing algorithm. */
234 VAProcDeinterlacingWeave,
235 /** \brief Motion adaptive deinterlacing algorithm. */
236 VAProcDeinterlacingMotionAdaptive,
237 /** \brief Motion compensated deinterlacing algorithm. */
238 VAProcDeinterlacingMotionCompensated,
239 /** \brief Max number of deinterlacing algorithms. */
240 VAProcDeinterlacingCount
241 } VAProcDeinterlacingType;
243 /** \brief Color balance types. */
244 typedef enum _VAProcColorBalanceType {
245 VAProcColorBalanceNone = 0,
247 VAProcColorBalanceHue,
248 /** \brief Saturation. */
249 VAProcColorBalanceSaturation,
250 /** \brief Brightness. */
251 VAProcColorBalanceBrightness,
252 /** \brief Contrast. */
253 VAProcColorBalanceContrast,
254 /** \brief Max number of color balance operations. */
255 VAProcColorBalanceCount
256 } VAProcColorBalanceType;
258 /** \brief Color standard types. */
259 typedef enum _VAProcColorStandardType {
260 VAProcColorStandardNone = 0,
261 /** \brief ITU-R BT.601. */
262 VAProcColorStandardBT601,
263 /** \brief ITU-R BT.709. */
264 VAProcColorStandardBT709,
265 /** \brief ITU-R BT.470-2 System M. */
266 VAProcColorStandardBT470M,
267 /** \brief ITU-R BT.470-2 System B, G. */
268 VAProcColorStandardBT470BG,
269 /** \brief SMPTE-170M. */
270 VAProcColorStandardSMPTE170M,
271 /** \brief SMPTE-240M. */
272 VAProcColorStandardSMPTE240M,
273 /** \brief Generic film. */
274 VAProcColorStandardGenericFilm,
275 } VAProcColorStandardType;
277 /** @name Video filter flags */
279 /** \brief Specifies whether the filter shall be present in the pipeline. */
280 #define VA_PROC_FILTER_MANDATORY 0x00000001
283 /** \brief Video processing pipeline capabilities. */
284 typedef struct _VAProcPipelineCaps {
285 /** \brief Video filter flags. See video pipeline flags. */
287 /** \brief Number of forward reference frames that are needed. */
288 unsigned int num_forward_references;
289 /** \brief Number of backward reference frames that are needed. */
290 unsigned int num_backward_references;
291 } VAProcPipelineCaps;
293 /** \brief Specification of values supported by the filter. */
294 typedef struct _VAProcFilterValueRange {
295 /** \brief Minimum value supported, inclusive. */
297 /** \brief Maximum value supported, inclusive. */
299 /** \brief Default value. */
301 /** \brief Step value that alters the filter behaviour in a sensible way. */
303 } VAProcFilterValueRange;
306 * \brief Video processing pipeline configuration.
308 * This buffer defines a video processing pipeline. As for any buffer
309 * passed to \c vaRenderPicture(), this is a one-time usage model.
310 * However, the actual filters to be applied are provided in the
311 * \c filters field, so they can be re-used in other processing
314 * The target surface is specified by the \c render_target argument of
315 * \c vaBeginPicture(). The general usage model is described as follows:
316 * - \c vaBeginPicture(): specify the target surface that receives the
318 * - \c vaRenderPicture(): specify a surface to be processed and composed
319 * into the \c render_target. Use as many \c vaRenderPicture() calls as
320 * necessary surfaces to compose ;
321 * - \c vaEndPicture(): tell the driver to start processing the surfaces
322 * with the requested filters.
324 * If a filter (e.g. noise reduction) needs to be applied with different
325 * values for multiple surfaces, the application needs to create as many
326 * filter parameter buffers as necessary. i.e. the filter parameters shall
327 * not change between two calls to \c vaRenderPicture().
329 * For composition usage models, the first surface to process will generally
330 * use an opaque background color, i.e. \c output_background_color set with
331 * the most significant byte set to \c 0xff. For instance, \c 0xff000000 for
332 * a black background. Then, subsequent surfaces would use a transparent
335 typedef struct _VAProcPipelineParameterBuffer {
337 * \brief Source surface ID.
339 * ID of the source surface to process. If subpictures are associated with
340 * the video surfaces then they shall be rendered to the target surface.
344 * \brief Region within the source surface to be processed.
346 * Pointer to a #VARectangle defining the region within the source
347 * surface to be processed. If NULL, \c surface_region implies the
350 const VARectangle *surface_region;
352 * \brief Region within the output surface.
354 * Pointer to a #VARectangle defining the region within the output
355 * surface that receives the processed pixels. If NULL, \c output_region
356 * implies the whole surface.
358 * Note that any pixels residing outside the specified region will
359 * be filled in with the \ref output_background_color.
361 const VARectangle *output_region;
363 * \brief Background color.
365 * Background color used to fill in pixels that reside outside of the
366 * specified \ref output_region. The color is specified in ARGB format:
367 * [31:24] alpha, [23:16] red, [15:8] green, [7:0] blue.
369 * Unless the alpha value is zero or the \ref output_region represents
370 * the whole target surface size, implementations shall not render the
371 * source surface to the target surface directly. Rather, in order to
372 * maintain the exact semantics of \ref output_background_color, the
373 * driver shall use a temporary surface and fill it in with the
374 * appropriate background color. Next, the driver will blend this
375 * temporary surface into the target surface.
377 unsigned int output_background_color;
379 * \brief Pipeline flags. See vaPutSurface() flags.
382 * - Bob-deinterlacing: \c VA_FRAME_PICTURE, \c VA_TOP_FIELD,
383 * \c VA_BOTTOM_FIELD. Note that any deinterlacing filter
384 * (#VAProcFilterDeinterlacing) will override those flags.
385 * - Color space conversion: \c VA_SRC_BT601, \c VA_SRC_BT709,
386 * \c VA_SRC_SMPTE_240. Note that any color standard filter
387 * (#VAProcFilterColorStandard) will override those flags.
388 * - Scaling: \c VA_FILTER_SCALING_DEFAULT, \c VA_FILTER_SCALING_FAST,
389 * \c VA_FILTER_SCALING_HQ, \c VA_FILTER_SCALING_NL_ANAMORPHIC.
393 * \brief Array of filters to apply to the surface.
395 * The list of filters shall be ordered in the same way the driver expects
396 * them. i.e. as was returned from vaQueryVideoProcFilters().
397 * Otherwise, a #VA_STATUS_ERROR_INVALID_FILTER_CHAIN is returned
398 * from vaRenderPicture() with this buffer.
400 * #VA_STATUS_ERROR_UNSUPPORTED_FILTER is returned if the list
401 * contains an unsupported filter.
403 * Note: no filter buffer is destroyed after a call to vaRenderPicture(),
404 * only this pipeline buffer will be destroyed as per the core API
405 * specification. This allows for flexibility in re-using the filter for
406 * other surfaces to be processed.
409 /** \brief Actual number of filters. */
410 unsigned int num_filters;
411 } VAProcPipelineParameterBuffer;
414 * \brief Filter parameter buffer base.
416 * This is a helper structure used by driver implementations only.
417 * Users are not supposed to allocate filter parameter buffers of this
420 typedef struct _VAProcFilterParameterBufferBase {
421 /** \brief Filter type. */
422 VAProcFilterType type;
423 } VAProcFilterParameterBufferBase;
426 * \brief Default filter parametrization.
428 * Unless there is a filter-specific parameter buffer,
429 * #VAProcFilterParameterBuffer is the default type to use.
431 typedef struct _VAProcFilterParameterBuffer {
432 /** \brief Filter type. */
433 VAProcFilterType type;
436 } VAProcFilterParameterBuffer;
438 /** \brief Deinterlacing filter parametrization. */
439 typedef struct _VAProcFilterParameterBufferDeinterlacing {
440 /** \brief Filter type. Shall be set to #VAProcFilterDeinterlacing. */
441 VAProcFilterType type;
442 /** \brief Deinterlacing algorithm. */
443 VAProcDeinterlacingType algorithm;
444 /** \brief Array of forward reference frames. */
445 VASurfaceID *forward_references;
446 /** \brief Number of forward reference frames that were supplied. */
447 unsigned int num_forward_references;
448 /** \brief Array of backward reference frames. */
449 VASurfaceID *backward_references;
450 /** \brief Number of backward reference frames that were supplied. */
451 unsigned int num_backward_references;
452 } VAProcFilterParameterBufferDeinterlacing;
455 * \brief Color balance filter parametrization.
457 * This buffer defines color balance attributes. A VA buffer can hold
458 * several color balance attributes by creating a VA buffer of desired
459 * number of elements. This can be achieved by the following pseudo-code:
462 * enum { kHue, kSaturation, kBrightness, kContrast };
464 * // Initial color balance parameters
465 * static const VAProcFilterParameterBufferColorBalance colorBalanceParams[4] =
468 * { VAProcFilterColorBalance, VAProcColorBalanceHue, 0.5 },
470 * { VAProcFilterColorBalance, VAProcColorBalanceSaturation, 0.5 },
472 * { VAProcFilterColorBalance, VAProcColorBalanceBrightness, 0.5 },
474 * { VAProcFilterColorBalance, VAProcColorBalanceSaturation, 0.5 }
478 * VABufferID colorBalanceBuffer;
479 * vaCreateBuffer(va_dpy, vpp_ctx,
480 * VAProcFilterParameterBufferType, sizeof(*pColorBalanceParam), 4,
481 * colorBalanceParams,
482 * &colorBalanceBuffer
485 * VAProcFilterParameterBufferColorBalance *pColorBalanceParam;
486 * vaMapBuffer(va_dpy, colorBalanceBuffer, &pColorBalanceParam);
488 * // Change brightness only
489 * pColorBalanceBuffer[kBrightness].value = 0.75;
491 * vaUnmapBuffer(va_dpy, colorBalanceBuffer);
494 typedef struct _VAProcFilterParameterBufferColorBalance {
495 /** \brief Filter type. Shall be set to #VAProcFilterColorBalance. */
496 VAProcFilterType type;
497 /** \brief Color balance attribute. */
498 VAProcColorBalanceType attrib;
499 /** \brief Color balance value. */
501 } VAProcFilterParameterBufferColorBalance;
503 /** \brief Color standard filter parametrization. */
504 typedef struct _VAProcFilterParameterBufferColorStandard {
505 /** \brief Filter type. Shall be set to #VAProcFilterColorStandard. */
506 VAProcFilterType type;
507 /** \brief Color standard to use. */
508 VAProcColorStandardType standard;
509 } VAProcFilterParameterBufferColorStandard;
512 * \brief Default filter cap specification (single range value).
514 * Unless there is a filter-specific cap structure, #VAProcFilterCap is the
515 * default type to use for output caps from vaQueryVideoProcFilterCaps().
517 typedef struct _VAProcFilterCap {
518 /** \brief Range of supported values for the filter. */
519 VAProcFilterValueRange range;
522 /** \brief Capabilities specification for the deinterlacing filter. */
523 typedef struct _VAProcFilterCapDeinterlacing {
524 /** \brief Deinterlacing algorithm. */
525 VAProcDeinterlacingType type;
526 /** \brief Number of forward references needed for deinterlacing. */
527 unsigned int num_forward_references;
528 /** \brief Number of backward references needed for deinterlacing. */
529 unsigned int num_backward_references;
530 } VAProcFilterCapDeinterlacing;
532 /** \brief Capabilities specification for the color balance filter. */
533 typedef struct _VAProcFilterCapColorBalance {
534 /** \brief Color balance operation. */
535 VAProcColorBalanceType type;
536 /** \brief Range of supported values for the specified operation. */
537 VAProcFilterValueRange range;
538 } VAProcFilterCapColorBalance;
540 /** \brief Capabilities specification for the color standard filter. */
541 typedef struct _VAProcFilterCapColorStandard {
542 /** \brief Color standard type. */
543 VAProcColorStandardType type;
544 } VAProcFilterCapColorStandard;
547 * \brief Queries video processing filters.
549 * This function returns the list of video processing filters supported
550 * by the driver. The \c filters array is allocated by the user and
551 * \c num_filters shall be initialized to the number of allocated
552 * elements in that array. Upon successful return, the actual number
553 * of filters will be overwritten into \c num_filters. Otherwise,
554 * \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned and \c num_filters
555 * is adjusted to the number of elements that would be returned if enough
556 * space was available.
558 * The list of video processing filters supported by the driver shall
559 * be ordered in the way they can be iteratively applied. This is needed
560 * for both correctness, i.e. some filters would not mean anything if
561 * applied at the beginning of the pipeline; but also for performance
562 * since some filters can be applied in a single pass (e.g. noise
563 * reduction + deinterlacing).
565 * @param[in] dpy the VA display
566 * @param[in] context the video processing context
567 * @param[out] filters the output array of #VAProcFilterType elements
568 * @param[in,out] num_filters the number of elements allocated on input,
569 * the number of elements actually filled in on output
572 vaQueryVideoProcFilters(
575 VAProcFilterType *filters,
576 unsigned int *num_filters
580 * \brief Queries video filter capabilities.
582 * This function returns the list of capabilities supported by the driver
583 * for a specific video filter. The \c filter_caps array is allocated by
584 * the user and \c num_filter_caps shall be initialized to the number
585 * of allocated elements in that array. Upon successful return, the
586 * actual number of filters will be overwritten into \c num_filter_caps.
587 * Otherwise, \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned and
588 * \c num_filter_caps is adjusted to the number of elements that would be
589 * returned if enough space was available.
591 * @param[in] dpy the VA display
592 * @param[in] context the video processing context
593 * @param[in] type the video filter type
594 * @param[out] filter_caps the output array of #VAProcFilterCap elements
595 * @param[in,out] num_filter_caps the number of elements allocated on input,
596 * the number of elements actually filled in output
599 vaQueryVideoProcFilterCaps(
602 VAProcFilterType type,
604 unsigned int *num_filter_caps
608 * \brief Queries video processing pipeline capabilities.
610 * This function returns the video processing pipeline capabilities. The
611 * \c filters array defines the video processing pipeline and is an array
612 * of buffers holding filter parameters.
614 * @param[in] dpy the VA display
615 * @param[in] context the video processing context
616 * @param[in] filters the array of VA buffers defining the video
617 * processing pipeline
618 * @param[in] num_filters the number of elements in filters
619 * @param[out] pipeline_caps the video processing pipeline capabilities
622 vaQueryVideoProcPipelineCaps(
626 unsigned int num_filters,
627 VAProcPipelineCaps *pipeline_caps
636 #endif /* VA_VPP_H */