blob: e0f16dadf907f1c2cb46ecd1989ac8f3e399d60c [file] [log] [blame]
Yin-Chia Yehc3603822016-01-18 22:11:19 -08001/*
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' Cai2f1a4732017-02-04 17:31:55 -080024#include <gui/BufferItem.h>
Yin-Chia Yehc3603822016-01-18 22:11:19 -080025#include <gui/CpuConsumer.h>
26
27#include "NdkImageReaderPriv.h"
Colin Cross7e8d4ba2017-05-04 16:17:42 -070028#include <media/NdkImage.h>
Yin-Chia Yehc3603822016-01-18 22:11:19 -080029
30
31using namespace android;
32
33// TODO: this only supports ImageReader
34struct AImage {
Jiwen 'Steve' Caie31bc872017-04-21 17:13:18 -070035 AImage(AImageReader* reader, int32_t format, uint64_t usage, BufferItem* buffer,
36 int64_t timestamp, int32_t width, int32_t height, int32_t numPlanes);
Yin-Chia Yehc3603822016-01-18 22:11:19 -080037
38 // free all resources while keeping object alive. Caller must obtain reader lock
Jiwen 'Steve' Caie1689962017-02-20 16:59:05 -080039 void close() { close(-1); }
40 void close(int releaseFenceFd);
Yin-Chia Yehc3603822016-01-18 22:11:19 -080041
42 // Remove from object memory. Must be called after close
43 void free();
44
45 bool isClosed() const ;
46
47 // only For AImage to grab reader lock
48 // Always grab reader lock before grabbing image lock
49 void lockReader() const;
50 void unlockReader() const;
51
52 media_status_t getWidth(/*out*/int32_t* width) const;
53 media_status_t getHeight(/*out*/int32_t* height) const;
54 media_status_t getFormat(/*out*/int32_t* format) const;
55 media_status_t getNumPlanes(/*out*/int32_t* numPlanes) const;
56 media_status_t getTimestamp(/*out*/int64_t* timestamp) const;
57
Jiwen 'Steve' Cai2f1a4732017-02-04 17:31:55 -080058 media_status_t lockImage();
59 media_status_t unlockImageIfLocked(/*out*/int* fenceFd);
60
Yin-Chia Yehc3603822016-01-18 22:11:19 -080061 media_status_t getPlanePixelStride(int planeIdx, /*out*/int32_t* pixelStride) const;
62 media_status_t getPlaneRowStride(int planeIdx, /*out*/int32_t* rowStride) const;
63 media_status_t getPlaneData(int planeIdx,/*out*/uint8_t** data, /*out*/int* dataLength) const;
Jiwen 'Steve' Caie1689962017-02-20 16:59:05 -080064 media_status_t getHardwareBuffer(/*out*/AHardwareBuffer** buffer) const;
Yin-Chia Yehc3603822016-01-18 22:11:19 -080065
66 private:
67 // AImage should be deleted through free() API.
68 ~AImage();
69
70 friend struct AImageReader; // for reader to access mBuffer
71
72 uint32_t getJpegSize() const;
73
74 // When reader is close, AImage will only accept close API call
75 wp<AImageReader> mReader;
76 const int32_t mFormat;
Jiwen 'Steve' Caie31bc872017-04-21 17:13:18 -070077 const uint64_t mUsage; // AHARDWAREBUFFER_USAGE_* flags.
Jiwen 'Steve' Cai2f1a4732017-02-04 17:31:55 -080078 BufferItem* mBuffer;
79 std::unique_ptr<CpuConsumer::LockedBuffer> mLockedBuffer;
Yin-Chia Yehc3603822016-01-18 22:11:19 -080080 const int64_t mTimestamp;
81 const int32_t mWidth;
82 const int32_t mHeight;
83 const int32_t mNumPlanes;
84 bool mIsClosed = false;
85 mutable Mutex mLock;
86};
87
88#endif // _NDK_IMAGE_PRIV_H