Skip to content

Commit

Permalink
[Camera] Add new Camera constructor for camera device internal select…
Browse files Browse the repository at this point in the history
…ion (Samsung#5941)
  • Loading branch information
hsgwon authored Feb 6, 2024
1 parent 43729e6 commit 8e68141
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
59 changes: 33 additions & 26 deletions src/Tizen.Multimedia.Camera/Camera/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public partial class Camera : IDisposable, IDisplayable<CameraError>
private bool _disposed = false;
private CameraState _state = CameraState.None;
PinnedPreviewBuffer<byte> _previewBuffer;
private CameraDeviceManager _cameraDeviceManager;

/// <summary>
/// Initializes a new instance of the <see cref="Camera"/> class.
Expand All @@ -69,12 +68,20 @@ public Camera(CameraDevice device)
/// <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>
/// <remarks>
/// If <see cref="CameraDeviceManager"/> is supported, <see cref="CameraDevice"/> will be selected automatically by internal policy.<br/>
/// (User can check whether CameraDeviceManager is supported or not by using <see cref="CameraDeviceManager.IsCameraDeviceManagerSupported"/>.)<br/>
/// But, if not, this constructor will try to create Camera instance with <see cref="CameraDevice.CameraDevice0"/> by default.
/// </remarks>
/// <exception cref="InvalidOperationException">
/// There's no available camera device.
/// -or-<br/>
/// In case of any invalid operations.
/// </exception>
/// <exception cref="NotSupportedException">The camera feature is not supported.</exception>
/// <since_tizen> 9 </since_tizen>
/// <since_tizen> 12 </since_tizen>
/// <feature> http://tizen.org/feature/camera </feature>
[EditorBrowsable(EditorBrowsableState.Never)]
/// <seealso cref="CameraDeviceManager.IsCameraDeviceManagerSupported"/>
public Camera() : this(CameraDevice.Default)
{
}
Expand All @@ -95,31 +102,31 @@ private void CreateCameraDevice(CameraDevice device)
CameraDeviceType cameraDeviceType = CameraDeviceType.BuiltIn;
CameraDevice cameraDevice = device;

try
{
_cameraDeviceManager = new CameraDeviceManager();
}
catch (NotSupportedException)
{
Log.Info(CameraLog.Tag,
$"CameraDeviceManager is not supported. Not error.");
}

if (_cameraDeviceManager != null)
if (device == CameraDevice.Default)
{
var deviceInfo = _cameraDeviceManager.SupportedDevices;

// CameraDeviceManager is not used internally anymore.
_cameraDeviceManager.Dispose();
var deviceInfo = Enumerable.Empty<CameraDeviceInformation>();

if (!deviceInfo.Any())
try
{
throw new InvalidOperationException("CameraDeviceManager is supported but, there's no available camera device.");
using (var cameraDeviceManager = new CameraDeviceManager())
{
deviceInfo = cameraDeviceManager.SupportedDevices;
}

if (!deviceInfo.Any())
{
throw new InvalidOperationException("CameraDeviceManager is supported but, there's no available camera device.");
}

cameraDeviceType = deviceInfo.First().Type;
cameraDevice = deviceInfo.First().Device;
Log.Debug(CameraLog.Tag, $"Type:[{cameraDeviceType}], Auto selected camera device:[{cameraDevice}]");
}
catch (NotSupportedException)
{
Log.Debug(CameraLog.Tag, "CameraDeviceManager is not supported. Try to create Camera instance by CameraDevice0.");
cameraDevice = CameraDevice.CameraDevice0;
}

cameraDeviceType = deviceInfo.First().Type;
cameraDevice = deviceInfo.First().Device;
Log.Debug(CameraLog.Tag, $"Type:[{cameraDeviceType}], Device:[{cameraDevice}]");
}

CreateNativeCameraDevice(cameraDeviceType, cameraDevice);
Expand Down
22 changes: 22 additions & 0 deletions src/Tizen.Multimedia.Camera/Camera/CameraDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ public CameraDeviceManager()
d.Type == CameraDeviceType.Network)
.Any();

/// <summary>
/// Gets the state of Camera Device Manager support.
/// </summary>
/// <returns>true if camera device manager is supported.</returns>
/// <since_tizen> 11 </since_tizen>
public static bool IsCameraDeviceManagerSupported
{
get
{
try
{
using (var cameraDeviceManager = new CameraDeviceManager()) {}
}
catch (NotSupportedException)
{
return false;
}

return true;
}
}

/// <summary>
/// Retrieves all the supported camera devices and returns its information.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Tizen.Multimedia.Camera/Camera/CameraEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Tizen.Multimedia
public enum CameraDevice
{
/// <summary>
/// The CameraDevice will be decided internally by target policy.
/// The CameraDevice will be decided automatically by internal policy, if CameraDeviceManager is supported.
/// </summary>
/// <since_tizen> 9 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
Expand Down

0 comments on commit 8e68141

Please sign in to comment.