blob: f2b1536cfc40dd3753daef02706fef7c918e107c [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,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080041 int dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
42 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070043
44 public:
45
46 virtual ~Camera3IOStreamBase();
47
48 /**
49 * Camera3Stream interface
50 */
51
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070052 virtual void dump(int fd, const Vector<String16> &args) const;
53
Shuzhen Wang316781a2020-08-18 18:11:01 -070054 int getMaxTotalBuffers() const { return mTotalBufferCount; }
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070055 protected:
56 size_t mTotalBufferCount;
57 // sum of input and output buffers that are currently acquired by HAL
Zhijun He6adc9cc2014-04-15 14:09:55 -070058 size_t mHandoutTotalBufferCount;
59 // number of output buffers that are currently acquired by HAL. This will be
60 // Redundant when camera3 streams are no longer bidirectional streams.
61 size_t mHandoutOutputBufferCount;
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070062 uint32_t mFrameCount;
63 // Last received output buffer's timestamp
64 nsecs_t mLastTimestamp;
65
66 // The merged release fence for all returned buffers
67 sp<Fence> mCombinedFence;
68
69 status_t returnAnyBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -070070 const camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070071 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -070072 nsecs_t readoutTimestamp,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070073 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -070074 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070075 const std::vector<size_t>& surface_ids = std::vector<size_t>());
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070076
77 virtual status_t returnBufferCheckedLocked(
Emilian Peevf4816702020-04-03 15:44:51 -070078 const camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070079 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -070080 nsecs_t readoutTimestamp,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070081 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -070082 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070083 const std::vector<size_t>& surface_ids,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -070084 /*out*/
85 sp<Fence> *releaseFenceOut) = 0;
86
87 /**
88 * Internal Camera3Stream interface
89 */
90 virtual bool hasOutstandingBuffersLocked() const;
91
92 virtual size_t getBufferCountLocked();
93
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -070094 virtual size_t getHandoutOutputBufferCountLocked() const;
Zhijun He6adc9cc2014-04-15 14:09:55 -070095
96 virtual size_t getHandoutInputBufferCountLocked();
97
Emilian Peev050f5dc2017-05-18 14:43:56 +010098 virtual status_t getEndpointUsage(uint64_t *usage) const = 0;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -070099
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700100 status_t getBufferPreconditionCheckLocked() const;
101 status_t returnBufferPreconditionCheckLocked() const;
102
103 // State check only
104 virtual status_t configureQueueLocked();
105 // State checks only
106 virtual status_t disconnectLocked();
107
108 // Hand out the buffer to a native location,
109 // incrementing the internal refcount and dequeued buffer count
Emilian Peevf4816702020-04-03 15:44:51 -0700110 void handoutBufferLocked(camera_stream_buffer &buffer,
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700111 buffer_handle_t *handle,
112 int acquire_fence,
113 int release_fence,
Emilian Peevf4816702020-04-03 15:44:51 -0700114 camera_buffer_status_t status,
Zhijun He6adc9cc2014-04-15 14:09:55 -0700115 bool output);
Igor Murashkinae3d0ba2013-05-08 18:03:15 -0700116
117}; // class Camera3IOStreamBase
118
119} // namespace camera3
120
121} // namespace android
122
123#endif