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