blob: dd3c706bc9f27f26a0c38074b66a41ace58aebec [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>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/MemoryBase.h>
25#include <binder/MemoryHeapBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026#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:
Marco Nelissen7907df72009-08-13 09:24:47 -070070 PreviewThread(CameraHardwareStub* hw) :
71#ifdef SINGLE_PROCESS
72 // In single process mode this thread needs to be a java thread,
73 // since we won't be calling through the binder.
74 Thread(true),
75#else
76 Thread(false),
77#endif
78 mHardware(hw) { }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 virtual void onFirstRef() {
80 run("CameraPreviewThread", PRIORITY_URGENT_DISPLAY);
81 }
82 virtual bool threadLoop() {
83 mHardware->previewThread();
84 // loop until we need to quit
85 return true;
86 }
87 };
88
89 void initDefaultParameters();
90 void initHeapLocked();
91
92 int previewThread();
93
94 static int beginAutoFocusThread(void *cookie);
95 int autoFocusThread();
96
97 static int beginPictureThread(void *cookie);
98 int pictureThread();
99
100 mutable Mutex mLock;
101
102 CameraParameters mParameters;
103
104 sp<MemoryHeapBase> mPreviewHeap;
105 sp<MemoryHeapBase> mRawHeap;
106 sp<MemoryBase> mBuffers[kBufferCount];
107
108 FakeCamera *mFakeCamera;
109 bool mPreviewRunning;
110 int mPreviewFrameSize;
111
112 shutter_callback mShutterCallback;
113 raw_callback mRawPictureCallback;
114 jpeg_callback mJpegPictureCallback;
115 void *mPictureCallbackCookie;
116
117 // protected by mLock
118 sp<PreviewThread> mPreviewThread;
119 preview_callback mPreviewCallback;
120 void *mPreviewCallbackCookie;
121
122 autofocus_callback mAutoFocusCallback;
123 void *mAutoFocusCallbackCookie;
124
125 // only used from PreviewThread
126 int mCurrentPreviewFrame;
127};
128
129}; // namespace android
130
131#endif