• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_SERVERS_CAMERA_HEICENCODER_INFO_MANAGER_H
18 #define ANDROID_SERVERS_CAMERA_HEICENCODER_INFO_MANAGER_H
19 
20 #include <unordered_map>
21 #include <utility>
22 #include <utils/Errors.h>
23 #include <utils/StrongPointer.h>
24 
25 #include <media/IMediaCodecList.h>
26 #include <media/stagefright/foundation/AMessage.h>
27 
28 namespace android {
29 namespace camera3 {
30 
31 class HeicEncoderInfoManager {
32 public:
getInstance()33     static HeicEncoderInfoManager& getInstance() {
34         static HeicEncoderInfoManager instance;
35         return instance;
36     }
37 
38     bool isSizeSupported(int32_t width, int32_t height,
39             bool* useHeic, bool* useGrid, int64_t* stall, AString* hevcName) const;
40 
41     static const auto kGridWidth = 512;
42     static const auto kGridHeight = 512;
43 private:
44     struct SizePairHash {
operatorSizePairHash45         std::size_t operator () (const std::pair<int32_t,int32_t> &p) const {
46             return p.first * 31 + p.second;
47         }
48     };
49 
50     typedef std::unordered_map<std::pair<int32_t, int32_t>,
51             std::pair<int32_t, int32_t>, SizePairHash> FrameRateMaps;
52 
53     HeicEncoderInfoManager();
54     virtual ~HeicEncoderInfoManager();
55 
56     status_t initialize();
57     status_t getFrameRateMaps(sp<AMessage> details, FrameRateMaps* maps);
58     status_t getCodecSizeRange(const char* codecName, sp<AMessage> details,
59             std::pair<int32_t, int32_t>* minSize, std::pair<int32_t, int32_t>* maxSize,
60             FrameRateMaps* frameRateMaps);
61     FrameRateMaps::const_iterator findClosestSize(const FrameRateMaps& maps,
62             int32_t width, int32_t height) const;
63     sp<AMessage> getCodecDetails(sp<IMediaCodecList> codecsList, const char* name);
64     bool getHevcCodecDetails(sp<IMediaCodecList> codecsList, const char* mime);
65 
66     bool mIsInited;
67     std::pair<int32_t, int32_t> mMinSizeHeic, mMaxSizeHeic;
68     std::pair<int32_t, int32_t> mMinSizeHevc, mMaxSizeHevc;
69     bool mHasHEVC, mHasHEIC;
70     AString mHevcName;
71     FrameRateMaps mHeicFrameRateMaps, mHevcFrameRateMaps;
72     bool mDisableGrid;
73 
74 };
75 
76 } // namespace camera3
77 } // namespace android
78 
79 #endif // ANDROID_SERVERS_CAMERA_HEICENCODER_INFO_MANAGER_H
80