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