blob: 643114ee8d17730e3df31129e2b1c952d111a098 [file] [log] [blame]
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -07001/*
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"
Igor Murashkin7efa5202013-02-13 15:53:56 -080025#include "camera/CameraMetadata.h"
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070026
27namespace android {
28
29class Camera2Client;
Eino-Ville Talvalad09801b2013-04-23 15:16:57 -070030class CameraDeviceBase;
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070031class IMemory;
32
33namespace camera2 {
34
35class Camera2Heap;
36
37/**
38 * Management and processing for preview and recording streams
39 */
40class StreamingProcessor: public BufferItemConsumer::FrameAvailableListener {
41 public:
Eino-Ville Talvalad09801b2013-04-23 15:16:57 -070042 StreamingProcessor(sp<Camera2Client> client);
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070043 ~StreamingProcessor();
44
45 status_t setPreviewWindow(sp<ANativeWindow> window);
46
47 bool haveValidPreviewWindow() const;
48
49 status_t updatePreviewRequest(const Parameters &params);
50 status_t updatePreviewStream(const Parameters &params);
51 status_t deletePreviewStream();
52 int getPreviewStreamId() const;
53
54 status_t setRecordingBufferCount(size_t count);
55 status_t updateRecordingRequest(const Parameters &params);
56 status_t updateRecordingStream(const Parameters &params);
57 status_t deleteRecordingStream();
58 int getRecordingStreamId() const;
59
60 enum StreamType {
Eino-Ville Talvala4865c522012-10-02 13:30:28 -070061 NONE,
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070062 PREVIEW,
63 RECORD
64 };
65 status_t startStream(StreamType type,
66 const Vector<uint8_t> &outputStreams);
67
68 status_t stopStream();
69
Eino-Ville Talvala4865c522012-10-02 13:30:28 -070070 // Returns the request ID for the currently streaming request
71 // Returns 0 if there is no active request.
72 status_t getActiveRequestId() const;
73 status_t incrementStreamingIds();
74
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070075 // Callback for new recording frames from HAL
76 virtual void onFrameAvailable();
77 // Callback from stagefright which returns used recording frames
78 void releaseRecordingFrame(const sp<IMemory>& mem);
79
80 status_t dump(int fd, const Vector<String16>& args);
81
82 private:
83 mutable Mutex mMutex;
84
85 enum {
86 NO_STREAM = -1
87 };
88
89 wp<Camera2Client> mClient;
Eino-Ville Talvalad09801b2013-04-23 15:16:57 -070090 wp<CameraDeviceBase> mDevice;
91 int mId;
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070092
Eino-Ville Talvala4865c522012-10-02 13:30:28 -070093 StreamType mActiveRequest;
94
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070095 // Preview-related members
Eino-Ville Talvala4865c522012-10-02 13:30:28 -070096 int32_t mPreviewRequestId;
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070097 int mPreviewStreamId;
98 CameraMetadata mPreviewRequest;
99 sp<ANativeWindow> mPreviewWindow;
100
101 // Recording-related members
Eino-Ville Talvala4865c522012-10-02 13:30:28 -0700102 int32_t mRecordingRequestId;
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -0700103 int mRecordingStreamId;
104 int mRecordingFrameCount;
105 sp<BufferItemConsumer> mRecordingConsumer;
106 sp<ANativeWindow> mRecordingWindow;
107 CameraMetadata mRecordingRequest;
108 sp<camera2::Camera2Heap> mRecordingHeap;
109
110 static const size_t kDefaultRecordingHeapCount = 8;
111 size_t mRecordingHeapCount;
112 Vector<BufferItemConsumer::BufferItem> mRecordingBuffers;
113 size_t mRecordingHeapHead, mRecordingHeapFree;
114
115};
116
117
118}; // namespace camera2
119}; // namespace android
120
121#endif