1 /*
2  * Copyright (C) 2012 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_CAMERA_CAMERA2_STREAMINGPROCESSOR_H
18 #define ANDROID_SERVERS_CAMERA_CAMERA2_STREAMINGPROCESSOR_H
19 
20 #include <utils/Mutex.h>
21 #include <utils/String16.h>
22 #include <gui/BufferItemConsumer.h>
23 
24 #include "camera/CameraMetadata.h"
25 
26 namespace android {
27 
28 class Camera2Client;
29 class CameraDeviceBase;
30 class IMemory;
31 
32 namespace camera2 {
33 
34 struct Parameters;
35 class Camera2Heap;
36 
37 /**
38  * Management and processing for preview and recording streams
39  */
40 class StreamingProcessor : public virtual VirtualLightRefBase {
41   public:
42     explicit StreamingProcessor(sp<Camera2Client> client);
43     ~StreamingProcessor();
44 
45     status_t setPreviewWindow(const sp<Surface>& window);
46     status_t setRecordingWindow(const sp<Surface>& window);
47 
48     bool haveValidPreviewWindow() const;
49     bool haveValidRecordingWindow() const;
50 
51     status_t updatePreviewRequest(const Parameters &params);
52     status_t updatePreviewStream(const Parameters &params);
53     status_t deletePreviewStream();
54     int getPreviewStreamId() const;
55 
56     status_t updateRecordingRequest(const Parameters &params);
57     // If needsUpdate is set to true, a updateRecordingStream call with params will recreate
58     // recording stream
59     status_t recordingStreamNeedsUpdate(const Parameters &params, bool *needsUpdate);
60     status_t updateRecordingStream(const Parameters &params);
61     status_t deleteRecordingStream();
62     int getRecordingStreamId() const;
63 
64     enum StreamType {
65         NONE,
66         PREVIEW,
67         RECORD
68     };
69     status_t startStream(StreamType type,
70             const Vector<int32_t> &outputStreams);
71 
72     // Toggle between paused and unpaused. Stream must be started first.
73     status_t togglePauseStream(bool pause);
74 
75     status_t stopStream();
76 
77     // Returns the request ID for the currently streaming request
78     // Returns 0 if there is no active request.
79     status_t getActiveRequestId() const;
80     status_t incrementStreamingIds();
81 
82     status_t dump(int fd, const Vector<String16>& args);
83 
84   private:
85     mutable Mutex mMutex;
86 
87     enum {
88         NO_STREAM = -1
89     };
90 
91     wp<Camera2Client> mClient;
92     wp<CameraDeviceBase> mDevice;
93     int mId;
94 
95     StreamType mActiveRequest;
96     bool mPaused;
97 
98     Vector<int32_t> mActiveStreamIds;
99 
100     // Preview-related members
101     int32_t mPreviewRequestId;
102     int mPreviewStreamId;
103     CameraMetadata mPreviewRequest;
104     sp<Surface> mPreviewWindow;
105 
106     int32_t mRecordingRequestId;
107     int mRecordingStreamId;
108     sp<Surface>  mRecordingWindow;
109     CameraMetadata mRecordingRequest;
110 };
111 
112 
113 }; // namespace camera2
114 }; // namespace android
115 
116 #endif
117