blob: b62114e7890bae35b8cf6544b26157f9e7f16224 [file] [log] [blame]
Alex Raybcaf7882013-02-28 16:04:35 -08001/*
2 * Copyright (C) 2013 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 STREAM_H_
18#define STREAM_H_
19
20#include <hardware/camera3.h>
21#include <hardware/gralloc.h>
22#include <system/graphics.h>
23
24namespace default_camera_hal {
25// Stream represents a single input or output stream for a camera device.
26class Stream {
27 public:
28 Stream(int id, camera3_stream_t *s);
29 ~Stream();
30
31 // validate that astream's parameters match this stream's parameters
32 bool isValidReuseStream(int id, camera3_stream_t *s);
33
Alex Ray8a8f86b2013-03-01 01:32:21 -080034 // Register buffers with hardware
35 int registerBuffers(const camera3_stream_buffer_set_t *buf_set);
36
Alex Raybcaf7882013-02-28 16:04:35 -080037 void setUsage(uint32_t usage);
38 void setMaxBuffers(uint32_t max_buffers);
39
40 int getType();
41 bool isInputType();
42 bool isOutputType();
Alex Ray8a8f86b2013-03-01 01:32:21 -080043 bool isRegistered();
Alex Ray69f1f912013-10-21 00:46:44 -070044 const char* typeToString(int type);
45 const char* formatToString(int format);
46 void dump(int fd);
Alex Raybcaf7882013-02-28 16:04:35 -080047
48 // This stream is being reused. Used in stream configuration passes
49 bool mReuse;
50
51 private:
Alex Ray8a8f86b2013-03-01 01:32:21 -080052 // Clean up buffer state. must be called with mMutex held.
53 void unregisterBuffers_L();
54
Alex Raybcaf7882013-02-28 16:04:35 -080055 // The camera device id this stream belongs to
56 const int mId;
57 // Handle to framework's stream, used as a cookie for buffers
Alex Ray2b286da2013-05-29 15:08:29 -070058 camera3_stream_t *mStream;
Alex Raybcaf7882013-02-28 16:04:35 -080059 // Stream type: CAMERA3_STREAM_* (see <hardware/camera3.h>)
60 const int mType;
61 // Width in pixels of the buffers in this stream
62 const uint32_t mWidth;
63 // Height in pixels of the buffers in this stream
64 const uint32_t mHeight;
65 // Gralloc format: HAL_PIXEL_FORMAT_* (see <system/graphics.h>)
66 const int mFormat;
67 // Gralloc usage mask : GRALLOC_USAGE_* (see <hardware/gralloc.h>)
68 uint32_t mUsage;
69 // Max simultaneous in-flight buffers for this stream
70 uint32_t mMaxBuffers;
71 // Buffers have been registered for this stream and are ready
72 bool mRegistered;
Alex Ray8a8f86b2013-03-01 01:32:21 -080073 // Array of handles to buffers currently in use by the stream
74 buffer_handle_t **mBuffers;
75 // Number of buffers in mBuffers
76 unsigned int mNumBuffers;
Alex Raybcaf7882013-02-28 16:04:35 -080077 // Lock protecting the Stream object for modifications
78 pthread_mutex_t mMutex;
79};
80} // namespace default_camera_hal
81
82#endif // STREAM_H_