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