blob: 583774550bc7690b85ae6975fe3824d8b598af09 [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>
26#include "common/CameraDeviceBase.h"
27#include "device3/Camera3StreamInterface.h"
28
29namespace android {
30
31class CameraDeviceClient;
32class CameraMetadata;
33class Surface;
34
35namespace camera3 {
36
37class CompositeStream : public camera3::Camera3StreamBufferListener {
38
39public:
40 CompositeStream(wp<CameraDeviceBase> device, wp<hardware::camera2::ICameraDeviceCallbacks> cb);
41 virtual ~CompositeStream() {}
42
43 status_t createStream(const std::vector<sp<Surface>>& consumers,
44 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
45 camera3_stream_rotation_t rotation, int *id, const String8& physicalCameraId,
46 std::vector<int> *surfaceIds, int streamSetId, bool isShared);
47
48 status_t deleteStream();
49
50 // Create and register all internal camera streams.
51 virtual status_t createInternalStreams(const std::vector<sp<Surface>>& consumers,
52 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
53 camera3_stream_rotation_t rotation, int *id, const String8& physicalCameraId,
54 std::vector<int> *surfaceIds, int streamSetId, bool isShared) = 0;
55
56 // Release all internal streams and corresponding resources.
57 virtual status_t deleteInternalStreams() = 0;
58
59 // Stream configuration completed.
60 virtual status_t configureStream() = 0;
61
62 // Insert the internal composite stream id in the user capture request.
63 virtual status_t insertGbp(SurfaceMap* /*out*/outSurfaceMap,
64 Vector<int32_t>* /*out*/outputStreamIds, int32_t* /*out*/currentStreamId) = 0;
65
66 // Return composite stream id.
67 virtual int getStreamId() = 0;
68
69 void onResultAvailable(const CaptureResult& result);
70 bool onError(int32_t errorCode, const CaptureResultExtras& resultExtras);
71
72 // Camera3StreamBufferListener implementation
73 void onBufferAcquired(const BufferInfo& /*bufferInfo*/) override { /*Empty for now */ }
74 void onBufferReleased(const BufferInfo& bufferInfo) override;
75 void onBufferRequestForFrameNumber(uint64_t frameNumber, int streamId) override;
76
77protected:
78 status_t registerCompositeStreamListener(int32_t streamId);
79 void eraseResult(int64_t frameNumber);
80 void flagAnErrorFrameNumber(int64_t frameNumber);
81 void notifyError(int64_t frameNumber);
82
83 // Subclasses should check for buffer errors from internal streams and return 'true' in
84 // case the error notification should remain within camera service.
85 virtual bool onStreamBufferError(const CaptureResultExtras& resultExtras) = 0;
86
87 // Subclasses can decide how to handle result errors depending on whether or not the
88 // internal processing needs result data.
89 virtual void onResultError(const CaptureResultExtras& resultExtras) = 0;
90
91 // Device and/or service is in unrecoverable error state.
92 // Composite streams should behave accordingly.
93 void enableErrorState();
94
95 wp<CameraDeviceBase> mDevice;
96 wp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
97
98 mutable Mutex mMutex;
99 Condition mInputReadyCondition;
100 int32_t mNumPartialResults;
101 bool mErrorState;
102
103 // Frame number to capture result map of partial pending request results.
104 std::unordered_map<uint64_t, CameraMetadata> mPendingCaptureResults;
105
106 // Timestamp to capture (frame number, result) map of completed pending request results.
107 std::unordered_map<int64_t, std::tuple<int64_t, CameraMetadata>> mCaptureResults;
108
109 // Frame number to timestamp map
110 std::unordered_map<int64_t, int64_t> mFrameNumberMap;
111
112 // Keeps a set buffer/result frame numbers for any errors detected during processing.
113 std::set<int64_t> mErrorFrameNumbers;
114
115};
116
117}; //namespace camera3
118}; //namespace android
119
120#endif