blob: e0f16dadf907f1c2cb46ecd1989ac8f3e399d60c [file] [log] [blame]
* Copyright (C) 2016 The Android Open Source Project
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
#include <inttypes.h>
#include <utils/Log.h>
#include <utils/StrongPointer.h>
#include <gui/BufferItem.h>
#include <gui/CpuConsumer.h>
#include "NdkImageReaderPriv.h"
#include <media/NdkImage.h>
using namespace android;
// TODO: this only supports ImageReader
struct AImage {
AImage(AImageReader* reader, int32_t format, uint64_t usage, BufferItem* buffer,
int64_t timestamp, int32_t width, int32_t height, int32_t numPlanes);
// free all resources while keeping object alive. Caller must obtain reader lock
void close() { close(-1); }
void close(int releaseFenceFd);
// Remove from object memory. Must be called after close
void free();
bool isClosed() const ;
// only For AImage to grab reader lock
// Always grab reader lock before grabbing image lock
void lockReader() const;
void unlockReader() const;
media_status_t getWidth(/*out*/int32_t* width) const;
media_status_t getHeight(/*out*/int32_t* height) const;
media_status_t getFormat(/*out*/int32_t* format) const;
media_status_t getNumPlanes(/*out*/int32_t* numPlanes) const;
media_status_t getTimestamp(/*out*/int64_t* timestamp) const;
media_status_t lockImage();
media_status_t unlockImageIfLocked(/*out*/int* fenceFd);
media_status_t getPlanePixelStride(int planeIdx, /*out*/int32_t* pixelStride) const;
media_status_t getPlaneRowStride(int planeIdx, /*out*/int32_t* rowStride) const;
media_status_t getPlaneData(int planeIdx,/*out*/uint8_t** data, /*out*/int* dataLength) const;
media_status_t getHardwareBuffer(/*out*/AHardwareBuffer** buffer) const;
// AImage should be deleted through free() API.
friend struct AImageReader; // for reader to access mBuffer
uint32_t getJpegSize() const;
// When reader is close, AImage will only accept close API call
wp<AImageReader> mReader;
const int32_t mFormat;
const uint64_t mUsage; // AHARDWAREBUFFER_USAGE_* flags.
BufferItem* mBuffer;
std::unique_ptr<CpuConsumer::LockedBuffer> mLockedBuffer;
const int64_t mTimestamp;
const int32_t mWidth;
const int32_t mHeight;
const int32_t mNumPlanes;
bool mIsClosed = false;
mutable Mutex mLock;
#endif // _NDK_IMAGE_PRIV_H