Loading camera/libcameraservice/CameraHardwareStub.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -314,7 +314,7 @@ status_t CameraHardwareStub::dump(int fd, const Vector<String16>& args) const String8 result; AutoMutex lock(&mLock); if (mFakeCamera != 0) { mFakeCamera->dump(fd, args); mFakeCamera->dump(fd); mParameters.dump(fd, args); snprintf(buffer, 255, " preview frame(%d), size (%d), running(%s)\n", mCurrentPreviewFrame, mPreviewFrameSize, mPreviewRunning?"true": "false"); result.append(buffer); Loading camera/libcameraservice/CameraService.cpp +18 −12 Original line number Diff line number Diff line Loading @@ -217,7 +217,13 @@ status_t CameraService::Client::unlock() // allow anyone to use camera LOGV("unlock (%p)", getCameraClient()->asBinder().get()); status_t result = checkPid(); if (result == NO_ERROR) mClientPid = 0; if (result == NO_ERROR) { mClientPid = 0; // we need to remove the reference so that when app goes // away, the reference count goes to 0. mCameraClient.clear(); } return result; } Loading Loading @@ -894,8 +900,6 @@ status_t CameraService::Client::setParameters(const String8& params) // get preview/capture parameters - key/value pairs String8 CameraService::Client::getParameters() const { LOGD("getParameters"); Mutex::Autolock lock(mLock); if (mHardware == 0) { Loading @@ -903,30 +907,32 @@ String8 CameraService::Client::getParameters() const return String8(); } return mHardware->getParameters().flatten(); String8 params(mHardware->getParameters().flatten()); LOGD("getParameters(%s)", params.string()); return params; } void CameraService::Client::postAutoFocus(bool focused) { LOGV("postAutoFocus"); mCameraClient->autoFocusCallback(focused); mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, (int32_t)focused, 0); } void CameraService::Client::postShutter() { mCameraClient->shutterCallback(); mCameraClient->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0); } void CameraService::Client::postRaw(const sp<IMemory>& mem) { LOGD("postRaw"); mCameraClient->rawCallback(mem); mCameraClient->dataCallback(CAMERA_MSG_RAW_IMAGE, mem); } void CameraService::Client::postJpeg(const sp<IMemory>& mem) { LOGD("postJpeg"); mCameraClient->jpegCallback(mem); mCameraClient->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem); } void CameraService::Client::copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size) Loading Loading @@ -954,7 +960,7 @@ void CameraService::Client::copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, si LOGE("failed to allocate space for frame callback"); return; } mCameraClient->previewCallback(frame); mCameraClient->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame); } void CameraService::Client::postRecordingFrame(const sp<IMemory>& frame) Loading @@ -964,7 +970,7 @@ void CameraService::Client::postRecordingFrame(const sp<IMemory>& frame) LOGW("frame is a null pointer"); return; } mCameraClient->recordingCallback(frame); mCameraClient->dataCallback(CAMERA_MSG_VIDEO_FRAME, frame); } void CameraService::Client::postPreviewFrame(const sp<IMemory>& mem) Loading Loading @@ -998,7 +1004,7 @@ void CameraService::Client::postPreviewFrame(const sp<IMemory>& mem) copyFrameAndPostCopiedFrame(heap, offset, size); } else { LOGV("frame is directly sent out without copying"); mCameraClient->previewCallback(mem); mCameraClient->dataCallback(CAMERA_MSG_PREVIEW_FRAME, mem); } // Is this is one-shot only? Loading @@ -1012,7 +1018,7 @@ void CameraService::Client::postPreviewFrame(const sp<IMemory>& mem) void CameraService::Client::postError(status_t error) { mCameraClient->errorCallback(error); mCameraClient->notifyCallback(CAMERA_MSG_ERROR, error, 0); } status_t CameraService::dump(int fd, const Vector<String16>& args) Loading camera/libcameraservice/FakeCamera.cpp +28 −2 Original line number Diff line number Diff line /* ** ** Copyright 2008, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ #define LOG_TAG "FakeCamera" #include <utils/Log.h> #include <string.h> #include <stdlib.h> #include <utils/String8.h> #include "FakeCamera.h" namespace android { // TODO: All this rgb to yuv should probably be in a util class. // TODO: I think something is wrong in this class because the shadow is kBlue // and the square color should alternate between kRed and kGreen. However on the // emulator screen these are all shades of gray. Y seems ok but the U and V are // probably not. static int tables_initialized = 0; uint8_t *gYTable, *gCbTable, *gCrTable; Loading Loading @@ -389,7 +416,7 @@ void FakeCamera::drawCheckerboard(uint16_t *dst, int size) } status_t FakeCamera::dump(int fd, const Vector<String16>& args) void FakeCamera::dump(int fd) const { const size_t SIZE = 256; char buffer[SIZE]; Loading @@ -397,7 +424,6 @@ status_t FakeCamera::dump(int fd, const Vector<String16>& args) snprintf(buffer, 255, " width x height (%d x %d), counter (%d), check x-y coordinate(%d, %d)\n", mWidth, mHeight, mCounter, mCheckX, mCheckY); result.append(buffer); ::write(fd, result.string(), result.size()); return NO_ERROR; } Loading camera/libcameraservice/FakeCamera.h +19 −3 Original line number Diff line number Diff line Loading @@ -18,21 +18,37 @@ #ifndef ANDROID_HARDWARE_FAKECAMERA_H #define ANDROID_HARDWARE_FAKECAMERA_H #include <ui/CameraHardwareInterface.h> #include <sys/types.h> #include <stdint.h> namespace android { /* * FakeCamera is used in the CameraHardwareStub to provide a fake video feed * when the system does not have a camera in hardware. * The fake video is a moving black and white checkerboard background with a * bouncing gray square in the foreground. * This class is not thread-safe. * * TODO: Since the major methods provides a raw/uncompressed video feed, rename * this class to RawVideoSource. */ class FakeCamera { public: FakeCamera(int width, int height); ~FakeCamera(); void setSize(int width, int height); void getNextFrameAsRgb565(uint16_t *buffer); void getNextFrameAsYuv422(uint8_t *buffer); status_t dump(int fd, const Vector<String16>& args); // Write to the fd a string representing the current state. void dump(int fd) const; private: // TODO: remove the uint16_t buffer param everywhere since it is a field of // this class. void getNextFrameAsRgb565(uint16_t *buffer); void drawSquare(uint16_t *buffer, int x, int y, int size, int color, int shadow); void drawCheckerboard(uint16_t *buffer, int size); Loading include/ui/Camera.h +20 −9 Original line number Diff line number Diff line Loading @@ -63,6 +63,23 @@ namespace android { #define FRAME_CALLBACK_FLAG_CAMERA 0x05 #define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07 // msgType in notifyCallback function enum { CAMERA_MSG_ERROR, CAMERA_MSG_SHUTTER, CAMERA_MSG_FOCUS, CAMERA_MSG_ZOOM }; // msgType in dataCallback function enum { CAMERA_MSG_PREVIEW_FRAME, CAMERA_MSG_VIDEO_FRAME, CAMERA_MSG_POSTVIEW_FRAME, CAMERA_MSG_RAW_IMAGE, CAMERA_MSG_COMPRESSED_IMAGE }; class ICameraService; class ICamera; class Surface; Loading @@ -78,8 +95,7 @@ class Camera : public BnCameraClient, public IBinder::DeathRecipient { public: // construct a camera client from an existing remote Camera(const sp<ICamera>& camera); static sp<Camera> create(const sp<ICamera>& camera); static sp<Camera> connect(); ~Camera(); void init(); Loading Loading @@ -137,13 +153,8 @@ public: void setAutoFocusCallback(autofocus_callback cb, void *cookie); // ICameraClient interface virtual void shutterCallback(); virtual void rawCallback(const sp<IMemory>& picture); virtual void jpegCallback(const sp<IMemory>& picture); virtual void previewCallback(const sp<IMemory>& frame); virtual void errorCallback(status_t error); virtual void autoFocusCallback(bool focused); virtual void recordingCallback(const sp<IMemory>& frame); virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr); sp<ICamera> remote(); Loading Loading
camera/libcameraservice/CameraHardwareStub.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -314,7 +314,7 @@ status_t CameraHardwareStub::dump(int fd, const Vector<String16>& args) const String8 result; AutoMutex lock(&mLock); if (mFakeCamera != 0) { mFakeCamera->dump(fd, args); mFakeCamera->dump(fd); mParameters.dump(fd, args); snprintf(buffer, 255, " preview frame(%d), size (%d), running(%s)\n", mCurrentPreviewFrame, mPreviewFrameSize, mPreviewRunning?"true": "false"); result.append(buffer); Loading
camera/libcameraservice/CameraService.cpp +18 −12 Original line number Diff line number Diff line Loading @@ -217,7 +217,13 @@ status_t CameraService::Client::unlock() // allow anyone to use camera LOGV("unlock (%p)", getCameraClient()->asBinder().get()); status_t result = checkPid(); if (result == NO_ERROR) mClientPid = 0; if (result == NO_ERROR) { mClientPid = 0; // we need to remove the reference so that when app goes // away, the reference count goes to 0. mCameraClient.clear(); } return result; } Loading Loading @@ -894,8 +900,6 @@ status_t CameraService::Client::setParameters(const String8& params) // get preview/capture parameters - key/value pairs String8 CameraService::Client::getParameters() const { LOGD("getParameters"); Mutex::Autolock lock(mLock); if (mHardware == 0) { Loading @@ -903,30 +907,32 @@ String8 CameraService::Client::getParameters() const return String8(); } return mHardware->getParameters().flatten(); String8 params(mHardware->getParameters().flatten()); LOGD("getParameters(%s)", params.string()); return params; } void CameraService::Client::postAutoFocus(bool focused) { LOGV("postAutoFocus"); mCameraClient->autoFocusCallback(focused); mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, (int32_t)focused, 0); } void CameraService::Client::postShutter() { mCameraClient->shutterCallback(); mCameraClient->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0); } void CameraService::Client::postRaw(const sp<IMemory>& mem) { LOGD("postRaw"); mCameraClient->rawCallback(mem); mCameraClient->dataCallback(CAMERA_MSG_RAW_IMAGE, mem); } void CameraService::Client::postJpeg(const sp<IMemory>& mem) { LOGD("postJpeg"); mCameraClient->jpegCallback(mem); mCameraClient->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem); } void CameraService::Client::copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size) Loading Loading @@ -954,7 +960,7 @@ void CameraService::Client::copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, si LOGE("failed to allocate space for frame callback"); return; } mCameraClient->previewCallback(frame); mCameraClient->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame); } void CameraService::Client::postRecordingFrame(const sp<IMemory>& frame) Loading @@ -964,7 +970,7 @@ void CameraService::Client::postRecordingFrame(const sp<IMemory>& frame) LOGW("frame is a null pointer"); return; } mCameraClient->recordingCallback(frame); mCameraClient->dataCallback(CAMERA_MSG_VIDEO_FRAME, frame); } void CameraService::Client::postPreviewFrame(const sp<IMemory>& mem) Loading Loading @@ -998,7 +1004,7 @@ void CameraService::Client::postPreviewFrame(const sp<IMemory>& mem) copyFrameAndPostCopiedFrame(heap, offset, size); } else { LOGV("frame is directly sent out without copying"); mCameraClient->previewCallback(mem); mCameraClient->dataCallback(CAMERA_MSG_PREVIEW_FRAME, mem); } // Is this is one-shot only? Loading @@ -1012,7 +1018,7 @@ void CameraService::Client::postPreviewFrame(const sp<IMemory>& mem) void CameraService::Client::postError(status_t error) { mCameraClient->errorCallback(error); mCameraClient->notifyCallback(CAMERA_MSG_ERROR, error, 0); } status_t CameraService::dump(int fd, const Vector<String16>& args) Loading
camera/libcameraservice/FakeCamera.cpp +28 −2 Original line number Diff line number Diff line /* ** ** Copyright 2008, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ #define LOG_TAG "FakeCamera" #include <utils/Log.h> #include <string.h> #include <stdlib.h> #include <utils/String8.h> #include "FakeCamera.h" namespace android { // TODO: All this rgb to yuv should probably be in a util class. // TODO: I think something is wrong in this class because the shadow is kBlue // and the square color should alternate between kRed and kGreen. However on the // emulator screen these are all shades of gray. Y seems ok but the U and V are // probably not. static int tables_initialized = 0; uint8_t *gYTable, *gCbTable, *gCrTable; Loading Loading @@ -389,7 +416,7 @@ void FakeCamera::drawCheckerboard(uint16_t *dst, int size) } status_t FakeCamera::dump(int fd, const Vector<String16>& args) void FakeCamera::dump(int fd) const { const size_t SIZE = 256; char buffer[SIZE]; Loading @@ -397,7 +424,6 @@ status_t FakeCamera::dump(int fd, const Vector<String16>& args) snprintf(buffer, 255, " width x height (%d x %d), counter (%d), check x-y coordinate(%d, %d)\n", mWidth, mHeight, mCounter, mCheckX, mCheckY); result.append(buffer); ::write(fd, result.string(), result.size()); return NO_ERROR; } Loading
camera/libcameraservice/FakeCamera.h +19 −3 Original line number Diff line number Diff line Loading @@ -18,21 +18,37 @@ #ifndef ANDROID_HARDWARE_FAKECAMERA_H #define ANDROID_HARDWARE_FAKECAMERA_H #include <ui/CameraHardwareInterface.h> #include <sys/types.h> #include <stdint.h> namespace android { /* * FakeCamera is used in the CameraHardwareStub to provide a fake video feed * when the system does not have a camera in hardware. * The fake video is a moving black and white checkerboard background with a * bouncing gray square in the foreground. * This class is not thread-safe. * * TODO: Since the major methods provides a raw/uncompressed video feed, rename * this class to RawVideoSource. */ class FakeCamera { public: FakeCamera(int width, int height); ~FakeCamera(); void setSize(int width, int height); void getNextFrameAsRgb565(uint16_t *buffer); void getNextFrameAsYuv422(uint8_t *buffer); status_t dump(int fd, const Vector<String16>& args); // Write to the fd a string representing the current state. void dump(int fd) const; private: // TODO: remove the uint16_t buffer param everywhere since it is a field of // this class. void getNextFrameAsRgb565(uint16_t *buffer); void drawSquare(uint16_t *buffer, int x, int y, int size, int color, int shadow); void drawCheckerboard(uint16_t *buffer, int size); Loading
include/ui/Camera.h +20 −9 Original line number Diff line number Diff line Loading @@ -63,6 +63,23 @@ namespace android { #define FRAME_CALLBACK_FLAG_CAMERA 0x05 #define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07 // msgType in notifyCallback function enum { CAMERA_MSG_ERROR, CAMERA_MSG_SHUTTER, CAMERA_MSG_FOCUS, CAMERA_MSG_ZOOM }; // msgType in dataCallback function enum { CAMERA_MSG_PREVIEW_FRAME, CAMERA_MSG_VIDEO_FRAME, CAMERA_MSG_POSTVIEW_FRAME, CAMERA_MSG_RAW_IMAGE, CAMERA_MSG_COMPRESSED_IMAGE }; class ICameraService; class ICamera; class Surface; Loading @@ -78,8 +95,7 @@ class Camera : public BnCameraClient, public IBinder::DeathRecipient { public: // construct a camera client from an existing remote Camera(const sp<ICamera>& camera); static sp<Camera> create(const sp<ICamera>& camera); static sp<Camera> connect(); ~Camera(); void init(); Loading Loading @@ -137,13 +153,8 @@ public: void setAutoFocusCallback(autofocus_callback cb, void *cookie); // ICameraClient interface virtual void shutterCallback(); virtual void rawCallback(const sp<IMemory>& picture); virtual void jpegCallback(const sp<IMemory>& picture); virtual void previewCallback(const sp<IMemory>& frame); virtual void errorCallback(status_t error); virtual void autoFocusCallback(bool focused); virtual void recordingCallback(const sp<IMemory>& frame); virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr); sp<ICamera> remote(); Loading