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_buffer.h" 22 #include "plugin_types.h" // NOLINT: used it 23 24 namespace OHOS { 25 namespace Media { 26 namespace Plugin { 27 /** 28 * @brief Unified enumerates media source types. 29 * 30 * @since 1.0 31 * @version 1.0 32 */ 33 enum class SourceType : int32_t { 34 /** Local file path or network address */ 35 SOURCE_TYPE_URI = 0, 36 /** Local file descriptor */ 37 SOURCE_TYPE_FD, 38 /** Stream data */ 39 SOURCE_TYPE_STREAM, 40 }; 41 42 class DataStream { 43 /** 44 * @brief Read data from data source. 45 * 46 * The function is valid only after RUNNING state. 47 * 48 * @param buffer Storage of the read data 49 * @param expectedLen Expected data size to be read 50 * @return Execution status return 51 * @retval OK: Plugin reset succeeded. 52 * @retval ERROR_NOT_ENOUGH_DATA: Data not enough 53 * @retval END_OF_STREAM: End of stream 54 */ 55 virtual Status Read(std::shared_ptr<Buffer>& buffer, size_t expectedLen) = 0; 56 57 /** 58 * @brief Get data source size. 59 * 60 * The function is valid only after INITIALIZED state. 61 * 62 * @param size data source size. 63 * @return Execution status return. 64 * @retval OK: Plugin reset succeeded. 65 */ 66 virtual Status GetSize(size_t& size) = 0; 67 }; 68 69 class MediaSource { 70 public: 71 /// Construct an a specified URI. 72 explicit MediaSource(std::string uri); 73 74 explicit MediaSource(std::shared_ptr<DataStream> dataStream); 75 76 MediaSource(std::string uri, std::map<std::string, std::string> header); 77 78 /// Destructor 79 virtual ~MediaSource() = default; 80 81 /// Obtains the source type. 82 SourceType GetSourceType() const; 83 84 /// Obtains the media source URI. 85 const std::string &GetSourceUri() const; 86 87 const std::map<std::string, std::string> &GetSourceHeader() const; 88 89 std::shared_ptr<DataStream> GetDataStream() const; 90 91 private: 92 std::string uri_ {}; 93 SourceType type_ {}; 94 std::map<std::string, std::string> header_ {}; 95 std::shared_ptr<DataStream> dataStream_ {}; 96 }; 97 } // namespace Plugin 98 } // namespace Media 99 } // namespace OHOS 100 #endif