video_types.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_BASE_VIDEO_TYPES_H_
  5. #define MEDIA_BASE_VIDEO_TYPES_H_
  6. #include <stdint.h>
  7. #include <iosfwd>
  8. #include <string>
  9. #include "build/build_config.h"
  10. #include "media/base/media_shmem_export.h"
  11. namespace media {
  12. // Pixel formats roughly based on FOURCC labels, see:
  13. // http://www.fourcc.org/rgb.php and http://www.fourcc.org/yuv.php
  14. // Logged to UMA, so never reuse values. Leave gaps if necessary.
  15. // Ordered as planar, semi-planar, YUV-packed, and RGB formats.
  16. // When a VideoFrame is backed by native textures, VideoPixelFormat describes
  17. // how those textures should be sampled and combined to produce the final
  18. // pixels.
  19. enum VideoPixelFormat {
  20. PIXEL_FORMAT_UNKNOWN = 0, // Unknown or unspecified format value.
  21. PIXEL_FORMAT_I420 =
  22. 1, // 12bpp YUV planar 1x1 Y, 2x2 UV samples, a.k.a. YU12.
  23. // Note: Chrome does not actually support YVU compositing, so you probably
  24. // don't actually want to use this. See http://crbug.com/784627.
  25. PIXEL_FORMAT_YV12 = 2, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
  26. PIXEL_FORMAT_I422 = 3, // 16bpp YUV planar 1x1 Y, 2x1 UV samples.
  27. PIXEL_FORMAT_I420A = 4, // 20bpp YUVA planar 1x1 Y, 2x2 UV, 1x1 A samples.
  28. PIXEL_FORMAT_I444 = 5, // 24bpp YUV planar, no subsampling.
  29. PIXEL_FORMAT_NV12 =
  30. 6, // 12bpp with Y plane followed by a 2x2 interleaved UV plane.
  31. PIXEL_FORMAT_NV21 =
  32. 7, // 12bpp with Y plane followed by a 2x2 interleaved VU plane.
  33. PIXEL_FORMAT_UYVY =
  34. 8, // 16bpp interleaved 2x1 U, 1x1 Y, 2x1 V, 1x1 Y samples.
  35. PIXEL_FORMAT_YUY2 =
  36. 9, // 16bpp interleaved 1x1 Y, 2x1 U, 1x1 Y, 2x1 V samples.
  37. PIXEL_FORMAT_ARGB = 10, // 32bpp BGRA (byte-order), 1 plane.
  38. PIXEL_FORMAT_XRGB = 11, // 24bpp BGRX (byte-order), 1 plane.
  39. PIXEL_FORMAT_RGB24 = 12, // 24bpp BGR (byte-order), 1 plane.
  40. /* PIXEL_FORMAT_RGB32 = 13, Deprecated */
  41. PIXEL_FORMAT_MJPEG = 14, // MJPEG compressed.
  42. /* PIXEL_FORMAT_MT21 = 15, Deprecated */
  43. // The P* in the formats below designates the number of bits per pixel
  44. // component. I.e. P9 is 9-bits per pixel component, P10 is 10-bits per pixel
  45. // component, etc.
  46. PIXEL_FORMAT_YUV420P9 = 16,
  47. PIXEL_FORMAT_YUV420P10 = 17,
  48. PIXEL_FORMAT_YUV422P9 = 18,
  49. PIXEL_FORMAT_YUV422P10 = 19,
  50. PIXEL_FORMAT_YUV444P9 = 20,
  51. PIXEL_FORMAT_YUV444P10 = 21,
  52. PIXEL_FORMAT_YUV420P12 = 22,
  53. PIXEL_FORMAT_YUV422P12 = 23,
  54. PIXEL_FORMAT_YUV444P12 = 24,
  55. /* PIXEL_FORMAT_Y8 = 25, Deprecated */
  56. PIXEL_FORMAT_Y16 = 26, // single 16bpp plane.
  57. PIXEL_FORMAT_ABGR = 27, // 32bpp RGBA (byte-order), 1 plane.
  58. PIXEL_FORMAT_XBGR = 28, // 24bpp RGBX (byte-order), 1 plane.
  59. PIXEL_FORMAT_P016LE = 29, // 24bpp NV12, 16 bits per channel
  60. PIXEL_FORMAT_XR30 =
  61. 30, // 32bpp BGRX, 10 bits per channel, 2 bits ignored, 1 plane
  62. PIXEL_FORMAT_XB30 =
  63. 31, // 32bpp RGBX, 10 bits per channel, 2 bits ignored, 1 plane
  64. PIXEL_FORMAT_BGRA = 32, // 32bpp ARGB (byte-order), 1 plane.
  65. PIXEL_FORMAT_RGBAF16 = 33, // Half float RGBA, 1 plane.
  66. PIXEL_FORMAT_I422A = 34, // 24bpp YUVA planar 1x1 Y, 2x1 UV, 1x1 A samples.
  67. PIXEL_FORMAT_I444A = 35, // 32bpp YUVA planar, no subsampling.
  68. // YUVA planar, 10 bits per pixel component.
  69. PIXEL_FORMAT_YUV420AP10 = 36,
  70. PIXEL_FORMAT_YUV422AP10 = 37,
  71. PIXEL_FORMAT_YUV444AP10 = 38,
  72. // Please update UMA histogram enumeration when adding new formats here.
  73. PIXEL_FORMAT_MAX =
  74. PIXEL_FORMAT_YUV444AP10, // Must always be equal to largest entry logged.
  75. };
  76. // These values are persisted to logs. Entries should not be renumbered and
  77. // numeric values should never be reused.
  78. enum class VideoChromaSampling : uint8_t {
  79. kUnknown = 0,
  80. k420, // 4:2:0 chroma channel has 1/2 height/width of luma channel.
  81. k422, // 4:2:2 chroma channel has same height & 1/2 width of luma channel.
  82. k444, // 4:4:4 chroma channel has same height/width of luma channel.
  83. k400, // 4:0:0 monochrome without chroma subsampling.
  84. // Please update UMA histogram enumeration when adding new formats here.
  85. kMaxValue = k400, // Must always be equal to largest entry logged.
  86. };
  87. // Return the name of chroma sampling format as a string.
  88. MEDIA_SHMEM_EXPORT std::string VideoChromaSamplingToString(
  89. VideoChromaSampling chroma_sampling);
  90. // Returns the name of a Format as a string.
  91. MEDIA_SHMEM_EXPORT std::string VideoPixelFormatToString(
  92. VideoPixelFormat format);
  93. // Stream operator of Format for logging etc.
  94. MEDIA_SHMEM_EXPORT std::ostream& operator<<(std::ostream& os,
  95. VideoPixelFormat format);
  96. // Returns human readable fourcc string.
  97. // If any of the four characters is non-printable, it outputs
  98. // "0x<32-bit integer in hex>", e.g. FourccToString(0x66616b00) returns
  99. // "0x66616b00".
  100. MEDIA_SHMEM_EXPORT std::string FourccToString(uint32_t fourcc);
  101. // Returns true if |format| is a YUV format with multiple planes.
  102. MEDIA_SHMEM_EXPORT bool IsYuvPlanar(VideoPixelFormat format);
  103. // Returns true if |format| is an RGB format.
  104. MEDIA_SHMEM_EXPORT bool IsRGB(VideoPixelFormat format);
  105. // Returns true if |format| has no Alpha channel (hence is always opaque).
  106. MEDIA_SHMEM_EXPORT bool IsOpaque(VideoPixelFormat format);
  107. // Returns the number of significant bits per channel.
  108. MEDIA_SHMEM_EXPORT size_t BitDepth(VideoPixelFormat format);
  109. } // namespace media
  110. #endif // MEDIA_BASE_VIDEO_TYPES_H_