The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 23 | #include <camera/CameraHardwareInterface.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 24 | #include <binder/MemoryBase.h> |
| 25 | #include <binder/MemoryHeapBase.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <utils/threads.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | class CameraHardwareStub : public CameraHardwareInterface { |
| 31 | public: |
| 32 | virtual sp<IMemoryHeap> getPreviewHeap() const; |
| 33 | virtual sp<IMemoryHeap> getRawHeap() const; |
| 34 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 35 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | virtual void stopPreview(); |
| 46 | virtual bool previewEnabled(); |
| 47 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 48 | virtual status_t startRecording(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | virtual void stopRecording(); |
| 50 | virtual bool recordingEnabled(); |
| 51 | virtual void releaseRecordingFrame(const sp<IMemory>& mem); |
| 52 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 53 | virtual status_t autoFocus(); |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 54 | virtual status_t cancelAutoFocus(); |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 55 | virtual status_t takePicture(); |
| 56 | virtual status_t cancelPicture(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | virtual status_t dump(int fd, const Vector<String16>& args) const; |
| 58 | virtual status_t setParameters(const CameraParameters& params); |
| 59 | virtual CameraParameters getParameters() const; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 60 | virtual status_t sendCommand(int32_t command, int32_t arg1, |
| 61 | int32_t arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | virtual void release(); |
| 63 | |
| 64 | static sp<CameraHardwareInterface> createInstance(); |
| 65 | |
| 66 | private: |
| 67 | CameraHardwareStub(); |
| 68 | virtual ~CameraHardwareStub(); |
| 69 | |
| 70 | static wp<CameraHardwareInterface> singleton; |
| 71 | |
| 72 | static const int kBufferCount = 4; |
| 73 | |
| 74 | class PreviewThread : public Thread { |
| 75 | CameraHardwareStub* mHardware; |
| 76 | public: |
Marco Nelissen | ae7f3c5 | 2009-08-13 09:24:47 -0700 | [diff] [blame] | 77 | PreviewThread(CameraHardwareStub* hw) : |
| 78 | #ifdef SINGLE_PROCESS |
| 79 | // In single process mode this thread needs to be a java thread, |
| 80 | // since we won't be calling through the binder. |
| 81 | Thread(true), |
| 82 | #else |
| 83 | Thread(false), |
| 84 | #endif |
| 85 | mHardware(hw) { } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | virtual void onFirstRef() { |
| 87 | run("CameraPreviewThread", PRIORITY_URGENT_DISPLAY); |
| 88 | } |
| 89 | virtual bool threadLoop() { |
| 90 | mHardware->previewThread(); |
| 91 | // loop until we need to quit |
| 92 | return true; |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | void initDefaultParameters(); |
| 97 | void initHeapLocked(); |
| 98 | |
| 99 | int previewThread(); |
| 100 | |
| 101 | static int beginAutoFocusThread(void *cookie); |
| 102 | int autoFocusThread(); |
| 103 | |
| 104 | static int beginPictureThread(void *cookie); |
| 105 | int pictureThread(); |
| 106 | |
| 107 | mutable Mutex mLock; |
| 108 | |
| 109 | CameraParameters mParameters; |
| 110 | |
| 111 | sp<MemoryHeapBase> mPreviewHeap; |
| 112 | sp<MemoryHeapBase> mRawHeap; |
| 113 | sp<MemoryBase> mBuffers[kBufferCount]; |
| 114 | |
| 115 | FakeCamera *mFakeCamera; |
| 116 | bool mPreviewRunning; |
| 117 | int mPreviewFrameSize; |
| 118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | // protected by mLock |
| 120 | sp<PreviewThread> mPreviewThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 122 | notify_callback mNotifyCb; |
| 123 | data_callback mDataCb; |
| 124 | data_callback_timestamp mDataCbTimestamp; |
| 125 | void *mCallbackCookie; |
| 126 | |
| 127 | int32_t mMsgEnabled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | |
| 129 | // only used from PreviewThread |
| 130 | int mCurrentPreviewFrame; |
| 131 | }; |
| 132 | |
| 133 | }; // namespace android |
| 134 | |
| 135 | #endif |