Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 _NDK_IMAGE_PRIV_H |
| 18 | #define _NDK_IMAGE_PRIV_H |
| 19 | |
| 20 | #include <inttypes.h> |
| 21 | #include <utils/Log.h> |
| 22 | #include <utils/StrongPointer.h> |
| 23 | |
Jiwen 'Steve' Cai | 2f1a473 | 2017-02-04 17:31:55 -0800 | [diff] [blame] | 24 | #include <gui/BufferItem.h> |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 25 | #include <gui/CpuConsumer.h> |
| 26 | |
| 27 | #include "NdkImageReaderPriv.h" |
Colin Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 28 | #include <media/NdkImage.h> |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 29 | |
| 30 | |
| 31 | using namespace android; |
| 32 | |
Dichen Zhang | ae54672 | 2020-02-19 14:41:52 -0800 | [diff] [blame] | 33 | // Formats not listed in the public API, but still available to AImageReader |
| 34 | enum AIMAGE_PRIVATE_FORMATS { |
| 35 | /** |
| 36 | * Unprocessed implementation-dependent raw |
| 37 | * depth measurements, opaque with 16 bit |
| 38 | * samples. |
| 39 | * |
| 40 | */ |
| 41 | |
| 42 | AIMAGE_FORMAT_RAW_DEPTH = 0x1002, |
| 43 | }; |
| 44 | |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 45 | // TODO: this only supports ImageReader |
| 46 | struct AImage { |
Jiwen 'Steve' Cai | e31bc87 | 2017-04-21 17:13:18 -0700 | [diff] [blame] | 47 | AImage(AImageReader* reader, int32_t format, uint64_t usage, BufferItem* buffer, |
| 48 | int64_t timestamp, int32_t width, int32_t height, int32_t numPlanes); |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 49 | |
| 50 | // free all resources while keeping object alive. Caller must obtain reader lock |
Jiwen 'Steve' Cai | e168996 | 2017-02-20 16:59:05 -0800 | [diff] [blame] | 51 | void close() { close(-1); } |
| 52 | void close(int releaseFenceFd); |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 53 | |
| 54 | // Remove from object memory. Must be called after close |
| 55 | void free(); |
| 56 | |
| 57 | bool isClosed() const ; |
| 58 | |
| 59 | // only For AImage to grab reader lock |
| 60 | // Always grab reader lock before grabbing image lock |
| 61 | void lockReader() const; |
| 62 | void unlockReader() const; |
| 63 | |
| 64 | media_status_t getWidth(/*out*/int32_t* width) const; |
| 65 | media_status_t getHeight(/*out*/int32_t* height) const; |
| 66 | media_status_t getFormat(/*out*/int32_t* format) const; |
| 67 | media_status_t getNumPlanes(/*out*/int32_t* numPlanes) const; |
| 68 | media_status_t getTimestamp(/*out*/int64_t* timestamp) const; |
| 69 | |
Jiwen 'Steve' Cai | 2f1a473 | 2017-02-04 17:31:55 -0800 | [diff] [blame] | 70 | media_status_t lockImage(); |
| 71 | media_status_t unlockImageIfLocked(/*out*/int* fenceFd); |
| 72 | |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 73 | media_status_t getPlanePixelStride(int planeIdx, /*out*/int32_t* pixelStride) const; |
| 74 | media_status_t getPlaneRowStride(int planeIdx, /*out*/int32_t* rowStride) const; |
| 75 | media_status_t getPlaneData(int planeIdx,/*out*/uint8_t** data, /*out*/int* dataLength) const; |
Jiwen 'Steve' Cai | e168996 | 2017-02-20 16:59:05 -0800 | [diff] [blame] | 76 | media_status_t getHardwareBuffer(/*out*/AHardwareBuffer** buffer) const; |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 77 | |
| 78 | private: |
| 79 | // AImage should be deleted through free() API. |
| 80 | ~AImage(); |
| 81 | |
| 82 | friend struct AImageReader; // for reader to access mBuffer |
| 83 | |
| 84 | uint32_t getJpegSize() const; |
| 85 | |
| 86 | // When reader is close, AImage will only accept close API call |
Jayant Chowdhary | 9e0302f | 2019-07-16 11:04:06 -0700 | [diff] [blame] | 87 | const sp<AImageReader> mReader; |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 88 | const int32_t mFormat; |
Jiwen 'Steve' Cai | e31bc87 | 2017-04-21 17:13:18 -0700 | [diff] [blame] | 89 | const uint64_t mUsage; // AHARDWAREBUFFER_USAGE_* flags. |
Jiwen 'Steve' Cai | 2f1a473 | 2017-02-04 17:31:55 -0800 | [diff] [blame] | 90 | BufferItem* mBuffer; |
| 91 | std::unique_ptr<CpuConsumer::LockedBuffer> mLockedBuffer; |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 92 | const int64_t mTimestamp; |
| 93 | const int32_t mWidth; |
| 94 | const int32_t mHeight; |
| 95 | const int32_t mNumPlanes; |
| 96 | bool mIsClosed = false; |
| 97 | mutable Mutex mLock; |
| 98 | }; |
| 99 | |
| 100 | #endif // _NDK_IMAGE_PRIV_H |