blob: 90c8a7b102e6bb83baa3c84e2f9c21bacd6481b4 [file] [log] [blame]
Igor Murashkinae3d0ba2013-05-08 18:03:15 -07001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Igor Murashkinae3d0ba2013-05-08 18:03:15 -07003 *
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:
Emilian Peevf4816702020-04-03 15:44:51 -070035 Camera3IOStreamBase(int id, camera_stream_type_t type,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080036 uint32_t width, uint32_t height, size_t maxSize, int format,
Emilian Peevf4816702020-04-03 15:44:51 -070037 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -080038 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080039 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Shuzhen Wang83bff122020-11-20 15:51:39 -080040 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070041
42 public:
43
44 virtual ~Camera3IOStreamBase();
45
46 /**
47 * Camera3Stream interface
48 */
49
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070050 virtual void dump(int fd, const Vector<String16> &args) const;
51
Shuzhen Wang316781a2020-08-18 18:11:01 -070052 int getMaxTotalBuffers() const { return mTotalBufferCount; }
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070053 protected:
54 size_t mTotalBufferCount;
55 // sum of input and output buffers that are currently acquired by HAL
Zhijun He6adc9cc2014-04-15 14:09:55 -070056 size_t mHandoutTotalBufferCount;
57 // number of output buffers that are currently acquired by HAL. This will be
58 // Redundant when camera3 streams are no longer bidirectional streams.
59 size_t mHandoutOutputBufferCount;
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070060 uint32_t mFrameCount;
61 // Last received output buffer's timestamp
62 nsecs_t mLastTimestamp;
63
64 // The merged release fence for all returned buffers
65 sp<Fence> mCombinedFence;
66
67 status_t returnAnyBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -070068 const camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070069 nsecs_t timestamp,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070070 bool output,
71 const std::vector<size_t>& surface_ids = std::vector<size_t>());
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070072
73 virtual status_t returnBufferCheckedLocked(
Emilian Peevf4816702020-04-03 15:44:51 -070074 const camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070075 nsecs_t timestamp,
76 bool output,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070077 const std::vector<size_t>& surface_ids,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070078 /*out*/
79 sp<Fence> *releaseFenceOut) = 0;
80
81 /**
82 * Internal Camera3Stream interface
83 */
84 virtual bool hasOutstandingBuffersLocked() const;
85
86 virtual size_t getBufferCountLocked();
87
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -070088 virtual size_t getHandoutOutputBufferCountLocked() const;
Zhijun He6adc9cc2014-04-15 14:09:55 -070089
90 virtual size_t getHandoutInputBufferCountLocked();
91
Emilian Peev050f5dc2017-05-18 14:43:56 +010092 virtual status_t getEndpointUsage(uint64_t *usage) const = 0;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -070093
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070094 status_t getBufferPreconditionCheckLocked() const;
95 status_t returnBufferPreconditionCheckLocked() const;
96
97 // State check only
98 virtual status_t configureQueueLocked();
99 // State checks only
100 virtual status_t disconnectLocked();
101
102 // Hand out the buffer to a native location,
103 // incrementing the internal refcount and dequeued buffer count
Emilian Peevf4816702020-04-03 15:44:51 -0700104 void handoutBufferLocked(camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700105 buffer_handle_t *handle,
106 int acquire_fence,
107 int release_fence,
Emilian Peevf4816702020-04-03 15:44:51 -0700108 camera_buffer_status_t status,
Zhijun He6adc9cc2014-04-15 14:09:55 -0700109 bool output);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700110
111}; // class Camera3IOStreamBase
112
113} // namespace camera3
114
115} // namespace android
116
117#endif