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 // kGridWidth and kGridHeight should be 2^n 42 static const auto kGridWidth = 512; 43 static const auto kGridHeight = 512; 44 private: 45 struct SizePairHash { operatorSizePairHash46 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); 65 bool getHevcCodecDetails(sp<IMediaCodecList> codecsList, const char* mime); 66 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; 71 AString mHevcName; 72 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 81