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