blob: 5efbc52ac838d24a1d44498d6c2b1dd39f87ed8f [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>
Alex Ray55567642013-11-12 12:58:39 -080023#include <utils/Mutex.h>
Alex Raybcaf7882013-02-28 16:04:35 -080024
25namespace default_camera_hal {
26// Stream represents a single input or output stream for a camera device.
27class Stream {
28 public:
29 Stream(int id, camera3_stream_t *s);
30 ~Stream();
31
32 // validate that astream's parameters match this stream's parameters
33 bool isValidReuseStream(int id, camera3_stream_t *s);
34
Alex Ray8a8f86b2013-03-01 01:32:21 -080035 // Register buffers with hardware
36 int registerBuffers(const camera3_stream_buffer_set_t *buf_set);
37
Alex Raybcaf7882013-02-28 16:04:35 -080038 void setUsage(uint32_t usage);
39 void setMaxBuffers(uint32_t max_buffers);
40
41 int getType();
42 bool isInputType();
43 bool isOutputType();
Alex Ray8a8f86b2013-03-01 01:32:21 -080044 bool isRegistered();
Alex Ray69f1f912013-10-21 00:46:44 -070045 const char* typeToString(int type);
46 const char* formatToString(int format);
47 void dump(int fd);
Alex Raybcaf7882013-02-28 16:04:35 -080048
49 // This stream is being reused. Used in stream configuration passes
50 bool mReuse;
51
52 private:
Alex Ray55567642013-11-12 12:58:39 -080053 // Clean up buffer state. must be called with mLock held.
Alex Ray8a8f86b2013-03-01 01:32:21 -080054 void unregisterBuffers_L();
55
Alex Raybcaf7882013-02-28 16:04:35 -080056 // The camera device id this stream belongs to
57 const int mId;
58 // Handle to framework's stream, used as a cookie for buffers
Alex Ray2b286da2013-05-29 15:08:29 -070059 camera3_stream_t *mStream;
Alex Raybcaf7882013-02-28 16:04:35 -080060 // Stream type: CAMERA3_STREAM_* (see <hardware/camera3.h>)
61 const int mType;
62 // Width in pixels of the buffers in this stream
63 const uint32_t mWidth;
64 // Height in pixels of the buffers in this stream
65 const uint32_t mHeight;
66 // Gralloc format: HAL_PIXEL_FORMAT_* (see <system/graphics.h>)
67 const int mFormat;
68 // Gralloc usage mask : GRALLOC_USAGE_* (see <hardware/gralloc.h>)
69 uint32_t mUsage;
70 // Max simultaneous in-flight buffers for this stream
71 uint32_t mMaxBuffers;
72 // Buffers have been registered for this stream and are ready
73 bool mRegistered;
Alex Ray8a8f86b2013-03-01 01:32:21 -080074 // Array of handles to buffers currently in use by the stream
75 buffer_handle_t **mBuffers;
76 // Number of buffers in mBuffers
77 unsigned int mNumBuffers;
Alex Raybcaf7882013-02-28 16:04:35 -080078 // Lock protecting the Stream object for modifications
Alex Ray55567642013-11-12 12:58:39 -080079 android::Mutex mLock;
Alex Raybcaf7882013-02-28 16:04:35 -080080};
81} // namespace default_camera_hal
82
83#endif // STREAM_H_