Camera3DummyStream.h revision 758c215374dba397dabe17b8e96dd38593c09dd7
1/*
2 * Copyright (C) 2014 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_DUMMY_STREAM_H
18#define ANDROID_SERVERS_CAMERA3_DUMMY_STREAM_H
19
20#include <utils/RefBase.h>
21#include <gui/Surface.h>
22
23#include "Camera3Stream.h"
24#include "Camera3IOStreamBase.h"
25#include "Camera3OutputStreamInterface.h"
26
27namespace android {
28namespace camera3 {
29
30/**
31 * A dummy output stream class, to be used as a placeholder when no valid
32 * streams are configured by the client.
33 * This is necessary because camera HAL v3.2 or older disallow configuring
34 * 0 output streams, while the public camera2 API allows for it.
35 */
36class Camera3DummyStream :
37        public Camera3IOStreamBase,
38        public Camera3OutputStreamInterface {
39
40  public:
41    /**
42     * Set up a dummy stream; doesn't actually connect to anything, and uses
43     * a default dummy format and size.
44     */
45    explicit Camera3DummyStream(int id);
46
47    virtual ~Camera3DummyStream();
48
49    /**
50     * Camera3Stream interface
51     */
52
53    virtual void     dump(int fd, const Vector<String16> &args) const;
54
55    status_t         setTransform(int transform);
56
57    virtual status_t detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd);
58
59    virtual status_t notifyRequestedSurfaces(uint32_t frame_number,
60            const std::vector<size_t>& surface_ids);
61
62    /**
63     * Return if this output stream is for video encoding.
64     */
65    bool isVideoStream() const;
66
67    /**
68     * Return if the consumer configuration of this stream is deferred.
69     */
70    virtual bool isConsumerConfigurationDeferred(size_t surface_id) const;
71
72    /**
73     * Set the consumer surfaces to the output stream.
74     */
75    virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers);
76
77  protected:
78
79    /**
80     * Note that we release the lock briefly in this function
81     */
82    virtual status_t returnBufferCheckedLocked(
83            const camera3_stream_buffer &buffer,
84            nsecs_t timestamp,
85            bool output,
86            /*out*/
87            sp<Fence> *releaseFenceOut);
88
89    virtual status_t disconnectLocked();
90
91  private:
92
93    // Default dummy parameters; 320x240 is a required size for all devices,
94    // otherwise act like a SurfaceView would.
95    static const int DUMMY_WIDTH = 320;
96    static const int DUMMY_HEIGHT = 240;
97    static const int DUMMY_FORMAT = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
98    static const android_dataspace DUMMY_DATASPACE = HAL_DATASPACE_UNKNOWN;
99    static const camera3_stream_rotation_t DUMMY_ROTATION = CAMERA3_STREAM_ROTATION_0;
100    static const uint32_t DUMMY_USAGE = GRALLOC_USAGE_HW_COMPOSER;
101
102    /**
103     * Internal Camera3Stream interface
104     */
105    virtual status_t getBufferLocked(camera3_stream_buffer *buffer);
106    virtual status_t returnBufferLocked(
107            const camera3_stream_buffer &buffer,
108            nsecs_t timestamp);
109
110    virtual status_t configureQueueLocked();
111
112    virtual status_t getEndpointUsage(uint32_t *usage) const;
113
114}; // class Camera3DummyStream
115
116} // namespace camera3
117
118} // namespace android
119
120#endif
121