StreamingProcessor.h revision 73bbd1f1c493835f191ea2b0b72439292496b40a
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
27namespace android {
28
29class Camera2Client;
30class IMemory;
31
32namespace camera2 {
33
34class Camera2Heap;
35
36/**
37 * Management and processing for preview and recording streams
38 */
39class 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        PREVIEW,
61        RECORD
62    };
63    status_t startStream(StreamType type,
64            const Vector<uint8_t> &outputStreams);
65
66    status_t stopStream();
67
68    // Callback for new recording frames from HAL
69    virtual void onFrameAvailable();
70    // Callback from stagefright which returns used recording frames
71    void releaseRecordingFrame(const sp<IMemory>& mem);
72
73    status_t dump(int fd, const Vector<String16>& args);
74
75  private:
76    mutable Mutex mMutex;
77
78    enum {
79        NO_STREAM = -1
80    };
81
82    wp<Camera2Client> mClient;
83
84    // Preview-related members
85    int mPreviewStreamId;
86    CameraMetadata mPreviewRequest;
87    sp<ANativeWindow> mPreviewWindow;
88
89    // Recording-related members
90    int mRecordingStreamId;
91    int mRecordingFrameCount;
92    sp<BufferItemConsumer> mRecordingConsumer;
93    sp<ANativeWindow>  mRecordingWindow;
94    CameraMetadata mRecordingRequest;
95    sp<camera2::Camera2Heap> mRecordingHeap;
96
97    static const size_t kDefaultRecordingHeapCount = 8;
98    size_t mRecordingHeapCount;
99    Vector<BufferItemConsumer::BufferItem> mRecordingBuffers;
100    size_t mRecordingHeapHead, mRecordingHeapFree;
101
102};
103
104
105}; // namespace camera2
106}; // namespace android
107
108#endif
109