Camera3IOStreamBase.h revision b2f5b19e5b6e1408a259add23dba91037756a943
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
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:
35    Camera3IOStreamBase(int id, camera3_stream_type_t type,
36            uint32_t width, uint32_t height, size_t maxSize, int format);
37
38  public:
39
40    virtual ~Camera3IOStreamBase();
41
42    /**
43     * Camera3Stream interface
44     */
45
46    virtual status_t waitUntilIdle(nsecs_t timeout);
47    virtual void     dump(int fd, const Vector<String16> &args) const;
48
49  protected:
50    size_t            mTotalBufferCount;
51    // sum of input and output buffers that are currently acquired by HAL
52    size_t            mDequeuedBufferCount;
53    Condition         mBufferReturnedSignal;
54    uint32_t          mFrameCount;
55    // Last received output buffer's timestamp
56    nsecs_t           mLastTimestamp;
57
58    // The merged release fence for all returned buffers
59    sp<Fence>         mCombinedFence;
60
61    status_t         returnAnyBufferLocked(
62            const camera3_stream_buffer &buffer,
63            nsecs_t timestamp,
64            bool output);
65
66    virtual status_t returnBufferCheckedLocked(
67            const camera3_stream_buffer &buffer,
68            nsecs_t timestamp,
69            bool output,
70            /*out*/
71            sp<Fence> *releaseFenceOut) = 0;
72
73    /**
74     * Internal Camera3Stream interface
75     */
76    virtual bool     hasOutstandingBuffersLocked() const;
77
78    virtual size_t   getBufferCountLocked();
79
80    virtual status_t getEndpointUsage(uint32_t *usage) = 0;
81
82    status_t getBufferPreconditionCheckLocked() const;
83    status_t returnBufferPreconditionCheckLocked() const;
84
85    // State check only
86    virtual status_t configureQueueLocked();
87    // State checks only
88    virtual status_t disconnectLocked();
89
90    // Hand out the buffer to a native location,
91    //   incrementing the internal refcount and dequeued buffer count
92    void handoutBufferLocked(camera3_stream_buffer &buffer,
93                             buffer_handle_t *handle,
94                             int acquire_fence,
95                             int release_fence,
96                             camera3_buffer_status_t status);
97
98}; // class Camera3IOStreamBase
99
100} // namespace camera3
101
102} // namespace android
103
104#endif
105