video_codecs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // Copyright 2012 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_CODECS_H_
  5. #define MEDIA_BASE_VIDEO_CODECS_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "media/base/media_export.h"
  9. #include "media/media_buildflags.h"
  10. namespace media {
  11. class VideoColorSpace;
  12. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.media
  13. enum class VideoCodec {
  14. // These values are histogrammed over time; do not change their ordinal
  15. // values. When deleting a codec replace it with a dummy value; when adding a
  16. // codec, do so at the bottom (and update kMaxValue).
  17. kUnknown = 0,
  18. kH264,
  19. kVC1,
  20. kMPEG2,
  21. kMPEG4,
  22. kTheora,
  23. kVP8,
  24. kVP9,
  25. kHEVC,
  26. kDolbyVision,
  27. kAV1,
  28. // DO NOT ADD RANDOM VIDEO CODECS!
  29. //
  30. // The only acceptable time to add a new codec is if there is production code
  31. // that uses said codec in the same CL.
  32. kMaxValue = kAV1, // Must equal the last "real" codec above.
  33. };
  34. // Video codec profiles. Keep in sync with mojo::VideoCodecProfile (see
  35. // media/mojo/mojom/media_types.mojom), gpu::VideoCodecProfile (see
  36. // gpu/config/gpu_info.h), and PP_VideoDecoder_Profile (translation is performed
  37. // in content/renderer/pepper/ppb_video_decoder_impl.cc).
  38. // NOTE: These values are histogrammed over time in UMA so the values must never
  39. // ever change (add new values to tools/metrics/histograms/histograms.xml)
  40. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.media
  41. enum VideoCodecProfile {
  42. // Keep the values in this enum unique, as they imply format (h.264 vs. VP8,
  43. // for example), and keep the values for a particular format grouped
  44. // together for clarity.
  45. VIDEO_CODEC_PROFILE_UNKNOWN = -1,
  46. VIDEO_CODEC_PROFILE_MIN = VIDEO_CODEC_PROFILE_UNKNOWN,
  47. H264PROFILE_MIN = 0,
  48. H264PROFILE_BASELINE = H264PROFILE_MIN,
  49. H264PROFILE_MAIN = 1,
  50. H264PROFILE_EXTENDED = 2,
  51. H264PROFILE_HIGH = 3,
  52. H264PROFILE_HIGH10PROFILE = 4,
  53. H264PROFILE_HIGH422PROFILE = 5,
  54. H264PROFILE_HIGH444PREDICTIVEPROFILE = 6,
  55. H264PROFILE_SCALABLEBASELINE = 7,
  56. H264PROFILE_SCALABLEHIGH = 8,
  57. H264PROFILE_STEREOHIGH = 9,
  58. H264PROFILE_MULTIVIEWHIGH = 10,
  59. H264PROFILE_MAX = H264PROFILE_MULTIVIEWHIGH,
  60. VP8PROFILE_MIN = 11,
  61. VP8PROFILE_ANY = VP8PROFILE_MIN,
  62. VP8PROFILE_MAX = VP8PROFILE_ANY,
  63. VP9PROFILE_MIN = 12,
  64. VP9PROFILE_PROFILE0 = VP9PROFILE_MIN,
  65. VP9PROFILE_PROFILE1 = 13,
  66. VP9PROFILE_PROFILE2 = 14,
  67. VP9PROFILE_PROFILE3 = 15,
  68. VP9PROFILE_MAX = VP9PROFILE_PROFILE3,
  69. HEVCPROFILE_MIN = 16,
  70. HEVCPROFILE_MAIN = HEVCPROFILE_MIN,
  71. HEVCPROFILE_MAIN10 = 17,
  72. HEVCPROFILE_MAIN_STILL_PICTURE = 18,
  73. HEVCPROFILE_MAX = HEVCPROFILE_MAIN_STILL_PICTURE,
  74. DOLBYVISION_PROFILE0 = 19,
  75. DOLBYVISION_PROFILE4 = 20,
  76. DOLBYVISION_PROFILE5 = 21,
  77. DOLBYVISION_PROFILE7 = 22,
  78. THEORAPROFILE_MIN = 23,
  79. THEORAPROFILE_ANY = THEORAPROFILE_MIN,
  80. THEORAPROFILE_MAX = THEORAPROFILE_ANY,
  81. AV1PROFILE_MIN = 24,
  82. AV1PROFILE_PROFILE_MAIN = AV1PROFILE_MIN,
  83. AV1PROFILE_PROFILE_HIGH = 25,
  84. AV1PROFILE_PROFILE_PRO = 26,
  85. AV1PROFILE_MAX = AV1PROFILE_PROFILE_PRO,
  86. DOLBYVISION_PROFILE8 = 27,
  87. DOLBYVISION_PROFILE9 = 28,
  88. HEVCPROFILE_EXT_MIN = 29,
  89. HEVCPROFILE_REXT = HEVCPROFILE_EXT_MIN,
  90. HEVCPROFILE_HIGH_THROUGHPUT = 30,
  91. HEVCPROFILE_MULTIVIEW_MAIN = 31,
  92. HEVCPROFILE_SCALABLE_MAIN = 32,
  93. HEVCPROFILE_3D_MAIN = 33,
  94. HEVCPROFILE_SCREEN_EXTENDED = 34,
  95. HEVCPROFILE_SCALABLE_REXT = 35,
  96. HEVCPROFILE_HIGH_THROUGHPUT_SCREEN_EXTENDED = 36,
  97. HEVCPROFILE_EXT_MAX = HEVCPROFILE_HIGH_THROUGHPUT_SCREEN_EXTENDED,
  98. VIDEO_CODEC_PROFILE_MAX = HEVCPROFILE_HIGH_THROUGHPUT_SCREEN_EXTENDED,
  99. };
  100. using VideoCodecLevel = uint32_t;
  101. constexpr VideoCodecLevel kNoVideoCodecLevel = 0;
  102. struct CodecProfileLevel {
  103. VideoCodec codec;
  104. VideoCodecProfile profile;
  105. VideoCodecLevel level;
  106. };
  107. std::string MEDIA_EXPORT GetCodecName(VideoCodec codec);
  108. std::string MEDIA_EXPORT GetProfileName(VideoCodecProfile profile);
  109. std::string MEDIA_EXPORT BuildH264MimeSuffix(VideoCodecProfile profile,
  110. uint8_t level);
  111. // ParseNewStyleVp9CodecID handles parsing of new style vp9 codec IDs per
  112. // proposed VP Codec ISO Media File Format Binding specification:
  113. // https://storage.googleapis.com/downloads.webmproject.org/docs/vp9/vp-codec-iso-media-file-format-binding-20160516-draft.pdf
  114. // ParseLegacyVp9CodecID handles parsing of legacy VP9 codec strings defined
  115. // for WebM.
  116. // TODO(kqyang): Consolidate the two functions once we address crbug.com/667834
  117. MEDIA_EXPORT bool ParseNewStyleVp9CodecID(const std::string& codec_id,
  118. VideoCodecProfile* profile,
  119. uint8_t* level_idc,
  120. VideoColorSpace* color_space);
  121. MEDIA_EXPORT bool ParseLegacyVp9CodecID(const std::string& codec_id,
  122. VideoCodecProfile* profile,
  123. uint8_t* level_idc);
  124. #if BUILDFLAG(ENABLE_AV1_DECODER)
  125. MEDIA_EXPORT bool ParseAv1CodecId(const std::string& codec_id,
  126. VideoCodecProfile* profile,
  127. uint8_t* level_idc,
  128. VideoColorSpace* color_space);
  129. #endif
  130. // Handle parsing AVC/H.264 codec ids as outlined in RFC 6381 and ISO-14496-10.
  131. MEDIA_EXPORT bool ParseAVCCodecId(const std::string& codec_id,
  132. VideoCodecProfile* profile,
  133. uint8_t* level_idc);
  134. #if BUILDFLAG(ENABLE_PLATFORM_HEVC)
  135. MEDIA_EXPORT bool ParseHEVCCodecId(const std::string& codec_id,
  136. VideoCodecProfile* profile,
  137. uint8_t* level_idc);
  138. #endif
  139. #if BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
  140. MEDIA_EXPORT bool ParseDolbyVisionCodecId(const std::string& codec_id,
  141. VideoCodecProfile* profile,
  142. uint8_t* level_id);
  143. #endif
  144. MEDIA_EXPORT void ParseCodec(const std::string& codec_id,
  145. VideoCodec& codec,
  146. VideoCodecProfile& profile,
  147. uint8_t& level,
  148. VideoColorSpace& color_space);
  149. MEDIA_EXPORT VideoCodec StringToVideoCodec(const std::string& codec_id);
  150. MEDIA_EXPORT VideoCodec
  151. VideoCodecProfileToVideoCodec(VideoCodecProfile profile);
  152. #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER)
  153. // Translate legacy avc1 codec ids (like avc1.66.30 or avc1.77.31) into a new
  154. // style standard avc1 codec ids like avc1.4D002F. If the input codec is not
  155. // recognized as a legacy codec id, then returns the input string unchanged.
  156. std::string TranslateLegacyAvc1CodecIds(const std::string& codec_id);
  157. #endif
  158. MEDIA_EXPORT std::ostream& operator<<(std::ostream& os,
  159. const VideoCodec& codec);
  160. } // namespace media
  161. #endif // MEDIA_BASE_VIDEO_CODECS_H_