blob: c7f4490b653902e8c7331dac9251251db82bd482 [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
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070024#include "Camera3OutputStream.h"
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080025
26namespace android {
27
28namespace camera3 {
29
30/**
31 * A class for managing a single opaque ZSL stream to/from the camera device.
32 * This acts as a bidirectional stream at the HAL layer, caching and discarding
33 * most output buffers, and when directed, pushes a buffer back to the HAL for
34 * processing.
35 */
Igor Murashkinae500e52013-04-22 14:03:54 -070036class Camera3ZslStream :
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070037 public Camera3OutputStream {
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080038 public:
39 /**
40 * Set up a ZSL stream of a given resolution. Depth is the number of buffers
41 * cached within the stream that can be retrieved for input.
42 */
43 Camera3ZslStream(int id, uint32_t width, uint32_t height, int depth);
Igor Murashkinae500e52013-04-22 14:03:54 -070044 ~Camera3ZslStream();
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080045
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080046 virtual void dump(int fd, const Vector<String16> &args) const;
47
Igor Murashkinae500e52013-04-22 14:03:54 -070048 enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE };
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080049
50 /**
Igor Murashkinae500e52013-04-22 14:03:54 -070051 * Locate a buffer matching this timestamp in the RingBufferConsumer,
52 * and mark it to be queued at the next getInputBufferLocked invocation.
53 *
54 * Errors: Returns NO_BUFFER_AVAILABLE if we could not find a match.
55 *
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080056 */
Igor Murashkinae500e52013-04-22 14:03:54 -070057 status_t enqueueInputBufferByTimestamp(nsecs_t timestamp,
58 nsecs_t* actualTimestamp);
59
60 /**
61 * Clears the buffers that can be used by enqueueInputBufferByTimestamp
62 */
63 status_t clearInputRingBuffer();
64
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070065 protected:
66
Igor Murashkinae500e52013-04-22 14:03:54 -070067 /**
68 * Camera3OutputStreamInterface implementation
69 */
70 status_t setTransform(int transform);
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080071
72 private:
73
74 int mDepth;
Igor Murashkinae500e52013-04-22 14:03:54 -070075 // Input buffers pending to be queued into HAL
76 List<sp<RingBufferConsumer::PinnedBufferItem> > mInputBufferQueue;
77 sp<RingBufferConsumer> mProducer;
Igor Murashkinae500e52013-04-22 14:03:54 -070078
79 // Input buffers in flight to HAL
80 Vector<sp<RingBufferConsumer::PinnedBufferItem> > mBuffersInFlight;
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080081
82 /**
83 * Camera3Stream interface
84 */
85
Igor Murashkinae500e52013-04-22 14:03:54 -070086 // getInputBuffer/returnInputBuffer operate the input stream side of the
87 // ZslStream.
88 virtual status_t getInputBufferLocked(camera3_stream_buffer *buffer);
89 virtual status_t returnInputBufferLocked(
90 const camera3_stream_buffer &buffer);
91
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070092 // Actual body to return either input or output buffers
93 virtual status_t returnBufferCheckedLocked(
94 const camera3_stream_buffer &buffer,
95 nsecs_t timestamp,
96 bool output,
97 /*out*/
98 sp<Fence> *releaseFenceOut);
Eino-Ville Talvala8be20f52013-03-06 16:20:06 -080099}; // class Camera3ZslStream
100
101}; // namespace camera3
102
103}; // namespace android
104
105#endif