blob: c6d8756715b15e4655eb467d128a5ff60dbbfa3b [file] [log] [blame]
Mathias Agopian65ab4712010-07-14 17:59:35 -07001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_STUB_H
19#define ANDROID_HARDWARE_CAMERA_HARDWARE_STUB_H
20
21#include "FakeCamera.h"
22#include <utils/threads.h>
23#include <camera/CameraHardwareInterface.h>
24#include <binder/MemoryBase.h>
25#include <binder/MemoryHeapBase.h>
26#include <utils/threads.h>
27
28namespace android {
29
30class CameraHardwareStub : public CameraHardwareInterface {
31public:
Jamie Gennis8f3e6aa2010-08-23 17:23:08 -070032 virtual status_t setPreviewWindow(const sp<ANativeWindow>& buf);
Mathias Agopian65ab4712010-07-14 17:59:35 -070033 virtual sp<IMemoryHeap> getRawHeap() const;
34
35 virtual void setCallbacks(notify_callback notify_cb,
36 data_callback data_cb,
37 data_callback_timestamp data_cb_timestamp,
38 void* user);
39
40 virtual void enableMsgType(int32_t msgType);
41 virtual void disableMsgType(int32_t msgType);
42 virtual bool msgTypeEnabled(int32_t msgType);
43
44 virtual status_t startPreview();
45 virtual void stopPreview();
46 virtual bool previewEnabled();
47
48 virtual status_t startRecording();
49 virtual void stopRecording();
50 virtual bool recordingEnabled();
51 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
52
53 virtual status_t autoFocus();
54 virtual status_t cancelAutoFocus();
55 virtual status_t takePicture();
56 virtual status_t cancelPicture();
57 virtual status_t dump(int fd, const Vector<String16>& args) const;
58 virtual status_t setParameters(const CameraParameters& params);
59 virtual CameraParameters getParameters() const;
60 virtual status_t sendCommand(int32_t command, int32_t arg1,
61 int32_t arg2);
62 virtual void release();
63
64 static sp<CameraHardwareInterface> createInstance();
65
66private:
67 CameraHardwareStub();
68 virtual ~CameraHardwareStub();
69
70 static const int kBufferCount = 4;
71
72 class PreviewThread : public Thread {
73 CameraHardwareStub* mHardware;
74 public:
75 PreviewThread(CameraHardwareStub* hw) :
Jeff Brown619d29f2011-07-08 18:52:57 -070076 Thread(false), mHardware(hw) { }
Mathias Agopian65ab4712010-07-14 17:59:35 -070077 virtual void onFirstRef() {
78 run("CameraPreviewThread", PRIORITY_URGENT_DISPLAY);
79 }
80 virtual bool threadLoop() {
81 mHardware->previewThread();
82 // loop until we need to quit
83 return true;
84 }
85 };
86
87 void initDefaultParameters();
88 void initHeapLocked();
89
90 int previewThread();
91
92 static int beginAutoFocusThread(void *cookie);
93 int autoFocusThread();
94
95 static int beginPictureThread(void *cookie);
96 int pictureThread();
97
98 mutable Mutex mLock;
99
100 CameraParameters mParameters;
101
102 sp<MemoryHeapBase> mPreviewHeap;
103 sp<MemoryHeapBase> mRawHeap;
104 sp<MemoryBase> mBuffers[kBufferCount];
105
106 FakeCamera *mFakeCamera;
107 bool mPreviewRunning;
108 int mPreviewFrameSize;
109
110 // protected by mLock
111 sp<PreviewThread> mPreviewThread;
112
113 notify_callback mNotifyCb;
114 data_callback mDataCb;
115 data_callback_timestamp mDataCbTimestamp;
116 void *mCallbackCookie;
117
118 int32_t mMsgEnabled;
119
120 // only used from PreviewThread
121 int mCurrentPreviewFrame;
122};
123
124}; // namespace android
125
126#endif