blob: 83d43506aacc8f850e4d7b9e836639913b3f534b [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,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080036 uint32_t width, uint32_t height, size_t maxSize, int format,
37 android_dataspace dataSpace);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070038
39 public:
40
41 virtual ~Camera3IOStreamBase();
42
43 /**
44 * Camera3Stream interface
45 */
46
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070047 virtual void dump(int fd, const Vector<String16> &args) const;
48
49 protected:
50 size_t mTotalBufferCount;
51 // sum of input and output buffers that are currently acquired by HAL
Zhijun He6adc9cc2014-04-15 14:09:55 -070052 size_t mHandoutTotalBufferCount;
53 // number of output buffers that are currently acquired by HAL. This will be
54 // Redundant when camera3 streams are no longer bidirectional streams.
55 size_t mHandoutOutputBufferCount;
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070056 Condition mBufferReturnedSignal;
57 uint32_t mFrameCount;
58 // Last received output buffer's timestamp
59 nsecs_t mLastTimestamp;
60
61 // The merged release fence for all returned buffers
62 sp<Fence> mCombinedFence;
63
64 status_t returnAnyBufferLocked(
65 const camera3_stream_buffer &buffer,
66 nsecs_t timestamp,
67 bool output);
68
69 virtual status_t returnBufferCheckedLocked(
70 const camera3_stream_buffer &buffer,
71 nsecs_t timestamp,
72 bool output,
73 /*out*/
74 sp<Fence> *releaseFenceOut) = 0;
75
76 /**
77 * Internal Camera3Stream interface
78 */
79 virtual bool hasOutstandingBuffersLocked() const;
80
81 virtual size_t getBufferCountLocked();
82
Zhijun He6adc9cc2014-04-15 14:09:55 -070083 virtual size_t getHandoutOutputBufferCountLocked();
84
85 virtual size_t getHandoutInputBufferCountLocked();
86
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -070087 virtual status_t getEndpointUsage(uint32_t *usage) = 0;
88
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070089 status_t getBufferPreconditionCheckLocked() const;
90 status_t returnBufferPreconditionCheckLocked() const;
91
92 // State check only
93 virtual status_t configureQueueLocked();
94 // State checks only
95 virtual status_t disconnectLocked();
96
97 // Hand out the buffer to a native location,
98 // incrementing the internal refcount and dequeued buffer count
99 void handoutBufferLocked(camera3_stream_buffer &buffer,
100 buffer_handle_t *handle,
101 int acquire_fence,
102 int release_fence,
Zhijun He6adc9cc2014-04-15 14:09:55 -0700103 camera3_buffer_status_t status,
104 bool output);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700105
106}; // class Camera3IOStreamBase
107
108} // namespace camera3
109
110} // namespace android
111
112#endif