mime_util.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_MIME_UTIL_H_
  5. #define MEDIA_BASE_MIME_UTIL_H_
  6. #include <string>
  7. #include <vector>
  8. #include "media/base/audio_codecs.h"
  9. #include "media/base/media_export.h"
  10. #include "media/base/video_codecs.h"
  11. namespace media {
  12. // Check to see if a particular MIME type is in the list of
  13. // supported/recognized MIME types.
  14. MEDIA_EXPORT bool IsSupportedMediaMimeType(const std::string& mime_type);
  15. // Splits |codecs| separated by comma into |codecs_out|. Codecs in |codecs| may
  16. // or may not be quoted. For example, "\"aaa.b.c,dd.eee\"" and "aaa.b.c,dd.eee"
  17. // will both be split into {"aaa.b.c", "dd.eee"}.
  18. // See http://www.ietf.org/rfc/rfc4281.txt.
  19. MEDIA_EXPORT void SplitCodecs(const std::string& codecs,
  20. std::vector<std::string>* codecs_out);
  21. // Strips the profile and level info from |codecs| in place. For example,
  22. // {"aaa.b.c", "dd.eee"} will be strip into {"aaa", "dd"}.
  23. // See http://www.ietf.org/rfc/rfc4281.txt.
  24. MEDIA_EXPORT void StripCodecs(std::vector<std::string>* codecs);
  25. // Returns true if successfully parsed the given |mime_type| and |codec_id|,
  26. // setting |out_*| arguments to the parsed video codec, profile, and level.
  27. // Empty string |mime_type| indicates "no mime type". |mime_type| should be
  28. // provided whenever available for parsing and validation in combination with
  29. // |codec_id|. |out_is_ambiguous| will be true when the codec string is
  30. // incomplete such that some guessing was required to decide the codec, profile,
  31. // or level.
  32. //
  33. // Returns false if parsing fails (invalid string, or unrecognized video codec),
  34. // in which case values for |out_*| arguments are undefined.
  35. MEDIA_EXPORT bool ParseVideoCodecString(const std::string& mime_type,
  36. const std::string& codec_id,
  37. bool* out_is_ambiguous,
  38. VideoCodec* out_codec,
  39. VideoCodecProfile* out_profile,
  40. uint8_t* out_level,
  41. VideoColorSpace* out_colorspace);
  42. // Returns true if successfully parsed the given |mime_type| and |codec_id|,
  43. // setting |out_audio_codec| to found codec. Empty string |mime_type| indicates
  44. // "no mime type". |mime_type| should be provided whenever available for parsing
  45. // and validation in combination with |codec_id|. |out_is_ambiguous| will be
  46. // true when the codec string is incomplete such that some guessing was required
  47. // to decide the codec.
  48. //
  49. // Returns false if parsing fails (invalid string, or unrecognized audio codec),
  50. // in which case values for |out_*| arguments are undefined.
  51. MEDIA_EXPORT bool ParseAudioCodecString(const std::string& mime_type,
  52. const std::string& codec_id,
  53. bool* out_is_ambiguous,
  54. AudioCodec* out_codec);
  55. // Indicates that the MIME type and (possible codec string) are supported.
  56. enum class SupportsType {
  57. // The given MIME type and codec combination is not supported.
  58. kNotSupported,
  59. // The given MIME type and codec combination is supported.
  60. kSupported,
  61. // There's not enough information to determine if the given MIME type and
  62. // codec combination can be rendered or not before actually trying to play it.
  63. kMaybeSupported
  64. };
  65. // Checks the |mime_type| and |codecs| against the MIME types known to support
  66. // only a particular subset of codecs.
  67. // * Returns kSupported if the |mime_type| is supported and all the codecs
  68. // within the |codecs| are supported for the |mime_type|.
  69. // * Returns kMaybeSupported if the |mime_type| is supported and is known to
  70. // support only a subset of codecs, but |codecs| was empty. Also returned if
  71. // all the codecs in |codecs| are supported, but additional codec parameters
  72. // were supplied (such as profile) for which the support cannot be decided.
  73. // * Returns kNotSupported if either the |mime_type| is not supported or the
  74. // |mime_type| is supported but at least one of the codecs within |codecs| is
  75. // not supported for the |mime_type|.
  76. MEDIA_EXPORT SupportsType
  77. IsSupportedMediaFormat(const std::string& mime_type,
  78. const std::vector<std::string>& codecs);
  79. // Similar to the above, but for encrypted formats.
  80. MEDIA_EXPORT SupportsType
  81. IsSupportedEncryptedMediaFormat(const std::string& mime_type,
  82. const std::vector<std::string>& codecs);
  83. } // namespace media
  84. #endif // MEDIA_BASE_MIME_UTIL_H_