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