xref: /aosp_15_r20/frameworks/av/services/camera/libcameraservice/device3/Camera3InputStream.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
2  * Copyright (C) 2013-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_CAMERA3_INPUT_STREAM_H
18 #define ANDROID_SERVERS_CAMERA3_INPUT_STREAM_H
19 
20 #include <utils/RefBase.h>
21 #include <gui/Flags.h>
22 #include <gui/Surface.h>
23 #include <gui/BufferItemConsumer.h>
24 
25 #include "Camera3IOStreamBase.h"
26 
27 namespace android {
28 
29 namespace camera3 {
30 
31 /**
32  * A class for managing a single stream of input data to the camera device.
33  *
34  * This class serves as a consumer adapter for the HAL, and will consume the
35  * buffers by feeding them into the HAL, as well as releasing the buffers back
36  * the buffers once the HAL is done with them.
37  */
38 class Camera3InputStream : public Camera3IOStreamBase,
39                            public BufferItemConsumer::BufferFreedListener {
40   public:
41     /**
42      * Set up a stream for formats that have fixed size, such as RAW and YUV.
43      */
44     Camera3InputStream(int id, uint32_t width, uint32_t height, int format);
45     ~Camera3InputStream();
46 
47     virtual void     dump(int fd, const Vector<String16> &args);
48 
49     // TODO: expose an interface to get the IGraphicBufferProducer
50 
51   private:
52 
53     sp<BufferItemConsumer> mConsumer;
54 #if WB_CAMERA3_AND_PROCESSORS_WITH_DEPENDENCIES
55     sp<Surface> mSurface;
56 #else
57     sp<IGraphicBufferProducer> mProducer;
58 #endif
59     Vector<BufferItem> mBuffersInFlight;
60 
61     static const std::string FAKE_ID;
62 
63     /**
64      * Camera3IOStreamBase
65      */
66     virtual status_t returnBufferCheckedLocked(
67             const camera_stream_buffer &buffer,
68             nsecs_t timestamp,
69             nsecs_t readoutTimestamp,
70             bool output,
71             int32_t transform,
72             const std::vector<size_t>& surface_ids,
73             /*out*/
74             sp<Fence> *releaseFenceOut);
75 
76     /**
77      * Camera3Stream interface
78      */
79 
80     virtual status_t getInputBufferLocked(camera_stream_buffer *buffer, Size *size);
81     virtual status_t returnInputBufferLocked(
82             const camera_stream_buffer &buffer);
83 #if WB_CAMERA3_AND_PROCESSORS_WITH_DEPENDENCIES
84     virtual status_t getInputSurfaceLocked(sp<Surface> *surface);
85 #else
86     virtual status_t getInputBufferProducerLocked(
87             sp<IGraphicBufferProducer> *producer);
88 #endif
89     virtual status_t disconnectLocked();
90 
91     virtual status_t configureQueueLocked();
92 
93     virtual status_t getEndpointUsage(uint64_t *usage);
94 
95     /**
96      * BufferItemConsumer::BufferFreedListener interface
97      */
98     virtual void onBufferFreed(const wp<GraphicBuffer>&) override;
99 
100 }; // class Camera3InputStream
101 
102 }; // namespace camera3
103 
104 }; // namespace android
105 
106 #endif
107