blob: 000906a743768433a63b15f6562188c433849537 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Agopian07952722009-05-19 19:08:10 -070024#include <binder/MemoryBase.h>
25#include <binder/MemoryHeapBase.h>
The Android Open Source Project9066cfe2009-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
Benny Wongda83f462009-08-12 12:01:27 -050035 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();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 virtual void stopPreview();
46 virtual bool previewEnabled();
47
Benny Wongda83f462009-08-12 12:01:27 -050048 virtual status_t startRecording();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 virtual void stopRecording();
50 virtual bool recordingEnabled();
51 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
52
Benny Wongda83f462009-08-12 12:01:27 -050053 virtual status_t autoFocus();
54 virtual status_t takePicture();
55 virtual status_t cancelPicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 virtual status_t dump(int fd, const Vector<String16>& args) const;
57 virtual status_t setParameters(const CameraParameters& params);
58 virtual CameraParameters getParameters() const;
59 virtual void release();
60
61 static sp<CameraHardwareInterface> createInstance();
62
63private:
64 CameraHardwareStub();
65 virtual ~CameraHardwareStub();
66
67 static wp<CameraHardwareInterface> singleton;
68
69 static const int kBufferCount = 4;
70
71 class PreviewThread : public Thread {
72 CameraHardwareStub* mHardware;
73 public:
Marco Nelissenae7f3c52009-08-13 09:24:47 -070074 PreviewThread(CameraHardwareStub* hw) :
75#ifdef SINGLE_PROCESS
76 // In single process mode this thread needs to be a java thread,
77 // since we won't be calling through the binder.
78 Thread(true),
79#else
80 Thread(false),
81#endif
82 mHardware(hw) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 virtual void onFirstRef() {
84 run("CameraPreviewThread", PRIORITY_URGENT_DISPLAY);
85 }
86 virtual bool threadLoop() {
87 mHardware->previewThread();
88 // loop until we need to quit
89 return true;
90 }
91 };
92
93 void initDefaultParameters();
94 void initHeapLocked();
95
96 int previewThread();
97
98 static int beginAutoFocusThread(void *cookie);
99 int autoFocusThread();
100
101 static int beginPictureThread(void *cookie);
102 int pictureThread();
103
104 mutable Mutex mLock;
105
106 CameraParameters mParameters;
107
108 sp<MemoryHeapBase> mPreviewHeap;
109 sp<MemoryHeapBase> mRawHeap;
110 sp<MemoryBase> mBuffers[kBufferCount];
111
112 FakeCamera *mFakeCamera;
113 bool mPreviewRunning;
114 int mPreviewFrameSize;
115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 // protected by mLock
117 sp<PreviewThread> mPreviewThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118
Benny Wongda83f462009-08-12 12:01:27 -0500119 notify_callback mNotifyCb;
120 data_callback mDataCb;
121 data_callback_timestamp mDataCbTimestamp;
122 void *mCallbackCookie;
123
124 int32_t mMsgEnabled;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125
126 // only used from PreviewThread
127 int mCurrentPreviewFrame;
128};
129
130}; // namespace android
131
132#endif