From 3cfe9068451634c69b18e4ba374ed3a796c69a95 Mon Sep 17 00:00:00 2001 From: Haesu Gwon Date: Fri, 30 Jun 2017 14:19:07 +0900 Subject: [PATCH] [Camera] minor code change Change-Id: I496a2a35a883f3853dfa59a61ad1e89b4c50d463 Signed-off-by: Haesu Gwon --- src/Tizen.Multimedia.Camera/Camera/Camera.cs | 29 ++--- .../Camera/CameraDisplaySettings.cs | 17 +-- .../Camera/CameraFeatures.cs | 5 +- .../Camera/CameraSettings.cs | 137 ++++++--------------- .../Interop/Interop.Camera.cs | 4 +- .../Interop/Interop.CameraSettings.cs | 2 +- 6 files changed, 53 insertions(+), 141 deletions(-) mode change 100644 => 100755 src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs diff --git a/src/Tizen.Multimedia.Camera/Camera/Camera.cs b/src/Tizen.Multimedia.Camera/Camera/Camera.cs index 0485c87..691f450 100755 --- a/src/Tizen.Multimedia.Camera/Camera/Camera.cs +++ b/src/Tizen.Multimedia.Camera/Camera/Camera.cs @@ -226,13 +226,11 @@ namespace Tizen.Multimedia { lock (_deviceStateChangedEventLock) { - int callbackId = 0; - _deviceStateChangedCallback = (CameraDevice device, CameraDeviceState state, IntPtr userData) => { _deviceStateChanged?.Invoke(null, new CameraDeviceStateChangedEventArgs(device, state)); }; - CameraErrorFactory.ThrowIfError(Native.SetDeviceStateChangedCallback(_deviceStateChangedCallback, IntPtr.Zero, out callbackId), + CameraErrorFactory.ThrowIfError(Native.SetDeviceStateChangedCallback(_deviceStateChangedCallback, IntPtr.Zero, out int callbackId), "Failed to set interrupt callback"); // Keep current callbackId and EventHandler pair to remove EventHandler later. @@ -249,8 +247,7 @@ namespace Tizen.Multimedia { _deviceStateChanged -= value; - int callbackId = 0; - _callbackIdInfo.TryGetValue(value, out callbackId); + _callbackIdInfo.TryGetValue(value, out int callbackId); Log.Info(CameraLog.Tag, "remove callbackId " + callbackId.ToString()); CameraErrorFactory.ThrowIfError(Native.UnsetDeviceStateChangedCallback(callbackId), @@ -479,9 +476,7 @@ namespace Tizen.Multimedia { ValidateNotDisposed(); - bool val = false; - - CameraErrorFactory.ThrowIfError(Native.GetDisplayReuseHint(_handle, out val), + CameraErrorFactory.ThrowIfError(Native.GetDisplayReuseHint(_handle, out bool val), "Failed to get camera display reuse hint"); return val; @@ -508,9 +503,7 @@ namespace Tizen.Multimedia { ValidateNotDisposed(); - CameraFacingDirection val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetFacingDirection(_handle, out val), + CameraErrorFactory.ThrowIfError(Native.GetFacingDirection(_handle, out var val), "Failed to get camera direction"); return val; @@ -530,9 +523,7 @@ namespace Tizen.Multimedia { ValidateNotDisposed(); - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetDeviceCount(_handle, out val), + CameraErrorFactory.ThrowIfError(Native.GetDeviceCount(_handle, out int val), "Failed to get camera device count"); return val; @@ -561,7 +552,7 @@ namespace Tizen.Multimedia ValidateState(CameraState.Created); ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device)); - CameraErrorFactory.ThrowIfError(Native.ChangeDevice(_handle, (int)device), + CameraErrorFactory.ThrowIfError(Native.ChangeDevice(_handle, device), "Failed to change the camera device"); } @@ -576,13 +567,12 @@ namespace Tizen.Multimedia /// In case of this feature is not supported. public CameraDeviceState GetDeviceState(CameraDevice device) { - int val = 0; ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device)); - CameraErrorFactory.ThrowIfError(Native.GetDeviceState(device, out val), + CameraErrorFactory.ThrowIfError(Native.GetDeviceState(device, out var val), "Failed to get the camera device state."); - return (CameraDeviceState)val; + return val; } /// @@ -596,10 +586,9 @@ namespace Tizen.Multimedia /// In case of this feature is not supported. public static CameraFlashState GetFlashState(CameraDevice device) { - CameraFlashState val = CameraFlashState.NotUsed; ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device)); - CameraErrorFactory.ThrowIfError(Native.GetFlashState(device, out val), + CameraErrorFactory.ThrowIfError(Native.GetFlashState(device, out var val), "Failed to get camera flash state"); return val; diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs b/src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs index 8149f55..0ded01e 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs @@ -42,9 +42,7 @@ namespace Tizen.Multimedia { get { - CameraDisplayMode val = CameraDisplayMode.LetterBox; - - CameraErrorFactory.ThrowIfError(Native.GetMode(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetMode(_camera.GetHandle(), out var val), "Failed to get camera display mode"); return val; @@ -68,9 +66,7 @@ namespace Tizen.Multimedia { get { - bool val = false; - - CameraErrorFactory.ThrowIfError(Native.GetVisible(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetVisible(_camera.GetHandle(), out bool val), "Failed to get visible value"); return val; @@ -144,13 +140,8 @@ namespace Tizen.Multimedia { get { - int x = 0; - int y = 0; - int width = 0; - int height = 0; - - CameraErrorFactory.ThrowIfError(Native.GetRoiArea(_camera.GetHandle(), out x, out y, out width, out height), - "Failed to get display roi area"); + CameraErrorFactory.ThrowIfError(Native.GetRoiArea(_camera.GetHandle(), + out int x, out int y, out int width, out int height), "Failed to get display roi area"); return new Rectangle(x, y, width, height); } diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs b/src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs index 9763f31..2361a9f 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs @@ -76,10 +76,7 @@ namespace Tizen.Multimedia private bool CheckRangeValid(GetRangeDelegate func) { - int min = 0; - int max = 0; - - CameraErrorFactory.ThrowIfError(func(_camera.GetHandle(), out min, out max), + CameraErrorFactory.ThrowIfError(func(_camera.GetHandle(), out int min, out int max), "Failed to check feature is suported or not."); return min < max; diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs b/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs index 8feaa6f..d188ef5 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs @@ -51,10 +51,7 @@ namespace Tizen.Multimedia private delegate CameraError GetRangeDelegate(IntPtr handle, out int min, out int max); private Range? GetRange(GetRangeDelegate func) { - int min = 0; - int max = 0; - - CameraErrorFactory.ThrowIfError(func(_camera.GetHandle(), out min, out max), + CameraErrorFactory.ThrowIfError(func(_camera.GetHandle(), out int min, out int max), "Failed to initialize the camera settings"); if (min > max) @@ -149,9 +146,7 @@ namespace Tizen.Multimedia { get { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetContrast(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetContrast(_camera.GetHandle(), out int val), "Failed to get camera contrast value"); return val; @@ -174,9 +169,7 @@ namespace Tizen.Multimedia { get { - bool val = false; - - CameraErrorFactory.ThrowIfError(Native.IsEnabledAutoContrast(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.IsEnabledAutoContrast(_camera.GetHandle(), out bool val), "Failed to get camera auto contrast"); return val; @@ -220,9 +213,7 @@ namespace Tizen.Multimedia { get { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetBrightness(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetBrightness(_camera.GetHandle(), out int val), "Failed to get camera brightness value"); return val; @@ -267,9 +258,7 @@ namespace Tizen.Multimedia { get { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetExposure(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetExposure(_camera.GetHandle(), out int val), "Failed to get camera exposure value"); return val; @@ -341,9 +330,7 @@ namespace Tizen.Multimedia { get { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetZoom(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetZoom(_camera.GetHandle(), out int val), "Failed to get zoom level"); return val; @@ -351,7 +338,7 @@ namespace Tizen.Multimedia set { - CameraErrorFactory.ThrowIfError(Native.SetZoom(_camera.GetHandle(), (int)value), + CameraErrorFactory.ThrowIfError(Native.SetZoom(_camera.GetHandle(), value), "Failed to set zoom level."); } } @@ -440,9 +427,7 @@ namespace Tizen.Multimedia { get { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetImageQuality(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetImageQuality(_camera.GetHandle(), out int val), "Failed to get image quality"); return val; @@ -471,9 +456,7 @@ namespace Tizen.Multimedia { get { - CameraFps val = CameraFps.Auto; - - CameraErrorFactory.ThrowIfError(Native.GetPreviewFps(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetPreviewFps(_camera.GetHandle(), out var val), "Failed to get camera preview fps"); return val; @@ -497,10 +480,7 @@ namespace Tizen.Multimedia { get { - int width = 0; - int height = 0; - - CameraErrorFactory.ThrowIfError(GetPreviewResolution(_camera.GetHandle(), out width, out height), + CameraErrorFactory.ThrowIfError(GetPreviewResolution(_camera.GetHandle(), out int width, out int height), "Failed to get camera preview resolution"); return new Size(width, height); @@ -526,10 +506,7 @@ namespace Tizen.Multimedia { get { - int width = 0; - int height = 0; - - CameraErrorFactory.ThrowIfError(GetRecommendedPreviewResolution(_camera.GetHandle(), out width, out height), + CameraErrorFactory.ThrowIfError(GetRecommendedPreviewResolution(_camera.GetHandle(), out int width, out int height), "Failed to get recommended preview resolution"); return new Size(width, height); @@ -547,9 +524,7 @@ namespace Tizen.Multimedia { get { - CameraPixelFormat val = 0; - - CameraErrorFactory.ThrowIfError(GetPreviewPixelFormat(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(GetPreviewPixelFormat(_camera.GetHandle(), out var val), "Failed to get preview format"); return val; @@ -573,10 +548,7 @@ namespace Tizen.Multimedia { get { - int width = 0; - int height = 0; - - CameraErrorFactory.ThrowIfError(GetCaptureResolution(_camera.GetHandle(), out width, out height), + CameraErrorFactory.ThrowIfError(GetCaptureResolution(_camera.GetHandle(), out int width, out int height), "Failed to get camera capture resolution"); return new Size(width, height); @@ -602,9 +574,7 @@ namespace Tizen.Multimedia { get { - CameraPixelFormat val = CameraPixelFormat.Invalid; - - CameraErrorFactory.ThrowIfError(GetCaptureFormat(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(GetCaptureFormat(_camera.GetHandle(), out var val), "Failed to get camera capture formats"); return val; @@ -629,9 +599,7 @@ namespace Tizen.Multimedia { get { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetBitrate(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetBitrate(_camera.GetHandle(), out int val), "Failed to get preview bitrate"); return val; @@ -639,7 +607,7 @@ namespace Tizen.Multimedia set { - CameraErrorFactory.ThrowIfError(Native.SetBitrate(_camera.GetHandle(), (int)value), + CameraErrorFactory.ThrowIfError(Native.SetBitrate(_camera.GetHandle(), value), "Failed to set encoded preview bitrate."); } } @@ -653,9 +621,7 @@ namespace Tizen.Multimedia { get { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetGopInterval(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetGopInterval(_camera.GetHandle(), out int val), "Failed to get preview gop interval"); return val; @@ -663,7 +629,7 @@ namespace Tizen.Multimedia set { - CameraErrorFactory.ThrowIfError(Native.SetGopInterval(_camera.GetHandle(), (int)value), + CameraErrorFactory.ThrowIfError(Native.SetGopInterval(_camera.GetHandle(), value), "Failed to set encoded preview gop intervals."); } } @@ -683,9 +649,7 @@ namespace Tizen.Multimedia { get { - CameraTheaterMode val = CameraTheaterMode.Disable; - - CameraErrorFactory.ThrowIfError(Native.GetTheaterMode(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetTheaterMode(_camera.GetHandle(), out var val), "Failed to get camera theater mode"); return val; @@ -709,9 +673,7 @@ namespace Tizen.Multimedia { get { - CameraEffectMode val = CameraEffectMode.None; - - CameraErrorFactory.ThrowIfError(Native.GetEffect(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetEffect(_camera.GetHandle(), out var val), "Failed to get camera effect"); return val; @@ -735,9 +697,7 @@ namespace Tizen.Multimedia { get { - CameraSceneMode val = CameraSceneMode.Normal; - - CameraErrorFactory.ThrowIfError(Native.GetSceneMode(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetSceneMode(_camera.GetHandle(), out var val), "Failed to get camera scene mode"); return val; @@ -761,9 +721,7 @@ namespace Tizen.Multimedia { get { - CameraFlashMode val = CameraFlashMode.Off; - - CameraErrorFactory.ThrowIfError(Native.GetFlashMode(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetFlashMode(_camera.GetHandle(), out var val), "Failed to get camera flash mode"); return val; @@ -786,9 +744,7 @@ namespace Tizen.Multimedia { get { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetLensOrientation(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetLensOrientation(_camera.GetHandle(), out var val), "Failed to get camera lens orientation"); return val; @@ -805,9 +761,7 @@ namespace Tizen.Multimedia { get { - CameraRotation val = CameraRotation.None; - - CameraErrorFactory.ThrowIfError(Native.GetStreamRotation(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetStreamRotation(_camera.GetHandle(), out var val), "Failed to get camera stream rotation"); return val; @@ -831,9 +785,7 @@ namespace Tizen.Multimedia { get { - CameraFlip val = CameraFlip.None; - - CameraErrorFactory.ThrowIfError(Native.GetFlip(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetFlip(_camera.GetHandle(), out var val), "Failed to get camera stream flip"); return val; @@ -862,9 +814,7 @@ namespace Tizen.Multimedia { get { - CameraHdrMode val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetHdrMode(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetHdrMode(_camera.GetHandle(), out var val), "Failed to get camera hdr mode"); return val; @@ -888,9 +838,7 @@ namespace Tizen.Multimedia { get { - bool val = false; - - CameraErrorFactory.ThrowIfError(Native.IsEnabledAntiShake(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.IsEnabledAntiShake(_camera.GetHandle(), out bool val), "Failed to get camera anti shake value"); return val; @@ -917,9 +865,7 @@ namespace Tizen.Multimedia { get { - bool val = false; - - CameraErrorFactory.ThrowIfError(Native.IsEnabledVideoStabilization(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.IsEnabledVideoStabilization(_camera.GetHandle(), out bool val), "Failed to get camera video stabilization"); return val; @@ -962,7 +908,8 @@ namespace Tizen.Multimedia set { ValidationUtil.ValidateEnum(typeof(CameraPtzType), value); - CameraErrorFactory.ThrowIfError(Native.SetPtzType(_camera.GetHandle(), (int)value), + + CameraErrorFactory.ThrowIfError(Native.SetPtzType(_camera.GetHandle(), value), "Failed to set camera ptz type."); } } @@ -990,9 +937,7 @@ namespace Tizen.Multimedia /// The camera already has been disposed. public int GetPan() { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetPan(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetPan(_camera.GetHandle(), out int val), "Failed to get the camera pan step."); return val; @@ -1021,9 +966,7 @@ namespace Tizen.Multimedia /// The camera already has been disposed. public int GetTilt() { - int val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetTilt(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetTilt(_camera.GetHandle(), out int val), "Failed to set the camera current position."); return val; @@ -1081,9 +1024,7 @@ namespace Tizen.Multimedia { get { - bool val = false; - - CameraErrorFactory.ThrowIfError(Native.IsEnabledTag(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.IsEnabledTag(_camera.GetHandle(), out bool val), "Failed to get camera enable tag"); return val; @@ -1166,12 +1107,8 @@ namespace Tizen.Multimedia { get { - double latitude = 0.0; - double longitude = 0.0; - double altitude = 0.0; - - CameraErrorFactory.ThrowIfError(Native.GetGeotag(_camera.GetHandle(), out latitude, out longitude, out altitude), - "Failed to get tag"); + CameraErrorFactory.ThrowIfError(Native.GetGeotag(_camera.GetHandle(), + out double latitude, out double longitude, out double altitude), "Failed to get tag"); return new Location(latitude, longitude, altitude); } @@ -1203,9 +1140,7 @@ namespace Tizen.Multimedia { get { - CameraTagOrientation val = 0; - - CameraErrorFactory.ThrowIfError(Native.GetTagOrientation(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetTagOrientation(_camera.GetHandle(), out var val), "Failed to get camera tag orientation"); return val; diff --git a/src/Tizen.Multimedia.Camera/Interop/Interop.Camera.cs b/src/Tizen.Multimedia.Camera/Interop/Interop.Camera.cs index 3262afe..0f4f289 100755 --- a/src/Tizen.Multimedia.Camera/Interop/Interop.Camera.cs +++ b/src/Tizen.Multimedia.Camera/Interop/Interop.Camera.cs @@ -59,7 +59,7 @@ internal static partial class Interop internal static extern CameraError Create(CameraDevice device, out IntPtr handle); [DllImport(Libraries.Camera, EntryPoint = "camera_change_device")] - internal static extern CameraError ChangeDevice(IntPtr handle, int device); + internal static extern CameraError ChangeDevice(IntPtr handle, CameraDevice device); [DllImport(Libraries.Camera, EntryPoint = "camera_destroy")] internal static extern CameraError Destroy(IntPtr handle); @@ -74,7 +74,7 @@ internal static partial class Interop internal static extern CameraError StopPreview(IntPtr handle); [DllImport(Libraries.Camera, EntryPoint = "camera_get_device_state")] - internal static extern CameraError GetDeviceState(CameraDevice device, out int state); + internal static extern CameraError GetDeviceState(CameraDevice device, out CameraDeviceState state); [DllImport(Libraries.Camera, EntryPoint = "camera_start_capture")] internal static extern CameraError StartCapture(IntPtr handle, CapturingCallback captureCallback, diff --git a/src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs b/src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs old mode 100644 new mode 100755 index 73d0ccf..1ff1a83 --- a/src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs +++ b/src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs @@ -230,6 +230,6 @@ internal static partial class Interop internal static extern CameraError GetTiltRange(IntPtr handle, out int min, out int max); [DllImport(Libraries.Camera, EntryPoint = "camera_attr_set_ptz_type")] - internal static extern CameraError SetPtzType(IntPtr handle, int type); + internal static extern CameraError SetPtzType(IntPtr handle, CameraPtzType type); } } -- 2.7.4