blob: b863e7f09ce178ee9f2070dacc6392f2e77626ef [file] [log] [blame]
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -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 ANDROID_SERVERS_CAMERA3_ZSL_STREAM_H
18#define ANDROID_SERVERS_CAMERA3_ZSL_STREAM_H
19
20#include <utils/RefBase.h>
21#include <gui/Surface.h>
Igor Murashkinae500e52013-04-22 14:03:54 -070022#include <gui/RingBufferConsumer.h>
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080023
24#include "Camera3Stream.h"
Igor Murashkinae500e52013-04-22 14:03:54 -070025#include "Camera3OutputStreamInterface.h"
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080026
27namespace android {
28
29namespace camera3 {
30
31/**
32 * A class for managing a single opaque ZSL stream to/from the camera device.
33 * This acts as a bidirectional stream at the HAL layer, caching and discarding
34 * most output buffers, and when directed, pushes a buffer back to the HAL for
35 * processing.
36 */
Igor Murashkinae500e52013-04-22 14:03:54 -070037class Camera3ZslStream :
38 public Camera3Stream,
39 public Camera3OutputStreamInterface {
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080040 public:
41 /**
42 * Set up a ZSL stream of a given resolution. Depth is the number of buffers
43 * cached within the stream that can be retrieved for input.
44 */
45 Camera3ZslStream(int id, uint32_t width, uint32_t height, int depth);
Igor Murashkinae500e52013-04-22 14:03:54 -070046 ~Camera3ZslStream();
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080047
48 virtual status_t waitUntilIdle(nsecs_t timeout);
49 virtual void dump(int fd, const Vector<String16> &args) const;
50
Igor Murashkinae500e52013-04-22 14:03:54 -070051 enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE };
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080052
53 /**
Igor Murashkinae500e52013-04-22 14:03:54 -070054 * Locate a buffer matching this timestamp in the RingBufferConsumer,
55 * and mark it to be queued at the next getInputBufferLocked invocation.
56 *
57 * Errors: Returns NO_BUFFER_AVAILABLE if we could not find a match.
58 *
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080059 */
Igor Murashkinae500e52013-04-22 14:03:54 -070060 status_t enqueueInputBufferByTimestamp(nsecs_t timestamp,
61 nsecs_t* actualTimestamp);
62
63 /**
64 * Clears the buffers that can be used by enqueueInputBufferByTimestamp
65 */
66 status_t clearInputRingBuffer();
67
68 /**
69 * Camera3OutputStreamInterface implementation
70 */
71 status_t setTransform(int transform);
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080072
73 private:
74
75 int mDepth;
Igor Murashkinae500e52013-04-22 14:03:54 -070076 // Input buffers pending to be queued into HAL
77 List<sp<RingBufferConsumer::PinnedBufferItem> > mInputBufferQueue;
78 sp<RingBufferConsumer> mProducer;
79 sp<ANativeWindow> mConsumer;
80
81 // Input buffers in flight to HAL
82 Vector<sp<RingBufferConsumer::PinnedBufferItem> > mBuffersInFlight;
83 size_t mTotalBufferCount;
84 // sum of input and output buffers that are currently acquired by HAL
85 size_t mDequeuedBufferCount;
86 Condition mBufferReturnedSignal;
87 uint32_t mFrameCount;
88 // Last received output buffer's timestamp
89 nsecs_t mLastTimestamp;
90
91 // The merged release fence for all returned buffers
92 sp<Fence> mCombinedFence;
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080093
94 /**
95 * Camera3Stream interface
96 */
97
98 // getBuffer/returnBuffer operate the output stream side of the ZslStream.
99 virtual status_t getBufferLocked(camera3_stream_buffer *buffer);
100 virtual status_t returnBufferLocked(const camera3_stream_buffer &buffer,
101 nsecs_t timestamp);
Igor Murashkinae500e52013-04-22 14:03:54 -0700102 // getInputBuffer/returnInputBuffer operate the input stream side of the
103 // ZslStream.
104 virtual status_t getInputBufferLocked(camera3_stream_buffer *buffer);
105 virtual status_t returnInputBufferLocked(
106 const camera3_stream_buffer &buffer);
107
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -0800108 virtual bool hasOutstandingBuffersLocked() const;
109 virtual status_t disconnectLocked();
110
Igor Murashkinae500e52013-04-22 14:03:54 -0700111 virtual status_t configureQueueLocked();
112 virtual size_t getBufferCountLocked();
113
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -0800114}; // class Camera3ZslStream
115
116}; // namespace camera3
117
118}; // namespace android
119
120#endif