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 #include "plugin/common/plugin_buffer.h" 22 #include "plugin/common/plugin_types.h" // NOLINT: used it 23 #include "data_stream.h" 24 25 namespace OHOS { 26 namespace Media { 27 namespace Plugin { 28 /** 29 * @brief Unified enumerates media source types. 30 * 31 * @since 1.0 32 * @version 1.0 33 */ 34 enum class SourceType : int32_t { 35 /** Local file path or network address */ 36 SOURCE_TYPE_URI = 0, 37 /** Local file descriptor */ 38 SOURCE_TYPE_FD, 39 /** Stream data */ 40 SOURCE_TYPE_STREAM, 41 }; 42 43 typedef struct PlayStrategy { 44 uint32_t width {0}; 45 uint32_t height {0}; 46 uint32_t duration {0}; 47 bool preferHDR {false}; 48 } PlayStrategy; 49 50 class MediaSource { 51 public: 52 /// Construct an a specified URI. 53 explicit MediaSource(std::string uri); 54 55 explicit MediaSource(std::shared_ptr<DataConsumer> dataStream); 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 72 void SetPlayStrategy(const std::shared_ptr<PlayStrategy>& playStrategy); 73 74 std::shared_ptr<PlayStrategy> GetPlayStrategy() const; 75 private: 76 std::string uri_ {}; 77 SourceType type_ {}; 78 std::map<std::string, std::string> header_ {}; 79 std::shared_ptr<DataConsumer> dataConsumer_ {}; 80 }; 81 } // namespace Plugin 82 } // namespace Media 83 } // namespace OHOS 84 #endif