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 #ifndef OHOS_CAMERA_DPS_READER_H 16 #define OHOS_CAMERA_DPS_READER_H 17 18 #include "basic_definitions.h" 19 #include "demuxer.h" 20 #include "dp_log.h" 21 #include "track.h" 22 #include "media_format.h" 23 24 namespace OHOS { 25 namespace CameraStandard { 26 namespace DeferredProcessing { 27 using namespace MediaAVCodec; 28 class Reader { 29 public: 30 Reader() = default; 31 virtual ~Reader(); 32 33 MediaManagerError Create(int32_t inputFd); 34 MediaManagerError Read(Media::Plugins::MediaType trackType, std::shared_ptr<AVBuffer>& sample); 35 MediaManagerError GetMediaInfo(std::shared_ptr<MediaInfo>& mediaInfo); 36 MediaManagerError Reset(int64_t resetPts); 37 GetTracks()38 inline const std::map<Media::Plugins::MediaType, std::shared_ptr<Track>>& GetTracks() 39 { 40 return tracks_; 41 }; 42 43 private: 44 MediaManagerError GetSourceFormat(); 45 MediaManagerError GetUserMeta(); 46 void GetSourceMediaInfo(std::shared_ptr<MediaInfo>& mediaInfo) const; 47 MediaManagerError GetTrackMediaInfo(const TrackFormat& trackFormat, std::shared_ptr<MediaInfo>& mediaInfo) const; 48 MediaManagerError InitTracksAndDemuxer(); 49 static int32_t FixFPS(const double fps); 50 51 template <typename T> CheckAndGetValue(const std::shared_ptr<Format> & format,const std::string_view & key,T & value)52 bool CheckAndGetValue(const std::shared_ptr<Format>& format, const std::string_view& key, T& value) const 53 { 54 bool ret = false; 55 if constexpr (std::is_same_v<T, int32_t>) { 56 ret = format->GetIntValue(key, value); 57 } else if constexpr (std::is_same_v<T, float>) { 58 ret = format->GetFloatValue(key, value); 59 } else if constexpr (std::is_same_v<T, double>) { 60 ret = format->GetDoubleValue(key, value); 61 } else if constexpr (std::is_same_v<T, int64_t>) { 62 ret = format->GetLongValue(key, value); 63 } else if constexpr (std::is_same_v<T, std::string>) { 64 ret = format->GetStringValue(key, value); 65 } 66 return ret; 67 } 68 69 private: 70 std::shared_ptr<AVSource> source_ {nullptr}; 71 std::shared_ptr<Format> sourceFormat_ {nullptr}; 72 std::shared_ptr<Format> userFormat_ {nullptr}; 73 std::shared_ptr<Demuxer> inputDemuxer_ {nullptr}; 74 int32_t trackCount_ {0}; 75 std::map<Media::Plugins::MediaType, std::shared_ptr<Track>> tracks_ {}; 76 }; 77 } // namespace DeferredProcessing 78 } // namespace CameraStandard 79 } // namespace OHOS 80 #endif // OHOS_CAMERA_DPS_READER_H