NdkImagePriv.h revision e168996c51cbbc78790c2b3282c9455a5c7b667c
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 "NdkImage.h" 29 30 31using namespace android; 32 33// TODO: this only supports ImageReader 34struct AImage { 35 AImage(AImageReader* reader, int32_t format, uint64_t usage0, uint64_t usage1, 36 BufferItem* buffer, int64_t timestamp, 37 int32_t width, int32_t height, int32_t numPlanes); 38 39 // free all resources while keeping object alive. Caller must obtain reader lock 40 void close() { close(-1); } 41 void close(int releaseFenceFd); 42 43 // Remove from object memory. Must be called after close 44 void free(); 45 46 bool isClosed() const ; 47 48 // only For AImage to grab reader lock 49 // Always grab reader lock before grabbing image lock 50 void lockReader() const; 51 void unlockReader() const; 52 53 media_status_t getWidth(/*out*/int32_t* width) const; 54 media_status_t getHeight(/*out*/int32_t* height) const; 55 media_status_t getFormat(/*out*/int32_t* format) const; 56 media_status_t getNumPlanes(/*out*/int32_t* numPlanes) const; 57 media_status_t getTimestamp(/*out*/int64_t* timestamp) const; 58 59 media_status_t lockImage(); 60 media_status_t unlockImageIfLocked(/*out*/int* fenceFd); 61 62 media_status_t getPlanePixelStride(int planeIdx, /*out*/int32_t* pixelStride) const; 63 media_status_t getPlaneRowStride(int planeIdx, /*out*/int32_t* rowStride) const; 64 media_status_t getPlaneData(int planeIdx,/*out*/uint8_t** data, /*out*/int* dataLength) const; 65 media_status_t getHardwareBuffer(/*out*/AHardwareBuffer** buffer) const; 66 67 private: 68 // AImage should be deleted through free() API. 69 ~AImage(); 70 71 friend struct AImageReader; // for reader to access mBuffer 72 73 uint32_t getJpegSize() const; 74 75 // When reader is close, AImage will only accept close API call 76 wp<AImageReader> mReader; 77 const int32_t mFormat; 78 const uint64_t mUsage0; // AHARDWAREBUFFER_USAGE0* flags. 79 const uint64_t mUsage1; // AHARDWAREBUFFER_USAGE1* flags. 80 BufferItem* mBuffer; 81 std::unique_ptr<CpuConsumer::LockedBuffer> mLockedBuffer; 82 const int64_t mTimestamp; 83 const int32_t mWidth; 84 const int32_t mHeight; 85 const int32_t mNumPlanes; 86 bool mIsClosed = false; 87 mutable Mutex mLock; 88}; 89 90#endif // _NDK_IMAGE_PRIV_H 91