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