Skip to content

Commit c59d1a8

Browse files
author
Wu-cheng Li
committed
Do not set camera preview display if the surface is null.
MediaRecorder.setPreviewDisplay() is not required if applications use MediaRecorder.setCamera(). Besides, this causes a problem when apps use Camera.setPreviewTexture. Camera service thinks the surface texture from Camera.setPreviewTexture and the surface from MediaRecorder.setPreviewDisplay are different. bug:5988937 Change-Id: Ia345705b6679ef349db6e354feaa3cc0fe8bcd8c
1 parent d85d590 commit c59d1a8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

media/java/android/media/MediaRecorder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,15 @@ public MediaRecorder() {
124124
/**
125125
* Sets a Surface to show a preview of recorded media (video). Calls this
126126
* before prepare() to make sure that the desirable preview display is
127-
* set.
127+
* set. If {@link #setCamera(Camera)} is used and the surface has been
128+
* already set to the camera, application do not need to call this. If
129+
* this is called with non-null surface, the preview surface of the camera
130+
* will be replaced by the new surface. If this method is called with null
131+
* surface or not called at all, media recorder will not change the preview
132+
* surface of the camera.
128133
*
129134
* @param sv the Surface to use for the preview
135+
* @see android.hardware.Camera#setPreviewDisplay(android.view.SurfaceHolder)
130136
*/
131137
public void setPreviewDisplay(Surface sv) {
132138
mSurface = sv;

media/libstagefright/CameraSource.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,13 @@ status_t CameraSource::initWithCameraAccess(
515515
return err;
516516
}
517517

518-
// This CHECK is good, since we just passed the lock/unlock
519-
// check earlier by calling mCamera->setParameters().
520-
CHECK_EQ((status_t)OK, mCamera->setPreviewDisplay(mSurface));
518+
// Set the preview display. Skip this if mSurface is null because
519+
// applications may already set a surface to the camera.
520+
if (mSurface != NULL) {
521+
// This CHECK is good, since we just passed the lock/unlock
522+
// check earlier by calling mCamera->setParameters().
523+
CHECK_EQ((status_t)OK, mCamera->setPreviewDisplay(mSurface));
524+
}
521525

522526
// By default, do not store metadata in video buffers
523527
mIsMetaDataStoredInVideoBuffers = false;

0 commit comments

Comments
 (0)