blob: de894f318f19e57f83f58a03b1304d33f3675cb0 [file] [log] [blame]
Emilian Peev538c90e2018-12-17 18:03:19 +00001/*
2 * Copyright (C) 2018 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_COMPOSITE_STREAM_H
18#define ANDROID_SERVERS_CAMERA_CAMERA3_COMPOSITE_STREAM_H
19
20#include <set>
21#include <unordered_map>
22
23#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
24#include <camera/CameraMetadata.h>
25#include <camera/camera2/OutputConfiguration.h>
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080026#include <gui/IProducerListener.h>
Emilian Peev538c90e2018-12-17 18:03:19 +000027#include "common/CameraDeviceBase.h"
28#include "device3/Camera3StreamInterface.h"
29
30namespace android {
31
32class CameraDeviceClient;
33class CameraMetadata;
34class Surface;
35
36namespace camera3 {
37
38class CompositeStream : public camera3::Camera3StreamBufferListener {
39
40public:
41 CompositeStream(wp<CameraDeviceBase> device, wp<hardware::camera2::ICameraDeviceCallbacks> cb);
42 virtual ~CompositeStream() {}
43
44 status_t createStream(const std::vector<sp<Surface>>& consumers,
45 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
46 camera3_stream_rotation_t rotation, int *id, const String8& physicalCameraId,
47 std::vector<int> *surfaceIds, int streamSetId, bool isShared);
48
49 status_t deleteStream();
50
51 // Create and register all internal camera streams.
52 virtual status_t createInternalStreams(const std::vector<sp<Surface>>& consumers,
53 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
54 camera3_stream_rotation_t rotation, int *id, const String8& physicalCameraId,
55 std::vector<int> *surfaceIds, int streamSetId, bool isShared) = 0;
56
57 // Release all internal streams and corresponding resources.
58 virtual status_t deleteInternalStreams() = 0;
59
60 // Stream configuration completed.
61 virtual status_t configureStream() = 0;
62
63 // Insert the internal composite stream id in the user capture request.
64 virtual status_t insertGbp(SurfaceMap* /*out*/outSurfaceMap,
65 Vector<int32_t>* /*out*/outputStreamIds, int32_t* /*out*/currentStreamId) = 0;
66
Emilian Peev4697b642019-11-19 17:11:14 -080067 // Attach the internal composite stream ids.
68 virtual status_t insertCompositeStreamIds(
69 std::vector<int32_t>* compositeStreamIds /*out*/) = 0;
70
Emilian Peev538c90e2018-12-17 18:03:19 +000071 // Return composite stream id.
72 virtual int getStreamId() = 0;
73
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080074 // Notify when shutter notify is triggered
75 virtual void onShutter(const CaptureResultExtras& /*resultExtras*/, nsecs_t /*timestamp*/) {}
76
Emilian Peev538c90e2018-12-17 18:03:19 +000077 void onResultAvailable(const CaptureResult& result);
78 bool onError(int32_t errorCode, const CaptureResultExtras& resultExtras);
79
80 // Camera3StreamBufferListener implementation
81 void onBufferAcquired(const BufferInfo& /*bufferInfo*/) override { /*Empty for now */ }
82 void onBufferReleased(const BufferInfo& bufferInfo) override;
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080083 void onBufferRequestForFrameNumber(uint64_t frameNumber, int streamId,
84 const CameraMetadata& settings) override;
Emilian Peev538c90e2018-12-17 18:03:19 +000085
86protected:
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080087 struct ProducerListener : public BnProducerListener {
88 // ProducerListener impementation
89 void onBufferReleased() override { /*No impl. for now*/ };
90 };
91
Emilian Peev538c90e2018-12-17 18:03:19 +000092 status_t registerCompositeStreamListener(int32_t streamId);
93 void eraseResult(int64_t frameNumber);
94 void flagAnErrorFrameNumber(int64_t frameNumber);
95 void notifyError(int64_t frameNumber);
96
97 // Subclasses should check for buffer errors from internal streams and return 'true' in
98 // case the error notification should remain within camera service.
99 virtual bool onStreamBufferError(const CaptureResultExtras& resultExtras) = 0;
100
101 // Subclasses can decide how to handle result errors depending on whether or not the
102 // internal processing needs result data.
103 virtual void onResultError(const CaptureResultExtras& resultExtras) = 0;
104
105 // Device and/or service is in unrecoverable error state.
106 // Composite streams should behave accordingly.
107 void enableErrorState();
108
109 wp<CameraDeviceBase> mDevice;
110 wp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
111
112 mutable Mutex mMutex;
113 Condition mInputReadyCondition;
114 int32_t mNumPartialResults;
115 bool mErrorState;
116
117 // Frame number to capture result map of partial pending request results.
118 std::unordered_map<uint64_t, CameraMetadata> mPendingCaptureResults;
119
120 // Timestamp to capture (frame number, result) map of completed pending request results.
121 std::unordered_map<int64_t, std::tuple<int64_t, CameraMetadata>> mCaptureResults;
122
123 // Frame number to timestamp map
124 std::unordered_map<int64_t, int64_t> mFrameNumberMap;
125
126 // Keeps a set buffer/result frame numbers for any errors detected during processing.
127 std::set<int64_t> mErrorFrameNumbers;
128
129};
130
131}; //namespace camera3
132}; //namespace android
133
134#endif