blob: efd31da83d4e57e8c198d7bc9420f735fd011b55 [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"
Emilian Peev567c31c2023-03-06 15:02:37 -080025#include "utils/SessionStatsBuilder.h"
Emilian Peev434248e2022-10-06 14:58:54 -070026
27#include "CompositeStream.h"
28
29namespace android {
30
31class CameraDeviceClient;
32class CameraMetadata;
33class Surface;
34
35namespace camera3 {
36
37class JpegRCompositeStream : public CompositeStream, public Thread,
38 public CpuConsumer::FrameAvailableListener {
39
40public:
41 JpegRCompositeStream(sp<CameraDeviceBase> device,
42 wp<hardware::camera2::ICameraDeviceCallbacks> cb);
43 ~JpegRCompositeStream() override;
44
45 static bool isJpegRCompositeStream(const sp<Surface> &surface);
Emilian Peeve75a2852024-05-20 22:35:15 +000046 static bool isJpegRCompositeStreamInfo(const OutputStreamInfo& streamInfo);
Emilian Peev434248e2022-10-06 14:58:54 -070047
48 // CompositeStream overrides
Shuzhen Wang38df0ca2024-10-09 11:33:44 -070049 status_t createInternalStreams(const std::vector<SurfaceHolder>& consumers,
Emilian Peev434248e2022-10-06 14:58:54 -070050 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
Austin Borger1c1bee02023-06-01 16:51:35 -070051 camera_stream_rotation_t rotation, int *id, const std::string& physicalCameraId,
Emilian Peev434248e2022-10-06 14:58:54 -070052 const std::unordered_set<int32_t> &sensorPixelModesUsed,
53 std::vector<int> *surfaceIds,
54 int streamSetId, bool isShared, int32_t colorSpace,
Shuzhen Wangbce53db2022-12-03 00:38:20 +000055 int64_t dynamicProfile, int64_t streamUseCase, bool useReadoutTimestamp) override;
Emilian Peev434248e2022-10-06 14:58:54 -070056 status_t deleteInternalStreams() override;
57 status_t configureStream() override;
58 status_t insertGbp(SurfaceMap* /*out*/outSurfaceMap, Vector<int32_t>* /*out*/outputStreamIds,
59 int32_t* /*out*/currentStreamId) override;
60 status_t insertCompositeStreamIds(std::vector<int32_t>* compositeStreamIds /*out*/) override;
61 int getStreamId() override { return mP010StreamId; }
62
63 // CpuConsumer listener implementation
64 void onFrameAvailable(const BufferItem& item) override;
65
66 // Return stream information about the internal camera streams
67 static status_t getCompositeStreamInfo(const OutputStreamInfo &streamInfo,
68 const CameraMetadata& ch, std::vector<OutputStreamInfo>* compositeOutput /*out*/);
69
Emilian Peev567c31c2023-03-06 15:02:37 -080070 // Get composite stream stats
71 void getStreamStats(hardware::CameraStreamStats* streamStats) override;
72
Emilian Peev434248e2022-10-06 14:58:54 -070073protected:
74
75 bool threadLoop() override;
76 bool onStreamBufferError(const CaptureResultExtras& resultExtras) override;
77 void onResultError(const CaptureResultExtras& resultExtras) override;
78
79private:
80 struct InputFrame {
81 CpuConsumer::LockedBuffer p010Buffer;
82 CpuConsumer::LockedBuffer jpegBuffer;
83 CameraMetadata result;
84 bool error;
85 bool errorNotified;
86 int64_t frameNumber;
87 int32_t requestId;
Emilian Peev567c31c2023-03-06 15:02:37 -080088 nsecs_t requestTimeNs;
Emilian Peev434248e2022-10-06 14:58:54 -070089
Emilian Peev567c31c2023-03-06 15:02:37 -080090 InputFrame() : error(false), errorNotified(false), frameNumber(-1), requestId(-1),
91 requestTimeNs(-1) { }
Emilian Peev434248e2022-10-06 14:58:54 -070092 };
93
94 status_t processInputFrame(nsecs_t ts, const InputFrame &inputFrame);
95
96 // Buffer/Results handling
97 void compilePendingInputLocked();
98 void releaseInputFrameLocked(InputFrame *inputFrame /*out*/);
99 void releaseInputFramesLocked(int64_t currentTs);
100
101 // Find first complete and valid frame with smallest timestamp
102 bool getNextReadyInputLocked(int64_t *currentTs /*inout*/);
103
104 // Find next failing frame number with smallest timestamp and return respective frame number
105 int64_t getNextFailingInputLocked(int64_t *currentTs /*inout*/);
106
107 static void deriveDynamicRangeAndDataspace(int64_t dynamicProfile, int64_t* /*out*/dynamicRange,
108 int64_t* /*out*/dataSpace);
109
110 static const nsecs_t kWaitDuration = 10000000; // 10 ms
111 static const auto kP010PixelFormat = HAL_PIXEL_FORMAT_YCBCR_P010;
112 static const auto kP010DefaultDataSpace = HAL_DATASPACE_BT2020_ITU_HLG;
113 static const auto kP010DefaultDynamicRange =
114 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HLG10;
115 static const auto kJpegDataSpace = HAL_DATASPACE_V0_JFIF;
116 static const auto kJpegRDataSpace =
117 aidl::android::hardware::graphics::common::Dataspace::JPEG_R;
118
119 bool mSupportInternalJpeg = false;
120 int64_t mP010DataSpace = HAL_DATASPACE_BT2020_HLG;
121 int64_t mP010DynamicRange =
122 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HLG10;
123 int mBlobStreamId, mBlobSurfaceId, mP010StreamId, mP010SurfaceId;
124 size_t mBlobWidth, mBlobHeight;
125 sp<CpuConsumer> mBlobConsumer, mP010Consumer;
126 bool mP010BufferAcquired, mBlobBufferAcquired;
127 sp<Surface> mP010Surface, mBlobSurface, mOutputSurface;
128 int32_t mOutputColorSpace;
Emilian Peev567c31c2023-03-06 15:02:37 -0800129 int64_t mOutputStreamUseCase;
130 nsecs_t mFirstRequestLatency;
Carlos Martinez Romeroae9834f2024-07-03 13:33:47 -0700131
132 sp<StreamSurfaceListener> mStreamSurfaceListener;
Emilian Peev434248e2022-10-06 14:58:54 -0700133
134 ssize_t mMaxJpegBufferSize;
135 ssize_t mUHRMaxJpegBufferSize;
136
137 camera3::Size mDefaultMaxJpegSize;
138 camera3::Size mUHRMaxJpegSize;
139
140 // Keep all incoming P010 buffer timestamps pending further processing.
141 std::vector<int64_t> mInputP010Buffers;
142
143 // Keep all incoming Jpeg/Blob buffer timestamps pending further processing.
144 std::vector<int64_t> mInputJpegBuffers;
145
146 // Map of all input frames pending further processing.
147 std::unordered_map<int64_t, InputFrame> mPendingInputFrames;
148
149 const CameraMetadata mStaticInfo;
Emilian Peev567c31c2023-03-06 15:02:37 -0800150
151 SessionStatsBuilder mSessionStatsBuilder;
Emilian Peev434248e2022-10-06 14:58:54 -0700152};
153
154}; //namespace camera3
155}; //namespace android
156
157#endif