CallbackProcessor.h revision 727d172137b4f32681c098de8e2623c0b65a6406
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_CALLBACKPROCESSOR_H
18#define ANDROID_SERVERS_CAMERA_CAMERA2_CALLBACKPROCESSOR_H
19
20#include <utils/Thread.h>
21#include <utils/String16.h>
22#include <utils/Vector.h>
23#include <utils/Mutex.h>
24#include <utils/Condition.h>
25#include <gui/CpuConsumer.h>
26
27#include "api1/client2/Camera2Heap.h"
28
29namespace android {
30
31class Camera2Client;
32class CameraDeviceBase;
33
34namespace camera2 {
35
36class Parameters;
37
38/***
39 * Still image capture output image processing
40 */
41class CallbackProcessor:
42            public Thread, public CpuConsumer::FrameAvailableListener {
43  public:
44    CallbackProcessor(sp<Camera2Client> client);
45    ~CallbackProcessor();
46
47    void onFrameAvailable(const BufferItem& item);
48
49    // Set to NULL to disable the direct-to-app callback window
50    status_t setCallbackWindow(sp<Surface> callbackWindow);
51    status_t updateStream(const Parameters &params);
52    status_t deleteStream();
53    int getStreamId() const;
54
55    void dump(int fd, const Vector<String16>& args) const;
56  private:
57    static const nsecs_t kWaitDuration = 10000000; // 10 ms
58    wp<Camera2Client> mClient;
59    wp<CameraDeviceBase> mDevice;
60    int mId;
61
62    mutable Mutex mInputMutex;
63    bool mCallbackAvailable;
64    Condition mCallbackAvailableSignal;
65
66    enum {
67        NO_STREAM = -1
68    };
69
70    // True if mCallbackWindow is a remote consumer, false if just the local
71    // mCallbackConsumer
72    bool mCallbackToApp;
73    int mCallbackStreamId;
74    static const size_t kCallbackHeapCount = 6;
75    sp<CpuConsumer>    mCallbackConsumer;
76    sp<Surface>        mCallbackWindow;
77    sp<Camera2Heap>    mCallbackHeap;
78    int mCallbackHeapId;
79    size_t mCallbackHeapHead, mCallbackHeapFree;
80
81    virtual bool threadLoop();
82
83    status_t processNewCallback(sp<Camera2Client> &client);
84    // Used when shutting down
85    status_t discardNewCallback();
86
87    // Convert from flexible YUV to NV21 or YV12
88    status_t convertFromFlexibleYuv(int32_t previewFormat,
89            uint8_t *dst,
90            const CpuConsumer::LockedBuffer &src,
91            uint32_t dstYStride,
92            uint32_t dstCStride) const;
93};
94
95
96}; //namespace camera2
97}; //namespace android
98
99#endif
100