blob: a35c290a2aac8538f7a0cdc1986766ded152a739 [file] [log] [blame]
Igor Murashkinae3d0ba2013-05-08 18:03:15 -07001/*
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_IO_STREAM_BASE_H
18#define ANDROID_SERVERS_CAMERA3_IO_STREAM_BASE_H
19
20#include <utils/RefBase.h>
21#include <gui/Surface.h>
22
23#include "Camera3Stream.h"
24
25namespace android {
26
27namespace camera3 {
28
29/**
30 * A base class for managing a single stream of I/O data from the camera device.
31 */
32class Camera3IOStreamBase :
33 public Camera3Stream {
34 protected:
35 Camera3IOStreamBase(int id, camera3_stream_type_t type,
36 uint32_t width, uint32_t height, size_t maxSize, int format);
37
38 public:
39
40 virtual ~Camera3IOStreamBase();
41
42 /**
43 * Camera3Stream interface
44 */
45
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070046 virtual void dump(int fd, const Vector<String16> &args) const;
47
48 protected:
49 size_t mTotalBufferCount;
50 // sum of input and output buffers that are currently acquired by HAL
Zhijun He6adc9cc2014-04-15 14:09:55 -070051 size_t mHandoutTotalBufferCount;
52 // number of output buffers that are currently acquired by HAL. This will be
53 // Redundant when camera3 streams are no longer bidirectional streams.
54 size_t mHandoutOutputBufferCount;
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070055 Condition mBufferReturnedSignal;
56 uint32_t mFrameCount;
57 // Last received output buffer's timestamp
58 nsecs_t mLastTimestamp;
59
60 // The merged release fence for all returned buffers
61 sp<Fence> mCombinedFence;
62
63 status_t returnAnyBufferLocked(
64 const camera3_stream_buffer &buffer,
65 nsecs_t timestamp,
66 bool output);
67
68 virtual status_t returnBufferCheckedLocked(
69 const camera3_stream_buffer &buffer,
70 nsecs_t timestamp,
71 bool output,
72 /*out*/
73 sp<Fence> *releaseFenceOut) = 0;
74
75 /**
76 * Internal Camera3Stream interface
77 */
78 virtual bool hasOutstandingBuffersLocked() const;
79
80 virtual size_t getBufferCountLocked();
81
Zhijun He6adc9cc2014-04-15 14:09:55 -070082 virtual size_t getHandoutOutputBufferCountLocked();
83
84 virtual size_t getHandoutInputBufferCountLocked();
85
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -070086 virtual status_t getEndpointUsage(uint32_t *usage) = 0;
87
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070088 status_t getBufferPreconditionCheckLocked() const;
89 status_t returnBufferPreconditionCheckLocked() const;
90
91 // State check only
92 virtual status_t configureQueueLocked();
93 // State checks only
94 virtual status_t disconnectLocked();
95
96 // Hand out the buffer to a native location,
97 // incrementing the internal refcount and dequeued buffer count
98 void handoutBufferLocked(camera3_stream_buffer &buffer,
99 buffer_handle_t *handle,
100 int acquire_fence,
101 int release_fence,
Zhijun He6adc9cc2014-04-15 14:09:55 -0700102 camera3_buffer_status_t status,
103 bool output);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700104
105}; // class Camera3IOStreamBase
106
107} // namespace camera3
108
109} // namespace android
110
111#endif