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