blob: cdd60116f36ef2649111ed947ba46273412c85c9 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -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 <ui/CameraHardwareInterface.h>
24#include <utils/MemoryBase.h>
25#include <utils/MemoryHeapBase.h>
26#include <utils/threads.h>
27
28namespace android {
29
30class CameraHardwareStub : public CameraHardwareInterface {
31public:
32 virtual sp<IMemoryHeap> getPreviewHeap() const;
33
34 virtual status_t startPreview(preview_callback cb, void* user);
35 virtual void stopPreview();
The Android Open Source Project27629322009-01-09 17:51:23 -080036 virtual bool previewEnabled();
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080037
38 virtual status_t startRecording(recording_callback cb, void* user);
39 virtual void stopRecording();
40 virtual bool recordingEnabled();
41 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
42
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070043 virtual status_t autoFocus(autofocus_callback, void *user);
44 virtual status_t takePicture(shutter_callback,
45 raw_callback,
46 jpeg_callback,
47 void* user);
48 virtual status_t cancelPicture(bool cancel_shutter,
49 bool cancel_raw,
50 bool cancel_jpeg);
51 virtual status_t dump(int fd, const Vector<String16>& args) const;
52 virtual status_t setParameters(const CameraParameters& params);
53 virtual CameraParameters getParameters() const;
54 virtual void release();
55
56 static sp<CameraHardwareInterface> createInstance();
57
58private:
59 CameraHardwareStub();
60 virtual ~CameraHardwareStub();
61
62 static wp<CameraHardwareInterface> singleton;
63
64 static const int kBufferCount = 4;
65
66 class PreviewThread : public Thread {
67 CameraHardwareStub* mHardware;
68 public:
69 PreviewThread(CameraHardwareStub* hw)
70 : Thread(false), mHardware(hw) { }
71 virtual void onFirstRef() {
72 run("CameraPreviewThread", PRIORITY_URGENT_DISPLAY);
73 }
74 virtual bool threadLoop() {
75 mHardware->previewThread();
76 // loop until we need to quit
77 return true;
78 }
79 };
80
81 void initDefaultParameters();
82 void initHeapLocked();
83
84 int previewThread();
85
86 static int beginAutoFocusThread(void *cookie);
87 int autoFocusThread();
88
89 static int beginPictureThread(void *cookie);
90 int pictureThread();
91
92 mutable Mutex mLock;
93
94 CameraParameters mParameters;
95
The Android Open Source Project43aa2b12009-03-03 14:04:24 -080096 sp<MemoryHeapBase> mHeap;
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070097 sp<MemoryBase> mBuffers[kBufferCount];
98
99 FakeCamera *mFakeCamera;
100 bool mPreviewRunning;
101 int mPreviewFrameSize;
102
103 shutter_callback mShutterCallback;
104 raw_callback mRawPictureCallback;
105 jpeg_callback mJpegPictureCallback;
106 void *mPictureCallbackCookie;
107
108 // protected by mLock
109 sp<PreviewThread> mPreviewThread;
110 preview_callback mPreviewCallback;
111 void *mPreviewCallbackCookie;
112
113 autofocus_callback mAutoFocusCallback;
114 void *mAutoFocusCallbackCookie;
115
116 // only used from PreviewThread
117 int mCurrentPreviewFrame;
118};
119
120}; // namespace android
121
122#endif