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 24 #include <gui/BufferItem.h> 25 #include <gui/CpuConsumer.h> 26 27 #include "NdkImageReaderPriv.h" 28 #include <media/NdkImage.h> 29 30 31 using namespace android; 32 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 /** 45 * Device specific 10 bits depth RAW image format. 46 * 47 * <p>Unprocessed implementation-dependent raw depth measurements, opaque with 10 bit samples 48 * and device specific bit layout.</p> 49 */ 50 AIMAGE_FORMAT_RAW_DEPTH10 = 0x1003, 51 }; 52 53 // TODO: this only supports ImageReader 54 struct AImage { 55 AImage(AImageReader* reader, int32_t format, uint64_t usage, BufferItem* buffer, 56 int64_t timestamp, int32_t width, int32_t height, int32_t numPlanes); 57 58 // free all resources while keeping object alive. Caller must obtain reader lock closeAImage59 void close() { close(-1); } 60 void close(int releaseFenceFd); 61 62 // Remove from object memory. Must be called after close 63 void free(); 64 65 bool isClosed() const ; 66 67 // only For AImage to grab reader lock 68 // Always grab reader lock before grabbing image lock 69 void lockReader() const; 70 void unlockReader() const; 71 72 media_status_t getWidth(/*out*/int32_t* width) const; 73 media_status_t getHeight(/*out*/int32_t* height) const; 74 media_status_t getFormat(/*out*/int32_t* format) const; 75 media_status_t getNumPlanes(/*out*/int32_t* numPlanes) const; 76 media_status_t getTimestamp(/*out*/int64_t* timestamp) const; 77 78 media_status_t lockImage(); 79 media_status_t unlockImageIfLocked(/*out*/int* fenceFd); 80 81 media_status_t getPlanePixelStride(int planeIdx, /*out*/int32_t* pixelStride) const; 82 media_status_t getPlaneRowStride(int planeIdx, /*out*/int32_t* rowStride) const; 83 media_status_t getPlaneData(int planeIdx,/*out*/uint8_t** data, /*out*/int* dataLength) const; 84 media_status_t getHardwareBuffer(/*out*/AHardwareBuffer** buffer) const; 85 media_status_t getDataSpace(/*out*/android_dataspace* dataSpace) const; 86 87 private: 88 // AImage should be deleted through free() API. 89 ~AImage(); 90 91 friend struct AImageReader; // for reader to access mBuffer 92 93 uint32_t getJpegSize() const; 94 95 // When reader is close, AImage will only accept close API call 96 const sp<AImageReader> mReader; 97 const int32_t mFormat; 98 const uint64_t mUsage; // AHARDWAREBUFFER_USAGE_* flags. 99 BufferItem* mBuffer; 100 std::unique_ptr<CpuConsumer::LockedBuffer> mLockedBuffer; 101 const int64_t mTimestamp; 102 const int32_t mWidth; 103 const int32_t mHeight; 104 const int32_t mNumPlanes; 105 android_dataspace mHalDataSpace = HAL_DATASPACE_UNKNOWN; 106 bool mIsClosed = false; 107 mutable Mutex mLock; 108 }; 109 110 #endif // _NDK_IMAGE_PRIV_H 111