blob: 6af08755401711ba2b18ae2bdac06a47b56cfbfd [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,
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,
Austin Borger9e2b27c2022-07-15 11:27:24 -070044 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
45 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070046
47 public:
48
49 virtual ~Camera3IOStreamBase();
50
51 /**
52 * Camera3Stream interface
53 */
54
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070055 virtual void dump(int fd, const Vector<String16> &args) const;
56
Shuzhen Wang316781a2020-08-18 18:11:01 -070057 int getMaxTotalBuffers() const { return mTotalBufferCount; }
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070058 protected:
59 size_t mTotalBufferCount;
Shuzhen Wangc2352702022-09-06 18:36:31 -070060 // The maximum number of cached buffers allowed for this stream
61 size_t mMaxCachedBufferCount;
62
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070063 // sum of input and output buffers that are currently acquired by HAL
Zhijun He6adc9cc2014-04-15 14:09:55 -070064 size_t mHandoutTotalBufferCount;
65 // number of output buffers that are currently acquired by HAL. This will be
66 // Redundant when camera3 streams are no longer bidirectional streams.
67 size_t mHandoutOutputBufferCount;
Shuzhen Wangc2352702022-09-06 18:36:31 -070068 // number of cached output buffers that are currently queued in the camera
69 // server but not yet queued to the buffer queue.
70 size_t mCachedOutputBufferCount;
71
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070072 uint32_t mFrameCount;
73 // Last received output buffer's timestamp
74 nsecs_t mLastTimestamp;
75
76 // The merged release fence for all returned buffers
77 sp<Fence> mCombinedFence;
78
79 status_t returnAnyBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -070080 const camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070081 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -070082 nsecs_t readoutTimestamp,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070083 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -070084 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070085 const std::vector<size_t>& surface_ids = std::vector<size_t>());
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070086
87 virtual status_t returnBufferCheckedLocked(
Emilian Peevf4816702020-04-03 15:44:51 -070088 const camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070089 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -070090 nsecs_t readoutTimestamp,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070091 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -070092 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070093 const std::vector<size_t>& surface_ids,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070094 /*out*/
95 sp<Fence> *releaseFenceOut) = 0;
96
97 /**
98 * Internal Camera3Stream interface
99 */
100 virtual bool hasOutstandingBuffersLocked() const;
101
102 virtual size_t getBufferCountLocked();
103
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700104 virtual size_t getHandoutOutputBufferCountLocked() const;
Zhijun He6adc9cc2014-04-15 14:09:55 -0700105
106 virtual size_t getHandoutInputBufferCountLocked();
107
Shuzhen Wangc2352702022-09-06 18:36:31 -0700108 virtual size_t getCachedOutputBufferCountLocked() const;
109 virtual size_t getMaxCachedOutputBuffersLocked() const;
110
Emilian Peev050f5dc2017-05-18 14:43:56 +0100111 virtual status_t getEndpointUsage(uint64_t *usage) const = 0;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700112
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700113 status_t getBufferPreconditionCheckLocked() const;
114 status_t returnBufferPreconditionCheckLocked() const;
115
116 // State check only
117 virtual status_t configureQueueLocked();
118 // State checks only
119 virtual status_t disconnectLocked();
120
121 // Hand out the buffer to a native location,
122 // incrementing the internal refcount and dequeued buffer count
Emilian Peevf4816702020-04-03 15:44:51 -0700123 void handoutBufferLocked(camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700124 buffer_handle_t *handle,
125 int acquire_fence,
126 int release_fence,
Emilian Peevf4816702020-04-03 15:44:51 -0700127 camera_buffer_status_t status,
Zhijun He6adc9cc2014-04-15 14:09:55 -0700128 bool output);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700129
130}; // class Camera3IOStreamBase
131
132} // namespace camera3
133
134} // namespace android
135
136#endif