• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "Parameters.h"
25 #include "CameraMetadata.h"
26 
27 namespace android {
28 
29 class Camera2Client;
30 class IMemory;
31 
32 namespace camera2 {
33 
34 class Camera2Heap;
35 
36 /**
37  * Management and processing for preview and recording streams
38  */
39 class StreamingProcessor: public BufferItemConsumer::FrameAvailableListener {
40   public:
41     StreamingProcessor(wp<Camera2Client> client);
42     ~StreamingProcessor();
43 
44     status_t setPreviewWindow(sp<ANativeWindow> window);
45 
46     bool haveValidPreviewWindow() const;
47 
48     status_t updatePreviewRequest(const Parameters &params);
49     status_t updatePreviewStream(const Parameters &params);
50     status_t deletePreviewStream();
51     int getPreviewStreamId() const;
52 
53     status_t setRecordingBufferCount(size_t count);
54     status_t updateRecordingRequest(const Parameters &params);
55     status_t updateRecordingStream(const Parameters &params);
56     status_t deleteRecordingStream();
57     int getRecordingStreamId() const;
58 
59     enum StreamType {
60         NONE,
61         PREVIEW,
62         RECORD
63     };
64     status_t startStream(StreamType type,
65             const Vector<uint8_t> &outputStreams);
66 
67     status_t stopStream();
68 
69     // Returns the request ID for the currently streaming request
70     // Returns 0 if there is no active request.
71     status_t getActiveRequestId() const;
72     status_t incrementStreamingIds();
73 
74     // Callback for new recording frames from HAL
75     virtual void onFrameAvailable();
76     // Callback from stagefright which returns used recording frames
77     void releaseRecordingFrame(const sp<IMemory>& mem);
78 
79     status_t dump(int fd, const Vector<String16>& args);
80 
81   private:
82     mutable Mutex mMutex;
83 
84     enum {
85         NO_STREAM = -1
86     };
87 
88     wp<Camera2Client> mClient;
89 
90     StreamType mActiveRequest;
91 
92     // Preview-related members
93     int32_t mPreviewRequestId;
94     int mPreviewStreamId;
95     CameraMetadata mPreviewRequest;
96     sp<ANativeWindow> mPreviewWindow;
97 
98     // Recording-related members
99     int32_t mRecordingRequestId;
100     int mRecordingStreamId;
101     int mRecordingFrameCount;
102     sp<BufferItemConsumer> mRecordingConsumer;
103     sp<ANativeWindow>  mRecordingWindow;
104     CameraMetadata mRecordingRequest;
105     sp<camera2::Camera2Heap> mRecordingHeap;
106 
107     static const size_t kDefaultRecordingHeapCount = 8;
108     size_t mRecordingHeapCount;
109     Vector<BufferItemConsumer::BufferItem> mRecordingBuffers;
110     size_t mRecordingHeapHead, mRecordingHeapFree;
111 
112 };
113 
114 
115 }; // namespace camera2
116 }; // namespace android
117 
118 #endif
119