blob: 08ae159d10775e6ebc9677929905103948ad53e3 [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#include <pthread.h>
18#include <hardware/camera3.h>
19#include <hardware/gralloc.h>
20#include <system/graphics.h>
21
22//#define LOG_NDEBUG 0
23#define LOG_TAG "Stream"
24#include <cutils/log.h>
25
26#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
27#include <cutils/trace.h>
28#include "ScopedTrace.h"
29
30#include "Stream.h"
31
32namespace default_camera_hal {
33
34Stream::Stream(int id, camera3_stream_t *s)
35 : mReuse(false),
36 mId(id),
37 mStream(s),
38 mType(s->stream_type),
39 mWidth(s->width),
40 mHeight(s->height),
41 mFormat(s->format),
42 mUsage(0),
43 mMaxBuffers(0),
44 mRegistered(false)
45{
46 // NULL (default) pthread mutex attributes
47 pthread_mutex_init(&mMutex, NULL);
48}
49
50Stream::~Stream()
51{
52 // TODO: unregister buffers from hw
53}
54
55void Stream::setUsage(uint32_t usage)
56{
57 pthread_mutex_lock(&mMutex);
58 if (usage != mUsage) {
59 mUsage = usage;
60 mRegistered = false;
61 // TODO: unregister buffers from hw
62 }
63 pthread_mutex_unlock(&mMutex);
64}
65
66void Stream::setMaxBuffers(uint32_t max_buffers)
67{
68 pthread_mutex_lock(&mMutex);
69 if (max_buffers != mMaxBuffers) {
70 mMaxBuffers = max_buffers;
71 mRegistered = false;
72 // TODO: unregister buffers from hw
73 }
74 pthread_mutex_unlock(&mMutex);
75}
76
77int Stream::getType()
78{
79 return mType;
80}
81
82bool Stream::isInputType()
83{
84 return mType & (CAMERA3_STREAM_INPUT | CAMERA3_STREAM_BIDIRECTIONAL);
85}
86
87bool Stream::isOutputType()
88{
89 return mType & (CAMERA3_STREAM_OUTPUT | CAMERA3_STREAM_BIDIRECTIONAL);
90}
91
92bool Stream::isValidReuseStream(int id, camera3_stream_t *s)
93{
94 if (id != mId) {
95 ALOGE("%s:%d: Invalid camera id for reuse. Got %d expect %d",
96 __func__, mId, id, mId);
97 return false;
98 }
99 if (s != mStream) {
100 ALOGE("%s:%d: Invalid stream handle for reuse. Got %p expect %p",
101 __func__, mId, s, mStream);
102 return false;
103 }
104 if (s->stream_type != mType) {
105 // TODO: prettyprint type string
106 ALOGE("%s:%d: Mismatched type in reused stream. Got %d expect %d",
107 __func__, mId, s->stream_type, mType);
108 return false;
109 }
110 if (s->format != mFormat) {
111 // TODO: prettyprint format string
112 ALOGE("%s:%d: Mismatched format in reused stream. Got %d expect %d",
113 __func__, mId, s->format, mFormat);
114 return false;
115 }
116 if (s->width != mWidth) {
117 ALOGE("%s:%d: Mismatched width in reused stream. Got %d expect %d",
118 __func__, mId, s->width, mWidth);
119 return false;
120 }
121 if (s->height != mHeight) {
122 ALOGE("%s:%d: Mismatched height in reused stream. Got %d expect %d",
123 __func__, mId, s->height, mHeight);
124 return false;
125 }
126 return true;
127}
128
129} // namespace default_camera_hal