• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
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 
25 namespace android {
26 
27 namespace camera3 {
28 
29 /**
30  * A base class for managing a single stream of I/O data from the camera device.
31  */
32 class Camera3IOStreamBase :
33         public Camera3Stream {
34   protected:
35     Camera3IOStreamBase(int id, camera3_stream_type_t type,
36             uint32_t width, uint32_t height, size_t maxSize, int format,
37             android_dataspace dataSpace, camera3_stream_rotation_t rotation,
38             int setId = CAMERA3_STREAM_SET_ID_INVALID);
39 
40   public:
41 
42     virtual ~Camera3IOStreamBase();
43 
44     /**
45      * Camera3Stream interface
46      */
47 
48     virtual void     dump(int fd, const Vector<String16> &args) const;
49 
50   protected:
51     size_t            mTotalBufferCount;
52     // sum of input and output buffers that are currently acquired by HAL
53     size_t            mHandoutTotalBufferCount;
54     // number of output buffers that are currently acquired by HAL. This will be
55     // Redundant when camera3 streams are no longer bidirectional streams.
56     size_t            mHandoutOutputBufferCount;
57     Condition         mBufferReturnedSignal;
58     uint32_t          mFrameCount;
59     // Last received output buffer's timestamp
60     nsecs_t           mLastTimestamp;
61 
62     // The merged release fence for all returned buffers
63     sp<Fence>         mCombinedFence;
64 
65     status_t         returnAnyBufferLocked(
66             const camera3_stream_buffer &buffer,
67             nsecs_t timestamp,
68             bool output);
69 
70     virtual status_t returnBufferCheckedLocked(
71             const camera3_stream_buffer &buffer,
72             nsecs_t timestamp,
73             bool output,
74             /*out*/
75             sp<Fence> *releaseFenceOut) = 0;
76 
77     /**
78      * Internal Camera3Stream interface
79      */
80     virtual bool     hasOutstandingBuffersLocked() const;
81 
82     virtual size_t   getBufferCountLocked();
83 
84     virtual size_t   getHandoutOutputBufferCountLocked();
85 
86     virtual size_t   getHandoutInputBufferCountLocked();
87 
88     virtual status_t getEndpointUsage(uint64_t *usage) const = 0;
89 
90     status_t getBufferPreconditionCheckLocked() const;
91     status_t returnBufferPreconditionCheckLocked() const;
92 
93     // State check only
94     virtual status_t configureQueueLocked();
95     // State checks only
96     virtual status_t disconnectLocked();
97 
98     // Hand out the buffer to a native location,
99     //   incrementing the internal refcount and dequeued buffer count
100     void handoutBufferLocked(camera3_stream_buffer &buffer,
101                              buffer_handle_t *handle,
102                              int acquire_fence,
103                              int release_fence,
104                              camera3_buffer_status_t status,
105                              bool output);
106 
107 }; // class Camera3IOStreamBase
108 
109 } // namespace camera3
110 
111 } // namespace android
112 
113 #endif
114