diff --git a/docs/guide/advanced/video-codecs.md b/docs/guide/advanced/video-codecs.md index 103ead45..22e1f2d7 100644 --- a/docs/guide/advanced/video-codecs.md +++ b/docs/guide/advanced/video-codecs.md @@ -27,14 +27,14 @@ PeerConnectionFactory factory = PeerConnectionFactory.builder() | Platform | Hardware encoding | |---|---| | Windows | H.264 with NVENC on NVIDIA GPUs, otherwise through the Media Foundation encoder of the GPU driver (AMD, Intel) | -| Linux | H.264 with NVENC on NVIDIA GPUs; other GPUs encode in software | +| Linux | H.264 with NVENC on NVIDIA GPUs, otherwise through the VA-API encoder of the GPU driver (Intel, AMD) | | macOS | H.264 through VideoToolbox, as with `DefaultVideoEncoderFactory` | -NVENC needs an NVIDIA driver of version 522 or newer on Windows, 520 or newer on Linux; it is loaded at run time, so nothing needs to be installed on machines without one. +NVENC needs an NVIDIA driver of version 522 or newer on Windows, 520 or newer on Linux. VA-API needs libva 2 and a driver that encodes H.264, such as Intel's `intel-media-va-driver` (iHD) or Mesa's `mesa-va-drivers` for AMD, and access to a render node in `/dev/dri`. All of them are loaded at run time, so nothing needs to be installed on machines without them. -The hardware encoders take over H.264 Constrained Baseline and Baseline with packetization mode 1, formats the software encoder offers too, so encoding in hardware never changes what is negotiated. When a hardware encoder fails to start, for example because the GPU has no encoder sessions left, or fails while encoding, the stream switches to the next encoder in line (on Windows, from NVENC to Media Foundation), and finally to the software encoder, and continues with a key frame. On a machine without a hardware encoder, the factory encodes like `DefaultVideoEncoderFactory`. +The hardware encoders take over H.264 Constrained Baseline and Baseline with packetization mode 1, formats the software encoder offers too, so encoding in hardware never changes what is negotiated. When a hardware encoder fails to start, for example because the GPU has no encoder sessions left, or fails while encoding, the stream switches to the next encoder in line (e.g. from NVENC to Media Foundation on Windows), and finally to the software encoder, and continues with a key frame. On a machine without a hardware encoder, the factory encodes like `DefaultVideoEncoderFactory`. -Which encoder a stream uses shows in the `encoderImplementation` statistic of its `outbound-rtp` stats, e.g. `NVENC (NVIDIA GeForce RTX 4070)`, `MediaFoundation (AMDh264Encoder)` or `OpenH264`. +Which encoder a stream uses shows in the `encoderImplementation` statistic of its `outbound-rtp` stats, e.g. `NVENC (NVIDIA GeForce RTX 4070)`, `MediaFoundation (AMDh264Encoder)`, `VA-API (Intel iHD driver ...)` or `OpenH264`. ### Native Codecs diff --git a/webrtc-jni/src/main/cpp/CMakeLists.txt b/webrtc-jni/src/main/cpp/CMakeLists.txt index d7ed2eab..ce28b20c 100644 --- a/webrtc-jni/src/main/cpp/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/CMakeLists.txt @@ -110,6 +110,10 @@ target_include_directories(${PROJECT_NAME} if(WIN32 OR LINUX) target_include_directories(${PROJECT_NAME} PRIVATE dependencies/nvenc/include) endif() +if(LINUX) + # libva is loaded at run time, so building needs its headers only. + target_include_directories(${PROJECT_NAME} PRIVATE dependencies/libva/include) +endif() set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}-${OUTPUT_NAME_SUFFIX}" @@ -170,3 +174,10 @@ if(WIN32 OR LINUX) COMPONENT Runtime ) endif() +if(LINUX) + install(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libva/COPYING" + DESTINATION "${CMAKE_INSTALL_PREFIX}/META-INF/licenses/libva" + COMPONENT Runtime + ) +endif() diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/COPYING b/webrtc-jni/src/main/cpp/dependencies/libva/COPYING new file mode 100644 index 00000000..900e7754 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/COPYING @@ -0,0 +1,19 @@ + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sub license, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial portions + of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/README.md b/webrtc-jni/src/main/cpp/dependencies/libva/README.md new file mode 100644 index 00000000..359df336 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/README.md @@ -0,0 +1,12 @@ +# libva headers + +`include/va/` holds the public headers of libva 2.17.0 (VA-API 1.17), taken +unchanged from https://github.com/intel/libva/tree/2.17.0/va, except: + +- `va_drm.h` comes from `va/drm/va_drm.h`; +- `va_version.h` is generated from `va/va_version.h.in` with version 1.17.0, + as the libva build does. + +The library loads `libva.so.2` and `libva-drm.so.2` at run time, so the +headers are all the build needs, including for the cross-compiled targets. +libva is licensed under the MIT license in `COPYING`. diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va.h new file mode 100644 index 00000000..b6c034f0 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va.h @@ -0,0 +1,5269 @@ +/* + * Copyright (c) 2007-2009 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +/* + * Video Acceleration (VA) API Specification + * + * Rev. 0.30 + * + * + * Revision History: + * rev 0.10 (12/10/2006 Jonathan Bian) - Initial draft + * rev 0.11 (12/15/2006 Jonathan Bian) - Fixed some errors + * rev 0.12 (02/05/2007 Jonathan Bian) - Added VC-1 data structures for slice level decode + * rev 0.13 (02/28/2007 Jonathan Bian) - Added GetDisplay() + * rev 0.14 (04/13/2007 Jonathan Bian) - Fixed MPEG-2 PictureParameter structure, cleaned up a few funcs. + * rev 0.15 (04/20/2007 Jonathan Bian) - Overhauled buffer management + * rev 0.16 (05/02/2007 Jonathan Bian) - Added error codes and fixed some issues with configuration + * rev 0.17 (05/07/2007 Jonathan Bian) - Added H.264/AVC data structures for slice level decode. + * rev 0.18 (05/14/2007 Jonathan Bian) - Added data structures for MPEG-4 slice level decode + * and MPEG-2 motion compensation. + * rev 0.19 (08/06/2007 Jonathan Bian) - Removed extra type for bitplane data. + * rev 0.20 (08/08/2007 Jonathan Bian) - Added missing fields to VC-1 PictureParameter structure. + * rev 0.21 (08/20/2007 Jonathan Bian) - Added image and subpicture support. + * rev 0.22 (08/27/2007 Jonathan Bian) - Added support for chroma-keying and global alpha. + * rev 0.23 (09/11/2007 Jonathan Bian) - Fixed some issues with images and subpictures. + * rev 0.24 (09/18/2007 Jonathan Bian) - Added display attributes. + * rev 0.25 (10/18/2007 Jonathan Bian) - Changed to use IDs only for some types. + * rev 0.26 (11/07/2007 Waldo Bastian) - Change vaCreateBuffer semantics + * rev 0.27 (11/19/2007 Matt Sottek) - Added DeriveImage + * rev 0.28 (12/06/2007 Jonathan Bian) - Added new versions of PutImage and AssociateSubpicture + * to enable scaling + * rev 0.29 (02/07/2008 Jonathan Bian) - VC1 parameter fixes, + * added VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED + * rev 0.30 (03/01/2009 Jonathan Bian) - Added encoding support for H.264 BP and MPEG-4 SP and fixes + * for ISO C conformance. + * rev 0.31 (09/02/2009 Gwenole Beauchesne) - VC-1/H264 fields change for VDPAU and XvBA backend + * Application needs to relink with the new library. + * + * rev 0.31.1 (03/29/2009) - Data structure for JPEG encode + * rev 0.31.2 (01/13/2011 Anthony Pabon)- Added a flag to indicate Subpicture coordinates are screen + * screen relative rather than source video relative. + * rev 0.32.0 (01/13/2011 Xiang Haihao) - Add profile into VAPictureParameterBufferVC1 + * update VAAPI to 0.32.0 + * + * Acknowledgements: + * Some concepts borrowed from XvMC and XvImage. + * Waldo Bastian (Intel), Matt Sottek (Intel), Austin Yuan (Intel), and Gwenole Beauchesne (SDS) + * contributed to various aspects of the API. + */ + +/** + * \file va.h + * \brief The Core API + * + * This file contains the \ref api_core "Core API". + */ + +#ifndef _VA_H_ +#define _VA_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__GNUC__) && !defined(__COVERITY__) +#define va_deprecated __attribute__((deprecated)) +#if __GNUC__ >= 6 +#define va_deprecated_enum va_deprecated +#else +#define va_deprecated_enum +#endif +#else +#define va_deprecated +#define va_deprecated_enum +#endif + +/** + * \mainpage Video Acceleration (VA) API + * + * \section intro Introduction + * + * The main motivation for VA-API (Video Acceleration API) is to + * enable hardware accelerated video decode and encode at various + * entry-points (VLD, IDCT, Motion Compensation etc.) for the + * prevailing coding standards today (MPEG-2, MPEG-4 ASP/H.263, MPEG-4 + * AVC/H.264, VC-1/VMW3, and JPEG, HEVC/H265, VP8, VP9) and video pre/post + * processing + * + * VA-API is split into several modules: + * - \ref api_core + * - Encoder (H264, HEVC, JPEG, MPEG2, VP8, VP9) + * - \ref api_enc_h264 + * - \ref api_enc_hevc + * - \ref api_enc_jpeg + * - \ref api_enc_mpeg2 + * - \ref api_enc_vp8 + * - \ref api_enc_vp9 + * - \ref api_enc_av1 + * - Decoder (HEVC, JPEG, VP8, VP9, AV1) + * - \ref api_dec_hevc + * - \ref api_dec_jpeg + * - \ref api_dec_vp8 + * - \ref api_dec_vp9 + * - \ref api_dec_av1 + * - \ref api_vpp + * - \ref api_prot + * - FEI (H264, HEVC) + * - \ref api_fei + * - \ref api_fei_h264 + * - \ref api_fei_hevc + * + * \section threading Multithreading Guide + * All VAAPI functions implemented in libva are thread-safe. For any VAAPI + * function that requires the implementation of a backend (e.g. hardware driver), + * the backend must ensure that its implementation is also thread-safe. If the + * backend implementation of a VAAPI function is not thread-safe then this should + * be considered as a bug against the backend implementation. + * + * It is assumed that none of the VAAPI functions will be called from signal + * handlers. + * + * Thread-safety in this context means that when VAAPI is being called by multiple + * concurrent threads, it will not crash or hang the OS, and VAAPI internal + * data structures will not be corrupted. When multiple threads are operating on + * the same VAAPI objects, it is the application's responsibility to synchronize + * these operations in order to generate the expected results. For example, using + * a single VAContext from multiple threads may generate unexpected results. + * + * Following pseudo code illustrates a multithreaded transcoding scenario, where + * one thread is handling the decoding operation and another thread is handling + * the encoding operation, while synchronizing the use of a common pool of + * surfaces. + * + * \code + * // Initialization + * dpy = vaGetDisplayDRM(fd); + * vaInitialize(dpy, ...); + * + * // Create surfaces required for decoding and subsequence encoding + * vaCreateSurfaces(dpy, VA_RT_FORMAT_YUV420, width, height, &surfaces[0], ...); + * + * // Set up a queue for the surfaces shared between decode and encode threads + * surface_queue = queue_create(); + * + * // Create decode_thread + * pthread_create(&decode_thread, NULL, decode, ...); + * + * // Create encode_thread + * pthread_create(&encode_thread, NULL, encode, ...); + * + * // Decode thread function + * decode() { + * // Find the decode entrypoint for H.264 + * vaQueryConfigEntrypoints(dpy, h264_profile, entrypoints, ...); + * + * // Create a config for H.264 decode + * vaCreateConfig(dpy, h264_profile, VAEntrypointVLD, ...); + * + * // Create a context for decode + * vaCreateContext(dpy, config, width, height, VA_PROGRESSIVE, surfaces, + * num_surfaces, &decode_context); + * + * // Decode frames in the bitstream + * for (;;) { + * // Parse one frame and decode + * vaBeginPicture(dpy, decode_context, surfaces[surface_index]); + * vaRenderPicture(dpy, decode_context, buf, ...); + * vaEndPicture(dpy, decode_context); + * // Poll the decoding status and enqueue the surface in display order after + * // decoding is complete + * vaQuerySurfaceStatus(); + * enqueue(surface_queue, surface_index); + * } + * } + * + * // Encode thread function + * encode() { + * // Find the encode entrypoint for HEVC + * vaQueryConfigEntrypoints(dpy, hevc_profile, entrypoints, ...); + * + * // Create a config for HEVC encode + * vaCreateConfig(dpy, hevc_profile, VAEntrypointEncSlice, ...); + * + * // Create a context for encode + * vaCreateContext(dpy, config, width, height, VA_PROGRESSIVE, surfaces, + * num_surfaces, &encode_context); + * + * // Encode frames produced by the decoder + * for (;;) { + * // Dequeue the surface enqueued by the decoder + * surface_index = dequeue(surface_queue); + * // Encode using this surface as the source + * vaBeginPicture(dpy, encode_context, surfaces[surface_index]); + * vaRenderPicture(dpy, encode_context, buf, ...); + * vaEndPicture(dpy, encode_context); + * } + * } + * \endcode + */ + +/** + * \defgroup api_core Core API + * + * @{ + */ + +/** +Overview + +The VA API is intended to provide an interface between a video decode/encode/processing +application (client) and a hardware accelerator (server), to off-load +video decode/encode/processing operations from the host to the hardware accelerator at various +entry-points. + +The basic operation steps are: + +- Negotiate a mutually acceptable configuration with the server to lock + down profile, entrypoints, and other attributes that will not change on + a frame-by-frame basis. +- Create a video decode, encode or processing context which represents a + "virtualized" hardware device +- Get and fill the render buffers with the corresponding data (depending on + profiles and entrypoints) +- Pass the render buffers to the server to handle the current frame + +Initialization & Configuration Management + +- Find out supported profiles +- Find out entrypoints for a given profile +- Find out configuration attributes for a given profile/entrypoint pair +- Create a configuration for use by the application + +*/ + +typedef void* VADisplay; /* window system dependent */ + +typedef int VAStatus; /** Return status type from functions */ +/** Values for the return status */ +#define VA_STATUS_SUCCESS 0x00000000 +#define VA_STATUS_ERROR_OPERATION_FAILED 0x00000001 +#define VA_STATUS_ERROR_ALLOCATION_FAILED 0x00000002 +#define VA_STATUS_ERROR_INVALID_DISPLAY 0x00000003 +#define VA_STATUS_ERROR_INVALID_CONFIG 0x00000004 +#define VA_STATUS_ERROR_INVALID_CONTEXT 0x00000005 +#define VA_STATUS_ERROR_INVALID_SURFACE 0x00000006 +#define VA_STATUS_ERROR_INVALID_BUFFER 0x00000007 +#define VA_STATUS_ERROR_INVALID_IMAGE 0x00000008 +#define VA_STATUS_ERROR_INVALID_SUBPICTURE 0x00000009 +#define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED 0x0000000a +#define VA_STATUS_ERROR_MAX_NUM_EXCEEDED 0x0000000b +#define VA_STATUS_ERROR_UNSUPPORTED_PROFILE 0x0000000c +#define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT 0x0000000d +#define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT 0x0000000e +#define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE 0x0000000f +#define VA_STATUS_ERROR_SURFACE_BUSY 0x00000010 +#define VA_STATUS_ERROR_FLAG_NOT_SUPPORTED 0x00000011 +#define VA_STATUS_ERROR_INVALID_PARAMETER 0x00000012 +#define VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED 0x00000013 +#define VA_STATUS_ERROR_UNIMPLEMENTED 0x00000014 +#define VA_STATUS_ERROR_SURFACE_IN_DISPLAYING 0x00000015 +#define VA_STATUS_ERROR_INVALID_IMAGE_FORMAT 0x00000016 +#define VA_STATUS_ERROR_DECODING_ERROR 0x00000017 +#define VA_STATUS_ERROR_ENCODING_ERROR 0x00000018 +/** + * \brief An invalid/unsupported value was supplied. + * + * This is a catch-all error code for invalid or unsupported values. + * e.g. value exceeding the valid range, invalid type in the context + * of generic attribute values. + */ +#define VA_STATUS_ERROR_INVALID_VALUE 0x00000019 +/** \brief An unsupported filter was supplied. */ +#define VA_STATUS_ERROR_UNSUPPORTED_FILTER 0x00000020 +/** \brief An invalid filter chain was supplied. */ +#define VA_STATUS_ERROR_INVALID_FILTER_CHAIN 0x00000021 +/** \brief Indicate HW busy (e.g. run multiple encoding simultaneously). */ +#define VA_STATUS_ERROR_HW_BUSY 0x00000022 +/** \brief An unsupported memory type was supplied. */ +#define VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE 0x00000024 +/** \brief Indicate allocated buffer size is not enough for input or output. */ +#define VA_STATUS_ERROR_NOT_ENOUGH_BUFFER 0x00000025 +/** \brief Indicate an operation isn't completed because time-out interval elapsed. */ +#define VA_STATUS_ERROR_TIMEDOUT 0x00000026 +#define VA_STATUS_ERROR_UNKNOWN 0xFFFFFFFF + +/** + * 1. De-interlacing flags for vaPutSurface() + * 2. Surface sample type for input/output surface flag + * - Progressive: VA_FRAME_PICTURE + * - Interleaved: VA_TOP_FIELD_FIRST, VA_BOTTOM_FIELD_FIRST + * - Field: VA_TOP_FIELD, VA_BOTTOM_FIELD +*/ +#define VA_FRAME_PICTURE 0x00000000 +#define VA_TOP_FIELD 0x00000001 +#define VA_BOTTOM_FIELD 0x00000002 +#define VA_TOP_FIELD_FIRST 0x00000004 +#define VA_BOTTOM_FIELD_FIRST 0x00000008 + +/** + * Enabled the positioning/cropping/blending feature: + * 1, specify the video playback position in the isurface + * 2, specify the cropping info for video playback + * 3, encoded video will blend with background color + */ +#define VA_ENABLE_BLEND 0x00000004 /* video area blend with the constant color */ + +/** + * Clears the drawable with background color. + * for hardware overlay based implementation this flag + * can be used to turn off the overlay + */ +#define VA_CLEAR_DRAWABLE 0x00000008 + +/** Color space conversion flags for vaPutSurface() */ +#define VA_SRC_COLOR_MASK 0x000000f0 +#define VA_SRC_BT601 0x00000010 +#define VA_SRC_BT709 0x00000020 +#define VA_SRC_SMPTE_240 0x00000040 + +/** Scaling flags for vaPutSurface() */ +#define VA_FILTER_SCALING_DEFAULT 0x00000000 +#define VA_FILTER_SCALING_FAST 0x00000100 +#define VA_FILTER_SCALING_HQ 0x00000200 +#define VA_FILTER_SCALING_NL_ANAMORPHIC 0x00000300 +#define VA_FILTER_SCALING_MASK 0x00000f00 + +/** Interpolation method for scaling */ +#define VA_FILTER_INTERPOLATION_DEFAULT 0x00000000 +#define VA_FILTER_INTERPOLATION_NEAREST_NEIGHBOR 0x00001000 +#define VA_FILTER_INTERPOLATION_BILINEAR 0x00002000 +#define VA_FILTER_INTERPOLATION_ADVANCED 0x00003000 +#define VA_FILTER_INTERPOLATION_MASK 0x0000f000 + +/** Padding size in 4-bytes */ +#define VA_PADDING_LOW 4 +#define VA_PADDING_MEDIUM 8 +#define VA_PADDING_HIGH 16 +#define VA_PADDING_LARGE 32 + +/** operation options */ +/** synchronization, block call, output should be ready after execution function return*/ +#define VA_EXEC_SYNC 0x0 +/** asynchronization,application should call additonal sync operation to access output */ +#define VA_EXEC_ASYNC 0x1 + +/** operation mode */ +#define VA_EXEC_MODE_DEFAULT 0x0 +#define VA_EXEC_MODE_POWER_SAVING 0x1 +#define VA_EXEC_MODE_PERFORMANCE 0x2 + +/* Values used to describe device features. */ +/** The feature is not supported by the device. + * + * Any corresponding feature flag must not be set. + */ +#define VA_FEATURE_NOT_SUPPORTED 0 +/** The feature is supported by the device. + * + * The user may decide whether or not to use this feature. + * + * Note that support for a feature only indicates that the hardware + * is able to use it; whether it is actually a positive change to + * enable it in a given situation will depend on other factors + * including the input provided by the user. + */ +#define VA_FEATURE_SUPPORTED 1 +/** The feature is required by the device. + * + * The device does not support not enabling this feature, so any + * corresponding feature flag must be set and any additional + * configuration needed by the feature must be supplied. + */ +#define VA_FEATURE_REQUIRED 2 + +/** + * Returns a short english description of error_status + */ +const char *vaErrorStr(VAStatus error_status); + +typedef struct _VARectangle { + int16_t x; + int16_t y; + uint16_t width; + uint16_t height; +} VARectangle; + +/** \brief Generic motion vector data structure. */ +typedef struct _VAMotionVector { + /** \mv0[0]: horizontal motion vector for past reference */ + /** \mv0[1]: vertical motion vector for past reference */ + /** \mv1[0]: horizontal motion vector for future reference */ + /** \mv1[1]: vertical motion vector for future reference */ + int16_t mv0[2]; /* past reference */ + int16_t mv1[2]; /* future reference */ +} VAMotionVector; + +/** Type of a message callback, used for both error and info log. */ +typedef void (*VAMessageCallback)(void *user_context, const char *message); + +/** + * Set the callback for error messages, or NULL for no logging. + * Returns the previous one, or NULL if it was disabled. + */ +VAMessageCallback vaSetErrorCallback(VADisplay dpy, VAMessageCallback callback, void *user_context); + +/** + * Set the callback for info messages, or NULL for no logging. + * Returns the previous one, or NULL if it was disabled. + */ +VAMessageCallback vaSetInfoCallback(VADisplay dpy, VAMessageCallback callback, void *user_context); + +/** + * Initialization: + * A display must be obtained by calling vaGetDisplay() before calling + * vaInitialize() and other functions. This connects the API to the + * native window system. + * For X Windows, native_dpy would be from XOpenDisplay() + */ +typedef void* VANativeDisplay; /* window system dependent */ + +int vaDisplayIsValid(VADisplay dpy); + +/** + * Set the override driver name instead of queried driver driver. + */ +VAStatus vaSetDriverName(VADisplay dpy, + char *driver_name + ); + +/** + * Initialize the library + */ +VAStatus vaInitialize( + VADisplay dpy, + int *major_version, /* out */ + int *minor_version /* out */ +); + +/** + * After this call, all library internal resources will be cleaned up + */ +VAStatus vaTerminate( + VADisplay dpy +); + +/** + * vaQueryVendorString returns a pointer to a zero-terminated string + * describing some aspects of the VA implemenation on a specific + * hardware accelerator. The format of the returned string is vendor + * specific and at the discretion of the implementer. + * e.g. for the Intel GMA500 implementation, an example would be: + * "Intel GMA500 - 2.0.0.32L.0005" + */ +const char *vaQueryVendorString( + VADisplay dpy +); + +typedef int (*VAPrivFunc)(void); + +/** + * Return a function pointer given a function name in the library. + * This allows private interfaces into the library + */ +VAPrivFunc vaGetLibFunc( + VADisplay dpy, + const char *func +); + +/** Currently defined profiles */ +typedef enum { + /** \brief Profile ID used for video processing. */ + VAProfileNone = -1, + VAProfileMPEG2Simple = 0, + VAProfileMPEG2Main = 1, + VAProfileMPEG4Simple = 2, + VAProfileMPEG4AdvancedSimple = 3, + VAProfileMPEG4Main = 4, + VAProfileH264Baseline va_deprecated_enum = 5, + VAProfileH264Main = 6, + VAProfileH264High = 7, + VAProfileVC1Simple = 8, + VAProfileVC1Main = 9, + VAProfileVC1Advanced = 10, + VAProfileH263Baseline = 11, + VAProfileJPEGBaseline = 12, + VAProfileH264ConstrainedBaseline = 13, + VAProfileVP8Version0_3 = 14, + VAProfileH264MultiviewHigh = 15, + VAProfileH264StereoHigh = 16, + VAProfileHEVCMain = 17, + VAProfileHEVCMain10 = 18, + VAProfileVP9Profile0 = 19, + VAProfileVP9Profile1 = 20, + VAProfileVP9Profile2 = 21, + VAProfileVP9Profile3 = 22, + VAProfileHEVCMain12 = 23, + VAProfileHEVCMain422_10 = 24, + VAProfileHEVCMain422_12 = 25, + VAProfileHEVCMain444 = 26, + VAProfileHEVCMain444_10 = 27, + VAProfileHEVCMain444_12 = 28, + VAProfileHEVCSccMain = 29, + VAProfileHEVCSccMain10 = 30, + VAProfileHEVCSccMain444 = 31, + VAProfileAV1Profile0 = 32, + VAProfileAV1Profile1 = 33, + VAProfileHEVCSccMain444_10 = 34, + /** \brief Profile ID used for protected video playback. */ + VAProfileProtected = 35 +} VAProfile; + +/** + * Currently defined entrypoints + */ +typedef enum { + VAEntrypointVLD = 1, + VAEntrypointIZZ = 2, + VAEntrypointIDCT = 3, + VAEntrypointMoComp = 4, + VAEntrypointDeblocking = 5, + VAEntrypointEncSlice = 6, /* slice level encode */ + VAEntrypointEncPicture = 7, /* pictuer encode, JPEG, etc */ + /* + * For an implementation that supports a low power/high performance variant + * for slice level encode, it can choose to expose the + * VAEntrypointEncSliceLP entrypoint. Certain encoding tools may not be + * available with this entrypoint (e.g. interlace, MBAFF) and the + * application can query the encoding configuration attributes to find + * out more details if this entrypoint is supported. + */ + VAEntrypointEncSliceLP = 8, + VAEntrypointVideoProc = 10, /**< Video pre/post-processing. */ + /** + * \brief VAEntrypointFEI + * + * The purpose of FEI (Flexible Encoding Infrastructure) is to allow applications to + * have more controls and trade off quality for speed with their own IPs. + * The application can optionally provide input to ENC for extra encode control + * and get the output from ENC. Application can chose to modify the ENC + * output/PAK input during encoding, but the performance impact is significant. + * + * On top of the existing buffers for normal encode, there will be + * one extra input buffer (VAEncMiscParameterFEIFrameControl) and + * three extra output buffers (VAEncFEIMVBufferType, VAEncFEIMBModeBufferType + * and VAEncFEIDistortionBufferType) for VAEntrypointFEI entry function. + * If separate PAK is set, two extra input buffers + * (VAEncFEIMVBufferType, VAEncFEIMBModeBufferType) are needed for PAK input. + **/ + VAEntrypointFEI = 11, + /** + * \brief VAEntrypointStats + * + * A pre-processing function for getting some statistics and motion vectors is added, + * and some extra controls for Encode pipeline are provided. The application can + * optionally call the statistics function to get motion vectors and statistics like + * variances, distortions before calling Encode function via this entry point. + * + * Checking whether Statistics is supported can be performed with vaQueryConfigEntrypoints(). + * If Statistics entry point is supported, then the list of returned entry-points will + * include #VAEntrypointStats. Supported pixel format, maximum resolution and statistics + * specific attributes can be obtained via normal attribute query. One input buffer + * (VAStatsStatisticsParameterBufferType) and one or two output buffers + * (VAStatsStatisticsBufferType, VAStatsStatisticsBottomFieldBufferType (for interlace only) + * and VAStatsMVBufferType) are needed for this entry point. + **/ + VAEntrypointStats = 12, + /** + * \brief VAEntrypointProtectedTEEComm + * + * A function for communicating with TEE (Trusted Execution Environment). + **/ + VAEntrypointProtectedTEEComm = 13, + /** + * \brief VAEntrypointProtectedContent + * + * A function for protected content to decrypt encrypted content. + **/ + VAEntrypointProtectedContent = 14, +} VAEntrypoint; + +/** Currently defined configuration attribute types */ +typedef enum { + VAConfigAttribRTFormat = 0, + VAConfigAttribSpatialResidual = 1, + VAConfigAttribSpatialClipping = 2, + VAConfigAttribIntraResidual = 3, + VAConfigAttribEncryption = 4, + VAConfigAttribRateControl = 5, + + /** @name Attributes for decoding */ + /**@{*/ + /** + * \brief Slice Decoding mode. Read/write. + * + * This attribute determines what mode the driver supports for slice + * decoding, through vaGetConfigAttributes(); and what mode the user + * will be providing to the driver, through vaCreateConfig(), if the + * driver supports those. If this attribute is not set by the user then + * it is assumed that VA_DEC_SLICE_MODE_NORMAL mode is used. + * + * See \c VA_DEC_SLICE_MODE_xxx for the list of slice decoding modes. + */ + VAConfigAttribDecSliceMode = 6, + /** + * \brief JPEG decoding attribute. Read-only. + * + * This attribute exposes a number of capabilities of the underlying + * JPEG implementation. The attribute value is partitioned into fields as defined in the + * VAConfigAttribValDecJPEG union. + */ + VAConfigAttribDecJPEG = 7, + /** + * \brief Decode processing support. Read/write. + * + * This attribute determines if the driver supports video processing + * with decoding using the decoding context in a single call, through + * vaGetConfigAttributes(); and if the user may use this feature, + * through vaCreateConfig(), if the driver supports the user scenario. + * The user will essentially create a regular decode VAContext. Therefore, + * the parameters of vaCreateContext() such as picture_width, picture_height + * and render_targets are in relation to the decode output parameters + * (not processing output parameters) as normal. + * If this attribute is not set by the user then it is assumed that no + * extra processing is done after decoding for this decode context. + * + * Since essentially the application is creating a decoder config and context, + * all function calls that take in the config (e.g. vaQuerySurfaceAttributes()) + * or context are in relation to the decoder, except those video processing + * function specified in the next paragraph. + * + * Once the decode config and context are created, the user must further + * query the supported processing filters using vaQueryVideoProcFilters(), + * vaQueryVideoProcFilterCaps(), vaQueryVideoProcPipelineCaps() by specifying + * the created decode context. The user must provide processing information + * and extra processing output surfaces as "additional_outputs" to the driver + * through VAProcPipelineParameterBufferType. The render_target specified + * at vaBeginPicture() time refers to the decode output surface. The + * target surface for the output of processing needs to be a different + * surface since the decode process requires the original reconstructed buffer. + * The “surface” member of VAProcPipelineParameterBuffer should be set to the + * same as “render_target” set in vaBeginPicture(), but the driver may choose + * to ignore this parameter. + */ + VAConfigAttribDecProcessing = 8, + /** @name Attributes for encoding */ + /**@{*/ + /** + * \brief Packed headers mode. Read/write. + * + * This attribute determines what packed headers the driver supports, + * through vaGetConfigAttributes(); and what packed headers the user + * will be providing to the driver, through vaCreateConfig(), if the + * driver supports those. + * + * See \c VA_ENC_PACKED_HEADER_xxx for the list of packed headers. + */ + VAConfigAttribEncPackedHeaders = 10, + /** + * \brief Interlaced mode. Read/write. + * + * This attribute determines what kind of interlaced encoding mode + * the driver supports. + * + * See \c VA_ENC_INTERLACED_xxx for the list of interlaced modes. + */ + VAConfigAttribEncInterlaced = 11, + /** + * \brief Maximum number of reference frames. Read-only. + * + * This attribute determines the maximum number of reference + * frames supported for encoding. + * + * Note: for H.264 encoding, the value represents the maximum number + * of reference frames for both the reference picture list 0 (bottom + * 16 bits) and the reference picture list 1 (top 16 bits). + */ + VAConfigAttribEncMaxRefFrames = 13, + /** + * \brief Maximum number of slices per frame. Read-only. + * + * This attribute determines the maximum number of slices the + * driver can support to encode a single frame. + */ + VAConfigAttribEncMaxSlices = 14, + /** + * \brief Slice structure. Read-only. + * + * This attribute determines slice structures supported by the + * driver for encoding. This attribute is a hint to the user so + * that he can choose a suitable surface size and how to arrange + * the encoding process of multiple slices per frame. + * + * More specifically, for H.264 encoding, this attribute + * determines the range of accepted values to + * VAEncSliceParameterBufferH264::macroblock_address and + * VAEncSliceParameterBufferH264::num_macroblocks. + * + * See \c VA_ENC_SLICE_STRUCTURE_xxx for the supported slice + * structure types. + */ + VAConfigAttribEncSliceStructure = 15, + /** + * \brief Macroblock information. Read-only. + * + * This attribute determines whether the driver supports extra + * encoding information per-macroblock. e.g. QP. + * + * More specifically, for H.264 encoding, if the driver returns a non-zero + * value for this attribute, this means the application can create + * additional #VAEncMacroblockParameterBufferH264 buffers referenced + * through VAEncSliceParameterBufferH264::macroblock_info. + */ + VAConfigAttribEncMacroblockInfo = 16, + /** + * \brief Maximum picture width. Read-only. + * + * This attribute determines the maximum picture width the driver supports + * for a given configuration. + */ + VAConfigAttribMaxPictureWidth = 18, + /** + * \brief Maximum picture height. Read-only. + * + * This attribute determines the maximum picture height the driver supports + * for a given configuration. + */ + VAConfigAttribMaxPictureHeight = 19, + /** + * \brief JPEG encoding attribute. Read-only. + * + * This attribute exposes a number of capabilities of the underlying + * JPEG implementation. The attribute value is partitioned into fields as defined in the + * VAConfigAttribValEncJPEG union. + */ + VAConfigAttribEncJPEG = 20, + /** + * \brief Encoding quality range attribute. Read-only. + * + * This attribute conveys whether the driver supports different quality level settings + * for encoding. A value less than or equal to 1 means that the encoder only has a single + * quality setting, and a value greater than 1 represents the number of quality levels + * that can be configured. e.g. a value of 2 means there are two distinct quality levels. + */ + VAConfigAttribEncQualityRange = 21, + /** + * \brief Encoding quantization attribute. Read-only. + * + * This attribute conveys whether the driver supports certain types of quantization methods + * for encoding (e.g. trellis). See \c VA_ENC_QUANTIZATION_xxx for the list of quantization methods + */ + VAConfigAttribEncQuantization = 22, + /** + * \brief Encoding intra refresh attribute. Read-only. + * + * This attribute conveys whether the driver supports certain types of intra refresh methods + * for encoding (e.g. adaptive intra refresh or rolling intra refresh). + * See \c VA_ENC_INTRA_REFRESH_xxx for intra refresh methods + */ + VAConfigAttribEncIntraRefresh = 23, + /** + * \brief Encoding skip frame attribute. Read-only. + * + * This attribute conveys whether the driver supports sending skip frame parameters + * (VAEncMiscParameterTypeSkipFrame) to the encoder's rate control, when the user has + * externally skipped frames. + */ + VAConfigAttribEncSkipFrame = 24, + /** + * \brief Encoding region-of-interest (ROI) attribute. Read-only. + * + * This attribute conveys whether the driver supports region-of-interest (ROI) encoding, + * based on user provided ROI rectangles. The attribute value is partitioned into fields + * as defined in the VAConfigAttribValEncROI union. + * + * If ROI encoding is supported, the ROI information is passed to the driver using + * VAEncMiscParameterTypeROI. + */ + VAConfigAttribEncROI = 25, + /** + * \brief Encoding extended rate control attribute. Read-only. + * + * This attribute conveys whether the driver supports any extended rate control features + * The attribute value is partitioned into fields as defined in the + * VAConfigAttribValEncRateControlExt union. + */ + VAConfigAttribEncRateControlExt = 26, + /** + * \brief Processing rate reporting attribute. Read-only. + * + * This attribute conveys whether the driver supports reporting of + * encode/decode processing rate based on certain set of parameters + * (i.e. levels, I frame internvals) for a given configuration. + * If this is supported, vaQueryProcessingRate() can be used to get + * encode or decode processing rate. + * See \c VA_PROCESSING_RATE_xxx for encode/decode processing rate + */ + VAConfigAttribProcessingRate = 27, + /** + * \brief Encoding dirty rectangle. Read-only. + * + * This attribute conveys whether the driver supports dirty rectangle. + * encoding, based on user provided ROI rectangles which indicate the rectangular areas + * where the content has changed as compared to the previous picture. The regions of the + * picture that are not covered by dirty rect rectangles are assumed to have not changed + * compared to the previous picture. The encoder may do some optimizations based on + * this information. The attribute value returned indicates the number of regions that + * are supported. e.g. A value of 0 means dirty rect encoding is not supported. If dirty + * rect encoding is supported, the ROI information is passed to the driver using + * VAEncMiscParameterTypeDirtyRect. + */ + VAConfigAttribEncDirtyRect = 28, + /** + * \brief Parallel Rate Control (hierachical B) attribute. Read-only. + * + * This attribute conveys whether the encoder supports parallel rate control. + * It is a integer value 0 - unsupported, > 0 - maximum layer supported. + * This is the way when hireachical B frames are encoded, multiple independent B frames + * on the same layer may be processed at same time. If supported, app may enable it by + * setting enable_parallel_brc in VAEncMiscParameterRateControl,and the number of B frames + * per layer per GOP will be passed to driver through VAEncMiscParameterParallelRateControl + * structure.Currently three layers are defined. + */ + VAConfigAttribEncParallelRateControl = 29, + /** + * \brief Dynamic Scaling Attribute. Read-only. + * + * This attribute conveys whether encoder is capable to determine dynamic frame + * resolutions adaptive to bandwidth utilization and processing power, etc. + * It is a boolean value 0 - unsupported, 1 - supported. + * If it is supported,for VP9, suggested frame resolution can be retrieved from VACodedBufferVP9Status. + */ + VAConfigAttribEncDynamicScaling = 30, + /** + * \brief frame size tolerance support + * it indicates the tolerance of frame size + */ + VAConfigAttribFrameSizeToleranceSupport = 31, + /** + * \brief Encode function type for FEI. + * + * This attribute conveys whether the driver supports different function types for encode. + * It can be VA_FEI_FUNCTION_ENC, VA_FEI_FUNCTION_PAK, or VA_FEI_FUNCTION_ENC_PAK. Currently + * it is for FEI entry point only. + * Default is VA_FEI_FUNCTION_ENC_PAK. + */ + VAConfigAttribFEIFunctionType = 32, + /** + * \brief Maximum number of FEI MV predictors. Read-only. + * + * This attribute determines the maximum number of MV predictors the driver + * can support to encode a single frame. 0 means no MV predictor is supported. + * Currently it is for FEI entry point only. + */ + VAConfigAttribFEIMVPredictors = 33, + /** + * \brief Statistics attribute. Read-only. + * + * This attribute exposes a number of capabilities of the VAEntrypointStats entry + * point. The attribute value is partitioned into fields as defined in the + * VAConfigAttribValStats union. Currently it is for VAEntrypointStats only. + */ + VAConfigAttribStats = 34, + /** + * \brief Tile Support Attribute. Read-only. + * + * This attribute conveys whether encoder is capable to support tiles. + * If not supported, the tile related parameters sent to encoder, such as + * tiling structure, should be ignored. 0 - unsupported, 1 - supported. + */ + VAConfigAttribEncTileSupport = 35, + /** + * \brief whether accept rouding setting from application. Read-only. + * This attribute is for encode quality, if it is report, + * application can change the rounding setting by VAEncMiscParameterTypeCustomRoundingControl + */ + VAConfigAttribCustomRoundingControl = 36, + /** + * \brief Encoding QP info block size attribute. Read-only. + * This attribute conveys the block sizes that underlying driver + * support for QP info for buffer #VAEncQpBuffer. + */ + VAConfigAttribQPBlockSize = 37, + /** + * \brief encode max frame size attribute. Read-only + * attribute value \c VAConfigAttribValMaxFrameSize represent max frame size support + */ + VAConfigAttribMaxFrameSize = 38, + /** \brief inter frame prediction directrion attribute. Read-only. + * this attribute conveys the prediction direction (backward or forword) for specific config + * the value could be VA_PREDICTION_DIRECTION_XXXX. it can be combined with VAConfigAttribEncMaxRefFrames + * to describe reference list , and the prediction direction. if this attrib is not present,both direction + * should be supported, no restriction. + * for example: normal HEVC encoding , maximum reference frame number in reflist 0 and reflist 1 is deduced + * by VAConfigAttribEncMaxRefFrames. so there are typical P frame, B frame, + * if VAConfigAttribPredictionDirection is also present. it will stipulate prediction direction in both + * reference list. if only one prediction direction present(such as PREVIOUS),all reference frame should be + * previous frame (PoC < current). + */ + VAConfigAttribPredictionDirection = 39, + /** \brief combined submission of multiple frames from different streams, it is optimization for different HW + * implementation, multiple frames encode/decode can improve HW concurrency + */ + VAConfigAttribMultipleFrame = 40, + /** \brief priority setting for the context. Read-Write + * attribute value is \c VAConfigAttribValContextPriority + * this setting also could be update by \c VAContextParameterUpdateBuffer + */ + VAConfigAttribContextPriority = 41, + /** \brief AV1 decoding features. Read-only. + * + * This attribute describes the supported features of an + * AV1 decoder configuration. The value returned uses the + * VAConfigAttribValDecAV1Features type. + */ + VAConfigAttribDecAV1Features = 42, + /** \brief TEE could be any HW secure device. Read-only */ + VAConfigAttribTEEType = 43, + /** \brief TEE type client is a specific module supporting specific functions in TEE. Read-only*/ + VAConfigAttribTEETypeClient = 44, + /** + * \brief Cipher algorithm of the protected content session. + * + * This attribute specifies the cipher algorithm of the protected content session. It + * could be \c VA_PC_CIPHER_AES, etc.... + */ + VAConfigAttribProtectedContentCipherAlgorithm = 45, + /** + * \brief Cipher block size of the protected content session. + * + * This attribute specifies the block size of the protected content session. It could be + * \c VA_PC_BLOCK_SIZE_128, \c VA_PC_BLOCK_SIZE_192, or \c VA_PC_BLOCK_SIZE_256, etc.... + */ + VAConfigAttribProtectedContentCipherBlockSize = 46, + /** + * \brief Cipher mode of the protected content session. + * + * This attribute specifies the cipher mode of the protected content session. It could + * be \c VA_PC_CIPHER_MODE_ECB, \c VA_PC_CIPHER_MODE_CBC, \c VA_PC_CIPHER_MODE_CTR, etc... + */ + VAConfigAttribProtectedContentCipherMode = 47, + /** + * \brief Decryption sample type of the protected content session. + * + * This attribute specifies the decryption sample type of the protected content session. + * It could be \c VA_PC_SAMPLE_TYPE_FULLSAMPLE or \c VA_PC_SAMPLE_TYPE_SUBSAMPLE. + */ + VAConfigAttribProtectedContentCipherSampleType = 48, + /** + * \brief Special usage attribute of the protected session. + * + * The attribute specifies the flow for the protected session could be used. For + * example, it could be \c VA_PC_USAGE_DEFAULT, \c VA_PC_USAGE_WIDEVINE, etc.... + */ + VAConfigAttribProtectedContentUsage = 49, + + /** \brief HEVC/H.265 encoding features. Read-only. + * + * This attribute describes the supported features of an + * HEVC/H.265 encoder configuration. The value returned uses the + * VAConfigAttribValEncHEVCFeatures type. + * + * If this attribute is supported by a driver then it must also + * support the VAConfigAttribEncHEVCBlockSizes attribute. + */ + VAConfigAttribEncHEVCFeatures = 50, + /** \brief HEVC/H.265 encoding block sizes. Read-only. + * + * This attribute describes the supported coding tree and transform + * block sizes of an HEVC/H.265 encoder configuration. The value + * returned uses the VAConfigAttribValEncHEVCBlockSizes type. + * + * If this attribute is supported by a driver then it must also + * support the VAConfigAttribEncHEVCFeatures attribute. + */ + VAConfigAttribEncHEVCBlockSizes = 51, + /** + * \brief AV1 encoding attribute. Read-only. + * + * This attribute exposes a number of capabilities of the underlying + * AV1 implementation. The attribute value is partitioned into fields as defined in the + * VAConfigAttribValEncAV1 union. + */ + VAConfigAttribEncAV1 = 52, + /** + * \brief AV1 encoding attribute extend1. Read-only. + * + * This attribute exposes a number of capabilities of the underlying + * AV1 implementation. The attribute value is partitioned into fields as defined in the + * VAConfigAttribValEncAV1Ext1 union. + */ + VAConfigAttribEncAV1Ext1 = 53, + /** + * \brief AV1 encoding attribute extend2. Read-only. + * + * This attribute exposes a number of capabilities of the underlying + * AV1 implementation. The attribute value is partitioned into fields as defined in the + * VAConfigAttribValEncAV1Ext2 union. + */ + VAConfigAttribEncAV1Ext2 = 54, + /** \brief Settings per block attribute for Encoding. Read-only. + * + * This attribute describes whether to support delta qp per block, + * the supported size of delta qp block and the size of delta QP in bytes. + * The value returned uses the VAConfigAttribValEncPerBlockControl type. + */ + VAConfigAttribEncPerBlockControl = 55, + /**@}*/ + VAConfigAttribTypeMax +} VAConfigAttribType; + +/** + * Configuration attributes + * If there is more than one value for an attribute, a default + * value will be assigned to the attribute if the client does not + * specify the attribute when creating a configuration + */ +typedef struct _VAConfigAttrib { + VAConfigAttribType type; + uint32_t value; /* OR'd flags (bits) for this attribute */ +} VAConfigAttrib; + +/* Attribute values for VAConfigAttribRTFormat. */ + +#define VA_RT_FORMAT_YUV420 0x00000001 ///< YUV 4:2:0 8-bit. +#define VA_RT_FORMAT_YUV422 0x00000002 ///< YUV 4:2:2 8-bit. +#define VA_RT_FORMAT_YUV444 0x00000004 ///< YUV 4:4:4 8-bit. +#define VA_RT_FORMAT_YUV411 0x00000008 ///< YUV 4:1:1 8-bit. +#define VA_RT_FORMAT_YUV400 0x00000010 ///< Greyscale 8-bit. +#define VA_RT_FORMAT_YUV420_10 0x00000100 ///< YUV 4:2:0 10-bit. +#define VA_RT_FORMAT_YUV422_10 0x00000200 ///< YUV 4:2:2 10-bit. +#define VA_RT_FORMAT_YUV444_10 0x00000400 ///< YUV 4:4:4 10-bit. +#define VA_RT_FORMAT_YUV420_12 0x00001000 ///< YUV 4:2:0 12-bit. +#define VA_RT_FORMAT_YUV422_12 0x00002000 ///< YUV 4:2:2 12-bit. +#define VA_RT_FORMAT_YUV444_12 0x00004000 ///< YUV 4:4:4 12-bit. + +#define VA_RT_FORMAT_RGB16 0x00010000 ///< Packed RGB, 16 bits per pixel. +#define VA_RT_FORMAT_RGB32 0x00020000 ///< Packed RGB, 32 bits per pixel, 8 bits per colour sample. +#define VA_RT_FORMAT_RGBP 0x00100000 ///< Planar RGB, 8 bits per sample. +#define VA_RT_FORMAT_RGB32_10 0x00200000 ///< Packed RGB, 32 bits per pixel, 10 bits per colour sample. + +#define VA_RT_FORMAT_PROTECTED 0x80000000 + +#define VA_RT_FORMAT_RGB32_10BPP VA_RT_FORMAT_RGB32_10 ///< @deprecated use VA_RT_FORMAT_RGB32_10 instead. +#define VA_RT_FORMAT_YUV420_10BPP VA_RT_FORMAT_YUV420_10 ///< @deprecated use VA_RT_FORMAT_YUV420_10 instead. + +/** @name Attribute values for VAConfigAttribRateControl */ +/**@{*/ +/** \brief Driver does not support any form of rate control. */ +#define VA_RC_NONE 0x00000001 +/** \brief Constant bitrate. */ +#define VA_RC_CBR 0x00000002 +/** \brief Variable bitrate. */ +#define VA_RC_VBR 0x00000004 +/** \brief Video conference mode. */ +#define VA_RC_VCM 0x00000008 +/** \brief Constant QP. */ +#define VA_RC_CQP 0x00000010 +/** \brief Variable bitrate with peak rate higher than average bitrate. */ +#define VA_RC_VBR_CONSTRAINED 0x00000020 +/** \brief Intelligent Constant Quality. Provided an initial ICQ_quality_factor, + * adjusts QP at a frame and MB level based on motion to improve subjective quality. */ +#define VA_RC_ICQ 0x00000040 +/** \brief Macroblock based rate control. Per MB control is decided + * internally in the encoder. It may be combined with other RC modes, except CQP. */ +#define VA_RC_MB 0x00000080 +/** \brief Constant Frame Size, it is used for small tolerent */ +#define VA_RC_CFS 0x00000100 +/** \brief Parallel BRC, for hierachical B. + * + * For hierachical B, B frames can be refered by other B frames. + * Currently three layers of hierachy are defined: + * B0 - regular B, no reference to other B frames. + * B1 - reference to only I, P and regular B0 frames. + * B2 - reference to any other frames, including B1. + * In Hierachical B structure, B frames on the same layer can be processed + * simultaneously. And BRC would adjust accordingly. This is so called + * Parallel BRC. */ +#define VA_RC_PARALLEL 0x00000200 +/** \brief Quality defined VBR + * Use Quality factor to determine the good enough QP for each MB such that + * good enough quality can be obtained without waste of bits + * for this BRC mode, you must set all legacy VBR parameters + * and reuse quality_factor in \c VAEncMiscParameterRateControl + * */ +#define VA_RC_QVBR 0x00000400 +/** \brief Average VBR + * Average variable bitrate control algorithm focuses on overall encoding + * quality while meeting the specified target bitrate, within the accuracy + * range, after a convergence period. + * bits_per_second in VAEncMiscParameterRateControl is target bitrate for AVBR. + * Convergence is specified in the unit of frame. + * window_size in VAEncMiscParameterRateControl is equal to convergence for AVBR. + * Accuracy is in the range of [1,100], 1 means one percent, and so on. + * target_percentage in VAEncMiscParameterRateControl is equal to accuracy for AVBR. + * */ +#define VA_RC_AVBR 0x00000800 +/** \brief Transport Controlled BRC + * Specific bitrate control for real time streaming. + * TCBRC can instantly react to channel change to remove or significantly reduce the delay. + * Application (transport) provides channel feedback to driver through TargetFrameSize. + * When channel condition is very good (almost no constraint on instant frame size), + * the app should set target frame size as zero. Otherwise, channel capacity divided by fps + * should be used. + * */ +#define VA_RC_TCBRC 0x00001000 + +/**@}*/ + +/** @name Attribute values for VAConfigAttribDecSliceMode */ +/**@{*/ +/** \brief Driver supports normal mode for slice decoding */ +#define VA_DEC_SLICE_MODE_NORMAL 0x00000001 +/** \brief Driver supports base mode for slice decoding */ +#define VA_DEC_SLICE_MODE_BASE 0x00000002 + +/** @name Attribute values for VAConfigAttribDecJPEG */ +/**@{*/ +typedef union _VAConfigAttribValDecJPEG { + struct { + /** \brief Set to (1 << VA_ROTATION_xxx) for supported rotation angles. */ + uint32_t rotation : 4; + /** \brief Reserved for future use. */ + uint32_t reserved : 28; + } bits; + uint32_t value; +} VAConfigAttribValDecJPEG; +/** @name Attribute values for VAConfigAttribDecProcessing */ +/**@{*/ +/** \brief No decoding + processing in a single decoding call. */ +#define VA_DEC_PROCESSING_NONE 0x00000000 +/** \brief Decode + processing in a single decoding call. */ +#define VA_DEC_PROCESSING 0x00000001 +/**@}*/ + +/** @name Attribute values for VAConfigAttribEncPackedHeaders */ +/**@{*/ +/** \brief Driver does not support any packed headers mode. */ +#define VA_ENC_PACKED_HEADER_NONE 0x00000000 +/** + * \brief Driver supports packed sequence headers. e.g. SPS for H.264. + * + * Application must provide it to driver once this flag is returned through + * vaGetConfigAttributes() + */ +#define VA_ENC_PACKED_HEADER_SEQUENCE 0x00000001 +/** + * \brief Driver supports packed picture headers. e.g. PPS for H.264. + * + * Application must provide it to driver once this falg is returned through + * vaGetConfigAttributes() + */ +#define VA_ENC_PACKED_HEADER_PICTURE 0x00000002 +/** + * \brief Driver supports packed slice headers. e.g. slice_header() for H.264. + * + * Application must provide it to driver once this flag is returned through + * vaGetConfigAttributes() + */ +#define VA_ENC_PACKED_HEADER_SLICE 0x00000004 +/** + * \brief Driver supports misc packed headers. e.g. SEI for H.264. + * + * @deprecated + * This is a deprecated packed header flag, All applications can use + * \c VA_ENC_PACKED_HEADER_RAW_DATA to pass the corresponding packed + * header data buffer to the driver + */ +#define VA_ENC_PACKED_HEADER_MISC 0x00000008 +/** \brief Driver supports raw packed header, see VAEncPackedHeaderRawData */ +#define VA_ENC_PACKED_HEADER_RAW_DATA 0x00000010 +/**@}*/ + +/** @name Attribute values for VAConfigAttribEncInterlaced */ +/**@{*/ +/** \brief Driver does not support interlaced coding. */ +#define VA_ENC_INTERLACED_NONE 0x00000000 +/** \brief Driver supports interlaced frame coding. */ +#define VA_ENC_INTERLACED_FRAME 0x00000001 +/** \brief Driver supports interlaced field coding. */ +#define VA_ENC_INTERLACED_FIELD 0x00000002 +/** \brief Driver supports macroblock adaptive frame field coding. */ +#define VA_ENC_INTERLACED_MBAFF 0x00000004 +/** \brief Driver supports picture adaptive frame field coding. */ +#define VA_ENC_INTERLACED_PAFF 0x00000008 +/**@}*/ + +/** @name Attribute values for VAConfigAttribEncSliceStructure */ +/**@{*/ +/** \brief Driver supports a power-of-two number of rows per slice. */ +#define VA_ENC_SLICE_STRUCTURE_POWER_OF_TWO_ROWS 0x00000001 +/** \brief Driver supports an arbitrary number of macroblocks per slice. */ +#define VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS 0x00000002 +/** \brief Driver support 1 row per slice */ +#define VA_ENC_SLICE_STRUCTURE_EQUAL_ROWS 0x00000004 +/** \brief Driver support max encoded slice size per slice */ +#define VA_ENC_SLICE_STRUCTURE_MAX_SLICE_SIZE 0x00000008 +/** \brief Driver supports an arbitrary number of rows per slice. */ +#define VA_ENC_SLICE_STRUCTURE_ARBITRARY_ROWS 0x00000010 +/** \brief Driver supports any number of rows per slice but they must be the same +* for all slices except for the last one, which must be equal or smaller +* to the previous slices. */ +#define VA_ENC_SLICE_STRUCTURE_EQUAL_MULTI_ROWS 0x00000020 +/**@}*/ + +/** \brief Attribute value for VAConfigAttribMaxFrameSize */ +typedef union _VAConfigAttribValMaxFrameSize { + struct { + /** \brief support max frame size + * if max_frame_size == 1, VAEncMiscParameterTypeMaxFrameSize/VAEncMiscParameterBufferMaxFrameSize + * could be used to set the frame size, if multiple_pass also equal 1, VAEncMiscParameterTypeMultiPassFrameSize + * VAEncMiscParameterBufferMultiPassFrameSize could be used to set frame size and pass information + */ + uint32_t max_frame_size : 1; + /** \brief multiple_pass support */ + uint32_t multiple_pass : 1; + /** \brief reserved bits for future, must be zero*/ + uint32_t reserved : 30; + } bits; + uint32_t value; +} VAConfigAttribValMaxFrameSize; + +/** \brief Attribute value for VAConfigAttribEncJPEG */ +typedef union _VAConfigAttribValEncJPEG { + struct { + /** \brief set to 1 for arithmatic coding. */ + uint32_t arithmatic_coding_mode : 1; + /** \brief set to 1 for progressive dct. */ + uint32_t progressive_dct_mode : 1; + /** \brief set to 1 for non-interleaved. */ + uint32_t non_interleaved_mode : 1; + /** \brief set to 1 for differential. */ + uint32_t differential_mode : 1; + uint32_t max_num_components : 3; + uint32_t max_num_scans : 4; + uint32_t max_num_huffman_tables : 3; + uint32_t max_num_quantization_tables : 3; + } bits; + uint32_t value; +} VAConfigAttribValEncJPEG; + +/** @name Attribute values for VAConfigAttribEncQuantization */ +/**@{*/ +/** \brief Driver does not support special types of quantization */ +#define VA_ENC_QUANTIZATION_NONE 0x00000000 +/** \brief Driver supports trellis quantization */ +#define VA_ENC_QUANTIZATION_TRELLIS_SUPPORTED 0x00000001 +/**@}*/ + +/** @name Attribute values for VAConfigAttribPredictionDirection */ +/**@{*/ +/** \brief Driver support forward reference frame (inter frame for vpx, P frame for H26x MPEG) + * can work with the VAConfigAttribEncMaxRefFrames. for example: low delay B frame of HEVC. + * these value can be OR'd together. typical value should be VA_PREDICTION_DIRECTION_PREVIOUS + * or VA_PREDICTION_DIRECTION_PREVIOUS | VA_PREDICTION_DIRECTION_FUTURE, theoretically, there + * are no stream only include future reference frame. + */ +#define VA_PREDICTION_DIRECTION_PREVIOUS 0x00000001 +/** \brief Driver support backward prediction frame/slice */ +#define VA_PREDICTION_DIRECTION_FUTURE 0x00000002 +/** \brief Dirver require both reference list must be not empty for inter frame */ +#define VA_PREDICTION_DIRECTION_BI_NOT_EMPTY 0x00000004 +/**@}*/ + +/** @name Attribute values for VAConfigAttribEncIntraRefresh */ +/**@{*/ +/** \brief Driver does not support intra refresh */ +#define VA_ENC_INTRA_REFRESH_NONE 0x00000000 +/** \brief Driver supports column based rolling intra refresh */ +#define VA_ENC_INTRA_REFRESH_ROLLING_COLUMN 0x00000001 +/** \brief Driver supports row based rolling intra refresh */ +#define VA_ENC_INTRA_REFRESH_ROLLING_ROW 0x00000002 +/** \brief Driver supports adaptive intra refresh */ +#define VA_ENC_INTRA_REFRESH_ADAPTIVE 0x00000010 +/** \brief Driver supports cyclic intra refresh */ +#define VA_ENC_INTRA_REFRESH_CYCLIC 0x00000020 +/** \brief Driver supports intra refresh of P frame*/ +#define VA_ENC_INTRA_REFRESH_P_FRAME 0x00010000 +/** \brief Driver supports intra refresh of B frame */ +#define VA_ENC_INTRA_REFRESH_B_FRAME 0x00020000 +/** \brief Driver supports intra refresh of multiple reference encoder */ +#define VA_ENC_INTRA_REFRESH_MULTI_REF 0x00040000 + +/**@}*/ + +/** \brief Attribute value for VAConfigAttribEncROI */ +typedef union _VAConfigAttribValEncROI { + struct { + /** \brief The number of ROI regions supported, 0 if ROI is not supported. */ + uint32_t num_roi_regions : 8; + /** + * \brief A flag indicates whether ROI priority is supported + * + * \ref roi_rc_priority_support equal to 1 specifies the underlying driver supports + * ROI priority when VAConfigAttribRateControl != VA_RC_CQP, user can use \c roi_value + * in #VAEncROI to set ROI priority. \ref roi_rc_priority_support equal to 0 specifies + * the underlying driver doesn't support ROI priority. + * + * User should ignore \ref roi_rc_priority_support when VAConfigAttribRateControl == VA_RC_CQP + * because ROI delta QP is always required when VAConfigAttribRateControl == VA_RC_CQP. + */ + uint32_t roi_rc_priority_support : 1; + /** + * \brief A flag indicates whether ROI delta QP is supported + * + * \ref roi_rc_qp_delta_support equal to 1 specifies the underlying driver supports + * ROI delta QP when VAConfigAttribRateControl != VA_RC_CQP, user can use \c roi_value + * in #VAEncROI to set ROI delta QP. \ref roi_rc_qp_delta_support equal to 0 specifies + * the underlying driver doesn't support ROI delta QP. + * + * User should ignore \ref roi_rc_qp_delta_support when VAConfigAttribRateControl == VA_RC_CQP + * because ROI delta QP is always required when VAConfigAttribRateControl == VA_RC_CQP. + */ + uint32_t roi_rc_qp_delta_support : 1; + uint32_t reserved : 22; + } bits; + uint32_t value; +} VAConfigAttribValEncROI; + +/** \brief Attribute value for VAConfigAttribEncRateControlExt */ +typedef union _VAConfigAttribValEncRateControlExt { + struct { + /** + * \brief The maximum number of temporal layers minus 1 + * + * \ref max_num_temporal_layers_minus1 plus 1 specifies the maximum number of temporal + * layers that supported by the underlying driver. \ref max_num_temporal_layers_minus1 + * equal to 0 implies the underlying driver doesn't support encoding with temporal layer. + */ + uint32_t max_num_temporal_layers_minus1 : 8; + + /** + * /brief support temporal layer bit-rate control flag + * + * \ref temporal_layer_bitrate_control_flag equal to 1 specifies the underlying driver + * can support bit-rate control per temporal layer when (#VAConfigAttribRateControl == #VA_RC_CBR || + * #VAConfigAttribRateControl == #VA_RC_VBR). + * + * The underlying driver must set \ref temporal_layer_bitrate_control_flag to 0 when + * \c max_num_temporal_layers_minus1 is equal to 0 + * + * To use bit-rate control per temporal layer, an application must send the right layer + * structure via #VAEncMiscParameterTemporalLayerStructure at the beginning of a coded sequence + * and then followed by #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate structures + * for each layer, using the \c temporal_id field as the layer identifier. Otherwise + * the driver doesn't use bitrate control per temporal layer if an application doesn't send the + * layer structure via #VAEncMiscParameterTemporalLayerStructure to the driver. The driver returns + * VA_STATUS_ERROR_INVALID_PARAMETER if an application sends a wrong layer structure or doesn't send + * #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate for each layer. + * + * The driver will ignore #VAEncMiscParameterTemporalLayerStructure and the \c temporal_id field + * in #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate if + * \ref temporal_layer_bitrate_control_flag is equal to 0 or #VAConfigAttribRateControl == #VA_RC_CQP + */ + uint32_t temporal_layer_bitrate_control_flag : 1; + uint32_t reserved : 23; + } bits; + uint32_t value; +} VAConfigAttribValEncRateControlExt; + +/** \brief Attribute value for VAConfigAttribMultipleFrame*/ +typedef union _VAConfigAttribValMultipleFrame { + struct { + /** \brief max num of concurrent frames from different stream */ + uint32_t max_num_concurrent_frames : 8; + /** \brief indicate whether all stream must support same quality level + * if mixed_quality_level == 0, same quality level setting for multple streams is required + * if mixed_quality_level == 1, different stream can have different quality level*/ + uint32_t mixed_quality_level : 1; + /** \brief reserved bit for future, must be zero */ + uint32_t reserved : 23; + } bits; + uint32_t value; +} VAConfigAttribValMultipleFrame; + +/** brief Attribute value VAConfigAttribValContextPriority */ +typedef union _VAConfigAttribValContextPriority { + struct { + /** \brief the priority , for the Query operation (read) it represents highest priority + * for the set operation (write), value should be [0~highest priority] , 0 is lowest priority*/ + uint32_t priority : 16; + /** \brief reserved bits for future, must be zero*/ + uint32_t reserved : 16; + } bits; + uint32_t value; +} VAConfigAttribValContextPriority; + +/** brief Attribute value VAConfigAttribEncPerBlockControl */ +typedef union _VAConfigAttribValEncPerBlockControl { + struct { + /** \brief whether to support dela qp per block */ + uint32_t delta_qp_support : 1; + /** \brief supported size of delta qp block */ + uint32_t log2_delta_qp_block_size : 4; + /** \brief size of delta qp per block in bytes*/ + uint32_t delta_qp_size_in_bytes : 3; + /** \brief reserved bit for future, must be zero */ + uint32_t reserved : 24; + } bits; + uint32_t value; +} VAConfigAttribValEncPerBlockControl; + +/** @name Attribute values for VAConfigAttribProtectedContentCipherAlgorithm */ +/** \brief AES cipher */ +#define VA_PC_CIPHER_AES 0x00000001 + +/** @name Attribute values for VAConfigAttribProtectedContentCipherBlockSize */ +/** \brief 128 bits block size */ +#define VA_PC_BLOCK_SIZE_128 0x00000001 +/** \brief 192 bits block size */ +#define VA_PC_BLOCK_SIZE_192 0x00000002 +/** \brief 256 bits block size */ +#define VA_PC_BLOCK_SIZE_256 0x00000004 + +/** @name Attribute values for VAConfigAttribProtectedContentCipherMode */ +/** \brief AES ECB */ +#define VA_PC_CIPHER_MODE_ECB 0x00000001 +/** \brief AES CBC */ +#define VA_PC_CIPHER_MODE_CBC 0x00000002 +/** \brief AES CTR */ +#define VA_PC_CIPHER_MODE_CTR 0x00000004 + +/** @name Attribute values for VAConfigAttribProtectedContentCipherSampleType */ +/** \brief Full sample */ +#define VA_PC_SAMPLE_TYPE_FULLSAMPLE 0x00000001 +/** \brief Sub sample */ +#define VA_PC_SAMPLE_TYPE_SUBSAMPLE 0x00000002 + +/** @name Attribute values for VAConfigAttribProtectedContentUsage */ +/** \brief Default usage */ +#define VA_PC_USAGE_DEFAULT 0x00000000 +/** \brief Widevine */ +#define VA_PC_USAGE_WIDEVINE 0x00000001 + +/** @name Attribute values for VAConfigAttribProcessingRate. */ +/**@{*/ +/** \brief Driver does not support processing rate report */ +#define VA_PROCESSING_RATE_NONE 0x00000000 +/** \brief Driver supports encode processing rate report */ +#define VA_PROCESSING_RATE_ENCODE 0x00000001 +/** \brief Driver supports decode processing rate report */ +#define VA_PROCESSING_RATE_DECODE 0x00000002 +/**@}*/ +/** + * if an attribute is not applicable for a given + * profile/entrypoint pair, then set the value to the following + */ +#define VA_ATTRIB_NOT_SUPPORTED 0x80000000 + +/** Get maximum number of profiles supported by the implementation */ +int vaMaxNumProfiles( + VADisplay dpy +); + +/** Get maximum number of entrypoints supported by the implementation */ +int vaMaxNumEntrypoints( + VADisplay dpy +); + +/** Get maximum number of attributs supported by the implementation */ +int vaMaxNumConfigAttributes( + VADisplay dpy +); + +/** + * Query supported profiles + * The caller must provide a "profile_list" array that can hold at + * least vaMaxNumProfile() entries. The actual number of profiles + * returned in "profile_list" is returned in "num_profile". + */ +VAStatus vaQueryConfigProfiles( + VADisplay dpy, + VAProfile *profile_list, /* out */ + int *num_profiles /* out */ +); + +/** + * Query supported entrypoints for a given profile + * The caller must provide an "entrypoint_list" array that can hold at + * least vaMaxNumEntrypoints() entries. The actual number of entrypoints + * returned in "entrypoint_list" is returned in "num_entrypoints". + */ +VAStatus vaQueryConfigEntrypoints( + VADisplay dpy, + VAProfile profile, + VAEntrypoint *entrypoint_list, /* out */ + int *num_entrypoints /* out */ +); + +/** + * Get attributes for a given profile/entrypoint pair + * The caller must provide an "attrib_list" with all attributes to be + * retrieved. Upon return, the attributes in "attrib_list" have been + * updated with their value. Unknown attributes or attributes that are + * not supported for the given profile/entrypoint pair will have their + * value set to VA_ATTRIB_NOT_SUPPORTED + */ +VAStatus vaGetConfigAttributes( + VADisplay dpy, + VAProfile profile, + VAEntrypoint entrypoint, + VAConfigAttrib *attrib_list, /* in/out */ + int num_attribs +); + +/** Generic ID type, can be re-typed for specific implementation */ +typedef unsigned int VAGenericID; + +typedef VAGenericID VAConfigID; + +/** + * Create a configuration for the video decode/encode/processing pipeline + * it passes in the attribute list that specifies the attributes it cares + * about, with the rest taking default values. + */ +VAStatus vaCreateConfig( + VADisplay dpy, + VAProfile profile, + VAEntrypoint entrypoint, + VAConfigAttrib *attrib_list, + int num_attribs, + VAConfigID *config_id /* out */ +); + +/** + * Free resources associdated with a given config + */ +VAStatus vaDestroyConfig( + VADisplay dpy, + VAConfigID config_id +); + +/** + * Query all attributes for a given configuration + * The profile of the configuration is returned in "profile" + * The entrypoint of the configuration is returned in "entrypoint" + * The caller must provide an "attrib_list" array that can hold at least + * vaMaxNumConfigAttributes() entries. The actual number of attributes + * returned in "attrib_list" is returned in "num_attribs" + */ +VAStatus vaQueryConfigAttributes( + VADisplay dpy, + VAConfigID config_id, + VAProfile *profile, /* out */ + VAEntrypoint *entrypoint, /* out */ + VAConfigAttrib *attrib_list,/* out */ + int *num_attribs /* out */ +); + + +/** + * Contexts and Surfaces + * + * Context represents a "virtual" video decode, encode or video processing + * pipeline. Surfaces are render targets for a given context. The data in the + * surfaces are not accessible to the client except if derived image is supported + * and the internal data format of the surface is implementation specific. + * + * Surfaces are provided as a hint of what surfaces will be used when the context + * is created through vaCreateContext(). A surface may be used by different contexts + * at the same time as soon as application can make sure the operations are synchronized + * between different contexts, e.g. a surface is used as the output of a decode context + * and the input of a video process context. Surfaces can only be destroyed after all + * contexts using these surfaces have been destroyed. + * + * Both contexts and surfaces are identified by unique IDs and its + * implementation specific internals are kept opaque to the clients + */ + +typedef VAGenericID VAContextID; + +typedef VAGenericID VASurfaceID; + +#define VA_INVALID_ID 0xffffffff +#define VA_INVALID_SURFACE VA_INVALID_ID + +/** \brief Generic value types. */ +typedef enum { + VAGenericValueTypeInteger = 1, /**< 32-bit signed integer. */ + VAGenericValueTypeFloat, /**< 32-bit floating-point value. */ + VAGenericValueTypePointer, /**< Generic pointer type */ + VAGenericValueTypeFunc /**< Pointer to function */ +} VAGenericValueType; + +/** \brief Generic function type. */ +typedef void (*VAGenericFunc)(void); + +/** \brief Generic value. */ +typedef struct _VAGenericValue { + /** \brief Value type. See #VAGenericValueType. */ + VAGenericValueType type; + /** \brief Value holder. */ + union { + /** \brief 32-bit signed integer. */ + int32_t i; + /** \brief 32-bit float. */ + float f; + /** \brief Generic pointer. */ + void *p; + /** \brief Pointer to function. */ + VAGenericFunc fn; + } value; +} VAGenericValue; + +/** @name Surface attribute flags */ +/**@{*/ +/** \brief Surface attribute is not supported. */ +#define VA_SURFACE_ATTRIB_NOT_SUPPORTED 0x00000000 +/** \brief Surface attribute can be got through vaQuerySurfaceAttributes(). */ +#define VA_SURFACE_ATTRIB_GETTABLE 0x00000001 +/** \brief Surface attribute can be set through vaCreateSurfaces(). */ +#define VA_SURFACE_ATTRIB_SETTABLE 0x00000002 +/**@}*/ + +/** \brief Surface attribute types. */ +typedef enum { + VASurfaceAttribNone = 0, + /** + * \brief Pixel format as a FOURCC (int, read/write). + * + * When vaQuerySurfaceAttributes() is called, the driver will return one + * PixelFormat attribute per supported pixel format. + * + * When provided as an input to vaCreateSurfaces(), the driver will + * allocate a surface with the provided pixel format. + */ + VASurfaceAttribPixelFormat, + /** \brief Minimal width in pixels (int, read-only). */ + VASurfaceAttribMinWidth, + /** \brief Maximal width in pixels (int, read-only). */ + VASurfaceAttribMaxWidth, + /** \brief Minimal height in pixels (int, read-only). */ + VASurfaceAttribMinHeight, + /** \brief Maximal height in pixels (int, read-only). */ + VASurfaceAttribMaxHeight, + /** \brief Surface memory type expressed in bit fields (int, read/write). */ + VASurfaceAttribMemoryType, + /** \brief External buffer descriptor (pointer, write). + * + * Refer to the documentation for the memory type being created to + * determine what descriptor structure to pass here. If not otherwise + * stated, the common VASurfaceAttribExternalBuffers should be used. + */ + VASurfaceAttribExternalBufferDescriptor, + /** \brief Surface usage hint, gives the driver a hint of intended usage + * to optimize allocation (e.g. tiling) (int, read/write). */ + VASurfaceAttribUsageHint, + /** \brief List of possible DRM format modifiers (pointer, write). + * + * The value must be a pointer to a VADRMFormatModifierList. This can only + * be used when allocating a new buffer, it's invalid to use this attribute + * when importing an existing buffer. + */ + VASurfaceAttribDRMFormatModifiers, + /** \brief Number of surface attributes. */ + VASurfaceAttribCount +} VASurfaceAttribType; + +/** \brief Surface attribute. */ +typedef struct _VASurfaceAttrib { + /** \brief Type. */ + VASurfaceAttribType type; + /** \brief Flags. See "Surface attribute flags". */ + uint32_t flags; + /** \brief Value. See "Surface attribute types" for the expected types. */ + VAGenericValue value; +} VASurfaceAttrib; + +/** + * @name VASurfaceAttribMemoryType values in bit fields. + * Bits 0:7 are reserved for generic types. Bits 31:28 are reserved for + * Linux DRM. Bits 23:20 are reserved for Android. Bits 19:16 are reserved for Win32. + * DRM, Android and Win32 specific types are defined in respective va_*.h header files. + */ +/**@{*/ +/** \brief VA memory type (default) is supported. */ +#define VA_SURFACE_ATTRIB_MEM_TYPE_VA 0x00000001 +/** \brief V4L2 buffer memory type is supported. */ +#define VA_SURFACE_ATTRIB_MEM_TYPE_V4L2 0x00000002 +/** \brief User pointer memory type is supported. */ +#define VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR 0x00000004 +/**@}*/ + +/** + * \brief VASurfaceAttribExternalBuffers structure for + * the VASurfaceAttribExternalBufferDescriptor attribute. + */ +typedef struct _VASurfaceAttribExternalBuffers { + /** \brief pixel format in fourcc. */ + uint32_t pixel_format; + /** \brief width in pixels. */ + uint32_t width; + /** \brief height in pixels. */ + uint32_t height; + /** \brief total size of the buffer in bytes. */ + uint32_t data_size; + /** \brief number of planes for planar layout */ + uint32_t num_planes; + /** \brief pitch for each plane in bytes */ + uint32_t pitches[4]; + /** \brief offset for each plane in bytes */ + uint32_t offsets[4]; + /** \brief buffer handles or user pointers */ + uintptr_t *buffers; + /** \brief number of elements in the "buffers" array */ + uint32_t num_buffers; + /** \brief flags. See "Surface external buffer descriptor flags". */ + uint32_t flags; + /** \brief reserved for passing private data */ + void *private_data; +} VASurfaceAttribExternalBuffers; + +/** @name VASurfaceAttribExternalBuffers flags */ +/**@{*/ +/** \brief Enable memory tiling */ +#define VA_SURFACE_EXTBUF_DESC_ENABLE_TILING 0x00000001 +/** \brief Memory is cacheable */ +#define VA_SURFACE_EXTBUF_DESC_CACHED 0x00000002 +/** \brief Memory is non-cacheable */ +#define VA_SURFACE_EXTBUF_DESC_UNCACHED 0x00000004 +/** \brief Memory is write-combined */ +#define VA_SURFACE_EXTBUF_DESC_WC 0x00000008 +/** \brief Memory is protected */ +#define VA_SURFACE_EXTBUF_DESC_PROTECTED 0x80000000 + +/** @name VASurfaceAttribUsageHint attribute usage hint flags */ +/**@{*/ +/** \brief Surface usage not indicated. */ +#define VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC 0x00000000 +/** \brief Surface used by video decoder. */ +#define VA_SURFACE_ATTRIB_USAGE_HINT_DECODER 0x00000001 +/** \brief Surface used by video encoder. */ +#define VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER 0x00000002 +/** \brief Surface read by video post-processing. */ +#define VA_SURFACE_ATTRIB_USAGE_HINT_VPP_READ 0x00000004 +/** \brief Surface written by video post-processing. */ +#define VA_SURFACE_ATTRIB_USAGE_HINT_VPP_WRITE 0x00000008 +/** \brief Surface used for display. */ +#define VA_SURFACE_ATTRIB_USAGE_HINT_DISPLAY 0x00000010 +/** \brief Surface used for export to third-party APIs, e.g. via + * vaExportSurfaceHandle(). */ +#define VA_SURFACE_ATTRIB_USAGE_HINT_EXPORT 0x00000020 + +/**@}*/ + +/** + * \brief Queries surface attributes for the supplied config. + * + * This function queries for all supported attributes for the + * supplied VA @config. In particular, if the underlying hardware + * supports the creation of VA surfaces in various formats, then + * this function will enumerate all pixel formats that are supported. + * + * The \c attrib_list array is allocated by the user and \c + * num_attribs shall be initialized to the number of allocated + * elements in that array. Upon successful return, the actual number + * of attributes will be overwritten into \c num_attribs. Otherwise, + * \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned and \c num_attribs + * is adjusted to the number of elements that would be returned if + * enough space was available. + * + * Note: it is perfectly valid to pass NULL to the \c attrib_list + * argument when vaQuerySurfaceAttributes() is used to determine the + * actual number of elements that need to be allocated. + * + * @param[in] dpy the VA display + * @param[in] config the config identifying a codec or a video + * processing pipeline + * @param[out] attrib_list the output array of #VASurfaceAttrib elements + * @param[in,out] num_attribs the number of elements allocated on + * input, the number of elements actually filled in output + */ +VAStatus +vaQuerySurfaceAttributes( + VADisplay dpy, + VAConfigID config, + VASurfaceAttrib *attrib_list, + unsigned int *num_attribs +); + +/** + * \brief Creates an array of surfaces + * + * Creates an array of surfaces. The optional list of attributes shall + * be constructed based on what the underlying hardware could expose + * through vaQuerySurfaceAttributes(). + * + * @param[in] dpy the VA display + * @param[in] format the desired surface format. See \c VA_RT_FORMAT_* + * @param[in] width the surface width + * @param[in] height the surface height + * @param[out] surfaces the array of newly created surfaces + * @param[in] num_surfaces the number of surfaces to create + * @param[in] attrib_list the list of (optional) attributes, or \c NULL + * @param[in] num_attribs the number of attributes supplied in + * \c attrib_list, or zero + */ +VAStatus +vaCreateSurfaces( + VADisplay dpy, + unsigned int format, + unsigned int width, + unsigned int height, + VASurfaceID *surfaces, + unsigned int num_surfaces, + VASurfaceAttrib *attrib_list, + unsigned int num_attribs +); + +/** + * vaDestroySurfaces - Destroy resources associated with surfaces. + * Surfaces can only be destroyed after all contexts using these surfaces have been + * destroyed. + * dpy: display + * surfaces: array of surfaces to destroy + * num_surfaces: number of surfaces in the array to be destroyed. + */ +VAStatus vaDestroySurfaces( + VADisplay dpy, + VASurfaceID *surfaces, + int num_surfaces +); + +#define VA_PROGRESSIVE 0x1 +/** + * vaCreateContext - Create a context + * dpy: display + * config_id: configuration for the context + * picture_width: coded picture width + * picture_height: coded picture height + * flag: any combination of the following: + * VA_PROGRESSIVE (only progressive frame pictures in the sequence when set) + * render_targets: a hint for render targets (surfaces) tied to the context + * num_render_targets: number of render targets in the above array + * context: created context id upon return + */ +VAStatus vaCreateContext( + VADisplay dpy, + VAConfigID config_id, + int picture_width, + int picture_height, + int flag, + VASurfaceID *render_targets, + int num_render_targets, + VAContextID *context /* out */ +); + +/** + * vaDestroyContext - Destroy a context + * dpy: display + * context: context to be destroyed + */ +VAStatus vaDestroyContext( + VADisplay dpy, + VAContextID context +); + +//Multi-frame context +typedef VAGenericID VAMFContextID; +/** + * vaCreateMFContext - Create a multi-frame context + * interface encapsulating common for all streams memory objects and structures + * required for single GPU task submission from several VAContextID's. + * Allocation: This call only creates an instance, doesn't allocate any additional memory. + * Support identification: Application can identify multi-frame feature support by ability + * to create multi-frame context. If driver supports multi-frame - call successful, + * mf_context != NULL and VAStatus = VA_STATUS_SUCCESS, otherwise if multi-frame processing + * not supported driver returns VA_STATUS_ERROR_UNIMPLEMENTED and mf_context = NULL. + * return values: + * VA_STATUS_SUCCESS - operation successful. + * VA_STATUS_ERROR_UNIMPLEMENTED - no support for multi-frame. + * dpy: display adapter. + * mf_context: Multi-Frame context encapsulating all associated context + * for multi-frame submission. + */ +VAStatus vaCreateMFContext( + VADisplay dpy, + VAMFContextID *mf_context /* out */ +); + +/** + * vaMFAddContext - Provide ability to associate each context used for + * Multi-Frame submission and common Multi-Frame context. + * Try to add context to understand if it is supported. + * Allocation: this call allocates and/or reallocates all memory objects + * common for all contexts associated with particular Multi-Frame context. + * All memory required for each context(pixel buffers, internal driver + * buffers required for processing) allocated during standard vaCreateContext call for each context. + * Runtime dependency - if current implementation doesn't allow to run different entry points/profile, + * first context added will set entry point/profile for whole Multi-Frame context, + * all other entry points and profiles can be rejected to be added. + * Return values: + * VA_STATUS_SUCCESS - operation successful, context was added. + * VA_STATUS_ERROR_OPERATION_FAILED - something unexpected happened - application have to close + * current mf_context and associated contexts and start working with new ones. + * VA_STATUS_ERROR_INVALID_CONTEXT - ContextID is invalid, means: + * 1 - mf_context is not valid context or + * 2 - driver can't suport different VAEntrypoint or VAProfile simultaneosly + * and current context contradicts with previously added, application can continue with current mf_context + * and other contexts passed this call, rejected context can continue work in stand-alone + * mode or other mf_context. + * VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT - particular context being added was created with with + * unsupported VAEntrypoint. Application can continue with current mf_context + * and other contexts passed this call, rejected context can continue work in stand-alone + * mode. + * VA_STATUS_ERROR_UNSUPPORTED_PROFILE - Current context with Particular VAEntrypoint is supported + * but VAProfile is not supported. Application can continue with current mf_context + * and other contexts passed this call, rejected context can continue work in stand-alone + * mode. + * dpy: display adapter. + * context: context being associated with Multi-Frame context. + * mf_context: - multi-frame context used to associate contexts for multi-frame submission. + */ +VAStatus vaMFAddContext( + VADisplay dpy, + VAMFContextID mf_context, + VAContextID context +); + +/** + * vaMFReleaseContext - Removes context from multi-frame and + * association with multi-frame context. + * After association removed vaEndPicture will submit tasks, but not vaMFSubmit. + * Return values: + * VA_STATUS_SUCCESS - operation successful, context was removed. + * VA_STATUS_ERROR_OPERATION_FAILED - something unexpected happened. + * application need to destroy this VAMFContextID and all assotiated VAContextID + * dpy: display + * mf_context: VAMFContextID where context is added + * context: VAContextID to be added + */ +VAStatus vaMFReleaseContext( + VADisplay dpy, + VAMFContextID mf_context, + VAContextID context +); + +/** + * Buffers + * Buffers are used to pass various types of data from the + * client to the server. The server maintains a data store + * for each buffer created, and the client idenfies a buffer + * through a unique buffer id assigned by the server. + */ + +typedef VAGenericID VABufferID; + +typedef enum { + VAPictureParameterBufferType = 0, + VAIQMatrixBufferType = 1, + VABitPlaneBufferType = 2, + VASliceGroupMapBufferType = 3, + VASliceParameterBufferType = 4, + VASliceDataBufferType = 5, + VAMacroblockParameterBufferType = 6, + VAResidualDataBufferType = 7, + VADeblockingParameterBufferType = 8, + VAImageBufferType = 9, + VAProtectedSliceDataBufferType = 10, + VAQMatrixBufferType = 11, + VAHuffmanTableBufferType = 12, + VAProbabilityBufferType = 13, + + /* Following are encode buffer types */ + VAEncCodedBufferType = 21, + VAEncSequenceParameterBufferType = 22, + VAEncPictureParameterBufferType = 23, + VAEncSliceParameterBufferType = 24, + VAEncPackedHeaderParameterBufferType = 25, + VAEncPackedHeaderDataBufferType = 26, + VAEncMiscParameterBufferType = 27, + VAEncMacroblockParameterBufferType = 28, + VAEncMacroblockMapBufferType = 29, + + /** + * \brief Encoding QP buffer + * + * This buffer contains QP per MB for encoding. Currently + * VAEncQPBufferH264 is defined for H.264 encoding, see + * #VAEncQPBufferH264 for details + */ + VAEncQPBufferType = 30, + /* Following are video processing buffer types */ + /** + * \brief Video processing pipeline parameter buffer. + * + * This buffer describes the video processing pipeline. See + * #VAProcPipelineParameterBuffer for details. + */ + VAProcPipelineParameterBufferType = 41, + /** + * \brief Video filter parameter buffer. + * + * This buffer describes the video filter parameters. All buffers + * inherit from #VAProcFilterParameterBufferBase, thus including + * a unique filter buffer type. + * + * The default buffer used by most filters is #VAProcFilterParameterBuffer. + * Filters requiring advanced parameters include, but are not limited to, + * deinterlacing (#VAProcFilterParameterBufferDeinterlacing), + * color balance (#VAProcFilterParameterBufferColorBalance), etc. + */ + VAProcFilterParameterBufferType = 42, + /** + * \brief FEI specific buffer types + */ + VAEncFEIMVBufferType = 43, + VAEncFEIMBCodeBufferType = 44, + VAEncFEIDistortionBufferType = 45, + VAEncFEIMBControlBufferType = 46, + VAEncFEIMVPredictorBufferType = 47, + VAStatsStatisticsParameterBufferType = 48, + /** \brief Statistics output for VAEntrypointStats progressive and top field of interlaced case*/ + VAStatsStatisticsBufferType = 49, + /** \brief Statistics output for VAEntrypointStats bottom field of interlaced case*/ + VAStatsStatisticsBottomFieldBufferType = 50, + VAStatsMVBufferType = 51, + VAStatsMVPredictorBufferType = 52, + /** Force MB's to be non skip for encode.it's per-mb control buffer, The width of the MB map + * Surface is (width of the Picture in MB unit) * 1 byte, multiple of 64 bytes. + * The height is (height of the picture in MB unit). The picture is either + * frame or non-interleaved top or bottom field. If the application provides this + *surface, it will override the "skipCheckDisable" setting in VAEncMiscParameterEncQuality. + */ + VAEncMacroblockDisableSkipMapBufferType = 53, + /** + * \brief HEVC FEI CTB level cmd buffer + * it is CTB level information for future usage. + */ + VAEncFEICTBCmdBufferType = 54, + /** + * \brief HEVC FEI CU level data buffer + * it's CTB level information for future usage + */ + VAEncFEICURecordBufferType = 55, + /** decode stream out buffer, intermedia data of decode, it may include MV, MB mode etc. + * it can be used to detect motion and analyze the frame contain */ + VADecodeStreamoutBufferType = 56, + + /** \brief HEVC Decoding Subset Parameter buffer type + * + * The subsets parameter buffer is concatenation with one or multiple + * subset entry point offsets. All the offset values are layed out one + * by one according to slice order with first slice segment first, second + * slice segment second, etc... The entry number is indicated by parameter + * \ref num_entry_point_offsets. And the first entry position of the entry + * point offsets for any slice segment is indicated by parameter + * entry_offset_to_subset_array in VAPictureParameterBufferHEVC data structure. + */ + VASubsetsParameterBufferType = 57, + /** \brief adjust context parameters dynamically + * + * this parameter is used to update context parameters, detail parameter is in + * \c VAContextParameterUpdateBuffer + */ + VAContextParameterUpdateBufferType = 58, + /** + * \brief Protected session execution buffer type + * + * It's for TEE execution usage (vaProtectedSessionExecute()). The buffer structure is in + * \c VAProtectedSessionExecuteBuffer + */ + VAProtectedSessionExecuteBufferType = 59, + + /** \brief Encryption parameters buffer for protected content session. + * + * Refer to \c VAEncryptionParameters + */ + VAEncryptionParameterBufferType = 60, + + /** + * \brief Encoding delta QP per block buffer + * + * This buffer only could be created and accepted + * when \c VAConfigAttribValEncPerBlockControl delta_qp_support == 1. + * This input buffer contains delta QP per block for encoding. + * The supported size of delta QP block and the size of delta QP + * must be quried from \c VAConfigAttribValEncPerBlockControl. + */ + VAEncDeltaQpPerBlockBufferType = 61, + + VABufferTypeMax +} VABufferType; + +/** \brief update the context parameter + * this structure is used to update context parameters, such as priority of the context + * backend driver should keep the parameter unchanged if there no new + * parameter updated. + */ +typedef struct _VAContextParameterUpdateBuffer { + union { + struct { + /** \brief indicate whether context priority changed */ + uint32_t context_priority_update : 1; + /** \brief Reserved bits for future use, must be zero */ + uint32_t reserved : 31; + } bits; + uint32_t value; + } flags; + /** \brief task/context priority */ + VAConfigAttribValContextPriority context_priority; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved[VA_PADDING_MEDIUM]; +} VAContextParameterUpdateBuffer; + +/** + * These ENCRYPTION_TYPEs are used for the attribute values for + * \c VAConfigAttribEncryption and for encryption_type in + * VAEncryptionParameters. + * + * When used for \c VAConfigAttribEncryption, it be used via + * vaQueryConfigEntrypoints to check which type are supported for specific + * profile or not. + * + * When used for encryption_type in VAEncryptionParameters, it tells driver + * the parameters in VAEncryptionParameters are used for which encryption type. + */ +#define VA_ENCRYPTION_TYPE_FULLSAMPLE_CTR 0x00000001 /* AES CTR fullsample */ +#define VA_ENCRYPTION_TYPE_FULLSAMPLE_CBC 0x00000002 /* AES CBC fullsample */ +#define VA_ENCRYPTION_TYPE_SUBSAMPLE_CTR 0x00000004 /* AES CTR fullsample */ +#define VA_ENCRYPTION_TYPE_SUBSAMPLE_CBC 0x00000008 /* AES CBC fullsample */ + +/** \brief structure for encrypted segment info. */ +typedef struct _VAEncryptionSegmentInfo { + /** \brief The offset relative to the start of the bitstream input in + * bytes of the start of the segment */ + uint32_t segment_start_offset; + /** \brief The length of the segments in bytes */ + uint32_t segment_length; + /** \brief The length in bytes of the remainder of an incomplete block + * from a previous segment*/ + uint32_t partial_aes_block_size; + /** \brief The length in bytes of the initial clear data */ + uint32_t init_byte_length; + /** \brief This will be AES counter for secure decode and secure encode + * when numSegments equals 1, valid size is specified by + * \c key_blob_size */ + uint8_t aes_cbc_iv_or_ctr[64]; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM]; +} VAEncryptionSegmentInfo; + +/** \brief Encryption parameters buffer for VAEncryptionParameterBufferType */ +typedef struct _VAEncryptionParameters { + /** \brief Encryption type, refer to \c VA_ENCRYPTION_TYPE_FULLSAMPLE_CTR, + * \c VA_ENCRYPTION_TYPE_FULLSAMPLE_CBC, \c VA_ENCRYPTION_TYPE_SUBSAMPLE_CTR, + * or \c VA_ENCRYPTION_TYPE_SUBSAMPLE_CBC */ + uint32_t encryption_type; + /** \brief The number of sengments */ + uint32_t num_segments; + /** \brief Pointer of segments */ + VAEncryptionSegmentInfo *segment_info; + /** \brief The status report index reserved for CENC fullsample workload. + * The related structures and definitions are vendor specific. + */ + uint32_t status_report_index; + /** \brief CENC counter length */ + uint32_t size_of_length; + /** \brief Wrapped decrypt blob (Snd)kb, valid size is specified by + * \c key_blob_size */ + uint8_t wrapped_decrypt_blob[64]; + /** \brief Wrapped Key blob info (Sne)kb, valid size is specified by + * \c key_blob_size */ + uint8_t wrapped_encrypt_blob[64]; + /** \brief key blob size + * It could be \c VA_PC_BLOCK_SIZE_128, \c VA_PC_BLOCK_SIZE_192, or + * \c VA_PC_BLOCK_SIZE_256 + */ + uint32_t key_blob_size; + /** \brief Indicates the number of 16-byte BLOCKS that are encrypted in any + * given encrypted region of segments. + * If this value is zero: + * 1. All bytes in encrypted region of segments are encrypted, i.e. the + * CENC or CBC1 scheme is being used + * 2. blocks_stripe_clear must also be zero. + * If this value is non-zero, blocks_stripe_clear must also be non-zero. + */ + uint32_t blocks_stripe_encrypted; + /** \brief Indicates the number of 16-byte BLOCKS that are clear in any given + * encrypted region of segments, as defined by the CENS and CBCS schemes in + * the common encryption spec. + * If this value is zero, all bytes in encrypted region of segments are + * encrypted, i.e. the CENC or CBC1 scheme is being used. + */ + uint32_t blocks_stripe_clear; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM]; +} VAEncryptionParameters; + +/** + * Processing rate parameter for encode. + */ +typedef struct _VAProcessingRateParameterEnc { + /** \brief Profile level */ + uint8_t level_idc; + uint8_t reserved[3]; + /** \brief quality level. When set to 0, default quality + * level is used. + */ + uint32_t quality_level; + /** \brief Period between I frames. */ + uint32_t intra_period; + /** \brief Period between I/P frames. */ + uint32_t ip_period; +} VAProcessingRateParameterEnc; + +/** + * Processing rate parameter for decode. + */ +typedef struct _VAProcessingRateParameterDec { + /** \brief Profile level */ + uint8_t level_idc; + uint8_t reserved0[3]; + uint32_t reserved; +} VAProcessingRateParameterDec; + +typedef struct _VAProcessingRateParameter { + union { + VAProcessingRateParameterEnc proc_buf_enc; + VAProcessingRateParameterDec proc_buf_dec; + }; +} VAProcessingRateParameter; + +/** + * \brief Queries processing rate for the supplied config. + * + * This function queries the processing rate based on parameters in + * \c proc_buf for the given \c config. Upon successful return, the processing + * rate value will be stored in \c processing_rate. Processing rate is + * specified as the number of macroblocks/CTU per second. + * + * If NULL is passed to the \c proc_buf, the default processing rate for the + * given configuration will be returned. + * + * @param[in] dpy the VA display + * @param[in] config the config identifying a codec or a video + * processing pipeline + * @param[in] proc_buf the buffer that contains the parameters for + either the encode or decode processing rate + * @param[out] processing_rate processing rate in number of macroblocks per + second constrained by parameters specified in proc_buf + * + */ +VAStatus +vaQueryProcessingRate( + VADisplay dpy, + VAConfigID config, + VAProcessingRateParameter *proc_buf, + unsigned int *processing_rate +); + +typedef enum { + VAEncMiscParameterTypeFrameRate = 0, + VAEncMiscParameterTypeRateControl = 1, + VAEncMiscParameterTypeMaxSliceSize = 2, + VAEncMiscParameterTypeAIR = 3, + /** \brief Buffer type used to express a maximum frame size (in bits). */ + VAEncMiscParameterTypeMaxFrameSize = 4, + /** \brief Buffer type used for HRD parameters. */ + VAEncMiscParameterTypeHRD = 5, + VAEncMiscParameterTypeQualityLevel = 6, + /** \brief Buffer type used for Rolling intra refresh */ + VAEncMiscParameterTypeRIR = 7, + /** \brief Buffer type used for quantization parameters, it's per-sequence parameter*/ + VAEncMiscParameterTypeQuantization = 8, + /** \brief Buffer type used for sending skip frame parameters to the encoder's + * rate control, when the user has externally skipped frames. */ + VAEncMiscParameterTypeSkipFrame = 9, + /** \brief Buffer type used for region-of-interest (ROI) parameters. */ + VAEncMiscParameterTypeROI = 10, + /** \brief Buffer type used to express a maximum frame size (in bytes) settings for multiple pass. */ + VAEncMiscParameterTypeMultiPassFrameSize = 11, + /** \brief Buffer type used for temporal layer structure */ + VAEncMiscParameterTypeTemporalLayerStructure = 12, + /** \brief Buffer type used for dirty region-of-interest (ROI) parameters. */ + VAEncMiscParameterTypeDirtyRect = 13, + /** \brief Buffer type used for parallel BRC parameters. */ + VAEncMiscParameterTypeParallelBRC = 14, + /** \brief Set MB partion mode mask and Half-pel/Quant-pel motion search */ + VAEncMiscParameterTypeSubMbPartPel = 15, + /** \brief set encode quality tuning */ + VAEncMiscParameterTypeEncQuality = 16, + /** \brief Buffer type used for encoder rounding offset parameters. */ + VAEncMiscParameterTypeCustomRoundingControl = 17, + /** \brief Buffer type used for FEI input frame level parameters */ + VAEncMiscParameterTypeFEIFrameControl = 18, + /** \brief encode extension buffer, ect. MPEG2 Sequence extenstion data */ + VAEncMiscParameterTypeExtensionData = 19 +} VAEncMiscParameterType; + +/** \brief Packed header type. */ +typedef enum { + /** \brief Packed sequence header. */ + VAEncPackedHeaderSequence = 1, + /** \brief Packed picture header. */ + VAEncPackedHeaderPicture = 2, + /** \brief Packed slice header. */ + VAEncPackedHeaderSlice = 3, + /** + * \brief Packed raw header. + * + * Packed raw data header can be used by the client to insert a header + * into the bitstream data buffer at the point it is passed, the driver + * will handle the raw packed header based on "has_emulation_bytes" field + * in the packed header parameter structure. + */ + VAEncPackedHeaderRawData = 4, + /** + * \brief Misc packed header. See codec-specific definitions. + * + * @deprecated + * This is a deprecated packed header type. All applications can use + * \c VAEncPackedHeaderRawData to insert a codec-specific packed header + */ + VAEncPackedHeaderMiscMask va_deprecated_enum = 0x80000000, +} VAEncPackedHeaderType; + +/** \brief Packed header parameter. */ +typedef struct _VAEncPackedHeaderParameterBuffer { + /** Type of the packed header buffer. See #VAEncPackedHeaderType. */ + uint32_t type; + /** \brief Size of the #VAEncPackedHeaderDataBuffer in bits. */ + uint32_t bit_length; + /** \brief Flag: buffer contains start code emulation prevention bytes? */ + uint8_t has_emulation_bytes; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncPackedHeaderParameterBuffer; + +/** + * For application, e.g. set a new bitrate + * VABufferID buf_id; + * VAEncMiscParameterBuffer *misc_param; + * VAEncMiscParameterRateControl *misc_rate_ctrl; + * + * vaCreateBuffer(dpy, context, VAEncMiscParameterBufferType, + * sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterRateControl), + * 1, NULL, &buf_id); + * + * vaMapBuffer(dpy,buf_id,(void **)&misc_param); + * misc_param->type = VAEncMiscParameterTypeRateControl; + * misc_rate_ctrl= (VAEncMiscParameterRateControl *)misc_param->data; + * misc_rate_ctrl->bits_per_second = 6400000; + * vaUnmapBuffer(dpy, buf_id); + * vaRenderPicture(dpy, context, &buf_id, 1); + */ +typedef struct _VAEncMiscParameterBuffer { + VAEncMiscParameterType type; + uint32_t data[]; +} VAEncMiscParameterBuffer; + +/** \brief Temporal layer Structure*/ +typedef struct _VAEncMiscParameterTemporalLayerStructure { + /** \brief The number of temporal layers */ + uint32_t number_of_layers; + /** \brief The length of the array defining frame layer membership. Should be 1-32 */ + uint32_t periodicity; + /** + * \brief The array indicating the layer id for each frame + * + * The layer id for the first frame in a coded sequence is always 0, so layer_id[] specifies the layer + * ids for frames starting from the 2nd frame. + */ + uint32_t layer_id[32]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterTemporalLayerStructure; + + +/** \brief Rate control parameters */ +typedef struct _VAEncMiscParameterRateControl { + /** The maximum bit-rate which the the rate controller should generate. */ + uint32_t bits_per_second; + /** The target bit-rate which the rate controller should generate, as a percentage of the + * maximum bit-rate. + * + * In CBR mode this value is ignored (treated as 100%). + */ + uint32_t target_percentage; + /** Rate control window size in milliseconds. + * + * The rate controller will attempt to guarantee that the target and maximum bit-rates are + * correct over this window. + */ + uint32_t window_size; + /** Initial quantiser value used at the start of the stream. + * + * Ignored if set to zero. + */ + uint32_t initial_qp; + /** Minimum quantiser value to use. + * + * The quantiser will not go below the value - if this limit is hit, the output bitrate may + * be lower than the target. Ignored if set to zero. + */ + uint32_t min_qp; + /** Basic unit size. + * + * Only used by some drivers - see driver documentation for details. Set to zero if unused. + */ + uint32_t basic_unit_size; + union { + struct { + /** Force rate controller reset. + * + * The next frame will be treated as the start of a new stream, with all rate + * controller state reset to its initial values. + */ + uint32_t reset : 1; + /** Disable frame skip in rate control mode. */ + uint32_t disable_frame_skip : 1; + /** Disable bit stuffing in rate control mode. */ + uint32_t disable_bit_stuffing : 1; + /** Macroblock-level rate control. + * + * 0: use default, 1: always enable, 2: always disable, other: reserved. + * + * This feature is only available if VAConfigAttribRateControl has the + * \ref VA_RC_MB bit set. + */ + uint32_t mb_rate_control : 4; + /** The temporal layer that these rate control parameters apply to. */ + uint32_t temporal_id : 8; + /** Ensure that intra frames also conform to the constant frame size. */ + uint32_t cfs_I_frames : 1; + /** Enable parallel rate control for hierarchical B frames. + * + * See \ref VA_RC_PARALLEL. + */ + uint32_t enable_parallel_brc : 1; + uint32_t enable_dynamic_scaling : 1; + /** Frame tolerance mode. + * + * Indicates the tolerance the application has to variations in the frame size. + * For example, wireless display scenarios may require very steady bit rate to + * reduce buffering time. It affects the rate control algorithm used, + * but may or may not have an effect based on the combination of other BRC + * parameters. Only valid when the driver reports support for + * #VAConfigAttribFrameSizeToleranceSupport. + * + * equals 0 -- normal mode; + * equals 1 -- maps to sliding window; + * equals 2 -- maps to low delay mode; + * other -- invalid. + */ + uint32_t frame_tolerance_mode : 2; + /** Reserved for future use, must be zero. */ + uint32_t reserved : 12; + } bits; + uint32_t value; + } rc_flags; + /** Initial quality factor used in ICQ mode. + * + * This value must be between 1 and 51. + * this value will be deprecated in future, to use quality_factor instead of it. + */ + uint32_t ICQ_quality_factor; + /** Maximum quantiser value to use. + * + * The quantiser will not go above this value - if this limit is hit, the output bitrate + * may exceed the target. Ignored if set to zero. + */ + uint32_t max_qp; + /** Quality factor + * + * the range will be different for different codec + */ + uint32_t quality_factor; + /** Target frame size + * + * Desired frame size in bytes. + * This parameter can be used in some RC modes (like Transport Controlled BRC) + * where feedback from the app is required. + * Zero value means no limits. + * + */ + uint32_t target_frame_size; + /** Reserved bytes for future use, must be zero. */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterRateControl; + +/** Encode framerate parameters. + * + * Sets the encode framerate used by the rate controller. This should be + * provided in all modes using a bitrate target (variable framerate is not + * supported). + */ +typedef struct _VAEncMiscParameterFrameRate { + /** Encode framerate. + * + * The framerate is specified as a number of frames per second, as a + * fraction. The denominator of the fraction is given in the top half + * (the high two bytes) of the framerate field, and the numerator is + * given in the bottom half (the low two bytes). + * + * That is: + * denominator = framerate >> 16 & 0xffff; + * numerator = framerate & 0xffff; + * fps = numerator / denominator; + * + * For example, if framerate is set to (100 << 16 | 750), this is + * 750 / 100, hence 7.5fps. + * + * If the denominator is zero (the high two bytes are both zero) then + * it takes the value one instead, so the framerate is just the integer + * in the low 2 bytes. + */ + uint32_t framerate; + union { + struct { + /** The temporal layer that these framerate parameters apply to. */ + uint32_t temporal_id : 8; + /** Reserved for future use, must be zero. */ + uint32_t reserved : 24; + } bits; + uint32_t value; + } framerate_flags; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterFrameRate; + +/** + * Allow a maximum slice size to be specified (in bits). + * The encoder will attempt to make sure that individual slices do not exceed this size + * Or to signal applicate if the slice size exceed this size, see "status" of VACodedBufferSegment + */ +typedef struct _VAEncMiscParameterMaxSliceSize { + uint32_t max_slice_size; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterMaxSliceSize; + +typedef struct _VAEncMiscParameterAIR { + uint32_t air_num_mbs; + uint32_t air_threshold; + uint32_t air_auto; /* if set to 1 then hardware auto-tune the AIR threshold */ + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterAIR; + +/* + * \brief Rolling intra refresh data structure for encoding. + */ +typedef struct _VAEncMiscParameterRIR { + union { + struct + /** + * \brief Indicate if intra refresh is enabled in column/row. + * + * App should query VAConfigAttribEncIntraRefresh to confirm RIR support + * by the driver before sending this structure. + */ + { + /* \brief enable RIR in column */ + uint32_t enable_rir_column : 1; + /* \brief enable RIR in row */ + uint32_t enable_rir_row : 1; + uint32_t reserved : 30; + } bits; + uint32_t value; + } rir_flags; + /** + * \brief Indicates the column or row location in MB. It is ignored if + * rir_flags is 0. + */ + uint16_t intra_insertion_location; + /** + * \brief Indicates the number of columns or rows in MB. It is ignored if + * rir_flags is 0. + */ + uint16_t intra_insert_size; + /** + * \brief indicates the Qp difference for inserted intra columns or rows. + * App can use this to adjust intra Qp based on bitrate & max frame size. + */ + uint8_t qp_delta_for_inserted_intra; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterRIR; + +/** HRD / VBV buffering parameters for encoding. + * + * This sets the HRD / VBV parameters which will be used by the rate + * controller for encoding. It should be specified in modes using a bitrate + * target when the buffering of the output stream needs to be constrained. + * + * If not provided, the encoder may use arbitrary amounts of buffering. + */ +typedef struct _VAEncMiscParameterHRD { + /** The initial fullness of the HRD coded picture buffer, in bits. + * + * This sets how full the CPB is when encoding begins - that is, how much + * buffering will happen on the decoder side before the first frame. + * The CPB fullness will be reset to this value after any rate control + * reset (a change in parameters or an explicit reset). + * + * For H.264, it should match the value of initial_cpb_removal_delay in + * buffering_period SEI messages. + */ + uint32_t initial_buffer_fullness; + /** The HRD coded picture buffer size, in bits. + * + * For H.264, it should match the value of cpb_size_value_minus1 in the VUI + * parameters. + */ + uint32_t buffer_size; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterHRD; + +/** + * \brief Defines a maximum frame size (in bits). + * + * This misc parameter buffer defines the maximum size of a frame (in + * bits). The encoder will try to make sure that each frame does not + * exceed this size. Otherwise, if the frame size exceeds this size, + * the \c status flag of #VACodedBufferSegment will contain + * #VA_CODED_BUF_STATUS_FRAME_SIZE_OVERFLOW. + */ +typedef struct _VAEncMiscParameterBufferMaxFrameSize { + /** \brief Type. Shall be set to #VAEncMiscParameterTypeMaxFrameSize. */ + /** duplicated with VAEncMiscParameterBuffer, should be deprecated*/ + va_deprecated VAEncMiscParameterType type; + /** \brief Maximum size of a frame (in bits). */ + uint32_t max_frame_size; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterBufferMaxFrameSize; + +/** + * \brief Maximum frame size (in bytes) settings for multiple pass. + * + * This misc parameter buffer defines the maximum size of a frame (in + * bytes) settings for multiple pass. currently only AVC encoder can + * support this settings in multiple pass case. If the frame size exceeds + * this size, the encoder will do more pak passes to adjust the QP value + * to control the frame size. + */ +typedef struct _VAEncMiscParameterBufferMultiPassFrameSize { + /** \brief Type. Shall be set to #VAEncMiscParameterTypeMultiPassMaxFrameSize. */ + /** duplicated with VAEncMiscParameterBuffer, should be deprecated*/ + va_deprecated VAEncMiscParameterType type; + /** \brief Maximum size of a frame (in byte) */ + uint32_t max_frame_size; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved; + /** \brief number of passes, every pass has different QP, currently AVC encoder can support up to 4 passes */ + uint8_t num_passes; + /** \brief delta QP list for every pass */ + uint8_t *delta_qp; + + /** \brief Reserved bytes for future use, must be zero */ + unsigned long va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterBufferMultiPassFrameSize; + +/** + * \brief Encoding quality level. + * + * The encoding quality could be set through this structure, if the implementation + * supports multiple quality levels. The quality level set through this structure is + * persistent over the entire coded sequence, or until a new structure is being sent. + * The quality level range can be queried through the VAConfigAttribEncQualityRange + * attribute. A lower value means higher quality, and a value of 1 represents the highest + * quality. The quality level setting is used as a trade-off between quality and speed/power + * consumption, with higher quality corresponds to lower speed and higher power consumption. + */ +typedef struct _VAEncMiscParameterBufferQualityLevel { + /** \brief Encoding quality level setting. When set to 0, default quality + * level is used. + */ + uint32_t quality_level; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterBufferQualityLevel; + +/** + * \brief Quantization settings for encoding. + * + * Some encoders support special types of quantization such as trellis, and this structure + * can be used by the app to control these special types of quantization by the encoder. + */ +typedef struct _VAEncMiscParameterQuantization { + union { + /* if no flags is set then quantization is determined by the driver */ + struct { + /* \brief disable trellis for all frames/fields */ + uint32_t disable_trellis : 1; + /* \brief enable trellis for I frames/fields */ + uint32_t enable_trellis_I : 1; + /* \brief enable trellis for P frames/fields */ + uint32_t enable_trellis_P : 1; + /* \brief enable trellis for B frames/fields */ + uint32_t enable_trellis_B : 1; + uint32_t reserved : 28; + } bits; + uint32_t value; + } quantization_flags; + uint32_t va_reserved; +} VAEncMiscParameterQuantization; + +/** + * \brief Encoding skip frame. + * + * The application may choose to skip frames externally to the encoder (e.g. drop completely or + * code as all skip's). For rate control purposes the encoder will need to know the size and number + * of skipped frames. Skip frame(s) indicated through this structure is applicable only to the + * current frame. It is allowed for the application to still send in packed headers for the driver to + * pack, although no frame will be encoded (e.g. for HW to encrypt the frame). + */ +typedef struct _VAEncMiscParameterSkipFrame { + /** \brief Indicates skip frames as below. + * 0: Encode as normal, no skip. + * 1: One or more frames were skipped prior to the current frame, encode the current frame as normal. + * 2: The current frame is to be skipped, do not encode it but pack/encrypt the packed header contents + * (all except VAEncPackedHeaderSlice) which could contain actual frame contents (e.g. pack the frame + * in VAEncPackedHeaderPicture). */ + uint8_t skip_frame_flag; + /** \brief The number of frames skipped prior to the current frame. Valid when skip_frame_flag = 1. */ + uint8_t num_skip_frames; + /** \brief When skip_frame_flag = 1, the size of the skipped frames in bits. When skip_frame_flag = 2, + * the size of the current skipped frame that is to be packed/encrypted in bits. */ + uint32_t size_skip_frames; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterSkipFrame; + +/** + * \brief Encoding region-of-interest (ROI). + * + * The encoding ROI can be set through VAEncMiscParameterBufferROI, if the implementation + * supports ROI input. The ROI set through this structure is applicable only to the + * current frame or field, so must be sent every frame or field to be applied. The number of + * supported ROIs can be queried through the VAConfigAttribEncROI. The encoder will use the + * ROI information to adjust the QP values of the MB's that fall within the ROIs. + */ +typedef struct _VAEncROI { + /** \brief Defines the ROI boundary in pixels, the driver will map it to appropriate + * codec coding units. It is relative to frame coordinates for the frame case and + * to field coordinates for the field case. */ + VARectangle roi_rectangle; + /** + * \brief ROI value + * + * \ref roi_value specifies ROI delta QP or ROI priority. + * -- ROI delta QP is the value that will be added on top of the frame level QP. + * -- ROI priority specifies the priority of a region, it can be positive (more important) + * or negative (less important) values and is compared with non-ROI region (taken as value 0), + * E.g. ROI region with \ref roi_value -3 is less important than the non-ROI region (\ref roi_value + * implied to be 0) which is less important than ROI region with roi_value +2. For overlapping + * regions, the roi_value that is first in the ROI array will have priority. + * + * \ref roi_value always specifes ROI delta QP when VAConfigAttribRateControl == VA_RC_CQP, no matter + * the value of \c roi_value_is_qp_delta in #VAEncMiscParameterBufferROI. + * + * \ref roi_value depends on \c roi_value_is_qp_delta in #VAEncMiscParameterBufferROI when + * VAConfigAttribRateControl != VA_RC_CQP. \ref roi_value specifies ROI_delta QP if \c roi_value_is_qp_delta + * in VAEncMiscParameterBufferROI is 1, otherwise \ref roi_value specifies ROI priority. + */ + int8_t roi_value; +} VAEncROI; + +typedef struct _VAEncMiscParameterBufferROI { + /** \brief Number of ROIs being sent.*/ + uint32_t num_roi; + + /** \brief Valid when VAConfigAttribRateControl != VA_RC_CQP, then the encoder's + * rate control will determine actual delta QPs. Specifies the max/min allowed delta + * QPs. */ + int8_t max_delta_qp; + int8_t min_delta_qp; + + /** \brief Pointer to a VAEncROI array with num_roi elements. It is relative to frame + * coordinates for the frame case and to field coordinates for the field case.*/ + VAEncROI *roi; + union { + struct { + /** + * \brief An indication for roi value. + * + * \ref roi_value_is_qp_delta equal to 1 indicates \c roi_value in #VAEncROI should + * be used as ROI delta QP. \ref roi_value_is_qp_delta equal to 0 indicates \c roi_value + * in #VAEncROI should be used as ROI priority. + * + * \ref roi_value_is_qp_delta is only available when VAConfigAttribRateControl != VA_RC_CQP, + * the setting must comply with \c roi_rc_priority_support and \c roi_rc_qp_delta_support in + * #VAConfigAttribValEncROI. The underlying driver should ignore this field + * when VAConfigAttribRateControl == VA_RC_CQP. + */ + uint32_t roi_value_is_qp_delta : 1; + uint32_t reserved : 31; + } bits; + uint32_t value; + } roi_flags; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterBufferROI; +/* + * \brief Dirty rectangle data structure for encoding. + * + * The encoding dirty rect can be set through VAEncMiscParameterBufferDirtyRect, if the + * implementation supports dirty rect input. The rect set through this structure is applicable + * only to the current frame or field, so must be sent every frame or field to be applied. + * The number of supported rects can be queried through the VAConfigAttribEncDirtyRect. The + * encoder will use the rect information to know those rectangle areas have changed while the + * areas not covered by dirty rect rectangles are assumed to have not changed compared to the + * previous picture. The encoder may do some internal optimizations. + */ +typedef struct _VAEncMiscParameterBufferDirtyRect { + /** \brief Number of Rectangle being sent.*/ + uint32_t num_roi_rectangle; + + /** \brief Pointer to a VARectangle array with num_roi_rectangle elements.*/ + VARectangle *roi_rectangle; +} VAEncMiscParameterBufferDirtyRect; + +/** \brief Attribute value for VAConfigAttribEncParallelRateControl */ +typedef struct _VAEncMiscParameterParallelRateControl { + /** brief Number of layers*/ + uint32_t num_layers; + /** brief Number of B frames per layer per GOP. + * + * it should be allocated by application, and the is num_layers. + * num_b_in_gop[0] is the number of regular B which refers to only I or P frames. */ + uint32_t *num_b_in_gop; +} VAEncMiscParameterParallelRateControl; + +/** per frame encoder quality controls, once set they will persist for all future frames + *till it is updated again. */ +typedef struct _VAEncMiscParameterEncQuality { + union { + struct { + /** Use raw frames for reference instead of reconstructed frames. + * it only impact motion estimation (ME) stage, and will not impact MC stage + * so the reconstruct picture will can match with decode side */ + uint32_t useRawPicForRef : 1; + /** Disables skip check for ME stage, it will increase the bistream size + * but will improve the qulity */ + uint32_t skipCheckDisable : 1; + /** Indicates app will override default driver FTQ settings using FTQEnable. + * FTQ is forward transform quantization */ + uint32_t FTQOverride : 1; + /** Enables/disables FTQ. */ + uint32_t FTQEnable : 1; + /** Indicates the app will provide the Skip Threshold LUT to use when FTQ is + * enabled (FTQSkipThresholdLUT), else default driver thresholds will be used. */ + uint32_t FTQSkipThresholdLUTInput : 1; + /** Indicates the app will provide the Skip Threshold LUT to use when FTQ is + * disabled (NonFTQSkipThresholdLUT), else default driver thresholds will be used. */ + uint32_t NonFTQSkipThresholdLUTInput : 1; + uint32_t ReservedBit : 1; + /** Control to enable the ME mode decision algorithm to bias to fewer B Direct/Skip types. + * Applies only to B frames, all other frames will ignore this setting. */ + uint32_t directBiasAdjustmentEnable : 1; + /** Enables global motion bias. global motion also is called HME (Heirarchical Motion Estimation ) + * HME is used to handle large motions and avoiding local minima in the video encoding process + * down scaled the input and reference picture, then do ME. the result will be a predictor to next level HME or ME + * current interface divide the HME to 3 level. UltraHME , SuperHME, and HME, result of UltraHME will be input of SurperHME, + * result of superHME will be a input for HME. HME result will be input of ME. it is a switch for HMEMVCostScalingFactor + * can change the HME bias inside RDO stage*/ + uint32_t globalMotionBiasAdjustmentEnable : 1; + /** MV cost scaling ratio for HME ( predictors. It is used when + * globalMotionBiasAdjustmentEnable == 1, else it is ignored. Values are: + * 0: set MV cost to be 0 for HME predictor. + * 1: scale MV cost to be 1/2 of the default value for HME predictor. + * 2: scale MV cost to be 1/4 of the default value for HME predictor. + * 3: scale MV cost to be 1/8 of the default value for HME predictor. */ + uint32_t HMEMVCostScalingFactor : 2; + /**disable HME, if it is disabled. Super*ultraHME should also be disabled */ + uint32_t HMEDisable : 1; + /**disable Super HME, if it is disabled, ultraHME should be disabled */ + uint32_t SuperHMEDisable : 1; + /** disable Ultra HME */ + uint32_t UltraHMEDisable : 1; + /** disable panic mode. Panic mode happened when there are extreme BRC (bit rate control) requirement + * frame size cant achieve the target of BRC. when Panic mode is triggered, Coefficients will + * be set to zero. disable panic mode will improve quality but will impact BRC */ + uint32_t PanicModeDisable : 1; + /** Force RepartitionCheck + * 0: DEFAULT - follow driver default settings. + * 1: FORCE_ENABLE - enable this feature totally for all cases. + * 2: FORCE_DISABLE - disable this feature totally for all cases. */ + uint32_t ForceRepartitionCheck : 2; + + }; + uint32_t encControls; + }; + + /** Maps QP to skip thresholds when FTQ is enabled. Valid range is 0-255. */ + uint8_t FTQSkipThresholdLUT[52]; + /** Maps QP to skip thresholds when FTQ is disabled. Valid range is 0-65535. */ + uint16_t NonFTQSkipThresholdLUT[52]; + + uint32_t reserved[VA_PADDING_HIGH]; // Reserved for future use. + +} VAEncMiscParameterEncQuality; + +/** + * \brief Custom Encoder Rounding Offset Control. + * Application may use this structure to set customized rounding + * offset parameters for quantization. + * Valid when \c VAConfigAttribCustomRoundingControl equals 1. + */ +typedef struct _VAEncMiscParameterCustomRoundingControl { + union { + struct { + /** \brief Enable customized rounding offset for intra blocks. + * If 0, default value would be taken by driver for intra + * rounding offset. + */ + uint32_t enable_custom_rouding_intra : 1 ; + + /** \brief Intra rounding offset + * Ignored if \c enable_custom_rouding_intra equals 0. + */ + uint32_t rounding_offset_intra : 7; + + /** \brief Enable customized rounding offset for inter blocks. + * If 0, default value would be taken by driver for inter + * rounding offset. + */ + uint32_t enable_custom_rounding_inter : 1 ; + + /** \brief Inter rounding offset + * Ignored if \c enable_custom_rouding_inter equals 0. + */ + uint32_t rounding_offset_inter : 7; + + /* Reserved */ + uint32_t reserved : 16; + } bits; + uint32_t value; + } rounding_offset_setting; +} VAEncMiscParameterCustomRoundingControl; + +/** + * There will be cases where the bitstream buffer will not have enough room to hold + * the data for the entire slice, and the following flags will be used in the slice + * parameter to signal to the server for the possible cases. + * If a slice parameter buffer and slice data buffer pair is sent to the server with + * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below), + * then a slice parameter and data buffer needs to be sent again to complete this slice. + */ +#define VA_SLICE_DATA_FLAG_ALL 0x00 /* whole slice is in the buffer */ +#define VA_SLICE_DATA_FLAG_BEGIN 0x01 /* The beginning of the slice is in the buffer but the end if not */ +#define VA_SLICE_DATA_FLAG_MIDDLE 0x02 /* Neither beginning nor end of the slice is in the buffer */ +#define VA_SLICE_DATA_FLAG_END 0x04 /* end of the slice is in the buffer */ + +/* Codec-independent Slice Parameter Buffer base */ +typedef struct _VASliceParameterBufferBase { + uint32_t slice_data_size; /* number of bytes in the slice data buffer for this slice */ + uint32_t slice_data_offset; /* the offset to the first byte of slice data */ + uint32_t slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX definitions */ +} VASliceParameterBufferBase; + +/********************************** + * JPEG common data structures + **********************************/ +/** + * \brief Huffman table for JPEG decoding. + * + * This structure holds the complete Huffman tables. This is an + * aggregation of all Huffman table (DHT) segments maintained by the + * application. i.e. up to 2 Huffman tables are stored in there for + * baseline profile. + * + * The #load_huffman_table array can be used as a hint to notify the + * VA driver implementation about which table(s) actually changed + * since the last submission of this buffer. + */ +typedef struct _VAHuffmanTableBufferJPEGBaseline { + /** \brief Specifies which #huffman_table is valid. */ + uint8_t load_huffman_table[2]; + /** \brief Huffman tables indexed by table identifier (Th). */ + struct { + /** @name DC table (up to 12 categories) */ + /**@{*/ + /** \brief Number of Huffman codes of length i + 1 (Li). */ + uint8_t num_dc_codes[16]; + /** \brief Value associated with each Huffman code (Vij). */ + uint8_t dc_values[12]; + /**@}*/ + /** @name AC table (2 special codes + up to 16 * 10 codes) */ + /**@{*/ + /** \brief Number of Huffman codes of length i + 1 (Li). */ + uint8_t num_ac_codes[16]; + /** \brief Value associated with each Huffman code (Vij). */ + uint8_t ac_values[162]; + /** \brief Padding to 4-byte boundaries. Must be set to zero. */ + uint8_t pad[2]; + /**@}*/ + } huffman_table[2]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAHuffmanTableBufferJPEGBaseline; + +/**************************** + * MPEG-2 data structures + ****************************/ + +/* MPEG-2 Picture Parameter Buffer */ +/* + * For each frame or field, and before any slice data, a single + * picture parameter buffer must be send. + */ +typedef struct _VAPictureParameterBufferMPEG2 { + uint16_t horizontal_size; + uint16_t vertical_size; + VASurfaceID forward_reference_picture; + VASurfaceID backward_reference_picture; + /* meanings of the following fields are the same as in the standard */ + int32_t picture_coding_type; + int32_t f_code; /* pack all four fcode into this */ + union { + struct { + uint32_t intra_dc_precision : 2; + uint32_t picture_structure : 2; + uint32_t top_field_first : 1; + uint32_t frame_pred_frame_dct : 1; + uint32_t concealment_motion_vectors : 1; + uint32_t q_scale_type : 1; + uint32_t intra_vlc_format : 1; + uint32_t alternate_scan : 1; + uint32_t repeat_first_field : 1; + uint32_t progressive_frame : 1; + uint32_t is_first_field : 1; /* indicate whether the current field + * is the first field for field picture + */ + } bits; + uint32_t value; + } picture_coding_extension; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAPictureParameterBufferMPEG2; + +/** MPEG-2 Inverse Quantization Matrix Buffer */ +typedef struct _VAIQMatrixBufferMPEG2 { + /** \brief Same as the MPEG-2 bitstream syntax element. */ + int32_t load_intra_quantiser_matrix; + /** \brief Same as the MPEG-2 bitstream syntax element. */ + int32_t load_non_intra_quantiser_matrix; + /** \brief Same as the MPEG-2 bitstream syntax element. */ + int32_t load_chroma_intra_quantiser_matrix; + /** \brief Same as the MPEG-2 bitstream syntax element. */ + int32_t load_chroma_non_intra_quantiser_matrix; + /** \brief Luminance intra matrix, in zig-zag scan order. */ + uint8_t intra_quantiser_matrix[64]; + /** \brief Luminance non-intra matrix, in zig-zag scan order. */ + uint8_t non_intra_quantiser_matrix[64]; + /** \brief Chroma intra matrix, in zig-zag scan order. */ + uint8_t chroma_intra_quantiser_matrix[64]; + /** \brief Chroma non-intra matrix, in zig-zag scan order. */ + uint8_t chroma_non_intra_quantiser_matrix[64]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAIQMatrixBufferMPEG2; + +/** MPEG-2 Slice Parameter Buffer */ +typedef struct _VASliceParameterBufferMPEG2 { + uint32_t slice_data_size;/* number of bytes in the slice data buffer for this slice */ + uint32_t slice_data_offset;/* the offset to the first byte of slice data */ + uint32_t slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */ + uint32_t macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */ + uint32_t slice_horizontal_position; + uint32_t slice_vertical_position; + int32_t quantiser_scale_code; + int32_t intra_slice_flag; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VASliceParameterBufferMPEG2; + +/** MPEG-2 Macroblock Parameter Buffer */ +typedef struct _VAMacroblockParameterBufferMPEG2 { + uint16_t macroblock_address; + /* + * macroblock_address (in raster scan order) + * top-left: 0 + * bottom-right: picture-height-in-mb*picture-width-in-mb - 1 + */ + uint8_t macroblock_type; /* see definition below */ + union { + struct { + uint32_t frame_motion_type : 2; + uint32_t field_motion_type : 2; + uint32_t dct_type : 1; + } bits; + uint32_t value; + } macroblock_modes; + uint8_t motion_vertical_field_select; + /* + * motion_vertical_field_select: + * see section 6.3.17.2 in the spec + * only the lower 4 bits are used + * bit 0: first vector forward + * bit 1: first vector backward + * bit 2: second vector forward + * bit 3: second vector backward + */ + int16_t PMV[2][2][2]; /* see Table 7-7 in the spec */ + uint16_t coded_block_pattern; + /* + * The bitplanes for coded_block_pattern are described + * in Figure 6.10-12 in the spec + */ + + /* Number of skipped macroblocks after this macroblock */ + uint16_t num_skipped_macroblocks; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAMacroblockParameterBufferMPEG2; + +/* + * OR'd flags for macroblock_type (section 6.3.17.1 in the spec) + */ +#define VA_MB_TYPE_MOTION_FORWARD 0x02 +#define VA_MB_TYPE_MOTION_BACKWARD 0x04 +#define VA_MB_TYPE_MOTION_PATTERN 0x08 +#define VA_MB_TYPE_MOTION_INTRA 0x10 + +/** + * MPEG-2 Residual Data Buffer + * For each macroblock, there wil be 64 shorts (16-bit) in the + * residual data buffer + */ + +/**************************** + * MPEG-4 Part 2 data structures + ****************************/ + +/* MPEG-4 Picture Parameter Buffer */ +/* + * For each frame or field, and before any slice data, a single + * picture parameter buffer must be send. + */ +typedef struct _VAPictureParameterBufferMPEG4 { + uint16_t vop_width; + uint16_t vop_height; + VASurfaceID forward_reference_picture; + VASurfaceID backward_reference_picture; + union { + struct { + uint32_t short_video_header : 1; + uint32_t chroma_format : 2; + uint32_t interlaced : 1; + uint32_t obmc_disable : 1; + uint32_t sprite_enable : 2; + uint32_t sprite_warping_accuracy : 2; + uint32_t quant_type : 1; + uint32_t quarter_sample : 1; + uint32_t data_partitioned : 1; + uint32_t reversible_vlc : 1; + uint32_t resync_marker_disable : 1; + } bits; + uint32_t value; + } vol_fields; + uint8_t no_of_sprite_warping_points; + int16_t sprite_trajectory_du[3]; + int16_t sprite_trajectory_dv[3]; + uint8_t quant_precision; + union { + struct { + uint32_t vop_coding_type : 2; + uint32_t backward_reference_vop_coding_type : 2; + uint32_t vop_rounding_type : 1; + uint32_t intra_dc_vlc_thr : 3; + uint32_t top_field_first : 1; + uint32_t alternate_vertical_scan_flag : 1; + } bits; + uint32_t value; + } vop_fields; + uint8_t vop_fcode_forward; + uint8_t vop_fcode_backward; + uint16_t vop_time_increment_resolution; + /* short header related */ + uint8_t num_gobs_in_vop; + uint8_t num_macroblocks_in_gob; + /* for direct mode prediction */ + int16_t TRB; + int16_t TRD; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAPictureParameterBufferMPEG4; + +/** MPEG-4 Inverse Quantization Matrix Buffer */ +typedef struct _VAIQMatrixBufferMPEG4 { + /** Same as the MPEG-4:2 bitstream syntax element. */ + int32_t load_intra_quant_mat; + /** Same as the MPEG-4:2 bitstream syntax element. */ + int32_t load_non_intra_quant_mat; + /** The matrix for intra blocks, in zig-zag scan order. */ + uint8_t intra_quant_mat[64]; + /** The matrix for non-intra blocks, in zig-zag scan order. */ + uint8_t non_intra_quant_mat[64]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAIQMatrixBufferMPEG4; + +/** MPEG-4 Slice Parameter Buffer */ +typedef struct _VASliceParameterBufferMPEG4 { + uint32_t slice_data_size;/* number of bytes in the slice data buffer for this slice */ + uint32_t slice_data_offset;/* the offset to the first byte of slice data */ + uint32_t slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */ + uint32_t macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */ + uint32_t macroblock_number; + int32_t quant_scale; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VASliceParameterBufferMPEG4; + +/** + VC-1 data structures +*/ + +typedef enum /* see 7.1.1.32 */ +{ + VAMvMode1Mv = 0, + VAMvMode1MvHalfPel = 1, + VAMvMode1MvHalfPelBilinear = 2, + VAMvModeMixedMv = 3, + VAMvModeIntensityCompensation = 4 +} VAMvModeVC1; + +/** VC-1 Picture Parameter Buffer */ +/* + * For each picture, and before any slice data, a picture parameter + * buffer must be send. Multiple picture parameter buffers may be + * sent for a single picture. In that case picture parameters will + * apply to all slice data that follow it until a new picture + * parameter buffer is sent. + * + * Notes: + * pic_quantizer_type should be set to the applicable quantizer + * type as defined by QUANTIZER (J.1.19) and either + * PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6) + */ +typedef struct _VAPictureParameterBufferVC1 { + VASurfaceID forward_reference_picture; + VASurfaceID backward_reference_picture; + /* if out-of-loop post-processing is done on the render + target, then we need to keep the in-loop decoded + picture as a reference picture */ + VASurfaceID inloop_decoded_picture; + + /* sequence layer for AP or meta data for SP and MP */ + union { + struct { + uint32_t pulldown : 1; /* SEQUENCE_LAYER::PULLDOWN */ + uint32_t interlace : 1; /* SEQUENCE_LAYER::INTERLACE */ + uint32_t tfcntrflag : 1; /* SEQUENCE_LAYER::TFCNTRFLAG */ + uint32_t finterpflag : 1; /* SEQUENCE_LAYER::FINTERPFLAG */ + uint32_t psf : 1; /* SEQUENCE_LAYER::PSF */ + uint32_t multires : 1; /* METADATA::MULTIRES */ + uint32_t overlap : 1; /* METADATA::OVERLAP */ + uint32_t syncmarker : 1; /* METADATA::SYNCMARKER */ + uint32_t rangered : 1; /* METADATA::RANGERED */ + uint32_t max_b_frames : 3; /* METADATA::MAXBFRAMES */ + uint32_t profile : 2; /* SEQUENCE_LAYER::PROFILE or The MSB of METADATA::PROFILE */ + } bits; + uint32_t value; + } sequence_fields; + + uint16_t coded_width; /* ENTRY_POINT_LAYER::CODED_WIDTH */ + uint16_t coded_height; /* ENTRY_POINT_LAYER::CODED_HEIGHT */ + union { + struct { + uint32_t broken_link : 1; /* ENTRY_POINT_LAYER::BROKEN_LINK */ + uint32_t closed_entry : 1; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */ + uint32_t panscan_flag : 1; /* ENTRY_POINT_LAYER::PANSCAN_FLAG */ + uint32_t loopfilter : 1; /* ENTRY_POINT_LAYER::LOOPFILTER */ + } bits; + uint32_t value; + } entrypoint_fields; + uint8_t conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */ + uint8_t fast_uvmc_flag; /* ENTRY_POINT_LAYER::FASTUVMC */ + union { + struct { + uint32_t luma_flag : 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */ + uint32_t luma : 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */ + uint32_t chroma_flag : 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */ + uint32_t chroma : 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */ + } bits; + uint32_t value; + } range_mapping_fields; + + uint8_t b_picture_fraction; /* Index for PICTURE_LAYER::BFRACTION value in Table 40 (7.1.1.14) */ + uint8_t cbp_table; /* PICTURE_LAYER::CBPTAB/ICBPTAB */ + uint8_t mb_mode_table; /* PICTURE_LAYER::MBMODETAB */ + uint8_t range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */ + uint8_t rounding_control; /* PICTURE_LAYER::RNDCTRL */ + uint8_t post_processing; /* PICTURE_LAYER::POSTPROC */ + uint8_t picture_resolution_index; /* PICTURE_LAYER::RESPIC */ + uint8_t luma_scale; /* PICTURE_LAYER::LUMSCALE */ + uint8_t luma_shift; /* PICTURE_LAYER::LUMSHIFT */ + + union { + struct { + uint32_t picture_type : 3; /* PICTURE_LAYER::PTYPE */ + uint32_t frame_coding_mode : 3; /* PICTURE_LAYER::FCM */ + uint32_t top_field_first : 1; /* PICTURE_LAYER::TFF */ + uint32_t is_first_field : 1; /* set to 1 if it is the first field */ + uint32_t intensity_compensation : 1; /* PICTURE_LAYER::INTCOMP */ + } bits; + uint32_t value; + } picture_fields; + union { + struct { + uint32_t mv_type_mb : 1; /* PICTURE::MVTYPEMB */ + uint32_t direct_mb : 1; /* PICTURE::DIRECTMB */ + uint32_t skip_mb : 1; /* PICTURE::SKIPMB */ + uint32_t field_tx : 1; /* PICTURE::FIELDTX */ + uint32_t forward_mb : 1; /* PICTURE::FORWARDMB */ + uint32_t ac_pred : 1; /* PICTURE::ACPRED */ + uint32_t overflags : 1; /* PICTURE::OVERFLAGS */ + } flags; + uint32_t value; + } raw_coding; + union { + struct { + uint32_t bp_mv_type_mb : 1; /* PICTURE::MVTYPEMB */ + uint32_t bp_direct_mb : 1; /* PICTURE::DIRECTMB */ + uint32_t bp_skip_mb : 1; /* PICTURE::SKIPMB */ + uint32_t bp_field_tx : 1; /* PICTURE::FIELDTX */ + uint32_t bp_forward_mb : 1; /* PICTURE::FORWARDMB */ + uint32_t bp_ac_pred : 1; /* PICTURE::ACPRED */ + uint32_t bp_overflags : 1; /* PICTURE::OVERFLAGS */ + } flags; + uint32_t value; + } bitplane_present; /* signal what bitplane is being passed via the bitplane buffer */ + union { + struct { + uint32_t reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */ + uint32_t reference_distance : 5;/* PICTURE_LAYER::REFDIST */ + uint32_t num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */ + uint32_t reference_field_pic_indicator : 1;/* PICTURE_LAYER::REFFIELD */ + } bits; + uint32_t value; + } reference_fields; + union { + struct { + uint32_t mv_mode : 3; /* PICTURE_LAYER::MVMODE */ + uint32_t mv_mode2 : 3; /* PICTURE_LAYER::MVMODE2 */ + uint32_t mv_table : 3; /* PICTURE_LAYER::MVTAB/IMVTAB */ + uint32_t two_mv_block_pattern_table: 2; /* PICTURE_LAYER::2MVBPTAB */ + uint32_t four_mv_switch : 1; /* PICTURE_LAYER::4MVSWITCH */ + uint32_t four_mv_block_pattern_table : 2; /* PICTURE_LAYER::4MVBPTAB */ + uint32_t extended_mv_flag : 1; /* ENTRY_POINT_LAYER::EXTENDED_MV */ + uint32_t extended_mv_range : 2; /* PICTURE_LAYER::MVRANGE */ + uint32_t extended_dmv_flag : 1; /* ENTRY_POINT_LAYER::EXTENDED_DMV */ + uint32_t extended_dmv_range : 2; /* PICTURE_LAYER::DMVRANGE */ + } bits; + uint32_t value; + } mv_fields; + union { + struct { + uint32_t dquant : 2; /* ENTRY_POINT_LAYER::DQUANT */ + uint32_t quantizer : 2; /* ENTRY_POINT_LAYER::QUANTIZER */ + uint32_t half_qp : 1; /* PICTURE_LAYER::HALFQP */ + uint32_t pic_quantizer_scale : 5;/* PICTURE_LAYER::PQUANT */ + uint32_t pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */ + uint32_t dq_frame : 1; /* VOPDQUANT::DQUANTFRM */ + uint32_t dq_profile : 2; /* VOPDQUANT::DQPROFILE */ + uint32_t dq_sb_edge : 2; /* VOPDQUANT::DQSBEDGE */ + uint32_t dq_db_edge : 2; /* VOPDQUANT::DQDBEDGE */ + uint32_t dq_binary_level : 1; /* VOPDQUANT::DQBILEVEL */ + uint32_t alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */ + } bits; + uint32_t value; + } pic_quantizer_fields; + union { + struct { + uint32_t variable_sized_transform_flag : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */ + uint32_t mb_level_transform_type_flag : 1;/* PICTURE_LAYER::TTMBF */ + uint32_t frame_level_transform_type : 2;/* PICTURE_LAYER::TTFRM */ + uint32_t transform_ac_codingset_idx1 : 2;/* PICTURE_LAYER::TRANSACFRM */ + uint32_t transform_ac_codingset_idx2 : 2;/* PICTURE_LAYER::TRANSACFRM2 */ + uint32_t intra_transform_dc_table : 1;/* PICTURE_LAYER::TRANSDCTAB */ + } bits; + uint32_t value; + } transform_fields; + + uint8_t luma_scale2; /* PICTURE_LAYER::LUMSCALE2 */ + uint8_t luma_shift2; /* PICTURE_LAYER::LUMSHIFT2 */ + uint8_t intensity_compensation_field; /* Index for PICTURE_LAYER::INTCOMPFIELD value in Table 109 (9.1.1.48) */ + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM - 1]; +} VAPictureParameterBufferVC1; + +/** VC-1 Bitplane Buffer +There will be at most three bitplanes coded in any picture header. To send +the bitplane data more efficiently, each byte is divided in two nibbles, with +each nibble carrying three bitplanes for one macroblock. The following table +shows the bitplane data arrangement within each nibble based on the picture +type. + +Picture Type Bit3 Bit2 Bit1 Bit0 +I or BI OVERFLAGS ACPRED FIELDTX +P MYTYPEMB SKIPMB DIRECTMB +B FORWARDMB SKIPMB DIRECTMB + +Within each byte, the lower nibble is for the first MB and the upper nibble is +for the second MB. E.g. the lower nibble of the first byte in the bitplane +buffer is for Macroblock #1 and the upper nibble of the first byte is for +Macroblock #2 in the first row. +*/ + +/* VC-1 Slice Parameter Buffer */ +typedef struct _VASliceParameterBufferVC1 { + uint32_t slice_data_size;/* number of bytes in the slice data buffer for this slice */ + uint32_t slice_data_offset;/* the offset to the first byte of slice data */ + uint32_t slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */ + uint32_t macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */ + uint32_t slice_vertical_position; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VASliceParameterBufferVC1; + +/* VC-1 Slice Data Buffer */ +/* +This is simplely a buffer containing raw bit-stream bytes +*/ + +/**************************** + * H.264/AVC data structures + ****************************/ + +typedef struct _VAPictureH264 { + VASurfaceID picture_id; + uint32_t frame_idx; + uint32_t flags; + int32_t TopFieldOrderCnt; + int32_t BottomFieldOrderCnt; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAPictureH264; +/* flags in VAPictureH264 could be OR of the following */ +#define VA_PICTURE_H264_INVALID 0x00000001 +#define VA_PICTURE_H264_TOP_FIELD 0x00000002 +#define VA_PICTURE_H264_BOTTOM_FIELD 0x00000004 +#define VA_PICTURE_H264_SHORT_TERM_REFERENCE 0x00000008 +#define VA_PICTURE_H264_LONG_TERM_REFERENCE 0x00000010 + +/** H.264 Picture Parameter Buffer */ +/* + * For each picture, and before any slice data, a single + * picture parameter buffer must be send. + */ +typedef struct _VAPictureParameterBufferH264 { + VAPictureH264 CurrPic; + VAPictureH264 ReferenceFrames[16]; /* in DPB */ + uint16_t picture_width_in_mbs_minus1; + uint16_t picture_height_in_mbs_minus1; + uint8_t bit_depth_luma_minus8; + uint8_t bit_depth_chroma_minus8; + uint8_t num_ref_frames; + union { + struct { + uint32_t chroma_format_idc : 2; + uint32_t residual_colour_transform_flag : 1; /* Renamed to separate_colour_plane_flag in newer standard versions. */ + uint32_t gaps_in_frame_num_value_allowed_flag : 1; + uint32_t frame_mbs_only_flag : 1; + uint32_t mb_adaptive_frame_field_flag : 1; + uint32_t direct_8x8_inference_flag : 1; + uint32_t MinLumaBiPredSize8x8 : 1; /* see A.3.3.2 */ + uint32_t log2_max_frame_num_minus4 : 4; + uint32_t pic_order_cnt_type : 2; + uint32_t log2_max_pic_order_cnt_lsb_minus4 : 4; + uint32_t delta_pic_order_always_zero_flag : 1; + } bits; + uint32_t value; + } seq_fields; + // FMO is not supported. + va_deprecated uint8_t num_slice_groups_minus1; + va_deprecated uint8_t slice_group_map_type; + va_deprecated uint16_t slice_group_change_rate_minus1; + int8_t pic_init_qp_minus26; + int8_t pic_init_qs_minus26; + int8_t chroma_qp_index_offset; + int8_t second_chroma_qp_index_offset; + union { + struct { + uint32_t entropy_coding_mode_flag : 1; + uint32_t weighted_pred_flag : 1; + uint32_t weighted_bipred_idc : 2; + uint32_t transform_8x8_mode_flag : 1; + uint32_t field_pic_flag : 1; + uint32_t constrained_intra_pred_flag : 1; + uint32_t pic_order_present_flag : 1; /* Renamed to bottom_field_pic_order_in_frame_present_flag in newer standard versions. */ + uint32_t deblocking_filter_control_present_flag : 1; + uint32_t redundant_pic_cnt_present_flag : 1; + uint32_t reference_pic_flag : 1; /* nal_ref_idc != 0 */ + } bits; + uint32_t value; + } pic_fields; + uint16_t frame_num; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM]; +} VAPictureParameterBufferH264; + +/** H.264 Inverse Quantization Matrix Buffer */ +typedef struct _VAIQMatrixBufferH264 { + /** \brief 4x4 scaling list, in raster scan order. */ + uint8_t ScalingList4x4[6][16]; + /** \brief 8x8 scaling list, in raster scan order. */ + uint8_t ScalingList8x8[2][64]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAIQMatrixBufferH264; + +/** H.264 Slice Parameter Buffer */ +typedef struct _VASliceParameterBufferH264 { + uint32_t slice_data_size;/* number of bytes in the slice data buffer for this slice */ + /** \brief Byte offset to the NAL Header Unit for this slice. */ + uint32_t slice_data_offset; + uint32_t slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */ + /** + * \brief Bit offset from NAL Header Unit to the begining of slice_data(). + * + * This bit offset is relative to and includes the NAL unit byte + * and represents the number of bits parsed in the slice_header() + * after the removal of any emulation prevention bytes in + * there. However, the slice data buffer passed to the hardware is + * the original bitstream, thus including any emulation prevention + * bytes. + */ + uint16_t slice_data_bit_offset; + uint16_t first_mb_in_slice; + uint8_t slice_type; + uint8_t direct_spatial_mv_pred_flag; + /** + * H264/AVC syntax element + * + * if num_ref_idx_active_override_flag equals 0, host decoder should + * set its value to num_ref_idx_l0_default_active_minus1. + */ + uint8_t num_ref_idx_l0_active_minus1; + /** + * H264/AVC syntax element + * + * if num_ref_idx_active_override_flag equals 0, host decoder should + * set its value to num_ref_idx_l1_default_active_minus1. + */ + uint8_t num_ref_idx_l1_active_minus1; + uint8_t cabac_init_idc; + int8_t slice_qp_delta; + uint8_t disable_deblocking_filter_idc; + int8_t slice_alpha_c0_offset_div2; + int8_t slice_beta_offset_div2; + VAPictureH264 RefPicList0[32]; /* See 8.2.4.2 */ + VAPictureH264 RefPicList1[32]; /* See 8.2.4.2 */ + uint8_t luma_log2_weight_denom; + uint8_t chroma_log2_weight_denom; + uint8_t luma_weight_l0_flag; + int16_t luma_weight_l0[32]; + int16_t luma_offset_l0[32]; + uint8_t chroma_weight_l0_flag; + int16_t chroma_weight_l0[32][2]; + int16_t chroma_offset_l0[32][2]; + uint8_t luma_weight_l1_flag; + int16_t luma_weight_l1[32]; + int16_t luma_offset_l1[32]; + uint8_t chroma_weight_l1_flag; + int16_t chroma_weight_l1[32][2]; + int16_t chroma_offset_l1[32][2]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VASliceParameterBufferH264; + +/**************************** + * Common encode data structures + ****************************/ +typedef enum { + VAEncPictureTypeIntra = 0, + VAEncPictureTypePredictive = 1, + VAEncPictureTypeBidirectional = 2, +} VAEncPictureType; + +/** + * \brief Encode Slice Parameter Buffer. + * + * @deprecated + * This is a deprecated encode slice parameter buffer, All applications + * \c can use VAEncSliceParameterBufferXXX (XXX = MPEG2, HEVC, H264, JPEG) + */ +typedef struct _VAEncSliceParameterBuffer { + uint32_t start_row_number; /* starting MB row number for this slice */ + uint32_t slice_height; /* slice height measured in MB */ + union { + struct { + uint32_t is_intra : 1; + uint32_t disable_deblocking_filter_idc : 2; + uint32_t uses_long_term_ref : 1; + uint32_t is_long_term_ref : 1; + } bits; + uint32_t value; + } slice_flags; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSliceParameterBuffer; + + +/**************************** + * H.263 specific encode data structures + ****************************/ + +typedef struct _VAEncSequenceParameterBufferH263 { + uint32_t intra_period; + uint32_t bits_per_second; + uint32_t frame_rate; + uint32_t initial_qp; + uint32_t min_qp; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSequenceParameterBufferH263; + +typedef struct _VAEncPictureParameterBufferH263 { + VASurfaceID reference_picture; + VASurfaceID reconstructed_picture; + VABufferID coded_buf; + uint16_t picture_width; + uint16_t picture_height; + VAEncPictureType picture_type; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncPictureParameterBufferH263; + +/**************************** + * MPEG-4 specific encode data structures + ****************************/ + +typedef struct _VAEncSequenceParameterBufferMPEG4 { + uint8_t profile_and_level_indication; + uint32_t intra_period; + uint32_t video_object_layer_width; + uint32_t video_object_layer_height; + uint32_t vop_time_increment_resolution; + uint32_t fixed_vop_rate; + uint32_t fixed_vop_time_increment; + uint32_t bits_per_second; + uint32_t frame_rate; + uint32_t initial_qp; + uint32_t min_qp; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSequenceParameterBufferMPEG4; + +typedef struct _VAEncPictureParameterBufferMPEG4 { + VASurfaceID reference_picture; + VASurfaceID reconstructed_picture; + VABufferID coded_buf; + uint16_t picture_width; + uint16_t picture_height; + uint32_t modulo_time_base; /* number of 1s */ + uint32_t vop_time_increment; + VAEncPictureType picture_type; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncPictureParameterBufferMPEG4; + + + +/** Buffer functions */ + +/** + * Creates a buffer for "num_elements" elements of "size" bytes and + * initalize with "data". + * if "data" is null, then the contents of the buffer data store + * are undefined. + * Basically there are two ways to get buffer data to the server side. One is + * to call vaCreateBuffer() with a non-null "data", which results the data being + * copied to the data store on the server side. A different method that + * eliminates this copy is to pass null as "data" when calling vaCreateBuffer(), + * and then use vaMapBuffer() to map the data store from the server side to the + * client address space for access. + * The user must call vaDestroyBuffer() to destroy a buffer. + * Note: image buffers are created by the library, not the client. Please see + * vaCreateImage on how image buffers are managed. + */ +VAStatus vaCreateBuffer( + VADisplay dpy, + VAContextID context, + VABufferType type, /* in */ + unsigned int size, /* in */ + unsigned int num_elements, /* in */ + void *data, /* in */ + VABufferID *buf_id /* out */ +); + +/** + * Create a buffer for given width & height get unit_size, pitch, buf_id for 2D buffer + * for permb qp buffer, it will return unit_size for one MB or LCU and the pitch for alignments + * can call vaMapBuffer with this Buffer ID to get virtual address. + * e.g. AVC 1080P encode, 1920x1088, the size in MB is 120x68,but inside driver, + * maybe it should align with 256, and one byte present one Qp.so, call the function. + * then get unit_size = 1, pitch = 256. call vaMapBuffer to get the virtual address (pBuf). + * then read write the memory like 2D. the size is 256x68, application can only use 120x68 + * pBuf + 256 is the start of next line. + * different driver implementation maybe return different unit_size and pitch + */ +VAStatus vaCreateBuffer2( + VADisplay dpy, + VAContextID context, + VABufferType type, + unsigned int width, + unsigned int height, + unsigned int *unit_size, + unsigned int *pitch, + VABufferID *buf_id +); + +/** + * Convey to the server how many valid elements are in the buffer. + * e.g. if multiple slice parameters are being held in a single buffer, + * this will communicate to the server the number of slice parameters + * that are valid in the buffer. + */ +VAStatus vaBufferSetNumElements( + VADisplay dpy, + VABufferID buf_id, /* in */ + unsigned int num_elements /* in */ +); + + +/** + * device independent data structure for codedbuffer + */ + +/* + * FICTURE_AVE_QP(bit7-0): The average Qp value used during this frame + * LARGE_SLICE(bit8):At least one slice in the current frame was large + * enough for the encoder to attempt to limit its size. + * SLICE_OVERFLOW(bit9): At least one slice in the current frame has + * exceeded the maximum slice size specified. + * BITRATE_OVERFLOW(bit10): The peak bitrate was exceeded for this frame. + * BITRATE_HIGH(bit11): The frame size got within the safety margin of the maximum size (VCM only) + * AIR_MB_OVER_THRESHOLD: the number of MBs adapted to Intra MB + */ +#define VA_CODED_BUF_STATUS_PICTURE_AVE_QP_MASK 0xff +#define VA_CODED_BUF_STATUS_LARGE_SLICE_MASK 0x100 +#define VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK 0x200 +#define VA_CODED_BUF_STATUS_BITRATE_OVERFLOW 0x400 +#define VA_CODED_BUF_STATUS_BITRATE_HIGH 0x800 +/** + * \brief The frame has exceeded the maximum requested size. + * + * This flag indicates that the encoded frame size exceeds the value + * specified through a misc parameter buffer of type + * #VAEncMiscParameterTypeMaxFrameSize. + */ +#define VA_CODED_BUF_STATUS_FRAME_SIZE_OVERFLOW 0x1000 +/** + * \brief the bitstream is bad or corrupt. + */ +#define VA_CODED_BUF_STATUS_BAD_BITSTREAM 0x8000 +#define VA_CODED_BUF_STATUS_AIR_MB_OVER_THRESHOLD 0xff0000 + +/** + * \brief The coded buffer segment status contains frame encoding passes number + * + * This is the mask to get the number of encoding passes from the coded + * buffer segment status. + * NUMBER_PASS(bit24~bit27): the number for encoding passes executed for the coded frame. + * + */ +#define VA_CODED_BUF_STATUS_NUMBER_PASSES_MASK 0xf000000 + +/** + * \brief The coded buffer segment contains a single NAL unit. + * + * This flag indicates that the coded buffer segment contains a + * single NAL unit. This flag might be useful to the user for + * processing the coded buffer. + */ +#define VA_CODED_BUF_STATUS_SINGLE_NALU 0x10000000 + +/** + * \brief Coded buffer segment. + * + * #VACodedBufferSegment is an element of a linked list describing + * some information on the coded buffer. The coded buffer segment + * could contain either a single NAL unit, or more than one NAL unit. + * It is recommended (but not required) to return a single NAL unit + * in a coded buffer segment, and the implementation should set the + * VA_CODED_BUF_STATUS_SINGLE_NALU status flag if that is the case. + */ +typedef struct _VACodedBufferSegment { + /** + * \brief Size of the data buffer in this segment (in bytes). + */ + uint32_t size; + /** \brief Bit offset into the data buffer where the video data starts. */ + uint32_t bit_offset; + /** \brief Status set by the driver. See \c VA_CODED_BUF_STATUS_*. */ + uint32_t status; + /** \brief Reserved for future use. */ + uint32_t reserved; + /** \brief Pointer to the start of the data buffer. */ + void *buf; + /** + * \brief Pointer to the next #VACodedBufferSegment element, + * or \c NULL if there is none. + */ + void *next; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VACodedBufferSegment; + +/** + * Map data store of the buffer into the client's address space + * vaCreateBuffer() needs to be called with "data" set to NULL before + * calling vaMapBuffer() + * + * if buffer type is VAEncCodedBufferType, pbuf points to link-list of + * VACodedBufferSegment, and the list is terminated if "next" is NULL + */ +VAStatus vaMapBuffer( + VADisplay dpy, + VABufferID buf_id, /* in */ + void **pbuf /* out */ +); + +/** + * After client making changes to a mapped data store, it needs to + * "Unmap" it to let the server know that the data is ready to be + * consumed by the server + */ +VAStatus vaUnmapBuffer( + VADisplay dpy, + VABufferID buf_id /* in */ +); + +/** + * After this call, the buffer is deleted and this buffer_id is no longer valid + * + * A buffer can be re-used and sent to the server by another Begin/Render/End + * sequence if vaDestroyBuffer() is not called with this buffer. + * + * Note re-using a shared buffer (e.g. a slice data buffer) between the host and the + * hardware accelerator can result in performance dropping. + */ +VAStatus vaDestroyBuffer( + VADisplay dpy, + VABufferID buffer_id +); + +/** \brief VA buffer information */ +typedef struct { + /** \brief Buffer handle */ + uintptr_t handle; + /** \brief Buffer type (See \ref VABufferType). */ + uint32_t type; + /** + * \brief Buffer memory type (See \ref VASurfaceAttribMemoryType). + * + * On input to vaAcquireBufferHandle(), this field can serve as a hint + * to specify the set of memory types the caller is interested in. + * On successful return from vaAcquireBufferHandle(), the field is + * updated with the best matching memory type. + */ + uint32_t mem_type; + /** \brief Size of the underlying buffer. */ + size_t mem_size; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VABufferInfo; + +/** + * \brief Acquires buffer handle for external API usage + * + * Locks the VA buffer object \ref buf_id for external API usage like + * EGL or OpenCL (OCL). This function is a synchronization point. This + * means that any pending operation is guaranteed to be completed + * prior to returning from the function. + * + * If the referenced VA buffer object is the backing store of a VA + * surface, then this function acts as if vaSyncSurface() on the + * parent surface was called first. + * + * The \ref VABufferInfo argument shall be zero'ed on input. On + * successful output, the data structure is filled in with all the + * necessary buffer level implementation details like handle, type, + * memory type and memory size. + * + * Note: the external API implementation, or the application, can + * express the memory types it is interested in by filling in the \ref + * mem_type field accordingly. On successful output, the memory type + * that fits best the request and that was used is updated in the \ref + * VABufferInfo data structure. If none of the supplied memory types + * is supported, then a \ref VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE + * error is returned. + * + * The \ref VABufferInfo data is valid until vaReleaseBufferHandle() + * is called. Besides, no additional operation is allowed on any of + * the buffer parent object until vaReleaseBufferHandle() is called. + * e.g. decoding into a VA surface backed with the supplied VA buffer + * object \ref buf_id would fail with a \ref VA_STATUS_ERROR_SURFACE_BUSY + * error. + * + * Possible errors: + * - \ref VA_STATUS_ERROR_UNIMPLEMENTED: the VA driver implementation + * does not support this interface + * - \ref VA_STATUS_ERROR_INVALID_DISPLAY: an invalid display was supplied + * - \ref VA_STATUS_ERROR_INVALID_BUFFER: an invalid buffer was supplied + * - \ref VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE: the implementation + * does not support exporting buffers of the specified type + * - \ref VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE: none of the requested + * memory types in \ref VABufferInfo.mem_type was supported + * + * @param[in] dpy the VA display + * @param[in] buf_id the VA buffer + * @param[in,out] buf_info the associated VA buffer information + * @return VA_STATUS_SUCCESS if successful + */ +VAStatus +vaAcquireBufferHandle(VADisplay dpy, VABufferID buf_id, VABufferInfo *buf_info); + +/** + * \brief Releases buffer after usage from external API + * + * Unlocks the VA buffer object \ref buf_id from external API usage like + * EGL or OpenCL (OCL). This function is a synchronization point. This + * means that any pending operation is guaranteed to be completed + * prior to returning from the function. + * + * The \ref VABufferInfo argument shall point to the original data + * structure that was obtained from vaAcquireBufferHandle(), unaltered. + * This is necessary so that the VA driver implementation could + * deallocate any resources that were needed. + * + * In any case, returning from this function invalidates any contents + * in \ref VABufferInfo. i.e. the underlyng buffer handle is no longer + * valid. Therefore, VA driver implementations are free to reset this + * data structure to safe defaults. + * + * Possible errors: + * - \ref VA_STATUS_ERROR_UNIMPLEMENTED: the VA driver implementation + * does not support this interface + * - \ref VA_STATUS_ERROR_INVALID_DISPLAY: an invalid display was supplied + * - \ref VA_STATUS_ERROR_INVALID_BUFFER: an invalid buffer was supplied + * - \ref VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE: the implementation + * does not support exporting buffers of the specified type + * + * @param[in] dpy the VA display + * @param[in] buf_id the VA buffer + * @return VA_STATUS_SUCCESS if successful + */ +VAStatus +vaReleaseBufferHandle(VADisplay dpy, VABufferID buf_id); + +/** @name vaExportSurfaceHandle() flags + * + * @{ + */ +/** Export surface to be read by external API. */ +#define VA_EXPORT_SURFACE_READ_ONLY 0x0001 +/** Export surface to be written by external API. */ +#define VA_EXPORT_SURFACE_WRITE_ONLY 0x0002 +/** Export surface to be both read and written by external API. */ +#define VA_EXPORT_SURFACE_READ_WRITE 0x0003 +/** Export surface with separate layers. + * + * For example, NV12 surfaces should be exported as two separate + * planes for luma and chroma. + */ +#define VA_EXPORT_SURFACE_SEPARATE_LAYERS 0x0004 +/** Export surface with composed layers. + * + * For example, NV12 surfaces should be exported as a single NV12 + * composed object. + */ +#define VA_EXPORT_SURFACE_COMPOSED_LAYERS 0x0008 + +/** @} */ + +/** + * \brief Export a handle to a surface for use with an external API + * + * The exported handles are owned by the caller, and the caller is + * responsible for freeing them when no longer needed (e.g. by closing + * DRM PRIME file descriptors). + * + * This does not perform any synchronisation. If the contents of the + * surface will be read, vaSyncSurface() must be called before doing so. + * If the contents of the surface are written, then all operations must + * be completed externally before using the surface again by via VA-API + * functions. + * + * @param[in] dpy VA display. + * @param[in] surface_id Surface to export. + * @param[in] mem_type Memory type to export to. + * @param[in] flags Combination of flags to apply + * (VA_EXPORT_SURFACE_*). + * @param[out] descriptor Pointer to the descriptor structure to fill + * with the handle details. The type of this structure depends on + * the value of mem_type. + * + * @return Status code: + * - VA_STATUS_SUCCESS: Success. + * - VA_STATUS_ERROR_INVALID_DISPLAY: The display is not valid. + * - VA_STATUS_ERROR_UNIMPLEMENTED: The driver does not implement + * this interface. + * - VA_STATUS_ERROR_INVALID_SURFACE: The surface is not valid, or + * the surface is not exportable in the specified way. + * - VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE: The driver does not + * support exporting surfaces to the specified memory type. + */ +VAStatus vaExportSurfaceHandle(VADisplay dpy, + VASurfaceID surface_id, + uint32_t mem_type, uint32_t flags, + void *descriptor); + +/** + * Render (Video Decode/Encode/Processing) Pictures + * + * A picture represents either a frame or a field. + * + * The Begin/Render/End sequence sends the video decode/encode/processing buffers + * to the server + */ + +/** + * Get ready for a video pipeline + * - decode a picture to a target surface + * - encode a picture from a target surface + * - process a picture to a target surface + */ +VAStatus vaBeginPicture( + VADisplay dpy, + VAContextID context, + VASurfaceID render_target +); + +/** + * Send video decode, encode or processing buffers to the server. + */ +VAStatus vaRenderPicture( + VADisplay dpy, + VAContextID context, + VABufferID *buffers, + int num_buffers +); + +/** + * Make the end of rendering for a picture. + * The server should start processing all pending operations for this + * surface. This call is non-blocking. The client can start another + * Begin/Render/End sequence on a different render target. + * if VAContextID used in this function previously successfully passed + * vaMFAddContext call, real processing will be started during vaMFSubmit + */ +VAStatus vaEndPicture( + VADisplay dpy, + VAContextID context +); + +/** + * Make the end of rendering for a pictures in contexts passed with submission. + * The server should start processing all pending operations for contexts. + * All contexts passed should be associated through vaMFAddContext + * and call sequence Begin/Render/End performed. + * This call is non-blocking. The client can start another + * Begin/Render/End/vaMFSubmit sequence on a different render targets. + * Return values: + * VA_STATUS_SUCCESS - operation successful, context was removed. + * VA_STATUS_ERROR_INVALID_CONTEXT - mf_context or one of contexts are invalid + * due to mf_context not created or one of contexts not assotiated with mf_context + * through vaAddContext. + * VA_STATUS_ERROR_INVALID_PARAMETER - one of context has not submitted it's frame + * through vaBeginPicture vaRenderPicture vaEndPicture call sequence. + * dpy: display + * mf_context: Multi-Frame context + * contexts: list of contexts submitting their tasks for multi-frame operation. + * num_contexts: number of passed contexts. + */ +VAStatus vaMFSubmit( + VADisplay dpy, + VAMFContextID mf_context, + VAContextID * contexts, + int num_contexts +); + +/* + +Synchronization + +*/ + +/** + * This function blocks until all pending operations on the render target + * have been completed. Upon return it is safe to use the render target for a + * different picture. + */ +VAStatus vaSyncSurface( + VADisplay dpy, + VASurfaceID render_target +); + +/** \brief Indicates an infinite timeout. */ +#define VA_TIMEOUT_INFINITE 0xFFFFFFFFFFFFFFFF + +/** + * \brief Synchronizes pending operations associated with the supplied surface. + * + * This function blocks during specified timeout (in nanoseconds) until + * all pending operations on the render target have been completed. + * If timeout is zero, the function returns immediately. + * + * Possible errors: + * - \ref VA_STATUS_ERROR_UNIMPLEMENTED: the VA driver implementation + * does not support this interface + * - \ref VA_STATUS_ERROR_INVALID_DISPLAY: an invalid display was supplied + * - \ref VA_STATUS_ERROR_INVALID_SURFACE: an invalid surface was supplied + * - \ref VA_STATUS_ERROR_TIMEDOUT: synchronization is still in progress, + * client should call the function again to complete synchronization + * + * @param[in] dpy the VA display + * @param[in] surface the surface for which synchronization is performed + * @param[in] timeout_ns the timeout in nanoseconds + * + */ +VAStatus vaSyncSurface2( + VADisplay dpy, + VASurfaceID surface, + uint64_t timeout_ns +); + +typedef enum { + VASurfaceRendering = 1, /* Rendering in progress */ + VASurfaceDisplaying = 2, /* Displaying in progress (not safe to render into it) */ + /* this status is useful if surface is used as the source */ + /* of an overlay */ + VASurfaceReady = 4, /* not being rendered or displayed */ + VASurfaceSkipped = 8 /* Indicate a skipped frame during encode */ +} VASurfaceStatus; + +/** + * Find out any pending ops on the render target + */ +VAStatus vaQuerySurfaceStatus( + VADisplay dpy, + VASurfaceID render_target, + VASurfaceStatus *status /* out */ +); + +typedef enum { + VADecodeSliceMissing = 0, + VADecodeMBError = 1, +} VADecodeErrorType; + +/** + * Client calls vaQuerySurfaceError with VA_STATUS_ERROR_DECODING_ERROR, server side returns + * an array of structure VASurfaceDecodeMBErrors, and the array is terminated by setting status=-1 +*/ +typedef struct _VASurfaceDecodeMBErrors { + int32_t status; /* 1 if hardware has returned detailed info below, -1 means this record is invalid */ + uint32_t start_mb; /* start mb address with errors */ + uint32_t end_mb; /* end mb address with errors */ + VADecodeErrorType decode_error_type; + uint32_t num_mb; /* number of mbs with errors */ + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW - 1]; +} VASurfaceDecodeMBErrors; + +/** + * After the application gets VA_STATUS_ERROR_DECODING_ERROR after calling vaSyncSurface(), + * it can call vaQuerySurfaceError to find out further details on the particular error. + * VA_STATUS_ERROR_DECODING_ERROR should be passed in as "error_status", + * upon the return, error_info will point to an array of _VASurfaceDecodeMBErrors structure, + * which is allocated and filled by libVA with detailed information on the missing or error macroblocks. + * The array is terminated if "status==-1" is detected. + */ +VAStatus vaQuerySurfaceError( + VADisplay dpy, + VASurfaceID surface, + VAStatus error_status, + void **error_info +); + +/** + * \brief Synchronizes pending operations associated with the supplied buffer. + * + * This function blocks during specified timeout (in nanoseconds) until + * all pending operations on the supplied buffer have been completed. + * If timeout is zero, the function returns immediately. + * + * Possible errors: + * - \ref VA_STATUS_ERROR_UNIMPLEMENTED: the VA driver implementation + * does not support this interface + * - \ref VA_STATUS_ERROR_INVALID_DISPLAY: an invalid display was supplied + * - \ref VA_STATUS_ERROR_INVALID_BUFFER: an invalid buffer was supplied + * - \ref VA_STATUS_ERROR_TIMEDOUT: synchronization is still in progress, + * client should call the function again to complete synchronization + * + * @param[in] dpy the VA display + * @param[in] buf_id the buffer for which synchronization is performed + * @param[in] timeout_ns the timeout in nanoseconds + * + */ +VAStatus vaSyncBuffer( + VADisplay dpy, + VABufferID buf_id, + uint64_t timeout_ns +); + +/** + * Notes about synchronization interfaces: + * vaSyncSurface: + * 1. Allows to synchronize output surface (i.e. from decoding or VP) + * 2. Allows to synchronize all bitstreams being encoded from the given input surface (1->N pipelines). + * + * vaSyncSurface2: + * 1. The same as vaSyncSurface but allows to specify a timeout + * + * vaSyncBuffer: + * 1. Allows to synchronize output buffer (e.g. bitstream from encoding). + * Comparing to vaSyncSurface this function synchronizes given bitstream only. + */ + +/** + * Images and Subpictures + * VAImage is used to either get the surface data to client memory, or + * to copy image data in client memory to a surface. + * Both images, subpictures and surfaces follow the same 2D coordinate system where origin + * is at the upper left corner with positive X to the right and positive Y down + */ +#define VA_FOURCC(ch0, ch1, ch2, ch3) \ + ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \ + ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 )) + +/* Pre-defined fourcc codes. */ + +/** NV12: two-plane 8-bit YUV 4:2:0. + * The first plane contains Y, the second plane contains U and V in pairs of bytes. + */ +#define VA_FOURCC_NV12 0x3231564E +/** NV21: two-plane 8-bit YUV 4:2:0. + * Same as NV12, but with U and V swapped. + */ +#define VA_FOURCC_NV21 0x3132564E + +/** AI44: packed 4-bit YA. + * + * The bottom half of each byte contains luma, the top half contains alpha. + */ +#define VA_FOURCC_AI44 0x34344149 + +/** RGBA: packed 8-bit RGBA. + * + * Four bytes per pixel: red, green, blue, alpha. + */ +#define VA_FOURCC_RGBA 0x41424752 +/** RGBX: packed 8-bit RGB. + * + * Four bytes per pixel: red, green, blue, unspecified. + */ +#define VA_FOURCC_RGBX 0x58424752 +/** BGRA: packed 8-bit RGBA. + * + * Four bytes per pixel: blue, green, red, alpha. + */ +#define VA_FOURCC_BGRA 0x41524742 +/** BGRX: packed 8-bit RGB. + * + * Four bytes per pixel: blue, green, red, unspecified. + */ +#define VA_FOURCC_BGRX 0x58524742 +/** ARGB: packed 8-bit RGBA. + * + * Four bytes per pixel: alpha, red, green, blue. + */ +#define VA_FOURCC_ARGB 0x42475241 +/** XRGB: packed 8-bit RGB. + * + * Four bytes per pixel: unspecified, red, green, blue. + */ +#define VA_FOURCC_XRGB 0x42475258 +/** ABGR: packed 8-bit RGBA. + * + * Four bytes per pixel: alpha, blue, green, red. + */ +#define VA_FOURCC_ABGR 0x52474241 +/** XBGR: packed 8-bit RGB. + * + * Four bytes per pixel: unspecified, blue, green, red. + */ +#define VA_FOURCC_XBGR 0x52474258 + +/** UYUV: packed 8-bit YUV 4:2:2. + * + * Four bytes per pair of pixels: U, Y, U, V. + */ +#define VA_FOURCC_UYVY 0x59565955 +/** YUY2: packed 8-bit YUV 4:2:2. + * + * Four bytes per pair of pixels: Y, U, Y, V. + */ +#define VA_FOURCC_YUY2 0x32595559 +/** AYUV: packed 8-bit YUVA 4:4:4. + * + * Four bytes per pixel: A, Y, U, V. + */ +#define VA_FOURCC_AYUV 0x56555941 +/** NV11: two-plane 8-bit YUV 4:1:1. + * + * The first plane contains Y, the second plane contains U and V in pairs of bytes. + */ +#define VA_FOURCC_NV11 0x3131564e +/** YV12: three-plane 8-bit YUV 4:2:0. + * + * The three planes contain Y, V and U respectively. + */ +#define VA_FOURCC_YV12 0x32315659 +/** P208: two-plane 8-bit YUV 4:2:2. + * + * The first plane contains Y, the second plane contains U and V in pairs of bytes. + */ +#define VA_FOURCC_P208 0x38303250 +/** I420: three-plane 8-bit YUV 4:2:0. + * + * The three planes contain Y, U and V respectively. + */ +#define VA_FOURCC_I420 0x30323449 +/** YV24: three-plane 8-bit YUV 4:4:4. + * + * The three planes contain Y, V and U respectively. + */ +#define VA_FOURCC_YV24 0x34325659 +/** YV32: four-plane 8-bit YUVA 4:4:4 + * + * The four planes contain Y, V, U and A respectively. + */ +#define VA_FOURCC_YV32 0x32335659 +/** Y800: 8-bit greyscale. + */ +#define VA_FOURCC_Y800 0x30303859 +/** IMC3: three-plane 8-bit YUV 4:2:0. + * + * Equivalent to YV12, but with the additional constraint that the pitch of all three planes + * must be the same. + */ +#define VA_FOURCC_IMC3 0x33434D49 +/** 411P: three-plane 8-bit YUV 4:1:1. + * + * The three planes contain Y, U and V respectively. + */ +#define VA_FOURCC_411P 0x50313134 +/** 411R: three-plane 8-bit YUV. + * + * The subsampling is the transpose of 4:1:1 - full chroma appears on every fourth line. + * The three planes contain Y, U and V respectively. + */ +#define VA_FOURCC_411R 0x52313134 +/** 422H: three-plane 8-bit YUV 4:2:2. + * + * The three planes contain Y, U and V respectively. + */ +#define VA_FOURCC_422H 0x48323234 +/** 422V: three-plane 8-bit YUV 4:4:0. + * + * The three planes contain Y, U and V respectively. + */ +#define VA_FOURCC_422V 0x56323234 +/** 444P: three-plane 8-bit YUV 4:4:4. + * + * The three planes contain Y, U and V respectively. + */ +#define VA_FOURCC_444P 0x50343434 + +/** RGBP: three-plane 8-bit RGB. + * + * The three planes contain red, green and blue respectively. + */ +#define VA_FOURCC_RGBP 0x50424752 +/** BGRP: three-plane 8-bit RGB. + * + * The three planes contain blue, green and red respectively. + */ +#define VA_FOURCC_BGRP 0x50524742 +/** RG16: packed 5/6-bit RGB. + * + * Each pixel is a two-byte little-endian value. + * Red, green and blue are found in bits 15:11, 10:5, 4:0 respectively. + */ +#define VA_FOURCC_RGB565 0x36314752 +/** BG16: packed 5/6-bit RGB. + * + * Each pixel is a two-byte little-endian value. + * Blue, green and red are found in bits 15:11, 10:5, 4:0 respectively. + */ +#define VA_FOURCC_BGR565 0x36314742 + +/** Y210: packed 10-bit YUV 4:2:2. + * + * Eight bytes represent a pair of pixels. Each sample is a two-byte little-endian value, + * with the bottom six bits ignored. The samples are in the order Y, U, Y, V. + */ +#define VA_FOURCC_Y210 0x30313259 +/** Y212: packed 12-bit YUV 4:2:2. + * + * Eight bytes represent a pair of pixels. Each sample is a two-byte little-endian value. + * The samples are in the order Y, U, Y, V. + */ +#define VA_FOURCC_Y212 0x32313259 +/** Y216: packed 16-bit YUV 4:2:2. + * + * Eight bytes represent a pair of pixels. Each sample is a two-byte little-endian value. + * The samples are in the order Y, U, Y, V. + */ +#define VA_FOURCC_Y216 0x36313259 +/** Y410: packed 10-bit YUVA 4:4:4. + * + * Each pixel is a four-byte little-endian value. + * A, V, Y, U are found in bits 31:30, 29:20, 19:10, 9:0 respectively. + */ +#define VA_FOURCC_Y410 0x30313459 +/** Y412 packed 12-bit YUVA 4:4:4. + * + * Each pixel is a set of four samples, each of which is a two-byte little-endian value. + * The samples are in the order A, V, Y, U. + */ +#define VA_FOURCC_Y412 0x32313459 +/** Y416: packed 16-bit YUVA 4:4:4. + * + * Each pixel is a set of four samples, each of which is a two-byte little-endian value. + * The samples are in the order A, V, Y, U. + */ +#define VA_FOURCC_Y416 0x36313459 + +/** YV16: three-plane 8-bit YUV 4:2:2. + * + * The three planes contain Y, V and U respectively. + */ +#define VA_FOURCC_YV16 0x36315659 +/** P010: two-plane 10-bit YUV 4:2:0. + * + * Each sample is a two-byte little-endian value with the bottom six bits ignored. + * The first plane contains Y, the second plane contains U and V in pairs of samples. + */ +#define VA_FOURCC_P010 0x30313050 +/** P012: two-plane 12-bit YUV 4:2:0. + * + * Each sample is a two-byte little-endian value with the bottom four bits ignored. + * The first plane contains Y, the second plane contains U and V in pairs of samples. + */ +#define VA_FOURCC_P012 0x32313050 +/** P016: two-plane 16-bit YUV 4:2:0. + * + * Each sample is a two-byte little-endian value. The first plane contains Y, the second + * plane contains U and V in pairs of samples. + */ +#define VA_FOURCC_P016 0x36313050 + +/** I010: three-plane 10-bit YUV 4:2:0. + * + * Each sample is a two-byte little-endian value with the top six bits ignored. + * The three planes contain Y, V and U respectively. + */ +#define VA_FOURCC_I010 0x30313049 + +/** IYUV: three-plane 8-bit YUV 4:2:0. + * + * @deprecated Use I420 instead. + */ +#define VA_FOURCC_IYUV 0x56555949 +/** + * 10-bit Pixel RGB formats. + */ +#define VA_FOURCC_A2R10G10B10 0x30335241 /* VA_FOURCC('A','R','3','0') */ +/** + * 10-bit Pixel BGR formats. + */ +#define VA_FOURCC_A2B10G10R10 0x30334241 /* VA_FOURCC('A','B','3','0') */ +/** + * 10-bit Pixel RGB formats without alpha. + */ +#define VA_FOURCC_X2R10G10B10 0x30335258 /* VA_FOURCC('X','R','3','0') */ +/** + * 10-bit Pixel BGR formats without alpha. + */ +#define VA_FOURCC_X2B10G10R10 0x30334258 /* VA_FOURCC('X','B','3','0') */ + +/** Y8: 8-bit greyscale. + * + * Only a single sample, 8 bit Y plane for monochrome images + */ +#define VA_FOURCC_Y8 0x20203859 +/** Y16: 16-bit greyscale. + * + * Only a single sample, 16 bit Y plane for monochrome images + */ +#define VA_FOURCC_Y16 0x20363159 +/** VYUV: packed 8-bit YUV 4:2:2. + * + * Four bytes per pair of pixels: V, Y, U, V. + */ +#define VA_FOURCC_VYUY 0x59555956 +/** YVYU: packed 8-bit YUV 4:2:2. + * + * Four bytes per pair of pixels: Y, V, Y, U. + */ +#define VA_FOURCC_YVYU 0x55595659 +/** AGRB64: three-plane 16-bit ARGB 16:16:16:16 + * + * The four planes contain: alpha, red, green, blue respectively. + */ +#define VA_FOURCC_ARGB64 0x34475241 +/** ABGR64: three-plane 16-bit ABGR 16:16:16:16 + * + * The four planes contain: alpha, blue, green, red respectively. + */ +#define VA_FOURCC_ABGR64 0x34474241 +/** XYUV: packed 8-bit YUVX 4:4:4. + * + * Four bytes per pixel: X, Y, U, V. + */ +#define VA_FOURCC_XYUV 0x56555958 + +/* byte order */ +#define VA_LSB_FIRST 1 +#define VA_MSB_FIRST 2 + +typedef struct _VAImageFormat { + uint32_t fourcc; + uint32_t byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */ + uint32_t bits_per_pixel; + /* for RGB formats */ + uint32_t depth; /* significant bits per pixel */ + uint32_t red_mask; + uint32_t green_mask; + uint32_t blue_mask; + uint32_t alpha_mask; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAImageFormat; + +typedef VAGenericID VAImageID; + +typedef struct _VAImage { + VAImageID image_id; /* uniquely identify this image */ + VAImageFormat format; + VABufferID buf; /* image data buffer */ + /* + * Image data will be stored in a buffer of type VAImageBufferType to facilitate + * data store on the server side for optimal performance. The buffer will be + * created by the CreateImage function, and proper storage allocated based on the image + * size and format. This buffer is managed by the library implementation, and + * accessed by the client through the buffer Map/Unmap functions. + */ + uint16_t width; + uint16_t height; + uint32_t data_size; + uint32_t num_planes; /* can not be greater than 3 */ + /* + * An array indicating the scanline pitch in bytes for each plane. + * Each plane may have a different pitch. Maximum 3 planes for planar formats + */ + uint32_t pitches[3]; + /* + * An array indicating the byte offset from the beginning of the image data + * to the start of each plane. + */ + uint32_t offsets[3]; + + /* The following fields are only needed for paletted formats */ + int32_t num_palette_entries; /* set to zero for non-palette images */ + /* + * Each component is one byte and entry_bytes indicates the number of components in + * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images + */ + int32_t entry_bytes; + /* + * An array of ascii characters describing the order of the components within the bytes. + * Only entry_bytes characters of the string are used. + */ + int8_t component_order[4]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAImage; + +/** Get maximum number of image formats supported by the implementation */ +int vaMaxNumImageFormats( + VADisplay dpy +); + +/** + * Query supported image formats + * The caller must provide a "format_list" array that can hold at + * least vaMaxNumImageFormats() entries. The actual number of formats + * returned in "format_list" is returned in "num_formats". + */ +VAStatus vaQueryImageFormats( + VADisplay dpy, + VAImageFormat *format_list, /* out */ + int *num_formats /* out */ +); + +/** + * Create a VAImage structure + * The width and height fields returned in the VAImage structure may get + * enlarged for some YUV formats. Upon return from this function, + * image->buf has been created and proper storage allocated by the library. + * The client can access the image through the Map/Unmap calls. + */ +VAStatus vaCreateImage( + VADisplay dpy, + VAImageFormat *format, + int width, + int height, + VAImage *image /* out */ +); + +/** + * Should call DestroyImage before destroying the surface it is bound to + */ +VAStatus vaDestroyImage( + VADisplay dpy, + VAImageID image +); + +VAStatus vaSetImagePalette( + VADisplay dpy, + VAImageID image, + /* + * pointer to an array holding the palette data. The size of the array is + * num_palette_entries * entry_bytes in size. The order of the components + * in the palette is described by the component_order in VAImage struct + */ + unsigned char *palette +); + +/** + * Retrive surface data into a VAImage + * Image must be in a format supported by the implementation + */ +VAStatus vaGetImage( + VADisplay dpy, + VASurfaceID surface, + int x, /* coordinates of the upper left source pixel */ + int y, + unsigned int width, /* width and height of the region */ + unsigned int height, + VAImageID image +); + +/** + * Copy data from a VAImage to a surface + * Image must be in a format supported by the implementation + * Returns a VA_STATUS_ERROR_SURFACE_BUSY if the surface + * shouldn't be rendered into when this is called + */ +VAStatus vaPutImage( + VADisplay dpy, + VASurfaceID surface, + VAImageID image, + int src_x, + int src_y, + unsigned int src_width, + unsigned int src_height, + int dest_x, + int dest_y, + unsigned int dest_width, + unsigned int dest_height +); + +/** + * Derive an VAImage from an existing surface. + * This interface will derive a VAImage and corresponding image buffer from + * an existing VA Surface. The image buffer can then be mapped/unmapped for + * direct CPU access. This operation is only possible on implementations with + * direct rendering capabilities and internal surface formats that can be + * represented with a VAImage. When the operation is not possible this interface + * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back + * to using vaCreateImage + vaPutImage to accomplish the same task in an + * indirect manner. + * + * Implementations should only return success when the resulting image buffer + * would be useable with vaMap/Unmap. + * + * When directly accessing a surface special care must be taken to insure + * proper synchronization with the graphics hardware. Clients should call + * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent + * rendering or currently being displayed by an overlay. + * + * Additionally nothing about the contents of a surface should be assumed + * following a vaPutSurface. Implementations are free to modify the surface for + * scaling or subpicture blending within a call to vaPutImage. + * + * Calls to vaPutImage or vaGetImage using the same surface from which the image + * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or + * vaGetImage with other surfaces is supported. + * + * An image created with vaDeriveImage should be freed with vaDestroyImage. The + * image and image buffer structures will be destroyed; however, the underlying + * surface will remain unchanged until freed with vaDestroySurfaces. + */ +VAStatus vaDeriveImage( + VADisplay dpy, + VASurfaceID surface, + VAImage *image /* out */ +); + +/** + * Subpictures + * Subpicture is a special type of image that can be blended + * with a surface during vaPutSurface(). Subpicture can be used to render + * DVD sub-titles or closed captioning text etc. + */ + +typedef VAGenericID VASubpictureID; + +/** Get maximum number of subpicture formats supported by the implementation */ +int vaMaxNumSubpictureFormats( + VADisplay dpy +); + +/** flags for subpictures */ +#define VA_SUBPICTURE_CHROMA_KEYING 0x0001 +#define VA_SUBPICTURE_GLOBAL_ALPHA 0x0002 +#define VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD 0x0004 +/** + * Query supported subpicture formats + * The caller must provide a "format_list" array that can hold at + * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag + * for each format to indicate additional capabilities for that format. The actual + * number of formats returned in "format_list" is returned in "num_formats". + * flags: returned value to indicate addtional capabilities + * VA_SUBPICTURE_CHROMA_KEYING - supports chroma-keying + * VA_SUBPICTURE_GLOBAL_ALPHA - supports global alpha + * VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD - supports unscaled screen relative subpictures for On Screen Display + */ + +VAStatus vaQuerySubpictureFormats( + VADisplay dpy, + VAImageFormat *format_list, /* out */ + unsigned int *flags, /* out */ + unsigned int *num_formats /* out */ +); + +/** + * Subpictures are created with an image associated. + */ +VAStatus vaCreateSubpicture( + VADisplay dpy, + VAImageID image, + VASubpictureID *subpicture /* out */ +); + +/** + * Destroy the subpicture before destroying the image it is assocated to + */ +VAStatus vaDestroySubpicture( + VADisplay dpy, + VASubpictureID subpicture +); + +/** + * Bind an image to the subpicture. This image will now be associated with + * the subpicture instead of the one at creation. + */ +VAStatus vaSetSubpictureImage( + VADisplay dpy, + VASubpictureID subpicture, + VAImageID image +); + +/** + * If chromakey is enabled, then the area where the source value falls within + * the chromakey [min, max] range is transparent + * The chromakey component format is the following: + * For RGB: [0:7] Red [8:15] Blue [16:23] Green + * For YUV: [0:7] V [8:15] U [16:23] Y + * The chromakey mask can be used to mask out certain components for chromakey + * comparision + */ +VAStatus vaSetSubpictureChromakey( + VADisplay dpy, + VASubpictureID subpicture, + unsigned int chromakey_min, + unsigned int chromakey_max, + unsigned int chromakey_mask +); + +/** + * Global alpha value is between 0 and 1. A value of 1 means fully opaque and + * a value of 0 means fully transparent. If per-pixel alpha is also specified then + * the overall alpha is per-pixel alpha multiplied by the global alpha + */ +VAStatus vaSetSubpictureGlobalAlpha( + VADisplay dpy, + VASubpictureID subpicture, + float global_alpha +); + +/** + * vaAssociateSubpicture associates the subpicture with target_surfaces. + * It defines the region mapping between the subpicture and the target + * surfaces through source and destination rectangles (with the same width and height). + * Both will be displayed at the next call to vaPutSurface. Additional + * associations before the call to vaPutSurface simply overrides the association. + */ +VAStatus vaAssociateSubpicture( + VADisplay dpy, + VASubpictureID subpicture, + VASurfaceID *target_surfaces, + int num_surfaces, + int16_t src_x, /* upper left offset in subpicture */ + int16_t src_y, + uint16_t src_width, + uint16_t src_height, + int16_t dest_x, /* upper left offset in surface */ + int16_t dest_y, + uint16_t dest_width, + uint16_t dest_height, + /* + * whether to enable chroma-keying, global-alpha, or screen relative mode + * see VA_SUBPICTURE_XXX values + */ + uint32_t flags +); + +/** + * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces. + */ +VAStatus vaDeassociateSubpicture( + VADisplay dpy, + VASubpictureID subpicture, + VASurfaceID *target_surfaces, + int num_surfaces +); + +/** + * Display attributes + * Display attributes are used to control things such as contrast, hue, saturation, + * brightness etc. in the rendering process. The application can query what + * attributes are supported by the driver, and then set the appropriate attributes + * before calling vaPutSurface() + * + * Display attributes can also be used to query/set platform or display adaptor (vaDisplay) + * related information. These attributes do not depend on vaConfig, and could not be used + * for vaPutSurface. Application can use vaQueryDisplayAttributes/vaGetDisplayAttributes + * at anytime after vaInitialize, but (for settable attributes) vaSetDisplayAttributes should be + * called after vaInitialize and before any other function call. + * + * To distinguish these two types of display attributes, display adaptor related attributes + * should be marked as "HW attribute" in the description. + */ + +/* PowerVR IEP Lite attributes */ +typedef enum { + VADISPLAYATTRIB_BLE_OFF = 0x00, + VADISPLAYATTRIB_BLE_LOW, + VADISPLAYATTRIB_BLE_MEDIUM, + VADISPLAYATTRIB_BLE_HIGH, + VADISPLAYATTRIB_BLE_NONE, +} VADisplayAttribBLEMode; + +/** attribute value for VADisplayAttribRotation */ +#define VA_ROTATION_NONE 0x00000000 +#define VA_ROTATION_90 0x00000001 +#define VA_ROTATION_180 0x00000002 +#define VA_ROTATION_270 0x00000003 +/**@}*/ + +/** + * @name Mirroring directions + * + * Those values could be used for VADisplayAttribMirror attribute or + * VAProcPipelineParameterBuffer::mirror_state. + + */ +/**@{*/ +/** \brief No Mirroring. */ +#define VA_MIRROR_NONE 0x00000000 +/** \brief Horizontal Mirroring. */ +#define VA_MIRROR_HORIZONTAL 0x00000001 +/** \brief Vertical Mirroring. */ +#define VA_MIRROR_VERTICAL 0x00000002 +/**@}*/ + +/** attribute value for VADisplayAttribOutOfLoopDeblock */ +#define VA_OOL_DEBLOCKING_FALSE 0x00000000 +#define VA_OOL_DEBLOCKING_TRUE 0x00000001 + +/** Render mode */ +#define VA_RENDER_MODE_UNDEFINED 0 +#define VA_RENDER_MODE_LOCAL_OVERLAY 1 +#define VA_RENDER_MODE_LOCAL_GPU 2 +#define VA_RENDER_MODE_EXTERNAL_OVERLAY 4 +#define VA_RENDER_MODE_EXTERNAL_GPU 8 + +/** Render device */ +#define VA_RENDER_DEVICE_UNDEFINED 0 +#define VA_RENDER_DEVICE_LOCAL 1 +#define VA_RENDER_DEVICE_EXTERNAL 2 + +/**\brief sub device info + * Sub-device is the concept basing on the "device" behind "vaDisplay". + * If a device could be divided to several sub devices, the task of + * decode/encode/vpp could be assigned on one sub-device. So, application + * could choose the sub device before any other operations. After that, + * all of the task execution/resource allocation will be dispatched to + * the sub device. If application does not choose the sub device, driver + * will assign one as default. + * + * If the value == VA_ATTRIB_NOT_SUPPORTED, it mean that the attribute + * is unsupport or UNKNOWN. + */ + +typedef union _VADisplayAttribValSubDevice { + struct { + /** \brief current sub device index, read - write */ + uint32_t current_sub_device : 4; + /** \brief sub devices count, read - only */ + uint32_t sub_device_count : 4; + /** \brief reserved bits for future, must be zero*/ + uint32_t reserved : 8; + /** \brief bit mask to indicate which sub_device is available, read only + * \code + * VADisplayAttribValSubDevice reg; + * VADisplayAttribute reg_attr; + * reg_attr.type = VADisplayAttribSubDevice; + * vaGetDisplayAttributes(dpy, ®_attr, 1); + * reg.value = reg_attr.value; + * + * for(int i = 0; i < reg.bits.sub_device_count; i ++ ){ + * if((1< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _VA_H_ */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_av1.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_av1.h new file mode 100644 index 00000000..c1955385 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_av1.h @@ -0,0 +1,695 @@ +/* + * Copyright (c) 2019 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_dec_av1.h + * \brief The AV1 decoding API + * + * This file contains the \ref api_dec_av1 "AV1 decoding API". + */ + +#ifndef VA_DEC_AV1_H +#define VA_DEC_AV1_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_dec_av1 AV1 decoding API + * + * This AV1 decoding API supports 8-bit/10bit 420 format only. + * + * @{ + */ + +/** Attribute value for VAConfigAttribDecAV1Features. + * + * This attribute decribes the supported features of a AV1 + * decoder configuration. + * + */ +typedef union VAConfigAttribValDecAV1Features { + struct { + /** large scale tile + * + * This conveys whether AV1 large scale tile is supported by HW. + * 0 - unsupported, 1 - supported. + */ + uint32_t lst_support : 2; + /* Reserved for future use. */ + uint32_t reserved : 30; + } bits; + uint32_t value; +} VAConfigAttribValDecAV1Features; + +/** + * \brief AV1 Decoding Picture Parameter Buffer Structure + * + * This structure conveys picture level parameters. + * App should send a surface with this data structure down to VAAPI once + * per frame. + * + */ + +/** \brief Segmentation Information + */ +typedef struct _VASegmentationStructAV1 { + union { + struct { + /** Indicates whether segmentation map related syntax elements + * are present or not for current frame. If equal to 0, + * the segmentation map related syntax elements are + * not present for the current frame and the control flags of + * segmentation map related tables feature_data[][], and + * feature_mask[] are not valid and shall be ignored by accelerator. + */ + uint32_t enabled : 1; + /** Value 1 indicates that the segmentation map are updated + * during the decoding of this frame. + * Value 0 means that the segmentation map from the previous + * frame is used. + */ + uint32_t update_map : 1; + /** Value 1 indicates that the updates to the segmentation map + * are coded relative to the existing segmentation map. + * Value 0 indicates that the new segmentation map is coded + * without reference to the existing segmentation map. + */ + uint32_t temporal_update : 1; + /** Value 1 indicates that new parameters are about to be + * specified for each segment. + * Value 0 indicates that the segmentation parameters + * should keep their existing values. + */ + uint32_t update_data : 1; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved : 28; + } bits; + uint32_t value; + } segment_info_fields; + + /** \brief Segmentation parameters for current frame. + * feature_data[segment_id][feature_id] + * where segment_id has value range [0..7] indicating the segment id. + * and feature_id is defined as + typedef enum { + SEG_LVL_ALT_Q, // Use alternate Quantizer .... + SEG_LVL_ALT_LF_Y_V, // Use alternate loop filter value on y plane vertical + SEG_LVL_ALT_LF_Y_H, // Use alternate loop filter value on y plane horizontal + SEG_LVL_ALT_LF_U, // Use alternate loop filter value on u plane + SEG_LVL_ALT_LF_V, // Use alternate loop filter value on v plane + SEG_LVL_REF_FRAME, // Optional Segment reference frame + SEG_LVL_SKIP, // Optional Segment (0,0) + skip mode + SEG_LVL_GLOBALMV, + SEG_LVL_MAX + } SEG_LVL_FEATURES; + * feature_data[][] is equivalent to variable FeatureData[][] in spec, + * which is after clip3() operation. + * Clip3(x, y, z) = (z < x)? x : ((z > y)? y : z); + * The limit is defined in Segmentation_Feature_Max[ SEG_LVL_MAX ] = { + * 255, MAX_LOOP_FILTER, MAX_LOOP_FILTER, MAX_LOOP_FILTER, MAX_LOOP_FILTER, 7, 0, 0 } + */ + int16_t feature_data[8][8]; + + /** \brief indicates if a feature is enabled or not. + * Each bit field itself is the feature_id. Index is segment_id. + * feature_mask[segment_id] & (1 << feature_id) equal to 1 specify that the feature of + * feature_id for segment of segment_id is enabled, otherwise disabled. + */ + uint8_t feature_mask[8]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; + +} VASegmentationStructAV1; + +/** \brief Film Grain Information + */ +typedef struct _VAFilmGrainStructAV1 { + union { + struct { + /** \brief Specify whether or not film grain is applied on current frame. + * If set to 0, all the rest parameters should be set to zero + * and ignored. + */ + uint32_t apply_grain : 1; + uint32_t chroma_scaling_from_luma : 1; + uint32_t grain_scaling_minus_8 : 2; + uint32_t ar_coeff_lag : 2; + uint32_t ar_coeff_shift_minus_6 : 2; + uint32_t grain_scale_shift : 2; + uint32_t overlap_flag : 1; + uint32_t clip_to_restricted_range : 1; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved : 20; + } bits; + uint32_t value; + } film_grain_info_fields; + + uint16_t grain_seed; + /* value range [0..14] */ + uint8_t num_y_points; + uint8_t point_y_value[14]; + uint8_t point_y_scaling[14]; + /* value range [0..10] */ + uint8_t num_cb_points; + uint8_t point_cb_value[10]; + uint8_t point_cb_scaling[10]; + /* value range [0..10] */ + uint8_t num_cr_points; + uint8_t point_cr_value[10]; + uint8_t point_cr_scaling[10]; + /* value range [-128..127] */ + int8_t ar_coeffs_y[24]; + int8_t ar_coeffs_cb[25]; + int8_t ar_coeffs_cr[25]; + uint8_t cb_mult; + uint8_t cb_luma_mult; + uint16_t cb_offset; + uint8_t cr_mult; + uint8_t cr_luma_mult; + uint16_t cr_offset; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; + +} VAFilmGrainStructAV1; + +typedef enum { + /** identity transformation, 0-parameter */ + VAAV1TransformationIdentity = 0, + /** translational motion, 2-parameter */ + VAAV1TransformationTranslation = 1, + /** simplified affine with rotation + zoom only, 4-parameter */ + VAAV1TransformationRotzoom = 2, + /** affine, 6-parameter */ + VAAV1TransformationAffine = 3, + /** transformation count */ + VAAV1TransformationCount +} VAAV1TransformationType; + +typedef struct _VAWarpedMotionParamsAV1 { + + /** \brief Specify the type of warped motion */ + VAAV1TransformationType wmtype; + + /** \brief Specify warp motion parameters + * wm.wmmat[] corresponds to gm_params[][] in spec. + * Details in AV1 spec section 5.9.24 or refer to libaom code + * https://aomedia.googlesource.com/aom/+/refs/heads/master/av1/decoder/decodeframe.c + */ + int32_t wmmat[8]; + + /* valid or invalid on affine set */ + uint8_t invalid; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; + +} VAWarpedMotionParamsAV1; + +/** + * \brief AV1 Decoding Picture Parameter Buffer Structure + * + * This structure conveys picture level parameters and should be sent once + * per frame. + * + */ +typedef struct _VADecPictureParameterBufferAV1 { + /**@{*/ + + /** \brief sequence level information + */ + + /** \brief AV1 bit stream profile + */ + uint8_t profile; + + uint8_t order_hint_bits_minus_1; + + /** \brief bit depth index + * value range [0..2] + * 0 - bit depth 8; + * 1 - bit depth 10; + * 2 - bit depth 12; + */ + uint8_t bit_depth_idx; + + /** \brief corresponds to AV1 spec variable of the same name. */ + uint8_t matrix_coefficients; + + union { + struct { + uint32_t still_picture : 1; + uint32_t use_128x128_superblock : 1; + uint32_t enable_filter_intra : 1; + uint32_t enable_intra_edge_filter : 1; + + /** read_compound_tools */ + uint32_t enable_interintra_compound : 1; + uint32_t enable_masked_compound : 1; + + uint32_t enable_dual_filter : 1; + uint32_t enable_order_hint : 1; + uint32_t enable_jnt_comp : 1; + uint32_t enable_cdef : 1; + uint32_t mono_chrome : 1; + uint32_t color_range : 1; + uint32_t subsampling_x : 1; + uint32_t subsampling_y : 1; + va_deprecated uint32_t chroma_sample_position : 1; + uint32_t film_grain_params_present : 1; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved : 16; + } fields; + uint32_t value; + } seq_info_fields; + + /** \brief Picture level information + */ + + /** \brief buffer description of decoded current picture + */ + VASurfaceID current_frame; + + /** \brief display buffer of current picture + * Used for film grain applied decoded picture. + * Valid only when apply_grain equals 1. + */ + VASurfaceID current_display_picture; + + /** \brief number of anchor frames for large scale tile + * This parameter gives the number of entries of anchor_frames_list[]. + * Value range [0..128]. + */ + uint8_t anchor_frames_num; + + /** \brief anchor frame list for large scale tile + * For large scale tile applications, the anchor frames could come from + * previously decoded frames in current sequence (aka. internal), or + * from external sources. + * For external anchor frames, application should call API + * vaCreateBuffer() to generate frame buffers and populate them with + * pixel frames. And this process may happen multiple times. + * The array anchor_frames_list[] is used to register all the available + * anchor frames from both external and internal, up to the current + * frame instance. If a previously registerred anchor frame is no longer + * needed, it should be removed from the list. But it does not prevent + * applications from relacing the frame buffer with new anchor frames. + * Please note that the internal anchor frames may not still be present + * in the current DPB buffer. But if it is in the anchor_frames_list[], + * it should not be replaced with other frames or removed from memory + * until it is not shown in the list. + * This number of entries of the list is given by parameter anchor_frames_num. + */ + VASurfaceID *anchor_frames_list; + + /** \brief Picture resolution minus 1 + * Picture original resolution. If SuperRes is enabled, + * this is the upscaled resolution. + * value range [0..65535] + */ + uint16_t frame_width_minus1; + uint16_t frame_height_minus1; + + /** \brief Output frame buffer size in unit of tiles + * Valid only when large_scale_tile equals 1. + * value range [0..65535] + */ + uint16_t output_frame_width_in_tiles_minus_1; + uint16_t output_frame_height_in_tiles_minus_1; + + /** \brief Surface indices of reference frames in DPB. + * + * Contains a list of uncompressed frame buffer surface indices as references. + * Application needs to make sure all the entries point to valid frames + * except for intra frames by checking ref_frame_id[]. If missing frame + * is identified, application may choose to perform error recovery by + * pointing problematic index to an alternative frame buffer. + * Driver is not responsible to validate reference frames' id. + */ + VASurfaceID ref_frame_map[8]; + + /** \brief Reference frame indices. + * + * Contains a list of indices into ref_frame_map[8]. + * It specifies the reference frame correspondence. + * The indices of the array are defined as [LAST_FRAME – LAST_FRAME, + * LAST2_FRAME – LAST_FRAME, …, ALTREF_FRAME – LAST_FRAME], where each + * symbol is defined as: + * enum{INTRA_FRAME = 0, LAST_FRAME, LAST2_FRAME, LAST3_FRAME, GOLDEN_FRAME, + * BWDREF_FRAME, ALTREF2_FRAME, ALTREF_FRAME}; + */ + uint8_t ref_frame_idx[7]; + + /** \brief primary reference frame index + * Index into ref_frame_idx[], specifying which reference frame contains + * propagated info that should be loaded at the start of the frame. + * When value equals PRIMARY_REF_NONE (7), it indicates there is + * no primary reference frame. + * value range [0..7] + */ + uint8_t primary_ref_frame; + + uint8_t order_hint; + + VASegmentationStructAV1 seg_info; + VAFilmGrainStructAV1 film_grain_info; + + /** \brief tile structure + * When uniform_tile_spacing_flag == 1, width_in_sbs_minus_1[] and + * height_in_sbs_minus_1[] should be ignored, which will be generated + * by driver based on tile_cols and tile_rows. + */ + uint8_t tile_cols; + uint8_t tile_rows; + + /* The width/height of a tile minus 1 in units of superblocks. Though the + * maximum number of tiles is 64, since ones of the last tile are computed + * from ones of the other tiles and frame_width/height, they are not + * necessarily specified. + */ + uint16_t width_in_sbs_minus_1[63]; + uint16_t height_in_sbs_minus_1[63]; + + /** \brief number of tiles minus 1 in large scale tile list + * Same as AV1 semantic element. + * Valid only when large_scale_tiles == 1. + */ + uint16_t tile_count_minus_1; + + /* specify the tile index for context updating */ + uint16_t context_update_tile_id; + + union { + struct { + /** \brief flags for current picture + * same syntax and semantic as those in AV1 code + */ + + /** \brief Frame Type + * 0: KEY_FRAME; + * 1: INTER_FRAME; + * 2: INTRA_ONLY_FRAME; + * 3: SWITCH_FRAME + * For SWITCH_FRAME, application shall set error_resilient_mode = 1, + * refresh_frame_flags, etc. appropriately. And driver will convert it + * to INTER_FRAME. + */ + uint32_t frame_type : 2; + uint32_t show_frame : 1; + uint32_t showable_frame : 1; + uint32_t error_resilient_mode : 1; + uint32_t disable_cdf_update : 1; + uint32_t allow_screen_content_tools : 1; + uint32_t force_integer_mv : 1; + uint32_t allow_intrabc : 1; + uint32_t use_superres : 1; + uint32_t allow_high_precision_mv : 1; + uint32_t is_motion_mode_switchable : 1; + uint32_t use_ref_frame_mvs : 1; + /* disable_frame_end_update_cdf is coded as refresh_frame_context. */ + uint32_t disable_frame_end_update_cdf : 1; + uint32_t uniform_tile_spacing_flag : 1; + uint32_t allow_warped_motion : 1; + /** \brief indicate if current frame in large scale tile mode */ + uint32_t large_scale_tile : 1; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved : 15; + } bits; + uint32_t value; + } pic_info_fields; + + /** \brief Supper resolution scale denominator. + * When use_superres=1, superres_scale_denominator must be in the range [9..16]. + * When use_superres=0, superres_scale_denominator must be 8. + */ + uint8_t superres_scale_denominator; + + /** \brief Interpolation filter. + * value range [0..4] + */ + uint8_t interp_filter; + + /** \brief luma loop filter levels. + * value range [0..63]. + */ + uint8_t filter_level[2]; + + /** \brief chroma loop filter levels. + * value range [0..63]. + */ + uint8_t filter_level_u; + uint8_t filter_level_v; + + union { + struct { + /** \brief flags for reference pictures + * same syntax and semantic as those in AV1 code + */ + uint8_t sharpness_level : 3; + uint8_t mode_ref_delta_enabled : 1; + uint8_t mode_ref_delta_update : 1; + + /** \brief Reserved bytes for future use, must be zero */ + uint8_t reserved : 3; + } bits; + uint8_t value; + } loop_filter_info_fields; + + /** \brief The adjustment needed for the filter level based on + * the chosen reference frame. + * value range [-64..63]. + */ + int8_t ref_deltas[8]; + + /** \brief The adjustment needed for the filter level based on + * the chosen mode. + * value range [-64..63]. + */ + int8_t mode_deltas[2]; + + /** \brief quantization + */ + /** \brief Y AC index + * value range [0..255] + */ + uint8_t base_qindex; + /** \brief Y DC delta from Y AC + * value range [-64..63] + */ + int8_t y_dc_delta_q; + /** \brief U DC delta from Y AC + * value range [-64..63] + */ + int8_t u_dc_delta_q; + /** \brief U AC delta from Y AC + * value range [-64..63] + */ + int8_t u_ac_delta_q; + /** \brief V DC delta from Y AC + * value range [-64..63] + */ + int8_t v_dc_delta_q; + /** \brief V AC delta from Y AC + * value range [-64..63] + */ + int8_t v_ac_delta_q; + + /** \brief quantization_matrix + */ + union { + struct { + uint16_t using_qmatrix : 1; + /** \brief qm level + * value range [0..15] + * Invalid if using_qmatrix equals 0. + */ + uint16_t qm_y : 4; + uint16_t qm_u : 4; + uint16_t qm_v : 4; + + /** \brief Reserved bytes for future use, must be zero */ + uint16_t reserved : 3; + } bits; + uint16_t value; + } qmatrix_fields; + + union { + struct { + /** \brief delta_q parameters + */ + uint32_t delta_q_present_flag : 1; + uint32_t log2_delta_q_res : 2; + + /** \brief delta_lf parameters + */ + uint32_t delta_lf_present_flag : 1; + uint32_t log2_delta_lf_res : 2; + + /** \brief CONFIG_LOOPFILTER_LEVEL + */ + uint32_t delta_lf_multi : 1; + + /** \brief read_tx_mode + * value range [0..2] + */ + uint32_t tx_mode : 2; + + /* AV1 frame reference mode semantic */ + uint32_t reference_select : 1; + + uint32_t reduced_tx_set_used : 1; + + uint32_t skip_mode_present : 1; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved : 20; + } bits; + uint32_t value; + } mode_control_fields; + + /** \brief CDEF parameters + */ + /* value range [0..3] */ + uint8_t cdef_damping_minus_3; + /* value range [0..3] */ + uint8_t cdef_bits; + + /** Encode cdef strength: + * + * The cdef_y_strengths[] and cdef_uv_strengths[] are expected to be packed + * with both primary and secondary strength. The secondary strength is + * given in the lower two bits and the primary strength is given in the next + * four bits. + * + * cdef_y_strengths[] & cdef_uv_strengths[] should be derived as: + * (cdef_y_strengths[]) = (cdef_y_pri_strength[] << 2) | (cdef_y_sec_strength[] & 0x03) + * (cdef_uv_strengths[]) = (cdef_uv_pri_strength[] << 2) | (cdef_uv_sec_strength[] & 0x03) + * In which, cdef_y_pri_strength[]/cdef_y_sec_strength[]/cdef_uv_pri_strength[]/cdef_uv_sec_strength[] + * are variables defined in AV1 Spec 5.9.19. The cdef_y_strengths[] & cdef_uv_strengths[] + * are corresponding to LIBAOM variables cm->cdef_strengths[] & cm->cdef_uv_strengths[] respectively. + */ + /* value range [0..63] */ + uint8_t cdef_y_strengths[8]; + /* value range [0..63] */ + uint8_t cdef_uv_strengths[8]; + + /** \brief loop restoration parameters + */ + union { + struct { + uint16_t yframe_restoration_type : 2; + uint16_t cbframe_restoration_type : 2; + uint16_t crframe_restoration_type : 2; + uint16_t lr_unit_shift : 2; + uint16_t lr_uv_shift : 1; + + /** \brief Reserved bytes for future use, must be zero */ + uint16_t reserved : 7; + } bits; + uint16_t value; + } loop_restoration_fields; + + /** \brief global motion + */ + VAWarpedMotionParamsAV1 wm[7]; + + /**@}*/ + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM]; +} VADecPictureParameterBufferAV1; + + +/** + * \brief AV1 Slice Parameter Buffer Structure + * + * This structure conveys parameters related to bit stream data and should be + * sent once per tile. + * + * It uses the name VASliceParameterBufferAV1 to be consistent with other codec, + * but actually means VATileParameterBufferAV1. + * + * Slice data buffer of VASliceDataBufferType is used + * to send the bitstream. + * + * Please note that host decoder is responsible to parse out the + * per tile information. And the bit stream in sent to driver in per + * tile granularity. + */ +typedef struct _VASliceParameterBufferAV1 { + /**@{*/ + /** \brief The byte count of current tile in the bitstream buffer, + * starting from first byte of the buffer. + * It uses the name slice_data_size to be consistent with other codec, + * but actually means tile_data_size. + */ + uint32_t slice_data_size; + /** + * offset to the first byte of the data buffer. + */ + uint32_t slice_data_offset; + /** + * see VA_SLICE_DATA_FLAG_XXX definitions + */ + uint32_t slice_data_flag; + + uint16_t tile_row; + uint16_t tile_column; + + va_deprecated uint16_t tg_start; + va_deprecated uint16_t tg_end; + /** \brief anchor frame index for large scale tile. + * index into an array AnchorFrames of the frames that the tile uses + * for prediction. + * valid only when large_scale_tile equals 1. + */ + uint8_t anchor_frame_idx; + + /** \brief tile index in the tile list. + * Valid only when large_scale_tile is enabled. + * Driver uses this field to decide the tile output location. + */ + uint16_t tile_idx_in_tile_list; + + /**@}*/ + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VASliceParameterBufferAV1; + + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_DEC_AV1_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_hevc.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_hevc.h new file mode 100644 index 00000000..eef05307 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_hevc.h @@ -0,0 +1,616 @@ +/* + * Copyright (c) 2014 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_dec_hevc.h + * \brief The HEVC decoding API + * + * This file contains the \ref api_dec_hevc "HEVC decoding API". + */ + +#ifndef VA_DEC_HEVC_H +#define VA_DEC_HEVC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_dec_hevc HEVC decoding API + * + * This HEVC decoding API supports Main and Main Still Picture profiles. + * And it supports both short slice format and long slice format. + * + * @{ + */ + +/** + * \brief HEVC Decoding Picture Parameter Buffer Structure + * + * This structure conveys picture level parameters and should be sent once + * per frame. + * + */ +typedef struct _VAPictureParameterBufferHEVC { + /** \brief buffer description of decoded current picture + * only VA_PICTURE_HEVC_FIELD_PIC and VA_PICTURE_HEVC_BOTTOM_FIELD + * of "flags" fields are meaningful. + */ + VAPictureHEVC CurrPic; + /** \brief buffer description of reference frames in DPB */ + VAPictureHEVC ReferenceFrames[15]; + /** \brief picture width, shall be integer multiple of minimum CB size. */ + uint16_t pic_width_in_luma_samples; + /** \brief picture height, shall be integer multiple of minimum CB size. */ + uint16_t pic_height_in_luma_samples; + + + union { + struct { + /** following flags have same syntax and semantic as those in HEVC spec */ + uint32_t chroma_format_idc : 2; + uint32_t separate_colour_plane_flag : 1; + uint32_t pcm_enabled_flag : 1; + uint32_t scaling_list_enabled_flag : 1; + uint32_t transform_skip_enabled_flag : 1; + uint32_t amp_enabled_flag : 1; + uint32_t strong_intra_smoothing_enabled_flag : 1; + uint32_t sign_data_hiding_enabled_flag : 1; + uint32_t constrained_intra_pred_flag : 1; + uint32_t cu_qp_delta_enabled_flag : 1; + uint32_t weighted_pred_flag : 1; + uint32_t weighted_bipred_flag : 1; + uint32_t transquant_bypass_enabled_flag : 1; + uint32_t tiles_enabled_flag : 1; + uint32_t entropy_coding_sync_enabled_flag : 1; + uint32_t pps_loop_filter_across_slices_enabled_flag : 1; + uint32_t loop_filter_across_tiles_enabled_flag : 1; + uint32_t pcm_loop_filter_disabled_flag : 1; + /** set based on sps_max_num_reorder_pics of current temporal layer. */ + uint32_t NoPicReorderingFlag : 1; + /** picture has no B slices */ + uint32_t NoBiPredFlag : 1; + + uint32_t ReservedBits : 11; + } bits; + uint32_t value; + } pic_fields; + + /** following parameters have same syntax with those in HEVC spec */ + /** \brief DPB size for current temporal layer */ + uint8_t sps_max_dec_pic_buffering_minus1; + uint8_t bit_depth_luma_minus8; + uint8_t bit_depth_chroma_minus8; + uint8_t pcm_sample_bit_depth_luma_minus1; + uint8_t pcm_sample_bit_depth_chroma_minus1; + uint8_t log2_min_luma_coding_block_size_minus3; + uint8_t log2_diff_max_min_luma_coding_block_size; + uint8_t log2_min_transform_block_size_minus2; + uint8_t log2_diff_max_min_transform_block_size; + uint8_t log2_min_pcm_luma_coding_block_size_minus3; + uint8_t log2_diff_max_min_pcm_luma_coding_block_size; + uint8_t max_transform_hierarchy_depth_intra; + uint8_t max_transform_hierarchy_depth_inter; + int8_t init_qp_minus26; + uint8_t diff_cu_qp_delta_depth; + int8_t pps_cb_qp_offset; + int8_t pps_cr_qp_offset; + uint8_t log2_parallel_merge_level_minus2; + uint8_t num_tile_columns_minus1; + uint8_t num_tile_rows_minus1; + /** + * when uniform_spacing_flag equals 1, application should populate + * column_width_minus[], and row_height_minus1[] with approperiate values. + */ + uint16_t column_width_minus1[19]; + uint16_t row_height_minus1[21]; + + /** + * The Following Parameters are needed for Short Slice Format Only. + * Only format decoding can ignore them. + */ + + /** + * \brief Parameters needed for parsing slice segment headers + */ + union { + struct { + /** following parameters have same syntax with those in HEVC spec */ + uint32_t lists_modification_present_flag : 1; + uint32_t long_term_ref_pics_present_flag : 1; + uint32_t sps_temporal_mvp_enabled_flag : 1; + uint32_t cabac_init_present_flag : 1; + uint32_t output_flag_present_flag : 1; + uint32_t dependent_slice_segments_enabled_flag : 1; + uint32_t pps_slice_chroma_qp_offsets_present_flag : 1; + uint32_t sample_adaptive_offset_enabled_flag : 1; + uint32_t deblocking_filter_override_enabled_flag : 1; + uint32_t pps_disable_deblocking_filter_flag : 1; + uint32_t slice_segment_header_extension_present_flag : 1; + + /** current picture with NUT between 16 and 21 inclusive */ + uint32_t RapPicFlag : 1; + /** current picture with NUT between 19 and 20 inclusive */ + uint32_t IdrPicFlag : 1; + /** current picture has only intra slices */ + uint32_t IntraPicFlag : 1; + + uint32_t ReservedBits : 18; + } bits; + uint32_t value; + } slice_parsing_fields; + + /** following parameters have same syntax with those in HEVC spec */ + uint8_t log2_max_pic_order_cnt_lsb_minus4; + uint8_t num_short_term_ref_pic_sets; + uint8_t num_long_term_ref_pic_sps; + uint8_t num_ref_idx_l0_default_active_minus1; + uint8_t num_ref_idx_l1_default_active_minus1; + int8_t pps_beta_offset_div2; + int8_t pps_tc_offset_div2; + uint8_t num_extra_slice_header_bits; + + /** + * \brief number of bits that structure + * short_term_ref_pic_set( num_short_term_ref_pic_sets ) takes in slice + * segment header when short_term_ref_pic_set_sps_flag equals 0. + * if short_term_ref_pic_set_sps_flag equals 1, the value should be 0. + * the bit count is calculated after emulation prevention bytes are removed + * from bit streams. + * This variable is used for accelorater to skip parsing the + * short_term_ref_pic_set( num_short_term_ref_pic_sets ) structure. + */ + uint32_t st_rps_bits; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM]; +} VAPictureParameterBufferHEVC; + +/** + * \brief HEVC Decoding Picture Parameter Buffer Structure for Range Extension + * + * This structure conveys picture level HEVC Range Extension parameters + * and should be sent once per frame. This data structure should be sent + * together with VAPictureParameterBufferHEVC in a single buffer of + * \ref VAPictureParameterBufferHEVCExtension since each frame + * of HEVC range extension contains both picture level parameters and picture + * level range extension parameters. They should be parsed together. The buffer + * type is same as \ref VAPictureParameterBufferHEVC. + * + */ +typedef struct _VAPictureParameterBufferHEVCRext { + union { + struct { + /** \brief HEVC range extension flags + * The following flags bears the same syntax and semantics as + * those defined in HEVC bit stream spec. + */ + uint32_t transform_skip_rotation_enabled_flag : 1; + uint32_t transform_skip_context_enabled_flag : 1; + uint32_t implicit_rdpcm_enabled_flag : 1; + uint32_t explicit_rdpcm_enabled_flag : 1; + uint32_t extended_precision_processing_flag : 1; + uint32_t intra_smoothing_disabled_flag : 1; + uint32_t high_precision_offsets_enabled_flag : 1; + uint32_t persistent_rice_adaptation_enabled_flag : 1; + uint32_t cabac_bypass_alignment_enabled_flag : 1; + uint32_t cross_component_prediction_enabled_flag : 1; + uint32_t chroma_qp_offset_list_enabled_flag : 1; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved : 21; + } bits; + uint32_t value; + } range_extension_pic_fields; + + /** \brief HEVC range extension flags + * The following flags bears the same syntax and semantics as + * those defined in HEVC bit stream spec. + */ + uint8_t diff_cu_chroma_qp_offset_depth; + uint8_t chroma_qp_offset_list_len_minus1; + uint8_t log2_sao_offset_scale_luma; + uint8_t log2_sao_offset_scale_chroma; + uint8_t log2_max_transform_skip_block_size_minus2; + int8_t cb_qp_offset_list[6]; + int8_t cr_qp_offset_list[6]; +} VAPictureParameterBufferHEVCRext; + +/** + *\brief HEVC Decoding Picture Parameter Buffer Structure for + *Screen Content extension + * + *This structure conveys picture level HEVC Scc parameters + *and should be sent once per frame. This data structure should be sent + *together with VAPictureParameterBufferHEVC and VAPictureParameterBufferHEVCRext + *in a single buffer of \ref VAPictureParameterBufferHEVCExtension since each + *frame of HEVC SCC contains picture level parameters, picture level range + *extension parameters and picture level Scc parameters. They should be parsed + *together and the buffer type is same as \ref VAPictureParameterBufferHEVC. + * + */ +typedef struct _VAPictureParameterBufferHEVCScc { + union { + struct { + /** \brief HEVC Scc extension flags + * The following flags bears the same syntax and semantics as + * those defined in HEVC bit stream spec. + */ + /* indicates if intra block copy (IBC) is enabled or not. */ + uint32_t pps_curr_pic_ref_enabled_flag : 1; + /* indicates if Palette Mode is enabled or not. */ + uint32_t palette_mode_enabled_flag : 1; + /* controls the presence and inference of the use_integer_mv_flag syntax + * in slice segment header that specifies the resolution of motion + * vectors for inter prediction. + */ + uint32_t motion_vector_resolution_control_idc : 2; + /* specifies that the intra boundary filtering process is + * disabled or not for intra prediction. + */ + uint32_t intra_boundary_filtering_disabled_flag : 1; + /* specifies that an adaptive colour transform may be applied + * to the residual in the decoding process. + */ + uint32_t residual_adaptive_colour_transform_enabled_flag : 1; + + /* specifies that slice_act_y_qp_offset, slice_act_cb_qp_offset, + * slice_act_cr_qp_offset are present in the slice header + */ + uint32_t pps_slice_act_qp_offsets_present_flag : 1; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved : 25; + } bits; + uint32_t value; + } screen_content_pic_fields; + + /* specifies the maximum allowed palette size. */ + uint8_t palette_max_size; + /* Correspond to HEVC syntax elements of the same names. + * It specifies the difference between the maximum allowed palette + * predictor size and the maximum allowed palette size. + * App needs to enforce that the variable PaletteMaxPredictorSize, + * which is derived as follows: + * PaletteMaxPredictorSize = palette_max_size + delta_palette_max_predictor_size + * should have a value range of [0..128]. + */ + uint8_t delta_palette_max_predictor_size; + /** \brief Size of initial palette predictor. + * It is derived from pps_num_palette_predictor_initializer or + * sps_num_palette_predictor_initializer_minus1. + * Details in HEVC SCC spec section 9.3.2.3. + */ + uint8_t predictor_palette_size; + /** \brief Palette predictor initializer. + * It is derived from pps_palette_predictor_initializers[][] + * or sps_palette_predictor_initializers[][]. + * Details in HEVC SCC spec section 9.3.2.3. + */ + uint16_t predictor_palette_entries[3][128]; + /* are used to determine the offsets that are applied to the + * quantization parameter values for the luma, Cb and Cr + * components, respectively. + */ + int8_t pps_act_y_qp_offset_plus5; + int8_t pps_act_cb_qp_offset_plus5; + int8_t pps_act_cr_qp_offset_plus3; +} VAPictureParameterBufferHEVCScc; + +/** + * \brief HEVC Decoding Picture Parameter Buffer Structure including Extensions + * + * This structure conveys picture level HEVC parameters including basic version 1 + * and range extension and screen content extension. + * The data buffer should be sent once per frame. + * + */ +typedef struct _VAPictureParameterBufferHEVCExtension { + /** \brief basic HEVC picture parameters data structure + */ + VAPictureParameterBufferHEVC base; + + /** \brief HEVC range extension picture parameters data structure + */ + VAPictureParameterBufferHEVCRext rext; + + /** \brief HEVC screen content picture parameters data structure + */ + VAPictureParameterBufferHEVCScc scc; +} VAPictureParameterBufferHEVCExtension; + +/** + * \brief HEVC Slice Parameter Buffer Structure For Long Format + * + * VASliceParameterBufferHEVC structure should be accompanied by a + * slice data buffer, which holds the whole raw slice NAL unit bit streams + * including start code prefix and emulation prevention bytes not removed. + * + * This structure conveys parameters related to slice segment header and should + * be sent once per slice. + * + * For short format, this data structure is not sent by application. + * + */ +typedef struct _VASliceParameterBufferHEVC { + /** @name Codec-independent Slice Parameter Buffer base. */ + + /**@{*/ + + /** \brief Number of bytes in the slice data buffer for this slice + * counting from and including NAL unit header. + */ + uint32_t slice_data_size; + /** \brief The offset to the NAL unit header for this slice */ + uint32_t slice_data_offset; + /** \brief Slice data buffer flags. See \c VA_SLICE_DATA_FLAG_XXX. */ + uint32_t slice_data_flag; + /** + * \brief Byte offset from NAL unit header to the begining of slice_data(). + * + * This byte offset is relative to and includes the NAL unit header + * and represents the number of bytes parsed in the slice_header() + * after the removal of any emulation prevention bytes in + * there. However, the slice data buffer passed to the hardware is + * the original bitstream, thus including any emulation prevention + * bytes. + */ + uint32_t slice_data_byte_offset; + /** HEVC syntax element. */ + uint32_t slice_segment_address; + /** \brief index into ReferenceFrames[] + * RefPicList[0][] corresponds to RefPicList0[] of HEVC variable. + * RefPicList[1][] corresponds to RefPicList1[] of HEVC variable. + * value range [0..14, 0xFF], where 0xFF indicates invalid entry. + */ + uint8_t RefPicList[2][15]; + union { + uint32_t value; + struct { + /** current slice is last slice of picture. */ + uint32_t LastSliceOfPic : 1; + /** HEVC syntax element. */ + uint32_t dependent_slice_segment_flag : 1; + /** HEVC syntax element. */ + uint32_t slice_type : 2; + /** HEVC syntax element. */ + uint32_t color_plane_id : 2; + /** HEVC syntax element. */ + uint32_t slice_sao_luma_flag : 1; + /** HEVC syntax element. */ + uint32_t slice_sao_chroma_flag : 1; + /** HEVC syntax element. */ + uint32_t mvd_l1_zero_flag : 1; + /** HEVC syntax element. */ + uint32_t cabac_init_flag : 1; + /** HEVC syntax element. */ + uint32_t slice_temporal_mvp_enabled_flag : 1; + /** HEVC syntax element. */ + uint32_t slice_deblocking_filter_disabled_flag : 1; + /** HEVC syntax element. */ + uint32_t collocated_from_l0_flag : 1; + /** HEVC syntax element. */ + uint32_t slice_loop_filter_across_slices_enabled_flag : 1; + uint32_t reserved : 18; + } fields; + } LongSliceFlags; + + /** HEVC syntax element. Collocated Reference Picture Index. + * index to RefPicList[0][] or RefPicList[1][]. + * when slice_temporal_mvp_enabled_flag equals 0, it should take value 0xFF. + * value range [0..14, 0xFF]. + */ + uint8_t collocated_ref_idx; + /** HEVC syntax element. + * if num_ref_idx_active_override_flag equals 0, host decoder should + * set its value to num_ref_idx_l0_default_active_minus1. + */ + uint8_t num_ref_idx_l0_active_minus1; + /** HEVC syntax element. + * if num_ref_idx_active_override_flag equals 0, host decoder should + * set its value to num_ref_idx_l1_default_active_minus1. + */ + uint8_t num_ref_idx_l1_active_minus1; + /** HEVC syntax element. */ + int8_t slice_qp_delta; + /** HEVC syntax element. */ + int8_t slice_cb_qp_offset; + /** HEVC syntax element. */ + int8_t slice_cr_qp_offset; + /** HEVC syntax element. */ + int8_t slice_beta_offset_div2; + /** HEVC syntax element. */ + int8_t slice_tc_offset_div2; + /** HEVC syntax element. */ + uint8_t luma_log2_weight_denom; + /** HEVC syntax element. */ + int8_t delta_chroma_log2_weight_denom; + /** HEVC syntax element. */ + int8_t delta_luma_weight_l0[15]; + /** HEVC syntax element. */ + int8_t luma_offset_l0[15]; + /** HEVC syntax element. */ + int8_t delta_chroma_weight_l0[15][2]; + /** corresponds to HEVC spec variable of the same name. */ + int8_t ChromaOffsetL0[15][2]; + /** HEVC syntax element. */ + int8_t delta_luma_weight_l1[15]; + /** HEVC syntax element. */ + int8_t luma_offset_l1[15]; + /** HEVC syntax element. */ + int8_t delta_chroma_weight_l1[15][2]; + /** corresponds to HEVC spec variable of the same name. */ + int8_t ChromaOffsetL1[15][2]; + /** HEVC syntax element. */ + uint8_t five_minus_max_num_merge_cand; + /** HEVC syntax element. */ + uint16_t num_entry_point_offsets; + /** HEVC syntax element. */ + uint16_t entry_offset_to_subset_array; + /** \brief Number of emulation prevention bytes in slice header. */ + uint16_t slice_data_num_emu_prevn_bytes; + /**@}*/ + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW - 2]; +} VASliceParameterBufferHEVC; + +/** + * \brief HEVC Extented Slice Parameter Buffer Structure For Long Format + * + * This data structure contains extension profiles (range extension and screen content). + * + * VASliceParameterBufferHEVCRext structure should be accompanied by a + * slice data buffer, which holds the whole raw slice NAL unit bit streams + * including start code prefix and emulation prevention bytes not removed. + * + * This structure conveys parameters related to slice segment header and should + * be sent once per slice with VASliceParameterBufferHEVC in a single buffer of + * \ref VASliceParameterBufferHEVCExtension and the buffer type is same as \ref + * VASliceParameterBufferHEVC. + * + * For short format, this data structure is not sent by application. + * + */ +typedef struct _VASliceParameterBufferHEVCRext { + /* below four parameters are used to replace data types of the + * corresponding parameters of those in \# VASliceParameterBufferHEVC. + */ + int16_t luma_offset_l0[15]; + int16_t ChromaOffsetL0[15][2]; + int16_t luma_offset_l1[15]; + int16_t ChromaOffsetL1[15][2]; + + union { + struct { + uint32_t cu_chroma_qp_offset_enabled_flag : 1; + uint32_t use_integer_mv_flag : 1; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved : 30; + } bits; + uint32_t value; + } slice_ext_flags; + + /** \brief Screen Content Extension parameters. + * data range [-12..12] + */ + int8_t slice_act_y_qp_offset; + int8_t slice_act_cb_qp_offset; + int8_t slice_act_cr_qp_offset; +} VASliceParameterBufferHEVCRext; + +/** + * \brief HEVC Decoding Slice Parameter Buffer Structure For Long Format including Extensions + * + * This data structure contains both baseline HEVC profiles (main, main10) + * and extension profiles (range extension and screen content). + * + * VASliceParameterBufferHEVCExtension structure should be accompanied by a + * slice data buffer, which holds the whole raw slice NAL unit bit streams + * including start code prefix and emulation prevention bytes not removed. + * + * This structure conveys parameters related to slice segment header and should + * be sent once per slice. For HEVC range extension and HEVC Scc decoding, + * application should parse both basic slice parameters and extented slice + * parameters into this buffer structure and sent it. + * + * For short format, this data structure is not sent by application. + * + */ +typedef struct _VASliceParameterBufferHEVCExtension { + /** \brief baseline HEVC slice parameters data structure */ + VASliceParameterBufferHEVC base; + + /** \brief extented HEVC slice parameters data structure */ + VASliceParameterBufferHEVCRext rext; +} VASliceParameterBufferHEVCExtension; + +/** + * \brief HEVC Inverse Quantization Matrix Buffer Structure + * + * This structure is sent once per frame, + * and only when scaling_list_enabled_flag = 1. + * When sps_scaling_list_data_present_flag = 0, app still + * needs to send in this structure with default matrix values. + * + * Matrix entries are in raster scan order which follows HEVC spec. + */ +typedef struct _VAIQMatrixBufferHEVC { + /** + * \brief scaling lists, + * corresponds to same HEVC spec syntax element + * ScalingList[ i ][ MatrixID ][ j ]. + * + * \brief 4x4 scaling, + * correspongs i = 0, MatrixID is in the range of 0 to 5, + * inclusive. And j is in the range of 0 to 15, inclusive. + */ + uint8_t ScalingList4x4[6][16]; + /** + * \brief 8x8 scaling, + * correspongs i = 1, MatrixID is in the range of 0 to 5, + * inclusive. And j is in the range of 0 to 63, inclusive. + */ + uint8_t ScalingList8x8[6][64]; + /** + * \brief 16x16 scaling, + * correspongs i = 2, MatrixID is in the range of 0 to 5, + * inclusive. And j is in the range of 0 to 63, inclusive. + */ + uint8_t ScalingList16x16[6][64]; + /** + * \brief 32x32 scaling, + * correspongs i = 3, MatrixID is in the range of 0 to 1, + * inclusive. And j is in the range of 0 to 63, inclusive. + */ + uint8_t ScalingList32x32[2][64]; + /** + * \brief DC values of the 16x16 scaling lists, + * corresponds to HEVC spec syntax + * scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8 + * with sizeID = 2 and matrixID in the range of 0 to 5, inclusive. + */ + uint8_t ScalingListDC16x16[6]; + /** + * \brief DC values of the 32x32 scaling lists, + * corresponds to HEVC spec syntax + * scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8 + * with sizeID = 3 and matrixID in the range of 0 to 1, inclusive. + */ + uint8_t ScalingListDC32x32[2]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAIQMatrixBufferHEVC; + + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_DEC_HEVC_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_jpeg.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_jpeg.h new file mode 100644 index 00000000..7bb26c2b --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_jpeg.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2007-2012 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_dec_jpeg.h + * \brief The JPEG decoding API + * + * This file contains the \ref api_dec_jpeg "JPEG decoding API". + */ + +#ifndef VA_DEC_JPEG_H +#define VA_DEC_JPEG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * \defgroup api_dec_jpeg JPEG decoding API + * + * This JPEG decoding API supports Baseline profile only. + * + * @{ + */ + +/** + * \brief Picture parameter for JPEG decoding. + * + * This structure holds information from the frame header, along with + * definitions from additional segments. + */ +typedef struct _VAPictureParameterBufferJPEGBaseline { + /** \brief Picture width in pixels. */ + uint16_t picture_width; + /** \brief Picture height in pixels. */ + uint16_t picture_height; + + struct { + /** \brief Component identifier (Ci). */ + uint8_t component_id; + /** \brief Horizontal sampling factor (Hi). */ + uint8_t h_sampling_factor; + /** \brief Vertical sampling factor (Vi). */ + uint8_t v_sampling_factor; + /* \brief Quantization table selector (Tqi). */ + uint8_t quantiser_table_selector; + } components[255]; + /** \brief Number of components in frame (Nf). */ + uint8_t num_components; + + /** \brief Input color space 0: YUV, 1: RGB, 2: BGR, others: reserved */ + uint8_t color_space; + /** \brief Set to VA_ROTATION_* for a single rotation angle reported by VAConfigAttribDecJPEG. */ + uint32_t rotation; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM - 1]; +} VAPictureParameterBufferJPEGBaseline; + +/** + * \brief Quantization table for JPEG decoding. + * + * This structure holds the complete quantization tables. This is an + * aggregation of all quantization table (DQT) segments maintained by + * the application. i.e. up to 4 quantization tables are stored in + * there for baseline profile. + * + * The #load_quantization_table array can be used as a hint to notify + * the VA driver implementation about which table(s) actually changed + * since the last submission of this buffer. + * + * The #quantiser_table values are specified in zig-zag scan order. + */ +typedef struct _VAIQMatrixBufferJPEGBaseline { + /** \brief Specifies which #quantiser_table is valid. */ + uint8_t load_quantiser_table[4]; + /** \brief Quanziation tables indexed by table identifier (Tqi). */ + uint8_t quantiser_table[4][64]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAIQMatrixBufferJPEGBaseline; + +/** + * \brief Slice parameter for JPEG decoding. + * + * This structure holds information from the scan header, along with + * definitions from additional segments. The associated slice data + * buffer holds all entropy coded segments (ECS) in the scan. + */ +typedef struct _VASliceParameterBufferJPEGBaseline { + /** @name Codec-independent Slice Parameter Buffer base. */ + /**@{*/ + /** \brief Number of bytes in the slice data buffer for this slice. */ + uint32_t slice_data_size; + /** \brief The offset to the first byte of the first MCU. */ + uint32_t slice_data_offset; + /** \brief Slice data buffer flags. See \c VA_SLICE_DATA_FLAG_xxx. */ + uint32_t slice_data_flag; + /**@}*/ + + /** \brief Scan horizontal position. */ + uint32_t slice_horizontal_position; + /** \brief Scan vertical position. */ + uint32_t slice_vertical_position; + + struct { + /** \brief Scan component selector (Csj). */ + uint8_t component_selector; + /** \brief DC entropy coding table selector (Tdj). */ + uint8_t dc_table_selector; + /** \brief AC entropy coding table selector (Taj). */ + uint8_t ac_table_selector; + } components[4]; + /** \brief Number of components in scan (Ns). */ + uint8_t num_components; + + /** \brief Restart interval definition (Ri). */ + uint16_t restart_interval; + /** \brief Number of MCUs in a scan. */ + uint32_t num_mcus; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VASliceParameterBufferJPEGBaseline; + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_DEC_JPEG_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_vp8.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_vp8.h new file mode 100644 index 00000000..8004f7d3 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_dec_vp8.h @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2007-2012 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_dec_vp.h + * \brief VP8 decoding API + * + * This file contains the \ref api_dec_vp8 "VP8 decoding API". + */ + +#ifndef VA_DEC_VP8_H +#define VA_DEC_VP8_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_dec_vp8 VP8 decoding API + * + * @{ + */ + +/** + * \brief VPX Bool Coder Context structure + * + * This common structure is defined for potential sharing by other VP formats + * + */ +typedef struct _VABoolCoderContextVPX { + /* partition 0 "range" */ + uint8_t range; + /* partition 0 "value" */ + uint8_t value; + /* + * 'partition 0 number of shifts before an output byte is available' + * it is the number of remaining bits in 'value' for decoding, range [0, 7]. + */ + + uint8_t count; +} VABoolCoderContextVPX; + +/** + * \brief VP8 Decoding Picture Parameter Buffer Structure + * + * This structure conveys frame level parameters and should be sent once + * per frame. + * + */ +typedef struct _VAPictureParameterBufferVP8 { + /* frame width in pixels */ + uint32_t frame_width; + /* frame height in pixels */ + uint32_t frame_height; + + /* specifies the "last" reference frame */ + VASurfaceID last_ref_frame; + /* specifies the "golden" reference frame */ + VASurfaceID golden_ref_frame; + /* specifies the "alternate" referrence frame */ + VASurfaceID alt_ref_frame; + /* specifies the out-of-loop deblocked frame, not used currently */ + VASurfaceID out_of_loop_frame; + + union { + struct { + /* same as key_frame in bitstream syntax, 0 means a key frame */ + uint32_t key_frame : 1; + /* same as version in bitstream syntax */ + uint32_t version : 3; + /* same as segmentation_enabled in bitstream syntax */ + uint32_t segmentation_enabled : 1; + /* same as update_mb_segmentation_map in bitstream syntax */ + uint32_t update_mb_segmentation_map : 1; + /* same as update_segment_feature_data in bitstream syntax */ + uint32_t update_segment_feature_data : 1; + /* same as filter_type in bitstream syntax */ + uint32_t filter_type : 1; + /* same as sharpness_level in bitstream syntax */ + uint32_t sharpness_level : 3; + /* same as loop_filter_adj_enable in bitstream syntax */ + uint32_t loop_filter_adj_enable : 1; + /* same as mode_ref_lf_delta_update in bitstream syntax */ + uint32_t mode_ref_lf_delta_update : 1; + /* same as sign_bias_golden in bitstream syntax */ + uint32_t sign_bias_golden : 1; + /* same as sign_bias_alternate in bitstream syntax */ + uint32_t sign_bias_alternate : 1; + /* same as mb_no_coeff_skip in bitstream syntax */ + uint32_t mb_no_coeff_skip : 1; + /* flag to indicate that loop filter should be disabled */ + uint32_t loop_filter_disable : 1; + } bits; + uint32_t value; + } pic_fields; + + /* + * probabilities of the segment_id decoding tree and same as + * mb_segment_tree_probs in the spec. + */ + uint8_t mb_segment_tree_probs[3]; + + /* Post-adjustment loop filter levels for the 4 segments */ + uint8_t loop_filter_level[4]; + /* loop filter deltas for reference frame based MB level adjustment */ + int8_t loop_filter_deltas_ref_frame[4]; + /* loop filter deltas for coding mode based MB level adjustment */ + int8_t loop_filter_deltas_mode[4]; + + /* same as prob_skip_false in bitstream syntax */ + uint8_t prob_skip_false; + /* same as prob_intra in bitstream syntax */ + uint8_t prob_intra; + /* same as prob_last in bitstream syntax */ + uint8_t prob_last; + /* same as prob_gf in bitstream syntax */ + uint8_t prob_gf; + + /* + * list of 4 probabilities of the luma intra prediction mode decoding + * tree and same as y_mode_probs in frame header + */ + uint8_t y_mode_probs[4]; + /* + * list of 3 probabilities of the chroma intra prediction mode decoding + * tree and same as uv_mode_probs in frame header + */ + uint8_t uv_mode_probs[3]; + /* + * updated mv decoding probabilities and same as mv_probs in + * frame header + */ + uint8_t mv_probs[2][19]; + + VABoolCoderContextVPX bool_coder_ctx; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAPictureParameterBufferVP8; + +/** + * \brief VP8 Slice Parameter Buffer Structure + * + * This structure conveys parameters related to data partitions and should be + * sent once per frame. Slice data buffer of VASliceDataBufferType is used + * to send the partition data. + * + */ +typedef struct _VASliceParameterBufferVP8 { + /* + * number of bytes in the slice data buffer for the partitions + */ + uint32_t slice_data_size; + /* + * offset to the first byte of partition data (control partition) + */ + uint32_t slice_data_offset; + /* + * see VA_SLICE_DATA_FLAG_XXX definitions + */ + uint32_t slice_data_flag; + /* + * offset to the first bit of MB from the first byte of partition data(slice_data_offset) + */ + uint32_t macroblock_offset; + + /* + * Partitions + * (1<lvl[seg][ref][mode] in VP9 code, + * where m is [ref], and n is [mode] in FilterLevel[m][n]. + */ + uint8_t filter_level[4][2]; + /** \brief Specifies per segment Luma AC quantization scale. + * Corresponding to y_dequant[qindex][1] in vp9_mb_init_quantizer() + * function of VP9 code. + */ + int16_t luma_ac_quant_scale; + /** \brief Specifies per segment Luma DC quantization scale. + * Corresponding to y_dequant[qindex][0] in vp9_mb_init_quantizer() + * function of VP9 code. + */ + int16_t luma_dc_quant_scale; + /** \brief Specifies per segment Chroma AC quantization scale. + * Corresponding to uv_dequant[qindex][1] in vp9_mb_init_quantizer() + * function of VP9 code. + */ + int16_t chroma_ac_quant_scale; + /** \brief Specifies per segment Chroma DC quantization scale. + * Corresponding to uv_dequant[qindex][0] in vp9_mb_init_quantizer() + * function of VP9 code. + */ + int16_t chroma_dc_quant_scale; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; + +} VASegmentParameterVP9; + + + +/** + * \brief VP9 Slice Parameter Buffer Structure + * + * This structure conveys parameters related to segmentation data and should be + * sent once per frame. + * + * When segmentation is disabled, only SegParam[0] has valid values, + * all other entries should be populated with 0. + * Otherwise, all eight entries should be valid. + * + * Slice data buffer of VASliceDataBufferType is used + * to send the bitstream which should include whole or part of partition 0 + * (at least compressed header) to the end of frame. + * + */ +typedef struct _VASliceParameterBufferVP9 { + /** \brief The byte count of current frame in the bitstream buffer, + * starting from first byte of the buffer. + * It uses the name slice_data_size to be consitent with other codec, + * but actually means frame_data_size. + */ + uint32_t slice_data_size; + /** + * offset to the first byte of partition data (control partition) + */ + uint32_t slice_data_offset; + /** + * see VA_SLICE_DATA_FLAG_XXX definitions + */ + uint32_t slice_data_flag; + + /** + * \brief per segment information + */ + VASegmentParameterVP9 seg_param[8]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; + +} VASliceParameterBufferVP9; + + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_DEC_VP9_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_drm.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_drm.h new file mode 100644 index 00000000..a39c5a2e --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_drm.h @@ -0,0 +1,61 @@ +/* + * va_drm.h - Raw DRM API + * + * Copyright (c) 2012 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef VA_DRM_H +#define VA_DRM_H + +#include + +/** + * \file va_drm.h + * \brief The raw DRM API + * + * This file contains the \ref api_drm "Raw DRM API". + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief Returns a VA display derived from the specified DRM connection. + * + * This function returns a (possibly cached) VA display from the + * specified DRM connection @fd. + * + * @param[in] fd the DRM connection descriptor + * @return the VA display + */ +VADisplay +vaGetDisplayDRM(int fd); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_DRM_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_av1.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_av1.h new file mode 100644 index 00000000..18dd1e60 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_av1.h @@ -0,0 +1,1004 @@ +/* + * Copyright (c) 2021 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_enc_av1.h + * \brief AV1 encoding API + * + * This file contains the \ref api_enc_av1 "AV1 encoding API". + * + */ + +#ifndef VA_ENC_AV1_H +#define VA_ENC_AV1_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * \defgroup api_enc_av1 AV1 encoding API + * + * This AV1 encoding API supports 8-bit/10bit 420 format only. + * + * @{ + */ + +/** \brief Attribute value for VAConfigAttribEncAV1. + * + * This attribute decribes the supported features of an AV1 + * encoder configuration. + * + * All of the field values in this attribute are VA_FEATURE_* values, + * indicating support for the corresponding feature. + * + */ +typedef union _VAConfigAttribValEncAV1 { + struct { + /** + * \brief Use 128x128 superblock. + * + * Allows setting use_128x128_superblock in the SPS. + */ + uint32_t support_128x128_superblock : 2; + /** + * \brief Intra filter. + * Allows setting enable_filter_intra in the SPS. + */ + uint32_t support_filter_intra : 2; + /** + * \brief Intra edge filter. + * Allows setting enable_intra_edge_filter in the SPS. + */ + uint32_t support_intra_edge_filter : 2; + /** + * \brief Interintra compound. + * Allows setting enable_interintra_compound in the SPS. + */ + uint32_t support_interintra_compound : 2; + /** + * \brief Masked compound. + * Allows setting enable_masked_compound in the SPS. + */ + uint32_t support_masked_compound : 2; + /** + * \brief Warped motion. + * Allows setting enable_warped_motion in the SPS. + */ + uint32_t support_warped_motion : 2; + /** + * \brief Palette mode. + * Allows setting palette_mode in the PPS. + */ + uint32_t support_palette_mode : 2; + /** + * \brief Dual filter. + * Allows setting enable_dual_filter in the SPS. + */ + uint32_t support_dual_filter : 2; + /** + * \brief Jnt compound. + * Allows setting enable_jnt_comp in the SPS. + */ + uint32_t support_jnt_comp : 2; + /** + * \brief Refrence frame mvs. + * Allows setting enable_ref_frame_mvs in the SPS. + */ + uint32_t support_ref_frame_mvs : 2; + /** + * \brief Super resolution. + * Allows setting enable_superres in the SPS. + */ + uint32_t support_superres : 2; + /** + * \brief Restoration. + * Allows setting enable_restoration in the SPS. + */ + uint32_t support_restoration : 2; + /** + * \brief Allow intraBC. + * Allows setting allow_intrabc in the PPS. + */ + uint32_t support_allow_intrabc : 2; + /** + * \brief Cdef channel strength. + * Allows setting cdef_y_strengths and cdef_uv_strengths in PPS. + */ + uint32_t support_cdef_channel_strength : 2; + /** \brief Reserved bits for future, must be zero. */ + uint32_t reserved : 4; + } bits; + uint32_t value; +} VAConfigAttribValEncAV1; + +/** \brief Attribute value for VAConfigAttribEncAV1Ext1. */ +typedef union _VAConfigAttribValEncAV1Ext1 { + struct { + /** + * \brief Fields indicate which types of interpolation filter are supported. + * (interpolation_filter & 0x01) == 1: eight_tap filter is supported, 0: not. + * (interpolation_filter & 0x02) == 1: eight_tap_smooth filter is supported, 0: not. + * (interpolation_filter & 0x04) == 1: eight_sharp filter is supported, 0: not. + * (interpolation_filter & 0x08) == 1: bilinear filter is supported, 0: not. + * (interpolation_filter & 0x10) == 1: switchable filter is supported, 0: not. + */ + uint32_t interpolation_filter : 5; + /** + * \brief Min segmentId block size accepted. + * Application need to send seg_id_block_size in PPS equal or larger than this value. + */ + uint32_t min_segid_block_size_accepted : 8; + /** + * \brief Type of segment feature supported. + * (segment_feature_support & 0x01) == 1: SEG_LVL_ALT_Q is supported, 0: not. + * (segment_feature_support & 0x02) == 1: SEG_LVL_ALT_LF_Y_V is supported, 0: not. + * (segment_feature_support & 0x04) == 1: SEG_LVL_ALT_LF_Y_H is supported, 0: not. + * (segment_feature_support & 0x08) == 1: SEG_LVL_ALT_LF_U is supported, 0: not. + * (segment_feature_support & 0x10) == 1: SEG_LVL_ALT_LF_V is supported, 0: not. + * (segment_feature_support & 0x20) == 1: SEG_LVL_REF_FRAME is supported, 0: not. + * (segment_feature_support & 0x40) == 1: SEG_LVL_SKIP is supported, 0: not. + * (segment_feature_support & 0x80) == 1: SEG_LVL_GLOBALMV is supported, 0: not. + */ + uint32_t segment_feature_support : 8; + /** \brief Reserved bits for future, must be zero. */ + uint32_t reserved : 11; + } bits; + uint32_t value; +} VAConfigAttribValEncAV1Ext1; + +/** \brief Attribute value for VAConfigAttribEncAV1Ext2. */ +typedef union _VAConfigAttribValEncAV1Ext2 { + struct { + /** + * \brief Tile size bytes minus1. + * Specify the number of bytes needed to code tile size supported. + * This value need to be set in frame header obu. + */ + uint32_t tile_size_bytes_minus1 : 2; + /** + * \brief Tile size bytes minus1. + * Specify the fixed number of bytes needed to code syntax obu_size. + */ + uint32_t obu_size_bytes_minus1 : 2; + /** + * \brief tx_mode supported. + * (tx_mode_support & 0x01) == 1: ONLY_4X4 is supported, 0: not. + * (tx_mode_support & 0x02) == 1: TX_MODE_LARGEST is supported, 0: not. + * (tx_mode_support & 0x04) == 1: TX_MODE_SELECT is supported, 0: not. + */ + uint32_t tx_mode_support : 3; + /** + * \brief Max tile num minus1. + * Specify the max number of tile supported by driver. + */ + uint32_t max_tile_num_minus1 : 13; + /** \brief Reserved bits for future, must be zero. */ + uint32_t reserved : 12; + } bits; + uint32_t value; +} VAConfigAttribValEncAV1Ext2; + +/** + * \brief Packed header types specific to AV1 encoding. + * + * Types of packed headers generally used for AV1 encoding. + * + */ +typedef enum { + /** + * \brief Packed Sequence Parameter Set (SPS). + * + * The corresponding packed header data buffer shall contain the + * complete sequence_header_obu() syntax element. + * + */ + VAEncPackedHeaderAV1_SPS = VAEncPackedHeaderSequence, + /** + * \brief Packed Picture Parameter Set (PPS). + * + * The corresponding packed header data buffer shall contain the + * complete frame_header_obu() syntax element. + * + */ + VAEncPackedHeaderAV1_PPS = VAEncPackedHeaderPicture, +} VAEncPackedHeaderTypeAV1; + +/** + * \brief AV1 Encoding Sequence Parameter Buffer Structure. + * + * This structure conveys sequence level parameters. + * + */ +typedef struct _VAEncSequenceParameterBufferAV1 { + /** \brief AV1 profile setting. + * value range [0..2]. + */ + uint8_t seq_profile; + + /** \brief Level Setting of current operation point. + * value range [0..23]. + */ + uint8_t seq_level_idx; + + /** \brief Tier Setting of current operation point. + * value range [0..1]. + */ + uint8_t seq_tier; + + /** \brief Indicates whether or not the encoding is in dyadic hierarchical GOP structure. + * value range [0..1]. + */ + uint8_t hierarchical_flag; + + /** \brief Period between intra_only frames. */ + uint32_t intra_period; + + /** \brief Period between I/P frames. + * For hierarchical structure, this is the anchor frame distance. + */ + uint32_t ip_period; + + /* \brief RC related fields. RC modes are set with VAConfigAttribRateControl. */ + /* For AV1, CBR implies HRD conformance and VBR implies no HRD conformance. */ + + /** + * \brief Initial bitrate set for this sequence in CBR or VBR modes. + * + * This field represents the initial bitrate value for CBR mode or + * initial max bitrate value for VBR mode in this sequence. + * i.e. if the encoder pipeline was created with a #VAConfigAttribRateControl + * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR. + * + * The bitrate can be modified later on through + * #VAEncMiscParameterRateControl buffers. + */ + uint32_t bits_per_second; + + union { + struct { + /** \brief Still picture encoding, no inter frame referencing. */ + uint32_t still_picture : 1; + /** \brief Force using 128x128 or 64x64 Supper block */ + uint32_t use_128x128_superblock : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_filter_intra : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_intra_edge_filter : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_interintra_compound : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_masked_compound : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_warped_motion : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_dual_filter : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_order_hint : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_jnt_comp : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_ref_frame_mvs : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_superres : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_cdef : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t enable_restoration : 1; + /** \brief Sepcify number of bits for every channel(Y, U or V). */ + uint32_t bit_depth_minus8 : 3; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t subsampling_x : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t subsampling_y : 1; + /** \brief Reserved bytes for future use, must be zero. */ + uint32_t reserved_bits : 13; + } bits; + uint32_t value; + } seq_fields; + + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..7]. + */ + uint8_t order_hint_bits_minus_1; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_HIGH]; +} VAEncSequenceParameterBufferAV1; + +#define VA_AV1_MAX_SEGMENTS 8 +#define VA_AV1_SEG_LVL_MAX 8 + +/** + * \brief Segment parameters + */ +typedef struct _VAEncSegParamAV1 { + union { + struct { + /** \brief Indicates if segmentation is enabled in the current frame. + * If disabled, all the below parameters in the structure should + * be set to 0, and ignored by driver. + */ + uint8_t segmentation_enabled : 1; + + /** + * When segmentation_enabled equals 1 and segment_number > 0, + * this parameter equals 1 indicates the segmentation map may + * come from application, and that "Segment map data buffer" + * should be provided with populated segment_id. If equals 0, + * segmentation map should be inherited from a reference frame + * (specified by \c primary_ref_frame). When segmentation_enabled or + * segment_number equals 0, this parameter should be set to 0 + * and ignored by driver. + */ + uint8_t segmentation_update_map : 1; + /** + * When segmentation_update_map equals 1, this parameter equaling 1 + * indicates segment id per block will be determined either from + * reference frame or from app. Equaling 0 means segment id per block + * will come from app. When segmentation_temporal_update equals 0, + * this parameter should be set to 0 and ignored by driver. + */ + uint8_t segmentation_temporal_update : 1; + /** \brief Reserved bytes for future use, must be zero. */ + uint8_t reserved : 5; + + } bits; + uint8_t value; + } seg_flags; + + /** + * If segmentation_enabled equals 1, this parameter indicates + * the number of segments conveyed through VAAPI. In this case, + * if segment_number equals 0, it will force the driver to determine + * how many segments would be created as well as the segmentation map + * to be generated. Also the driver shall write the segmentation_params() + * syntax in the uncompressed header at \c bit_offset_segmentation (back-annotation). + * In application, the rest parameters in this structure should be all + * set to 0 and ignored by driver. And app should NOT send the + * "Segment map data buffer". In packed uncompressed header + * bitstream, app should write syntax element segmentation_enabled + * as 0 and segmentation_params() should be only 1-bit-long. + * If segment_number > 0, and segmentation_update_map = 1, app should provide + * the "Segment map data buffer" and populate the rest of the + * current data structure. And that underline encoder would honor + * the segmentation parameters feature_data[0..segment_number-1][] + * and feature_mask[0..segment_number-1], etc. + * Value range [0..8]. + */ + uint8_t segment_number; + + /** \brief segment parameters. + * feature_data[][] is equivalent to variable FeatureData[][] in spec, + * which is after clip3() operation. + * Clip3(x, y, z) = (z y)? y : z); + * The limit is defined in Segmentation_Feature_Max[ SEG_LVL_MAX ] = { + * 255, MAX_LOOP_FILTER, MAX_LOOP_FILTER, MAX_LOOP_FILTER, + * MAX_LOOP_FILTER, 7, 0, 0 } + */ + int16_t feature_data[VA_AV1_MAX_SEGMENTS][VA_AV1_SEG_LVL_MAX]; + + /** \brief Bit field to indicate each feature is enabled or not per + * segment_id. Each bit is the feature_id. + */ + uint8_t feature_mask[VA_AV1_MAX_SEGMENTS]; + + /** \brief Reserved bytes for future use, must be zero. */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSegParamAV1; + +/** + * \brief Segment map data buffer. + * + * This buffer is optional depending on the value of av1_segments.segmentation_enabled. + * If av1_segments.segmentation_enabled in the picture parameters equals 1, + * and RateControlMethod is not CQP and this surface is not provided by App, + * the encoder will determine the per block segmentation map. In this case, + * App should not provide the segmentation parameter data structure + * in frame header as well. If av1_segments.segmentation_enabled equals 1 + * and the segmentation map buffer is provided, app should embed the + * segmentation info in frame header, populate the VAEncSegParamAV1 structure with + * #VAEncMacroblockMapBufferType and the driver as well as the underline encoder + * should honor what is given by the app. + */ +typedef struct _VAEncSegMapBufferAV1 { + /** \brief Segment map data size. */ + uint32_t segmentMapDataSize; + + /** + * \brief Segment map. + * Size of this map is indicated by \ref segmentMapDataSize and each element + * in this map contains the segment id of a particular block. + * The element is indexed by raster scan order. + * The value of each entry should be in the range [0..7], inclusive. + */ + uint8_t *pSegmentMap; +} VAEncSegMapBufferAV1; + +typedef enum { + /** \brief Identity transformation, 0-parameter. */ + VAAV1EncTransformationIdentity = 0, + /** \brief Translational motion, 2-parameter. */ + VAAV1EncTransformationTranslation = 1, + /** \brief Simplified affine with rotation + zoom only, 4-parameter. */ + VAAV1EncTransformationRotzoom = 2, + /** \brief Affine, 6-parameter. */ + VAAV1EncTransformationAffine = 3, + /** \brief Transformation count. */ + VAAV1EncTransformationCount +} VAEncTransformationTypeAV1; + +typedef struct _VAEncWarpedMotionParamsAV1 { + + /** \brief Specify the type of warped motion. */ + VAEncTransformationTypeAV1 wmtype; + + /** \brief Specify warp motion parameters. + * wm.wmmat[] corresponds to gm_params[][] in spec. + * Details in AV1 spec section 5.9.24 or refer to libaom code + * https://aomedia.googlesource.com/aom/+/refs/heads/master/av1/decoder/decodeframe.c. + */ + int32_t wmmat[8]; + + /** \brief Valid or invalid on affine set. */ + uint8_t invalid; + + /** \brief Reserved bytes for future use, must be zero. */ + uint32_t va_reserved[VA_PADDING_LOW]; + +} VAEncWarpedMotionParamsAV1; + +/** + * \brief Reference frame control. + * + * Suggest which frame to be used as reference along with preferred search order. + * + * search_idx#: index into ref_frame_idx[] to indicate that frame will be included + * in the reference list if value in range [1..7]. Invalid when value is 0. + * The order of the search_idx# indicates the preferred search order. + * + */ +typedef union { + struct { + /** + * \brief Value used as index into ref_frame_idx[] to indicate that frame + * will be included in the reference list. + * valid value range: [1..7], invalid when value is 0. + */ + uint32_t search_idx0 : 3; + /** + * \brief Value used as index into ref_frame_idx[] to indicate that frame + * will be included in the reference list. + * valid value range: [1..7], invalid when value is 0. + */ + uint32_t search_idx1 : 3; + /** + * \brief Value used as index into ref_frame_idx[] to indicate that frame + * will be included in the reference list. + * valid value range: [1..7], invalid when value is 0. + */ + uint32_t search_idx2 : 3; + /** + * \brief Value used as index into ref_frame_idx[] to indicate that frame + * will be included in the reference list. + * valid value range: [1..7], invalid when value is 0. + */ + uint32_t search_idx3 : 3; + /** + * \brief Value used as index into ref_frame_idx[] to indicate that frame + * will be included in the reference list. + * valid value range: [1..7], invalid when value is 0. + */ + uint32_t search_idx4 : 3; + /** + * \brief Value used as index into ref_frame_idx[] to indicate that frame + * will be included in the reference list. + * valid value range: [1..7], invalid when value is 0. + */ + uint32_t search_idx5 : 3; + /** + * \brief Value used as index into ref_frame_idx[] to indicate that frame + * will be included in the reference list. + * valid value range: [1..7], invalid when value is 0. + */ + uint32_t search_idx6 : 3; + + /** \brief Reserved bytes for future use, must be zero. */ + uint32_t Reserved : 11; + } fields; + uint32_t value; +} VARefFrameCtrlAV1; + +/** + * \brief AV1 Encoding Picture Parameter Buffer Structure. + * + * This structure conveys picture level parameters. + * + */ +typedef struct _VAEncPictureParameterBufferAV1 { + /** \brief AV1 encoder may support SupRes and dynamic scaling function. + * For SupRes, underline encoder is responsible to do downscaling. + * For dynamic scaling, app should provide the scaled raw source. + */ + /** \brief Raw source frame width in pixels. */ + uint16_t frame_width_minus_1; + /** \brief Raw source frame height in pixels. */ + uint16_t frame_height_minus_1; + + /** \brief Surface to store reconstructed frame, not used for enc only case. */ + VASurfaceID reconstructed_frame; + + /** \brief Buffer to store coded data. */ + VABufferID coded_buf; + + /** \brief Reference frame buffers. + * Each entry of the array specifies the surface index of the picture + * that is referred by current picture or will be referred by any future + * picture. The valid entries take value from 0 to 127, inclusive. + * Non-valid entries, those do not point to pictures which are referred + * by current picture or future pictures, should take value 0xFF. + * Other values are not allowed. + * + * Application should update this array based on the refreshing + * information expected. + */ + VASurfaceID reference_frames[8]; + + /** \brief Reference index list. + * Contains a list of indices into refernce_frames[]. + * Indice with refernce frames range: [LAST_FRAME - LAST_FRAME, + * LAST2_FRAME - LAST_FRAME, ..., ALTREF2_FRAME - LAST_FRAME]. + * #define LAST_FRAME 1 + * #define LAST2_FRAME 2 + * #define LAST3_FRAME 3 + * #define GOLDEN_FRAME 4 + * #define BWDREF_FRAME 5 + * #define ALTREF_FRAME 6 + * #define ALTREF2_FRAME 7 + * value range [0..7]. + */ + uint8_t ref_frame_idx[7]; + + /** \brief When hierarchical_level_plus1 > 0, hierarchical_level_plus1-1 indicates + * the current frame's level. If VAEncMiscParameterTemporalLayerStructure + * is valid (number_of_layers >0), hierarchical_level_plus1 shouldn't larger than number_of_layers. + */ + uint8_t hierarchical_level_plus1; + + /** \brief primary reference frame. + * Index into reference_frames[] + * segment id map, context table, etc. come from the reference + * frame pointed by this index. + * value range [0..7]. + */ + uint8_t primary_ref_frame; + + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint8_t order_hint; + + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint8_t refresh_frame_flags; + + /** \brief Reserved bytes for future use, must be zero. */ + uint8_t reserved8bits1; + + /** \brief Suggest which frames to be used as references. + * see struct #VARefFrameCtrl for details. + */ + VARefFrameCtrlAV1 ref_frame_ctrl_l0; + VARefFrameCtrlAV1 ref_frame_ctrl_l1; + + union { + struct { + /** \brief frame type. + * 0: key_frame. + * 1: inter_frame. + * 2: intra_only frame. + * 3: switch_frame (app needs to set error_resilient_mode = 1, + * refresh_frame_flags, etc approperately.). + */ + uint32_t frame_type : 2; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t error_resilient_mode : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t disable_cdf_update : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t use_superres : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t allow_high_precision_mv : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t use_ref_frame_mvs : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t disable_frame_end_update_cdf : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t reduced_tx_set : 1; + + /** \brief For single tile group, app may choose to use one frame obu + * to replace one frame header obu + one tile group obu. + * Invalid if num_tile_groups_minus1 > 0. + */ + uint32_t enable_frame_obu : 1; + + /** \brief Indicate the current frame will be used as a long term reference. */ + uint32_t long_term_reference : 1; + /** \brief If the encoded frame will not be referred by other frames, + * its recon may not be generated in order to save memory bandwidth. + */ + uint32_t disable_frame_recon : 1; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint32_t allow_intrabc : 1; + /** \brief Equal to 1 indicates that intra blocks may use palette encoding. + * Otherwise disable palette encoding. + */ + uint32_t palette_mode_enable : 1; + /** \brief Reserved bytes for future use, must be zero. */ + uint32_t reserved : 18; + } bits; + uint32_t value; + } picture_flags; + + /** \brief Block size for each Segment ID in Segment Map. + * 0: 16x16 block size, default value; + * 1: 32x32 block size; + * 2: 64x64 block size; + * 3: 8x8 block size. + */ + uint8_t seg_id_block_size; + + /** \brief Number of tile groups minus 1. + * value range [0..255]. + */ + uint8_t num_tile_groups_minus1; + + /** \brief Temporal id of the frame.*/ + uint8_t temporal_id; + + /** \brief Deblock filter parameters. + * value range [0..63]. + */ + uint8_t filter_level[2]; + uint8_t filter_level_u; + uint8_t filter_level_v; + + union { + struct { + /** \brief Sharpness level for deblock filter. + * value range [0..7]. + */ + uint8_t sharpness_level : 3; + uint8_t mode_ref_delta_enabled : 1; + uint8_t mode_ref_delta_update : 1; + /** \brief Reserved bytes for future use, must be zero. */ + uint8_t reserved : 3; + } bits; + uint8_t value; + } loop_filter_flags; + + /** \brief Super resolution scale denominator. + * value range [9..16]. + */ + uint8_t superres_scale_denominator; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint8_t interpolation_filter; + + /** \brief Loop filter ref deltas. + * value range [-63..63]. + */ + int8_t ref_deltas[8]; + + /** \brief Loop filter mode deltas. + * value range [-63..63]. + */ + int8_t mode_deltas[2]; + + /** \brief Quantization params. */ + uint8_t base_qindex; + int8_t y_dc_delta_q; + int8_t u_dc_delta_q; + int8_t u_ac_delta_q; + int8_t v_dc_delta_q; + int8_t v_ac_delta_q; + + /** \brief Min value for base q index for BRC. + * value range [1..255]. + */ + uint8_t min_base_qindex; + + /** \brief Max value for base q index for BRC. + * value range [1..255]. + */ + uint8_t max_base_qindex; + + /** \brief Quantization matrix. */ + union { + struct { + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint16_t using_qmatrix : 1; + /** \brief Following parameters only valid when using_qmatrix == 1. */ + uint16_t qm_y : 4; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint16_t qm_u : 4; + /** \brief Corresponds to AV1 syntax element of the same name. */ + uint16_t qm_v : 4; + /** \brief Reserved bytes for future use, must be zero. */ + uint16_t reserved : 3; + } bits; + uint16_t value; + } qmatrix_flags; + + /** \brief Reserved bytes for future use, must be zero. */ + uint16_t reserved16bits1; + + union { + struct { + /** \brief Specify whether quantizer index delta values are present. + * value range [0..1]. */ + uint32_t delta_q_present : 1; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..3]. */ + uint32_t delta_q_res : 2; + + /** \brief Specify whether loop filter delta values are present. + * value range [0..1]. */ + uint32_t delta_lf_present : 1; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..3]. */ + uint32_t delta_lf_res : 2; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..1]. */ + uint32_t delta_lf_multi : 1; + + /** \brief Corresponds to AV1 syntax element of the same name. + * 0: ONLY_4X4; + * 1: TX_MODE_LARGEST; + * 2: TX_MODE_SELECT; + * 3: Invalid. + */ + uint32_t tx_mode : 2; + + /** \brief Indicates whether to use single or compound reference prediction. + * 0: SINGLE_REFERENCE; + * 1: COMPOUND_REFERENCE; + * 2: REFERENCE_MODE_SELECT. + * 3: Invalid. + * + * Value 2 means driver make decision to use single reference or compound reference. + */ + uint32_t reference_mode : 2; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..1]. + */ + uint32_t skip_mode_present : 1; + /** \brief Reserved bytes for future use, must be zero. */ + uint32_t reserved : 20; + } bits; + uint32_t value; + } mode_control_flags; + + /** \brief Segmentation parameters. */ + VAEncSegParamAV1 segments; + + /** \brief Number of tile columns. */ + uint8_t tile_cols; + /** \brief Number of tile rows. */ + uint8_t tile_rows; + + /** \brief Reserved bytes for future use, must be zero. */ + uint16_t reserved16bits2; + + /** \brief The last tile column or row size needs to be derived. */ + uint16_t width_in_sbs_minus_1[63]; + uint16_t height_in_sbs_minus_1[63]; + + /** \brief specify which tile to use for the CDF update. + * value range [0..127]*/ + uint16_t context_update_tile_id; + + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..3]. + */ + uint8_t cdef_damping_minus_3; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..3]. + */ + uint8_t cdef_bits; + /** \brief CDEF Y strengths. + * value range [0..63]*/ + uint8_t cdef_y_strengths[8]; + /** \brief CDEF UV strengths. + * value range [0..63]*/ + uint8_t cdef_uv_strengths[8]; + + union { + struct { + /** \brief Restoration type for Y frame. + * value range [0..3]. + */ + uint16_t yframe_restoration_type : 2; + /** \brief Restoration type for Cb frame. + * value range [0..3]. + */ + uint16_t cbframe_restoration_type : 2; + /** \brief Restoration type for Cr frame. + * value range [0..3]. + */ + uint16_t crframe_restoration_type : 2; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..2]. + */ + uint16_t lr_unit_shift : 2; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..1]. + */ + uint16_t lr_uv_shift : 1; + /** \brief Reserved bytes for future use, must be zero. */ + uint16_t reserved : 7; + } bits; + uint16_t value; + } loop_restoration_flags; + + /** \brief Global motion. */ + VAEncWarpedMotionParamsAV1 wm[7]; + + /** + * Offset in bits for syntax base_q_idx in packed frame header bit stream + * from the start of the packed header data. + * In BRC mode, this parameter should be set and driver will update base_q_idx in + * uncompressed header according to this offset. + * In CQP mode, this parameter should be set to 0 and ignored by driver. + */ + uint32_t bit_offset_qindex; + /** + * Offset in bits for syntax segmentation_enabled of frame header OBU + * in packed frame header bit stream from the start of the packed header data. + * Valid only in auto segmentation mode. Other than that, this parameter + * should be set to 0 and ignored by driver. + */ + uint32_t bit_offset_segmentation; + /** + * Offset in bits for syntax loop_filter_params() in packed frame + * header bit stream from the start of the packed header data. + * In BRC mode, this parameter should be set and driver will update filter params + * in packed frame header according to this offset. + * In CQP mode, this parameter should be set to 0 and ignored by driver. + */ + uint32_t bit_offset_loopfilter_params; + /** + * In BRC mode, underline encoder should generate the approperiate + * CDEF values and write back into uncompressed header. And app + * should provide default CDEF values in packed header. This parameter + * should point to the starting bit of cdef_params() syntax structure + * in packed header. + * In CQP mode, this parameter should be set to 0 and ignored by driver. + */ + uint32_t bit_offset_cdef_params; + /** + * In BRC mode, this parameter indicates the actual bit usage of + * cdef_params() syntax structure in packed uncompressed header. + * In CQP mode, this parameter should be set to 0 and ignored by driver. + */ + uint32_t size_in_bits_cdef_params; + + /** + * Offset in bytes for syntax obu_size of frame header OBU in packed + * frame header bit stream from the start of the packed header. The frame + * header OBU size depends on the encoded tile sizes. It applies to both + * Frame Header OBU and Frame OBU if obu_size needs to be updated by + * underline encoder. Otherwise, app can set it to 0 and ignored by driver. + * + * In BRC mode, obu_size needs to be updated and this parameter should be set. + * In CQP mode, this parameter should be set to 0 and ignored by driver. + */ + uint32_t byte_offset_frame_hdr_obu_size; + + /** + * Frame header OBU bit stream size in bits. The frame header obu packed bit + * stream contains an obu header, a 4-byte long obu_size field, frame_header_obu() + * syntax chain, and a trailing bit if not inside a frame obu. If \c enable_frame_obu == 1, + * the value should include and up to the last bit of frame_header_obu() and + * excluding the bits generated by byte_alignment(). If \c enable_frame_obu == 0, + * the value should include and up to the trailing bit at the end of the frame + * header obu. The size will be used by encoder to calculate the final frame + * header size after bit shifting due to auto segmentation. + * In CQP mode, this parameter should be set to 0 and ignored by driver. + */ + uint32_t size_in_bits_frame_hdr_obu; + + /** \brief Tile Group OBU header */ + union { + struct { + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..1]. + */ + uint8_t obu_extension_flag : 1; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..1]. + */ + uint8_t obu_has_size_field : 1; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..7]. + */ + uint8_t temporal_id : 3; + /** \brief Corresponds to AV1 syntax element of the same name. + * value range [0..2]. + */ + uint8_t spatial_id : 2; + /** \brief Reserved bytes for future use, must be zero. */ + uint8_t reserved : 1; + } bits; + uint8_t value; + } tile_group_obu_hdr_info; + + /** \brief The number of frames skipped prior to the current frame. + * It includes only the skipped frames that were not counted before. + * App may generate the "show_existing_frame" short frame header OBUs + * and send to driver with the next frame. Default value 0. + */ + uint8_t number_skip_frames; + + /** \brief Reserved bytes for future use, must be zero. */ + uint16_t reserved16bits3; + + /** \brief Indicates the application forced frame size change in bytes. + * When the value is positive, the frame size is reduced. Otherwise, the frame + * size increases. The parameter can be used when application skips frames with + * setting of NumSkipFrames. And application can also use it for other scenarios + * such as inserting "show_existing_frame" at very end of the sequence. + */ + int32_t skip_frames_reduced_size; + + /** \brief Reserved bytes for future use, must be zero. */ + uint32_t va_reserved[VA_PADDING_HIGH]; +} VAEncPictureParameterBufferAV1; + +/** + * \brief Tile Group Buffer. + */ +typedef struct _VAEncTileGroupBufferAV1 { + /** \brief Tile group start location. + * The position of the first tile in current tile group + * in raster scan order across the frame. + * value range [0..127]. + */ + uint8_t tg_start; + /** \brief Tile group end location. + * The position of the last tile in current tile group + * in raster scan order across the frame. + * value range [0..127]. + */ + uint8_t tg_end; + + /** \brief Reserved bytes for future use, must be zero. */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncTileGroupBufferAV1; + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_ENC_AV1_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_h264.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_h264.h new file mode 100644 index 00000000..46a6704e --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_h264.h @@ -0,0 +1,659 @@ +/* + * Copyright (c) 2007-2011 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_enc_h264.h + * \brief The H.264 encoding API + * + * This file contains the \ref api_enc_h264 "H.264 encoding API". + */ + +#ifndef VA_ENC_H264_H +#define VA_ENC_H264_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_enc_h264 H.264 encoding API + * + * @{ + */ + +/** + * @name Picture flags + * + * Those flags flags are meant to signal when a picture marks the end + * of a sequence, a stream, or even both at once. + * + * @{ + */ +/** + * \brief Marks the last picture in the sequence. + * + * i.e. the driver appends \c end_of_seq() NAL unit to the encoded frame. + */ +#define H264_LAST_PICTURE_EOSEQ 0x01 +/** + * \brief Marks the last picture in the stream. + * + * i.e. the driver appends \c end_of_stream() NAL unit to the encoded frame. + */ +#define H264_LAST_PICTURE_EOSTREAM 0x02 +/**@}*/ + +/** + * \brief Packed header types specific to H.264 encoding. + * + * Types of packed headers generally used for H.264 encoding. Each + * associated packed header data buffer shall contain the start code + * prefix 0x000001 followed by the complete NAL unit, thus also + * including the \c nal_unit_type. + * + * Note: the start code prefix can contain an arbitrary number of leading + * zeros. The driver will skip them for emulation prevention bytes insertion, + * if necessary. + */ +typedef enum { + /** + * \brief Packed Sequence Parameter Set (SPS). + * + * The corresponding packed header data buffer shall contain the + * complete seq_parameter_set_rbsp() syntax element. + * + * Note: packed \c nal_unit_type shall be equal to 7. + */ + VAEncPackedHeaderH264_SPS = VAEncPackedHeaderSequence, + /** + * \brief Packed Picture Parameter Set (PPS). + * + * The corresponding packed header data buffer shall contain the + * complete pic_parameter_set_rbsp() syntax element. + * + * Note: packed \c nal_unit_type shall be equal to 8. + */ + VAEncPackedHeaderH264_PPS = VAEncPackedHeaderPicture, + /** + * \brief Packed slice header. + * + * The corresponding packed header data buffer shall contain the + * \c slice_header() syntax element only, along with any start + * code prefix and NAL unit type preceeding it. i.e. this means + * that the buffer does not contain any of the \c slice_data() or + * the \c rbsp_slice_trailing_bits(). + * + * Note: packed \c nal_unit_type shall be equal to 1 (non-IDR + * picture), or 5 (IDR picture). + */ + VAEncPackedHeaderH264_Slice = VAEncPackedHeaderSlice, + /** + * \brief Packed Supplemental Enhancement Information (SEI). + * + * The corresponding packed header data buffer shall contain the + * complete sei_rbsp() syntax element, thus including several + * sei_message() elements if necessary. + * + * Note: packed \c nal_unit_type shall be equal to 6. + * + * @deprecated + * This is a deprecated packed header flag, All applications can use + * \c VA_ENC_PACKED_HEADER_RAW_DATA to pass the corresponding packed + * SEI header data buffer to the driver + */ + VAEncPackedHeaderH264_SEI va_deprecated_enum = (0x80000000 | 1), +} VAEncPackedHeaderTypeH264; + +/** + * \brief Sequence parameter for H.264 encoding in baseline, main & high + * profiles. + * + * This structure holds information for \c seq_parameter_set_data() as + * defined by the H.264 specification. + * + * If packed sequence headers mode is used, i.e. if the encoding + * pipeline was configured with the #VA_ENC_PACKED_HEADER_SEQUENCE + * flag, then the driver expects two more buffers to be provided to + * the same \c vaRenderPicture() as this buffer: + * - a #VAEncPackedHeaderParameterBuffer with type set to + * VAEncPackedHeaderType::VAEncPackedHeaderSequence ; + * - a #VAEncPackedHeaderDataBuffer which holds the actual packed + * header data. + * + * If \c seq_scaling_matrix_present_flag is set to \c 1, then a + * #VAIQMatrixBufferH264 buffer shall also be provided within the same + * \c vaRenderPicture() call as this sequence parameter buffer. + */ +typedef struct _VAEncSequenceParameterBufferH264 { + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t seq_parameter_set_id; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t level_idc; + /** \brief Period between I frames. */ + uint32_t intra_period; + /** \brief Period between IDR frames. */ + uint32_t intra_idr_period; + /** \brief Period between I/P frames. */ + uint32_t ip_period; + /** + * \brief Initial bitrate set for this sequence in CBR or VBR modes. + * + * This field represents the initial bitrate value for this + * sequence if CBR or VBR mode is used, i.e. if the encoder + * pipeline was created with a #VAConfigAttribRateControl + * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR. + * + * The bitrate can be modified later on through + * #VAEncMiscParameterRateControl buffers. + */ + uint32_t bits_per_second; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t max_num_ref_frames; + /** \brief Picture width in macroblocks. */ + uint16_t picture_width_in_mbs; + /** \brief Picture height in macroblocks. */ + uint16_t picture_height_in_mbs; + + union { + struct { + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t chroma_format_idc : 2; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t frame_mbs_only_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t mb_adaptive_frame_field_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t seq_scaling_matrix_present_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t direct_8x8_inference_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t log2_max_frame_num_minus4 : 4; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t pic_order_cnt_type : 2; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t log2_max_pic_order_cnt_lsb_minus4 : 4; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t delta_pic_order_always_zero_flag : 1; + } bits; + uint32_t value; + } seq_fields; + + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t bit_depth_luma_minus8; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t bit_depth_chroma_minus8; + + /** if pic_order_cnt_type == 1 */ + /**@{*/ + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t num_ref_frames_in_pic_order_cnt_cycle; + /** \brief Same as the H.264 bitstream syntax element. */ + int32_t offset_for_non_ref_pic; + /** \brief Same as the H.264 bitstream syntax element. */ + int32_t offset_for_top_to_bottom_field; + /** \brief Same as the H.264 bitstream syntax element. */ + int32_t offset_for_ref_frame[256]; + /**@}*/ + + /** @name Cropping (optional) */ + /**@{*/ + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t frame_cropping_flag; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t frame_crop_left_offset; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t frame_crop_right_offset; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t frame_crop_top_offset; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t frame_crop_bottom_offset; + /**@}*/ + + /** @name VUI parameters (optional) */ + /**@{*/ + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t vui_parameters_present_flag; + union { + struct { + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t aspect_ratio_info_present_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t timing_info_present_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t bitstream_restriction_flag : 1; + /** \brief Range: 0 to 16, inclusive. */ + uint32_t log2_max_mv_length_horizontal : 5; + /** \brief Range: 0 to 16, inclusive. */ + uint32_t log2_max_mv_length_vertical : 5; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t fixed_frame_rate_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t low_delay_hrd_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t motion_vectors_over_pic_boundaries_flag: 1; + /** \brief Reserved for future use, must be zero */ + uint32_t reserved : 16; + } bits; + uint32_t value; + } vui_fields; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t aspect_ratio_idc; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t sar_width; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t sar_height; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t num_units_in_tick; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t time_scale; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; + /**@}*/ +} VAEncSequenceParameterBufferH264; + +/** + * \brief Picture parameter for H.264 encoding in baseline, main & high + * profiles. + * + * This structure holds information for \c pic_parameter_set_rbsp() as + * defined by the H.264 specification. + * + * If packed picture headers mode is used, i.e. if the encoding + * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE + * flag, then the driver expects two more buffers to be provided to + * the same \c vaRenderPicture() as this buffer: + * - a #VAEncPackedHeaderParameterBuffer with type set to + * VAEncPackedHeaderType::VAEncPackedHeaderPicture ; + * - a #VAEncPackedHeaderDataBuffer which holds the actual packed + * header data. + * + * If \c pic_scaling_matrix_present_flag is set to \c 1, then a + * #VAIQMatrixBufferH264 buffer shall also be provided within the same + * \c vaRenderPicture() call as this picture parameter buffer. + */ +typedef struct _VAEncPictureParameterBufferH264 { + /** + * \brief Information about the picture to be encoded. + * + * See #VAPictureH264 for further description of each field. + * Note that CurrPic.picture_id represents the reconstructed + * (decoded) picture. User provides a scratch VA surface ID here. + */ + VAPictureH264 CurrPic; + /** + * \brief Decoded Picture Buffer (DPB). + * + * This array represents the list of reconstructed (decoded) + * frames used as reference. It is important to keep track of + * reconstructed frames so that they can be used later on as + * reference for P or B-frames encoding. + */ + VAPictureH264 ReferenceFrames[16]; + /** + * \brief Output encoded bitstream. + * + * \ref coded_buf has type #VAEncCodedBufferType. It should be + * large enough to hold the compressed NAL slice and possibly SPS + * and PPS NAL units. + */ + VABufferID coded_buf; + + /** \brief The picture parameter set referred to in the slice header. */ + uint8_t pic_parameter_set_id; + /** \brief The active sequence parameter set. Range: 0 to 31, inclusive. */ + uint8_t seq_parameter_set_id; + + /** + * \brief OR'd flags describing whether the picture is the last one or not. + * + * This fields holds 0 if the picture to be encoded is not the last + * one in the stream or sequence. Otherwise, it is a combination of + * \ref H264_LAST_PICTURE_EOSEQ or \ref H264_LAST_PICTURE_EOSTREAM. + */ + uint8_t last_picture; + + /** \brief The picture identifier. + * Range: 0 to \f$2^{log2\_max\_frame\_num\_minus4 + 4} - 1\f$, inclusive. + */ + uint16_t frame_num; + + /** \brief \c pic_init_qp_minus26 + 26. */ + uint8_t pic_init_qp; + /** \brief Maximum reference index for reference picture list 0. + * Range: 0 to 31, inclusive. + */ + uint8_t num_ref_idx_l0_active_minus1; + /** \brief Maximum reference index for reference picture list 1. + * Range: 0 to 31, inclusive. + */ + uint8_t num_ref_idx_l1_active_minus1; + + /** \brief Range: -12 to 12, inclusive. */ + int8_t chroma_qp_index_offset; + /** \brief Range: -12 to 12, inclusive. */ + int8_t second_chroma_qp_index_offset; + + union { + struct { + /** \brief Is picture an IDR picture? */ + uint32_t idr_pic_flag : 1; + /** \brief Is picture a reference picture? */ + uint32_t reference_pic_flag : 2; + /** \brief Selects CAVLC (0) or CABAC (1) entropy coding mode. */ + uint32_t entropy_coding_mode_flag : 1; + /** \brief Is weighted prediction applied to P slices? */ + uint32_t weighted_pred_flag : 1; + /** \brief Range: 0 to 2, inclusive. */ + uint32_t weighted_bipred_idc : 2; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t constrained_intra_pred_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t transform_8x8_mode_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t deblocking_filter_control_present_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t redundant_pic_cnt_present_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t pic_order_present_flag : 1; + /** \brief Same as the H.264 bitstream syntax element. */ + uint32_t pic_scaling_matrix_present_flag : 1; + } bits; + uint32_t value; + } pic_fields; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncPictureParameterBufferH264; + +typedef struct _VAEncQPBufferH264 { + /* + * \brief This structure holds QP per 16x16 macroblock. Buffer size shall be + * sufficient to fit the slice or frame to be encoded depending on if it is a + * slice level or frame level encoding. + */ + uint8_t qp; +} VAEncQPBufferH264; + +/** + * \brief Slice parameter for H.264 encoding in baseline, main & high profiles. + * + * This structure holds information for \c + * slice_layer_without_partitioning_rbsp() as defined by the H.264 + * specification. + * + * If packed slice headers mode is used, i.e. if the encoding + * pipeline was configured with the #VA_ENC_PACKED_HEADER_SLICE + * flag, then the driver expects two more buffers to be provided to + * the same \c vaRenderPicture() as this buffer: + * - a #VAEncPackedHeaderParameterBuffer with type set to + * VAEncPackedHeaderType::VAEncPackedHeaderSlice ; + * - a #VAEncPackedHeaderDataBuffer which holds the actual packed + * header data. + * + * If per-macroblock encoder configuration is needed, \c macroblock_info + * references a buffer of type #VAEncMacroblockParameterBufferH264. This + * buffer is not passed to vaRenderPicture() and it can be re-used + * without re-allocating the whole buffer. + */ +typedef struct _VAEncSliceParameterBufferH264 { + /** \brief Starting MB address for this slice. */ + uint32_t macroblock_address; + /** \brief Number of macroblocks in this slice. */ + uint32_t num_macroblocks; + /** + * \brief Per-MB encoder configuration buffer, or \c VA_INVALID_ID. + * + * If per-MB encoder configuration is needed, then \ref macroblock_info + * references a buffer of type #VAEncMacroblockParameterBufferH264 + * (\c VAEncMacroblockParameterBufferType). Otherwise, buffer id + * is set to \c VA_INVALID_ID and per-MB configuration is derived + * from this slice parameter. + * + * The \c macroblock_info buffer must hold \ref num_macroblocks + * elements. + */ + VABufferID macroblock_info; + /** \brief Slice type. + * Range: 0..2, 5..7, i.e. no switching slices. + */ + uint8_t slice_type; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t pic_parameter_set_id; + /** \brief Same as the H.264 bitstream syntax element. */ + uint16_t idr_pic_id; + + /** @name If pic_order_cnt_type == 0 */ + /**@{*/ + /** \brief The picture order count modulo MaxPicOrderCntLsb. */ + uint16_t pic_order_cnt_lsb; + /** \brief Valid if \c pic_order_present_flag and this is a bottom field. */ + int32_t delta_pic_order_cnt_bottom; + /**@}*/ + /** @name If pic_order_cnt_type == 1 && !delta_pic_order_always_zero_flag */ + /**@{*/ + /** \brief [0]: top, [1]: bottom. */ + int32_t delta_pic_order_cnt[2]; + /**@}*/ + + /** @name If slice_type == B */ + /**@{*/ + uint8_t direct_spatial_mv_pred_flag; + /**@}*/ + + /** @name If slice_type == P */ + /**@{*/ + /** \brief Specifies if + * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l0_active_minus1 or + * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l1_active_minus1 are + * overriden by the values for this slice. + */ + uint8_t num_ref_idx_active_override_flag; + /** \brief Maximum reference index for reference picture list 0. + * Range: 0 to 31, inclusive. + */ + uint8_t num_ref_idx_l0_active_minus1; + /** \brief Maximum reference index for reference picture list 1. + * Range: 0 to 31, inclusive. + */ + uint8_t num_ref_idx_l1_active_minus1; + /** \brief Reference picture list 0 (for P slices). */ + VAPictureH264 RefPicList0[32]; + /** \brief Reference picture list 1 (for B slices). */ + VAPictureH264 RefPicList1[32]; + /**@}*/ + + /** @name pred_weight_table() */ + /**@{*/ + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t luma_log2_weight_denom; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t chroma_log2_weight_denom; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t luma_weight_l0_flag; + /** \brief Same as the H.264 bitstream syntax element. */ + signed short luma_weight_l0[32]; + /** \brief Same as the H.264 bitstream syntax element. */ + signed short luma_offset_l0[32]; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t chroma_weight_l0_flag; + /** \brief Same as the H.264 bitstream syntax element. */ + signed short chroma_weight_l0[32][2]; + /** \brief Same as the H.264 bitstream syntax element. */ + signed short chroma_offset_l0[32][2]; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t luma_weight_l1_flag; + /** \brief Same as the H.264 bitstream syntax element. */ + signed short luma_weight_l1[32]; + /** \brief Same as the H.264 bitstream syntax element. */ + signed short luma_offset_l1[32]; + /** \brief Same as the H.264 bitstream syntax element. */ + uint8_t chroma_weight_l1_flag; + /** \brief Same as the H.264 bitstream syntax element. */ + signed short chroma_weight_l1[32][2]; + /** \brief Same as the H.264 bitstream syntax element. */ + signed short chroma_offset_l1[32][2]; + /**@}*/ + + /** \brief Range: 0 to 2, inclusive. */ + uint8_t cabac_init_idc; + /** \brief Same as the H.264 bitstream syntax element. */ + int8_t slice_qp_delta; + /** @name If deblocking_filter_control_present_flag */ + /**@{*/ + /** \brief Range: 0 to 2, inclusive. */ + uint8_t disable_deblocking_filter_idc; + /** \brief Same as the H.264 bitstream syntax element. */ + int8_t slice_alpha_c0_offset_div2; + /** \brief Same as the H.264 bitstream syntax element. */ + int8_t slice_beta_offset_div2; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; + /**@}*/ +} VAEncSliceParameterBufferH264; + +/** + * @name Macroblock neighbour availability bits + * + * \anchor api_enc_h264_mb_pred_avail_bits + * Definitions for macroblock neighbour availability bits used in + * intra prediction mode (non MBAFF only). + * + * @{ + */ +/** \brief References macroblock in the top-left corner. */ +#define VA_MB_PRED_AVAIL_TOP_LEFT (1 << 2) +/** \brief References macroblock above the current macroblock. */ +#define VA_MB_PRED_AVAIL_TOP (1 << 4) +/** \brief References macroblock in the top-right corner. */ +#define VA_MB_PRED_AVAIL_TOP_RIGHT (1 << 3) +/** \brief References macroblock on the left of the current macroblock. */ +#define VA_MB_PRED_AVAIL_LEFT (1 << 6) +/**@}*/ + +/** + * \brief Macroblock parameter for H.264 encoding in baseline, main & high + * profiles. + * + * This structure holds per-macroblock information. The buffer must be + * allocated with as many elements (macroblocks) as necessary to fit + * the slice to be encoded. Besides, the per-macroblock records must + * be written in a strict raster order and with no gap. i.e. every + * macroblock, regardless of its type, shall have an entry. + */ +typedef struct _VAEncMacroblockParameterBufferH264 { + /** + * \brief Quantization parameter. + * + * Requested quantization parameter. Range: 0 to 51, inclusive. + * If \ref qp is set to 0xff, then the actual value is derived + * from the slice-level value: \c pic_init_qp + \c slice_qp_delta. + */ + uint8_t qp; + + union { + /** @name Data for intra macroblock */ + /**@{*/ + union { + struct { + /** + * \brief Flag specified to override MB neighbour + * availability bits from VME stage. + * + * This flag specifies that macroblock neighbour + * availability bits from the VME stage are overriden + * by the \ref pred_avail_flags hereunder. + */ + uint32_t pred_avail_override_flag : 1; + /** + * \brief Bitwise representation of which macroblocks + * are available for intra prediction. + * + * If the slice is intra-coded, this field represents + * the macroblocks available for intra prediction. + * See \ref api_enc_h264_mb_pred_avail_bits + * "macroblock neighbour availability" bit definitions. + */ + uint32_t pred_avail_flags : 8; + } bits; + uint32_t value; + } intra_fields; + /**@}*/ + + /** @name Data for inter macroblock */ + /**@{*/ + union { + struct { + uint32_t reserved; + } bits; + uint32_t value; + } inter_fields; + /**@}*/ + } info; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMacroblockParameterBufferH264; + +/** + * \brief MB partition modes and 1/2 1/4 motion search configuration + * + * Specifies MB partition modes that are disabled. Specifies Half-pel + * mode and Quarter-pel mode searching + */ +typedef struct _VAEncMiscParameterSubMbPartPelH264 { + uint32_t disable_inter_sub_mb_partition; + union { + struct { + uint32_t disable_16x16_inter_mb_partition : 1; + uint32_t disable_16x8_inter_mb_partition : 1; + uint32_t disable_8x16_inter_mb_partition : 1; + uint32_t disable_8x8_inter_mb_partition : 1; + uint32_t disable_8x4_inter_mb_partition : 1; + uint32_t disable_4x8_inter_mb_partition : 1; + uint32_t disable_4x4_inter_mb_partition : 1; + uint32_t reserved : 1; + } bits; + uint8_t value; + } inter_sub_mb_partition_mask; + + /** + * \brief Precison of motion search + * 0:Integer mode searching + * 1:Half-pel mode searching + * 2:Reserved + * 3:Quarter-pel mode searching + */ + uint32_t enable_sub_pel_mode; + uint8_t sub_pel_mode; + uint8_t reserved[3]; +} VAEncMiscParameterSubMbPartPelH264; +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_ENC_H264_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_hevc.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_hevc.h new file mode 100644 index 00000000..96b5ae56 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_hevc.h @@ -0,0 +1,958 @@ +/* + * Copyright (c) 2007-2014 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_enc_hevc.h + * \brief The HEVC encoding API + * + * This file contains the \ref api_enc_hevc "HEVC encoding API". + * + */ + +#ifndef VA_ENC_HEVC_H +#define VA_ENC_HEVC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * \defgroup api_enc_hevc HEVC encoding API + * + * @{ + */ + +/** Attribute value for VAConfigAttribEncHEVCFeatures. + * + * This attribute decribes the supported features of an HEVC/H.265 + * encoder configuration. + * + * All of the field values in this attribute are VA_FEATURE_* values, + * indicating support for the corresponding feature. + */ +typedef union VAConfigAttribValEncHEVCFeatures { + struct { + /** Separate colour planes. + * + * Allows setting separate_colour_plane_flag in the SPS. + */ + uint32_t separate_colour_planes : 2; + /** Scaling lists. + * + * Allows scaling_list() elements to be present in both the SPS + * and the PPS. The decoded form of the scaling lists must also + * be supplied in a VAQMatrixBufferHEVC buffer when scaling lists + * are enabled. + */ + uint32_t scaling_lists : 2; + /** Asymmetric motion partitions. + * + * Allows setting amp_enabled_flag in the SPS. + */ + uint32_t amp : 2; + /** Sample adaptive offset filter. + * + * Allows setting slice_sao_luma_flag and slice_sao_chroma_flag + * in slice headers. + */ + uint32_t sao : 2; + /** PCM sample blocks. + * + * Allows setting pcm_enabled_flag in the SPS. When enabled + * PCM parameters must be supplied with the sequence parameters, + * including block sizes which may be further constrained as + * noted in the VAConfigAttribEncHEVCBlockSizes attribute. + */ + uint32_t pcm : 2; + /** Temporal motion vector Prediction. + * + * Allows setting slice_temporal_mvp_enabled_flag in slice + * headers. + */ + uint32_t temporal_mvp : 2; + /** Strong intra smoothing. + * + * Allows setting strong_intra_smoothing_enabled_flag in the SPS. + */ + uint32_t strong_intra_smoothing : 2; + /** Dependent slices. + * + * Allows setting dependent_slice_segment_flag in slice headers. + */ + uint32_t dependent_slices : 2; + /** Sign data hiding. + * + * Allows setting sign_data_hiding_enable_flag in the PPS. + */ + uint32_t sign_data_hiding : 2; + /** Constrained intra prediction. + * + * Allows setting constrained_intra_pred_flag in the PPS. + */ + uint32_t constrained_intra_pred : 2; + /** Transform skipping. + * + * Allows setting transform_skip_enabled_flag in the PPS. + */ + uint32_t transform_skip : 2; + /** QP delta within coding units. + * + * Allows setting cu_qp_delta_enabled_flag in the PPS. + */ + uint32_t cu_qp_delta : 2; + /** Weighted prediction. + * + * Allows setting weighted_pred_flag and weighted_bipred_flag in + * the PPS. The pred_weight_table() data must be supplied with + * every slice header when weighted prediction is enabled. + */ + uint32_t weighted_prediction : 2; + /** Transform and quantisation bypass. + * + * Allows setting transquant_bypass_enabled_flag in the PPS. + */ + uint32_t transquant_bypass : 2; + /** Deblocking filter disable. + * + * Allows setting slice_deblocking_filter_disabled_flag. + */ + uint32_t deblocking_filter_disable : 2; + /* Reserved,should not be used, avoid conflict with VA_ATTRIB_NOT_SUPPORTED. */ + uint32_t reserved : 2; + } bits; + uint32_t value; +} VAConfigAttribValEncHEVCFeatures; + +/** Attribute value for VAConfigAttribEncHEVCBlockSizes. + * + * This attribute describes the supported coding tree and transform block + * sizes of an HEVC/H.265 encoder configuration + */ +typedef union VAConfigAttribValEncHEVCBlockSizes { + struct { + /** Largest supported size of coding tree blocks. + * + * CtbLog2SizeY must not be larger than this. + */ + uint32_t log2_max_coding_tree_block_size_minus3 : 2; + /** Smallest supported size of coding tree blocks. + * + * CtbLog2SizeY must not be smaller than this. + * + * This may be the same as the maximum size, indicating that only + * one CTB size is supported. + */ + uint32_t log2_min_coding_tree_block_size_minus3 : 2; + + /** Smallest supported size of luma coding blocks. + * + * MinCbLog2SizeY must not be smaller than this. + */ + uint32_t log2_min_luma_coding_block_size_minus3 : 2; + + /** Largest supported size of luma transform blocks. + * + * MaxTbLog2SizeY must not be larger than this. + */ + uint32_t log2_max_luma_transform_block_size_minus2 : 2; + /** Smallest supported size of luma transform blocks. + * + * MinTbLog2SizeY must not be smaller than this. + */ + uint32_t log2_min_luma_transform_block_size_minus2 : 2; + + /** Largest supported transform hierarchy depth in inter + * coding units. + * + * max_transform_hierarchy_depth_inter must not be larger + * than this. + */ + uint32_t max_max_transform_hierarchy_depth_inter : 2; + /** Smallest supported transform hierarchy depth in inter + * coding units. + * + * max_transform_hierarchy_depth_inter must not be smaller + * than this. + */ + uint32_t min_max_transform_hierarchy_depth_inter : 2; + + /** Largest supported transform hierarchy depth in intra + * coding units. + * + * max_transform_hierarchy_depth_intra must not be larger + * than this. + */ + uint32_t max_max_transform_hierarchy_depth_intra : 2; + /** Smallest supported transform hierarchy depth in intra + * coding units. + * + * max_transform_hierarchy_depth_intra must not be smaller + * than this. + */ + uint32_t min_max_transform_hierarchy_depth_intra : 2; + + /** Largest supported size of PCM coding blocks. + * + * Log2MaxIpcmCbSizeY must not be larger than this. + */ + uint32_t log2_max_pcm_coding_block_size_minus3 : 2; + /** Smallest supported size of PCM coding blocks. + * + * Log2MinIpcmCbSizeY must not be smaller than this. + */ + uint32_t log2_min_pcm_coding_block_size_minus3 : 2; + + /** Reserved for future use. */ + uint32_t reserved : 10; + } bits; + uint32_t value; +} VAConfigAttribValEncHEVCBlockSizes; + +/** + * @name Picture flags + * + * Those flags flags are meant to signal when a picture marks the end + * of a sequence, a stream, or even both at once. + * + * @{ + */ +/** + * \brief Marks the last picture in the sequence. + * + * i.e. the driver appends \c end_of_seq() NAL unit to the encoded frame. + */ +#define HEVC_LAST_PICTURE_EOSEQ 0x01 +/** + * \brief Marks the last picture in the stream. + * + * i.e. the driver appends \c end_of_stream() NAL unit to the encoded frame. + */ +#define HEVC_LAST_PICTURE_EOSTREAM 0x02 +/**@}*/ + +/** + * \brief Packed header types specific to HEVC encoding. + * + * Types of packed headers generally used for HEVC encoding. Each + * associated packed header data buffer shall contain the start code + * prefix 0x000001 followed by the complete NAL unit, thus also + * including the \c nal_unit_type. + * + * Note: the start code prefix can contain an arbitrary number of leading + * zeros. The driver will skip them for emulation prevention bytes insertion, + * if necessary. + */ +typedef enum { + /** + * \brief Packed Video Parameter Set (VPS). + * + * The corresponding packed header data buffer shall contain the + * complete video_parameter_set_rbsp() syntax element. + * + * Note: packed \c nal_unit_type shall be equal to 32. + */ + VAEncPackedHeaderHEVC_VPS = VAEncPackedHeaderSequence, + /** + * \brief Packed Sequence Parameter Set (SPS). + * + * The corresponding packed header data buffer shall contain the + * complete seq_parameter_set_rbsp() syntax element. + * + * Note: packed \c nal_unit_type shall be equal to 33. + */ + VAEncPackedHeaderHEVC_SPS = VAEncPackedHeaderSequence, + /** + * \brief Packed Picture Parameter Set (PPS). + * + * The corresponding packed header data buffer shall contain the + * complete pic_parameter_set_rbsp() syntax element. + * + * Note: packed \c nal_unit_type shall be equal to 34. + */ + VAEncPackedHeaderHEVC_PPS = VAEncPackedHeaderPicture, + /** + * \brief Packed slice header. + * + * The corresponding packed header data buffer shall contain the + * \c slice_header() syntax element only, along with any start + * code prefix and NAL unit type preceeding it. i.e. this means + * that the buffer does not contain any of the \c slice_data() or + * the \c rbsp_slice_trailing_bits(). + * + * Note: packed \c nal_unit_type shall be equal to 0 to 9 (non-IRAP + * picture), or 16 to 21 (IRAP picture). + */ + VAEncPackedHeaderHEVC_Slice = VAEncPackedHeaderSlice, + /** + * \brief Packed Supplemental Enhancement Information (SEI). + * + * The corresponding packed header data buffer shall contain the + * complete sei_rbsp() syntax element, thus including several + * sei_message() elements if necessary. + * + * Note: packed \c nal_unit_type shall be equal to 39 or 40. + * + * @deprecated + * This is a deprecated packed header flag, All applications can use + * \c VA_ENC_PACKED_HEADER_RAW_DATA to pass the corresponding packed + * SEI header data buffer to the driver + */ + VAEncPackedHeaderHEVC_SEI va_deprecated_enum = (0x80000000 | 1), +} VAEncPackedHeaderTypeHEVC; + +/** + * \brief Sequence parameter for HEVC encoding in main & main 10 + * profiles. + * + * This structure holds information for \c seq_parameter_set_data() as + * defined by the HEVC specification. + * + * If packed sequence headers mode is used, i.e. if the encoding + * pipeline was configured with the #VA_ENC_PACKED_HEADER_SEQUENCE + * flag, then the driver expects two more buffers to be provided to + * the same \c vaRenderPicture() as this buffer: + * - a #VAEncPackedHeaderParameterBuffer with type set to + * VAEncPackedHeaderType::VAEncPackedHeaderSequence ; + * - a #VAEncPackedHeaderDataBuffer which holds the actual packed + * header data. + * + * If \c seq_scaling_matrix_present_flag is set to \c 1, then a + * #VAQMatrixBufferHEVC buffer shall also be provided within the same + * \c vaRenderPicture() call as this sequence parameter buffer. + */ +typedef struct _VAEncSequenceParameterBufferHEVC { + /** \brief Same as the HEVC bitstream syntax element. + * value range [1..2]. + */ + uint8_t general_profile_idc; + /** \brief Same as the HEVC bitstream syntax element. + * general_level_idc shall be set equal to a value of 30 times the level + * numbers allowed [1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 5.2, 6, 6.1, 6.2] + */ + uint8_t general_level_idc; + /** \brief Same as the HEVC bitstream syntax element. + * Only value 0 is allowed for level value below 4, exclusive. + */ + uint8_t general_tier_flag; + /** \brief Period between I frames. */ + uint32_t intra_period; + /** \brief Period between IDR frames. */ + uint32_t intra_idr_period; + /** \brief Period between I/P frames. */ + uint32_t ip_period; + /** + * \brief Initial bitrate set for this sequence in CBR or VBR modes. + * + * This field represents the initial bitrate value for this + * sequence if CBR or VBR mode is used, i.e. if the encoder + * pipeline was created with a #VAConfigAttribRateControl + * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR. + * + * The bitrate can be modified later on through + * #VAEncMiscParameterRateControl buffers. + */ + uint32_t bits_per_second; + /** \brief Picture width in pixel samples. + * Its value must be multiple of min CU size. + */ + uint16_t pic_width_in_luma_samples; + /** \brief Picture height in pixel samples. + * Its value must be multiple of min CU size. + */ + uint16_t pic_height_in_luma_samples; + + union { + struct { + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t chroma_format_idc : 2; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t separate_colour_plane_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t bit_depth_luma_minus8 : 3; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t bit_depth_chroma_minus8 : 3; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t scaling_list_enabled_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t strong_intra_smoothing_enabled_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t amp_enabled_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t sample_adaptive_offset_enabled_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t pcm_enabled_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t pcm_loop_filter_disabled_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t sps_temporal_mvp_enabled_flag : 1; + /** \brief Indicates whether or not the encoding is in low delay mode. + * 0 normal sequence + * 1 no random access B will be coded . and the coding type could be only I, P or LDB + * this flag only indicates the frame coding type of the sequence. + */ + uint32_t low_delay_seq : 1; + /** \brief Indicates whether or not the encoding is in dyadic hierarchical GOP structure + * the default value 0, BRC would treat is as flat structure. if HierachicalFlag == 1, + * application would enable Qp Modulation + */ + uint32_t hierachical_flag : 1; + /** \brief keep for future , should be set to 0 */ + uint32_t reserved_bits : 14; + } bits; + uint32_t value; + } seq_fields; + + /** \brief Same as the HEVC bitstream syntax element. + * value range [0..3] + */ + uint8_t log2_min_luma_coding_block_size_minus3; + + /** \brief Same as the HEVC bitstream syntax element. + */ + uint8_t log2_diff_max_min_luma_coding_block_size; + + /** \brief Same as the HEVC bitstream syntax element. + * value range [0..3] + */ + uint8_t log2_min_transform_block_size_minus2; + + /** \brief Same as the HEVC bitstream syntax element. + */ + uint8_t log2_diff_max_min_transform_block_size; + + /** \brief Same as the HEVC bitstream syntax element. + * value range [2] + */ + uint8_t max_transform_hierarchy_depth_inter; + + /** \brief Same as the HEVC bitstream syntax element. + * value range [2] + */ + uint8_t max_transform_hierarchy_depth_intra; + + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t pcm_sample_bit_depth_luma_minus1; + + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t pcm_sample_bit_depth_chroma_minus1; + + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t log2_min_pcm_luma_coding_block_size_minus3; + + /** \brief Derived from the HEVC bitstream syntax element. + * log2_min_pcm_luma_coding_block_size_minus3 + + * log2_diff_max_min_pcm_luma_coding_block_size + */ + uint32_t log2_max_pcm_luma_coding_block_size_minus3; + + /** @name VUI parameters (optional) */ + /**@{*/ + /** \brief Same as the HEVC bitstream syntax element. */ + uint8_t vui_parameters_present_flag; + union { + struct { + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t aspect_ratio_info_present_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t neutral_chroma_indication_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t field_seq_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t vui_timing_info_present_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t bitstream_restriction_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t tiles_fixed_structure_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t motion_vectors_over_pic_boundaries_flag : 1; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t restricted_ref_pic_lists_flag : 1; + /** \brief Range: 0 to 16, inclusive. */ + uint32_t log2_max_mv_length_horizontal : 5; + /** \brief Range: 0 to 16, inclusive. */ + uint32_t log2_max_mv_length_vertical : 5; + } bits; + uint32_t value; + } vui_fields; + /** \brief Same as the HEVC bitstream syntax element. */ + uint8_t aspect_ratio_idc; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t sar_width; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t sar_height; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t vui_num_units_in_tick; + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t vui_time_scale; + /** \brief Same as the HEVC bitstream syntax element. */ + uint16_t min_spatial_segmentation_idc; + /** \brief Same as the HEVC bitstream syntax element. */ + uint8_t max_bytes_per_pic_denom; + /** \brief Same as the HEVC bitstream syntax element. */ + uint8_t max_bits_per_min_cu_denom; + + /** \brief SCC flags to enable/disable features, including IBC and palette mode at present.*/ + union { + struct { + /** \brief Same as the HEVC bitstream syntax element. */ + uint32_t palette_mode_enabled_flag : 1; + /** \brief Reserved bits for future use, must be zero */ + uint32_t reserved : 31; + } bits; + uint32_t value; + } scc_fields; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM - 1]; + /**@}*/ +} VAEncSequenceParameterBufferHEVC; + +/**************************** + * HEVC data structures + ****************************/ +/** + * \brief Picture parameter for HEVC encoding in main & main 10 + * profiles. + * + * This structure holds information for \c pic_parameter_set_rbsp() as + * defined by the HEVC specification. + * + * If packed picture headers mode is used, i.e. if the encoding + * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE + * flag, then the driver expects two more buffers to be provided to + * the same \c vaRenderPicture() as this buffer: + * - a #VAEncPackedHeaderParameterBuffer with type set to + * VAEncPackedHeaderType::VAEncPackedHeaderPicture ; + * - a #VAEncPackedHeaderDataBuffer which holds the actual packed + * header data. + * + * If \c pic_scaling_matrix_present_flag is set to \c 1, then a + * #VAQMatrixBufferHEVC buffer shall also be provided within the same + * \c vaRenderPicture() call as this picture parameter buffer. + */ +typedef struct _VAEncPictureParameterBufferHEVC { + /** + * \brief Information about the picture to be encoded. + * + * See #VAPictureHEVC for further description of each field. + * Note that decoded_curr_pic.picture_id represents the reconstructed + * (decoded) picture. User provides a scratch VA surface ID here. + * Long term reference and RPS related fields should be set to 0 + * and ignored. + */ + VAPictureHEVC decoded_curr_pic; + /** + * \brief Decoded Picture Buffer (DPB). + * + * This array represents the list of reconstructed (decoded) + * frames used as reference. It is important to keep track of + * reconstructed frames so that they can be used later on as + * reference for P or B-frames encoding. + */ + VAPictureHEVC reference_frames[15]; + /** + * \brief Output encoded bitstream. + * + * \ref coded_buf has type #VAEncCodedBufferType. It should be + * large enough to hold the compressed NAL slice and possibly VPS, SPS + * and PPS NAL units, and other NAL units such as SEI. + */ + VABufferID coded_buf; + + /** \brief collocated reference picture buffer index of ReferenceFrames[]. + * Please note it is different from HEVC syntac element collocated_ref_idx. + * When the HEVC syntax element slice_temporal_mvp_enable_flag takes value 0, + * collocated_ref_pic_index should take value 0xFF. . + * Range: [0..14, 0xFF] + */ + uint8_t collocated_ref_pic_index; + + /** + * \brief OR'd flags describing whether the picture is the last one or not. + * + * This fields holds 0 if the picture to be encoded is not the last + * one in the stream or sequence. Otherwise, it is a combination of + * \ref HEVC_LAST_PICTURE_EOSEQ or \ref HEVC_LAST_PICTURE_EOSTREAM. + */ + uint8_t last_picture; + + /** \brief \c init_qp_minus26 + 26. */ + uint8_t pic_init_qp; + + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint8_t diff_cu_qp_delta_depth; + + /** \brief Corresponds to HEVC syntax element of the same name. */ + int8_t pps_cb_qp_offset; + + /** \brief Corresponds to HEVC syntax element of the same name. */ + int8_t pps_cr_qp_offset; + + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint8_t num_tile_columns_minus1; + + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint8_t num_tile_rows_minus1; + + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint8_t column_width_minus1[19]; + + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint8_t row_height_minus1[21]; + + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint8_t log2_parallel_merge_level_minus2; + + /** \brief Application may set the CTU bit size limit based on + * spec requirement (A.3.2), or other value for special purpose. + * If the value is set 0, no bit size limit is checked. + */ + uint8_t ctu_max_bitsize_allowed; + + /** \brief Maximum reference index for reference picture list 0. + * value range: [0..14]. + */ + uint8_t num_ref_idx_l0_default_active_minus1; + + /** \brief Maximum reference index for reference picture list 1. + * value range: [0..14]. + */ + uint8_t num_ref_idx_l1_default_active_minus1; + + /** \brief PPS header + * Used by GPU to generate new slice headers in slice size control. + * value range: [0..63]. + */ + uint8_t slice_pic_parameter_set_id; + + /** \brief NAL unit type + * Used by GPU to generate new slice headers in slice size control. + * value range: [0..63]. + */ + uint8_t nal_unit_type; + + union { + struct { + /** \brief Is picture an IDR picture? */ + uint32_t idr_pic_flag : 1; + /** \brief Picture type. + * I - 1; + * P - 2; + * B - 3; + * B1 - 4; + * B2 - 5; + * B1 and B2 are frame types for hierachical B, explanation + * can refer to num_b_in_gop[]. + */ + uint32_t coding_type : 3; + /** \brief Is picture a reference picture? */ + uint32_t reference_pic_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t dependent_slice_segments_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t sign_data_hiding_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t constrained_intra_pred_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t transform_skip_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t cu_qp_delta_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t weighted_pred_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t weighted_bipred_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t transquant_bypass_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t tiles_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t entropy_coding_sync_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t loop_filter_across_tiles_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t pps_loop_filter_across_slices_enabled_flag : 1; + /** \brief A combination of HEVC syntax element of + * sps_scaling_list_data_present_flag and + * pps_scaling_list_data_present_flag + * when scaling_list_enable_flag is 0, it must be 0. + */ + uint32_t scaling_list_data_present_flag : 1; + /** \brief indicate the current picture contains significant + * screen contents (text, characters, etc.) or animated image. + * GPU may want to treat them differently from normal video. + * For example, encoder may choose a small transform unit size + * and may use transform skip mode. + */ + uint32_t screen_content_flag : 1; + /** + * When either weighted_pred_flag or weighted_bipred_flag is + * turned on, the flag enable_gpu_weighted_prediction requests + * GPU to determine weighted prediction factors. In this case, + * the following parameters in slice control data structure + * shall be ignored: + * luma_log2_weight_denom, delta_chroma_log2_weight_denom, + * luma_offset_l0[15], luma_offset_l1[15], + * delta_luma_weight_l0[15], delta_luma_weight_l1[15], + * chroma_offset_l0[15][2], chroma_offset_l1[15][2], + * and delta_chroma_weight_l0[15][2], delta_chroma_weight_l1[15][2]. + */ + uint32_t enable_gpu_weighted_prediction : 1; + /** \brief HEVC syntax element in slice segment header + * GPU uses it to generate new slice headers in slice size control. + */ + uint32_t no_output_of_prior_pics_flag : 1; + uint32_t reserved : 11; + } bits; + uint32_t value; + } pic_fields; + + /** \brief When hierachical_level_plus1 > 0, hierachical_level_plus1-1 indicates + *the current frame's level.when it > 0. B1, B2 setting in CodingType can be treated as B, + *hirachical level is determined by this variable.When hierachical_level_plus1 == 0, + *hierarchical level information still comes from coding_type. + */ + uint8_t hierarchical_level_plus1; + /** \brief Reserved bytes for future use, must be zero */ + uint8_t va_byte_reserved; + /** \brief SCC flags to enable/disable feature, only IBC at present.*/ + union { + struct { + /** \brief Same as the HEVC bitstream syntax element. */ + uint16_t pps_curr_pic_ref_enabled_flag : 1; + /** \brief Reserved bits for future use, must be zero */ + uint16_t reserved : 15; + } bits; + uint16_t value; + } scc_fields; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_HIGH - 1]; +} VAEncPictureParameterBufferHEVC; + +/** + * \brief Slice parameter for HEVC encoding in main & main 10 profiles. + * + * This structure holds information for \c + * slice_segment_layer_rbsp() as defined by the HEVC + * specification. + * + * If packed slice headers mode is used, i.e. if the encoding + * pipeline was configured with the #VA_ENC_PACKED_HEADER_SLICE + * flag, then the driver expects two more buffers to be provided to + * the same \c vaRenderPicture() as this buffer: + * - a #VAEncPackedHeaderParameterBuffer with type set to + * VAEncPackedHeaderType::VAEncPackedHeaderSlice ; + * - a #VAEncPackedHeaderDataBuffer which holds the actual packed + * header data. + * + */ +typedef struct _VAEncSliceParameterBufferHEVC { + /** \brief Starting CTU address for this slice. */ + uint32_t slice_segment_address; + /** \brief Number of CTUs in this slice. */ + uint32_t num_ctu_in_slice; + + /** \brief Slice type. + * Corresponds to HEVC syntax element of the same name. + */ + uint8_t slice_type; + /** \brief Same as the HEVC bitstream syntax element. */ + uint8_t slice_pic_parameter_set_id; + + /** \brief Maximum reference index for reference picture list 0. + * Range: 0 to 14, inclusive. + */ + uint8_t num_ref_idx_l0_active_minus1; + /** \brief Maximum reference index for reference picture list 1. + * Range: 0 to 14, inclusive. + */ + uint8_t num_ref_idx_l1_active_minus1; + /** \brief Reference picture list 0 (for P slices). */ + VAPictureHEVC ref_pic_list0[15]; + /** \brief Reference picture list 1 (for B slices). */ + VAPictureHEVC ref_pic_list1[15]; + /**@}*/ + + /** @name pred_weight_table() */ + /**@{*/ + /** \brief Same as the HEVC bitstream syntax element. */ + uint8_t luma_log2_weight_denom; + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t delta_chroma_log2_weight_denom; + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t delta_luma_weight_l0[15]; + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t luma_offset_l0[15]; + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t delta_chroma_weight_l0[15][2]; + /** \brief Same as the HEVC spec variable ChromaOffsetL0[]. */ + int8_t chroma_offset_l0[15][2]; + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t delta_luma_weight_l1[15]; + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t luma_offset_l1[15]; + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t delta_chroma_weight_l1[15][2]; + /** \brief Same as the HEVC spec variable ChromaOffsetL1[]. */ + int8_t chroma_offset_l1[15][2]; + /**@}*/ + + /** \brief Corresponds to HEVC spec variable MaxNumMergeCand. + * Range: [1..5]. + */ + uint8_t max_num_merge_cand; + + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t slice_qp_delta; + + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t slice_cb_qp_offset; + + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t slice_cr_qp_offset; + + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t slice_beta_offset_div2; + + /** \brief Same as the HEVC bitstream syntax element. */ + int8_t slice_tc_offset_div2; + + union { + struct { + /** \brief Indicates if current slice is the last one in picture */ + uint32_t last_slice_of_pic_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name */ + uint32_t dependent_slice_segment_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name */ + uint32_t colour_plane_id : 2; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t slice_temporal_mvp_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t slice_sao_luma_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t slice_sao_chroma_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. + * if this flag is set to 0, num_ref_idx_l0_active_minus1 should be + * equal to num_ref_idx_l0_default_active_minus1 + * as well as for that for l1. + */ + uint32_t num_ref_idx_active_override_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t mvd_l1_zero_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t cabac_init_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t slice_deblocking_filter_disabled_flag : 2; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t slice_loop_filter_across_slices_enabled_flag : 1; + /** \brief Corresponds to HEVC syntax element of the same name. */ + uint32_t collocated_from_l0_flag : 1; + } bits; + uint32_t value; + } slice_fields; + + + /** + * \brief bit offset of syntax element pred_weight_table() in slice segment header. + * It aligns with the starting position of the current packed slice header. + * It is used when encoder prefers to override the weighted prediction parameters passed in + * from application. + * Please refer to enable_gpu_weighted_prediction in VAEncPictureParameterBufferHEVC. + */ + uint32_t pred_weight_table_bit_offset; + /** + * \brief bit length of syntax element pred_weight_table() in slice segment header. + * It is used when encoder prefers to override the weighted prediction parameters passed in + * from application. + * Please refer to enable_gpu_weighted_prediction in VAEncPictureParameterBufferHEVC. + */ + uint32_t pred_weight_table_bit_length; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM - 2]; + /**@}*/ +} VAEncSliceParameterBufferHEVC; + +/** + * \brief HEVC Quantization Matrix Buffer Structure + * + * This structure is sent once per frame, + * and only when scaling_list_enabled_flag = 1 and scaling_list_data_present_flag = 1. + * Only when scaling_list_data_present_flag = 1, app still + * needs to send in this structure. When scaling_list_enabled_flag = 1 and + * scaling_list_data_present_flag = 0, driver is responsible to generate + * the default scaling list values. + * + * Matrix entries are in raster scan order which follows HEVC spec. + */ +typedef struct _VAQMatrixBufferHEVC { + /** + * \brief scaling lists, + * corresponds to same HEVC spec syntax element + * ScalingList[ i ][ MatrixID ][ j ]. + * + * \brief 4x4 scaling, + */ + uint8_t scaling_lists_4x4[3][2][16]; + /** + * \brief 8x8 scaling, + */ + uint8_t scaling_lists_8x8[3][2][64]; + /** + * \brief 16x16 scaling, + * correspongs i = 2, MatrixID is in the range of 0 to 5, + * inclusive. And j is in the range of 0 to 63, inclusive. + */ + uint8_t scaling_lists_16x16[3][2][64]; + /** + * \brief 32x32 scaling, + * correspongs i = 3, MatrixID is in the range of 0 to 1, + * inclusive. And j is in the range of 0 to 63, inclusive. + */ + uint8_t scaling_lists_32x32[2][64]; + /** + * \brief DC values of the 16x16 scaling lists, + * corresponds to HEVC spec syntax + * scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8 + * with sizeID = 2 and matrixID in the range of 0 to 5, inclusive. + */ + uint8_t scaling_list_dc_16x16[3][2]; + /** + * \brief DC values of the 32x32 scaling lists, + * corresponds to HEVC spec syntax + * scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8 + * with sizeID = 3 and matrixID in the range of 0 to 1, inclusive. + */ + uint8_t scaling_list_dc_32x32[2]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAQMatrixBufferHEVC; + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_ENC_HEVC_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_jpeg.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_jpeg.h new file mode 100644 index 00000000..ec02191c --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_jpeg.h @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2007-2013 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_enc_jpeg.h + * \brief JPEG encoding API + * + * This file contains the \ref api_enc_jpeg "JPEG encoding API". + */ + +#ifndef VA_ENC_JPEG_H +#define VA_ENC_JPEG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_enc_jpeg JPEG encoding API + * + * @{ + */ + +/** + * \brief JPEG Encoding Picture Parameter Buffer Structure + * + * This structure conveys picture level parameters. + * + */ +typedef struct _VAEncPictureParameterBufferJPEG { + /** \brief holds reconstructed picture. */ + VASurfaceID reconstructed_picture; + /** \brief picture width. */ + uint16_t picture_width; + /** \brief picture height. */ + uint16_t picture_height; + /** \brief holds coded data. */ + VABufferID coded_buf; + + /** + * \brief pic_flags + * + */ + union { + struct { + /** + * \brief profile: + * 0 - Baseline, 1 - Extended, 2 - Lossless, 3 - Hierarchical + */ + uint32_t profile : 2; + /** + * \brief progressive: + * 0 - sequential, 1 - extended, 2 - progressive + */ + uint32_t progressive : 1; + /** + * \brief huffman: + * 0 - arithmetic, 1 - huffman + */ + uint32_t huffman : 1; + /** + * \brief interleaved: + * 0 - non interleaved, 1 - interleaved + */ + uint32_t interleaved : 1; + /** + * \brief differential: + * 0 - non differential, 1 - differential + */ + uint32_t differential : 1; + } bits; + uint32_t value; + } pic_flags; + + /** \brief number of bits per sample. */ + uint8_t sample_bit_depth; + /** \brief total number of scans in image. */ + uint8_t num_scan; + /** \brief number of image components in frame. */ + uint16_t num_components; + /** \brief Component identifier (Ci). */ + uint8_t component_id[4]; + /** \brief Quantization table selector (Tqi). */ + uint8_t quantiser_table_selector[4]; + /** \brief number from 1 to 100 that specifies quality of image. */ + uint8_t quality; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncPictureParameterBufferJPEG; + + +/** + * \brief Slice parameter for JPEG encoding. + * + * This structure conveys slice (scan) level parameters. + * + */ +typedef struct _VAEncSliceParameterBufferJPEG { + /** \brief Restart interval definition (Ri). */ + uint16_t restart_interval; + /** \brief number of image components in a scan. */ + uint16_t num_components; + struct { + /** \brief Scan component selector (Csj). */ + uint8_t component_selector; + /** \brief DC entropy coding table selector (Tdj). */ + uint8_t dc_table_selector; + /** \brief AC entropy coding table selector (Taj). */ + uint8_t ac_table_selector; + } components[4]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSliceParameterBufferJPEG; + +/** + * \brief Quantization table for JPEG encoding. + * + */ +typedef struct _VAQMatrixBufferJPEG { + /** \brief load luma quantization table. */ + int32_t load_lum_quantiser_matrix; + /** \brief load chroma quantization table. */ + int32_t load_chroma_quantiser_matrix; + /** \brief luma quantization table. */ + uint8_t lum_quantiser_matrix[64]; + /** \brief chroma quantization table. */ + uint8_t chroma_quantiser_matrix[64]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAQMatrixBufferJPEG; + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_ENC_JPEG_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_mpeg2.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_mpeg2.h new file mode 100644 index 00000000..669df032 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_mpeg2.h @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2012 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_enc_mpeg2.h + * \brief The MPEG-2 encoding API + * + * This file contains the \ref api_enc_mpeg2 "MPEG-2 encoding API". + */ + +#ifndef _VA_ENC_MPEG2_H_ +#define _VA_ENC_MPEG2_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_enc_mpeg2 MPEG-2 encoding API + * + * @{ + */ + +/** + * \brief MPEG-2 Quantization Matrix Buffer + * + */ +typedef VAIQMatrixBufferMPEG2 VAQMatrixBufferMPEG2; + +/** + * \brief Packed header types specific to MPEG-2 encoding. + * + * Types of packed headers generally used for MPEG-2 encoding. + */ +typedef enum { + /** + * \brief Packed Sequence Parameter Set (SPS). + * + */ + VAEncPackedHeaderMPEG2_SPS = VAEncPackedHeaderSequence, + /** + * \brief Packed Picture Parameter Set (PPS). + * + */ + VAEncPackedHeaderMPEG2_PPS = VAEncPackedHeaderPicture, + /** + * \brief Packed slice header. + * + */ + VAEncPackedHeaderMPEG2_Slice = VAEncPackedHeaderSlice, +} VAEncPackedHeaderTypeMPEG2; + +/** + * \brief Sequence parameter for MPEG-2 encoding + * + * This structure holds information for \c sequence_header() and + * sequence_extension(). + * + * If packed sequence headers mode is used, i.e. if the encoding + * pipeline was configured with the #VA_ENC_PACKED_HEADER_SEQUENCE + * flag, then the driver expects two more buffers to be provided to + * the same \c vaRenderPicture() as this buffer: + * - a #VAEncPackedHeaderParameterBuffer with type set to + * VAEncPackedHeaderType::VAEncPackedHeaderSequence ; + * - a #VAEncPackedHeaderDataBuffer which holds the actual packed + * header data. + * + */ +typedef struct _VAEncSequenceParameterBufferMPEG2 { + /** \brief Period between I frames. */ + uint32_t intra_period; + /** \brief Period between I/P frames. */ + uint32_t ip_period; + /** \brief Picture width. + * + * A 14bits unsigned inter, the lower 12bits + * is horizontal_size_value, and the upper + * 2bits is \c horizontal_size_extension + * + */ + uint16_t picture_width; + /** \brief Picture height. + * + * A 14bits unsigned inter, the lower 12bits + * is vertical_size_value, and the upper 2bits is + * vertical_size_size_extension + * + */ + uint16_t picture_height; + /** + * \brief Initial bitrate set for this sequence in CBR or VBR modes. + * + * This field represents the initial bitrate value for this + * sequence if CBR or VBR mode is used, i.e. if the encoder + * pipeline was created with a #VAConfigAttribRateControl + * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR. + * + * bits_per_second may be derived from bit_rate. + * + */ + uint32_t bits_per_second; + /** + * \brief Frame rate + * + * Derived from frame_rate_value, frame_rate_extension_n and + * frame_rate_extension_d + * + */ + float frame_rate; + /** \brief Same as the element in sequence_header() */ + uint16_t aspect_ratio_information; + /** \brief Define the size of VBV */ + uint32_t vbv_buffer_size; + + union { + struct { + /** \brief Same as the element in Sequence extension() */ + uint32_t profile_and_level_indication : 8; + /** \brief Same as the element in Sequence extension() */ + uint32_t progressive_sequence : 1; + /** \brief Same as the element in Sequence extension() */ + uint32_t chroma_format : 2; + /** \brief Same as the element in Sequence extension() */ + uint32_t low_delay : 1; + /** \brief Same as the element in Sequence extension() */ + uint32_t frame_rate_extension_n : 2; + /** \brief Same as the element in Sequence extension() */ + uint32_t frame_rate_extension_d : 5; + } bits; + uint32_t value; + } sequence_extension; + + /** \brief Flag to indicate the following GOP header are being updated */ + uint32_t new_gop_header; + + union { + struct { + /** \brief Time code */ + uint32_t time_code : 25; + /** \brief Same as the element in GOP header */ + uint32_t closed_gop : 1; + /** \brief SAme as the element in GOP header */ + uint32_t broken_link : 1; + } bits; + uint32_t value; + } gop_header; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSequenceParameterBufferMPEG2; + +/** + * \brief Picture parameter for MPEG-2 encoding + * + * This structure holds information for picture_header() and + * picture_coding_extension() + * + * If packed picture headers mode is used, i.e. if the encoding + * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE + * flag, then the driver expects two more buffers to be provided to + * the same \c vaRenderPicture() as this buffer: + * - a #VAEncPackedHeaderParameterBuffer with type set to + * VAEncPackedHeaderType::VAEncPackedHeaderPicture ; + * - a #VAEncPackedHeaderDataBuffer which holds the actual packed + * header data. + * + */ +typedef struct _VAEncPictureParameterBufferMPEG2 { + /** \brief Forward reference picture */ + VASurfaceID forward_reference_picture; + /** \brief Backward reference picture */ + VASurfaceID backward_reference_picture; + /** \brief Reconstructed(decoded) picture */ + VASurfaceID reconstructed_picture; + /** + * \brief Output encoded bitstream. + * + * \ref coded_buf has type #VAEncCodedBufferType. It should be + * large enough to hold the compressed NAL slice and possibly SPS + * and PPS NAL units. + */ + VABufferID coded_buf; + /** + * \brief Flag to indicate the picture is the last one or not. + * + * This fields holds 0 if the picture to be encoded is not + * the last one in the stream. Otherwise, it + * is \ref MPEG2_LAST_PICTURE_EOSTREAM. + */ + uint8_t last_picture; + /** \brief Picture type */ + VAEncPictureType picture_type; + /** \brief Same as the element in picture_header() */ + uint32_t temporal_reference; + /** \brief Same as the element in picture_header() */ + uint32_t vbv_delay; + /** \brief Same as the element in Picture coding extension */ + uint8_t f_code[2][2]; + union { + struct { + /** \brief Same as the element in Picture coding extension */ + uint32_t intra_dc_precision : 2; + /** \brief Same as the element in Picture coding extension */ + uint32_t picture_structure : 2; + /** \brief Same as the element in Picture coding extension */ + uint32_t top_field_first : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t frame_pred_frame_dct : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t concealment_motion_vectors : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t q_scale_type : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t intra_vlc_format : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t alternate_scan : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t repeat_first_field : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t progressive_frame : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t composite_display_flag : 1; + } bits; + uint32_t value; + } picture_coding_extension; + + /* \brief Parameters for composite display + * + * Valid only when omposite_display_flag is 1 + */ + union { + struct { + /** \brief Same as the element in Picture coding extension */ + uint32_t v_axis : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t field_sequence : 3; + /** \brief Same as the element in Picture coding extension */ + uint32_t sub_carrier : 1; + /** \brief Same as the element in Picture coding extension */ + uint32_t burst_amplitude : 7; + /** \brief Same as the element in Picture coding extension */ + uint32_t sub_carrier_phase : 8; + } bits; + uint32_t value; + } composite_display; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncPictureParameterBufferMPEG2; + +/** + * \brief Slice parameter for MPEG-2 encoding + * + */ +typedef struct _VAEncSliceParameterBufferMPEG2 { + /** \brief Starting MB address for this slice. */ + uint32_t macroblock_address; + /** \brief Number of macroblocks in this slice. */ + uint32_t num_macroblocks; + /** \brief Same as the element in slice() */ + int32_t quantiser_scale_code; + /** \brief Flag to indicate intra slice */ + int32_t is_intra_slice; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSliceParameterBufferMPEG2; + +typedef struct _VAEncMiscParameterExtensionDataSeqDisplayMPEG2 { + /** should always be 0x02 to identify it is Sequence Display Extension ISO-13818 */ + uint8_t extension_start_code_identifier; + /** these field should follow ISO-13818 6.3.6 */ + uint8_t video_format; + uint8_t colour_description; + uint8_t colour_primaries; + uint8_t transfer_characteristics; + uint8_t matrix_coefficients; + uint16_t display_horizontal_size; + uint16_t display_vertical_size; +} VAEncMiscParameterExtensionDataSeqDisplayMPEG2; +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _VA_ENC_MPEG2_H_ */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_vp8.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_vp8.h new file mode 100644 index 00000000..84ce05f4 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_vp8.h @@ -0,0 +1,350 @@ +/* + * Copyright (c) 2007-2012 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_enc_vp8.h + * \brief VP8 encoding API + * + * This file contains the \ref api_enc_vp8 "VP8 encoding API". + */ + +#ifndef VA_ENC_VP8_H +#define VA_ENC_VP8_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_enc_vp8 VP8 encoding API + * + * @{ + */ + +/** + * \brief VP8 Encoding Sequence Parameter Buffer Structure + * + * This structure conveys sequence level parameters. + * + */ +typedef struct _VAEncSequenceParameterBufferVP8 { + /* frame width in pixels */ + uint32_t frame_width; + /* frame height in pixels */ + uint32_t frame_height; + /* horizontal scale */ + uint32_t frame_width_scale; + /* vertical scale */ + uint32_t frame_height_scale; + + /* whether to enable error resilience features */ + uint32_t error_resilient; + /* auto keyframe placement, non-zero means enable auto keyframe placement */ + uint32_t kf_auto; + /* keyframe minimum interval */ + uint32_t kf_min_dist; + /* keyframe maximum interval */ + uint32_t kf_max_dist; + + + /* RC related fields. RC modes are set with VAConfigAttribRateControl */ + /* For VP8, CBR implies HRD conformance and VBR implies no HRD conformance */ + + /** + * Initial bitrate set for this sequence in CBR or VBR modes. + * + * This field represents the initial bitrate value for this + * sequence if CBR or VBR mode is used, i.e. if the encoder + * pipeline was created with a #VAConfigAttribRateControl + * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR. + * + * The bitrate can be modified later on through + * #VAEncMiscParameterRateControl buffers. + */ + uint32_t bits_per_second; + /* Period between I frames. */ + uint32_t intra_period; + + /* reference and reconstructed frame buffers + * Used for driver auto reference management when configured through + * VAConfigAttribEncAutoReference. + */ + VASurfaceID reference_frames[4]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSequenceParameterBufferVP8; + + +/** + * \brief VP8 Encoding Picture Parameter Buffer Structure + * + * This structure conveys picture level parameters. + * + */ +typedef struct _VAEncPictureParameterBufferVP8 { + /* surface to store reconstructed frame */ + VASurfaceID reconstructed_frame; + + /* + * surfaces to store reference frames in non auto reference mode + * VA_INVALID_SURFACE can be used to denote an invalid reference frame. + */ + VASurfaceID ref_last_frame; + VASurfaceID ref_gf_frame; + VASurfaceID ref_arf_frame; + + /* buffer to store coded data */ + VABufferID coded_buf; + + union { + struct { + /* force this frame to be a keyframe */ + uint32_t force_kf : 1; + /* don't reference the last frame */ + uint32_t no_ref_last : 1; + /* don't reference the golden frame */ + uint32_t no_ref_gf : 1; + /* don't reference the alternate reference frame */ + uint32_t no_ref_arf : 1; + /* The temporal id the frame belongs to. */ + uint32_t temporal_id : 8; + /** + * following two flags indicate the reference order + * LastRef is specified by 01b; + * GoldRef is specified by 10b; + * AltRef is specified by 11b; + * first_ref specifies the reference frame which is searched first. + * second_ref specifies the reference frame which is searched second + * if there is. + */ + uint32_t first_ref : 2; + uint32_t second_ref : 2; + /** \brief Reserved for future use, must be zero */ + uint32_t reserved : 16; + } bits; + uint32_t value; + } ref_flags; + + union { + struct { + /* version */ + uint32_t frame_type : 1; + uint32_t version : 3; + /* show_frame */ + uint32_t show_frame : 1; + /* color_space */ + uint32_t color_space : 1; + /* 0: bicubic, 1: bilinear, other: none */ + uint32_t recon_filter_type : 2; + /* 0: no loop fitler, 1: simple loop filter */ + uint32_t loop_filter_type : 2; + /* 0: disabled, 1: normal, 2: simple */ + uint32_t auto_partitions : 1; + /* same as log2_nbr_of_dct_partitions in frame header syntax */ + uint32_t num_token_partitions : 2; + + /** + * The following fields correspond to the same VP8 syntax elements + * in the frame header. + */ + /** + * 0: clamping of reconstruction pixels is disabled, + * 1: clamping enabled. + */ + uint32_t clamping_type : 1; + /* indicate segmentation is enabled for the current frame. */ + uint32_t segmentation_enabled : 1; + /** + * Determines if the MB segmentation map is updated in the current + * frame. + */ + uint32_t update_mb_segmentation_map : 1; + /** + * Indicates if the segment feature data is updated in the current + * frame. + */ + uint32_t update_segment_feature_data : 1; + /** + * indicates if the MB level loop filter adjustment is enabled for + * the current frame (0 off, 1 on). + */ + uint32_t loop_filter_adj_enable : 1; + /** + * Determines whether updated token probabilities are used only for + * this frame or until further update. + * It may be used by application to enable error resilient mode. + * In this mode probability updates are allowed only at Key Frames. + */ + uint32_t refresh_entropy_probs : 1; + /** + * Determines if the current decoded frame refreshes the golden frame. + */ + uint32_t refresh_golden_frame : 1; + /** + * Determines if the current decoded frame refreshes the alternate + * reference frame. + */ + uint32_t refresh_alternate_frame : 1; + /** + * Determines if the current decoded frame refreshes the last frame + * reference buffer. + */ + uint32_t refresh_last : 1; + /** + * Determines if the golden reference is replaced by another reference. + */ + uint32_t copy_buffer_to_golden : 2; + /** + * Determines if the alternate reference is replaced by another reference. + */ + uint32_t copy_buffer_to_alternate : 2; + /** + * Controls the sign of motion vectors when the golden frame is referenced. + */ + uint32_t sign_bias_golden : 1; + /** + * Controls the sign of motion vectors when the alternate frame is + * referenced. + */ + uint32_t sign_bias_alternate : 1; + /** + * Enables or disables the skipping of macroblocks containing no + * non-zero coefficients. + */ + uint32_t mb_no_coeff_skip : 1; + /** + * Enforces unconditional per-MB loop filter delta update setting frame + * header flags mode_ref_lf_delta_update, all mb_mode_delta_update_flag[4], + * and all ref_frame_delta_update_flag[4] to 1. + * Since loop filter deltas are not automatically refreshed to default + * values at key frames, dropped frame with delta update may prevent + * correct decoding from the next key frame. + * Encoder application is advised to set this flag to 1 at key frames. + */ + uint32_t forced_lf_adjustment : 1; + uint32_t reserved : 2; + } bits; + uint32_t value; + } pic_flags; + + /** + * Contains a list of 4 loop filter level values (updated value if applicable) + * controlling the deblocking filter strength. Each entry represents a segment. + * When segmentation is disabled, use entry 0. + * When loop_filter_level is 0, loop filter shall be disabled. + */ + int8_t loop_filter_level[4]; + + /** + * Contains a list of 4 delta values for reference frame based MB-level + * loop filter adjustment. + * If no update, then set to 0. + */ + int8_t ref_lf_delta[4]; + + /** + * Contains a list of 4 delta values for coding mode based MB-level loop + * filter adjustment. + * If no update, then set to 0. + */ + int8_t mode_lf_delta[4]; + + /** + * Controls the deblocking filter sensitivity. + * Corresponds to the same VP8 syntax element in frame header. + */ + uint8_t sharpness_level; + + /** + * Application supplied maximum clamp value for Qindex used in quantization. + * Qindex will not be allowed to exceed this value. + * It has a valid range [0..127] inclusive. + */ + uint8_t clamp_qindex_high; + + /** + * Application supplied minimum clamp value for Qindex used in quantization. + * Qindex will not be allowed to be lower than this value. + * It has a valid range [0..127] inclusive. + * Condition clamp_qindex_low <= clamp_qindex_high must be guaranteed, + * otherwise they are ignored. + */ + uint8_t clamp_qindex_low; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncPictureParameterBufferVP8; + + +/** + * \brief VP8 MB Segmentation ID Buffer + * + * application provides buffer containing the initial segmentation id for each + * MB, in raster scan order. Rate control may reassign it. + * For an 640x480 video, the buffer has 1200 entries. + * the value of each entry should be in the range [0..3], inclusive. + * If segmentation is not enabled, application does not need to provide it. + */ +typedef struct _VAEncMBMapBufferVP8 { + /** + * number of MBs in the frame. + * It is also the number of entries of mb_segment_id[]; + */ + uint32_t num_mbs; + /** + * per MB Segmentation ID Buffer + */ + uint8_t *mb_segment_id; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMBMapBufferVP8; + + +/** + * \brief VP8 Quantization Matrix Buffer Structure + * + * Contains quantization index for yac(0-3) for each segment and quantization + * index deltas, ydc(0), y2dc(1), y2ac(2), uvdc(3), uvac(4) that are applied + * to all segments. When segmentation is disabled, only quantization_index[0] + * will be used. This structure is sent once per frame. + */ +typedef struct _VAQMatrixBufferVP8 { + uint16_t quantization_index[4]; + int16_t quantization_index_delta[5]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAQMatrixBufferVP8; + + + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_ENC_VP8_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_vp9.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_vp9.h new file mode 100644 index 00000000..107ab0c9 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_enc_vp9.h @@ -0,0 +1,603 @@ +/* + * Copyright (c) 2007-2015 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_enc_vp9.h + * \brief VP9 encoding API + * + * This file contains the \ref api_enc_vp9 "VP9 encoding API". + * + */ + +#ifndef VA_ENC_VP9_H +#define VA_ENC_VP9_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_enc_vp9 VP9 encoding API + * + * @{ + */ + +/** + * \brief VP9 Encoding Status Data Buffer Structure + * + * This structure is used to convey status data from encoder to application. + * Driver allocates VACodedBufferVP9Status as a private data buffer. + * Driver encapsulates the status buffer with a VACodedBufferSegment, + * and sets VACodedBufferSegment.status to be VA_CODED_BUF_STATUS_CODEC_SPECIFIC. + * And driver associates status data segment to the bit stream buffer segment + * by setting VACodedBufferSegment.next of coded_buf (bit stream) to the private + * buffer segment of status data. + * Application accesses it by calling VAMapBuffer() with VAEncCodedBufferType. + */ +typedef struct _VACodedBufferVP9Status { + /** Final quantization index used (yac), determined by BRC. + * Application is providing quantization index deltas + * ydc(0), y2dc(1), y2ac(2), uvdc(3), uvac(4) that are applied to all segments + * and segmentation qi deltas, they will not be changed by BRC. + */ + uint16_t base_qp_index; + + /** Final loopfilter levels for the frame, if segmentation is disabled only + * index 0 is used. + * If loop_filter_level is 0, it indicates loop filter is disabled. + */ + uint8_t loop_filter_level; + + /** + * Long term reference frame indication from BRC. BRC recommends the + * current frame that is being queried is a good candidate for a long + * term reference. + */ + uint8_t long_term_indication; + + /* suggested next frame width */ + uint16_t next_frame_width; + + /* suggested next frame height */ + uint16_t next_frame_height; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VACodedBufferVP9Status; + +/** + * \brief VP9 Encoding Sequence Parameter Buffer Structure + * + * This structure conveys sequence level parameters. + * + */ +typedef struct _VAEncSequenceParameterBufferVP9 { + /** \brief Frame size note: + * Picture resolution may change frame by frame. + * Application needs to allocate surfaces and frame buffers based on + * max frame resolution in case resolution changes for later frames. + * The source and recon surfaces allocated should be 64x64(SB) aligned + * on both horizontal and vertical directions. + * But buffers on the surfaces need to be aligned to CU boundaries. + */ + /* maximum frame width in pixels for the whole sequence */ + uint32_t max_frame_width; + + /* maximum frame height in pixels for the whole sequence */ + uint32_t max_frame_height; + + /* auto keyframe placement, non-zero means enable auto keyframe placement */ + uint32_t kf_auto; + + /* keyframe minimum interval */ + uint32_t kf_min_dist; + + /* keyframe maximum interval */ + uint32_t kf_max_dist; + + + /* RC related fields. RC modes are set with VAConfigAttribRateControl */ + /* For VP9, CBR implies HRD conformance and VBR implies no HRD conformance */ + + /** + * Initial bitrate set for this sequence in CBR or VBR modes. + * + * This field represents the initial bitrate value for this + * sequence if CBR or VBR mode is used, i.e. if the encoder + * pipeline was created with a #VAConfigAttribRateControl + * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR. + * + * The bitrate can be modified later on through + * #VAEncMiscParameterRateControl buffers. + */ + uint32_t bits_per_second; + + /* Period between key frames */ + uint32_t intra_period; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSequenceParameterBufferVP9; + + +/** + * \brief VP9 Encoding Picture Parameter Buffer Structure + * + * This structure conveys picture level parameters. + * + */ +typedef struct _VAEncPictureParameterBufferVP9 { + /** VP9 encoder may support dynamic scaling function. + * If enabled (enable_dynamic_scaling is set), application may request + * GPU encodes picture with a different resolution from the raw source. + * GPU should handle the scaling process of source and + * all reference frames. + */ + /* raw source frame width in pixels */ + uint32_t frame_width_src; + /* raw source frame height in pixels */ + uint32_t frame_height_src; + + /* to be encoded frame width in pixels */ + uint32_t frame_width_dst; + /* to be encoded frame height in pixels */ + uint32_t frame_height_dst; + + /* surface to store reconstructed frame, not used for enc only case */ + VASurfaceID reconstructed_frame; + + /** \brief reference frame buffers + * Each entry of the array specifies the surface index of the picture + * that is referred by current picture or will be referred by any future + * picture. The valid entries take value from 0 to 127, inclusive. + * Non-valid entries, those do not point to pictures which are referred + * by current picture or future pictures, should take value 0xFF. + * Other values are not allowed. + * + * Application should update this array based on the refreshing + * information expected. + */ + VASurfaceID reference_frames[8]; + + /* buffer to store coded data */ + VABufferID coded_buf; + + union { + struct { + /* force this frame to be a keyframe */ + uint32_t force_kf : 1; + + /** \brief Indiates which frames to be used as reference. + * (Ref_frame_ctrl & 0x01) ? 1: last frame as reference frame, 0: not. + * (Ref_frame_ctrl & 0x02) ? 1: golden frame as reference frame, 0: not. + * (Ref_frame_ctrl & 0x04) ? 1: alt frame as reference frame, 0: not. + * L0 is for forward prediction. + * L1 is for backward prediction. + */ + uint32_t ref_frame_ctrl_l0 : 3; + uint32_t ref_frame_ctrl_l1 : 3; + + /** \brief Last Reference Frame index + * Specifies the index to RefFrameList[] which points to the LAST + * reference frame. It corresponds to active_ref_idx[0] in VP9 code. + */ + uint32_t ref_last_idx : 3; + + /** \brief Specifies the Sign Bias of the LAST reference frame. + * It corresponds to ref_frame_sign_bias[LAST_FRAME] in VP9 code. + */ + uint32_t ref_last_sign_bias : 1; + + /** \brief GOLDEN Reference Frame index + * Specifies the index to RefFrameList[] which points to the Golden + * reference frame. It corresponds to active_ref_idx[1] in VP9 code. + */ + uint32_t ref_gf_idx : 3; + + /** \brief Specifies the Sign Bias of the GOLDEN reference frame. + * It corresponds to ref_frame_sign_bias[GOLDEN_FRAME] in VP9 code. + */ + uint32_t ref_gf_sign_bias : 1; + + /** \brief Alternate Reference Frame index + * Specifies the index to RefFrameList[] which points to the Alternate + * reference frame. It corresponds to active_ref_idx[2] in VP9 code. + */ + uint32_t ref_arf_idx : 3; + + /** \brief Specifies the Sign Bias of the ALTERNATE reference frame. + * It corresponds to ref_frame_sign_bias[ALTREF_FRAME] in VP9 code. + */ + uint32_t ref_arf_sign_bias : 1; + + /* The temporal id the frame belongs to */ + uint32_t temporal_id : 8; + + uint32_t reserved : 5; + } bits; + uint32_t value; + } ref_flags; + + union { + struct { + /** + * Indicates if the current frame is a key frame or not. + * Corresponds to the same VP9 syntax element in frame tag. + */ + uint32_t frame_type : 1; + + /** \brief show_frame + * 0: current frame is not for display + * 1: current frame is for display + */ + uint32_t show_frame : 1; + + /** + * The following fields correspond to the same VP9 syntax elements + * in the frame header. + */ + uint32_t error_resilient_mode : 1; + + /** \brief Indicate intra-only for inter pictures. + * Must be 0 for key frames. + * 0: inter frame use both intra and inter blocks + * 1: inter frame use only intra blocks. + */ + uint32_t intra_only : 1; + + /** \brief Indicate high precision mode for Motion Vector prediction + * 0: normal mode + * 1: high precision mode + */ + uint32_t allow_high_precision_mv : 1; + + /** \brief Motion Compensation Filter type + * 0: eight-tap (only this mode is supported now.) + * 1: eight-tap-smooth + * 2: eight-tap-sharp + * 3: bilinear + * 4: switchable + */ + uint32_t mcomp_filter_type : 3; + uint32_t frame_parallel_decoding_mode : 1; + uint32_t reset_frame_context : 2; + uint32_t refresh_frame_context : 1; + uint32_t frame_context_idx : 2; + uint32_t segmentation_enabled : 1; + + /* corresponds to variable temporal_update in VP9 code. + * Indicates whether Segment ID is from bitstream or from previous + * frame. + * 0: Segment ID from bitstream + * 1: Segment ID from previous frame + */ + uint32_t segmentation_temporal_update : 1; + + /* corresponds to variable update_mb_segmentation_map in VP9 code. + * Indicates how hardware determines segmentation ID + * 0: intra block - segment id is 0; + * inter block - segment id from previous frame + * 1: intra block - segment id from bitstream (app or GPU decides) + * inter block - depends on segmentation_temporal_update + */ + uint32_t segmentation_update_map : 1; + + /** \brief Specifies if the picture is coded in lossless mode. + * + * lossless_mode = base_qindex == 0 && y_dc_delta_q == 0 \ + * && uv_dc_delta_q == 0 && uv_ac_delta_q == 0; + * Where base_qindex, y_dc_delta_q, uv_dc_delta_q and uv_ac_delta_q + * are all variables in VP9 code. + * + * When enabled, tx_mode needs to be set to 4x4 only and all + * tu_size in CU record set to 4x4 for entire frame. + * Software also has to program such that final_qindex=0 and + * final_filter_level=0 following the Quant Scale and + * Filter Level Table in Segmentation State section. + * Hardware forces Hadamard Tx when this bit is set. + * When lossless_mode is on, BRC has to be turned off. + * 0: normal mode + * 1: lossless mode + */ + uint32_t lossless_mode : 1; + + /** \brief MV prediction mode. Corresponds to VP9 variable with same name. + * comp_prediction_mode = 0: single prediction ony, + * comp_prediction_mode = 1: compound prediction, + * comp_prediction_mode = 2: hybrid prediction + * + * Not mandatory. App may suggest the setting based on power or + * performance. Kernal may use it as a guildline and decide the proper + * setting on its own. + */ + uint32_t comp_prediction_mode : 2; + + /** \brief Indicate how segmentation is specified + * 0 application specifies segmentation partitioning and + * relevant parameters. + * 1 GPU may decide on segmentation. If application already + * provides segmentation information, GPU may choose to + * honor it and further split into more levels if possible. + */ + uint32_t auto_segmentation : 1; + + /** \brief Indicate super frame syntax should be inserted + * 0 current frame is not encapsulated in super frame structure + * 1 current fame is to be encapsulated in super frame structure. + * super frame index syntax will be inserted by encoder at + * the end of current frame. + */ + uint32_t super_frame_flag : 1; + + uint32_t reserved : 10; + } bits; + uint32_t value; + } pic_flags; + + /** \brief indicate which frames in DPB should be refreshed. + * same syntax and semantic as in VP9 code. + */ + uint8_t refresh_frame_flags; + + /** \brief Base Q index in the VP9 term. + * Added with per segment delta Q index to get Q index of Luma AC. + */ + uint8_t luma_ac_qindex; + + /** + * Q index delta from base Q index in the VP9 term for Luma DC. + */ + int8_t luma_dc_qindex_delta; + + /** + * Q index delta from base Q index in the VP9 term for Chroma AC. + */ + int8_t chroma_ac_qindex_delta; + + /** + * Q index delta from base Q index in the VP9 term for Chroma DC. + */ + int8_t chroma_dc_qindex_delta; + + /** \brief filter level + * Corresponds to the same VP9 syntax element in frame header. + */ + uint8_t filter_level; + + /** + * Controls the deblocking filter sensitivity. + * Corresponds to the same VP9 syntax element in frame header. + */ + uint8_t sharpness_level; + + /** \brief Loop filter level reference delta values. + * Contains a list of 4 delta values for reference frame based block-level + * loop filter adjustment. + * If no update, set to 0. + * value range [-63..63] + */ + int8_t ref_lf_delta[4]; + + /** \brief Loop filter level mode delta values. + * Contains a list of 4 delta values for coding mode based MB-level loop + * filter adjustment. + * If no update, set to 0. + * value range [-63..63] + */ + int8_t mode_lf_delta[2]; + + /** + * Offset from starting position of output bitstream in bits where + * ref_lf_delta[] should be inserted. This offset should cover any metadata + * ahead of uncompressed header in inserted bit stream buffer (the offset + * should be same as that for final output bitstream buffer). + * + * In BRC mode, always insert ref_lf_delta[] (This implies uncompressed + * header should have mode_ref_delta_enabled=1 and mode_ref_delta_update=1). + */ + uint16_t bit_offset_ref_lf_delta; + + /** + * Offset from starting position of output bitstream in bits where + * mode_lf_delta[] should be inserted. + * + * In BRC mode, always insert mode_lf_delta[] (This implies uncompressed + * header should have mode_ref_delta_enabled=1 and mode_ref_delta_update=1). + */ + uint16_t bit_offset_mode_lf_delta; + + /** + * Offset from starting position of output bitstream in bits where (loop) + * filter_level should be inserted. + */ + uint16_t bit_offset_lf_level; + + /** + * Offset from starting position of output bitstream in bits where + * Base Qindex should be inserted. + */ + uint16_t bit_offset_qindex; + + /** + * Offset from starting position of output bitstream in bits where + * First Partition Size should be inserted. + */ + uint16_t bit_offset_first_partition_size; + + /** + * Offset from starting position of output bitstream in bits where + * segmentation_enabled is located in bitstream. When auto_segmentation + * is enabled, GPU uses this offset to locate and update the + * segmentation related information. + */ + uint16_t bit_offset_segmentation; + + /** \brief length in bit of segmentation portion from the location + * in bit stream where segmentation_enabled syntax is coded. + * When auto_segmentation is enabled, GPU uses this bit size to locate + * and update the information after segmentation. + */ + uint16_t bit_size_segmentation; + + + /** \brief log2 of number of tile rows + * Corresponds to the same VP9 syntax element in frame header. + * value range [0..2] + */ + uint8_t log2_tile_rows; + + /** \brief log2 of number of tile columns + * Corresponds to the same VP9 syntax element in frame header. + * value range [0..6] + */ + uint8_t log2_tile_columns; + + /** \brief indicate frame-skip happens + * Application may choose to drop/skip one or mulitple encoded frames or + * to-be-encoded frame due to various reasons such as insufficient + * bandwidth. + * Application uses the following three flags to inform GPU about frame-skip. + * + * value range of skip_frame_flag: [0..2] + * 0 - encode as normal, no skip; + * 1 - one or more frames were skipped by application prior to the + * current frame. Encode the current frame as normal. The driver + * will pass the number_skip_frames and skip_frames_size + * to bit rate control for adjustment. + * 2 - the current frame is to be skipped. Do not encode it but encrypt + * the packed header contents. This is for the secure encoding case + * where application generates a frame of all skipped blocks. + * The packed header will contain the skipped frame. + */ + uint8_t skip_frame_flag; + + /** \brief The number of frames skipped prior to the current frame. + * It includes only the skipped frames that were not counted before, + * and does not include the frame with skip_frame_flag == 2. + * Valid when skip_frame_flag = 1. + */ + uint8_t number_skip_frames; + + /** \brief When skip_frame_flag = 1, the size of the skipped frames in bits. + * It includes only the skipped frames that were not counted before, + * and does not include the frame size with skip_frame_flag = 2. + * When skip_frame_flag = 2, it is the size of the current skipped frame + * that is to be encrypted. + */ + uint32_t skip_frames_size; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_MEDIUM]; +} VAEncPictureParameterBufferVP9; + + +/** + * \brief Per segment parameters + */ +typedef struct _VAEncSegParamVP9 { + union { + struct { + /** \brief Indicates if per segment reference frame indicator is enabled. + * Corresponding to variable feature_enabled when + * j == SEG_LVL_REF_FRAME in function setup_segmentation() VP9 code. + */ + uint8_t segment_reference_enabled : 1; + + /** \brief Specifies per segment reference indication. + * 0: reserved + * 1: Last ref + * 2: golden + * 3: altref + * Value can be derived from variable data when + * j == SEG_LVL_REF_FRAME in function setup_segmentation() VP9 code. + * value range: [0..3] + */ + uint8_t segment_reference : 2; + + /** \brief Indicates if per segment skip mode is enabled. + * Corresponding to variable feature_enabled when + * j == SEG_LVL_SKIP in function setup_segmentation() VP9 code. + */ + uint8_t segment_reference_skipped : 1; + + uint8_t reserved : 4; + + } bits; + uint8_t value; + } seg_flags; + + /** \brief Specifies per segment Loop Filter Delta. + * Must be 0 when segmentation_enabled == 0. + * value range: [-63..63] + */ + int8_t segment_lf_level_delta; + + /** \brief Specifies per segment QIndex Delta. + * Must be 0 when segmentation_enabled == 0. + * value range: [-255..255] + */ + int16_t segment_qindex_delta; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncSegParamVP9; + +/** + * Structure to convey all segment related information. + * If segmentation is disabled, this data structure is still required. + * In this case, only seg_data[0] contains valid data. + * This buffer is sent once per frame. + * + * The buffer is created with VABufferType VAQMatrixBufferType. + * + */ +typedef struct _VAEncMiscParameterTypeVP9PerSegmantParam { + /** + * Parameters for 8 segments. + */ + VAEncSegParamVP9 seg_data[8]; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAEncMiscParameterTypeVP9PerSegmantParam; + + +/** + * \brief VP9 Block Segmentation ID Buffer + * + * The application provides a buffer of VAEncMacroblockMapBufferType containing + * the initial segmentation id for each 8x8 block, one byte each, in raster scan order. + * Rate control may reassign it. For example, a 640x480 video, the buffer has 4800 entries. + * The value of each entry should be in the range [0..7], inclusive. + * If segmentation is not enabled, the application does not need to provide it. + */ + + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_ENC_VP9_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei.h new file mode 100644 index 00000000..5563cc93 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei.h @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2007-2017 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_fei.h + * \brief The FEI encoding common API + */ + +#ifndef VA_FEI_H +#define VA_FEI_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * \defgroup api_fei FEI encoding common API + * + * @{ + */ + +/** + * \brief FEI specific attribute definitions + */ +/** @name Attribute values for VAConfigAttribFEIFunctionType + * + * This is only for VAEntrypointFEI + * The desired type should be passed to driver when creating the configuration. + * If VA_FEI_FUNCTION_ENC_PAK is set, VA_FEI_FUNCTION_ENC and VA_FEI_FUNCTION_PAK + * will be ignored if set also. Combination of VA_FEI_FUNCTION_ENC and VA_FEI_FUNCTION_PAK + * is not valid. If VA_FEI_FUNCTION_ENC is set, there will be no bitstream output. + * If VA_FEI_FUNCTION_PAK is set, two extra input buffers for PAK are needed: + * VAEncFEIMVBufferType and VAEncFEIMBCodeBufferType. + * VA_FEI_FUNCTION_ENC_PAK is recommended for best performance. + * + **/ +/**@{*/ +/** \brief ENC only is supported */ +#define VA_FEI_FUNCTION_ENC 0x00000001 +/** \brief PAK only is supported */ +#define VA_FEI_FUNCTION_PAK 0x00000002 +/** \brief ENC_PAK is supported */ +#define VA_FEI_FUNCTION_ENC_PAK 0x00000004 + +/**@}*/ + +/** \brief Attribute value for VAConfigAttribStats */ +typedef union _VAConfigAttribValStats { + struct { + /** \brief Max number of past reference frames that are supported. */ + uint32_t max_num_past_references : 4; + /** \brief Max number of future reference frames that are supported. */ + uint32_t max_num_future_references : 4; + /** \brief Number of supported output buffers for VAStatsStatisticsParameter->outputs */ + uint32_t num_outputs : 3; + /** \brief Interlaced content is supported */ + uint32_t interlaced : 1; + uint32_t reserved : 20; + } bits; + uint32_t value; +} VAConfigAttribValStats; + +typedef struct _VAPictureStats { + VASurfaceID picture_id; + /* + * see flags below. + */ + uint32_t flags; +} VAPictureStats; +/* flags in VAPictureStats could be one of the following */ +#define VA_PICTURE_STATS_INVALID 0x00000001 +#define VA_PICTURE_STATS_PROGRESSIVE 0x00000000 +#define VA_PICTURE_STATS_TOP_FIELD 0x00000002 +#define VA_PICTURE_STATS_BOTTOM_FIELD 0x00000004 +/** \brief picutre surface content updated indicator. + * The picture surface content is updated, it means temporary buffer like downscaled pixel data in driver + * internal needs be forced freshing + **/ +#define VA_PICTURE_STATS_CONTENT_UPDATED 0x00000010 + +/** \brief Motion Vector and Statistics frame level controls. + * common part VAStatsStatisticsParameterBufferType for a MB or CTB + **/ +typedef struct _VAStatsStatisticsParameter { + /** \brief Source surface ID. */ + VAPictureStats input; + + /** \brief Past reference surface ID pointer. */ + VAPictureStats *past_references; + + /** \brief Past reference surface number */ + uint32_t num_past_references; + + /** \brief Statistics output for past reference surface. + * Only enabling statistics output for past reference picture when *past_ref_stat_buf is a valid + * VABufferID, it is needed in case app wants statistics data of both reference and current pictures + * in very special use cases for better performance. + * The output layout is defined by VAStatsStatisticsBufferType(for progressive and top field of + * interlaced case) and VAStatsStatisticsBottomFieldBufferType(only for interlaced case), only + * pixel_average_16x16/pixel_average_8x8 and variance_16x16/variance_8x8 data are valid. + **/ + VABufferID *past_ref_stat_buf; + + /** \brief Future reference surface ID pointer. */ + VAPictureStats *future_references; + + /** \brief Future reference surface number */ + uint32_t num_future_references; + + /** \brief Statistics output for future reference surface. + * Only enabling statistics output for future reference picture when *past_ref_stat_buf is a valid + * VABufferID, it is needed in case app wants statistics data of both reference and current pictures + * in very special use cases for better performance. + * The output layout is defined by VAStatsStatisticsBufferType(for progressive and top field of + * interlaced case) and VAStatsStatisticsBottomFieldBufferType(only for interlaced case), only + * pixel_average_16x16/pixel_average_8x8 and variance_16x16/variance_8x8 data are valid. + **/ + VABufferID *future_ref_stat_buf; + + /** \brief ID of the output buffer. + * The number of outputs is determined by below DisableMVOutput and DisableStatisticsOutput. + * The output layout is defined by VAStatsMVBufferType, VAStatsStatisticsBufferType(for progressive and + * top field of interlaced case) and VAStatsStatisticsBottomFieldBufferType(only for interlaced case). + **/ + VABufferID *outputs; + + /** \brief MV predictor. It is valid only when mv_predictor_ctrl is not 0. + * Each block has a pair of MVs, one for past and one for future reference + * as defined by VAMotionVector. The block is in raster scan order. + * Buffer size shall not be less than the number of blocks multiplied by sizeof(VAMotionVector). + **/ + VABufferID mv_predictor; + + /** \brief QP input buffer. It is valid only when mb_qp is set to 1. + * The data in this buffer correspond to the input source. + * One QP per MB or CTB block in raster scan order, each QP is a signed char (8-bit) value. + **/ + VABufferID qp; +} VAStatsStatisticsParameter; + +#ifdef __cplusplus +} +#endif + +#endif /* VA_FEI_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei_h264.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei_h264.h new file mode 100644 index 00000000..ddb8e8cf --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei_h264.h @@ -0,0 +1,504 @@ +/* + * Copyright (c) 2007-2017 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_fei_h264.h + * \brief The FEI encoding H264 special API + */ + +#ifndef VA_FEI_H264_H +#define VA_FEI_H264_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "va_fei.h" + +/** + * \defgroup api_fei_h264 H.264 FEI encoding API + * + * @{ + */ + +/** \brief FEI frame level control buffer for H.264 */ +typedef struct _VAEncMiscParameterFEIFrameControlH264 { + uint32_t function; /* one of the VAConfigAttribFEIFunctionType values */ + /** \brief MB (16x16) control input buffer. It is valid only when (mb_input | mb_size_ctrl) + * is set to 1. The data in this buffer correspond to the input source. 16x16 MB is in raster scan order, + * each MB control data structure is defined by VAEncFEIMBControlH264. + * Buffer size shall not be less than the number of 16x16 blocks multiplied by + * sizeof(VAEncFEIMBControlH264). + * Note: if mb_qp is set, VAEncQPBufferH264 is expected. + */ + VABufferID mb_ctrl; + /** \brief distortion output of MB ENC or ENC_PAK. + * Each 16x16 block has one distortion data with VAEncFEIDistortionH264 layout + * Buffer size shall not be less than the number of 16x16 blocks multiplied by + * sizeof(VAEncFEIDistortionH264). + */ + VABufferID distortion; + /** \brief MVs data output of MB ENC. + * Each 16x16 block has one MVs data with layout VAMotionVector + * Buffer size shall not be less than the number of 16x16 blocks multiplied by + * sizeof(VAMotionVector) * 16. + */ + VABufferID mv_data; + /** \brief MBCode data output of MB ENC. + * Each 16x16 block has one MB Code data with layout VAEncFEIMBCodeH264 + * Buffer size shall not be less than the number of 16x16 blocks multiplied by + * sizeof(VAEncFEIMBCodeH264). + */ + VABufferID mb_code_data; + /** \brief QP input buffer with layout VAEncQPBufferH264. It is valid only when mb_qp is set to 1. + * The data in this buffer correspond to the input source. + * One QP per 16x16 block in raster scan order, each QP is a signed char (8-bit) value. + **/ + VABufferID qp; + /** \brief MV predictor. It is valid only when mv_predictor_enable is set to 1. + * Each 16x16 block has one or more pair of motion vectors and the corresponding + * reference indexes as defined by VAEncFEIMVPredictorH264. 16x16 block is in raster scan order. + * Buffer size shall not be less than the number of 16x16 blocks multiplied by + * sizeof(VAEncFEIMVPredictorH264). */ + VABufferID mv_predictor; + + /** \brief number of MV predictors. It must not be greater than maximum supported MV predictor. */ + uint32_t num_mv_predictors_l0 : 16; + uint32_t num_mv_predictors_l1 : 16; + + /** \brief motion search method definition + * 0: default value, diamond search + * 1: full search + * 2: diamond search + **/ + uint32_t search_path : 8; + /** \brief maximum number of Search Units, valid range is [1, 63] + * 0 is treated as 1. reference search locations are grouped in a predefined pattern, + * and all locations within the same group must be either all are chosen or all are skipped. + * These predefined groups are called search unit (SU).*/ + uint32_t len_sp : 8; + uint32_t reserved0 : 16; + /** \brief defines the bit-mask for disabling sub-partition + * The lower 4 bits are for the major partitions (sub-macroblock) and the higher 3 bits for minor partitions (with sub-partition for 4x(8x8) sub-macroblocks. + * xxxxxx1 : 16x16 sub-macroblock disabled + * xxxxx1x : 2x(16x8) sub-macroblock within 16x16 disabled + * xxxx1xx : 2x(8x16) sub-macroblock within 16x16 disabled + * xxx1xxx : 1x(8x8) sub-partition for 4x(8x8) within 16x16 disabled + * xx1xxxx : 2x(8x4) sub-partition for 4x(8x8) within 16x16 disabled + * x1xxxxx : 2x(4x8) sub-partition for 4x(8x8) within 16x16 disabled + * 1xxxxxx : 4x(4x4) sub-partition for 4x(8x8) within 16x16 disabled + * 1111111 : Invalid + * 0000000 : default value */ + uint32_t sub_mb_part_mask : 7; + /** specifies which Luma Intra partition is enabled/disabled for intra mode decision. + * xxxx1: luma_intra_16x16 disabled + * xxx1x: luma_intra_8x8 disabled + * xx1xx: luma_intra_4x4 disabled + * xx111: intra prediction is disabled */ + uint32_t intra_part_mask : 5; + /** when set to 1, neighbor MV will be used as predictor; when set to 0, no neighbor MV will be used as predictor.*/ + uint32_t multi_pred_l0 : 1; + /** when set to 1, neighbor MV will be used as predictor; when set to 0, no neighbor MV will be used as predictor.*/ + uint32_t multi_pred_l1 : 1; + /**defines the half/quarter pel modes. The mode is inclusive, ie., higher precision mode samples lower precision locations. + * 00b: integer mode searching + * 01b: half-pel mode searching + * 10b: reserved + * 11b: quarter-pel mode searching */ + uint32_t sub_pel_mode : 2; + /** specifies distortion measure adjustments used for the inter motion search SAD comparison. + * 00b: none + * 10b: Haar transform adjusted*/ + uint32_t inter_sad : 2; + /** specifies distortion measure adjustments used for the intra motion search SAD comparison. + * 00b: none + * 10b: Haar transform adjusted*/ + uint32_t intra_sad : 2; + /** specifies if the output distortion is the raw distortion or cost adjusted distortion. + * 0: Raw Distortion without Cost + * 1: Distortion with added Cost */ + uint32_t distortion_type : 1; + /** when set to 1, enables the additional calls on Fraction & Bidirectional Refinement*/ + uint32_t repartition_check_enable : 1; + /** defines whether adaptive searching is enabled for IME(Integer Motion Estimation). + * 0: disable + * 1: enable */ + uint32_t adaptive_search : 1; + /** enables using the motion vector as an extra predictor provided by the host. If it is set, + * host needs to provide a buffer with motion vectors and the associated reference index for + * each 16x16 block as defined . The host can call processing function to get motion vectors and use as predictor. + * 0: MV predictor disabled + * 1: MV predictor enabled */ + uint32_t mv_predictor_enable : 1; + /** enables using the QP buffer to set the QP for each block*/ + uint32_t mb_qp : 1; + /** enable mb_ctrl buffer to handle MB*/ + uint32_t mb_input : 1; + /** when this flag is set, mb_ctrl must be set too and a buffer with per MB input + * needs to be provided and MaxSizeInWord and */ + uint32_t mb_size_ctrl : 1; + /** when this flag is set, extra distortion between the current MB and co-located MB is provided. + * Extra distortion output has performance impact, set it only when it is needed.*/ + uint32_t colocated_mb_distortion : 1; + uint32_t reserved1 : 4; + + /** \brief motion search window(ref_width * ref_height) */ + uint32_t ref_width : 8; + uint32_t ref_height : 8; + /** \brief predefined motion search windows. If selected, len_sp, window(ref_width * ref_eight) + * and search_path setting are ignored. + * 0: not use predefined search window + * 1: Tiny, len_sp=4, 24x24 window and diamond search + * 2: Small, len_sp=9, 28x28 window and diamond search + * 3: Diamond, len_sp=16, 48x40 window and diamond search + * 4: Large Diamond, len_sp=32, 48x40 window and diamond search + * 5: Exhaustive, len_sp=48, 48x40 window and full search + * 6: Extend Diamond, len_sp=16, 64x40 window and diamond search + * 7: Extend Large Diamond, len_sp=32, 64x40 window and diamond search + * 8: Extend Exhaustive, len_sp=48, 64x40 window and full search + **/ + uint32_t search_window : 4; + uint32_t reserved2 : 12; + + /** \brief max frame size control with multi passes QP setting */ + uint32_t max_frame_size; + /** \brief number of passes, every pass has different QP */ + uint32_t num_passes; + /** \brief delta QP list for every pass */ + uint8_t *delta_qp; + uint32_t reserved3[VA_PADDING_LOW]; +} VAEncMiscParameterFEIFrameControlH264; + +/** \brief FEI MB level control data structure */ +typedef struct _VAEncFEIMBControlH264 { + /** \brief when set, correposndent MB is coded as intra */ + uint32_t force_to_intra : 1; + /** \brief when set, correposndent MB is coded as skip */ + uint32_t force_to_skip : 1; + /** \brief specifies whether this macroblock should be coded as a non-skipped macroblock. */ + uint32_t force_to_nonskip : 1; + uint32_t enable_direct_bias_adjustment : 1; + uint32_t enable_motion_bias_adjustment : 1; + uint32_t ext_mv_cost_scaling_factor : 3; + uint32_t reserved0 : 24; + + uint32_t reserved1; + + uint32_t reserved2; + + uint32_t reserved3 : 16; + /** \brief when mb_size_ctrl is set, size here is used to budget accumulatively. Set to 0xFF if don't care. */ + uint32_t target_size_in_word : 8; + /** \brief specifies the max size of each MB */ + uint32_t max_size_in_word : 8; +} VAEncFEIMBControlH264; + + +/** \brief Application can use this definition as reference to allocate the buffer + * based on MaxNumPredictor returned from attribute VAConfigAttribFEIMVPredictors query. + **/ +typedef struct _VAEncFEIMVPredictorH264 { + /** \brief Reference index corresponding to the entry of RefPicList0 & RefPicList1 in VAEncSliceParameterBufferH264. + * Note that RefPicList0 & RefPicList1 needs to be the same for all slices. + * ref_idx_l0_x : index to RefPicList0; ref_idx_l1_x : index to RefPicList1; x : 0 - MaxNumPredictor. + **/ + struct { + uint8_t ref_idx_l0 : 4; + uint8_t ref_idx_l1 : 4; + } ref_idx[4]; /* index is predictor number */ + uint32_t reserved; + /** \brief MV. MaxNumPredictor must be the returned value from attribute VAConfigAttribFEIMVPredictors query. + * Even application doesn't use the maximum predictors, the VAFEIMVPredictorH264 structure size + * has to be defined as maximum so each MB can be at a fixed location. + * Note that 0x8000 must be used for correspondent intra block. + **/ + VAMotionVector mv[4]; /* MaxNumPredictor is 4 */ +} VAEncFEIMVPredictorH264; + +/** \brief FEI output */ +/** + * Motion vector output is per 4x4 block. For each 4x4 block there is a pair of MVs + * for RefPicList0 and RefPicList1 and each MV is 4 bytes including horizontal and vertical directions. + * Depending on Subblock partition, for the shape that is not 4x4, the MV is replicated + * so each 4x4 block has a pair of MVs. The 16x16 block has 32 MVs (128 bytes). + * 0x8000 is used for correspondent intra block. The 16x16 block is in raster scan order, + * within the 16x16 block, each 4x4 block MV is ordered as below in memory. + * The buffer size shall be greater than or equal to the number of 16x16 blocks multiplied by 128 bytes. + * Note that, when separate ENC and PAK is enabled, the exact layout of this buffer is needed for PAK input. + * App can reuse this buffer, or copy to a different buffer as PAK input. + * Layout is defined as Generic motion vector data structure VAMotionVector + * 16x16 Block + * ----------------------------------------- + * | 1 | 2 | 5 | 6 | + * ----------------------------------------- + * | 3 | 4 | 7 | 8 | + * ----------------------------------------- + * | 9 | 10 | 13 | 14 | + * ----------------------------------------- + * | 11 | 12 | 15 | 16 | + * ----------------------------------------- + **/ + +/** \brief VAEncFEIMBCodeH264 defines the data structure for VAEncFEIMBCodeBufferType per 16x16 MB block. + * it is output buffer of ENC and ENC_PAK modes, it's also input buffer of PAK mode. + * The 16x16 block is in raster scan order. Buffer size shall not be less than the number of 16x16 blocks + * multiplied by sizeof(VAEncFEIMBCodeH264). Note that, when separate ENC and PAK is enabled, + * the exact layout of this buffer is needed for PAK input. App can reuse this buffer, + * or copy to a different buffer as PAK input, reserved elements must not be modified when used as PAK input. + **/ +typedef struct _VAEncFEIMBCodeH264 { + //DWORD 0~2 + uint32_t reserved0[3]; + + //DWORD 3 + uint32_t inter_mb_mode : 2; + uint32_t mb_skip_flag : 1; + uint32_t reserved1 : 1; + uint32_t intra_mb_mode : 2; + uint32_t reserved2 : 1; + uint32_t field_mb_polarity_flag : 1; + uint32_t mb_type : 5; + uint32_t intra_mb_flag : 1; + uint32_t field_mb_flag : 1; + uint32_t transform8x8_flag : 1; + uint32_t reserved3 : 1; + uint32_t dc_block_coded_cr_flag : 1; + uint32_t dc_block_coded_cb_flag : 1; + uint32_t dc_block_coded_y_flag : 1; + uint32_t reserved4 : 12; + + //DWORD 4 + uint32_t horz_origin : 8; + uint32_t vert_origin : 8; + uint32_t cbp_y : 16; + + //DWORD 5 + uint32_t cbp_cb : 16; + uint32_t cbp_cr : 16; + + //DWORD 6 + uint32_t qp_prime_y : 8; + uint32_t reserved5 : 17; + uint32_t mb_skip_conv_disable : 1; + uint32_t is_last_mb : 1; + uint32_t enable_coefficient_clamp : 1; + uint32_t direct8x8_pattern : 4; + + //DWORD 7 8 and 9 + union { + /* Intra MBs */ + struct { + uint32_t luma_intra_pred_modes0 : 16; + uint32_t luma_intra_pred_modes1 : 16; + + uint32_t luma_intra_pred_modes2 : 16; + uint32_t luma_intra_pred_modes3 : 16; + + uint32_t chroma_intra_pred_mode : 2; + uint32_t intra_pred_avail_flag : 5; + uint32_t intra_pred_avail_flagF : 1; + uint32_t reserved6 : 24; + } intra_mb; + + /* Inter MBs */ + struct { + uint32_t sub_mb_shapes : 8; + uint32_t sub_mb_pred_modes : 8; + uint32_t reserved7 : 16; + + uint32_t ref_idx_l0_0 : 8; + uint32_t ref_idx_l0_1 : 8; + uint32_t ref_idx_l0_2 : 8; + uint32_t ref_idx_l0_3 : 8; + + uint32_t ref_idx_l1_0 : 8; + uint32_t ref_idx_l1_1 : 8; + uint32_t ref_idx_l1_2 : 8; + uint32_t ref_idx_l1_3 : 8; + } inter_mb; + } mb_mode; + + //DWORD 10 + uint32_t reserved8 : 16; + uint32_t target_size_in_word : 8; + uint32_t max_size_in_word : 8; + + //DWORD 11~14 + uint32_t reserved9[4]; + + //DWORD 15 + uint32_t reserved10; +} VAEncFEIMBCodeH264; // 64 bytes + +/** \brief VAEncFEIDistortionH264 defines the data structure for VAEncFEIDistortionBufferType per 16x16 MB block. + * It is output buffer of ENC and ENC_PAK modes, The 16x16 block is in raster scan order. + * Buffer size shall not be less than the number of 16x16 blocks multiple by sizeof(VAEncFEIDistortionH264). + **/ +typedef struct _VAEncFEIDistortionH264 { + /** \brief Inter-prediction-distortion associated with motion vector i (co-located with subblock_4x4_i). + * Its meaning is determined by sub-shape. It must be zero if the corresponding sub-shape is not chosen. + **/ + uint16_t inter_distortion[16]; + uint32_t best_inter_distortion : 16; + uint32_t best_intra_distortion : 16; + uint32_t colocated_mb_distortion : 16; + uint32_t reserved0 : 16; + uint32_t reserved1[2]; +} VAEncFEIDistortionH264; // 48 bytes + +/** \brief Motion Vector and Statistics frame level controls. + * VAStatsStatisticsParameterBufferType for H264 16x16 block + **/ +typedef struct _VAStatsStatisticsParameterH264 { + VAStatsStatisticsParameter stats_params; + + uint32_t frame_qp : 8; + /** \brief length of search path */ + uint32_t len_sp : 8; + /** \brief motion search method definition + * 0: default value, diamond search + * 1: full search + * 2: diamond search + **/ + uint32_t search_path : 8; + uint32_t reserved0 : 8; + + uint32_t sub_mb_part_mask : 7; + /** \brief sub pixel mode definition + * 00b: integer mode searching + * 01b: half-pel mode searching + * 10b: reserved + * 11b: quarter-pel mode searching + **/ + uint32_t sub_pel_mode : 2; + /** \brief distortion measure adjustment for inter search SAD comparison + * 00b: none + * 01b: reserved + * 10b: Haar transform adjusted + * 11b: reserved + **/ + uint32_t inter_sad : 2; + /** \brief distortion measure adjustment for intra search SAD comparison + * 00b: none + * 01b: reserved + * 10b: Haar transform adjusted + * 11b: reserved + **/ + uint32_t intra_sad : 2; + uint32_t adaptive_search : 1; + /** \brief indicate if future or/and past MV in mv_predictor buffer is valid. + * 0: MV predictor disabled + * 1: MV predictor enabled for past reference + * 2: MV predictor enabled for future reference + * 3: MV predictor enabled for both past and future references + **/ + uint32_t mv_predictor_ctrl : 3; + uint32_t mb_qp : 1; + /** \brief forward transform enable + * 0: disable + * 1: enable, needs frame_qp or mb_qp input for transform + **/ + uint32_t ft_enable : 1; + /** \brief luma intra mode partition mask + * xxxx1: luma_intra_16x16 disabled + * xxx1x: luma_intra_8x8 disabled + * xx1xx: luma_intra_4x4 disabled + * xx111: intra prediction is disabled + **/ + uint32_t intra_part_mask : 5; + uint32_t reserved1 : 8; + + /** \brief motion search window(ref_width * ref_height) */ + uint32_t ref_width : 8; + uint32_t ref_height : 8; + /** \brief predefined motion search windows. If selected, len_sp, window(ref_width * ref_eight) + * and search_path setting are ignored. + * 0: not use predefined search window + * 1: Tiny, len_sp=4, 24x24 window and diamond search + * 2: Small, len_sp=9, 28x28 window and diamond search + * 3: Diamond, len_sp=16, 48x40 window and diamond search + * 4: Large Diamond, len_sp=32, 48x40 window and diamond search + * 5: Exhaustive, len_sp=48, 48x40 window and full search + * 6: Extend Diamond, len_sp=16, 64x40 window and diamond search + * 7: Extend Large Diamond, len_sp=32, 64x40 window and diamond search + * 8: Extend Exhaustive, len_sp=48, 64x40 window and full search + **/ + uint32_t search_window : 4; + uint32_t reserved2 : 12; + + /** \brief MVOutput. When set to 1, MV output is NOT provided */ + uint32_t disable_mv_output : 1; + /** \brief StatisticsOutput. When set to 1, Statistics output is NOT provided. */ + uint32_t disable_statistics_output : 1; + /** \brief block 8x8 data enabling in statistics output */ + uint32_t enable_8x8_statistics : 1; + uint32_t reserved3 : 29; + uint32_t reserved4[2]; +} VAStatsStatisticsParameterH264; + +/** \brief VAStatsStatisticsH264. H264 Statistics buffer layout for VAStatsStatisticsBufferType + * and VAStatsStatisticsBottomFieldBufferType(for interlaced only). + * Statistics output is per 16x16 block. Data structure per 16x16 block is defined below. + * The 16x16 block is in raster scan order. The buffer size shall be greater than or equal to + * the number of 16x16 blocks multiplied by sizeof(VAStatsStatisticsH264). + **/ +typedef struct _VAStatsStatisticsH264 { + /** \brief past reference */ + uint32_t best_inter_distortion0 : 16; + uint32_t inter_mode0 : 16; + + /** \brief future reference */ + uint32_t best_inter_distortion1 : 16; + uint32_t inter_mode1 : 16; + + uint32_t best_intra_distortion : 16; + uint32_t intra_mode : 16; + + uint32_t num_non_zero_coef : 16; + uint32_t reserved0 : 16; + + uint32_t sum_coef; + + /** \brief DWORD 5 flat info **/ + uint32_t mb_is_flat : 1; + uint32_t reserved1 : 31; + + /** \brief DWORD 6 variance for block16x16**/ + uint32_t variance_16x16; + /** \brief DWORD 7 ~ 10, variance for block8x8 **/ + uint32_t variance_8x8[4]; + + /** \brief DWORD 11 pixel_average for block16x16 **/ + uint32_t pixel_average_16x16; + /** \brief DWORD 12 ~ 15, pixel_average for block8x8 **/ + uint32_t pixel_average_8x8[4]; +} VAStatsStatisticsH264; // 64 bytes + + +#ifdef __cplusplus +} +#endif + +#endif /* VA_FEI_H264_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei_hevc.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei_hevc.h new file mode 100644 index 00000000..6ba9047e --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_fei_hevc.h @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2007-2017 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_fei_hevc.h + * \brief The FEI encoding HEVC special API + */ + + +#ifndef __VA_FEI_HEVC_H__ +#define __VA_FEI_HEVC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "va_fei.h" + +/** + * \defgroup api_fei_hevc HEVC FEI encoding API + * + * @{ + */ + +/** \brief FEI frame level control buffer for HEVC */ +typedef struct _VAEncMiscParameterFEIFrameControlHEVC { + /* one of the VAConfigAttribFEIFunctionType values */ + uint32_t function; + /** \brief CTB control input buffer. It is valid only when per_ctb_input + * is set to 1. The data in this buffer correspond to the input source. CTB is in raster scan order, + * each CTB control data structure is defined by VAEncFEICTBControlHEVC. + * Buffer size shall not be less than the number of CTBs multiplied by + * sizeof(VAEncFEICTBControlHEVC). + */ + VABufferID ctb_ctrl; + /** \brief CTB cmd per CTB data output of ENC + * it is reserved for CTB level information + * it should include CU split information and other CTB datas . + * Each CTB block has one CTB cmd data. + */ + VABufferID ctb_cmd; + /** \brief CU record data output of ENC + * it is reserved for CU level information + * it should include CU detail data. include mode,MV, reference etc. + * Each CTB block has one CU record data. + */ + VABufferID cu_record; + /** \brief distortion output of ENC or ENC_PAK. + * Each CTB has one distortion data with VAEncFEIDistortionHevc + * Buffer size shall not be less than the number of CTBs multiplied by + * sizeof(VAEncFEIDistortionHevc). + */ + VABufferID distortion; + /** \brief Qp input buffer. It is valid only when per_block_qp is set to 1. + * The data in this buffer correspond to the input source. + * One Qp per block block is in raster scan order, each Qp is a signed char (8-bit) value. + **/ + VABufferID qp; + /** \brief MV predictor. It is valid only when mv_predictor_input is set to non-zero. + * Each CTB block has one or more pair of motion vectors and the corresponding + * reference indexes as defined by VAEncFEIMVPredictorHEVC. 32x32 block is in raster scan order. + * Buffer size shall not be less than the number of 16x16 blocks multiplied by + * sizeof(VAEncFEIMVPredictorHEVC). */ + VABufferID mv_predictor; + + /** \brief number of MV predictors L0 and L1. the maximum number of motion vector predictor for a 16x16, 32x32 or + * 64x64 block is four, it must not be greater than maximum supported MV predictor, + **/ + uint32_t num_mv_predictors_l0 : 16; + uint32_t num_mv_predictors_l1 : 16; + + /** \brief control parameters */ + uint32_t search_path : 8; + uint32_t len_sp : 8; + uint32_t reserved0 : 16; + + /** \brief multi pred l0/1 + * 0000: no internal MV predictor will be used + * 0001: spatial MV predictors + * 0100/1000: Reserved + **/ + uint32_t multi_pred_l0 : 4; + uint32_t multi_pred_l1 : 4; + /** \brief defines the motion vector precision, like integer/half/quarter pel. + * 00b: integer pel + * 01b: half-pel + * 10b: reserved + * 11b: quarter-pel + */ + uint32_t sub_pel_mode : 2; + uint32_t adaptive_search : 1; + /** \brief mv_predictor_input + * 000: MV predictor disabled + * 001: MV predictor enabled per 16x16 block + * 010: MV predictor enabled per 32x32 block + * 011: MV predictor enabled per 64x64 block + * 111: MV predictor enabled, block size can vary and is determined by BlockSize in motion vector predictor buffer + * 100/101/110: Reserved + **/ + uint32_t mv_predictor_input : 3; + /** \brief enables per CTB or CU qp */ + uint32_t per_block_qp : 1; + /** \brief enables the per CTB input , if 1, need ctb_ctrl to be a real surface ID*/ + uint32_t per_ctb_input : 1; + /** when this flag is set, extra distortion between current CTB and co-located CTB is provided. + * Extra distortion output has performance impact, set it only when it is needed */ + uint32_t colocated_ctb_distortion : 1; + /** brief specifies whether this CTB should be forced to split to remove Inter big LCU: do not check Inter 32x32 + * PUs. Every 32x32 LCU is split at least once. It can be used to improved performance. + * 0: ENC determined block type + * 1: Force to split + **/ + uint32_t force_lcu_split : 1; + /** \brief enables CU64x64 check */ + uint32_t enable_cu64_check : 1; + /** \brief enables CU64x64 asymmetric motion partition check */ + uint32_t enable_cu64_amp_check : 1; + /** \brief specifies if check the 64x64 merge candidate + * 0: after skip check, + * 1: only skip check for 64x64 + Default: 0. This field is used by LCU64 bi-directional. + **/ + uint32_t cu64_skip_check_only : 1; + uint32_t reserved1 : 11; + /** specifies the search region width in pixels. + * When bidirectional search is enabled, this applies to both search regions */ + uint32_t ref_width : 8; + /** specifies the reference region height in pixels. When bidirectional search is enabled, + * this applies to both search regions. */ + uint32_t ref_height : 8; + /** \brief search window similar for AVC + * defines predefined search windows. If it is selected, RefWidth, RefHeight, LenSP and SearchPath are ignored. + * 0 : not use predefined search window + * 1 : Tiny – (4 SUs) 24x24 window diamond search + * 2 : Small – (9 SUs) 28x28 window diamond search + * 3 : Diamond – (16 SUs) 48x40 window diamond search + * 4 : Large Diamond – (32 SUs) 48x40 window diamond search + * 5 : Exhaustive – 48x40 window full search + * 6 : (64 SUs) 64x64 window full search + * Note: option 1, 2, 3 and 4 are valid only when CAP parameter SearchWindow64Support is 0. + * And option 6 is valid only when SearchWindow64Support is 1.*/ + uint32_t search_window : 8; + /** \brief number of internal MV predictors for IME searches */ + uint32_t max_num_ime_search_center : 3; + /** \brief fast intra prediction enabling bit. It is used as a trade-off between speed and quality. + * The flag will be ignored if it's unsupported in the driver*/ + uint32_t fast_intra_mode : 1; + uint32_t reserved2 : 4; + + /** \brief specifies number of splits that encoder could be run concurrently + * 1: level 1, default value + * 2: level 2 + * 4: level 3 + **/ + uint32_t num_concurrent_enc_frame_partition : 8; + uint32_t reserved3 : 24; + + /** \brief max frame size control with multi passes QP setting */ + uint32_t max_frame_size; + /** \brief number of passes, every pass has different QP */ + uint32_t num_passes; + /** \brief delta QP list for every pass */ + uint8_t *delta_qp; + + uint32_t reserved4[2]; +} VAEncMiscParameterFEIFrameControlHEVC; + +/** \brief Application can use this definition as reference to allocate the buffer + * based on MaxNumPredictor returned from attribute VAConfigAttribFEIMVPredictors query. + * this buffer allocation is always based on 16x16 block even block size is indicated as 32x32 or 64x64, and buffer + * layout is always in 32x32 block raster scan order even block size is 16x16 or 64x64. If 32x32 block size is set, + * only the data in the first 16x16 block (block 0) is used for 32x32 block. If 64x64 block size is set + * MV layout is still in 32x32 raster scan order, the same as 32x32 and the first 16x16 + * block within each 32x32 block needs to have intended MV data (four 32x32 blocks will have the same MV data in the + * correspondent first 16x16 block). Data structure for each 16x16 block is defined as below (same as AVC except + * BlockSize/Reserved bits). + **/ +typedef struct _VAEncFEIMVPredictorHEVC { + /** \brief Feference index corresponding to the entry of RefPicList0 & RefPicList1 in slice header (final reference + * list). Note that RefPicList0 & RefPicList1 needs to be the same for all slices. + * Ref0xIndex – RefPicList0; Ref1xIndex – RefPicList1; x – 0 ~ MaxNumPredictor */ + struct { + uint8_t ref_idx_l0 : 4; + uint8_t ref_idx_l1 : 4; + } ref_idx[4]; /* index is predictor number */ + /** \brief Valid only when MVPredictor is set to 011 for HEVC. Only valid in the first 16x16 block. + * 00: MV predictor disabled for this 32x32 block + * 01: MV predictor enabled per 16x16 block for this 32x32 block + * 10: MV predictor enabled per 32x32 block, the rest of 16x16 block data within this 32x32 block are ignored + * 11: Reserved */ + uint32_t block_size : 2; + uint32_t reserved : 30; + + VAMotionVector mv[4]; /* MaxNumPredictor is 4 */ +} VAEncFEIMVPredictorHEVC; //40 bytes + +/** \brief FEI CTB level control data structure */ +typedef struct _VAEncFEICTBControlHEVC { + // DWORD 0 + uint32_t force_to_intra : 1; + uint32_t force_to_inter : 1; + uint32_t force_to_skip : 1; + /** \brief force all coeff to zero */ + uint32_t force_to_zero_coeff : 1; + uint32_t reserved0 : 28; + // DWORD 1 + uint32_t reserved1; + // DWORD 2 + uint32_t reserved2; + // DWORD 3 + uint32_t reserved3; +} VAEncFEICTBControlHEVC; + +/** \brief VAEncFEIDistortionHevc defines the data structure for VAEncFEIDistortionBufferType per CTB block. + * It is output buffer of ENC and ENC_PAK modes, The CTB block is in raster scan order. + * Buffer size shall not be less than the number of CTB blocks multiple by sizeof(VAEncFEIDistortionHevc). + **/ +typedef struct _VAEncFEIDistortionHevc { + /** best CTB distortion */ + uint32_t best_distortion; + /** only when colocated_ctb_distortion in VAEncMiscParameterFEIFrameControlHEVC is set */ + uint32_t colocated_ctb_distortion; +} VAEncFEIDistortionHevc; +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_prot.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_prot.h new file mode 100644 index 00000000..5c59bb0f --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_prot.h @@ -0,0 +1,515 @@ +/* + * Copyright (c) 2020 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_prot.h + * \brief Protected content API. + * + * This file contains the \ref api_prot "Protected content API". + */ + +#ifndef VA_PROT_H +#define VA_PROT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_prot Protected content API + * + * @{ + * \section prolouge Prolouge + * Video streaming is ubiquitous and the support for video streaming is widely + * available across client open systems such as PCs, MACs, Chromebooks etc. and + * closed systems such as settop box, smart TVs, DVDs etc. By default, + * video streaming is not considered premium due to various constraints such as + * resolution, quality, production cost etc. but recently streaming of premium + * video(1080p+) has become norm. The streaming of premium video in open systems + * such as PCs, MACs, Chromebooks etc. makes video particularly susceptible to + * piracy (due to non-video playback usages of such systems) resulting in + * millions of dollars of loss to content creators. + * + * Digital Rights Management(DRM) has been proposed to stop piracy of premium + * video streams across a wide spectrum. There are some known open/closed DRM + * standards such as [Widevine by Google](https://www.widevine.com/), + * [PlayReady by Microsoft](https://www.microsoft.com/playready/), + * [FairPlay by Apple](https://developer.apple.com/streaming/fps/), + * [Merlin by Sony](https://www.marlin-community.com/), etc... Each DRM + * standard has its properties but all DRM standards support a common + * mechanism. This common mechanism involves cryptographical method for + * authenticating the client system, delivering bitstream and required + * cryptographic assets to client system and then cryptographically processing + * bitstream in client system. The cryptographic methods used in these steps + * are asymmetric such as RSA, DH etc. and symmetric such as AES CTR, CBC etc. + * encryption mechanisms. The authentication of client system, delivery of + * bitstream and cryptographic assets to client system is performed using + * asymmetric cryptographic mechanism while bitstream is encrypted and processed + * using symmetric cryptographic. In DRM world, authentication of client system, + * delivery of bitstream and required cryptographic assets to client system is + * loosely called provisioning and license acquisition while the processing of + * cryptographically secure bitstream is divided as video decryption/decoding, + * audio decryption/playback, video display. Besides DRM standards, Video/Audio + * bitstream encryption standard such as + * [Common Encryption Standard(CENC)](https://www.iso.org/standard/76597.html) + * provides a mechanism to normalize bitstream encryption methods across vendors + * while providing flexibility. + * + * \section DRM Pipeline + * Most DRM standards execute the following deep pipeline to playback + * contents on client systems from streaming servers - provisioning uses + * provisioning servers, licence aquisition uses license servers, video + * bitstream delivery uses content servers and decryption/decoding, audio + * bitstream delivery uses content servers and decyption/playback, + * display/playback. The system level HWDRM sequence diagram is following - + * ![HWDRM sequence diagram](https://user-images.githubusercontent.com/75039699/102427278-df284e80-3fc5-11eb-9a3e-129b5f6b567a.png) + * and HWDRM pipeline view is following - + * ![HWDRM pipeline view](https://user-images.githubusercontent.com/75039699/102427357-04b55800-3fc6-11eb-8b8c-f34fc44ec061.png) + * + * \section LibVA Protected Content APIs + * The LibVA Protected APIs are designed to enable DRM capabilities or + * facilitate isolated communicaiton with TEE. + * The VAEntrypointProtectedTEEComm is to define interfaces for Application + * to TEE direct communication to perform various TEE centric operations + * such as standalone provisioning of platform at factory or provisioning + * TEE for other usages, providing TEE capabilities etc. + * The VAEntrypointProtectedContent is to define interfaces for protected + * video playback using HWDRM. This entry point co-ordinates assets across + * TEE/GPU/Display for HWDRM playback. + * + * The difference between Protected Content and Protected TEE Communication + * is that Protected Content Entrypoint does not provide isolated entry + * point for TEE and invokes TEE only from HWDRM perspective. + * + * Protected Content Entrypoint + * The most of DRM standards execute following deep pipeline to playback + * contents on client systems from streaming servers - provisioning uses + * provisioning servers, licence aquisition uses license servers, video + * bitstream delivery uses content servers and decryption/decoding, audio + * bitstream delivery uses content servers and decyption/playback, + * display/playback. + * + * The Provisioning and License aquisition implementations are Independent + * Hardware Vendor (IHV) specific but most IHVs use some form of Trusted + * Execution Environment (TEE) to prepare client platform or system for DRM + * content playback. The provisioning operations use provisioning servers (as + * instructed in DRM standard) and client system TEE. The communication between + * provisioning servers and client system TEE uses asymmetic cryptographic + * mechanism. This step provides a way to establish root-of-trust between + * client system and streaming servers. Once root-of-trust is established then + * client system requests for license aquisition for a particular streaming + * title. The license aquisition involves communication between licensing + * servers and TEE using asymmetic cryptographic mechanism. At end of this step, + * client system TEE has required assets to decrypt/decode. Although these + * communication does not direcly involve video aspect of GPU but **facilitate + * GPU required assets to playback premium contents**. + * + * To support DRM standard requirements in playback pipeline, OSes and HWs + * incorporate various methods to protect full playback pipeline. These + * methods of protection could be SW based or HW based. The SW based protection + * mechanism of DRMs is called SWDRM while HW based protection mechanism is + * called HWDRM. There is no previous support in LibVA to support either DRM + * mechanism. + * + * For DRM capabilities, APIs inolve creation of protected session to + * communicate with TEE and then using these protected sessions to process + * video/audio data. The philophashy behind these API is to leverage existing + * LibVA infrastructure as much as possible. + * + * Note: TEE could be any secure HW device such as ME-FW or FPGA Secure + * Enclave or NPU Secure Enclave. There are 2 concepts here – TEE Type such + * as ME-FW or FPGA or NPU; TEE Type Client such as for AMT or HDCP or + * something else etc. + * + * \section description Detailed Description + * The Protected content API provides a general mechanism for opening + * protected session with TEE and if required then \ref priming GPU/Display. + * The behavior of protected session API depends on parameterization/ + * configuration of protected session. Just for TEE tasks, protected + * session is parameterized/configured as TEE Communication while for + * HWDRM, protected session is parameterized/confgured as Protected + * Content. + * + * TEE Communication Entrypoint + * With TEE Communication parameterization/configuration, client + * executes TEE workloads in TEE with TEE Communication protected + * session. + * + * Protected Content Entrypoint + * With Protected Content parameterization/configuration, client + * executes HWDRM playback workloads HW accelerating protected video + * content decryption/decoding with protected content session. + * + * Before calling vaCreateProtectedSession, VAConfigID is obtained using + * existing libva mechanism to determine configuration parameters of + * protected session. The VAConfigID is determined in this way so that + * Protected Session implementation aligns with existing libva implementation. + * After obtaining VAConfigID, Protected Session needs to be created but + * note this is a session and not a context. Refer VAProtectedSessionID + * for more details. + * + * Note:- Protected session represents session object that has all security + * information needed for Secure Enclave to operate certain operations. + * + * \subsection priming Priming + * Priming is used to refer various types of initializations. For example, + * if license acquisition is being performed then priming means that TEE is + * already provisioned aka TEE has some sort of "cryptographic" whitelist of + * servers that TEE will use to do license acquisition for video playback. If + * HWDRM video playback is being performed then priming means that HWDRM + * eco-system TEE/GPU/Display has proper keys to do proper video playback etc. + * + * Protected content API uses the following paradigm for protected content + * session: + * - \ref api_pc_caps + * - \ref api_pc_setup + * - \ref api_pc_exec + * - \ref api_pc_attach + * + * \subsection api_pc_caps Query for supported cipher mode, block size, mode + * + * Checking whether protected content is supported can be performed with + * vaQueryConfigEntrypoints() and the profile argument set to + * #VAProfileProtected. If protected content is supported, then the list of + * returned entry-points will include #VAEntrypointProtectedContent + * + * \code + * VAEntrypoint *entrypoints; + * int i, num_entrypoints, supportsProtectedContent = 0; + * + * num_entrypoints = vaMaxNumEntrypoints(); + * entrypoints = malloc(num_entrypoints * sizeof(entrypoints[0]); + * vaQueryConfigEntrypoints(va_dpy, VAProfileProtected, entrypoints, + * &num_entrypoints); + * + * for (i = 0; !supportsProtectedContent && i < num_entrypoints; i++) { + * if (entrypoints[i] == VAEntrypointProtectedContent) + * supportsProtectedContent = 1; + * } + * \endcode + * + * Then, the vaGetConfigAttributes() function is used to query the protected + * session capabilities. + * + * \code + * VAConfigAttrib attribs; + * attribs[0].type = VAConfigAttribProtectedContentCipherAlgorithm; + * attribs[1].type = VAConfigAttribProtectedContentCipherBlockSize; + * attribs[2].type = VAConfigAttribProtectedContentCipherMode; + * attribs[3].type = VAConfigAttribProtectedContentCipherSampleType; + * attribs[4].type = VAConfigAttribProtectedContentUsage; + * vaGetConfigAttributes(va_dpy, VAProfileProtected, + * VAEntrypointProtectedContent, attribs, 5); + * if ((attribs[1].value & VA_PC_CIPHER_AES) == 0) { + * // not find desired cipher algorithm + * assert(0); + * } + * if ((attribs[2].value & VA_PC_BLOCK_SIZE_128) == 0) { + * // not find desired block size + * assert(0); + * } + * if ((attribs[3].value & VA_PC_CIPHER_MODE_CBC) == 0) { + * // not find desired counter mode + * assert(0); + * } + * if ((attribs[4].value & VA_PC_SAMPLE_TYPE_SUBSAMPLE) == 0) { + * // not find desired sample type + * assert(0); + * } + * if ((attribs[5].value & VA_PC_USAGE_WIDEVINE) == 0) { + * // not find desired usage + * assert(0); + * } + * \endcode + * + * \subsection api_pc_setup Set up a protected content session + * + * TEE Communication Entrypoint + * The protected content session provides a TEE session that is used to extract + * TEE information. This information could be used to peform TEE operations. + * + * Protected Content Entrypoint + * The protected content session can be attached to VA decode/encode/vp context + * to do decryption/protection in the pipeline. + * Before creating a protected content session, it needs to create a config + * first via vaCreateConfig(). Then using this config id to create a protected + * content session via vaCreateProtectedSession(). + * + * The general control flow is demonstrated by the following pseudo-code: + * \code + * // Create config + * VAConfigID config_id; + * + * attribs[0].value = VA_PC_CIPHER_AES; + * attribs[1].value = VA_PC_BLOCK_SIZE_128; + * attribs[2].value = VA_PC_CIPHER_MODE_CBC; + * attribs[3].value = VA_PC_SAMPLE_TYPE_SUBSAMPLE; + * attribs[4].value = VA_PC_USAGE_WIDEVINE; + * va_status = vaCreateConfig(va_dpy, VAProfileProtected, + * VAEntrypointProtectedContent, attribs, 5, &config_id); + * CHECK_VASTATUS(va_status, "vaCreateConfig"); + * \endcode + * + * Once the config is set up, we can create protected content session via + vaCreateProtectedSession(). + * \code + * // Create a protected session + * VAProtectedSessionID crypto_session; + * + * va_status = vaCreateProtectedSession(va_dpy, config_id, &crypto_session); + * CHECK_VASTATUS(va_status, "vaCreateProtectedSession"); + * \endcode + * + * \subsection api_pc_exec TEE communication via vaProtectedSessionExecute() + * + * TEE Communication Entrypoint + * App needs to communicate with TEE to get TEE information or \ref priming + * "prime" TEE with information that will be utilized for future TEE + * operations/tasks. + * + * Protected Content Entrypoint + * Before starting decryption/encryption operation in GPU, app may need to + * communicate with TEE to get encrypted assets for \ref priming HWDRM pipeline + * for decryption. App need to call vaProtectedSessionExecute() to get this + * asset. The following pseudo-code demonstrates getting session assets via + * vaProtectedSessionExecute() as an example. + * + * In this example, the vaCreateBuffer is called with exec_buffer mainly becasue TEE + * Communication Entrypoint buffers are CPU bound and buffer size is small enough to + * have extra copy operation without impacting performance. + * + * \code + * uint32_t app_id = 0xFF; + * VABufferID buffer; + * VAProtectedSessionExecuteBuffer exec_buff = {0}; + * + * exec_buff.function_id = GET_SESSION_ID; + * exec_buff.input.data = nullptr; + * exec_buff.input.data_size = 0; + * exec_buff.output.data = &app_id; + * exec_buff.output.max_data_size = sizeof(app_id); + * va_status = vaCreateBuffer( + * va_dpy, + * crypto_session, + * (VABufferType) VAProtectedSessionExecuteBufferType, + * sizeof(exec_buff), + * 1, + * &exec_buff, + * &buffer); + * + * va_status = vaProtectedSessionExecute(va_dpy, crypto_session, buffer); + * + * vaDestroyBuffer(va_dpy, buffer); + * \endcode + * + * \subsection api_pc_attach Attach/Detach protected content session to the VA + * context which want to enable/disable decryption/protection + * + * Protected content session is attached to VA decode/encode/vp context to + * enable protected decoding/encoding/video processing per frame or entire + * stream. If protected session attached per frame then application has 2 + * options for decoding/encoding skip processing i.e. accomodating clear + * frames - 1. Application could do detach after each frame is processed + * to process clear frame 2. Application could remains attached to decode/ + * encode session but specify enryption byte length to 0. + * The video processing does not has option #2 mainly because API does + * not provide skip processing. + * + * \code + * vaAttachProtectedSession(va_dpy, decode_ctx, crypto_session); + * foreach (iteration) { + * vaBeginPicture(va_dpy, decode_ctx, surface); + * ... + * vaRenderPicture(va_dpy, decode_ctx, &buf_id1, 1); + * vaRenderPicture(va_dpy, decode_ctx, &buf_id2, 1); + * // Buffer holding encryption parameters, i.e. VAEncryptionParameterBufferType buffer + * vaRenderPicture(va_dpy, decode_ctx, &buf_id_enc_param, 1); + * ... + * vaEndPicture(va_dpy, decode_ctx); + * } + * vaDetachProtectedSession(va_dpy, decode_ctx); + * \endcode + * + * or it could be frame-by-frame attaching/detaching as following: + * + * \code + * foreach (iteration) { + * if (encrypted) + * vaAttachProtectedSession(va_dpy, decode_ctx, crypto_session); + + * vaBeginPicture(va_dpy, decode_ctx, surface); + * ... + * vaRenderPicture(va_dpy, decode_ctx, &buf_id1, 1); + * vaRenderPicture(va_dpy, decode_ctx, &buf_id2, 1); + * // Buffer holding encryption parameters, i.e. VAEncryptionParameterBufferType buffer + * vaRenderPicture(va_dpy, decode_ctx, &buf_id_enc_param, 1); + * ... + * vaEndPicture(va_dpy, decode_ctx); + * + * if (encrypted) + * vaDetachProtectedSession(va_dpy, decode_ctx); + + * // check encrypted variable for next frame + * } + * \endcode + */ + +/** + * ProtectedSessions and Contexts + * + * According to #VAContextID, Context represents a "virtual" video decode, + * encode or video processing pipeline. Surfaces are render targets for a given + * context. The data in the surfaces are not accessible to the client except if + * derived image is supported and the internal data format of the surface is + * implementation specific. Application can create a video decode, encode or + * processing context which represents a "virtualized" hardware device. + * + * Since Protected Session does not virtualize any HW device or build any + * pipeline but rather accessorize existing virtualized HW device or pipeline + * to operate in protected mode so we decided to create separate function. + * Beside this, a virtualized HW device or pipeline could own several protected + * sessions and operate in those protected modes without ever re-creating + * virtualization of HW device or re-building HW pipeline (an unique protected + * environment multiplexing capability in Intel HW). + * + * The returned protected_session represents a notion of Host and TEE clients + * while representing protection status in GPU and Display. + * + * Both contexts and protected sessions are identified by unique IDs and its + * implementation specific internals are kept opaque to the clients + */ +typedef VAGenericID VAProtectedSessionID; + +/** \brief TEE Execucte Function ID. */ +typedef enum _VA_TEE_EXEC_FUNCTION_ID { + VA_TEE_EXECUTE_FUNCTION_ID_PASS_THROUGH = 0x00000001, + VA_TEE_EXECUTE_FUNCTION_ID_GET_FIRMWARE_VERSION = 0x00000002, + +} VA_TEE_EXECUTE_FUNCTION_ID; + +/** \brief Input/Output buffer of VAProtectedSessionExecuteBuffer */ +typedef struct _VAProtectedSessionBuffer { + /* + * This is used when this buffer refer to output buffer. The maximum size of + * data that the driver can return in the output buffer. It is not used for + * input buffer. + */ + uint32_t max_data_size; + /* + * If it is used for input buffer, it is the size of the input data. If it is + * used for output buffer, it is the returns size of the output data written + * by the driver. + */ + uint32_t data_size; + /* + * data pointer of this buffer + */ + void *data; + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProtectedSessionBuffer; + +/** \brief Buffer for vaProtectedSessionExecute() */ +typedef struct _VAProtectedSessionExecuteBuffer { + /** \brief Specify the function to execute. It is IHV's implementation + * specific */ + uint32_t function_id; + /** \brief Input buffer */ + VAProtectedSessionBuffer input; + /** \brief Output buffer */ + VAProtectedSessionBuffer output; + /** \brief Return the result of this function. The status result is IHV's + * implementation specific */ + uint32_t status; + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProtectedSessionExecuteBuffer; + +/** + * \brief Create a protected session + * + * Create a protected session + * + * @param[in] dpy the VA display + * @param[in] config_id configuration for the protected session + * @param[out] protected_session created protected session id upon return + */ +VAStatus vaCreateProtectedSession(VADisplay dpy, VAConfigID config_id, + VAProtectedSessionID *protected_session); + +/** + * \brief Destroy a protected session + * + * Destroy a protected session + * + * @param[in] dpy the VA display + * @param[in] protected_session protected session to be destroyed + */ +VAStatus vaDestroyProtectedSession(VADisplay dpy, + VAProtectedSessionID protected_session); + +/** + * \brief Attach a protected content session to VA context + * + * Attach a protected content session to the context to enable + * decryption/protection + * + * @param[in] dpy the VA display + * @param[in] id the VA decode/encode/vp context + * @param[in] protected_session the protected session to attach + */ +VAStatus vaAttachProtectedSession(VADisplay dpy, VAGenericID id, + VAProtectedSessionID protected_session); + +/** + * \brief Detach the protected content session from the VA context + * + * Detach protected content session of the context to disable + * decryption/protection + * + * @param[in] dpy the VA display + * @param[in] id TEE client id to be detached + */ +VAStatus vaDetachProtectedSession(VADisplay dpy, VAGenericID id); + +/** + * \brief Execute provides a general mechanism for TEE client tasks execution. + * + * vaProtectedSessionExecute provides a mechanism for TEE clients to execute + * specific tasks. The implementation may differ between IHVs. + * This is a synchronous API. + * + * @param[in] dpy the VA display + * @param[in] protected_session the protected session + * @param[in,out] buf_id the VA buffer + */ +VAStatus vaProtectedSessionExecute(VADisplay dpy, + VAProtectedSessionID protected_session, + VABufferID buf_id); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_PROT_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_version.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_version.h new file mode 100644 index 00000000..e0eedce4 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_version.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2009 Splitted-Desktop Systems. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef VA_VERSION_H +#define VA_VERSION_H + +/** + * VA_MAJOR_VERSION: + * + * The major version of VA-API (1, if %VA_VERSION is 1.2.3) + */ +#define VA_MAJOR_VERSION 1 + +/** + * VA_MINOR_VERSION: + * + * The minor version of VA-API (2, if %VA_VERSION is 1.2.3) + */ +#define VA_MINOR_VERSION 17 + +/** + * VA_MICRO_VERSION: + * + * The micro version of VA-API (3, if %VA_VERSION is 1.2.3) + */ +#define VA_MICRO_VERSION 0 + +/** + * VA_VERSION: + * + * The full version of VA-API, like 1.2.3 + */ +#define VA_VERSION 1.17.0 + +/** + * VA_VERSION_S: + * + * The full version of VA-API, in string form (suited for string + * concatenation) + */ +#define VA_VERSION_S "1.17.0" + +/** + * VA_VERSION_HEX: + * + * Numerically encoded version of VA-API, like 0x010203 + */ +#define VA_VERSION_HEX ((VA_MAJOR_VERSION << 24) | \ + (VA_MINOR_VERSION << 16) | \ + (VA_MICRO_VERSION << 8)) + +/** + * VA_CHECK_VERSION: + * @major: major version, like 1 in 1.2.3 + * @minor: minor version, like 2 in 1.2.3 + * @micro: micro version, like 3 in 1.2.3 + * + * Evaluates to %TRUE if the version of VA-API is greater than + * @major, @minor and @micro + */ +#define VA_CHECK_VERSION(major,minor,micro) \ + (VA_MAJOR_VERSION > (major) || \ + (VA_MAJOR_VERSION == (major) && VA_MINOR_VERSION > (minor)) || \ + (VA_MAJOR_VERSION == (major) && VA_MINOR_VERSION == (minor) && VA_MICRO_VERSION >= (micro))) + +#endif /* VA_VERSION_H */ diff --git a/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_vpp.h b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_vpp.h new file mode 100644 index 00000000..193dc5f0 --- /dev/null +++ b/webrtc-jni/src/main/cpp/dependencies/libva/include/va/va_vpp.h @@ -0,0 +1,1590 @@ +/* + * Copyright (c) 2007-2011 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file va_vpp.h + * \brief The video processing API + * + * This file contains the \ref api_vpp "Video processing API". + */ + +#ifndef VA_VPP_H +#define VA_VPP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup api_vpp Video processing API + * + * @{ + * + * The video processing API uses the same paradigm as for decoding: + * - Query for supported filters; + * - Set up a video processing pipeline; + * - Send video processing parameters through VA buffers. + * + * \section api_vpp_caps Query for supported filters + * + * Checking whether video processing is supported can be performed + * with vaQueryConfigEntrypoints() and the profile argument set to + * #VAProfileNone. If video processing is supported, then the list of + * returned entry-points will include #VAEntrypointVideoProc. + * + * \code + * VAEntrypoint *entrypoints; + * int i, num_entrypoints, supportsVideoProcessing = 0; + * + * num_entrypoints = vaMaxNumEntrypoints(); + * entrypoints = malloc(num_entrypoints * sizeof(entrypoints[0]); + * vaQueryConfigEntrypoints(va_dpy, VAProfileNone, + * entrypoints, &num_entrypoints); + * + * for (i = 0; !supportsVideoProcessing && i < num_entrypoints; i++) { + * if (entrypoints[i] == VAEntrypointVideoProc) + * supportsVideoProcessing = 1; + * } + * \endcode + * + * Then, the vaQueryVideoProcFilters() function is used to query the + * list of video processing filters. + * + * \code + * VAProcFilterType filters[VAProcFilterCount]; + * unsigned int num_filters = VAProcFilterCount; + * + * // num_filters shall be initialized to the length of the array + * vaQueryVideoProcFilters(va_dpy, vpp_ctx, &filters, &num_filters); + * \endcode + * + * Finally, individual filter capabilities can be checked with + * vaQueryVideoProcFilterCaps(). + * + * \code + * VAProcFilterCap denoise_caps; + * unsigned int num_denoise_caps = 1; + * vaQueryVideoProcFilterCaps(va_dpy, vpp_ctx, + * VAProcFilterNoiseReduction, + * &denoise_caps, &num_denoise_caps + * ); + * + * VAProcFilterCapDeinterlacing deinterlacing_caps[VAProcDeinterlacingCount]; + * unsigned int num_deinterlacing_caps = VAProcDeinterlacingCount; + * vaQueryVideoProcFilterCaps(va_dpy, vpp_ctx, + * VAProcFilterDeinterlacing, + * &deinterlacing_caps, &num_deinterlacing_caps + * ); + * \endcode + * + * \section api_vpp_setup Set up a video processing pipeline + * + * A video processing pipeline buffer is created for each source + * surface we want to process. However, buffers holding filter + * parameters can be created once and for all. Rationale is to avoid + * multiple creation/destruction chains of filter buffers and also + * because filter parameters generally won't change frame after + * frame. e.g. this makes it possible to implement a checkerboard of + * videos where the same filters are applied to each video source. + * + * The general control flow is demonstrated by the following pseudo-code: + * \code + * // Create filters + * VABufferID denoise_filter, deint_filter; + * VABufferID filter_bufs[VAProcFilterCount]; + * unsigned int num_filter_bufs; + * + * for (i = 0; i < num_filters; i++) { + * switch (filters[i]) { + * case VAProcFilterNoiseReduction: { // Noise reduction filter + * VAProcFilterParameterBuffer denoise; + * denoise.type = VAProcFilterNoiseReduction; + * denoise.value = 0.5; + * vaCreateBuffer(va_dpy, vpp_ctx, + * VAProcFilterParameterBufferType, sizeof(denoise), 1, + * &denoise, &denoise_filter + * ); + * filter_bufs[num_filter_bufs++] = denoise_filter; + * break; + * } + * + * case VAProcFilterDeinterlacing: // Motion-adaptive deinterlacing + * for (j = 0; j < num_deinterlacing_caps; j++) { + * VAProcFilterCapDeinterlacing * const cap = &deinterlacing_caps[j]; + * if (cap->type != VAProcDeinterlacingMotionAdaptive) + * continue; + * + * VAProcFilterParameterBufferDeinterlacing deint; + * deint.type = VAProcFilterDeinterlacing; + * deint.algorithm = VAProcDeinterlacingMotionAdaptive; + * vaCreateBuffer(va_dpy, vpp_ctx, + * VAProcFilterParameterBufferType, sizeof(deint), 1, + * &deint, &deint_filter + * ); + * filter_bufs[num_filter_bufs++] = deint_filter; + * } + * } + * } + * \endcode + * + * Once the video processing pipeline is set up, the caller shall check the + * implied capabilities and requirements with vaQueryVideoProcPipelineCaps(). + * This function can be used to validate the number of reference frames are + * needed by the specified deinterlacing algorithm, the supported color + * primaries, etc. + * \code + * // Create filters + * VAProcPipelineCaps pipeline_caps; + * VASurfaceID *forward_references; + * unsigned int num_forward_references; + * VASurfaceID *backward_references; + * unsigned int num_backward_references; + * VAProcColorStandardType in_color_standards[VAProcColorStandardCount]; + * VAProcColorStandardType out_color_standards[VAProcColorStandardCount]; + * + * pipeline_caps.input_color_standards = NULL; + * pipeline_caps.num_input_color_standards = ARRAY_ELEMS(in_color_standards); + * pipeline_caps.output_color_standards = NULL; + * pipeline_caps.num_output_color_standards = ARRAY_ELEMS(out_color_standards); + * vaQueryVideoProcPipelineCaps(va_dpy, vpp_ctx, + * filter_bufs, num_filter_bufs, + * &pipeline_caps + * ); + * + * num_forward_references = pipeline_caps.num_forward_references; + * forward_references = + * malloc(num__forward_references * sizeof(VASurfaceID)); + * num_backward_references = pipeline_caps.num_backward_references; + * backward_references = + * malloc(num_backward_references * sizeof(VASurfaceID)); + * \endcode + * + * \section api_vpp_submit Send video processing parameters through VA buffers + * + * Video processing pipeline parameters are submitted for each source + * surface to process. Video filter parameters can also change, per-surface. + * e.g. the list of reference frames used for deinterlacing. + * + * \code + * foreach (iteration) { + * vaBeginPicture(va_dpy, vpp_ctx, vpp_surface); + * foreach (surface) { + * VARectangle output_region; + * VABufferID pipeline_buf; + * VAProcPipelineParameterBuffer *pipeline_param; + * + * vaCreateBuffer(va_dpy, vpp_ctx, + * VAProcPipelineParameterBuffer, sizeof(*pipeline_param), 1, + * NULL, &pipeline_buf + * ); + * + * // Setup output region for this surface + * // e.g. upper left corner for the first surface + * output_region.x = BORDER; + * output_region.y = BORDER; + * output_region.width = + * (vpp_surface_width - (Nx_surfaces + 1) * BORDER) / Nx_surfaces; + * output_region.height = + * (vpp_surface_height - (Ny_surfaces + 1) * BORDER) / Ny_surfaces; + * + * vaMapBuffer(va_dpy, pipeline_buf, &pipeline_param); + * pipeline_param->surface = surface; + * pipeline_param->surface_region = NULL; + * pipeline_param->output_region = &output_region; + * pipeline_param->output_background_color = 0; + * if (first surface to render) + * pipeline_param->output_background_color = 0xff000000; // black + * pipeline_param->filter_flags = VA_FILTER_SCALING_HQ; + * pipeline_param->filters = filter_bufs; + * pipeline_param->num_filters = num_filter_bufs; + * vaUnmapBuffer(va_dpy, pipeline_buf); + * + * // Update reference frames for deinterlacing, if necessary + * pipeline_param->forward_references = forward_references; + * pipeline_param->num_forward_references = num_forward_references_used; + * pipeline_param->backward_references = backward_references; + * pipeline_param->num_backward_references = num_bacward_references_used; + * + * // Apply filters + * vaRenderPicture(va_dpy, vpp_ctx, &pipeline_buf, 1); + * } + * vaEndPicture(va_dpy, vpp_ctx); + * } + * \endcode + */ + +/** \brief Video filter types. */ +typedef enum _VAProcFilterType { + VAProcFilterNone = 0, + /** \brief Noise reduction filter. */ + VAProcFilterNoiseReduction, + /** \brief Deinterlacing filter. */ + VAProcFilterDeinterlacing, + /** \brief Sharpening filter. */ + VAProcFilterSharpening, + /** \brief Color balance parameters. */ + VAProcFilterColorBalance, + /** \brief Skin Tone Enhancement. */ + VAProcFilterSkinToneEnhancement, + /** \brief Total Color Correction. */ + VAProcFilterTotalColorCorrection, + /** \brief Human Vision System(HVS) Noise reduction filter. */ + VAProcFilterHVSNoiseReduction, + /** \brief High Dynamic Range Tone Mapping. */ + VAProcFilterHighDynamicRangeToneMapping, + /** \brief Three-Dimensional Look Up Table (3DLUT). */ + VAProcFilter3DLUT, + /** \brief Number of video filters. */ + VAProcFilterCount +} VAProcFilterType; + +/** \brief Deinterlacing types. */ +typedef enum _VAProcDeinterlacingType { + VAProcDeinterlacingNone = 0, + /** \brief Bob deinterlacing algorithm. */ + VAProcDeinterlacingBob, + /** \brief Weave deinterlacing algorithm. */ + VAProcDeinterlacingWeave, + /** \brief Motion adaptive deinterlacing algorithm. */ + VAProcDeinterlacingMotionAdaptive, + /** \brief Motion compensated deinterlacing algorithm. */ + VAProcDeinterlacingMotionCompensated, + /** \brief Number of deinterlacing algorithms. */ + VAProcDeinterlacingCount +} VAProcDeinterlacingType; + +/** \brief Color balance types. */ +typedef enum _VAProcColorBalanceType { + VAProcColorBalanceNone = 0, + /** \brief Hue. */ + VAProcColorBalanceHue, + /** \brief Saturation. */ + VAProcColorBalanceSaturation, + /** \brief Brightness. */ + VAProcColorBalanceBrightness, + /** \brief Contrast. */ + VAProcColorBalanceContrast, + /** \brief Automatically adjusted saturation. */ + VAProcColorBalanceAutoSaturation, + /** \brief Automatically adjusted brightness. */ + VAProcColorBalanceAutoBrightness, + /** \brief Automatically adjusted contrast. */ + VAProcColorBalanceAutoContrast, + /** \brief Number of color balance attributes. */ + VAProcColorBalanceCount +} VAProcColorBalanceType; + +/** \brief Color standard types. + * + * These define a set of color properties corresponding to particular + * video standards. + * + * Where matrix_coefficients is specified, it applies only to YUV data - + * RGB data always use the identity matrix (matrix_coefficients = 0). + */ +typedef enum _VAProcColorStandardType { + VAProcColorStandardNone = 0, + /** \brief ITU-R BT.601. + * + * It is unspecified whether this will use 525-line or 625-line values; + * specify the colour primaries and matrix coefficients explicitly if + * it is known which one is required. + * + * Equivalent to: + * colour_primaries = 5 or 6 + * transfer_characteristics = 6 + * matrix_coefficients = 5 or 6 + */ + VAProcColorStandardBT601, + /** \brief ITU-R BT.709. + * + * Equivalent to: + * colour_primaries = 1 + * transfer_characteristics = 1 + * matrix_coefficients = 1 + */ + VAProcColorStandardBT709, + /** \brief ITU-R BT.470-2 System M. + * + * Equivalent to: + * colour_primaries = 4 + * transfer_characteristics = 4 + * matrix_coefficients = 4 + */ + VAProcColorStandardBT470M, + /** \brief ITU-R BT.470-2 System B, G. + * + * Equivalent to: + * colour_primaries = 5 + * transfer_characteristics = 5 + * matrix_coefficients = 5 + */ + VAProcColorStandardBT470BG, + /** \brief SMPTE-170M. + * + * Equivalent to: + * colour_primaries = 6 + * transfer_characteristics = 6 + * matrix_coefficients = 6 + */ + VAProcColorStandardSMPTE170M, + /** \brief SMPTE-240M. + * + * Equivalent to: + * colour_primaries = 7 + * transfer_characteristics = 7 + * matrix_coefficients = 7 + */ + VAProcColorStandardSMPTE240M, + /** \brief Generic film. + * + * Equivalent to: + * colour_primaries = 8 + * transfer_characteristics = 1 + * matrix_coefficients = 1 + */ + VAProcColorStandardGenericFilm, + /** \brief sRGB. + * + * Equivalent to: + * colour_primaries = 1 + * transfer_characteristics = 13 + * matrix_coefficients = 0 + */ + VAProcColorStandardSRGB, + /** \brief stRGB. + * + * ??? + */ + VAProcColorStandardSTRGB, + /** \brief xvYCC601. + * + * Equivalent to: + * colour_primaries = 1 + * transfer_characteristics = 11 + * matrix_coefficients = 5 + */ + VAProcColorStandardXVYCC601, + /** \brief xvYCC709. + * + * Equivalent to: + * colour_primaries = 1 + * transfer_characteristics = 11 + * matrix_coefficients = 1 + */ + VAProcColorStandardXVYCC709, + /** \brief ITU-R BT.2020. + * + * Equivalent to: + * colour_primaries = 9 + * transfer_characteristics = 14 + * matrix_coefficients = 9 + */ + VAProcColorStandardBT2020, + /** \brief Explicitly specified color properties. + * + * Use corresponding color properties section. + * For example, HDR10 content: + * colour_primaries = 9 (BT2020) + * transfer_characteristics = 16 (SMPTE ST2084) + * matrix_coefficients = 9 + */ + VAProcColorStandardExplicit, + /** \brief Number of color standards. */ + VAProcColorStandardCount +} VAProcColorStandardType; + +/** \brief Total color correction types. */ +typedef enum _VAProcTotalColorCorrectionType { + VAProcTotalColorCorrectionNone = 0, + /** \brief Red Saturation. */ + VAProcTotalColorCorrectionRed, + /** \brief Green Saturation. */ + VAProcTotalColorCorrectionGreen, + /** \brief Blue Saturation. */ + VAProcTotalColorCorrectionBlue, + /** \brief Cyan Saturation. */ + VAProcTotalColorCorrectionCyan, + /** \brief Magenta Saturation. */ + VAProcTotalColorCorrectionMagenta, + /** \brief Yellow Saturation. */ + VAProcTotalColorCorrectionYellow, + /** \brief Number of color correction attributes. */ + VAProcTotalColorCorrectionCount +} VAProcTotalColorCorrectionType; + +/** \brief High Dynamic Range Metadata types. */ +typedef enum _VAProcHighDynamicRangeMetadataType { + VAProcHighDynamicRangeMetadataNone = 0, + /** \brief Metadata type for HDR10. */ + VAProcHighDynamicRangeMetadataHDR10, + /** \brief Number of Metadata type. */ + VAProcHighDynamicRangeMetadataTypeCount +} VAProcHighDynamicRangeMetadataType; + +/** \brief Video Processing Mode. */ +typedef enum _VAProcMode { + /** + * \brief Default Mode. + * In this mode, pipeline is decided in driver to the appropriate mode. + * e.g. a mode that's a balance between power and performance. + */ + VAProcDefaultMode = 0, + /** + * \brief Power Saving Mode. + * In this mode, pipeline is optimized for power saving. + */ + VAProcPowerSavingMode, + /** + * \brief Performance Mode. + * In this mode, pipeline is optimized for performance. + */ + VAProcPerformanceMode +} VAProcMode; + +/** @name Video blending flags */ +/**@{*/ +/** \brief Global alpha blending. */ +#define VA_BLEND_GLOBAL_ALPHA 0x0001 +/** \brief Premultiplied alpha blending (RGBA surfaces only). */ +#define VA_BLEND_PREMULTIPLIED_ALPHA 0x0002 +/** \brief Luma color key (YUV surfaces only). */ +#define VA_BLEND_LUMA_KEY 0x0010 +/**@}*/ + +/** \brief Video blending state definition. */ +typedef struct _VABlendState { + /** \brief Video blending flags. */ + unsigned int flags; + /** + * \brief Global alpha value. + * + * Valid if \flags has VA_BLEND_GLOBAL_ALPHA. + * Valid range is 0.0 to 1.0 inclusive. + */ + float global_alpha; + /** + * \brief Minimum luma value. + * + * Valid if \flags has VA_BLEND_LUMA_KEY. + * Valid range is 0.0 to 1.0 inclusive. + * \ref min_luma shall be set to a sensible value lower than \ref max_luma. + */ + float min_luma; + /** + * \brief Maximum luma value. + * + * Valid if \flags has VA_BLEND_LUMA_KEY. + * Valid range is 0.0 to 1.0 inclusive. + * \ref max_luma shall be set to a sensible value larger than \ref min_luma. + */ + float max_luma; +} VABlendState; + +/** @name Video pipeline flags */ +/**@{*/ +/** \brief Specifies whether to apply subpictures when processing a surface. */ +#define VA_PROC_PIPELINE_SUBPICTURES 0x00000001 +/** + * \brief Specifies whether to apply power or performance + * optimizations to a pipeline. + * + * When processing several surfaces, it may be necessary to prioritize + * more certain pipelines than others. This flag is only a hint to the + * video processor so that it can omit certain filters to save power + * for example. Typically, this flag could be used with video surfaces + * decoded from a secondary bitstream. + */ +#define VA_PROC_PIPELINE_FAST 0x00000002 +/**@}*/ + +/** @name Video filter flags */ +/**@{*/ +/** \brief Specifies whether the filter shall be present in the pipeline. */ +#define VA_PROC_FILTER_MANDATORY 0x00000001 +/**@}*/ + +/** @name Pipeline end flags */ +/**@{*/ +/** \brief Specifies the pipeline is the last. */ +#define VA_PIPELINE_FLAG_END 0x00000004 +/**@}*/ + +/** @name Chroma Siting flag */ +/**@{*/ +/** vertical chroma sitting take bit 0-1, horizontal chroma sitting take bit 2-3 + * vertical chromma siting | horizontal chroma sitting to be chroma sitting */ +#define VA_CHROMA_SITING_UNKNOWN 0x00 +/** \brief Chroma samples are co-sited vertically on the top with the luma samples. */ +#define VA_CHROMA_SITING_VERTICAL_TOP 0x01 +/** \brief Chroma samples are not co-sited vertically with the luma samples. */ +#define VA_CHROMA_SITING_VERTICAL_CENTER 0x02 +/** \brief Chroma samples are co-sited vertically on the bottom with the luma samples. */ +#define VA_CHROMA_SITING_VERTICAL_BOTTOM 0x03 +/** \brief Chroma samples are co-sited horizontally on the left with the luma samples. */ +#define VA_CHROMA_SITING_HORIZONTAL_LEFT 0x04 +/** \brief Chroma samples are not co-sited horizontally with the luma samples. */ +#define VA_CHROMA_SITING_HORIZONTAL_CENTER 0x08 +/**@}*/ + +/** + * This is to indicate that the color-space conversion uses full range or reduced range. + * VA_SOURCE_RANGE_FULL(Full range): Y/Cb/Cr is in [0, 255]. It is mainly used + * for JPEG/JFIF formats. The combination with the BT601 flag means that + * JPEG/JFIF color-space conversion matrix is used. + * VA_SOURCE_RANGE_REDUCED(Reduced range): Y is in [16, 235] and Cb/Cr is in [16, 240]. + * It is mainly used for the YUV->RGB color-space conversion in SDTV/HDTV/UHDTV. + */ +#define VA_SOURCE_RANGE_UNKNOWN 0 +#define VA_SOURCE_RANGE_REDUCED 1 +#define VA_SOURCE_RANGE_FULL 2 + +/** @name Tone Mapping flags multiple HDR mode*/ +/**@{*/ +/** \brief Tone Mapping from HDR content to HDR display. */ +#define VA_TONE_MAPPING_HDR_TO_HDR 0x0001 +/** \brief Tone Mapping from HDR content to SDR display. */ +#define VA_TONE_MAPPING_HDR_TO_SDR 0x0002 +/** \brief Tone Mapping from HDR content to EDR display. */ +#define VA_TONE_MAPPING_HDR_TO_EDR 0x0004 +/** \brief Tone Mapping from SDR content to HDR display. */ +#define VA_TONE_MAPPING_SDR_TO_HDR 0x0008 +/**@}*/ + +/** \brief Video processing pipeline capabilities. */ +typedef struct _VAProcPipelineCaps { + /** \brief Pipeline flags. See VAProcPipelineParameterBuffer::pipeline_flags. */ + uint32_t pipeline_flags; + /** \brief Extra filter flags. See VAProcPipelineParameterBuffer::filter_flags. */ + uint32_t filter_flags; + /** \brief Number of forward reference frames that are needed. */ + uint32_t num_forward_references; + /** \brief Number of backward reference frames that are needed. */ + uint32_t num_backward_references; + /** \brief List of color standards supported on input. */ + VAProcColorStandardType *input_color_standards; + /** \brief Number of elements in \ref input_color_standards array. */ + uint32_t num_input_color_standards; + /** \brief List of color standards supported on output. */ + VAProcColorStandardType *output_color_standards; + /** \brief Number of elements in \ref output_color_standards array. */ + uint32_t num_output_color_standards; + + /** + * \brief Rotation flags. + * + * For each rotation angle supported by the underlying hardware, + * the corresponding bit is set in \ref rotation_flags. See + * "Rotation angles" for a description of rotation angles. + * + * A value of 0 means the underlying hardware does not support any + * rotation. Otherwise, a check for a specific rotation angle can be + * performed as follows: + * + * \code + * VAProcPipelineCaps pipeline_caps; + * ... + * vaQueryVideoProcPipelineCaps(va_dpy, vpp_ctx, + * filter_bufs, num_filter_bufs, + * &pipeline_caps + * ); + * ... + * if (pipeline_caps.rotation_flags & (1 << VA_ROTATION_xxx)) { + * // Clockwise rotation by xxx degrees is supported + * ... + * } + * \endcode + */ + uint32_t rotation_flags; + /** \brief Blend flags. See "Video blending flags". */ + uint32_t blend_flags; + /** + * \brief Mirroring flags. + * + * For each mirroring direction supported by the underlying hardware, + * the corresponding bit is set in \ref mirror_flags. See + * "Mirroring directions" for a description of mirroring directions. + * + */ + uint32_t mirror_flags; + /** \brief Number of additional output surfaces supported by the pipeline */ + uint32_t num_additional_outputs; + + /** \brief Number of elements in \ref input_pixel_format array. */ + uint32_t num_input_pixel_formats; + /** \brief List of input pixel formats in fourcc. */ + uint32_t *input_pixel_format; + /** \brief Number of elements in \ref output_pixel_format array. */ + uint32_t num_output_pixel_formats; + /** \brief List of output pixel formats in fourcc. */ + uint32_t *output_pixel_format; + + /** \brief Max supported input width in pixels. */ + uint32_t max_input_width; + /** \brief Max supported input height in pixels. */ + uint32_t max_input_height; + /** \brief Min supported input width in pixels. */ + uint32_t min_input_width; + /** \brief Min supported input height in pixels. */ + uint32_t min_input_height; + + /** \brief Max supported output width in pixels. */ + uint32_t max_output_width; + /** \brief Max supported output height in pixels. */ + uint32_t max_output_height; + /** \brief Min supported output width in pixels. */ + uint32_t min_output_width; + /** \brief Min supported output height in pixels. */ + uint32_t min_output_height; + /** \brief Reserved bytes for future use, must be zero */ +#if defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__) || defined(__LP64__) + uint32_t va_reserved[VA_PADDING_HIGH - 2]; +#else + uint32_t va_reserved[VA_PADDING_HIGH]; +#endif +} VAProcPipelineCaps; + +/** \brief Specification of values supported by the filter. */ +typedef struct _VAProcFilterValueRange { + /** \brief Minimum value supported, inclusive. */ + float min_value; + /** \brief Maximum value supported, inclusive. */ + float max_value; + /** \brief Default value. */ + float default_value; + /** \brief Step value that alters the filter behaviour in a sensible way. */ + float step; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProcFilterValueRange; + +typedef struct _VAProcColorProperties { + /** Chroma sample location.\c VA_CHROMA_SITING_VERTICAL_XXX | VA_CHROMA_SITING_HORIZONTAL_XXX */ + uint8_t chroma_sample_location; + /** Color range. \c VA_SOURCE_RANGE_XXX*/ + uint8_t color_range; + /** Colour primaries. + * + * See ISO/IEC 23001-8 or ITU H.273, section 8.1 and table 2. + * Only used if the color standard in use is \c VAColorStandardExplicit. + * Below list the typical colour primaries for the reference. + * --------------------------------------------------------------------------------- + * | Value | Primaries | Informative Remark | + * -------------------------------------------------------------------------------- + * | 1 |primary x y |Rec.ITU-R BT.709-5 | + * | |green 0.300 0.600 |IEC 61966-2-1(sRGB or sYCC) | + * | |blue 0.150 0.060 | | + * | |red 0.640 0.330 | | + * | |whiteD65 0.3127 0.3290 | | + * --------------------------------------------------------------------------------- + * | 6 |primary x y |Rec.ITU-R BT.601-6 525 | + * | |green 0.310 0.595 | | + * | |blue 0.155 0.070 | | + * | |red 0.630 0.340 | | + * | |whiteD65 0.3127 0.3290 | | + * --------------------------------------------------------------------------------- + * | 9 |primary x y |Rec.ITU-R BT.2020 | + * | |green 0.170 0.797 | | + * | |blue 0.131 0.046 | | + * | |red 0.708 0.292 | | + * | |whiteD65 0.3127 0.3290 | | + * --------------------------------------------------------------------------------- + */ + uint8_t colour_primaries; + /** Transfer characteristics. + * + * See ISO/IEC 23001-8 or ITU H.273, section 8.2 and table 3. + * Only used if the color standard in use is \c VAColorStandardExplicit. + * Below list the typical transfer characteristics for the reference. + * ----------------------------------------------------------- + * | Value | Informative Remark | + * ----------------------------------------------------------- + * | 1 |Rec.ITU-R BT.709-5 | + * | |colour gamut system | + * ----------------------------------------------------------- + * | 4 |Assumed display gamma 2.2 | + * ----------------------------------------------------------- + * | 6 |Rec.ITU-R BT.601-6 525 or 625 | + * ----------------------------------------------------------- + * | 8 |Linear transfer characteristics | + * ----------------------------------------------------------- + * | 13 |IEC 61966-2-1(sRGB or sYCC) | + * ----------------------------------------------------------- + * | 14,15 |Rec.ITU-R BT.2020 | + * ----------------------------------------------------------- + * | 16 |SMPTE ST 2084 for 10,12,14 and 16bit system | + * ----------------------------------------------------------- + */ + uint8_t transfer_characteristics; + /** Matrix coefficients. + * + * See ISO/IEC 23001-8 or ITU H.273, section 8.3 and table 4. + * Only used if the color standard in use is \c VAColorStandardExplicit. + */ + uint8_t matrix_coefficients; + /** Reserved bytes for future use, must be zero. */ + uint8_t reserved[3]; +} VAProcColorProperties; + +/** \brief Describes High Dynamic Range Meta Data for HDR10. + * + * Specifies the colour volume(the colour primaries, white point and luminance range) of + * a display considered to be the mastering display for the associated video content -e.g., + * the colour volume of a display that was used for viewing while authoring the video content. + * See ITU-T H.265 D.3.27 Mastering display colour volume SEI message semantics. + * + * Specifies upper bounds for the nominal light level of the content. See ITU-T H.265 D.3.35 + * Content light level information SEI message semantics. + * + * This structure can be used to indicate the HDR10 metadata for 1) the content which was authored; + * 2) the display on which the content will be presented. If it is for display, max_content_light_level + * and max_pic_average_light_level are ignored. + */ +typedef struct _VAHdrMetaDataHDR10 { + /** + * \brief X chromaticity coordinate of the mastering display. + * + * Index value c equal to 0 should correspond to the green primary. + * Index value c equal to 1 should correspond to the blue primary. + * Index value c equal to 2 should correspond to the red primary. + * The value for display_primaries_x shall be in the range of 0 to 50000 inclusive. + */ + uint16_t display_primaries_x[3]; + /** + * \brief Y chromaticity coordinate of the mastering display. + * + * Index value c equal to 0 should correspond to the green primary. + * Index value c equal to 1 should correspond to the blue primary. + * Index value c equal to 2 should correspond to the red primary. + * The value for display_primaries_y shall be in the range of 0 to 50000 inclusive. + */ + uint16_t display_primaries_y[3]; + /** + * \brief X chromaticity coordinate of the white point of the mastering display. + * + * The value for white_point_x shall be in the range of 0 to 50000 inclusive. + */ + uint16_t white_point_x; + /** + * \brief Y chromaticity coordinate of the white point of the mastering display. + * + * The value for white_point_y shall be in the range of 0 to 50000 inclusive. + */ + uint16_t white_point_y; + /** + * \brief The maximum display luminance of the mastering display. + * + * The value is in units of 0.0001 candelas per square metre. + */ + uint32_t max_display_mastering_luminance; + /** + * \brief The minumum display luminance of the mastering display. + * + * The value is in units of 0.0001 candelas per square metre. + */ + uint32_t min_display_mastering_luminance; + /** + * \brief The maximum content light level (MaxCLL). + * + * The value is in units of 1 candelas per square metre. + */ + uint16_t max_content_light_level; + /** + * \brief The maximum picture average light level (MaxFALL). + * + * The value is in units of 1 candelas per square metre. + */ + uint16_t max_pic_average_light_level; + /** Resevered */ + uint16_t reserved[VA_PADDING_HIGH]; +} VAHdrMetaDataHDR10; + +/** \brief Capabilities specification for the High Dynamic Range filter. */ +typedef struct _VAProcFilterCapHighDynamicRange { + /** \brief high dynamic range type. */ + VAProcHighDynamicRangeMetadataType metadata_type; + /** + * \brief flag for high dynamic range tone mapping + * + * The flag is the combination of VA_TONE_MAPPING_XXX_TO_XXX. + * It could be VA_TONE_MAPPING_HDR_TO_HDR | VA_TONE_MAPPING_HDR_TO_SDR. + * SDR content to SDR display is always supported by default since it is legacy path. + */ + uint16_t caps_flag; + /** \brief Reserved bytes for future use, must be zero */ + uint16_t va_reserved[VA_PADDING_HIGH]; +} VAProcFilterCapHighDynamicRange; + +/** \brief High Dynamic Range Meta Data. */ +typedef struct _VAHdrMetaData { + /** \brief high dynamic range metadata type, HDR10 etc. */ + VAProcHighDynamicRangeMetadataType metadata_type; + /** + * \brief Pointer to high dynamic range metadata. + * + * The pointer could point to VAHdrMetaDataHDR10 or other HDR meta data. + */ + void* metadata; + /** + * \brief Size of high dynamic range metadata. + */ + uint32_t metadata_size; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t reserved[VA_PADDING_LOW]; +} VAHdrMetaData; + +/** + * \brief Video processing pipeline configuration. + * + * This buffer defines a video processing pipeline. The actual filters to + * be applied are provided in the \c filters field, they can be re-used + * in other processing pipelines. + * + * The target surface is specified by the \c render_target argument of + * \c vaBeginPicture(). The general usage model is described as follows: + * - \c vaBeginPicture(): specify the target surface that receives the + * processed output; + * - \c vaRenderPicture(): specify a surface to be processed and composed + * into the \c render_target. Use as many \c vaRenderPicture() calls as + * necessary surfaces to compose ; + * - \c vaEndPicture(): tell the driver to start processing the surfaces + * with the requested filters. + * + * If a filter (e.g. noise reduction) needs to be applied with different + * values for multiple surfaces, the application needs to create as many + * filter parameter buffers as necessary. i.e. the filter parameters shall + * not change between two calls to \c vaRenderPicture(). + * + * For composition usage models, the first surface to process will generally + * use an opaque background color, i.e. \c output_background_color set with + * the most significant byte set to \c 0xff. For instance, \c 0xff000000 for + * a black background. Then, subsequent surfaces would use a transparent + * background color. + */ +typedef struct _VAProcPipelineParameterBuffer { + /** + * \brief Source surface ID. + * + * ID of the source surface to process. If subpictures are associated + * with the video surfaces then they shall be rendered to the target + * surface, if the #VA_PROC_PIPELINE_SUBPICTURES pipeline flag is set. + */ + VASurfaceID surface; + /** + * \brief Region within the source surface to be processed. + * + * Pointer to a #VARectangle defining the region within the source + * surface to be processed. If NULL, \c surface_region implies the + * whole surface. + */ + const VARectangle *surface_region; + /** + * \brief Requested input color standard. + * + * Color properties are implicitly converted throughout the processing + * pipeline. The video processor chooses the best moment to apply + * this conversion. The set of supported color standards for input shall + * be queried with vaQueryVideoProcPipelineCaps(). + * + * If this is set to VAProcColorStandardExplicit, the color properties + * are specified explicitly in surface_color_properties instead. + */ + VAProcColorStandardType surface_color_standard; + /** + * \brief Region within the output surface. + * + * Pointer to a #VARectangle defining the region within the output + * surface that receives the processed pixels. If NULL, \c output_region + * implies the whole surface. + * + * Note that any pixels residing outside the specified region will + * be filled in with the \ref output_background_color. + */ + const VARectangle *output_region; + /** + * \brief Background color. + * + * Background color used to fill in pixels that reside outside of the + * specified \ref output_region. The color is specified in ARGB format: + * [31:24] alpha, [23:16] red, [15:8] green, [7:0] blue. + * + * Unless the alpha value is zero or the \ref output_region represents + * the whole target surface size, implementations shall not render the + * source surface to the target surface directly. Rather, in order to + * maintain the exact semantics of \ref output_background_color, the + * driver shall use a temporary surface and fill it in with the + * appropriate background color. Next, the driver will blend this + * temporary surface into the target surface. + */ + uint32_t output_background_color; + /** + * \brief Requested output color standard. + * + * If this is set to VAProcColorStandardExplicit, the color properties + * are specified explicitly in output_color_properties instead. + */ + VAProcColorStandardType output_color_standard; + /** + * \brief Pipeline filters. See video pipeline flags. + * + * Flags to control the pipeline, like whether to apply subpictures + * or not, notify the driver that it can opt for power optimizations, + * should this be needed. + */ + uint32_t pipeline_flags; + /** + * \brief Extra filter flags. See vaPutSurface() flags. + * + * Filter flags are used as a fast path, wherever possible, to use + * vaPutSurface() flags instead of explicit filter parameter buffers. + * + * Allowed filter flags API-wise. Use vaQueryVideoProcPipelineCaps() + * to check for implementation details: + * - Bob-deinterlacing: \c VA_FRAME_PICTURE, \c VA_TOP_FIELD, + * \c VA_BOTTOM_FIELD. Note that any deinterlacing filter + * (#VAProcFilterDeinterlacing) will override those flags. + * - Color space conversion: \c VA_SRC_BT601, \c VA_SRC_BT709, + * \c VA_SRC_SMPTE_240. + * - Scaling: \c VA_FILTER_SCALING_DEFAULT, \c VA_FILTER_SCALING_FAST, + * \c VA_FILTER_SCALING_HQ, \c VA_FILTER_SCALING_NL_ANAMORPHIC. + * - Interpolation Method: \c VA_FILTER_INTERPOLATION_DEFAULT, + * \c VA_FILTER_INTERPOLATION_NEAREST_NEIGHBOR, + * \c VA_FILTER_INTERPOLATION_BILINEAR, \c VA_FILTER_INTERPOLATION_ADVANCED. + */ + uint32_t filter_flags; + /** + * \brief Array of filters to apply to the surface. + * + * The list of filters shall be ordered in the same way the driver expects + * them. i.e. as was returned from vaQueryVideoProcFilters(). + * Otherwise, a #VA_STATUS_ERROR_INVALID_FILTER_CHAIN is returned + * from vaRenderPicture() with this buffer. + * + * #VA_STATUS_ERROR_UNSUPPORTED_FILTER is returned if the list + * contains an unsupported filter. + * + */ + VABufferID *filters; + /** \brief Actual number of filters. */ + uint32_t num_filters; + /** \brief Array of forward reference frames (past frames). */ + VASurfaceID *forward_references; + /** \brief Number of forward reference frames that were supplied. */ + uint32_t num_forward_references; + /** \brief Array of backward reference frames (future frames). */ + VASurfaceID *backward_references; + /** \brief Number of backward reference frames that were supplied. */ + uint32_t num_backward_references; + /** + * \brief Rotation state. See rotation angles. + * + * The rotation angle is clockwise. There is no specific rotation + * center for this operation. Rather, The source \ref surface is + * first rotated by the specified angle and then scaled to fit the + * \ref output_region. + * + * This means that the top-left hand corner (0,0) of the output + * (rotated) surface is expressed as follows: + * - \ref VA_ROTATION_NONE: (0,0) is the top left corner of the + * source surface -- no rotation is performed ; + * - \ref VA_ROTATION_90: (0,0) is the bottom-left corner of the + * source surface ; + * - \ref VA_ROTATION_180: (0,0) is the bottom-right corner of the + * source surface -- the surface is flipped around the X axis ; + * - \ref VA_ROTATION_270: (0,0) is the top-right corner of the + * source surface. + * + * Check VAProcPipelineCaps::rotation_flags first prior to + * defining a specific rotation angle. Otherwise, the hardware can + * perfectly ignore this variable if it does not support any + * rotation. + */ + uint32_t rotation_state; + /** + * \brief blending state. See "Video blending state definition". + * + * If \ref blend_state is NULL, then default operation mode depends + * on the source \ref surface format: + * - RGB: per-pixel alpha blending ; + * - YUV: no blending, i.e override the underlying pixels. + * + * Otherwise, \ref blend_state is a pointer to a #VABlendState + * structure that shall be live until vaEndPicture(). + * + * Implementation note: the driver is responsible for checking the + * blend state flags against the actual source \ref surface format. + * e.g. premultiplied alpha blending is only applicable to RGB + * surfaces, and luma keying is only applicable to YUV surfaces. + * If a mismatch occurs, then #VA_STATUS_ERROR_INVALID_BLEND_STATE + * is returned. + */ + const VABlendState *blend_state; + /** + * \bried mirroring state. See "Mirroring directions". + * + * Mirroring of an image can be performed either along the + * horizontal or vertical axis. It is assumed that the rotation + * operation is always performed before the mirroring operation. + */ + uint32_t mirror_state; + /** \brief Array of additional output surfaces. */ + VASurfaceID *additional_outputs; + /** \brief Number of additional output surfaces. */ + uint32_t num_additional_outputs; + /** + * \brief Flag to indicate the input surface flag + * + * bit0~3: Surface sample type + * - 0000: Progressive --> VA_FRAME_PICTURE + * - 0001: Single Top Field --> VA_TOP_FIELD + * - 0010: Single Bottom Field --> VA_BOTTOM_FIELD + * - 0100: Interleaved Top Field First --> VA_TOP_FIELD_FIRST + * - 1000: Interleaved Bottom Field First --> VA_BOTTOM_FIELD_FIRST + * + * For interlaced scaling, examples as follow: + * - 1. Interleaved to Interleaved (Suppose input is top field first) + * -- set input_surface_flag as VA_TOP_FIELD_FIRST + * -- set output_surface_flag as VA_TOP_FIELD_FIRST + * - 2. Interleaved to Field (Suppose input is top field first) + * An interleaved frame need to be passed twice. + * First cycle to get the first field: + * -- set input_surface_flag as VA_TOP_FIELD_FIRST + * -- set output_surface_flag as VA_TOP_FIELD + * Second cycle to get the second field: + * -- set input_surface_flag as VA_TOP_FIELD_FIRST + * -- set output_surface_flag as VA_BOTTOM_FIELD + * - 3. Field to Interleaved (Suppose first field is top field) + * -- create two surfaces, one for top field, the other for bottom field + * -- set surface with the first field surface id + * -- set backward_reference with the second field surface id + * -- set input_surface_flag as VA_TOP_FIELD + * -- set output_surface_flag as VA_TOP_FIELD_FIRST + * - 4. Field to Field: + * -- set flag according to each frame. + * + * bit31: Surface encryption + * - 0: non-protected + * - 1: protected + * + * bit4~30 for future + */ + uint32_t input_surface_flag; + /** + * \brief Flag to indicate the output surface flag + * + * bit0~3: Surface sample type + * - 0000: Progressive --> VA_FRAME_PICTURE + * - 0001: Top Field --> VA_TOP_FIELD + * - 0010: Bottom Field --> VA_BOTTOM_FIELD + * - 0100: Top Field First --> VA_TOP_FIELD_FIRST + * - 1000: Bottom Field First --> VA_BOTTOM_FIELD_FIRST + * + * bit31: Surface encryption + * - 0: non-protected + * - 1: protected + * + * bit4~30 for future + */ + uint32_t output_surface_flag; + /** + * \brief Input Color Properties. See "VAProcColorProperties". + */ + VAProcColorProperties input_color_properties; + /** + * \brief Output Color Properties. See "VAProcColorProperties". + */ + VAProcColorProperties output_color_properties; + /** + * \brief Processing mode. See "VAProcMode". + */ + VAProcMode processing_mode; + /** + * \brief Output High Dynamic Metadata. + * + * If output_metadata is NULL, then output default to SDR. + */ + VAHdrMetaData *output_hdr_metadata; + + /** \brief Reserved bytes for future use, must be zero */ +#if defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)|| defined(__LP64__) + uint32_t va_reserved[VA_PADDING_LARGE - 16]; +#else + uint32_t va_reserved[VA_PADDING_LARGE - 13]; +#endif +} VAProcPipelineParameterBuffer; + +/** + * \brief Filter parameter buffer base. + * + * This is a helper structure used by driver implementations only. + * Users are not supposed to allocate filter parameter buffers of this + * type. + */ +typedef struct _VAProcFilterParameterBufferBase { + /** \brief Filter type. */ + VAProcFilterType type; +} VAProcFilterParameterBufferBase; + +/** + * \brief Default filter parametrization. + * + * Unless there is a filter-specific parameter buffer, + * #VAProcFilterParameterBuffer is the default type to use. + */ +typedef struct _VAProcFilterParameterBuffer { + /** \brief Filter type. */ + VAProcFilterType type; + /** \brief Value. */ + float value; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProcFilterParameterBuffer; + +/** @name De-interlacing flags */ +/**@{*/ +/** + * \brief Bottom field first in the input frame. + * if this is not set then assumes top field first. + */ +#define VA_DEINTERLACING_BOTTOM_FIELD_FIRST 0x0001 +/** + * \brief Bottom field used in deinterlacing. + * if this is not set then assumes top field is used. + */ +#define VA_DEINTERLACING_BOTTOM_FIELD 0x0002 +/** + * \brief A single field is stored in the input frame. + * if this is not set then assumes the frame contains two interleaved fields. + */ +#define VA_DEINTERLACING_ONE_FIELD 0x0004 +/** + * \brief Film Mode Detection is enabled. If enabled, driver performs inverse + * of various pulldowns, such as 3:2 pulldown. + * if this is not set then assumes FMD is disabled. + */ +#define VA_DEINTERLACING_FMD_ENABLE 0x0008 + +//Scene change parameter for ADI on Linux, if enabled, driver use spatial DI(Bob), instead of ADI. if not, use old behavior for ADI +//Input stream is TFF(set flags = 0), SRC0,1,2,3 are interlaced frame (top +bottom fields), DSTs are progressive frames +//30i->30p +//SRC0 -> BOBDI, no reference, set flag = 0, output DST0 +//SRC1 -> ADI, reference frame=SRC0, set flags = 0, call VP, output DST1 +//SRC2 -> ADI, reference frame=SRC1, set flags = 0x0010(decimal 16), call VP, output DST2(T4) +//SRC3 -> ADI, reference frame=SRC2, set flags = 0, call VP, output DST3 +//30i->60p +//SRC0 -> BOBDI, no reference, set flag = 0, output DST0 +//SRC0 -> BOBDI, no reference, set flag =0x0002, output DST1 + +//SRC1 -> ADI, reference frame =SRC0, set flags = 0, call VP, output DST2 +//SRC1 -> ADI, reference frame =SRC0, set flags = 0x0012(decimal18), call VP, output DST3(B3) + +//SRC2 -> ADI, reference frame =SRC1, set flags = 0x0010(decimal 16), call VP, output DST4(T4) +//SRC2 -> ADI, reference frame =SRC1, set flags = 0x0002, call VP, output DST5 + +//SRC3 -> ADI, reference frame =SRC2, set flags = 0, call VP, output DST6 +//SRC3 -> ADI, reference frame =SRC1, set flags = 0x0002, call VP, output DST7 + +#define VA_DEINTERLACING_SCD_ENABLE 0x0010 + +/**@}*/ + +/** \brief Deinterlacing filter parametrization. */ +typedef struct _VAProcFilterParameterBufferDeinterlacing { + /** \brief Filter type. Shall be set to #VAProcFilterDeinterlacing. */ + VAProcFilterType type; + /** \brief Deinterlacing algorithm. */ + VAProcDeinterlacingType algorithm; + /** \brief Deinterlacing flags. */ + uint32_t flags; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProcFilterParameterBufferDeinterlacing; + +/** + * \brief Color balance filter parametrization. + * + * This buffer defines color balance attributes. A VA buffer can hold + * several color balance attributes by creating a VA buffer of desired + * number of elements. This can be achieved by the following pseudo-code: + * + * \code + * enum { kHue, kSaturation, kBrightness, kContrast }; + * + * // Initial color balance parameters + * static const VAProcFilterParameterBufferColorBalance colorBalanceParams[4] = + * { + * [kHue] = + * { VAProcFilterColorBalance, VAProcColorBalanceHue, 0.5 }, + * [kSaturation] = + * { VAProcFilterColorBalance, VAProcColorBalanceSaturation, 0.5 }, + * [kBrightness] = + * { VAProcFilterColorBalance, VAProcColorBalanceBrightness, 0.5 }, + * [kSaturation] = + * { VAProcFilterColorBalance, VAProcColorBalanceSaturation, 0.5 } + * }; + * + * // Create buffer + * VABufferID colorBalanceBuffer; + * vaCreateBuffer(va_dpy, vpp_ctx, + * VAProcFilterParameterBufferType, sizeof(*pColorBalanceParam), 4, + * colorBalanceParams, + * &colorBalanceBuffer + * ); + * + * VAProcFilterParameterBufferColorBalance *pColorBalanceParam; + * vaMapBuffer(va_dpy, colorBalanceBuffer, &pColorBalanceParam); + * { + * // Change brightness only + * pColorBalanceBuffer[kBrightness].value = 0.75; + * } + * vaUnmapBuffer(va_dpy, colorBalanceBuffer); + * \endcode + */ +typedef struct _VAProcFilterParameterBufferColorBalance { + /** \brief Filter type. Shall be set to #VAProcFilterColorBalance. */ + VAProcFilterType type; + /** \brief Color balance attribute. */ + VAProcColorBalanceType attrib; + /** + * \brief Color balance value. + * + * Special case for automatically adjusted attributes. e.g. + * #VAProcColorBalanceAutoSaturation, + * #VAProcColorBalanceAutoBrightness, + * #VAProcColorBalanceAutoContrast. + * - If \ref value is \c 1.0 +/- \c FLT_EPSILON, the attribute is + * automatically adjusted and overrides any other attribute of + * the same type that would have been set explicitly; + * - If \ref value is \c 0.0 +/- \c FLT_EPSILON, the attribute is + * disabled and other attribute of the same type is used instead. + */ + float value; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProcFilterParameterBufferColorBalance; + +/** \brief Total color correction filter parametrization. */ +typedef struct _VAProcFilterParameterBufferTotalColorCorrection { + /** \brief Filter type. Shall be set to #VAProcFilterTotalColorCorrection. */ + VAProcFilterType type; + /** \brief Color to correct. */ + VAProcTotalColorCorrectionType attrib; + /** \brief Color correction value. */ + float value; +} VAProcFilterParameterBufferTotalColorCorrection; + +/** @name Video Processing Human Vision System (HVS) Denoise Mode.*/ +/**@{*/ +/** + * \brief Default Mode. + * This mode is decided in driver to the appropriate mode. + */ +#define VA_PROC_HVS_DENOISE_DEFAULT 0x0000 +/** + * \brief Auto BDRate Mode. + * Indicates auto BD rate improvement in pre-processing (such as before video encoding), ignore Strength. + */ +#define VA_PROC_HVS_DENOISE_AUTO_BDRATE 0x0001 +/** + * \brief Auto Subjective Mode. + * Indicates auto subjective quality improvement in pre-processing (such as before video encoding), ignore Strength. + */ +#define VA_PROC_HVS_DENOISE_AUTO_SUBJECTIVE 0x0002 +/** + * \brief Manual Mode. + * Indicates manual mode, allow to adjust the denoise strength manually (need to set Strength explicitly). + */ +#define VA_PROC_HVS_DENOISE_MANUAL 0x0003 +/**@}*/ + +/** \brief Human Vision System(HVS) Noise reduction filter parametrization. */ +typedef struct _VAProcFilterParameterBufferHVSNoiseReduction { + /** \brief Filter type. Shall be set to #VAProcFilterHVSNoiseReduction. */ + VAProcFilterType type; + /** \brief QP for encoding, used for HVS Denoise */ + uint16_t qp; + /** + * \brief QP to Noise Reduction Strength Mode, used for Human Vision System Based Noise Reduction. + * Controls Noise Reduction strength of conservative and aggressive mode. + * It is an integer from [0-16]. + * Value 0 means completely turn off Noise Reduction; + * Value 16 means the most aggressive mode of Noise Reduction; + * Value 10 is the default value. + */ + uint16_t strength; + /** + * \brief HVS Denoise Mode which controls denoise method. + * It is a value of VA_PROC_HVS_DENOISE_xxx. + * Please see the definition of VA_PROC_HVS_DENOISE_xxx. + */ + uint16_t mode; + /** \brief Reserved bytes for future use, must be zero */ + uint16_t va_reserved[VA_PADDING_HIGH - 1]; +} VAProcFilterParameterBufferHVSNoiseReduction; + +/** \brief High Dynamic Range(HDR) Tone Mapping filter parametrization. */ +typedef struct _VAProcFilterParameterBufferHDRToneMapping { + /** \brief Filter type. Shall be set to #VAProcFilterHighDynamicRangeToneMapping.*/ + VAProcFilterType type; + /** + * \brief High Dynamic Range metadata, could be HDR10 etc. + * + * This metadata is mainly for the input surface. Given that dynamic metadata is changing + * on frame-by-frame or scene-by-scene basis for HDR10 plus, differentiate the metadata + * for the input and output. + */ + VAHdrMetaData data; + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_HIGH]; +} VAProcFilterParameterBufferHDRToneMapping; + +/** @name 3DLUT Channel Layout and Mapping */ +/**@{*/ +/** \brief 3DLUT Channel Layout is unknown. */ +#define VA_3DLUT_CHANNEL_UNKNOWN 0x00000000 +/** \brief 3DLUT Channel Layout is R, G, B, the default layout. Map RGB to RGB. */ +#define VA_3DLUT_CHANNEL_RGB_RGB 0x00000001 +/** \brief 3DLUT Channel Layout is Y, U, V. Map YUV to RGB. */ +#define VA_3DLUT_CHANNEL_YUV_RGB 0x00000002 +/** \brief 3DLUT Channel Layout is V, U, Y. Map VUY to RGB. */ +#define VA_3DLUT_CHANNEL_VUY_RGB 0x00000004 +/**@}*/ + +/** + * \brief 3DLUT filter parametrization. + * + * 3DLUT (Three Dimensional Look Up Table) is often used when converting an image or a video frame + * from one color representation to another, for example, when converting log and gamma encodings, + * changing the color space, applying a color correction, changing the dynamic range, gamut mapping etc. + * + * This buffer defines 3DLUT attributes and memory layout. The typical 3DLUT has fixed number(lut_size) + * per dimension and memory layout is 3 dimensional array as 3dlut[stride_0][stride_1][stride_2] (lut_size + * shall be smaller than stride_0/1/2). + * + * API user should query hardware capability by using the VAProcFilterCap3DLUT to get the 3DLUT attributes + * which hardware supports, and use these attributes. For example, if the user queries hardware, the API user + * could get caps with 3dlut[33][33][64] (lut_size = 33, lut_stride[0/1/2] = 33/33/64). API user shall not + * use the attributes which hardware can not support. + * + * 3DLUT is usually used to transform input RGB/YUV values in one color space to output RGB values in another + * color space. Based on 1) the format and color space of VPP input and output and 2) 3DLUT memory layout and + * channel mapping, driver will enable some color space conversion implicitly if needed. For example, the input of + * VPP is P010 format in BT2020 color space, the output of VPP is NV12 in BT709 color space and the 3DLUT channel + * mapping is VA_3DLUT_CHANNEL_RGB_RGB, driver could build the data pipeline as P010(BT2020)->RGB(BT2020) + * ->3DULT(BT709)->NV12(BT709). Please note, the limitation of 3DLUT filter color space is that the color space of + * 3DLUT filter input data needs to be same as the input data of VPP; the color space of 3DLUT filter output data + * needs to be same as the output data of VPP; format does not have such limitation. + */ +typedef struct _VAProcFilterParameterBuffer3DLUT { + /** \brief Filter type. Shall be set to #VAProcFilter3DLUT.*/ + VAProcFilterType type; + + /** \brief lut_surface contains 3DLUT data in the 3DLUT memory layout, must be linear */ + VASurfaceID lut_surface; + /** + * \brief lut_size is the number of valid points on every dimension of the three dimensional look up table. + * The size of LUT (lut_size) shall be same among every dimension of the three dimensional look up table. + * The size of LUT (lut_size) shall be smaller than lut_stride[0/1/2]. + */ + uint16_t lut_size; + /** + * \brief lut_stride are the number of points on every dimension of the three dimensional look up table. + * Three dimension can has 3 different stride, lut3d[lut_stride[0]][lut_stride[1]][lut_stride[2]]. + * But the valid point shall start from 0, the range of valid point is [0, lut_size-1] for every dimension. + */ + uint16_t lut_stride[3]; + /** \brief bit_depth is the number of bits for every channel R, G or B (or Y, U, V) */ + uint16_t bit_depth; + /** \brief num_channel is the number of channels */ + uint16_t num_channel; + + /** \brief channel_mapping defines the mapping of input and output channels, could be one of VA_3DLUT_CHANNEL_XXX*/ + uint32_t channel_mapping; + + /** \brief reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_HIGH]; +} VAProcFilterParameterBuffer3DLUT; + +/** \brief Capabilities specification for the 3DLUT filter. */ +typedef struct _VAProcFilterCap3DLUT { + /** \brief lut_size is the number of valid points on every dimension of the three dimensional look up table. */ + uint16_t lut_size; + /** \brief lut_stride are the number of points on every dimension of the three dimensional look up table. lut3d[lut_stride[0]][lut_stride[1]][lut_stride[2]]*/ + uint16_t lut_stride[3]; + /** \brief bit_depth is the number of bits for every channel R, G or B (or Y, U, V) */ + uint16_t bit_depth; + /** \brief num_channel is the number of channels */ + uint16_t num_channel; + /** \brief channel_mapping defines the mapping of channels, could be some combination of VA_3DLUT_CHANNEL_XXX*/ + uint32_t channel_mapping; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_HIGH]; +} VAProcFilterCap3DLUT; + +/** + * \brief Default filter cap specification (single range value). + * + * Unless there is a filter-specific cap structure, #VAProcFilterCap is the + * default type to use for output caps from vaQueryVideoProcFilterCaps(). + */ +typedef struct _VAProcFilterCap { + /** \brief Range of supported values for the filter. */ + VAProcFilterValueRange range; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProcFilterCap; + +/** \brief Capabilities specification for the deinterlacing filter. */ +typedef struct _VAProcFilterCapDeinterlacing { + /** \brief Deinterlacing algorithm. */ + VAProcDeinterlacingType type; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProcFilterCapDeinterlacing; + +/** \brief Capabilities specification for the color balance filter. */ +typedef struct _VAProcFilterCapColorBalance { + /** \brief Color balance operation. */ + VAProcColorBalanceType type; + /** \brief Range of supported values for the specified operation. */ + VAProcFilterValueRange range; + + /** \brief Reserved bytes for future use, must be zero */ + uint32_t va_reserved[VA_PADDING_LOW]; +} VAProcFilterCapColorBalance; + +/** \brief Capabilities specification for the Total Color Correction filter. */ +typedef struct _VAProcFilterCapTotalColorCorrection { + /** \brief Color to correct. */ + VAProcTotalColorCorrectionType type; + /** \brief Range of supported values for the specified color. */ + VAProcFilterValueRange range; +} VAProcFilterCapTotalColorCorrection; + +/** + * \brief Queries video processing filters. + * + * This function returns the list of video processing filters supported + * by the driver. The \c filters array is allocated by the user and + * \c num_filters shall be initialized to the number of allocated + * elements in that array. Upon successful return, the actual number + * of filters will be overwritten into \c num_filters. Otherwise, + * \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned and \c num_filters + * is adjusted to the number of elements that would be returned if enough + * space was available. + * + * The list of video processing filters supported by the driver shall + * be ordered in the way they can be iteratively applied. This is needed + * for both correctness, i.e. some filters would not mean anything if + * applied at the beginning of the pipeline; but also for performance + * since some filters can be applied in a single pass (e.g. noise + * reduction + deinterlacing). + * + * @param[in] dpy the VA display + * @param[in] context the video processing context + * @param[out] filters the output array of #VAProcFilterType elements + * @param[in,out] num_filters the number of elements allocated on input, + * the number of elements actually filled in on output + */ +VAStatus +vaQueryVideoProcFilters( + VADisplay dpy, + VAContextID context, + VAProcFilterType *filters, + unsigned int *num_filters +); + +/** + * \brief Queries video filter capabilities. + * + * This function returns the list of capabilities supported by the driver + * for a specific video filter. The \c filter_caps array is allocated by + * the user and \c num_filter_caps shall be initialized to the number + * of allocated elements in that array. Upon successful return, the + * actual number of filters will be overwritten into \c num_filter_caps. + * Otherwise, \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned and + * \c num_filter_caps is adjusted to the number of elements that would be + * returned if enough space was available. + * + * @param[in] dpy the VA display + * @param[in] context the video processing context + * @param[in] type the video filter type + * @param[out] filter_caps the output array of #VAProcFilterCap elements + * @param[in,out] num_filter_caps the number of elements allocated on input, + * the number of elements actually filled in output + */ +VAStatus +vaQueryVideoProcFilterCaps( + VADisplay dpy, + VAContextID context, + VAProcFilterType type, + void *filter_caps, + unsigned int *num_filter_caps +); + +/** + * \brief Queries video processing pipeline capabilities. + * + * This function returns the video processing pipeline capabilities. The + * \c filters array defines the video processing pipeline and is an array + * of buffers holding filter parameters. + * + * Note: the #VAProcPipelineCaps structure contains user-provided arrays. + * If non-NULL, the corresponding \c num_* fields shall be filled in on + * input with the number of elements allocated. Upon successful return, + * the actual number of elements will be overwritten into the \c num_* + * fields. Otherwise, \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned + * and \c num_* fields are adjusted to the number of elements that would + * be returned if enough space was available. + * + * @param[in] dpy the VA display + * @param[in] context the video processing context + * @param[in] filters the array of VA buffers defining the video + * processing pipeline + * @param[in] num_filters the number of elements in filters + * @param[in,out] pipeline_caps the video processing pipeline capabilities + */ +VAStatus +vaQueryVideoProcPipelineCaps( + VADisplay dpy, + VAContextID context, + VABufferID *filters, + unsigned int num_filters, + VAProcPipelineCaps *pipeline_caps +); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* VA_VPP_H */ diff --git a/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiH264Encoder.h b/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiH264Encoder.h new file mode 100644 index 00000000..b7b08ac2 --- /dev/null +++ b/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiH264Encoder.h @@ -0,0 +1,111 @@ +/* + * Copyright 2026 Alex Andres + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JNI_WEBRTC_MEDIA_VIDEO_CODEC_VAAPI_H264_ENCODER_H_ +#define JNI_WEBRTC_MEDIA_VIDEO_CODEC_VAAPI_H264_ENCODER_H_ + +#include "media/video/codec/linux/VaapiLibrary.h" + +#include "api/video/video_frame.h" +#include "api/video_codecs/sdp_video_format.h" +#include "api/video_codecs/video_codec.h" +#include "api/video_codecs/video_encoder.h" +#include "common_video/h264/h264_bitstream_parser.h" +#include "modules/video_coding/codecs/h264/include/h264_globals.h" + +#include +#include + +#include +#include +#include + +namespace jni +{ + // Encodes H.264 Constrained Baseline with the GPU driver's VA-API encoder, + // as Intel and AMD drivers provide it on Linux. + // + // Encoding is synchronous, with one reference frame and P-frames only, so + // each frame is encoded before Encode() returns. The driver writes the + // parameter sets and slice headers itself from the parameters it is given. + // A driver that leaves the parameter sets out of a key frame, which WebRTC + // cannot send without them, makes the encoder give up, as does anything + // else that fails, so that the software encoder takes over. + class VaapiH264Encoder : public webrtc::VideoEncoder + { + public: + VaapiH264Encoder(VaapiLibrary & library, const webrtc::SdpVideoFormat & format); + ~VaapiH264Encoder() override; + + int32_t InitEncode(const webrtc::VideoCodec * codecSettings, const Settings & settings) override; + int32_t RegisterEncodeCompleteCallback(webrtc::EncodedImageCallback * callback) override; + int32_t Release() override; + int32_t Encode(const webrtc::VideoFrame & frame, const std::vector * frameTypes) override; + void SetRates(const RateControlParameters & parameters) override; + EncoderInfo GetEncoderInfo() const override; + + private: + bool CreateSession(); + void DestroySession(); + bool Upload(const webrtc::VideoFrame & frame); + bool Submit(bool idr); + bool ReadOutput(std::vector & output); + + bool AddBuffer(VABufferType type, void * data, size_t size); + bool AddMiscParameter(VAEncMiscParameterType type, const void * data, size_t size); + void DestroyFrameBuffers(); + + void FillSequence(VAEncSequenceParameterBufferH264 & sequence) const; + void FillPicture(VAEncPictureParameterBufferH264 & picture, bool idr) const; + void FillSlice(VAEncSliceParameterBufferH264 & slice, bool idr) const; + + bool Check(VAStatus status, const char * operation) const; + + private: + VaapiLibrary & library; + const VaapiFunctions & va; + const std::string implementationName; + + VAConfigID config; + VAContextID context; + VASurfaceID inputSurface; + // The frame being encoded, and the one it refers to. + VASurfaceID reconstructed[2]; + VABufferID codedBuffer; + std::vector frameBuffers; + + webrtc::VideoCodec codecSettings; + uint32_t widthInMbs; + uint32_t heightInMbs; + uint32_t bitrateBps; + uint32_t framerate; + bool ratesChanged; + + // The frame number within the current IDR period, and which of + // the reconstructed surfaces holds the reference. + uint32_t frameNum; + uint32_t idrPicId; + int current; + bool referenceValid; + + webrtc::EncodedImageCallback * callback; + + webrtc::H264BitstreamParser bitstreamParser; + webrtc::H264PacketizationMode packetizationMode; + }; +} + +#endif diff --git a/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiLibrary.h b/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiLibrary.h new file mode 100644 index 00000000..849d3288 --- /dev/null +++ b/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiLibrary.h @@ -0,0 +1,107 @@ +/* + * Copyright 2026 Alex Andres + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JNI_WEBRTC_MEDIA_VIDEO_CODEC_VAAPI_LIBRARY_H_ +#define JNI_WEBRTC_MEDIA_VIDEO_CODEC_VAAPI_LIBRARY_H_ + +#include "media/video/codec/nvenc/DynamicLibrary.h" + +#include +#include + +#include + +namespace jni +{ + // The functions of libva this library uses, typed after the libva + // headers, which are only declared, never linked. + struct VaapiFunctions + { + decltype(&::vaGetDisplayDRM) GetDisplayDRM = nullptr; + decltype(&::vaInitialize) Initialize = nullptr; + decltype(&::vaTerminate) Terminate = nullptr; + decltype(&::vaSetInfoCallback) SetInfoCallback = nullptr; + decltype(&::vaQueryVendorString) QueryVendorString = nullptr; + decltype(&::vaErrorStr) ErrorStr = nullptr; + decltype(&::vaMaxNumEntrypoints) MaxNumEntrypoints = nullptr; + decltype(&::vaQueryConfigEntrypoints) QueryConfigEntrypoints = nullptr; + decltype(&::vaGetConfigAttributes) GetConfigAttributes = nullptr; + decltype(&::vaCreateConfig) CreateConfig = nullptr; + decltype(&::vaDestroyConfig) DestroyConfig = nullptr; + decltype(&::vaCreateSurfaces) CreateSurfaces = nullptr; + decltype(&::vaDestroySurfaces) DestroySurfaces = nullptr; + decltype(&::vaCreateContext) CreateContext = nullptr; + decltype(&::vaDestroyContext) DestroyContext = nullptr; + decltype(&::vaCreateBuffer) CreateBuffer = nullptr; + decltype(&::vaDestroyBuffer) DestroyBuffer = nullptr; + decltype(&::vaMapBuffer) MapBuffer = nullptr; + decltype(&::vaUnmapBuffer) UnmapBuffer = nullptr; + decltype(&::vaBeginPicture) BeginPicture = nullptr; + decltype(&::vaRenderPicture) RenderPicture = nullptr; + decltype(&::vaEndPicture) EndPicture = nullptr; + decltype(&::vaSyncSurface) SyncSurface = nullptr; + decltype(&::vaDeriveImage) DeriveImage = nullptr; + decltype(&::vaCreateImage) CreateImage = nullptr; + decltype(&::vaPutImage) PutImage = nullptr; + decltype(&::vaDestroyImage) DestroyImage = nullptr; + }; + + // libva, loaded once, when first asked for, with the display of the + // first GPU whose driver encodes H.264 Constrained Baseline with constant + // bitrate. Kept for the life of the process; the display is shared by all + // encoders, which libva allows. + class VaapiLibrary + { + public: + // Returns the library, or null if libva is not installed, or no GPU + // driver encodes H.264 through it. + static VaapiLibrary * Get(); + + VaapiLibrary(const VaapiLibrary &) = delete; + VaapiLibrary & operator=(const VaapiLibrary &) = delete; + + const VaapiFunctions & Api() const; + + VADisplay Display() const; + + // The encode entrypoint the driver offers, full or low-power. + VAEntrypoint Entrypoint() const; + + // The driver, e.g. "Intel iHD driver for Intel(R) Gen Graphics". + const std::string & Vendor() const; + + const char * ErrorString(VAStatus status) const; + + private: + VaapiLibrary() = default; + + bool Load(); + bool OpenDisplay(); + bool SupportsEncoding(VADisplay display, VAEntrypoint * entrypoint) const; + + private: + DynamicLibrary va; + DynamicLibrary vaDrm; + VaapiFunctions api; + + int fd = -1; + VADisplay display = nullptr; + VAEntrypoint entrypoint = VAEntrypointEncSlice; + std::string vendor; + }; +} + +#endif diff --git a/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiVideoEncoderFactory.h b/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiVideoEncoderFactory.h new file mode 100644 index 00000000..5ac62484 --- /dev/null +++ b/webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiVideoEncoderFactory.h @@ -0,0 +1,57 @@ +/* + * Copyright 2026 Alex Andres + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JNI_WEBRTC_MEDIA_VIDEO_CODEC_VAAPI_VIDEO_ENCODER_FACTORY_H_ +#define JNI_WEBRTC_MEDIA_VIDEO_CODEC_VAAPI_VIDEO_ENCODER_FACTORY_H_ + +#include "media/video/codec/linux/VaapiLibrary.h" + +#include "api/environment/environment.h" +#include "api/video_codecs/sdp_video_format.h" +#include "api/video_codecs/video_encoder.h" +#include "api/video_codecs/video_encoder_factory.h" + +#include +#include + +namespace jni +{ + // Creates VA-API encoders on the GPU whose driver encodes H.264, as Intel + // and AMD drivers do. It offers H.264 in the profiles WebRTC's software + // encoder offers too, and only with packetization mode 1: mode 0 needs + // each NAL unit to fit a packet. + class VaapiVideoEncoderFactory : public webrtc::VideoEncoderFactory + { + public: + // Returns a factory, or null if no GPU driver encodes H.264 + // through VA-API. + static std::unique_ptr Create(); + + ~VaapiVideoEncoderFactory() override = default; + + std::vector GetSupportedFormats() const override; + std::unique_ptr Create(const webrtc::Environment & env, + const webrtc::SdpVideoFormat & format) override; + + private: + explicit VaapiVideoEncoderFactory(VaapiLibrary & library); + + private: + VaapiLibrary & library; + }; +} + +#endif diff --git a/webrtc-jni/src/main/cpp/src/media/video/codec/linux/LinuxHardwareVideoEncoderFactories.cpp b/webrtc-jni/src/main/cpp/src/media/video/codec/linux/LinuxHardwareVideoEncoderFactories.cpp index ef61c827..b253de85 100644 --- a/webrtc-jni/src/main/cpp/src/media/video/codec/linux/LinuxHardwareVideoEncoderFactories.cpp +++ b/webrtc-jni/src/main/cpp/src/media/video/codec/linux/LinuxHardwareVideoEncoderFactories.cpp @@ -15,6 +15,7 @@ */ #include "media/video/codec/HardwareVideoEncoderFactory.h" +#include "media/video/codec/linux/VaapiVideoEncoderFactory.h" #include "media/video/codec/nvenc/NvencVideoEncoderFactory.h" namespace jni @@ -23,9 +24,14 @@ namespace jni { std::vector> factories; + // NVENC first where there is an NVIDIA GPU, whose driver has no + // VA-API encoder; VA-API for the GPUs of Intel and AMD. if (auto nvenc = NvencVideoEncoderFactory::Create()) { factories.push_back(std::move(nvenc)); } + if (auto vaapi = VaapiVideoEncoderFactory::Create()) { + factories.push_back(std::move(vaapi)); + } return factories; } diff --git a/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiH264Encoder.cpp b/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiH264Encoder.cpp new file mode 100644 index 00000000..0c0fe440 --- /dev/null +++ b/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiH264Encoder.cpp @@ -0,0 +1,709 @@ +/* + * Copyright 2026 Alex Andres + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "media/video/codec/linux/VaapiH264Encoder.h" + +#include "api/video/encoded_image.h" +#include "api/video/i420_buffer.h" +#include "common_video/h264/h264_common.h" +#include "modules/video_coding/codecs/interface/common_constants.h" +#include "modules/video_coding/include/video_codec_interface.h" +#include "modules/video_coding/include/video_error_codes.h" +#include "rtc_base/logging.h" +#include "third_party/libyuv/include/libyuv/convert_from.h" + +#include +#include +#include + +namespace jni +{ + namespace + { + // The QP thresholds of WebRTC's own H.264 encoder. + constexpr int kLowH264QpThreshold = 24; + constexpr int kHighH264QpThreshold = 37; + + // frame_num counts to 2^8 before it wraps. + constexpr uint32_t kLog2MaxFrameNum = 8; + constexpr uint32_t kMaxFrameNum = 1 << kLog2MaxFrameNum; + + // Key frames come when WebRTC asks for them; this only bounds how + // long a stream may go without one if it never does. + constexpr uint32_t kIntraPeriod = 3000; + + // H.264 slice types. + constexpr uint8_t kSliceTypeP = 0; + constexpr uint8_t kSliceTypeI = 2; + + constexpr uint32_t kInitialQp = 26; + + // How many seconds of video the rate control may buffer, as a + // multiple of the bitrate. + constexpr uint32_t kHrdBufferNumerator = 3; + constexpr uint32_t kHrdBufferDenominator = 2; + + // The lowest H.264 level whose limits a stream fits in, going by its + // frame size and macroblock rate, per table A-1 of the standard. + uint8_t LevelIdc(uint32_t frameSizeMbs, uint32_t framerate) + { + struct Level + { + uint8_t idc; + uint32_t maxMbps; + uint32_t maxFs; + }; + + static const Level levels[] = { + { 31, 108000, 3600 }, + { 32, 216000, 5120 }, + { 40, 245760, 8192 }, + { 42, 522240, 8704 }, + { 50, 589824, 22080 }, + { 51, 983040, 36864 }, + { 52, 2073600, 36864 } + }; + + const uint32_t mbps = frameSizeMbs * framerate; + + for (const Level & level : levels) { + if (frameSizeMbs <= level.maxFs && mbps <= level.maxMbps) { + return level.idc; + } + } + + return 52; + } + + void InvalidatePicture(VAPictureH264 & picture) + { + picture = {}; + picture.picture_id = VA_INVALID_SURFACE; + picture.flags = VA_PICTURE_H264_INVALID; + } + + // Whether a key frame carries both parameter sets, which the receiver + // needs to decode it. + bool HasParameterSets(const std::vector & output) + { + bool sps = false; + bool pps = false; + + for (const webrtc::H264::NaluIndex & nalu : webrtc::H264::FindNaluIndices(output)) { + const webrtc::H264::NaluType type = webrtc::H264::ParseNaluType(output[nalu.payload_start_offset]); + + sps |= type == webrtc::H264::NaluType::kSps; + pps |= type == webrtc::H264::NaluType::kPps; + } + + return sps && pps; + } + } + + VaapiH264Encoder::VaapiH264Encoder(VaapiLibrary & library, const webrtc::SdpVideoFormat & format) : + library(library), + va(library.Api()), + implementationName("VA-API (" + library.Vendor() + ")"), + config(VA_INVALID_ID), + context(VA_INVALID_ID), + inputSurface(VA_INVALID_SURFACE), + reconstructed{ VA_INVALID_SURFACE, VA_INVALID_SURFACE }, + codedBuffer(VA_INVALID_ID), + codecSettings(), + widthInMbs(0), + heightInMbs(0), + bitrateBps(0), + framerate(30), + ratesChanged(false), + frameNum(0), + idrPicId(0), + current(0), + referenceValid(false), + callback(nullptr), + packetizationMode(webrtc::H264PacketizationMode::NonInterleaved) + { + auto mode = format.parameters.find("packetization-mode"); + + if (mode == format.parameters.end() || mode->second != "1") { + packetizationMode = webrtc::H264PacketizationMode::SingleNalUnit; + } + } + + VaapiH264Encoder::~VaapiH264Encoder() + { + Release(); + } + + bool VaapiH264Encoder::Check(VAStatus status, const char * operation) const + { + if (status == VA_STATUS_SUCCESS) { + return true; + } + + RTC_LOG(LS_WARNING) << "VA-API: " << operation << " failed: " << library.ErrorString(status); + + return false; + } + + int32_t VaapiH264Encoder::InitEncode(const webrtc::VideoCodec * settings, const Settings & encoderSettings) + { + if (settings == nullptr || settings->width == 0 || settings->height == 0) { + return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; + } + if (settings->numberOfSimulcastStreams > 1) { + return WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED; + } + // NV12 has chroma at half the resolution in both directions, and the + // frame is cropped in units of two pixels. + if (settings->width % 2 != 0 || settings->height % 2 != 0) { + return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; + } + + Release(); + + codecSettings = *settings; + widthInMbs = (codecSettings.width + 15) / 16; + heightInMbs = (codecSettings.height + 15) / 16; + bitrateBps = std::max(1u, codecSettings.startBitrate) * 1000; + framerate = std::max(1u, codecSettings.maxFramerate); + ratesChanged = true; + frameNum = 0; + current = 0; + referenceValid = false; + + if (!CreateSession()) { + Release(); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + RTC_LOG(LS_INFO) << implementationName << " initialized: " << codecSettings.width << "x" + << codecSettings.height << " at " << bitrateBps << " bps"; + + return WEBRTC_VIDEO_CODEC_OK; + } + + bool VaapiH264Encoder::CreateSession() + { + VADisplay display = library.Display(); + + VAConfigAttrib attributes[2] = {}; + attributes[0].type = VAConfigAttribRTFormat; + attributes[0].value = VA_RT_FORMAT_YUV420; + attributes[1].type = VAConfigAttribRateControl; + attributes[1].value = VA_RC_CBR; + + if (!Check(va.CreateConfig(display, VAProfileH264ConstrainedBaseline, library.Entrypoint(), attributes, 2, + &config), "creating the configuration")) + { + config = VA_INVALID_ID; + return false; + } + + // Whole macroblocks; the stream is cropped to the frame size. + const unsigned int width = widthInMbs * 16; + const unsigned int height = heightInMbs * 16; + + VASurfaceID surfaces[3] = { VA_INVALID_SURFACE, VA_INVALID_SURFACE, VA_INVALID_SURFACE }; + + if (!Check(va.CreateSurfaces(display, VA_RT_FORMAT_YUV420, width, height, surfaces, 3, nullptr, 0), + "creating surfaces")) + { + return false; + } + + inputSurface = surfaces[0]; + reconstructed[0] = surfaces[1]; + reconstructed[1] = surfaces[2]; + + if (!Check(va.CreateContext(display, config, width, height, VA_PROGRESSIVE, surfaces, 3, &context), + "creating the context")) + { + context = VA_INVALID_ID; + return false; + } + + // Room for a frame that does not compress at all. + const unsigned int codedSize = width * height * 3 / 2 + 64 * 1024; + + if (!Check(va.CreateBuffer(display, context, VAEncCodedBufferType, codedSize, 1, nullptr, &codedBuffer), + "creating the output buffer")) + { + codedBuffer = VA_INVALID_ID; + return false; + } + + return true; + } + + int32_t VaapiH264Encoder::RegisterEncodeCompleteCallback(webrtc::EncodedImageCallback * encodeCallback) + { + callback = encodeCallback; + + return WEBRTC_VIDEO_CODEC_OK; + } + + int32_t VaapiH264Encoder::Release() + { + DestroySession(); + + return WEBRTC_VIDEO_CODEC_OK; + } + + void VaapiH264Encoder::DestroySession() + { + VADisplay display = library.Display(); + + DestroyFrameBuffers(); + + if (codedBuffer != VA_INVALID_ID) { + va.DestroyBuffer(display, codedBuffer); + codedBuffer = VA_INVALID_ID; + } + if (context != VA_INVALID_ID) { + va.DestroyContext(display, context); + context = VA_INVALID_ID; + } + + VASurfaceID surfaces[3] = { inputSurface, reconstructed[0], reconstructed[1] }; + + if (inputSurface != VA_INVALID_SURFACE) { + va.DestroySurfaces(display, surfaces, 3); + } + + inputSurface = VA_INVALID_SURFACE; + reconstructed[0] = VA_INVALID_SURFACE; + reconstructed[1] = VA_INVALID_SURFACE; + + if (config != VA_INVALID_ID) { + va.DestroyConfig(display, config); + config = VA_INVALID_ID; + } + + referenceValid = false; + } + + int32_t VaapiH264Encoder::Encode(const webrtc::VideoFrame & frame, + const std::vector * frameTypes) + { + if (context == VA_INVALID_ID || callback == nullptr) { + return WEBRTC_VIDEO_CODEC_UNINITIALIZED; + } + + bool idr = !referenceValid; + + if (frameTypes != nullptr) { + idr |= std::any_of(frameTypes->begin(), frameTypes->end(), [](webrtc::VideoFrameType type) { + return type == webrtc::VideoFrameType::kVideoFrameKey; + }); + } + + if (idr) { + frameNum = 0; + } + + std::vector output; + + if (!Upload(frame) || !Submit(idr) || !ReadOutput(output)) { + DestroyFrameBuffers(); + return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; + } + + DestroyFrameBuffers(); + + if (idr && !HasParameterSets(output)) { + // Nothing can decode the stream then; better in software. + RTC_LOG(LS_WARNING) << implementationName << " writes no parameter sets into key frames"; + return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; + } + + // The frame just encoded is the reference of the next one. + referenceValid = true; + current = 1 - current; + frameNum = (frameNum + 1) % kMaxFrameNum; + ratesChanged = false; + + if (idr) { + idrPicId = (idrPicId + 1) & 0xFFFF; + } + + webrtc::EncodedImage image; + image.SetEncodedData(webrtc::EncodedImageBuffer::Create(output.data(), output.size())); + image._encodedWidth = codecSettings.width; + image._encodedHeight = codecSettings.height; + image.SetRtpTimestamp(frame.rtp_timestamp()); + image.capture_time_ms_ = frame.render_time_ms(); + image.ntp_time_ms_ = frame.ntp_time_ms(); + image.rotation_ = frame.rotation(); + image.set_frame_type(idr + ? webrtc::VideoFrameType::kVideoFrameKey + : webrtc::VideoFrameType::kVideoFrameDelta); + + bitstreamParser.ParseBitstream(std::span(output.data(), output.size())); + image.qp_ = bitstreamParser.GetLastSliceQp().value_or(-1); + + webrtc::CodecSpecificInfo info; + info.codecType = webrtc::kVideoCodecH264; + info.codecSpecific.H264.packetization_mode = packetizationMode; + info.codecSpecific.H264.temporal_idx = webrtc::kNoTemporalIdx; + info.codecSpecific.H264.base_layer_sync = false; + info.codecSpecific.H264.idr_frame = idr; + + callback->OnEncodedImage(image, &info); + + return WEBRTC_VIDEO_CODEC_OK; + } + + bool VaapiH264Encoder::Upload(const webrtc::VideoFrame & frame) + { + webrtc::scoped_refptr i420 = frame.video_frame_buffer()->ToI420(); + + if (!i420) { + return false; + } + + const int width = static_cast(codecSettings.width); + const int height = static_cast(codecSettings.height); + + // WebRTC initializes the encoder again when the frame size changes, + // so a frame of another size is one that raced with that. + if (i420->width() != width || i420->height() != height) { + webrtc::scoped_refptr scaled = webrtc::I420Buffer::Create(width, height); + scaled->ScaleFrom(*i420); + i420 = scaled; + } + + VADisplay display = library.Display(); + VAImage image = {}; + image.image_id = VA_INVALID_ID; + + // Writing into the surface directly where the driver allows it, + // otherwise into an image that is copied into the surface. + bool derived = va.DeriveImage(display, inputSurface, &image) == VA_STATUS_SUCCESS + && image.format.fourcc == VA_FOURCC_NV12; + + if (!derived) { + if (image.image_id != VA_INVALID_ID) { + va.DestroyImage(display, image.image_id); + } + + VAImageFormat format = {}; + format.fourcc = VA_FOURCC_NV12; + format.byte_order = VA_LSB_FIRST; + format.bits_per_pixel = 12; + + if (!Check(va.CreateImage(display, &format, width, height, &image), "creating an image")) { + return false; + } + } + + void * data = nullptr; + bool uploaded = Check(va.MapBuffer(display, image.buf, &data), "mapping an image"); + + if (uploaded) { + uint8_t * base = static_cast(data); + + libyuv::I420ToNV12(i420->DataY(), i420->StrideY(), i420->DataU(), i420->StrideU(), + i420->DataV(), i420->StrideV(), + base + image.offsets[0], static_cast(image.pitches[0]), + base + image.offsets[1], static_cast(image.pitches[1]), + width, height); + + va.UnmapBuffer(display, image.buf); + + if (!derived) { + uploaded = Check(va.PutImage(display, inputSurface, image.image_id, 0, 0, width, height, + 0, 0, width, height), "copying an image"); + } + } + + va.DestroyImage(display, image.image_id); + + return uploaded; + } + + bool VaapiH264Encoder::Submit(bool idr) + { + if (idr) { + VAEncSequenceParameterBufferH264 sequence = {}; + FillSequence(sequence); + + if (!AddBuffer(VAEncSequenceParameterBufferType, &sequence, sizeof(sequence))) { + return false; + } + } + + if (idr || ratesChanged) { + VAEncMiscParameterRateControl rateControl = {}; + rateControl.bits_per_second = bitrateBps; + rateControl.target_percentage = 100; + rateControl.window_size = 1000; + rateControl.initial_qp = kInitialQp; + + VAEncMiscParameterFrameRate frameRate = {}; + // The numerator in the low 16 bits, the denominator in the high. + frameRate.framerate = framerate | (1u << 16); + + VAEncMiscParameterHRD hrd = {}; + hrd.buffer_size = static_cast( + static_cast(bitrateBps) * kHrdBufferNumerator / kHrdBufferDenominator); + hrd.initial_buffer_fullness = hrd.buffer_size / 2; + + if (!AddMiscParameter(VAEncMiscParameterTypeRateControl, &rateControl, sizeof(rateControl)) || + !AddMiscParameter(VAEncMiscParameterTypeFrameRate, &frameRate, sizeof(frameRate)) || + !AddMiscParameter(VAEncMiscParameterTypeHRD, &hrd, sizeof(hrd))) + { + return false; + } + } + + VAEncPictureParameterBufferH264 picture = {}; + FillPicture(picture, idr); + + VAEncSliceParameterBufferH264 slice = {}; + FillSlice(slice, idr); + + if (!AddBuffer(VAEncPictureParameterBufferType, &picture, sizeof(picture)) || + !AddBuffer(VAEncSliceParameterBufferType, &slice, sizeof(slice))) + { + return false; + } + + VADisplay display = library.Display(); + + if (!Check(va.BeginPicture(display, context, inputSurface), "beginning a picture")) { + return false; + } + + bool rendered = Check(va.RenderPicture(display, context, frameBuffers.data(), + static_cast(frameBuffers.size())), "rendering a picture"); + + // A picture that was begun has to be ended. + bool ended = Check(va.EndPicture(display, context), "ending a picture"); + + return rendered && ended && Check(va.SyncSurface(display, inputSurface), "waiting for a picture"); + } + + bool VaapiH264Encoder::ReadOutput(std::vector & output) + { + VADisplay display = library.Display(); + void * data = nullptr; + + if (!Check(va.MapBuffer(display, codedBuffer, &data), "mapping the output")) { + return false; + } + + bool complete = true; + + for (auto * segment = static_cast(data); segment != nullptr; + segment = static_cast(segment->next)) + { + if (segment->status & VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK) { + complete = false; + } + + const uint8_t * bytes = static_cast(segment->buf); + output.insert(output.end(), bytes, bytes + segment->size); + } + + va.UnmapBuffer(display, codedBuffer); + + if (!complete || output.empty()) { + RTC_LOG(LS_WARNING) << "VA-API: a frame did not fit the output buffer"; + return false; + } + + return true; + } + + bool VaapiH264Encoder::AddBuffer(VABufferType type, void * data, size_t size) + { + VABufferID buffer = VA_INVALID_ID; + + if (!Check(va.CreateBuffer(library.Display(), context, type, static_cast(size), 1, data, + &buffer), "creating a parameter buffer")) + { + return false; + } + + frameBuffers.push_back(buffer); + + return true; + } + + bool VaapiH264Encoder::AddMiscParameter(VAEncMiscParameterType type, const void * data, size_t size) + { + // A VAEncMiscParameterBuffer: the type, followed by the parameter. + std::vector buffer(sizeof(VAEncMiscParameterBuffer) + size); + + auto * header = reinterpret_cast(buffer.data()); + header->type = type; + std::memcpy(header->data, data, size); + + return AddBuffer(VAEncMiscParameterBufferType, buffer.data(), buffer.size()); + } + + void VaapiH264Encoder::DestroyFrameBuffers() + { + for (VABufferID buffer : frameBuffers) { + va.DestroyBuffer(library.Display(), buffer); + } + + frameBuffers.clear(); + } + + void VaapiH264Encoder::FillSequence(VAEncSequenceParameterBufferH264 & sequence) const + { + sequence.seq_parameter_set_id = 0; + sequence.level_idc = LevelIdc(widthInMbs * heightInMbs, framerate); + sequence.intra_period = kIntraPeriod; + sequence.intra_idr_period = kIntraPeriod; + sequence.ip_period = 1; + sequence.bits_per_second = bitrateBps; + sequence.max_num_ref_frames = 1; + sequence.picture_width_in_mbs = static_cast(widthInMbs); + sequence.picture_height_in_mbs = static_cast(heightInMbs); + + sequence.seq_fields.bits.chroma_format_idc = 1; + sequence.seq_fields.bits.frame_mbs_only_flag = 1; + sequence.seq_fields.bits.direct_8x8_inference_flag = 1; + sequence.seq_fields.bits.log2_max_frame_num_minus4 = kLog2MaxFrameNum - 4; + // Display order follows frame_num, which there are no B-frames to + // break. + sequence.seq_fields.bits.pic_order_cnt_type = 2; + + const uint32_t croppedRight = widthInMbs * 16 - codecSettings.width; + const uint32_t croppedBottom = heightInMbs * 16 - codecSettings.height; + + if (croppedRight > 0 || croppedBottom > 0) { + // In units of two luma samples for 4:2:0 frames. + sequence.frame_cropping_flag = 1; + sequence.frame_crop_right_offset = croppedRight / 2; + sequence.frame_crop_bottom_offset = croppedBottom / 2; + } + + sequence.vui_parameters_present_flag = 1; + sequence.vui_fields.bits.timing_info_present_flag = 1; + sequence.num_units_in_tick = 1; + sequence.time_scale = framerate * 2; + } + + void VaapiH264Encoder::FillPicture(VAEncPictureParameterBufferH264 & picture, bool idr) const + { + picture.CurrPic.picture_id = reconstructed[current]; + picture.CurrPic.frame_idx = frameNum; + picture.CurrPic.flags = 0; + picture.CurrPic.TopFieldOrderCnt = static_cast(frameNum * 2); + picture.CurrPic.BottomFieldOrderCnt = picture.CurrPic.TopFieldOrderCnt; + + for (VAPictureH264 & reference : picture.ReferenceFrames) { + InvalidatePicture(reference); + } + + if (!idr) { + const uint32_t previous = (frameNum + kMaxFrameNum - 1) % kMaxFrameNum; + + VAPictureH264 & reference = picture.ReferenceFrames[0]; + reference.picture_id = reconstructed[1 - current]; + reference.frame_idx = previous; + reference.flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE; + reference.TopFieldOrderCnt = static_cast(previous * 2); + reference.BottomFieldOrderCnt = reference.TopFieldOrderCnt; + } + + picture.coded_buf = codedBuffer; + picture.pic_parameter_set_id = 0; + picture.seq_parameter_set_id = 0; + picture.last_picture = 0; + picture.frame_num = static_cast(frameNum); + picture.pic_init_qp = kInitialQp; + picture.num_ref_idx_l0_active_minus1 = 0; + picture.num_ref_idx_l1_active_minus1 = 0; + + picture.pic_fields.bits.idr_pic_flag = idr ? 1 : 0; + picture.pic_fields.bits.reference_pic_flag = 1; + // CAVLC: Constrained Baseline has no CABAC. + picture.pic_fields.bits.entropy_coding_mode_flag = 0; + picture.pic_fields.bits.transform_8x8_mode_flag = 0; + picture.pic_fields.bits.deblocking_filter_control_present_flag = 1; + } + + void VaapiH264Encoder::FillSlice(VAEncSliceParameterBufferH264 & slice, bool idr) const + { + slice.macroblock_address = 0; + slice.num_macroblocks = widthInMbs * heightInMbs; + slice.macroblock_info = VA_INVALID_ID; + slice.slice_type = idr ? kSliceTypeI : kSliceTypeP; + slice.pic_parameter_set_id = 0; + slice.idr_pic_id = static_cast(idrPicId); + slice.pic_order_cnt_lsb = 0; + slice.num_ref_idx_active_override_flag = 0; + slice.num_ref_idx_l0_active_minus1 = 0; + + for (VAPictureH264 & reference : slice.RefPicList0) { + InvalidatePicture(reference); + } + for (VAPictureH264 & reference : slice.RefPicList1) { + InvalidatePicture(reference); + } + + if (!idr) { + const uint32_t previous = (frameNum + kMaxFrameNum - 1) % kMaxFrameNum; + + VAPictureH264 & reference = slice.RefPicList0[0]; + reference.picture_id = reconstructed[1 - current]; + reference.frame_idx = previous; + reference.flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE; + reference.TopFieldOrderCnt = static_cast(previous * 2); + reference.BottomFieldOrderCnt = reference.TopFieldOrderCnt; + } + + slice.slice_qp_delta = 0; + slice.disable_deblocking_filter_idc = 0; + } + + void VaapiH264Encoder::SetRates(const RateControlParameters & parameters) + { + const uint32_t bitrate = parameters.bitrate.get_sum_bps(); + + // A zero bitrate pauses the stream; the encoder gets no frames then. + if (bitrate == 0) { + return; + } + + bitrateBps = bitrate; + + if (parameters.framerate_fps >= 1.0) { + framerate = static_cast(parameters.framerate_fps + 0.5); + } + + // Applied with the next frame. + ratesChanged = true; + } + + webrtc::VideoEncoder::EncoderInfo VaapiH264Encoder::GetEncoderInfo() const + { + EncoderInfo info; + info.implementation_name = implementationName; + info.is_hardware_accelerated = true; + info.supports_native_handle = false; + info.supports_simulcast = false; + info.scaling_settings = ScalingSettings(kLowH264QpThreshold, kHighH264QpThreshold); + // NV12 needs even dimensions. + info.requested_resolution_alignment = 2; + + return info; + } +} diff --git a/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiLibrary.cpp b/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiLibrary.cpp new file mode 100644 index 00000000..f97cd7e2 --- /dev/null +++ b/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiLibrary.cpp @@ -0,0 +1,230 @@ +/* + * Copyright 2026 Alex Andres + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "media/video/codec/linux/VaapiLibrary.h" + +#include "rtc_base/logging.h" + +#include +#include + +#include +#include +#include + +namespace jni +{ + namespace + { + // DRM render nodes are numbered from 128, one per GPU. + constexpr int kFirstRenderNode = 128; + constexpr int kRenderNodeCount = 8; + + // libva prints what it does to stdout unless told otherwise. + void IgnoreInfo(void * context, const char * message) + { + } + } + + VaapiLibrary * VaapiLibrary::Get() + { + static std::once_flag once; + static VaapiLibrary * instance = nullptr; + + std::call_once(once, [] { + auto library = new VaapiLibrary(); + + if (library->Load()) { + instance = library; + } + else { + delete library; + } + }); + + return instance; + } + + bool VaapiLibrary::Load() + { + if (!va.Open("libva.so.2") || !vaDrm.Open("libva-drm.so.2")) { + RTC_LOG(LS_INFO) << "VA-API: libva is not installed"; + return false; + } + + bool resolved = vaDrm.Resolve("vaGetDisplayDRM", api.GetDisplayDRM) + && va.Resolve("vaInitialize", api.Initialize) + && va.Resolve("vaTerminate", api.Terminate) + && va.Resolve("vaQueryVendorString", api.QueryVendorString) + && va.Resolve("vaErrorStr", api.ErrorStr) + && va.Resolve("vaMaxNumEntrypoints", api.MaxNumEntrypoints) + && va.Resolve("vaQueryConfigEntrypoints", api.QueryConfigEntrypoints) + && va.Resolve("vaGetConfigAttributes", api.GetConfigAttributes) + && va.Resolve("vaCreateConfig", api.CreateConfig) + && va.Resolve("vaDestroyConfig", api.DestroyConfig) + && va.Resolve("vaCreateSurfaces", api.CreateSurfaces) + && va.Resolve("vaDestroySurfaces", api.DestroySurfaces) + && va.Resolve("vaCreateContext", api.CreateContext) + && va.Resolve("vaDestroyContext", api.DestroyContext) + && va.Resolve("vaCreateBuffer", api.CreateBuffer) + && va.Resolve("vaDestroyBuffer", api.DestroyBuffer) + && va.Resolve("vaMapBuffer", api.MapBuffer) + && va.Resolve("vaUnmapBuffer", api.UnmapBuffer) + && va.Resolve("vaBeginPicture", api.BeginPicture) + && va.Resolve("vaRenderPicture", api.RenderPicture) + && va.Resolve("vaEndPicture", api.EndPicture) + && va.Resolve("vaSyncSurface", api.SyncSurface) + && va.Resolve("vaDeriveImage", api.DeriveImage) + && va.Resolve("vaCreateImage", api.CreateImage) + && va.Resolve("vaPutImage", api.PutImage) + && va.Resolve("vaDestroyImage", api.DestroyImage); + + if (!resolved) { + RTC_LOG(LS_WARNING) << "VA-API: libva lacks functions this library needs"; + return false; + } + + // Optional; older versions of libva do not have it. + va.Resolve("vaSetInfoCallback", api.SetInfoCallback); + + if (!OpenDisplay()) { + RTC_LOG(LS_INFO) << "VA-API: no GPU driver encodes H.264"; + return false; + } + + RTC_LOG(LS_INFO) << "VA-API H.264 encoding available: " << vendor; + + return true; + } + + bool VaapiLibrary::OpenDisplay() + { + for (int node = kFirstRenderNode; node < kFirstRenderNode + kRenderNodeCount; node++) { + const std::string path = "/dev/dri/renderD" + std::to_string(node); + const int nodeFd = open(path.c_str(), O_RDWR | O_CLOEXEC); + + if (nodeFd < 0) { + continue; + } + + VADisplay nodeDisplay = api.GetDisplayDRM(nodeFd); + + if (nodeDisplay != nullptr && api.SetInfoCallback != nullptr) { + api.SetInfoCallback(nodeDisplay, IgnoreInfo, nullptr); + } + + int major = 0; + int minor = 0; + + if (nodeDisplay != nullptr && api.Initialize(nodeDisplay, &major, &minor) == VA_STATUS_SUCCESS) { + VAEntrypoint nodeEntrypoint; + + if (SupportsEncoding(nodeDisplay, &nodeEntrypoint)) { + fd = nodeFd; + display = nodeDisplay; + entrypoint = nodeEntrypoint; + + const char * vendorString = api.QueryVendorString(display); + vendor = vendorString != nullptr ? vendorString : "unknown"; + + return true; + } + + api.Terminate(nodeDisplay); + } + + close(nodeFd); + } + + return false; + } + + bool VaapiLibrary::SupportsEncoding(VADisplay nodeDisplay, VAEntrypoint * supported) const + { + const int maxEntrypoints = api.MaxNumEntrypoints(nodeDisplay); + + if (maxEntrypoints <= 0) { + return false; + } + + std::vector entrypoints(maxEntrypoints); + int count = 0; + + if (api.QueryConfigEntrypoints(nodeDisplay, VAProfileH264ConstrainedBaseline, entrypoints.data(), + &count) != VA_STATUS_SUCCESS) + { + return false; + } + + entrypoints.resize(count); + + // The full encoder where there is one; the low-power one otherwise. + const VAEntrypoint candidates[] = { VAEntrypointEncSlice, VAEntrypointEncSliceLP }; + + for (VAEntrypoint candidate : candidates) { + if (std::find(entrypoints.begin(), entrypoints.end(), candidate) == entrypoints.end()) { + continue; + } + + VAConfigAttrib attributes[2] = {}; + attributes[0].type = VAConfigAttribRTFormat; + attributes[1].type = VAConfigAttribRateControl; + + if (api.GetConfigAttributes(nodeDisplay, VAProfileH264ConstrainedBaseline, candidate, attributes, 2) != + VA_STATUS_SUCCESS) + { + continue; + } + + const bool yuv420 = attributes[0].value != VA_ATTRIB_NOT_SUPPORTED + && (attributes[0].value & VA_RT_FORMAT_YUV420); + const bool cbr = attributes[1].value != VA_ATTRIB_NOT_SUPPORTED + && (attributes[1].value & VA_RC_CBR); + + if (yuv420 && cbr) { + *supported = candidate; + return true; + } + } + + return false; + } + + const VaapiFunctions & VaapiLibrary::Api() const + { + return api; + } + + VADisplay VaapiLibrary::Display() const + { + return display; + } + + VAEntrypoint VaapiLibrary::Entrypoint() const + { + return entrypoint; + } + + const std::string & VaapiLibrary::Vendor() const + { + return vendor; + } + + const char * VaapiLibrary::ErrorString(VAStatus status) const + { + return api.ErrorStr(status); + } +} diff --git a/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiVideoEncoderFactory.cpp b/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiVideoEncoderFactory.cpp new file mode 100644 index 00000000..d642a144 --- /dev/null +++ b/webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiVideoEncoderFactory.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 2026 Alex Andres + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "media/video/codec/linux/VaapiVideoEncoderFactory.h" +#include "media/video/codec/linux/VaapiH264Encoder.h" + +#include "api/video_codecs/h264_profile_level_id.h" +#include "modules/video_coding/codecs/h264/include/h264.h" + +namespace jni +{ + std::unique_ptr VaapiVideoEncoderFactory::Create() + { + VaapiLibrary * library = VaapiLibrary::Get(); + + if (library == nullptr) { + return nullptr; + } + + return std::unique_ptr(new VaapiVideoEncoderFactory(*library)); + } + + VaapiVideoEncoderFactory::VaapiVideoEncoderFactory(VaapiLibrary & library) : + library(library) + { + } + + std::vector VaapiVideoEncoderFactory::GetSupportedFormats() const + { + return { + webrtc::CreateH264Format(webrtc::H264Profile::kProfileConstrainedBaseline, webrtc::H264Level::kLevel3_1, "1"), + webrtc::CreateH264Format(webrtc::H264Profile::kProfileBaseline, webrtc::H264Level::kLevel3_1, "1") + }; + } + + std::unique_ptr VaapiVideoEncoderFactory::Create(const webrtc::Environment & env, + const webrtc::SdpVideoFormat & format) + { + return std::make_unique(library, format); + } +} diff --git a/webrtc/src/main/java/dev/onvoid/webrtc/media/video/codec/HardwareVideoEncoderFactory.java b/webrtc/src/main/java/dev/onvoid/webrtc/media/video/codec/HardwareVideoEncoderFactory.java index 8e30a75a..af1b373c 100644 --- a/webrtc/src/main/java/dev/onvoid/webrtc/media/video/codec/HardwareVideoEncoderFactory.java +++ b/webrtc/src/main/java/dev/onvoid/webrtc/media/video/codec/HardwareVideoEncoderFactory.java @@ -34,8 +34,9 @@ * .build(); * } *

- * H.264 is encoded on an NVIDIA GPU with NVENC, on Windows and Linux, and - * on Windows otherwise with the Media Foundation encoder of the GPU driver. + * H.264 is encoded on an NVIDIA GPU with NVENC, on Windows and Linux. On + * other GPUs it is encoded with the Media Foundation encoder of the driver on + * Windows, and with its VA-API encoder on Linux. * A hardware encoder that fails to start, for example because the GPU has no * encoder sessions left, or fails while encoding, is replaced by the next one * in line, and finally by the software encoder of the same codec, so a stream diff --git a/webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoEncoderIntegrationTest.java b/webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoEncoderIntegrationTest.java index 2827c8db..8777a2c4 100644 --- a/webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoEncoderIntegrationTest.java +++ b/webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoEncoderIntegrationTest.java @@ -83,6 +83,7 @@ void hardwareEncodesH264() throws Exception { String implementation = encoderImplementation(hardware); boolean hardwareUsed = implementation.startsWith("NVENC") + || implementation.startsWith("VA-API") || implementation.contains("MediaFoundation"); if (HARDWARE_REQUIRED) {