Lajos Molnar | 7c357a7 | 2016-03-08 11:30:15 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef VIDEO_API_H_ |
| 18 | |
| 19 | #define VIDEO_API_H_ |
| 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | /** |
| 24 | * Structure describing a media image (frame) |
| 25 | * Currently only supporting YUV |
| 26 | * @deprecated. Use MediaImage2 instead |
| 27 | */ |
| 28 | struct MediaImage { |
| 29 | enum Type { |
| 30 | MEDIA_IMAGE_TYPE_UNKNOWN = 0, |
| 31 | MEDIA_IMAGE_TYPE_YUV, |
| 32 | }; |
| 33 | |
| 34 | enum PlaneIndex { |
| 35 | Y = 0, |
| 36 | U, |
| 37 | V, |
| 38 | MAX_NUM_PLANES |
| 39 | }; |
| 40 | |
| 41 | Type mType; |
| 42 | uint32_t mNumPlanes; // number of planes |
| 43 | uint32_t mWidth; // width of largest plane (unpadded, as in nFrameWidth) |
| 44 | uint32_t mHeight; // height of largest plane (unpadded, as in nFrameHeight) |
| 45 | uint32_t mBitDepth; // useable bit depth |
| 46 | struct PlaneInfo { |
| 47 | uint32_t mOffset; // offset of first pixel of the plane in bytes |
| 48 | // from buffer offset |
| 49 | uint32_t mColInc; // column increment in bytes |
| 50 | uint32_t mRowInc; // row increment in bytes |
| 51 | uint32_t mHorizSubsampling; // subsampling compared to the largest plane |
| 52 | uint32_t mVertSubsampling; // subsampling compared to the largest plane |
| 53 | }; |
| 54 | PlaneInfo mPlane[MAX_NUM_PLANES]; |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * Structure describing a media image (frame) |
| 59 | */ |
| 60 | struct MediaImage2 { |
| 61 | enum Type : uint32_t { |
| 62 | MEDIA_IMAGE_TYPE_UNKNOWN = 0, |
| 63 | MEDIA_IMAGE_TYPE_YUV, |
| 64 | MEDIA_IMAGE_TYPE_YUVA, |
| 65 | MEDIA_IMAGE_TYPE_RGB, |
| 66 | MEDIA_IMAGE_TYPE_RGBA, |
| 67 | MEDIA_IMAGE_TYPE_Y, |
| 68 | }; |
| 69 | |
| 70 | enum PlaneIndex : uint32_t { |
| 71 | Y = 0, |
| 72 | U = 1, |
| 73 | V = 2, |
| 74 | R = 0, |
| 75 | G = 1, |
| 76 | B = 2, |
| 77 | A = 3, |
| 78 | MAX_NUM_PLANES = 4, |
| 79 | }; |
| 80 | |
| 81 | Type mType; |
| 82 | uint32_t mNumPlanes; // number of planes |
| 83 | uint32_t mWidth; // width of largest plane (unpadded, as in nFrameWidth) |
| 84 | uint32_t mHeight; // height of largest plane (unpadded, as in nFrameHeight) |
| 85 | uint32_t mBitDepth; // useable bit depth (always MSB) |
| 86 | uint32_t mBitDepthAllocated; // bits per component (must be 8 or 16) |
| 87 | |
| 88 | struct PlaneInfo { |
| 89 | uint32_t mOffset; // offset of first pixel of the plane in bytes |
| 90 | // from buffer offset |
| 91 | int32_t mColInc; // column increment in bytes |
| 92 | int32_t mRowInc; // row increment in bytes |
| 93 | uint32_t mHorizSubsampling; // subsampling compared to the largest plane |
| 94 | uint32_t mVertSubsampling; // subsampling compared to the largest plane |
| 95 | }; |
| 96 | PlaneInfo mPlane[MAX_NUM_PLANES]; |
| 97 | |
| 98 | void initFromV1(const MediaImage&); // for internal use only |
| 99 | }; |
| 100 | |
| 101 | /** |
| 102 | * Aspects of color. |
| 103 | */ |
| 104 | |
| 105 | // NOTE: this structure is expected to grow in the future if new color aspects are |
| 106 | // added to codec bitstreams. OMX component should not require a specific nSize |
| 107 | // though could verify that nSize is at least the size of the structure at the |
| 108 | // time of implementation. All new fields will be added at the end of the structure |
| 109 | // ensuring backward compatibility. |
| 110 | struct ColorAspects { |
| 111 | // this is in sync with the range values in graphics.h |
| 112 | enum Range : uint32_t { |
| 113 | RangeUnspecified, |
| 114 | RangeFull, |
| 115 | RangeLimited, |
| 116 | RangeOther = 0xff, |
| 117 | }; |
| 118 | |
| 119 | enum Primaries : uint32_t { |
| 120 | PrimariesUnspecified, |
| 121 | PrimariesBT709_5, // Rec.ITU-R BT.709-5 or equivalent |
| 122 | PrimariesBT470_6M, // Rec.ITU-R BT.470-6 System M or equivalent |
| 123 | PrimariesBT601_6_625, // Rec.ITU-R BT.601-6 625 or equivalent |
| 124 | PrimariesBT601_6_525, // Rec.ITU-R BT.601-6 525 or equivalent |
| 125 | PrimariesGenericFilm, // Generic Film |
| 126 | PrimariesBT2020, // Rec.ITU-R BT.2020 or equivalent |
| 127 | PrimariesOther = 0xff, |
| 128 | }; |
| 129 | |
| 130 | // this partially in sync with the transfer values in graphics.h prior to the transfers |
| 131 | // unlikely to be required by Android section |
| 132 | enum Transfer : uint32_t { |
| 133 | TransferUnspecified, |
| 134 | TransferLinear, // Linear transfer characteristics |
| 135 | TransferSRGB, // sRGB or equivalent |
| 136 | TransferSMPTE170M, // SMPTE 170M or equivalent (e.g. BT.601/709/2020) |
| 137 | TransferGamma22, // Assumed display gamma 2.2 |
| 138 | TransferGamma28, // Assumed display gamma 2.8 |
| 139 | TransferST2084, // SMPTE ST 2084 for 10/12/14/16 bit systems |
| 140 | TransferHLG, // ARIB STD-B67 hybrid-log-gamma |
| 141 | |
| 142 | // transfers unlikely to be required by Android |
| 143 | TransferSMPTE240M = 0x40, // SMPTE 240M |
| 144 | TransferXvYCC, // IEC 61966-2-4 |
| 145 | TransferBT1361, // Rec.ITU-R BT.1361 extended gamut |
| 146 | TransferST428, // SMPTE ST 428-1 |
| 147 | TransferOther = 0xff, |
| 148 | }; |
| 149 | |
| 150 | enum MatrixCoeffs : uint32_t { |
| 151 | MatrixUnspecified, |
| 152 | MatrixBT709_5, // Rec.ITU-R BT.709-5 or equivalent |
| 153 | MatrixBT470_6M, // KR=0.30, KB=0.11 or equivalent |
| 154 | MatrixBT601_6, // Rec.ITU-R BT.601-6 625 or equivalent |
| 155 | MatrixSMPTE240M, // SMPTE 240M or equivalent |
| 156 | MatrixBT2020, // Rec.ITU-R BT.2020 non-constant luminance |
| 157 | MatrixBT2020Constant, // Rec.ITU-R BT.2020 constant luminance |
| 158 | MatrixOther = 0xff, |
| 159 | }; |
| 160 | |
| 161 | // this is in sync with the standard values in graphics.h |
| 162 | enum Standard : uint32_t { |
| 163 | StandardUnspecified, |
| 164 | StandardBT709, // PrimariesBT709_5 and MatrixBT709_5 |
| 165 | StandardBT601_625, // PrimariesBT601_6_625 and MatrixBT601_6 |
| 166 | StandardBT601_625_Unadjusted, // PrimariesBT601_6_625 and KR=0.222, KB=0.071 |
| 167 | StandardBT601_525, // PrimariesBT601_6_525 and MatrixBT601_6 |
| 168 | StandardBT601_525_Unadjusted, // PrimariesBT601_6_525 and MatrixSMPTE240M |
| 169 | StandardBT2020, // PrimariesBT2020 and MatrixBT2020 |
| 170 | StandardBT2020Constant, // PrimariesBT2020 and MatrixBT2020Constant |
| 171 | StandardBT470M, // PrimariesBT470_6M and MatrixBT470_6M |
| 172 | StandardFilm, // PrimariesGenericFilm and KR=0.253, KB=0.068 |
| 173 | StandardOther = 0xff, |
| 174 | }; |
| 175 | |
| 176 | Range mRange; // IN/OUT |
| 177 | Primaries mPrimaries; // IN/OUT |
| 178 | Transfer mTransfer; // IN/OUT |
| 179 | MatrixCoeffs mMatrixCoeffs; // IN/OUT |
| 180 | }; |
| 181 | |
| 182 | #ifdef STRINGIFY_ENUMS |
| 183 | |
| 184 | inline static const char *asString(MediaImage::Type i, const char *def = "??") { |
| 185 | switch (i) { |
| 186 | case MediaImage::MEDIA_IMAGE_TYPE_UNKNOWN: return "Unknown"; |
| 187 | case MediaImage::MEDIA_IMAGE_TYPE_YUV: return "YUV"; |
| 188 | default: return def; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | inline static const char *asString(MediaImage::PlaneIndex i, const char *def = "??") { |
| 193 | switch (i) { |
| 194 | case MediaImage::Y: return "Y"; |
| 195 | case MediaImage::U: return "U"; |
| 196 | case MediaImage::V: return "V"; |
| 197 | default: return def; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | inline static const char *asString(MediaImage2::Type i, const char *def = "??") { |
| 202 | switch (i) { |
| 203 | case MediaImage2::MEDIA_IMAGE_TYPE_UNKNOWN: return "Unknown"; |
| 204 | case MediaImage2::MEDIA_IMAGE_TYPE_YUV: return "YUV"; |
| 205 | case MediaImage2::MEDIA_IMAGE_TYPE_YUVA: return "YUVA"; |
| 206 | case MediaImage2::MEDIA_IMAGE_TYPE_RGB: return "RGB"; |
| 207 | case MediaImage2::MEDIA_IMAGE_TYPE_RGBA: return "RGBA"; |
| 208 | case MediaImage2::MEDIA_IMAGE_TYPE_Y: return "Y"; |
| 209 | default: return def; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | inline static char asChar2( |
| 214 | MediaImage2::PlaneIndex i, MediaImage2::Type j, char def = '?') { |
| 215 | const char *planes = asString(j, NULL); |
| 216 | // handle unknown values |
| 217 | if (j == MediaImage2::MEDIA_IMAGE_TYPE_UNKNOWN || planes == NULL || i >= strlen(planes)) { |
| 218 | return def; |
| 219 | } |
| 220 | return planes[i]; |
| 221 | } |
| 222 | |
| 223 | inline static const char *asString(ColorAspects::Range i, const char *def = "??") { |
| 224 | switch (i) { |
| 225 | case ColorAspects::RangeUnspecified: return "Unspecified"; |
| 226 | case ColorAspects::RangeFull: return "Full"; |
| 227 | case ColorAspects::RangeLimited: return "Limited"; |
| 228 | case ColorAspects::RangeOther: return "Other"; |
| 229 | default: return def; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | inline static const char *asString(ColorAspects::Primaries i, const char *def = "??") { |
| 234 | switch (i) { |
| 235 | case ColorAspects::PrimariesUnspecified: return "Unspecified"; |
| 236 | case ColorAspects::PrimariesBT709_5: return "BT709_5"; |
| 237 | case ColorAspects::PrimariesBT470_6M: return "BT470_6M"; |
| 238 | case ColorAspects::PrimariesBT601_6_625: return "BT601_6_625"; |
| 239 | case ColorAspects::PrimariesBT601_6_525: return "BT601_6_525"; |
| 240 | case ColorAspects::PrimariesGenericFilm: return "GenericFilm"; |
| 241 | case ColorAspects::PrimariesBT2020: return "BT2020"; |
| 242 | case ColorAspects::PrimariesOther: return "Other"; |
| 243 | default: return def; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | inline static const char *asString(ColorAspects::Transfer i, const char *def = "??") { |
| 248 | switch (i) { |
| 249 | case ColorAspects::TransferUnspecified: return "Unspecified"; |
| 250 | case ColorAspects::TransferLinear: return "Linear"; |
| 251 | case ColorAspects::TransferSRGB: return "SRGB"; |
| 252 | case ColorAspects::TransferSMPTE170M: return "SMPTE170M"; |
| 253 | case ColorAspects::TransferGamma22: return "Gamma22"; |
| 254 | case ColorAspects::TransferGamma28: return "Gamma28"; |
| 255 | case ColorAspects::TransferST2084: return "ST2084"; |
| 256 | case ColorAspects::TransferHLG: return "HLG"; |
| 257 | case ColorAspects::TransferSMPTE240M: return "SMPTE240M"; |
| 258 | case ColorAspects::TransferXvYCC: return "XvYCC"; |
| 259 | case ColorAspects::TransferBT1361: return "BT1361"; |
| 260 | case ColorAspects::TransferST428: return "ST428"; |
| 261 | case ColorAspects::TransferOther: return "Other"; |
| 262 | default: return def; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | inline static const char *asString(ColorAspects::MatrixCoeffs i, const char *def = "??") { |
| 267 | switch (i) { |
| 268 | case ColorAspects::MatrixUnspecified: return "Unspecified"; |
| 269 | case ColorAspects::MatrixBT709_5: return "BT709_5"; |
| 270 | case ColorAspects::MatrixBT470_6M: return "BT470_6M"; |
| 271 | case ColorAspects::MatrixBT601_6: return "BT601_6"; |
| 272 | case ColorAspects::MatrixSMPTE240M: return "SMPTE240M"; |
| 273 | case ColorAspects::MatrixBT2020: return "BT2020"; |
| 274 | case ColorAspects::MatrixBT2020Constant: return "BT2020Constant"; |
| 275 | case ColorAspects::MatrixOther: return "Other"; |
| 276 | default: return def; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | inline static const char *asString(ColorAspects::Standard i, const char *def = "??") { |
| 281 | switch (i) { |
| 282 | case ColorAspects::StandardUnspecified: return "Unspecified"; |
| 283 | case ColorAspects::StandardBT709: return "BT709"; |
| 284 | case ColorAspects::StandardBT601_625: return "BT601_625"; |
| 285 | case ColorAspects::StandardBT601_625_Unadjusted: return "BT601_625_Unadjusted"; |
| 286 | case ColorAspects::StandardBT601_525: return "BT601_525"; |
| 287 | case ColorAspects::StandardBT601_525_Unadjusted: return "BT601_525_Unadjusted"; |
| 288 | case ColorAspects::StandardBT2020: return "BT2020"; |
| 289 | case ColorAspects::StandardBT2020Constant: return "BT2020Constant"; |
| 290 | case ColorAspects::StandardBT470M: return "BT470M"; |
| 291 | case ColorAspects::StandardFilm: return "Film"; |
| 292 | case ColorAspects::StandardOther: return "Other"; |
| 293 | default: return def; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | #endif |
| 298 | |
| 299 | } // namespace android |
| 300 | |
| 301 | #endif // VIDEO_API_H_ |