• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HISTREAMER_PLUGIN_MEDIA_SOURCE_H
17 #define HISTREAMER_PLUGIN_MEDIA_SOURCE_H
18 
19 #include <map>
20 #include <memory>
21 #ifndef OHOS_LITE
22 #include "media_data_source.h"
23 #endif
24 #include "plugin/common/plugin_buffer.h"
25 #include "plugin/common/plugin_types.h" // NOLINT: used it
26 #include "data_stream.h"
27 
28 namespace OHOS {
29 namespace Media {
30 namespace Plugin {
31 /**
32  * @brief Unified enumerates media source types.
33  *
34  * @since 1.0
35  * @version 1.0
36  */
37 enum class SourceType : int32_t {
38     /** Local file path or network address */
39     SOURCE_TYPE_URI = 0,
40     /** Local file descriptor */
41     SOURCE_TYPE_FD,
42     /** Stream data */
43     SOURCE_TYPE_STREAM,
44 };
45 
46 class MediaSource {
47 public:
48     /// Construct an a specified URI.
49     explicit MediaSource(std::string uri);
50 
51     explicit MediaSource(std::shared_ptr<DataConsumer> dataStream);
52 
53 #ifndef OHOS_LITE
54     explicit MediaSource(std::shared_ptr<IMediaDataSource> dataSrc);
55 #endif
56 
57     MediaSource(std::string uri, std::map<std::string, std::string> header);
58 
59     /// Destructor
60     virtual ~MediaSource() = default;
61 
62     /// Obtains the source type.
63     SourceType GetSourceType() const;
64 
65     /// Obtains the media source URI.
66     const std::string &GetSourceUri() const;
67 
68     const std::map<std::string, std::string> &GetSourceHeader() const;
69 
70     std::shared_ptr<DataConsumer> GetDataConsumer() const;
71 #ifndef OHOS_LITE
72     std::shared_ptr<IMediaDataSource> GetDataSrc() const;
73 #endif
74 private:
75     std::string uri_ {};
76     SourceType type_ {};
77     std::map<std::string, std::string> header_ {};
78     std::shared_ptr<DataConsumer> dataConsumer_ {};
79 #ifndef OHOS_LITE
80     std::shared_ptr<IMediaDataSource> dataSrc_ {};
81 #endif
82 };
83 } // namespace Plugin
84 } // namespace Media
85 } // namespace OHOS
86 #endif