Merge change I05fd0df0 into eclair
* changes: Fix potential deadlock in stopPreview/stopRecord.
This commit is contained in:
@@ -683,22 +683,30 @@ void CameraService::Client::stopPreview()
|
|||||||
{
|
{
|
||||||
LOGD("stopPreview (pid %d)", getCallingPid());
|
LOGD("stopPreview (pid %d)", getCallingPid());
|
||||||
|
|
||||||
Mutex::Autolock lock(mLock);
|
// hold main lock during state transition
|
||||||
if (checkPid() != NO_ERROR) return;
|
{
|
||||||
|
Mutex::Autolock lock(mLock);
|
||||||
|
if (checkPid() != NO_ERROR) return;
|
||||||
|
|
||||||
if (mHardware == 0) {
|
if (mHardware == 0) {
|
||||||
LOGE("mHardware is NULL, returning.");
|
LOGE("mHardware is NULL, returning.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mHardware->stopPreview();
|
||||||
|
mHardware->disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
|
||||||
|
LOGD("stopPreview(), hardware stopped OK");
|
||||||
|
|
||||||
|
if (mSurface != 0 && !mUseOverlay) {
|
||||||
|
mSurface->unregisterBuffers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mHardware->stopPreview();
|
// hold preview buffer lock
|
||||||
mHardware->disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
|
{
|
||||||
LOGD("stopPreview(), hardware stopped OK");
|
Mutex::Autolock lock(mPreviewLock);
|
||||||
|
mPreviewBuffer.clear();
|
||||||
if (mSurface != 0 && !mUseOverlay) {
|
|
||||||
mSurface->unregisterBuffers();
|
|
||||||
}
|
}
|
||||||
mPreviewBuffer.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop recording mode
|
// stop recording mode
|
||||||
@@ -706,24 +714,31 @@ void CameraService::Client::stopRecording()
|
|||||||
{
|
{
|
||||||
LOGD("stopRecording (pid %d)", getCallingPid());
|
LOGD("stopRecording (pid %d)", getCallingPid());
|
||||||
|
|
||||||
Mutex::Autolock lock(mLock);
|
// hold main lock during state transition
|
||||||
if (checkPid() != NO_ERROR) return;
|
{
|
||||||
|
Mutex::Autolock lock(mLock);
|
||||||
|
if (checkPid() != NO_ERROR) return;
|
||||||
|
|
||||||
if (mHardware == 0) {
|
if (mHardware == 0) {
|
||||||
LOGE("mHardware is NULL, returning.");
|
LOGE("mHardware is NULL, returning.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mMediaPlayerBeep.get() != NULL) {
|
||||||
|
mMediaPlayerBeep->seekTo(0);
|
||||||
|
mMediaPlayerBeep->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
mHardware->stopRecording();
|
||||||
|
mHardware->disableMsgType(CAMERA_MSG_VIDEO_FRAME);
|
||||||
|
LOGD("stopRecording(), hardware stopped OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMediaPlayerBeep.get() != NULL) {
|
// hold preview buffer lock
|
||||||
mMediaPlayerBeep->seekTo(0);
|
{
|
||||||
mMediaPlayerBeep->start();
|
Mutex::Autolock lock(mPreviewLock);
|
||||||
|
mPreviewBuffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
mHardware->stopRecording();
|
|
||||||
mHardware->disableMsgType(CAMERA_MSG_VIDEO_FRAME);
|
|
||||||
LOGD("stopRecording(), hardware stopped OK");
|
|
||||||
|
|
||||||
mPreviewBuffer.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// release a recording frame
|
// release a recording frame
|
||||||
@@ -1216,10 +1231,10 @@ void CameraService::Client::copyFrameAndPostCopiedFrame(const sp<ICameraClient>&
|
|||||||
// provided it's big enough. Don't allocate the memory or
|
// provided it's big enough. Don't allocate the memory or
|
||||||
// perform the copy if there's no callback.
|
// perform the copy if there's no callback.
|
||||||
|
|
||||||
// hold the lock while we grab a reference to the preview buffer
|
// hold the preview lock while we grab a reference to the preview buffer
|
||||||
sp<MemoryHeapBase> previewBuffer;
|
sp<MemoryHeapBase> previewBuffer;
|
||||||
{
|
{
|
||||||
Mutex::Autolock lock(mLock);
|
Mutex::Autolock lock(mPreviewLock);
|
||||||
if (mPreviewBuffer == 0) {
|
if (mPreviewBuffer == 0) {
|
||||||
mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
|
mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
|
||||||
} else if (size > mPreviewBuffer->virtualSize()) {
|
} else if (size > mPreviewBuffer->virtualSize()) {
|
||||||
|
|||||||
@@ -181,7 +181,6 @@ private:
|
|||||||
mutable Condition mReady;
|
mutable Condition mReady;
|
||||||
sp<CameraService> mCameraService;
|
sp<CameraService> mCameraService;
|
||||||
sp<ISurface> mSurface;
|
sp<ISurface> mSurface;
|
||||||
sp<MemoryHeapBase> mPreviewBuffer;
|
|
||||||
int mPreviewCallbackFlag;
|
int mPreviewCallbackFlag;
|
||||||
|
|
||||||
sp<MediaPlayer> mMediaPlayerClick;
|
sp<MediaPlayer> mMediaPlayerClick;
|
||||||
@@ -197,6 +196,9 @@ private:
|
|||||||
sp<OverlayRef> mOverlayRef;
|
sp<OverlayRef> mOverlayRef;
|
||||||
int mOverlayW;
|
int mOverlayW;
|
||||||
int mOverlayH;
|
int mOverlayH;
|
||||||
|
|
||||||
|
mutable Mutex mPreviewLock;
|
||||||
|
sp<MemoryHeapBase> mPreviewBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user