stream_parser_factory.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (c) 2013 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_FILTERS_STREAM_PARSER_FACTORY_H_
  5. #define MEDIA_FILTERS_STREAM_PARSER_FACTORY_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/containers/span.h"
  10. #include "media/base/media_export.h"
  11. #include "media/base/media_log.h"
  12. #include "media/base/mime_util.h"
  13. namespace media {
  14. class AudioDecoderConfig;
  15. class StreamParser;
  16. class VideoDecoderConfig;
  17. class MEDIA_EXPORT StreamParserFactory {
  18. public:
  19. // Checks to see if the specified |type| and |codecs| list are supported.
  20. // Returns one of the following SupportsType values:
  21. // kNotSupported indicates definitive lack of support.
  22. // kSupported indicates the mime type is supported, any non-empty codecs
  23. // requirement is met for the mime type, and all of the passed codecs are
  24. // supported for the mime type.
  25. // kMaybeSupported indicates the mime type is supported, but the mime type
  26. // requires a codecs parameter that is missing.
  27. static SupportsType IsTypeSupported(const std::string& type,
  28. base::span<const std::string> codecs);
  29. // Creates a new StreamParser object if the specified |type| and |codecs| list
  30. // are supported. |media_log| can be used to report errors if there is
  31. // something wrong with |type| or the codec IDs in |codecs|.
  32. // Returns a new StreamParser object if |type| and all codecs listed in
  33. // |codecs| are supported.
  34. // Returns NULL otherwise.
  35. // The |audio_config| and |video_config| overloads behave similarly, except
  36. // the caller must provide a valid, supported decoder config; those overloads'
  37. // usage indicates that we intend to buffer WebCodecs encoded audio or video
  38. // chunks with this parser's ProcessChunks() method. Note that
  39. // these overloads do not check support, unlike the |type| and |codecs|
  40. // version. Support checking for WebCodecs-originated decoder configs could be
  41. // async, and should be done by the caller if necessary as part of the decoder
  42. // config creation rather than relying upon parser creation to do this
  43. // potentially expensive step (this step is typically done in a synchronous
  44. // API call by the web app, such as addSourceBuffer().) Like |type| and
  45. // |codecs| versions, basic IsValidConfig() is done on configs emitted from
  46. // the parser. Failing that catching an unsupported config, eventual pipeline
  47. // error should occur for unsupported or invalid decoder configs during
  48. // attempted decode.
  49. static std::unique_ptr<StreamParser> Create(
  50. const std::string& type,
  51. base::span<const std::string> codecs,
  52. MediaLog* media_log);
  53. static std::unique_ptr<StreamParser> Create(
  54. std::unique_ptr<AudioDecoderConfig> audio_config);
  55. static std::unique_ptr<StreamParser> Create(
  56. std::unique_ptr<VideoDecoderConfig> video_config);
  57. };
  58. } // namespace media
  59. #endif // MEDIA_FILTERS_STREAM_PARSER_FACTORY_H_