• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_info.h"
23 #include "media_format.h"
24 
25 namespace OHOS {
26 namespace CameraStandard {
27 namespace DeferredProcessing {
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     Media::Plugins::VideoEncodeBitrateMode MapVideoBitrateMode(const std::string& modeName) const;
51 
52     template <typename T>
CheckAndGetValue(const std::shared_ptr<Format> & format,const std::string_view & key,T & value)53     bool CheckAndGetValue(const std::shared_ptr<Format>& format, const std::string_view& key, T& value) const
54     {
55         bool ret = false;
56         if (format == nullptr) {
57             return ret;
58         }
59 
60         if constexpr (std::is_same_v<T, int32_t>) {
61             ret = format->GetIntValue(key, value);
62         } else if constexpr (std::is_same_v<T, float>) {
63             ret = format->GetFloatValue(key, value);
64         } else if constexpr (std::is_same_v<T, double>) {
65             ret = format->GetDoubleValue(key, value);
66         } else if constexpr (std::is_same_v<T, int64_t>) {
67             ret = format->GetLongValue(key, value);
68         } else if constexpr (std::is_same_v<T, std::string>) {
69             ret = format->GetStringValue(key, value);
70         }
71         return ret;
72     }
73 
74 private:
75     std::shared_ptr<AVSource> source_ {nullptr};
76     std::shared_ptr<Format> sourceFormat_ {nullptr};
77     std::shared_ptr<Format> userFormat_ {nullptr};
78     std::shared_ptr<Demuxer> inputDemuxer_ {nullptr};
79     int32_t trackCount_ {0};
80     std::map<Media::Plugins::MediaType, std::shared_ptr<Track>> tracks_ {};
81 };
82 } // namespace DeferredProcessing
83 } // namespace CameraStandard
84 } // namespace OHOS
85 #endif // OHOS_CAMERA_DPS_READER_H