blob: 1086955184602ec7137bd13aacd384d2ef2ce4fb [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,
Austin Borger0fb3ad92023-06-01 16:51:35 -070038 const std::string& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080039 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev2295df72021-11-12 18:14:10 -080040 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -080041 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -080042 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -080043 bool deviceTimeBaseIsRealtime = false,
44 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070045
46 public:
47
48 virtual ~Camera3IOStreamBase();
49
50 /**
51 * Camera3Stream interface
52 */
53
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070054 virtual void dump(int fd, const Vector<String16> &args) const;
55
Shuzhen Wang316781a2020-08-18 18:11:01 -070056 int getMaxTotalBuffers() const { return mTotalBufferCount; }
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070057 protected:
58 size_t mTotalBufferCount;
Shuzhen Wangc2352702022-09-06 18:36:31 -070059 // The maximum number of cached buffers allowed for this stream
60 size_t mMaxCachedBufferCount;
61
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070062 // sum of input and output buffers that are currently acquired by HAL
Zhijun He6adc9cc2014-04-15 14:09:55 -070063 size_t mHandoutTotalBufferCount;
64 // number of output buffers that are currently acquired by HAL. This will be
65 // Redundant when camera3 streams are no longer bidirectional streams.
66 size_t mHandoutOutputBufferCount;
Shuzhen Wangc2352702022-09-06 18:36:31 -070067 // number of cached output buffers that are currently queued in the camera
68 // server but not yet queued to the buffer queue.
69 size_t mCachedOutputBufferCount;
70
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070071 uint32_t mFrameCount;
72 // Last received output buffer's timestamp
73 nsecs_t mLastTimestamp;
74
75 // The merged release fence for all returned buffers
76 sp<Fence> mCombinedFence;
77
78 status_t returnAnyBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -070079 const camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070080 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -070081 nsecs_t readoutTimestamp,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070082 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -070083 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070084 const std::vector<size_t>& surface_ids = std::vector<size_t>());
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070085
86 virtual status_t returnBufferCheckedLocked(
Emilian Peevf4816702020-04-03 15:44:51 -070087 const camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070088 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -070089 nsecs_t readoutTimestamp,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070090 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -070091 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070092 const std::vector<size_t>& surface_ids,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070093 /*out*/
94 sp<Fence> *releaseFenceOut) = 0;
95
96 /**
97 * Internal Camera3Stream interface
98 */
99 virtual bool hasOutstandingBuffersLocked() const;
100
101 virtual size_t getBufferCountLocked();
102
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700103 virtual size_t getHandoutOutputBufferCountLocked() const;
Zhijun He6adc9cc2014-04-15 14:09:55 -0700104
105 virtual size_t getHandoutInputBufferCountLocked();
106
Shuzhen Wangc2352702022-09-06 18:36:31 -0700107 virtual size_t getCachedOutputBufferCountLocked() const;
108 virtual size_t getMaxCachedOutputBuffersLocked() const;
109
Emilian Peev050f5dc2017-05-18 14:43:56 +0100110 virtual status_t getEndpointUsage(uint64_t *usage) const = 0;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700111
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700112 status_t getBufferPreconditionCheckLocked() const;
113 status_t returnBufferPreconditionCheckLocked() const;
114
115 // State check only
116 virtual status_t configureQueueLocked();
117 // State checks only
118 virtual status_t disconnectLocked();
119
120 // Hand out the buffer to a native location,
121 // incrementing the internal refcount and dequeued buffer count
Emilian Peevf4816702020-04-03 15:44:51 -0700122 void handoutBufferLocked(camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700123 buffer_handle_t *handle,
124 int acquire_fence,
125 int release_fence,
Emilian Peevf4816702020-04-03 15:44:51 -0700126 camera_buffer_status_t status,
Zhijun He6adc9cc2014-04-15 14:09:55 -0700127 bool output);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700128
129}; // class Camera3IOStreamBase
130
131} // namespace camera3
132
133} // namespace android
134
135#endif