blob: fb0b9140a9a16559fb76832b0682f3acd990dabb [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,
39 bool* useHeic, bool* useGrid, int64_t* stall) const;
40
41 static const auto kGridWidth = 512;
42 static const auto kGridHeight = 512;
43private:
44 struct SizePairHash {
45 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
65 bool mIsInited;
66 std::pair<int32_t, int32_t> mMinSizeHeic, mMaxSizeHeic;
67 std::pair<int32_t, int32_t> mMinSizeHevc, mMaxSizeHevc;
68 bool mHasHEVC, mHasHEIC;
69 FrameRateMaps mHeicFrameRateMaps, mHevcFrameRateMaps;
70 bool mDisableGrid;
71
72};
73
74} // namespace camera3
75} // namespace android
76
77#endif // ANDROID_SERVERS_CAMERA_HEICENCODER_INFO_MANAGER_H