// stop preview mode
void CameraClient::stopPreview() {
    LOG1("stopPreview (pid %d)", getCallingPid());
#ifdef QCOM_HARDWARE
    disableMsgType(CAMERA_MSG_PREVIEW_METADATA);
#endif
    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return;

#ifdef OMAP_ENHANCEMENT
    // According to framework documentation, preview needs
    // to be started for image capture. This will make sure
    // that image capture related messages get disabled if
    // not done already in their respective handlers.
    // If these messages come when in the midddle of
    // stopping preview we will deadlock the system in
    // lockIfMessageWanted().
    disableMsgType(CAMERA_MSG_POSTVIEW_FRAME);
#endif

    disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
#ifdef QCOM_HARDWARE
    //Disable picture related message types
    ALOGI("stopPreview: Disable picture related messages");
    int picMsgType = 0;
    picMsgType = (CAMERA_MSG_SHUTTER |
                  CAMERA_MSG_POSTVIEW_FRAME |
                  CAMERA_MSG_RAW_IMAGE |
                  CAMERA_MSG_RAW_IMAGE_NOTIFY |
                  CAMERA_MSG_COMPRESSED_IMAGE);
    disableMsgType(picMsgType);
#endif
    mHardware->stopPreview();

    mPreviewBuffer.clear();
}
// enable shutter sound
status_t CameraService::Client::enableShutterSound(bool enable) {
    LOG1("enableShutterSound (pid %d)", getCallingPid());

    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    if (enable) {
        mPlayShutterSound = true;
        return OK;
    }

    // Disabling shutter sound may not be allowed. In that case only
    // allow the mediaserver process to disable the sound.
    char value[PROPERTY_VALUE_MAX];
    property_get("ro.camera.sound.forced", value, "0");
    if (strcmp(value, "0") != 0) {
        // Disabling shutter sound is not allowed. Deny if the current
        // process is not mediaserver.
        if (getCallingPid() != getpid()) {
            LOGE("Failed to disable shutter sound. Permission denied (pid %d)", getCallingPid());
            return PERMISSION_DENIED;
        }
    }

    mPlayShutterSound = false;
    return OK;
}
// take a picture - image is returned in callback
status_t CameraService::Client::takePicture(int msgType) {
    LOG1("takePicture (pid %d): 0x%x", getCallingPid(), msgType);

    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    if ((msgType & CAMERA_MSG_RAW_IMAGE) &&
        (msgType & CAMERA_MSG_RAW_IMAGE_NOTIFY)) {
        LOGE("CAMERA_MSG_RAW_IMAGE and CAMERA_MSG_RAW_IMAGE_NOTIFY"
                " cannot be both enabled");
        return BAD_VALUE;
    }

    // We only accept picture related message types
    // and ignore other types of messages for takePicture().
    int picMsgType = msgType
                        & (CAMERA_MSG_SHUTTER |
                           CAMERA_MSG_POSTVIEW_FRAME |
                           CAMERA_MSG_RAW_IMAGE |
                           CAMERA_MSG_RAW_IMAGE_NOTIFY |
                           CAMERA_MSG_COMPRESSED_IMAGE);

    enableMsgType(picMsgType);

    return mHardware->takePicture();
}
Esempio n. 4
0
// take a picture - image is returned in callback
status_t CameraService::Client::takePicture(int msgType) {
    char prop[PROPERTY_VALUE_MAX];
    LOG1("takePicture (pid %d): 0x%x", getCallingPid(), msgType);

    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;
	//zxj ++
	mstopPreview = true;
	//zxj --
    if ((msgType & CAMERA_MSG_RAW_IMAGE) &&
        (msgType & CAMERA_MSG_RAW_IMAGE_NOTIFY)) {
        LOGE("CAMERA_MSG_RAW_IMAGE and CAMERA_MSG_RAW_IMAGE_NOTIFY"
                " cannot be both enabled");
        return BAD_VALUE;
    }

    // We only accept picture related message types
    // and ignore other types of messages for takePicture().
    int picMsgType = msgType
                        & (CAMERA_MSG_SHUTTER |
                           CAMERA_MSG_POSTVIEW_FRAME |
                           CAMERA_MSG_RAW_IMAGE |
                           CAMERA_MSG_RAW_IMAGE_NOTIFY |
                           CAMERA_MSG_COMPRESSED_IMAGE);
    disableMsgType(CAMERA_MSG_PREVIEW_METADATA);
    enableMsgType(picMsgType);
    mburstCnt = mHardware->getParameters().getInt("num-snaps-per-shutter");
    if(mburstCnt <= 0) mburstCnt = 1;
    LOG1("mburstCnt = %d", mburstCnt);
    return mHardware->takePicture();
}
bool CameraClient::previewEnabled() {
    LOG1("previewEnabled (pid %d)", getCallingPid());

    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return false;
    return mHardware->previewEnabled();
}
bool CameraService::Client::recordingEnabled() {
    LOG1("recordingEnabled (pid %d)", getCallingPid());

    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return false;
    return mHardware->recordingEnabled();
}
		status_t CameraService::Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
			LOG1("sendCommand (pid %d)", getCallingPid());
			int orientation;
			Mutex::Autolock lock(mLock);
			status_t result = checkPidAndHardware();
			if (result != NO_ERROR) return result;
			
			if (cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
				// The orientation cannot be set during preview.
				if (mHardware->previewEnabled()) {
					return INVALID_OPERATION;
				}
				// Mirror the preview if the camera is front-facing.
				orientation = getOrientation(arg1, mCameraFacing == CAMERA_FACING_FRONT);
				if (orientation == -1) return BAD_VALUE;
				
				if (mOrientation != orientation) {
					mOrientation = orientation;
					if (mOverlayRef != 0) mOrientationChanged = true;
				}
				return OK;
			}
			
			return mHardware->sendCommand(cmd, arg1, arg2);
		}
// get preview/capture parameters - key/value pairs
String8 CameraService::Client::getParameters() const {
    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return String8();

    String8 params(mHardware->getParameters().flatten());
    LOG1("getParameters (pid %d) (%s)", getCallingPid(), params.string());
    return params;
}
Esempio n. 9
0
status_t CameraClient::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
    LOG1("sendCommand (pid %d)", getCallingPid());
    int orientation;
    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    if (cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
        // Mirror the preview if the camera is front-facing.
        orientation = getOrientation(arg1, mCameraFacing == CAMERA_FACING_FRONT);
        if (orientation == -1) return BAD_VALUE;

        if (mOrientation != orientation) {
            mOrientation = orientation;
            if (mPreviewWindow != 0) {
                native_window_set_buffers_transform(mPreviewWindow.get(),
                        mOrientation);
            }
        }
        return OK;
    } else if (cmd == CAMERA_CMD_ENABLE_SHUTTER_SOUND) {
        switch (arg1) {
            case 0:
                return enableShutterSound(false);
            case 1:
                return enableShutterSound(true);
            default:
                return BAD_VALUE;
        }
        return OK;
    } else if (cmd == CAMERA_CMD_PLAY_RECORDING_SOUND) {
        mCameraService->playSound(CameraService::SOUND_RECORDING);
    } else if (cmd == CAMERA_CMD_SET_VIDEO_BUFFER_COUNT) {
        // Silently ignore this command
        return INVALID_OPERATION;
    } else if (cmd == CAMERA_CMD_PING) {
        // If mHardware is 0, checkPidAndHardware will return error.
        return OK;
#ifdef QCOM_HARDWARE
    } 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);
#endif
    }

    return mHardware->sendCommand(cmd, arg1, arg2);
}
status_t CameraService::Client::storeMetaDataInBuffers(bool enabled)
{
    LOG1("storeMetaDataInBuffers: %s", enabled? "true": "false");
    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) {
        return UNKNOWN_ERROR;
    }
    return mHardware->storeMetaDataInBuffers(enabled);
}
// get preview/capture parameters - key/value pairs
String8 CameraClient::getParameters() const {
    Mutex::Autolock lock(mLock);
    // The camera service can unconditionally get the parameters at all times
    if (getCallingPid() != mServicePid && checkPidAndHardware() != NO_ERROR) return String8();

    String8 params(mHardware->getParameters().flatten());
    LOG1("getParameters (pid %d) (%s)", getCallingPid(), params.string());
    return params;
}
status_t CameraService::Client::cancelAutoFocus() {
    LOG1("cancelAutoFocus (pid %d)", getCallingPid());

    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    return mHardware->cancelAutoFocus();
}
// set preview/capture parameters - key/value pairs
status_t CameraService::Client::setParameters(const String8& params) {
    LOG1("setParameters (pid %d) (%s)", getCallingPid(), params.string());

    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    CameraParameters p(params);
    return mHardware->setParameters(p);
}
// stop recording mode
void CameraService::Client::stopRecording() {
    LOG1("stopRecording (pid %d)", getCallingPid());
    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return;

    mCameraService->playSound(SOUND_RECORDING);
    disableMsgType(CAMERA_MSG_VIDEO_FRAME);
    mHardware->stopRecording();

    mPreviewBuffer.clear();
}
// stop preview mode
void CameraService::Client::stopPreview() {
    LOG1("stopPreview (pid %d)", getCallingPid());
    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return;


    disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
    mHardware->stopPreview();

    mPreviewBuffer.clear();
}
// set the preview callback flag to affect how the received frames from
// preview are handled.
void CameraService::Client::setPreviewCallbackFlag(int callback_flag) {
    LOG1("setPreviewCallbackFlag(%d) (pid %d)", callback_flag, getCallingPid());
    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return;

    mPreviewCallbackFlag = callback_flag;
    if (mPreviewCallbackFlag & CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK) {
        enableMsgType(CAMERA_MSG_PREVIEW_FRAME);
    } else {
        disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
    }
}
status_t CameraClient::setPreviewWindow(const sp<IBinder>& binder,
        const sp<ANativeWindow>& window) {
    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    // return if no change in surface.
    if (binder == mSurface) {
        return NO_ERROR;
    }

    if (window != 0) {
        result = native_window_api_connect(window.get(), NATIVE_WINDOW_API_CAMERA);
        if (result != NO_ERROR) {
            ALOGE("native_window_api_connect failed: %s (%d)", strerror(-result),
                    result);
            return result;
        }
    }

    // If preview has been already started, register preview buffers now.
    if (mHardware->previewEnabled()) {
        if (window != 0) {
            native_window_set_scaling_mode(window.get(),
                    NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
            native_window_set_buffers_transform(window.get(), mOrientation);
            result = mHardware->setPreviewWindow(window);
        }
#ifdef QCOM_HARDWARE
#ifndef NO_UPDATE_PREVIEW
    } else {
        if (window != 0) {
            native_window_set_buffers_transform(window.get(), mOrientation);
        }
        result = mHardware->setPreviewWindow(window);
#endif
#endif
    }

    if (result == NO_ERROR) {
        // Everything has succeeded.  Disconnect the old window and remember the
        // new window.
        disconnectWindow(mPreviewWindow);
        mSurface = binder;
        mPreviewWindow = window;
    } else {
        // Something went wrong after we connected to the new window, so
        // disconnect here.
        disconnectWindow(window);
    }

    return result;
}
Esempio n. 18
0
// take a picture - image is returned in callback
status_t CameraClient::takePicture(int msgType) {
    LOG1("takePicture (pid %d): 0x%x", getCallingPid(), msgType);

    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    if ((msgType & CAMERA_MSG_RAW_IMAGE) &&
        (msgType & CAMERA_MSG_RAW_IMAGE_NOTIFY)) {
        ALOGE("CAMERA_MSG_RAW_IMAGE and CAMERA_MSG_RAW_IMAGE_NOTIFY"
                " cannot be both enabled");
        return BAD_VALUE;
    }

    // We only accept picture related message types
    // and ignore other types of messages for takePicture().
    int picMsgType = msgType
                        & (CAMERA_MSG_SHUTTER |
                           CAMERA_MSG_POSTVIEW_FRAME |
                           CAMERA_MSG_RAW_IMAGE |
                           CAMERA_MSG_RAW_IMAGE_NOTIFY |
#if defined(OMAP_ICS_CAMERA) || defined(OMAP_ENHANCEMENT_BURST_CAPTURE)
                           CAMERA_MSG_RAW_BURST |
#endif
                           CAMERA_MSG_COMPRESSED_IMAGE);

#if defined(OMAP_ICS_CAMERA) || defined(OMAP_ENHANCEMENT_BURST_CAPTURE)
    picMsgType |= CAMERA_MSG_COMPRESSED_BURST_IMAGE;
#endif
#ifdef CAMERA_MSG_MGMT
    disableMsgType(CAMERA_MSG_PREVIEW_METADATA);
#endif
    enableMsgType(picMsgType);
#ifdef QCOM_HARDWARE
    mBurstCnt = mHardware->getParameters().getInt("num-snaps-per-shutter");
    if(mBurstCnt <= 0)
        mBurstCnt = 1;

    LOG1("mBurstCnt = %d", mBurstCnt);

    // HTC HDR mode requires that we snap multiple times, but only get one jpeg
    int numJpegs = mHardware->getParameters().getInt("num-jpegs-per-shutter");
    if (numJpegs == 1 && mBurstCnt > 1) {
        while (mBurstCnt > 1) {
            result = mHardware->takePicture();
            mBurstCnt--;
        }
    }
#endif

    return mHardware->takePicture();
}
Esempio n. 19
0
status_t CameraService::Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
    LOG1("sendCommand (pid %d)", getCallingPid());
    int orientation;
    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    if (cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
        // Mirror the preview if the camera is front-facing.
        orientation = getOrientation(arg1, mCameraFacing == CAMERA_FACING_FRONT);
        if (orientation == -1) return BAD_VALUE;

        if (mOrientation != orientation) {
            mOrientation = orientation;
            if (mPreviewWindow != 0) {
                native_window_set_buffers_transform(mPreviewWindow.get(),
                        mOrientation);
            }
        }
        return OK;
    } else if (cmd == CAMERA_CMD_ENABLE_SHUTTER_SOUND) {
        switch (arg1) {
            case 0:
                enableShutterSound(false);
                break;
            case 1:
                enableShutterSound(true);
                break;
            default:
                return BAD_VALUE;
        }
        return OK;
    } else if (cmd == CAMERA_CMD_PLAY_RECORDING_SOUND) {
        mCameraService->playSound(SOUND_RECORDING);
    }
    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_START_FACE_DETECTION) {
      mFaceDetection = true;
      enableMsgType(CAMERA_MSG_PREVIEW_METADATA);
    } else if (cmd ==   CAMERA_CMD_STOP_FACE_DETECTION) {
      mFaceDetection = false;
      disableMsgType(CAMERA_MSG_PREVIEW_METADATA);
    }


    return mHardware->sendCommand(cmd, arg1, arg2);
}
		// take a picture - image is returned in callback
		status_t CameraService::Client::takePicture() {
			LOG1("takePicture (pid %d)", getCallingPid());
			
			Mutex::Autolock lock(mLock);
			status_t result = checkPidAndHardware();
			if (result != NO_ERROR) return result;
			
			enableMsgType(CAMERA_MSG_SHUTTER |
						  CAMERA_MSG_POSTVIEW_FRAME |
						  CAMERA_MSG_RAW_IMAGE |
						  CAMERA_MSG_COMPRESSED_IMAGE);
			
			return mHardware->takePicture();
		}
status_t CameraClient::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
    LOG1("sendCommand (pid %d)", getCallingPid());
    int orientation;
    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    if (cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
//!++
        LOG1("CAMERA_CMD_SET_DISPLAY_ORIENTATION - tid(%d), (degrees, mirror)=(%d, %d)", ::gettid(), arg1, mCameraFacing);
//!--
        // Mirror the preview if the camera is front-facing.
        orientation = getOrientation(arg1, mCameraFacing == CAMERA_FACING_FRONT);
        if (orientation == -1) return BAD_VALUE;

        if (mOrientation != orientation) {
            mOrientation = orientation;
            if (mPreviewWindow != 0) {
                native_window_set_buffers_transform(mPreviewWindow.get(),
                        mOrientation);
            }
        }
        return OK;
    } else if (cmd == CAMERA_CMD_ENABLE_SHUTTER_SOUND) {
        switch (arg1) {
            case 0:
                return enableShutterSound(false);
            case 1:
                return enableShutterSound(true);
            default:
                return BAD_VALUE;
        }
        return OK;
    } else if (cmd == CAMERA_CMD_PLAY_RECORDING_SOUND) {
        mCameraService->playSound(CameraService::SOUND_RECORDING);
    } else if (cmd == CAMERA_CMD_SET_VIDEO_BUFFER_COUNT) {
        // Silently ignore this command
        return INVALID_OPERATION;
    } else if (cmd == CAMERA_CMD_PING) {
        // If mHardware is 0, checkPidAndHardware will return error.
        return OK;
    }

    return mHardware->sendCommand(cmd, arg1, arg2);
}
		// stop preview mode
		void CameraService::Client::stopPreview() {
			LOG1("stopPreview (pid %d)", getCallingPid());
			Mutex::Autolock lock(mLock);
			if (checkPidAndHardware() != NO_ERROR) return;
			
			disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
			mHardware->stopPreview();
			
			if (mSurface != 0 && !mUseOverlay) {
				mSurface->unregisterBuffers();
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
			} else {
				mOverlayW = 0;
				mOverlayH = 0;
#endif
			}
			
			mPreviewBuffer.clear();
		}
// release a recording frame
void CameraClient::releaseRecordingFrame(const sp<IMemory>& mem) {
//!++
#if 1
    ssize_t offset;
    size_t size;
    sp<IMemoryHeap> heap = mem->getMemory(&offset, &size);
    void *data = ((uint8_t *)heap->base()) + offset;
    LOG1("RRF:VA(%p)", data);
#endif
//!--
    Mutex::Autolock lock(mLock);
//!++
#if 1
    LOG1("RRF:VA(%p), get mLock (%d)", data, getCallingPid()); 
#endif
//!--
    if (checkPidAndHardware() != NO_ERROR) return;
    mHardware->releaseRecordingFrame(mem);
}
Esempio n. 24
0
// start preview or recording
status_t CameraClient::startCameraMode(camera_mode mode) {
    LOG1("startCameraMode(%d)", mode);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    switch(mode) {
        case CAMERA_PREVIEW_MODE:
            if (mSurface == 0 && mPreviewWindow == 0) {
                LOG1("mSurface is not set yet.");
                // still able to start preview in this case.
            }
            return startPreviewMode();
        case CAMERA_RECORDING_MODE:
            if (mSurface == 0 && mPreviewWindow == 0) {
                ALOGE("mSurface or mPreviewWindow must be set before startRecordingMode.");
                return INVALID_OPERATION;
            }
            return startRecordingMode();
        default:
            return UNKNOWN_ERROR;
    }
}
// stop recording mode
void CameraClient::stopRecording() {
    LOG1("stopRecording (pid %d)", getCallingPid());
    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return;

    disableMsgType(CAMERA_MSG_VIDEO_FRAME);
#ifdef QCOM_HARDWARE
    //Disable picture related message types
    ALOGI("stopRecording: Disable picture related messages");
    int picMsgType = 0;
    picMsgType = (CAMERA_MSG_SHUTTER |
                  CAMERA_MSG_POSTVIEW_FRAME |
                  CAMERA_MSG_RAW_IMAGE |
                  CAMERA_MSG_RAW_IMAGE_NOTIFY |
                  CAMERA_MSG_COMPRESSED_IMAGE);
    disableMsgType(picMsgType);
#endif
    mHardware->stopRecording();
    mCameraService->playSound(CameraService::SOUND_RECORDING);

    mPreviewBuffer.clear();
}
	// set the ISurface that the preview will use
	status_t CameraService::Client::setPreviewDisplay(const sp<ISurface>& surface) {
		LOG1("setPreviewDisplay(%p) (pid %d)", surface.get(), getCallingPid());
		Mutex::Autolock lock(mLock);
		status_t result = checkPidAndHardware();
		if (result != NO_ERROR) return result;
		
		result = NO_ERROR;
		
		// return if no change in surface.
		// asBinder() is safe on NULL (returns NULL)
		if (surface->asBinder() == mSurface->asBinder()) {
			return result;
		}
		
		if (mSurface != 0) {
			LOG1("clearing old preview surface %p", mSurface.get());
			if (mUseOverlay) {
				// Force the destruction of any previous overlay
				sp<Overlay> dummy;
				mHardware->setOverlay(dummy);
				mOverlayRef = 0;
			} else {
				mSurface->unregisterBuffers();
			}
		}
		mSurface = surface;
		mOverlayRef = 0;
		// If preview has been already started, set overlay or register preview
		// buffers now.
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
		if (mHardware->previewEnabled() || mUseOverlay) {
#else
			if (mHardware->previewEnabled()) {
#endif
				if (mUseOverlay) {
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
					if (mSurface != NULL) {
#endif
						result = setOverlay();
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
					}
#endif
				} else if (mSurface != 0) {
					result = registerPreviewBuffers();
				}
			}
			
			return result;
		}
		
		status_t CameraService::Client::registerPreviewBuffers() {
			int w, h;
			CameraParameters params(mHardware->getParameters());
			params.getPreviewSize(&w, &h);
			
			//for 720p recording , preview can be 800X448
			if(w ==  preview_sizes[0].width && h== preview_sizes[0].height){
				LOGD("registerpreviewbufs :changing dimensions to 768X432 for 720p recording.");
				w = preview_sizes[1].width;
				h = preview_sizes[1].height;
			}
			
			// FIXME: don't use a hardcoded format here.
			ISurface::BufferHeap buffers(w, h, w, h,
										 HAL_PIXEL_FORMAT_YCrCb_420_SP,
										 mOrientation,
										 0,
										 mHardware->getPreviewHeap());
			
			status_t result = mSurface->registerBuffers(buffers);
			if (result != NO_ERROR) {
				LOGE("registerBuffers failed with status %d", result);
			}
			return result;
		}
		
		status_t CameraService::Client::setOverlay() {
			int w, h;
			CameraParameters params(mHardware->getParameters());
			params.getPreviewSize(&w, &h);
			
			//for 720p recording , preview can be 800X448
			if(w == preview_sizes[0].width && h==preview_sizes[0].height){
				LOGD("Changing overlay dimensions to 768X432 for 720p recording.");
				w = preview_sizes[1].width;
				h = preview_sizes[1].height;
			}
			
			if (w != mOverlayW || h != mOverlayH || mOrientationChanged) {
				// Force the destruction of any previous overlay
				sp<Overlay> dummy;
				mHardware->setOverlay(dummy);
				mOverlayRef = 0;
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
				if (mOverlay != NULL) {
					mOverlay->destroy();
				}
#endif
				mOrientationChanged = false;
			}
			
			status_t result = NO_ERROR;
			if (mSurface == 0) {
				result = mHardware->setOverlay(NULL);
			} else {
				if (mOverlayRef == 0) {
					// FIXME:
					// Surfaceflinger may hold onto the previous overlay reference for some
					// time after we try to destroy it. retry a few times. In the future, we
					// should make the destroy call block, or possibly specify that we can
					// wait in the createOverlay call if the previous overlay is in the
					// process of being destroyed.
					for (int retry = 0; retry < 50; ++retry) {
						mOverlayRef = mSurface->createOverlay(w, h,
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
															  HAL_PIXEL_FORMAT_YCbCr_420_SP,
#else
															  OVERLAY_FORMAT_DEFAULT,
#endif
															  mOrientation);
						if (mOverlayRef != 0) break;
						LOGW("Overlay create failed - retrying");
						usleep(20000);
					}
					if (mOverlayRef == 0) {
						LOGE("Overlay Creation Failed!");
						return -EINVAL;
					}
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
					mOverlay = new Overlay(mOverlayRef);
					result = mHardware->setOverlay(mOverlay);
#else
					result = mHardware->setOverlay(new Overlay(mOverlayRef));
#endif
				}
			}
			if (result != NO_ERROR) {
				LOGE("mHardware->setOverlay() failed with status %d\n", result);
				return result;
			}
			
			mOverlayW = w;
			mOverlayH = h;
			
			return result;
		}
		
		// set the preview callback flag to affect how the received frames from
		// preview are handled.
		void CameraService::Client::setPreviewCallbackFlag(int callback_flag) {
			LOG1("setPreviewCallbackFlag(%d) (pid %d)", callback_flag, getCallingPid());
			Mutex::Autolock lock(mLock);
			if (checkPidAndHardware() != NO_ERROR) return;
			
			mPreviewCallbackFlag = callback_flag;
			
			// If we don't use overlay, we always need the preview frame for display.
			// If we do use overlay, we only need the preview frame if the user
			// wants the data.
			if (mUseOverlay) {
				if(mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ENABLE_MASK) {
					enableMsgType(CAMERA_MSG_PREVIEW_FRAME);
				} else {
					disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
				}
			}
		}
// release a recording frame
void CameraService::Client::releaseRecordingFrame(const sp<IMemory>& mem) {
    Mutex::Autolock lock(mLock);
    if (checkPidAndHardware() != NO_ERROR) return;
    mHardware->releaseRecordingFrame(mem);
}