blob: 97d86348cdedbbf5469084bbdf05333c32503590 [file] [log] [blame]
Ari Hausman-Cohen73442152016-06-08 15:50:49 -07001/*
2 * Copyright (C) 2016 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// Modified from hardware/libhardware/modules/camera/Stream.cpp
18
19#include <stdio.h>
20#include <hardware/camera3.h>
21#include <hardware/gralloc.h>
22#include <system/graphics.h>
23#include <utils/Mutex.h>
24
25//#define LOG_NDEBUG 0
26#define LOG_TAG "Stream"
27#include <cutils/log.h>
28
29#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
30#include <utils/Trace.h>
31
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070032#include "stream.h"
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070033
34namespace default_camera_hal {
35
36Stream::Stream(int id, camera3_stream_t *s)
37 : mReuse(false),
38 mId(id),
39 mStream(s),
40 mType(s->stream_type),
41 mWidth(s->width),
42 mHeight(s->height),
43 mFormat(s->format),
44 mUsage(0),
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -070045 mRotation(s->rotation),
46 mDataSpace(s->data_space),
47 mMaxBuffers(0)
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070048{
49}
50
51Stream::~Stream()
52{
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070053}
54
55void Stream::setUsage(uint32_t usage)
56{
57 android::Mutex::Autolock al(mLock);
58 if (usage != mUsage) {
59 mUsage = usage;
60 mStream->usage = usage;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070061 }
62}
63
64void Stream::setMaxBuffers(uint32_t max_buffers)
65{
66 android::Mutex::Autolock al(mLock);
67 if (max_buffers != mMaxBuffers) {
68 mMaxBuffers = max_buffers;
69 mStream->max_buffers = max_buffers;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070070 }
71}
72
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -070073void Stream::setDataSpace(android_dataspace_t data_space)
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070074{
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -070075 android::Mutex::Autolock al(mLock);
76 if (data_space != mDataSpace) {
77 mDataSpace = data_space;
78 mStream->data_space = data_space;
79 }
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070080}
81
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -070082bool Stream::isInputType() const
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070083{
84 return mType == CAMERA3_STREAM_INPUT ||
85 mType == CAMERA3_STREAM_BIDIRECTIONAL;
86}
87
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -070088bool Stream::isOutputType() const
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070089{
90 return mType == CAMERA3_STREAM_OUTPUT ||
91 mType == CAMERA3_STREAM_BIDIRECTIONAL;
92}
93
94const char* Stream::typeToString(int type)
95{
96 switch (type) {
97 case CAMERA3_STREAM_INPUT:
98 return "CAMERA3_STREAM_INPUT";
99 case CAMERA3_STREAM_OUTPUT:
100 return "CAMERA3_STREAM_OUTPUT";
101 case CAMERA3_STREAM_BIDIRECTIONAL:
102 return "CAMERA3_STREAM_BIDIRECTIONAL";
103 }
104 return "Invalid stream type!";
105}
106
107const char* Stream::formatToString(int format)
108{
109 // See <system/graphics.h> for full list
110 switch (format) {
111 case HAL_PIXEL_FORMAT_BGRA_8888:
112 return "BGRA 8888";
113 case HAL_PIXEL_FORMAT_RGBA_8888:
114 return "RGBA 8888";
115 case HAL_PIXEL_FORMAT_RGBX_8888:
116 return "RGBX 8888";
117 case HAL_PIXEL_FORMAT_RGB_888:
118 return "RGB 888";
119 case HAL_PIXEL_FORMAT_RGB_565:
120 return "RGB 565";
121 case HAL_PIXEL_FORMAT_Y8:
122 return "Y8";
123 case HAL_PIXEL_FORMAT_Y16:
124 return "Y16";
125 case HAL_PIXEL_FORMAT_YV12:
126 return "YV12";
127 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
128 return "NV16";
129 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
130 return "NV21";
131 case HAL_PIXEL_FORMAT_YCbCr_422_I:
132 return "YUY2";
133 case HAL_PIXEL_FORMAT_RAW10:
134 return "RAW10";
135 case HAL_PIXEL_FORMAT_RAW16:
136 return "RAW16";
137 case HAL_PIXEL_FORMAT_BLOB:
138 return "BLOB";
139 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
140 return "IMPLEMENTATION DEFINED";
141 case HAL_PIXEL_FORMAT_YCbCr_420_888:
142 return "FLEXIBLE YCbCr 420 888";
143 }
144 return "Invalid stream format!";
145}
146
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700147bool Stream::isValidReuseStream(int id, camera3_stream_t *s)
148{
149 if (id != mId) {
150 ALOGE("%s:%d: Invalid camera id for reuse. Got %d expect %d",
151 __func__, mId, id, mId);
152 return false;
153 }
154 if (s != mStream) {
155 ALOGE("%s:%d: Invalid stream handle for reuse. Got %p expect %p",
156 __func__, mId, s, mStream);
157 return false;
158 }
159 if (s->stream_type != mType) {
160 ALOGE("%s:%d: Mismatched type in reused stream. Got %s(%d) "
161 "expect %s(%d)", __func__, mId, typeToString(s->stream_type),
162 s->stream_type, typeToString(mType), mType);
163 return false;
164 }
165 if (s->format != mFormat) {
166 ALOGE("%s:%d: Mismatched format in reused stream. Got %s(%d) "
167 "expect %s(%d)", __func__, mId, formatToString(s->format),
168 s->format, formatToString(mFormat), mFormat);
169 return false;
170 }
171 if (s->width != mWidth) {
172 ALOGE("%s:%d: Mismatched width in reused stream. Got %d expect %d",
173 __func__, mId, s->width, mWidth);
174 return false;
175 }
176 if (s->height != mHeight) {
177 ALOGE("%s:%d: Mismatched height in reused stream. Got %d expect %d",
178 __func__, mId, s->height, mHeight);
179 return false;
180 }
181 return true;
182}
183
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700184void Stream::dump(int fd)
185{
186 android::Mutex::Autolock al(mLock);
187
188 dprintf(fd, "Stream ID: %d (%p)\n", mId, mStream);
189 dprintf(fd, "Stream Type: %s (%d)\n", typeToString(mType), mType);
190 dprintf(fd, "Width: %" PRIu32 " Height: %" PRIu32 "\n", mWidth, mHeight);
191 dprintf(fd, "Stream Format: %s (%d)", formatToString(mFormat), mFormat);
192 // ToDo: prettyprint usage mask flags
193 dprintf(fd, "Gralloc Usage Mask: %#" PRIx32 "\n", mUsage);
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -0700194 dprintf(fd, "Stream Rotation: %d\n", mRotation);
195 dprintf(fd, "Stream Dataspace: 0x%x\n", mDataSpace);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700196 dprintf(fd, "Max Buffer Count: %" PRIu32 "\n", mMaxBuffers);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700197}
198
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -0700199} // namespace default_camera_hal