1 /* 2 * Copyright (C) 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 MEDIA_AVCODEC_AVSOURCE_H 17 #define MEDIA_AVCODEC_AVSOURCE_H 18 19 #include <vector> 20 #include <memory> 21 #include <string> 22 #include "meta/format.h" 23 #include "media_demuxer.h" 24 25 namespace OHOS { 26 namespace MediaAVCodec { 27 class AVSource { 28 public: 29 virtual ~AVSource() = default; 30 31 /** 32 * @brief Get the format info of source. 33 * @param format The Format handle pointer to get format info. 34 * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. 35 * @since 4.0 36 */ 37 virtual int32_t GetSourceFormat(OHOS::Media::Format &format) = 0; 38 39 /** 40 * @brief Gets the parameters of the source. 41 * @param format The Format handle pointer to get format info. 42 * @param trackIndex The track index to get format. 43 * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. 44 * @since 4.0 45 */ 46 virtual int32_t GetTrackFormat(OHOS::Media::Format &format, uint32_t trackIndex) = 0; 47 48 /** 49 * @brief Gets the user meta for media. 50 * @param format The Format handle pointer to get format info. 51 * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. 52 * @since 5.0 53 */ 54 virtual int32_t GetUserMeta(OHOS::Media::Format &format) = 0; 55 56 std::string sourceUri; 57 std::shared_ptr<Media::MediaDemuxer> demuxerEngine = nullptr; 58 }; 59 60 class __attribute__((visibility("default"))) AVSourceFactory { 61 public: 62 #ifdef UNSUPPORT_SOURCE CreateWithURI(const std::string & uri)63 static std::shared_ptr<AVSource> CreateWithURI(const std::string &uri) 64 { 65 (void)uri; 66 return nullptr; 67 } 68 CreateWithFD(int32_t fd,int64_t offset,int64_t size)69 static std::shared_ptr<AVSource> CreateWithFD(int32_t fd, int64_t offset, int64_t size) 70 { 71 (void)uri; 72 return nullptr; 73 } 74 CreateWithDataSource(const std::shared_ptr<Media::IMediaDataSource> & dataSource)75 static std::shared_ptr<AVSource> CreateWithDataSource(const std::shared_ptr<Media::IMediaDataSource> &dataSource) 76 { 77 (void)uri; 78 return nullptr; 79 } 80 81 #else 82 /** 83 * @brief Instantiate the preferred source of the uri. 84 * @param uri The file's uri. 85 * @return Returns the preferred source. 86 * @since 4.0 87 */ 88 static std::shared_ptr<AVSource> CreateWithURI(const std::string &uri); 89 90 /** 91 * @brief Instantiate the preferred source of the fd. 92 * @param fd The fileDescriptor data source. 93 * @param offset The offset into the file to start reading. 94 * @param size the length in bytes to read. 95 * @return Returns the preferred source. 96 * @since 4.0 97 */ 98 static std::shared_ptr<AVSource> CreateWithFD(int32_t fd, int64_t offset, int64_t size); 99 100 static std::shared_ptr<AVSource> CreateWithDataSource(const std::shared_ptr<Media::IMediaDataSource> &dataSource); 101 102 #endif 103 private: 104 AVSourceFactory() = default; 105 ~AVSourceFactory() = default; 106 }; 107 } // namespace MediaAVCodec 108 } // namespace OHOS 109 #endif // MEDIA_AVCODEC_AVSOURCE_H 110 111