@@ -406,8 +406,8 @@ class LCamera (private[this] val camera: CameraDevice) (implicit cameraManager:
406406 createSession(List (previewSurface, imageReader.getSurface), (session) => new BulbSession (session, previewSurface, imageReader))
407407 }
408408
409- def openVideoSession (previewSurface : Surface , vc : VideoConfiguration ): Unit = {
410- val mr = new MyMediaRecorder (vc, windowManager.getDefaultDisplay.getRotation )
409+ def openVideoSession (previewSurface : Surface , vc : VideoConfiguration , orientation : Int ): Unit = {
410+ val mr = new MyMediaRecorder (vc, orientation )
411411 createSession(List (previewSurface, mr.getSurface), (session) => new VideoSession (session, previewSurface, mr))
412412 }
413413
@@ -427,7 +427,7 @@ class LCamera (private[this] val camera: CameraDevice) (implicit cameraManager:
427427 override def onImageAvailable (reader : ImageReader ): Unit = { rawImageChannel.write(reader.acquireNextImage()) }
428428 }, null )
429429
430- def capture (focus : Focus , exposure : Exposure , successHandler : (TotalCaptureResult , Image , Image ) => Unit , orientation : Int = windowManager.getDefaultDisplay.getRotation ): Unit = {
430+ def capture (focus : Focus , exposure : Exposure , orientation : Int , successHandler : (TotalCaptureResult , Image , Image ) => Unit ): Unit = {
431431 if (! capturing()) {
432432 debug(s " Starting capture using $camera" )
433433 capturingVar() = true
@@ -483,7 +483,7 @@ class LCamera (private[this] val camera: CameraDevice) (implicit cameraManager:
483483 }, null )
484484
485485 case class Request (focus : Focus , exposure : Exposure , handler : (TotalCaptureResult , Image ) => Unit )
486- def burstCapture (requests : List [Request ], orientation : Int = windowManager.getDefaultDisplay.getRotation ): Unit = {
486+ def burstCapture (requests : List [Request ], orientation : Int ): Unit = {
487487 if (! capturing()) {
488488 debug(s " Starting burst capture using $camera" )
489489 capturingVar() = true
@@ -546,7 +546,7 @@ class LCamera (private[this] val camera: CameraDevice) (implicit cameraManager:
546546 override def onImageAvailable (reader : ImageReader ): Unit = { imageChannel.write(reader.acquireNextImage()) }
547547 }, null )
548548
549- def startCapturing (focus : Focus , exposure : Exposure , handler : (TotalCaptureResult , Image , Int ) => Unit , orientation : Int = windowManager.getDefaultDisplay.getRotation ): Unit = {
549+ def startCapturing (focus : Focus , exposure : Exposure , orientation : Int , handler : (TotalCaptureResult , Image , Int ) => Unit ): Unit = {
550550 if (! capturing()) {
551551 debug(s " Starting bulb capture using $camera" )
552552 capturingVar() = true
@@ -727,13 +727,20 @@ class MainActivity extends SActivity with Observable {
727727 val userVideoConfiguration = Var (videoConfigurations(0 ))
728728 val videoConfiguration = Rx { availableVideoConfigurations() find { _ == userVideoConfiguration() } orElse availableVideoConfigurations().lift(0 ) }
729729
730- val orientation = Var (windowManager.getDefaultDisplay.getRotation)
730+ val orientationVar = Var (windowManager.getDefaultDisplay.getRotation)
731731
732732 val orientationEventListener = new OrientationEventListener (this ) {
733- override def onOrientationChanged (ignored : Int ) = {
734- val newOrientation = windowManager.getDefaultDisplay.getRotation
735- if (orientation() != newOrientation) {
736- orientation() = newOrientation
733+ override def onOrientationChanged (deg : Int ) = {
734+ val newOrientation =
735+ if (deg >= 0 && deg < 45 || deg >= 315 && deg < 360 ) Surface .ROTATION_0
736+ else if (deg >= 45 && deg < 135 ) Surface .ROTATION_270
737+ else if (deg >= 135 && deg < 225 ) Surface .ROTATION_180
738+ else if (deg >= 225 && deg < 315 ) Surface .ROTATION_90
739+ else Surface .ROTATION_0
740+
741+ debug(newOrientation.toString)
742+ if (orientationVar() != newOrientation) {
743+ orientationVar() = newOrientation // FIXME: Re-create video session
737744 }
738745 }
739746 }
@@ -776,7 +783,7 @@ class MainActivity extends SActivity with Observable {
776783 new Surface (texture)
777784 }}
778785
779- observe { for { (rotation, cameraOption, _) <- Rx { (orientation(), lcamera(), previewSurface()) } ; camera <- cameraOption } {
786+ observe { for { (cameraOption, _) <- Rx { (lcamera(), previewSurface()) } ; camera <- cameraOption } {
780787 if (textureView.isAvailable) {
781788 textureView.setTransform {
782789 val textureSize = camera.streamConfigurationMap.getOutputSizes(textureView.getSurfaceTexture.getClass).filter(sz => sz <= camera.rawSize && sz <= new Size (1600 , 1200 ))(0 )
@@ -785,7 +792,7 @@ class MainActivity extends SActivity with Observable {
785792 bufferRect.offset(viewRect.centerX - bufferRect.centerX, viewRect.centerY - bufferRect.centerY)
786793 val matrix = new Matrix ()
787794 matrix.setRectToRect(viewRect, bufferRect, Matrix .ScaleToFit .CENTER )
788- matrix.postRotate(rotation * 90 , viewRect.centerX, viewRect.centerY)
795+ // matrix.postRotate(rotation * 90, viewRect.centerX, viewRect.centerY) // TODO: Rotate by the difference of screen orientation and camera orientation
789796 matrix
790797 }
791798 }
@@ -815,17 +822,17 @@ class MainActivity extends SActivity with Observable {
815822 val time = new Time
816823 time.setToNow()
817824 val filePathBase = Utils .createPathIfNotExist(Environment .getExternalStoragePublicDirectory(Environment .DIRECTORY_DCIM ) + " /Camera/" ) + time.format(" IMG_%Y%m%d_%H%M%S" )
818- val orientation = windowManager.getDefaultDisplay.getRotation
825+ val orientation = orientationVar()
819826
820- ps.capture(focus(), exposure(), { (result, jpegImage, rawImage) => {
827+ ps.capture(focus(), exposure(), orientation, { (result, jpegImage, rawImage) => {
821828 saveJpegFile(s " $filePathBase.jpg " , jpegImage)
822829 if (saveDng()) { saveDngFile(s " $filePathBase.dng " , camera.characteristics, result, rawImage, orientation) }
823830 }})
824831 case Some (bs : camera.BurstSession ) =>
825832 val time = new Time
826833 time.setToNow()
827834 val filePathBase = Utils .createPathIfNotExist(Environment .getExternalStoragePublicDirectory(Environment .DIRECTORY_DCIM ) + " /Camera/" ) + time.format(" IMG_%Y%m%d_%H%M%S" )
828- val orientation = windowManager.getDefaultDisplay.getRotation
835+ val orientation = orientationVar()
829836
830837 val requests = for (n <- 1 to numBursts()) yield {
831838 val exp = if (exposureBracketing() == 0 ) exposure() else {
@@ -842,22 +849,22 @@ class MainActivity extends SActivity with Observable {
842849 })
843850 }
844851
845- bs.burstCapture(requests.toList)
852+ bs.burstCapture(requests.toList, orientation )
846853 case Some (bs : camera.BulbSession ) => if (! bs.capturing()) {
847854 val time = new Time
848855 time.setToNow()
849856 val filePathBase = Utils .createPathIfNotExist(Environment .getExternalStoragePublicDirectory(Environment .DIRECTORY_DCIM ) + " /Camera/" ) + time.format(" IMG_%Y%m%d_%H%M%S" )
850- val orientation = windowManager.getDefaultDisplay.getRotation
857+ val orientation = orientationVar()
851858
852- bs.startCapturing(focus(), exposure(), (result, image, n) => saveDngFile(s " ${filePathBase}_ $n.dng " , camera.characteristics, result, image, orientation))
859+ bs.startCapturing(focus(), exposure(), orientation, (result, image, n) => saveDngFile(s " ${filePathBase}_ $n.dng " , camera.characteristics, result, image, orientation))
853860 } else bs.stopCapturing()
854861 case Some (vs : camera.VideoSession ) =>
855862 if (! vs.recording()) {
856863 vs.startRecording(focus(), exposure())
857864 } else {
858865 vs.stopRecording()
859866 for { surface <- previewSurface() ; vc <- videoConfiguration() } {
860- camera.openVideoSession(surface, vc)
867+ camera.openVideoSession(surface, vc, orientationVar() )
861868 }
862869 }
863870 case _ =>
@@ -1139,7 +1146,7 @@ class MainActivity extends SActivity with Observable {
11391146 += (makeModeButton(R .drawable.ic_photo_mode, isPhotoSession, { (camera, surface) => camera.openPhotoSession(surface) }))
11401147 += (makeModeButton(R .drawable.ic_burst_mode, isBurstSession, { (camera, surface) => camera.openBurstSession(surface, burstCaptureRawYuv(), maxBursts) }))
11411148 += (makeModeButton(R .drawable.ic_bulb_mode , isBulbSession , { (camera, surface) => camera.openBulbSession(surface) }))
1142- += (makeModeButton(R .drawable.ic_video_mode, isVideoSession, { (camera, surface) => videoConfiguration() foreach { vc => camera.openVideoSession(surface, vc) } }))
1149+ += (makeModeButton(R .drawable.ic_video_mode, isVideoSession, { (camera, surface) => videoConfiguration() foreach { vc => camera.openVideoSession(surface, vc, orientationVar() ) } }))
11431150 }
11441151
11451152 val bottomBar = new SLinearLayout {
0 commit comments