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