blob: a65be9c394909e2b94e5baecd79ba8831905cb75 [file] [log] [blame]
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001/*
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
28namespace android {
29namespace camera3 {
30
31class HeicEncoderInfoManager {
32public:
33 static HeicEncoderInfoManager& getInstance() {
34 static HeicEncoderInfoManager instance;
35 return instance;
36 }
37
38 bool isSizeSupported(int32_t width, int32_t height,
Chong Zhang688abaa2019-05-17 16:32:23 -070039 bool* useHeic, bool* useGrid, int64_t* stall, AString* hevcName) const;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080040
Susmitha Gummallae911f2e2020-11-23 09:57:03 -080041 // kGridWidth and kGridHeight should be 2^n
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080042 static const auto kGridWidth = 512;
43 static const auto kGridHeight = 512;
44private:
45 struct SizePairHash {
46 std::size_t operator () (const std::pair<int32_t,int32_t> &p) const {
47 return p.first * 31 + p.second;
48 }
49 };
50
51 typedef std::unordered_map<std::pair<int32_t, int32_t>,
52 std::pair<int32_t, int32_t>, SizePairHash> FrameRateMaps;
53
54 HeicEncoderInfoManager();
55 virtual ~HeicEncoderInfoManager();
56
57 status_t initialize();
58 status_t getFrameRateMaps(sp<AMessage> details, FrameRateMaps* maps);
59 status_t getCodecSizeRange(const char* codecName, sp<AMessage> details,
60 std::pair<int32_t, int32_t>* minSize, std::pair<int32_t, int32_t>* maxSize,
61 FrameRateMaps* frameRateMaps);
62 FrameRateMaps::const_iterator findClosestSize(const FrameRateMaps& maps,
63 int32_t width, int32_t height) const;
64 sp<AMessage> getCodecDetails(sp<IMediaCodecList> codecsList, const char* name);
Chong Zhang688abaa2019-05-17 16:32:23 -070065 bool getHevcCodecDetails(sp<IMediaCodecList> codecsList, const char* mime);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080066
67 bool mIsInited;
68 std::pair<int32_t, int32_t> mMinSizeHeic, mMaxSizeHeic;
69 std::pair<int32_t, int32_t> mMinSizeHevc, mMaxSizeHevc;
70 bool mHasHEVC, mHasHEIC;
Chong Zhang688abaa2019-05-17 16:32:23 -070071 AString mHevcName;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080072 FrameRateMaps mHeicFrameRateMaps, mHevcFrameRateMaps;
73 bool mDisableGrid;
74
75};
76
77} // namespace camera3
78} // namespace android
79
80#endif // ANDROID_SERVERS_CAMERA_HEICENCODER_INFO_MANAGER_H