1c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh/* 2c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * Copyright (C) 2016 The Android Open Source Project 3c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * 4c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * Licensed under the Apache License, Version 2.0 (the "License"); 5c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * you may not use this file except in compliance with the License. 6c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * You may obtain a copy of the License at 7c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * 8c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * http://www.apache.org/licenses/LICENSE-2.0 9c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * 10c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * Unless required by applicable law or agreed to in writing, software 11c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * distributed under the License is distributed on an "AS IS" BASIS, 12c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * See the License for the specific language governing permissions and 14c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh * limitations under the License. 15c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh */ 16c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 17c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#ifndef _NDK_IMAGE_PRIV_H 18c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#define _NDK_IMAGE_PRIV_H 19c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 20c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#include <inttypes.h> 21c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#include <utils/Log.h> 22c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#include <utils/StrongPointer.h> 23c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 24c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#include <gui/CpuConsumer.h> 25c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 26c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#include "NdkImageReaderPriv.h" 27c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#include "NdkImage.h" 28c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 29c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 30c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yehusing namespace android; 31c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 32c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh// TODO: this only supports ImageReader 33c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yehstruct AImage { 34c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh AImage(AImageReader* reader, int32_t format, 35c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh CpuConsumer::LockedBuffer* buffer, int64_t timestamp, 36c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh int32_t width, int32_t height, int32_t numPlanes); 37c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 38c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh // free all resources while keeping object alive. Caller must obtain reader lock 39c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh void close(); 40c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 41c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh // Remove from object memory. Must be called after close 42c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh void free(); 43c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 44c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh bool isClosed() const ; 45c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 46c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh // only For AImage to grab reader lock 47c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh // Always grab reader lock before grabbing image lock 48c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh void lockReader() const; 49c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh void unlockReader() const; 50c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 51c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh media_status_t getWidth(/*out*/int32_t* width) const; 52c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh media_status_t getHeight(/*out*/int32_t* height) const; 53c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh media_status_t getFormat(/*out*/int32_t* format) const; 54c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh media_status_t getNumPlanes(/*out*/int32_t* numPlanes) const; 55c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh media_status_t getTimestamp(/*out*/int64_t* timestamp) const; 56c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 57c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh media_status_t getPlanePixelStride(int planeIdx, /*out*/int32_t* pixelStride) const; 58c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh media_status_t getPlaneRowStride(int planeIdx, /*out*/int32_t* rowStride) const; 59c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh media_status_t getPlaneData(int planeIdx,/*out*/uint8_t** data, /*out*/int* dataLength) const; 60c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 61c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh private: 62c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh // AImage should be deleted through free() API. 63c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh ~AImage(); 64c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 65c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh friend struct AImageReader; // for reader to access mBuffer 66c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 67c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh uint32_t getJpegSize() const; 68c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 69c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh // When reader is close, AImage will only accept close API call 70c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh wp<AImageReader> mReader; 71c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh const int32_t mFormat; 72c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh CpuConsumer::LockedBuffer* mBuffer; 73c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh const int64_t mTimestamp; 74c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh const int32_t mWidth; 75c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh const int32_t mHeight; 76c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh const int32_t mNumPlanes; 77c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh bool mIsClosed = false; 78c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh mutable Mutex mLock; 79c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh}; 80c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh 81c360382bf257d815b2a411152485d3c3b37a9f46Yin-Chia Yeh#endif // _NDK_IMAGE_PRIV_H 82