@ -63,6 +63,7 @@ class Camera1 extends CameraImpl {
private ConstantMapper . MapperImpl mMapper = new ConstantMapper . Mapper1 ( ) ;
private ConstantMapper . MapperImpl mMapper = new ConstantMapper . Mapper1 ( ) ;
private boolean mIsSetup = false ;
private boolean mIsSetup = false ;
private boolean mIsCapturingImage = false ;
private boolean mIsCapturingImage = false ;
private boolean mIsCapturingVideo = false ;
private final Object mLock = new Object ( ) ;
private final Object mLock = new Object ( ) ;
@ -360,13 +361,17 @@ class Camera1 extends CameraImpl {
void captureImage ( ) {
void captureImage ( ) {
if ( mIsCapturingImage ) return ;
if ( mIsCapturingImage ) return ;
if ( ! isCameraOpened ( ) ) return ;
if ( ! isCameraOpened ( ) ) return ;
switch ( mSessionType ) {
if ( mIsCapturingVideo | | mSessionType = = SESSION_TYPE_VIDEO ) {
case SESSION_TYPE_PICTURE :
captureSnapshot ( ) ;
return ;
}
// Set boolean to wait for image callback
// Set boolean to wait for image callback
mIsCapturingImage = true ;
mIsCapturingImage = true ;
synchronized ( mLock ) {
synchronized ( mLock ) {
Camera . Parameters parameters = mCamera . getParameters ( ) ;
Camera . Parameters parameters = mCamera . getParameters ( ) ;
parameters . setRotation ( computeExifOrientation ( ) ) ;
parameters . setRotation ( computeExifRotation ( ) ) ;
// TODO: add flipping
mCamera . setParameters ( parameters ) ;
mCamera . setParameters ( parameters ) ;
}
}
mCamera . takePicture ( null , null , null ,
mCamera . takePicture ( null , null , null ,
@ -378,11 +383,13 @@ class Camera1 extends CameraImpl {
camera . startPreview ( ) ; // This is needed, read somewhere in the docs.
camera . startPreview ( ) ; // This is needed, read somewhere in the docs.
}
}
} ) ;
} ) ;
break ;
}
case SESSION_TYPE_VIDEO :
@Override
// If we are in a video session, camera captures are fast captures coming
void captureSnapshot ( ) {
// from the preview stream.
if ( mIsCapturingImage ) return ;
if ( ! isCameraOpened ( ) ) return ;
// TODO: will this work while recording a video? test...
// TODO: will this work while recording a video? test...
mIsCapturingImage = true ;
mIsCapturingImage = true ;
mCamera . setOneShotPreviewCallback ( new Camera . PreviewCallback ( ) {
mCamera . setOneShotPreviewCallback ( new Camera . PreviewCallback ( ) {
@ -390,8 +397,9 @@ class Camera1 extends CameraImpl {
public void onPreviewFrame ( final byte [ ] data , Camera camera ) {
public void onPreviewFrame ( final byte [ ] data , Camera camera ) {
// Got to rotate the preview frame, since byte[] data here does not include
// Got to rotate the preview frame, since byte[] data here does not include
// EXIF tags automatically set by camera. So either we add EXIF, or we rotate.
// EXIF tags automatically set by camera. So either we add EXIF, or we rotate.
// TODO: add exif, and also care about flipping.
Camera . Parameters params = mCamera . getParameters ( ) ;
Camera . Parameters params = mCamera . getParameters ( ) ;
final int rotation = computeExifOrien tation ( ) ;
final int rotation = computeExifRo tation ( ) ;
final boolean flip = rotation % 180 ! = 0 ;
final boolean flip = rotation % 180 ! = 0 ;
final int preWidth = mPreviewSize . getWidth ( ) ;
final int preWidth = mPreviewSize . getWidth ( ) ;
final int preHeight = mPreviewSize . getHeight ( ) ;
final int preHeight = mPreviewSize . getHeight ( ) ;
@ -409,8 +417,6 @@ class Camera1 extends CameraImpl {
} ) . start ( ) ;
} ) . start ( ) ;
}
}
} ) ;
} ) ;
break ;
}
}
}
@Override
@Override
@ -458,8 +464,9 @@ class Camera1 extends CameraImpl {
/ * *
/ * *
* Returns the orientation to be set as a exif tag . This is already managed by
* Returns the orientation to be set as a exif tag . This is already managed by
* the camera APIs as long as you call { @link Camera . Parameters # setRotation ( int ) } .
* the camera APIs as long as you call { @link Camera . Parameters # setRotation ( int ) } .
* This ignores flipping for facing camera .
* /
* /
private int computeExifOrien tation ( ) {
private int computeExifRo tation ( ) {
return ( mDeviceOrientation + mSensorOffset ) % 360 ;
return ( mDeviceOrientation + mSensorOffset ) % 360 ;
}
}
@ -507,7 +514,10 @@ class Camera1 extends CameraImpl {
@Override
@Override
void startVideo ( @NonNull File videoFile ) {
void startVideo ( @NonNull File videoFile ) {
mVideoFile = videoFile ;
mVideoFile = videoFile ;
if ( mIsCapturingVideo ) return ;
if ( ! isCameraOpened ( ) ) return ;
if ( mSessionType = = SESSION_TYPE_VIDEO ) {
if ( mSessionType = = SESSION_TYPE_VIDEO ) {
mIsCapturingVideo = true ;
initMediaRecorder ( ) ;
initMediaRecorder ( ) ;
try {
try {
mMediaRecorder . prepare ( ) ;
mMediaRecorder . prepare ( ) ;
@ -525,6 +535,7 @@ class Camera1 extends CameraImpl {
@Override
@Override
void endVideo ( ) {
void endVideo ( ) {
mIsCapturingVideo = false ;
mMediaRecorder . stop ( ) ;
mMediaRecorder . stop ( ) ;
mMediaRecorder . release ( ) ;
mMediaRecorder . release ( ) ;
mMediaRecorder = null ;
mMediaRecorder = null ;