1 /* 2 * Copyright (c) 2023-2023 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_PLUGINS_MEDIA_SOURCE_H 17 #define HISTREAMER_PLUGINS_MEDIA_SOURCE_H 18 19 #include <map> 20 #include <memory> 21 #ifndef OHOS_LITE 22 #include "common/media_data_source.h" 23 #endif 24 #include "meta/media_types.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace Plugins { 29 /// End of Stream Buffer Flag 30 #define BUFFER_FLAG_EOS 0x00000001 31 /// Video Key Frame Flag 32 #define BUFFER_FLAG_KEY_FRAME 0x00000002 33 /** 34 * @brief Unified enumerates media source types. 35 * 36 * @since 1.0 37 * @version 1.0 38 */ 39 enum class SourceType : int32_t { 40 /** Local file path or network address */ 41 SOURCE_TYPE_URI = 0, 42 /** Local file descriptor */ 43 SOURCE_TYPE_FD, 44 /** Stream data */ 45 SOURCE_TYPE_STREAM, 46 }; 47 48 typedef struct PlayStrategy { 49 uint32_t width {0}; 50 uint32_t height {0}; 51 uint32_t duration {0}; 52 bool preferHDR {false}; 53 std::string audioLanguage {""}; 54 std::string subtitleLanguage {""}; 55 } PlayStrategy; 56 57 class AVMimeTypes { 58 public: 59 static constexpr std::string_view APPLICATION_M3U8 = "application/m3u8"; 60 }; 61 62 typedef struct DownloadInfo { 63 int32_t avgDownloadRate {0}; 64 int32_t avgDownloadSpeed {0}; 65 uint64_t totalDownLoadBits {0}; 66 bool isTimeOut {false}; 67 } DownloadInfo; 68 69 typedef struct PlaybackInfo { 70 std::string serverIpAddress {}; 71 int64_t averageDownloadRate = 0; 72 int64_t downloadRate = 0; 73 bool isDownloading = false; 74 int64_t bufferDuration = 0; 75 } PlaybackInfo; 76 77 class MediaSource { 78 public: 79 /// Construct an a specified URI. 80 explicit MediaSource(std::string uri); 81 82 #ifndef OHOS_LITE 83 explicit MediaSource(std::shared_ptr<IMediaDataSource> dataSrc); 84 #endif 85 86 MediaSource(std::string uri, std::map<std::string, std::string> header); 87 88 /// Destructor 89 virtual ~MediaSource() = default; 90 91 /// Obtains the source type. 92 SourceType GetSourceType() const; 93 94 /// Obtains the media source URI. 95 const std::string &GetSourceUri() const; 96 97 const std::map<std::string, std::string> &GetSourceHeader() const; 98 99 void SetPlayStrategy(const std::shared_ptr<PlayStrategy>& playStrategy); 100 101 std::shared_ptr<PlayStrategy> GetPlayStrategy() const; 102 103 void SetMimeType(const std::string& mimeType); 104 105 std::string GetMimeType() const; 106 107 void SetAppUid(int32_t appUid); 108 109 int32_t GetAppUid(); 110 111 //std::shared_ptr<DataConsumer> GetDataConsumer() const; 112 #ifndef OHOS_LITE 113 std::shared_ptr<IMediaDataSource> GetDataSrc() const; 114 #endif 115 private: 116 std::string uri_ {}; 117 std::string mimeType_ {}; 118 SourceType type_ {}; 119 std::map<std::string, std::string> header_ {}; 120 std::shared_ptr<PlayStrategy> playStrategy_ {}; 121 int32_t appUid_ {-1}; 122 //std::shared_ptr<DataConsumer> dataConsumer_ {}; 123 #ifndef OHOS_LITE 124 std::shared_ptr<IMediaDataSource> dataSrc_ {}; 125 #endif 126 }; 127 } // namespace Plugins 128 } // namespace Media 129 } // namespace OHOS 130 #endif // HISTREAMER_PLUGINS_MEDIA_SOURCE_H