1 /* 2 * uvc_h264.h - Definitions of the UVC H.264 Payload specification Version 1.0 3 * 4 * Copyright (c) 2011 USB Implementers Forum, Inc. 5 * 6 * Modification into glib-like header by : 7 * Copyright (C) 2012 Cisco Systems, Inc. 8 * Author: Youness Alaoui <youness.alaoui@collabora.co.uk> 9 * 10 * 11 * Permission is hereby granted, free of charge, to any person obtaining a copy 12 * of this software and associated documentation files (the "Software"), to deal 13 * in the Software without restriction, including without limitation the rights 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 * copies of the Software, and to permit persons to whom the Software is 16 * furnished to do so, subject to the following conditions: 17 * The above copyright notice and this permission notice shall be included in 18 * all copies or substantial portions of the Software. 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 * THE SOFTWARE. 26 */ 27 28 #ifndef _UVC_H264_H_ 29 #define _UVC_H264_H_ 30 31 /* Header File for the little-endian platform */ 32 33 #include <glib.h> 34 #include <glib-object.h> 35 36 /* bmHints defines */ 37 38 #define UVC_H264_BMHINTS_RESOLUTION (0x0001) 39 #define UVC_H264_BMHINTS_PROFILE (0x0002) 40 #define UVC_H264_BMHINTS_RATECONTROL (0x0004) 41 #define UVC_H264_BMHINTS_USAGE (0x0008) 42 #define UVC_H264_BMHINTS_SLICEMODE (0x0010) 43 #define UVC_H264_BMHINTS_SLICEUNITS (0x0020) 44 #define UVC_H264_BMHINTS_MVCVIEW (0x0040) 45 #define UVC_H264_BMHINTS_TEMPORAL (0x0080) 46 #define UVC_H264_BMHINTS_SNR (0x0100) 47 #define UVC_H264_BMHINTS_SPATIAL (0x0200) 48 #define UVC_H264_BMHINTS_SPATIAL_RATIO (0x0400) 49 #define UVC_H264_BMHINTS_FRAME_INTERVAL (0x0800) 50 #define UVC_H264_BMHINTS_LEAKY_BKT_SIZE (0x1000) 51 #define UVC_H264_BMHINTS_BITRATE (0x2000) 52 #define UVC_H264_BMHINTS_ENTROPY (0x4000) 53 #define UVC_H264_BMHINTS_IFRAMEPERIOD (0x8000) 54 55 56 #define UVC_H264_QP_STEPS_I_FRAME_TYPE (0x01) 57 #define UVC_H264_QP_STEPS_P_FRAME_TYPE (0x02) 58 #define UVC_H264_QP_STEPS_B_FRAME_TYPE (0x04) 59 #define UVC_H264_QP_STEPS_ALL_FRAME_TYPES (UVC_H264_QP_STEPS_I_FRAME_TYPE | \ 60 UVC_H264_QP_STEPS_P_FRAME_TYPE | UVC_H264_QP_STEPS_B_FRAME_TYPE) 61 62 /* wSliceMode defines */ 63 64 typedef enum 65 { 66 UVC_H264_SLICEMODE_IGNORED = 0x0000, 67 UVC_H264_SLICEMODE_BITSPERSLICE = 0x0001, 68 UVC_H264_SLICEMODE_MBSPERSLICE = 0x0002, 69 UVC_H264_SLICEMODE_SLICEPERFRAME = 0x0003 70 } UvcH264SliceMode; 71 72 #define UVC_H264_SLICEMODE_TYPE (uvc_h264_slicemode_get_type()) 73 74 GType uvc_h264_slicemode_get_type (void); 75 76 /* bUsageType defines */ 77 78 typedef enum { 79 UVC_H264_USAGETYPE_REALTIME = 0x01, 80 UVC_H264_USAGETYPE_BROADCAST = 0x02, 81 UVC_H264_USAGETYPE_STORAGE = 0x03, 82 UVC_H264_USAGETYPE_UCCONFIG_0 = 0x04, 83 UVC_H264_USAGETYPE_UCCONFIG_1 = 0x05, 84 UVC_H264_USAGETYPE_UCCONFIG_2Q = 0x06, 85 UVC_H264_USAGETYPE_UCCONFIG_2S = 0x07, 86 UVC_H264_USAGETYPE_UCCONFIG_3 = 0x08, 87 } UvcH264UsageType; 88 89 #define UVC_H264_USAGETYPE_TYPE (uvc_h264_usagetype_get_type()) 90 91 GType uvc_h264_usagetype_get_type (void); 92 93 /* bRateControlMode defines */ 94 95 typedef enum { 96 UVC_H264_RATECONTROL_CBR = 0x01, 97 UVC_H264_RATECONTROL_VBR = 0x02, 98 UVC_H264_RATECONTROL_CONST_QP = 0x03, 99 } UvcH264RateControl; 100 101 #define UVC_H264_RATECONTROL_FIXED_FRM_FLG (0x10) 102 103 #define UVC_H264_RATECONTROL_TYPE (uvc_h264_ratecontrol_get_type()) 104 105 GType uvc_h264_ratecontrol_get_type (void); 106 107 /* bStreamFormat defines */ 108 109 typedef enum { 110 UVC_H264_STREAMFORMAT_ANNEXB = 0x00, 111 UVC_H264_STREAMFORMAT_NAL = 0x01, 112 } UvcH264StreamFormat; 113 114 #define UVC_H264_STREAMFORMAT_TYPE (uvc_h264_streamformat_get_type()) 115 116 GType uvc_h264_streamformat_get_type (void); 117 118 /* bEntropyCABAC defines */ 119 120 typedef enum { 121 UVC_H264_ENTROPY_CAVLC = 0x00, 122 UVC_H264_ENTROPY_CABAC = 0x01, 123 } UvcH264Entropy; 124 125 #define UVC_H264_ENTROPY_TYPE (uvc_h264_entropy_get_type()) 126 127 GType uvc_h264_entropy_get_type (void); 128 129 /* bProfile defines */ 130 #define UVC_H264_PROFILE_CONSTRAINED_BASELINE 0x4240 131 #define UVC_H264_PROFILE_BASELINE 0x4200 132 #define UVC_H264_PROFILE_MAIN 0x4D00 133 #define UVC_H264_PROFILE_HIGH 0x6400 134 135 /* bTimingstamp defines */ 136 137 #define UVC_H264_TIMESTAMP_SEI_DISABLE (0x00) 138 #define UVC_H264_TIMESTAMP_SEI_ENABLE (0x01) 139 140 /* bPreviewFlipped defines */ 141 142 #define UVC_H264_PREFLIPPED_DISABLE (0x00) 143 #define UVC_H264_PREFLIPPED_HORIZONTAL (0x01) 144 145 /* wPicType defines */ 146 #define UVC_H264_PICTYPE_I_FRAME (0x00) 147 #define UVC_H264_PICTYPE_IDR (0x01) 148 #define UVC_H264_PICTYPE_IDR_WITH_PPS_SPS (0x02) 149 150 151 /* wLayerID Macro */ 152 153 /* wLayerID 154 |------------+------------+------------+----------------+------------| 155 | Reserved | StreamID | QualityID | DependencyID | TemporalID | 156 | (3 bits) | (3 bits) | (3 bits) | (4 bits) | (3 bits) | 157 |------------+------------+------------+----------------+------------| 158 |15 13|12 10|9 7|6 3|2 0| 159 |------------+------------+------------+----------------+------------| 160 */ 161 162 #define xLayerID(stream_id, quality_id, dependency_id, temporal_id) \ 163 ((((stream_id) & 7) << 10) | \ 164 (((quality_id) & 7) << 7) | \ 165 (((dependency_id) & 15) << 3) | \ 166 ((temporal_id) & 7)) 167 168 /* id extraction from wLayerID */ 169 170 #define xStream_id(layer_id) (((layer_id) >> 10) & 7) 171 #define xQuality_id(layer_id) (((layer_id) >> 7) & 7) 172 #define xDependency_id(layer_id) (((layer_id) >> 3) & 15) 173 #define xTemporal_id(layer_id) ((layer_id)&7) 174 175 /* UVC H.264 control selectors */ 176 177 typedef enum _uvcx_control_selector_t 178 { 179 UVCX_VIDEO_CONFIG_PROBE = 0x01, 180 UVCX_VIDEO_CONFIG_COMMIT = 0x02, 181 UVCX_RATE_CONTROL_MODE = 0x03, 182 UVCX_TEMPORAL_SCALE_MODE = 0x04, 183 UVCX_SPATIAL_SCALE_MODE = 0x05, 184 UVCX_SNR_SCALE_MODE = 0x06, 185 UVCX_LTR_BUFFER_SIZE_CONTROL = 0x07, 186 UVCX_LTR_PICTURE_CONTROL = 0x08, 187 UVCX_PICTURE_TYPE_CONTROL = 0x09, 188 UVCX_VERSION = 0x0A, 189 UVCX_ENCODER_RESET = 0x0B, 190 UVCX_FRAMERATE_CONFIG = 0x0C, 191 UVCX_VIDEO_ADVANCE_CONFIG = 0x0D, 192 UVCX_BITRATE_LAYERS = 0x0E, 193 UVCX_QP_STEPS_LAYERS = 0x0F, 194 } uvcx_control_selector_t; 195 196 197 typedef struct _uvcx_video_config_probe_commit_t 198 { 199 guint32 dwFrameInterval; 200 guint32 dwBitRate; 201 guint16 bmHints; 202 guint16 wConfigurationIndex; 203 guint16 wWidth; 204 guint16 wHeight; 205 guint16 wSliceUnits; 206 guint16 wSliceMode; 207 guint16 wProfile; 208 guint16 wIFramePeriod; 209 guint16 wEstimatedVideoDelay; 210 guint16 wEstimatedMaxConfigDelay; 211 guint8 bUsageType; 212 guint8 bRateControlMode; 213 guint8 bTemporalScaleMode; 214 guint8 bSpatialScaleMode; 215 guint8 bSNRScaleMode; 216 guint8 bStreamMuxOption; 217 guint8 bStreamFormat; 218 guint8 bEntropyCABAC; 219 guint8 bTimestamp; 220 guint8 bNumOfReorderFrames; 221 guint8 bPreviewFlipped; 222 guint8 bView; 223 guint8 bReserved1; 224 guint8 bReserved2; 225 guint8 bStreamID; 226 guint8 bSpatialLayerRatio; 227 guint16 wLeakyBucketSize; 228 } __attribute__((packed)) uvcx_video_config_probe_commit_t; 229 230 231 typedef struct _uvcx_rate_control_mode_t 232 { 233 guint16 wLayerID; 234 guint8 bRateControlMode; 235 } __attribute__((packed)) uvcx_rate_control_mode_t; 236 237 238 typedef struct _uvcx_temporal_scale_mode_t 239 { 240 guint16 wLayerID; 241 guint8 bTemporalScaleMode; 242 } __attribute__((packed)) uvcx_temporal_scale_mode_t; 243 244 245 typedef struct _uvcx_spatial_scale_mode_t 246 { 247 guint16 wLayerID; 248 guint8 bSpatialScaleMode; 249 } __attribute__((packed)) uvcx_spatial_scale_mode_t; 250 251 252 typedef struct _uvcx_snr_scale_mode_t 253 { 254 guint16 wLayerID; 255 guint8 bSNRScaleMode; 256 guint8 bMGSSublayerMode; 257 } __attribute__((packed)) uvcx_snr_scale_mode_t; 258 259 260 typedef struct _uvcx_ltr_buffer_size_control_t 261 { 262 guint16 wLayerID; 263 guint8 bLTRBufferSize; 264 guint8 bLTREncoderControl; 265 } __attribute__((packed)) uvcx_ltr_buffer_size_control_t; 266 267 typedef struct _uvcx_ltr_picture_control 268 { 269 guint16 wLayerID; 270 guint8 bPutAtPositionInLTRBuffer; 271 guint8 bEncodeUsingLTR; 272 } __attribute__((packed)) uvcx_ltr_picture_control; 273 274 275 typedef struct _uvcx_picture_type_control_t 276 { 277 guint16 wLayerID; 278 guint16 wPicType; 279 } __attribute__((packed)) uvcx_picture_type_control_t; 280 281 282 typedef struct _uvcx_version_t 283 { 284 guint16 wVersion; 285 } __attribute__((packed)) uvcx_version_t; 286 287 288 typedef struct _uvcx_encoder_reset 289 { 290 guint16 wLayerID; 291 } __attribute__((packed)) uvcx_encoder_reset; 292 293 294 typedef struct _uvcx_framerate_config_t 295 { 296 guint16 wLayerID; 297 guint32 dwFrameInterval; 298 } __attribute__((packed)) uvcx_framerate_config_t; 299 300 301 typedef struct _uvcx_video_advance_config_t 302 { 303 guint16 wLayerID; 304 guint32 dwMb_max; 305 guint8 blevel_idc; 306 guint8 bReserved; 307 } __attribute__((packed)) uvcx_video_advance_config_t; 308 309 310 typedef struct _uvcx_bitrate_layers_t 311 { 312 guint16 wLayerID; 313 guint32 dwPeakBitrate; 314 guint32 dwAverageBitrate; 315 } __attribute__((packed)) uvcx_bitrate_layers_t; 316 317 318 typedef struct _uvcx_qp_steps_layers_t 319 { 320 guint16 wLayerID; 321 guint8 bFrameType; 322 guint8 bMinQp; 323 guint8 bMaxQp; 324 } __attribute__((packed)) uvcx_qp_steps_layers_t; 325 326 327 #ifdef _WIN32 328 // GUID of the UVC H.264 extension unit: {A29E7641-DE04-47E3-8B2B-F4341AFF003B} 329 DEFINE_GUID(GUID_UVCX_H264_XU, 0xA29E7641, 0xDE04, 0x47E3, 0x8B, 0x2B, 0xF4, 0x34, 0x1A, 0xFF, 0x00, 0x3B); 330 #else 331 #define GUID_UVCX_H264_XU \ 332 {0x41, 0x76, 0x9e, 0xa2, 0x04, 0xde, 0xe3, 0x47, 0x8b, 0x2b, 0xF4, 0x34, 0x1A, 0xFF, 0x00, 0x3B} 333 #endif 334 335 #endif /*_UVC_H264_H_*/ 336