blob: 4b462b533efa043a942258bc70c3b5d686c52ea2 [file] [log] [blame]
Emilian Peev434248e2022-10-06 14:58:54 -07001/*
2 * Copyright (C) 2022 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 ANDROID_SERVERS_CAMERA_CAMERA3_JPEG_R_COMPOSITE_STREAM_H
18#define ANDROID_SERVERS_CAMERA_CAMERA3_JPEG_R_COMPOSITE_STREAM_H
19
20#include <gui/CpuConsumer.h>
21#include "aidl/android/hardware/graphics/common/Dataspace.h"
22#include "system/graphics-base-v1.1.h"
23
24#include "api1/client2/JpegProcessor.h"
25
26#include "CompositeStream.h"
27
28namespace android {
29
30class CameraDeviceClient;
31class CameraMetadata;
32class Surface;
33
34namespace camera3 {
35
36class JpegRCompositeStream : public CompositeStream, public Thread,
37 public CpuConsumer::FrameAvailableListener {
38
39public:
40 JpegRCompositeStream(sp<CameraDeviceBase> device,
41 wp<hardware::camera2::ICameraDeviceCallbacks> cb);
42 ~JpegRCompositeStream() override;
43
44 static bool isJpegRCompositeStream(const sp<Surface> &surface);
45
46 // CompositeStream overrides
47 status_t createInternalStreams(const std::vector<sp<Surface>>& consumers,
48 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
49 camera_stream_rotation_t rotation, int *id, const String8& physicalCameraId,
50 const std::unordered_set<int32_t> &sensorPixelModesUsed,
51 std::vector<int> *surfaceIds,
52 int streamSetId, bool isShared, int32_t colorSpace,
Shuzhen Wangbce53db2022-12-03 00:38:20 +000053 int64_t dynamicProfile, int64_t streamUseCase, bool useReadoutTimestamp) override;
Emilian Peev434248e2022-10-06 14:58:54 -070054 status_t deleteInternalStreams() override;
55 status_t configureStream() override;
56 status_t insertGbp(SurfaceMap* /*out*/outSurfaceMap, Vector<int32_t>* /*out*/outputStreamIds,
57 int32_t* /*out*/currentStreamId) override;
58 status_t insertCompositeStreamIds(std::vector<int32_t>* compositeStreamIds /*out*/) override;
59 int getStreamId() override { return mP010StreamId; }
60
61 // CpuConsumer listener implementation
62 void onFrameAvailable(const BufferItem& item) override;
63
64 // Return stream information about the internal camera streams
65 static status_t getCompositeStreamInfo(const OutputStreamInfo &streamInfo,
66 const CameraMetadata& ch, std::vector<OutputStreamInfo>* compositeOutput /*out*/);
67
68protected:
69
70 bool threadLoop() override;
71 bool onStreamBufferError(const CaptureResultExtras& resultExtras) override;
72 void onResultError(const CaptureResultExtras& resultExtras) override;
73
74private:
75 struct InputFrame {
76 CpuConsumer::LockedBuffer p010Buffer;
77 CpuConsumer::LockedBuffer jpegBuffer;
78 CameraMetadata result;
79 bool error;
80 bool errorNotified;
81 int64_t frameNumber;
82 int32_t requestId;
83
84 InputFrame() : error(false), errorNotified(false), frameNumber(-1), requestId(-1) { }
85 };
86
87 status_t processInputFrame(nsecs_t ts, const InputFrame &inputFrame);
88
89 // Buffer/Results handling
90 void compilePendingInputLocked();
91 void releaseInputFrameLocked(InputFrame *inputFrame /*out*/);
92 void releaseInputFramesLocked(int64_t currentTs);
93
94 // Find first complete and valid frame with smallest timestamp
95 bool getNextReadyInputLocked(int64_t *currentTs /*inout*/);
96
97 // Find next failing frame number with smallest timestamp and return respective frame number
98 int64_t getNextFailingInputLocked(int64_t *currentTs /*inout*/);
99
100 static void deriveDynamicRangeAndDataspace(int64_t dynamicProfile, int64_t* /*out*/dynamicRange,
101 int64_t* /*out*/dataSpace);
102
103 static const nsecs_t kWaitDuration = 10000000; // 10 ms
104 static const auto kP010PixelFormat = HAL_PIXEL_FORMAT_YCBCR_P010;
105 static const auto kP010DefaultDataSpace = HAL_DATASPACE_BT2020_ITU_HLG;
106 static const auto kP010DefaultDynamicRange =
107 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HLG10;
108 static const auto kJpegDataSpace = HAL_DATASPACE_V0_JFIF;
109 static const auto kJpegRDataSpace =
110 aidl::android::hardware::graphics::common::Dataspace::JPEG_R;
111
112 bool mSupportInternalJpeg = false;
113 int64_t mP010DataSpace = HAL_DATASPACE_BT2020_HLG;
114 int64_t mP010DynamicRange =
115 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HLG10;
116 int mBlobStreamId, mBlobSurfaceId, mP010StreamId, mP010SurfaceId;
117 size_t mBlobWidth, mBlobHeight;
118 sp<CpuConsumer> mBlobConsumer, mP010Consumer;
119 bool mP010BufferAcquired, mBlobBufferAcquired;
120 sp<Surface> mP010Surface, mBlobSurface, mOutputSurface;
121 int32_t mOutputColorSpace;
122 sp<ProducerListener> mProducerListener;
123
124 ssize_t mMaxJpegBufferSize;
125 ssize_t mUHRMaxJpegBufferSize;
126
127 camera3::Size mDefaultMaxJpegSize;
128 camera3::Size mUHRMaxJpegSize;
129
130 // Keep all incoming P010 buffer timestamps pending further processing.
131 std::vector<int64_t> mInputP010Buffers;
132
133 // Keep all incoming Jpeg/Blob buffer timestamps pending further processing.
134 std::vector<int64_t> mInputJpegBuffers;
135
136 // Map of all input frames pending further processing.
137 std::unordered_map<int64_t, InputFrame> mPendingInputFrames;
138
139 const CameraMetadata mStaticInfo;
140};
141
142}; //namespace camera3
143}; //namespace android
144
145#endif