xref: /aosp_15_r20/hardware/libhardware/modules/camera/3_0/Stream.h (revision e01b6f769022e40d0923dee176e8dc7cd1d52984)
1*e01b6f76SAndroid Build Coastguard Worker /*
2*e01b6f76SAndroid Build Coastguard Worker  * Copyright (C) 2013 The Android Open Source Project
3*e01b6f76SAndroid Build Coastguard Worker  *
4*e01b6f76SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*e01b6f76SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*e01b6f76SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*e01b6f76SAndroid Build Coastguard Worker  *
8*e01b6f76SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*e01b6f76SAndroid Build Coastguard Worker  *
10*e01b6f76SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*e01b6f76SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*e01b6f76SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e01b6f76SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*e01b6f76SAndroid Build Coastguard Worker  * limitations under the License.
15*e01b6f76SAndroid Build Coastguard Worker  */
16*e01b6f76SAndroid Build Coastguard Worker 
17*e01b6f76SAndroid Build Coastguard Worker #ifndef STREAM_H_
18*e01b6f76SAndroid Build Coastguard Worker #define STREAM_H_
19*e01b6f76SAndroid Build Coastguard Worker 
20*e01b6f76SAndroid Build Coastguard Worker #include <hardware/camera3.h>
21*e01b6f76SAndroid Build Coastguard Worker #include <hardware/gralloc.h>
22*e01b6f76SAndroid Build Coastguard Worker #include <system/graphics.h>
23*e01b6f76SAndroid Build Coastguard Worker #include <utils/Mutex.h>
24*e01b6f76SAndroid Build Coastguard Worker 
25*e01b6f76SAndroid Build Coastguard Worker namespace default_camera_hal {
26*e01b6f76SAndroid Build Coastguard Worker // Stream represents a single input or output stream for a camera device.
27*e01b6f76SAndroid Build Coastguard Worker class Stream {
28*e01b6f76SAndroid Build Coastguard Worker     public:
29*e01b6f76SAndroid Build Coastguard Worker         Stream(int id, camera3_stream_t *s);
30*e01b6f76SAndroid Build Coastguard Worker         ~Stream();
31*e01b6f76SAndroid Build Coastguard Worker 
32*e01b6f76SAndroid Build Coastguard Worker         // validate that astream's parameters match this stream's parameters
33*e01b6f76SAndroid Build Coastguard Worker         bool isValidReuseStream(int id, camera3_stream_t *s);
34*e01b6f76SAndroid Build Coastguard Worker 
35*e01b6f76SAndroid Build Coastguard Worker         // Register buffers with hardware
36*e01b6f76SAndroid Build Coastguard Worker         int registerBuffers(const camera3_stream_buffer_set_t *buf_set);
37*e01b6f76SAndroid Build Coastguard Worker 
38*e01b6f76SAndroid Build Coastguard Worker         void setUsage(uint32_t usage);
39*e01b6f76SAndroid Build Coastguard Worker         void setMaxBuffers(uint32_t max_buffers);
40*e01b6f76SAndroid Build Coastguard Worker 
41*e01b6f76SAndroid Build Coastguard Worker         int getType();
42*e01b6f76SAndroid Build Coastguard Worker         bool isInputType();
43*e01b6f76SAndroid Build Coastguard Worker         bool isOutputType();
44*e01b6f76SAndroid Build Coastguard Worker         bool isRegistered();
45*e01b6f76SAndroid Build Coastguard Worker         const char* typeToString(int type);
46*e01b6f76SAndroid Build Coastguard Worker         const char* formatToString(int format);
47*e01b6f76SAndroid Build Coastguard Worker         void dump(int fd);
48*e01b6f76SAndroid Build Coastguard Worker 
49*e01b6f76SAndroid Build Coastguard Worker         // This stream is being reused. Used in stream configuration passes
50*e01b6f76SAndroid Build Coastguard Worker         bool mReuse;
51*e01b6f76SAndroid Build Coastguard Worker 
52*e01b6f76SAndroid Build Coastguard Worker     private:
53*e01b6f76SAndroid Build Coastguard Worker         // Clean up buffer state. must be called with mLock held.
54*e01b6f76SAndroid Build Coastguard Worker         void unregisterBuffers_L();
55*e01b6f76SAndroid Build Coastguard Worker 
56*e01b6f76SAndroid Build Coastguard Worker         // The camera device id this stream belongs to
57*e01b6f76SAndroid Build Coastguard Worker         const int mId;
58*e01b6f76SAndroid Build Coastguard Worker         // Handle to framework's stream, used as a cookie for buffers
59*e01b6f76SAndroid Build Coastguard Worker         camera3_stream_t *mStream;
60*e01b6f76SAndroid Build Coastguard Worker         // Stream type: CAMERA3_STREAM_* (see <hardware/camera3.h>)
61*e01b6f76SAndroid Build Coastguard Worker         const int mType;
62*e01b6f76SAndroid Build Coastguard Worker         // Width in pixels of the buffers in this stream
63*e01b6f76SAndroid Build Coastguard Worker         const uint32_t mWidth;
64*e01b6f76SAndroid Build Coastguard Worker         // Height in pixels of the buffers in this stream
65*e01b6f76SAndroid Build Coastguard Worker         const uint32_t mHeight;
66*e01b6f76SAndroid Build Coastguard Worker         // Gralloc format: HAL_PIXEL_FORMAT_* (see <system/graphics.h>)
67*e01b6f76SAndroid Build Coastguard Worker         const int mFormat;
68*e01b6f76SAndroid Build Coastguard Worker         // Gralloc usage mask : GRALLOC_USAGE_* (see <hardware/gralloc.h>)
69*e01b6f76SAndroid Build Coastguard Worker         uint32_t mUsage;
70*e01b6f76SAndroid Build Coastguard Worker         // Max simultaneous in-flight buffers for this stream
71*e01b6f76SAndroid Build Coastguard Worker         uint32_t mMaxBuffers;
72*e01b6f76SAndroid Build Coastguard Worker         // Buffers have been registered for this stream and are ready
73*e01b6f76SAndroid Build Coastguard Worker         bool mRegistered;
74*e01b6f76SAndroid Build Coastguard Worker         // Array of handles to buffers currently in use by the stream
75*e01b6f76SAndroid Build Coastguard Worker         buffer_handle_t **mBuffers;
76*e01b6f76SAndroid Build Coastguard Worker         // Number of buffers in mBuffers
77*e01b6f76SAndroid Build Coastguard Worker         unsigned int mNumBuffers;
78*e01b6f76SAndroid Build Coastguard Worker         // Lock protecting the Stream object for modifications
79*e01b6f76SAndroid Build Coastguard Worker         android::Mutex mLock;
80*e01b6f76SAndroid Build Coastguard Worker };
81*e01b6f76SAndroid Build Coastguard Worker } // namespace default_camera_hal
82*e01b6f76SAndroid Build Coastguard Worker 
83*e01b6f76SAndroid Build Coastguard Worker #endif // STREAM_H_
84