{
ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device));
- Create(device);
+ CreateCameraDevice(device);
+ Initialize();
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Camera"/> class.
+ /// </summary>
+ /// <remarks>CameraDevice and Type will be selected internally by CameraDeviceManager.</remarks>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">The camera feature is not supported.</exception>
+ /// <since_tizen> 9 </since_tizen>
+ /// <feature> http://tizen.org/feature/camera </feature>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Camera() : this(CameraDevice.Default)
+ {
+ }
+
+ private void Initialize()
+ {
Capabilities = new CameraCapabilities(this);
Settings = new CameraSettings(this);
DisplaySettings = new CameraDisplaySettings(this);
SetState(CameraState.Created);
}
- private void Create(CameraDevice device)
+ private void CreateCameraDevice(CameraDevice device)
{
CameraDeviceType cameraDeviceType = CameraDeviceType.BuiltIn;
+ CameraDevice cameraDevice = device;
- try
+ if (device == CameraDevice.Default || CameraDeviceManager.IsSupported)
{
- using (var cameraDeviceManager = new CameraDeviceManager())
+ var deviceInfo = GetDeviceInformation();
+ if (!deviceInfo.Any())
{
- var deviceInfo = cameraDeviceManager.GetDeviceInformation();
- if (!deviceInfo.Any())
- {
- throw new InvalidOperationException("There's no available camera device.");
- }
-
- cameraDeviceType = deviceInfo.First().Type;
+ throw new InvalidOperationException("CDM is supported but, there's no available camera device.");
}
+
+ cameraDeviceType = deviceInfo.First().Type;
+ cameraDevice = deviceInfo.First().Device;
+ Log.Debug(CameraLog.Tag, $"Type:[{cameraDeviceType}], Device:[{cameraDevice}]");
}
- catch (NotSupportedException e)
+
+ CreateNativeCameraDevice(cameraDeviceType, cameraDevice);
+ }
+
+ private IEnumerable<CameraDeviceInformation> GetDeviceInformation()
+ {
+ using (var cameraDeviceManager = new CameraDeviceManager())
{
- Log.Info(CameraLog.Tag,
- $"CameraDeviceManager is not supported. {e.Message}. Not error.");
+ return cameraDeviceManager.GetDeviceInformation();
}
+ }
- if (cameraDeviceType == CameraDeviceType.BuiltIn ||
- cameraDeviceType == CameraDeviceType.Usb)
+ private void CreateNativeCameraDevice(CameraDeviceType type, CameraDevice device)
+ {
+ if (type == CameraDeviceType.BuiltIn || type == CameraDeviceType.Usb)
{
Native.Create(device, out _handle).
- ThrowIfFailed($"Failed to create {cameraDeviceType.ToString()} camera");
+ ThrowIfFailed($"Failed to create {type} camera");
}
else
{
Native.CreateNetworkCamera(device, out _handle).
- ThrowIfFailed($"Failed to create {cameraDeviceType.ToString()} camera");
+ ThrowIfFailed($"Failed to create {type} camera");
}
}