diff options
Diffstat (limited to 'services/camera')
9 files changed, 102 insertions, 15 deletions
diff --git a/services/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk index 45900c4..ab09cb3 100644 --- a/services/camera/libcameraservice/Android.mk +++ b/services/camera/libcameraservice/Android.mk @@ -79,6 +79,14 @@ LOCAL_C_INCLUDES += \ LOCAL_CFLAGS += -Wall -Wextra +ifeq ($(BOARD_NEEDS_MEMORYHEAPION),true) + LOCAL_CFLAGS += -DUSE_MEMORY_HEAP_ION +endif + +ifneq ($(BOARD_NUMBER_OF_CAMERAS),) + LOCAL_CFLAGS += -DMAX_CAMERAS=$(BOARD_NUMBER_OF_CAMERAS) +endif + LOCAL_MODULE:= libcameraservice include $(BUILD_SHARED_LIBRARY) diff --git a/services/camera/libcameraservice/CameraFlashlight.cpp b/services/camera/libcameraservice/CameraFlashlight.cpp index 406c1c4..62ce610 100644 --- a/services/camera/libcameraservice/CameraFlashlight.cpp +++ b/services/camera/libcameraservice/CameraFlashlight.cpp @@ -828,6 +828,18 @@ status_t CameraHardwareInterfaceFlashControl::initializePreviewWindow( return device->setPreviewWindow(mSurface); } +static void notifyCallback(int32_t, int32_t, int32_t, void*) { + /* Empty */ +} + +static void dataCallback(int32_t, const sp<IMemory>&, camera_frame_metadata_t*, void*) { + /* Empty */ +} + +static void dataCallbackTimestamp(nsecs_t, int32_t, const sp<IMemory>&, void*) { + /* Empty */ +} + status_t CameraHardwareInterfaceFlashControl::connectCameraDevice( const String8& cameraId) { sp<CameraHardwareInterface> device = @@ -841,7 +853,7 @@ status_t CameraHardwareInterfaceFlashControl::connectCameraDevice( } // need to set __get_memory in set_callbacks(). - device->setCallbacks(NULL, NULL, NULL, NULL); + device->setCallbacks(notifyCallback, dataCallback, dataCallbackTimestamp, this); mParameters = device->getParameters(); diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 7c4594f..3c9fd16 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -81,7 +81,7 @@ static void camera_device_status_change( sp<CameraService> cs = const_cast<CameraService*>( static_cast<const CameraService*>(callbacks)); - cs->onDeviceStatusChanged(static_cast<camera_device_status_t>(camera_id), + cs->onDeviceStatusChanged(camera_id, static_cast<camera_device_status_t>(new_status)); } @@ -153,6 +153,7 @@ void CameraService::onFirstRef() ALOGE("Could not load camera HAL module: %d (%s)", err, strerror(-err)); logServiceError("Could not load camera HAL module", err); mNumberOfCameras = 0; + mNumberOfNormalCameras = 0; return; } @@ -276,7 +277,7 @@ CameraService::~CameraService() { gCameraService = nullptr; } -void CameraService::onDeviceStatusChanged(camera_device_status_t cameraId, +void CameraService::onDeviceStatusChanged(int cameraId, camera_device_status_t newStatus) { ALOGI("%s: Status changed for cameraId=%d, newStatus=%d", __FUNCTION__, cameraId, newStatus); diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h index d2c1bd3..53233bd 100644 --- a/services/camera/libcameraservice/CameraService.h +++ b/services/camera/libcameraservice/CameraService.h @@ -49,6 +49,10 @@ #include <memory> #include <utility> +#ifndef MAX_CAMERAS +#define MAX_CAMERAS 2 +#endif + namespace android { extern volatile int32_t gLogLevel; @@ -98,7 +102,7 @@ public: ///////////////////////////////////////////////////////////////////// // HAL Callbacks - virtual void onDeviceStatusChanged(camera_device_status_t cameraId, + virtual void onDeviceStatusChanged(int cameraId, camera_device_status_t newStatus); virtual void onTorchStatusChanged(const String8& cameraId, ICameraServiceListener::TorchStatus diff --git a/services/camera/libcameraservice/api1/Camera2Client.cpp b/services/camera/libcameraservice/api1/Camera2Client.cpp index fbd4034..96266ed 100644 --- a/services/camera/libcameraservice/api1/Camera2Client.cpp +++ b/services/camera/libcameraservice/api1/Camera2Client.cpp @@ -1745,8 +1745,6 @@ void Camera2Client::notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCod err = CAMERA_ERROR_RELEASED; break; case ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE: - err = CAMERA_ERROR_UNKNOWN; - break; case ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE: err = CAMERA_ERROR_SERVER_DIED; break; diff --git a/services/camera/libcameraservice/api1/CameraClient.cpp b/services/camera/libcameraservice/api1/CameraClient.cpp index 6020e35..af46d63 100644 --- a/services/camera/libcameraservice/api1/CameraClient.cpp +++ b/services/camera/libcameraservice/api1/CameraClient.cpp @@ -56,6 +56,9 @@ CameraClient::CameraClient(const sp<CameraService>& cameraService, mOrientation = getOrientation(0, mCameraFacing == CAMERA_FACING_FRONT); mLegacyMode = legacyMode; mPlayShutterSound = true; + + mLongshotEnabled = false; + mBurstCnt = 0; LOG1("CameraClient::CameraClient X (pid %d, id %d)", callingPid, cameraId); } @@ -240,11 +243,6 @@ void CameraClient::disconnect() { return; } - if (mClientPid <= 0) { - LOG1("camera is unlocked (mClientPid = %d), don't tear down hardware", mClientPid); - return; - } - // Make sure disconnect() is done once and once only, whether it is called // from the user directly, or called by the destructor. if (mHardware == 0) return; @@ -364,12 +362,14 @@ status_t CameraClient::setPreviewCallbackTarget( // start preview mode status_t CameraClient::startPreview() { + Mutex::Autolock lock(mLock); LOG1("startPreview (pid %d)", getCallingPid()); return startCameraMode(CAMERA_PREVIEW_MODE); } // start recording mode status_t CameraClient::startRecording() { + Mutex::Autolock lock(mLock); LOG1("startRecording (pid %d)", getCallingPid()); return startCameraMode(CAMERA_RECORDING_MODE); } @@ -377,7 +377,6 @@ status_t CameraClient::startRecording() { // start preview or recording status_t CameraClient::startCameraMode(camera_mode mode) { LOG1("startCameraMode(%d)", mode); - Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; @@ -557,6 +556,10 @@ status_t CameraClient::takePicture(int msgType) { CAMERA_MSG_COMPRESSED_IMAGE); enableMsgType(picMsgType); + mBurstCnt = mHardware->getParameters().getInt("num-snaps-per-shutter"); + if(mBurstCnt <= 0) + mBurstCnt = 1; + LOG1("mBurstCnt = %d", mBurstCnt); return mHardware->takePicture(); } @@ -659,6 +662,20 @@ status_t CameraClient::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) { } else if (cmd == CAMERA_CMD_PING) { // If mHardware is 0, checkPidAndHardware will return error. return OK; + } else if (cmd == CAMERA_CMD_HISTOGRAM_ON) { + enableMsgType(CAMERA_MSG_STATS_DATA); + } else if (cmd == CAMERA_CMD_HISTOGRAM_OFF) { + disableMsgType(CAMERA_MSG_STATS_DATA); + } else if (cmd == CAMERA_CMD_METADATA_ON) { + enableMsgType(CAMERA_MSG_META_DATA); + } else if (cmd == CAMERA_CMD_METADATA_OFF) { + disableMsgType(CAMERA_MSG_META_DATA); + } else if ( cmd == CAMERA_CMD_LONGSHOT_ON ) { + mLongshotEnabled = true; + } else if ( cmd == CAMERA_CMD_LONGSHOT_OFF ) { + mLongshotEnabled = false; + disableMsgType(CAMERA_MSG_SHUTTER); + disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE); } return mHardware->sendCommand(cmd, arg1, arg2); @@ -678,6 +695,9 @@ void CameraClient::disableMsgType(int32_t msgType) { #define CHECK_MESSAGE_INTERVAL 10 // 10ms bool CameraClient::lockIfMessageWanted(int32_t msgType) { +#ifdef MTK_HARDWARE + return true; +#endif int sleepCount = 0; while (mMsgEnabled & msgType) { if (mLock.tryLock() == NO_ERROR) { @@ -801,7 +821,9 @@ void CameraClient::handleShutter(void) { c->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0); if (!lockIfMessageWanted(CAMERA_MSG_SHUTTER)) return; } - disableMsgType(CAMERA_MSG_SHUTTER); + if ( !mLongshotEnabled ) { + disableMsgType(CAMERA_MSG_SHUTTER); + } // Shutters only happen in response to takePicture, so mark device as // idle now, until preview is restarted @@ -886,7 +908,13 @@ void CameraClient::handleRawPicture(const sp<IMemory>& mem) { // picture callback - compressed picture ready void CameraClient::handleCompressedPicture(const sp<IMemory>& mem) { - disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE); + if (mBurstCnt) + mBurstCnt--; + + if (!mBurstCnt && !mLongshotEnabled) { + LOG1("handleCompressedPicture mBurstCnt = %d", mBurstCnt); + disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE); + } sp<ICameraClient> c = mRemoteCallback; mLock.unlock(); diff --git a/services/camera/libcameraservice/api1/CameraClient.h b/services/camera/libcameraservice/api1/CameraClient.h index 17999a5..d2cb64a 100644 --- a/services/camera/libcameraservice/api1/CameraClient.h +++ b/services/camera/libcameraservice/api1/CameraClient.h @@ -164,6 +164,9 @@ private: // This function keeps trying to grab mLock, or give up if the message // is found to be disabled. It returns true if mLock is grabbed. bool lockIfMessageWanted(int32_t msgType); + + bool mLongshotEnabled; + int mBurstCnt; }; } diff --git a/services/camera/libcameraservice/api1/client2/StreamingProcessor.cpp b/services/camera/libcameraservice/api1/client2/StreamingProcessor.cpp index 66d7b00..9e6c0db 100644 --- a/services/camera/libcameraservice/api1/client2/StreamingProcessor.cpp +++ b/services/camera/libcameraservice/api1/client2/StreamingProcessor.cpp @@ -30,6 +30,7 @@ #include <utils/Trace.h> #include <gui/BufferItem.h> #include <gui/Surface.h> +#include <camera/ICameraRecordingProxy.h> #include <media/hardware/HardwareAPI.h> #include "common/CameraDeviceBase.h" @@ -826,6 +827,9 @@ status_t StreamingProcessor::processRecordingFrame() { (uint8_t*)heap->getBase() + offset); payload->eType = kMetadataBufferTypeANWBuffer; payload->pBuffer = imgBuffer.mGraphicBuffer->getNativeBuffer(); + // b/28466701 + payload->pBuffer = (ANativeWindowBuffer*)((uint8_t*)payload->pBuffer - + ICameraRecordingProxy::getCommonBaseAddress()); payload->nFenceFd = -1; ALOGVV("%s: Camera %d: Sending out ANWBuffer %p", @@ -874,6 +878,10 @@ void StreamingProcessor::releaseRecordingFrame(const sp<IMemory>& mem) { return; } + // b/28466701 + payload->pBuffer = (ANativeWindowBuffer*)(((uint8_t*)payload->pBuffer) + + ICameraRecordingProxy::getCommonBaseAddress()); + // Release the buffer back to the recording queue size_t itemIndex; for (itemIndex = 0; itemIndex < mRecordingBuffers.size(); itemIndex++) { diff --git a/services/camera/libcameraservice/device1/CameraHardwareInterface.h b/services/camera/libcameraservice/device1/CameraHardwareInterface.h index 7f14cd4..35947a9 100644 --- a/services/camera/libcameraservice/device1/CameraHardwareInterface.h +++ b/services/camera/libcameraservice/device1/CameraHardwareInterface.h @@ -25,7 +25,10 @@ #include <camera/Camera.h> #include <camera/CameraParameters.h> #include <system/window.h> -#include <hardware/camera.h> +#include "hardware/camera.h" +#ifdef USE_MEMORY_HEAP_ION +#include <binder/MemoryHeapIon.h> +#endif namespace android { @@ -322,6 +325,10 @@ public: void releaseRecordingFrame(const sp<IMemory>& mem) { ALOGV("%s(%s)", __FUNCTION__, mName.string()); + if (mem == NULL) { + ALOGE("%s: NULL memory reference", __FUNCTION__); + return; + } if (mDevice->ops->release_recording_frame) { ssize_t offset; size_t size; @@ -501,7 +508,11 @@ private: mBufSize(buf_size), mNumBufs(num_buffers) { +#ifdef USE_MEMORY_HEAP_ION + mHeap = new MemoryHeapIon(fd, buf_size * num_buffers); +#else mHeap = new MemoryHeapBase(fd, buf_size * num_buffers); +#endif commonInitialization(); } @@ -509,7 +520,11 @@ private: mBufSize(buf_size), mNumBufs(num_buffers) { +#ifdef USE_MEMORY_HEAP_ION + mHeap = new MemoryHeapIon(buf_size * num_buffers); +#else mHeap = new MemoryHeapBase(buf_size * num_buffers); +#endif commonInitialization(); } @@ -541,14 +556,24 @@ private: camera_memory_t handle; }; +#ifdef USE_MEMORY_HEAP_ION + static camera_memory_t* __get_memory(int fd, size_t buf_size, uint_t num_bufs, + void *ion_fd) + { +#else static camera_memory_t* __get_memory(int fd, size_t buf_size, uint_t num_bufs, void *user __attribute__((unused))) { +#endif CameraHeapMemory *mem; if (fd < 0) mem = new CameraHeapMemory(buf_size, num_bufs); else mem = new CameraHeapMemory(fd, buf_size, num_bufs); +#ifdef USE_MEMORY_HEAP_ION + if (ion_fd) + *((int *) ion_fd) = mem->mHeap->getHeapID(); +#endif mem->incStrong(mem); return &mem->handle; } |