[Camera] Add extra stream format for production (#3257)
authorHaesu Gwon <haesu.gwon@samsung.com>
Tue, 6 Jul 2021 07:55:12 +0000 (16:55 +0900)
committerGitHub <noreply@github.com>
Tue, 6 Jul 2021 07:55:12 +0000 (16:55 +0900)
* [Camera] Add extra stream format for production

src/Tizen.Multimedia.Camera/Camera/CameraDeviceManager.cs
src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs
src/Tizen.Multimedia.Camera/Interop/Interop.Camera.cs

index 0291272..496a554 100644 (file)
@@ -101,18 +101,7 @@ namespace Tizen.Multimedia
         }
 
         internal static CameraDeviceInformation GetDeviceInformation(Native.CameraDeviceStruct device) =>
-            new CameraDeviceInformation(device.Type, device.device, GetString(device.name), GetString(device.id));
-
-        private static string GetString(char[] word)
-        {
-            int length = 0;
-            while(word[length] != '\0')
-            {
-                length++;
-            }
-
-            return new String(word, 0, length);
-        }
+            new CameraDeviceInformation(device.Type, device.device, device.name, device.id, device.extraStreamNum);
 
         private event EventHandler<CameraDeviceConnectionChangedEventArgs> _deviceConnectionChanged;
         /// <summary>
@@ -231,7 +220,7 @@ namespace Tizen.Multimedia
     /// </summary>
     /// <since_tizen> 9 </since_tizen>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class CameraDeviceInformation
+    public struct CameraDeviceInformation
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="CameraDeviceInformation"/> class.
@@ -240,11 +229,12 @@ namespace Tizen.Multimedia
         /// <param name="device"><see cref="CameraDevice"/></param>
         /// <param name="name">The name of camera device</param>
         /// <param name="id">The ID of camera device</param>
+        /// <param name="numberOfExtraStream">The number of extra stream</param>
         /// <exception cref="ArgumentException">Invalid enumeration.</exception>
         /// <exception cref="ArgumentNullException">name or id is null.</exception>
         /// <since_tizen> 9 </since_tizen>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        internal CameraDeviceInformation(CameraDeviceType type, CameraDevice device, string name, string id)
+        internal CameraDeviceInformation(CameraDeviceType type, CameraDevice device, string name, string id, int numberOfExtraStream)
         {
             ValidationUtil.ValidateEnum(typeof(CameraDeviceType), type, nameof(type));
             ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device));
@@ -253,6 +243,7 @@ namespace Tizen.Multimedia
             Device = device;
             Name = name ?? throw new ArgumentNullException(nameof(name), "name is null");
             Id = id ?? throw new ArgumentNullException(nameof(id), "id is null");
+            NumberOfExtraStream = numberOfExtraStream;
         }
 
         /// <summary>
@@ -288,12 +279,20 @@ namespace Tizen.Multimedia
         public string Id { get; }
 
         /// <summary>
+        /// Gets the number of extra stream.
+        /// </summary>
+        /// <value>The number of extra stream.</value>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int NumberOfExtraStream { get; }
+
+        /// <summary>
         /// Returns a string that represents the current object.
         /// </summary>
         /// <returns>A string that represents the current object.</returns>
         /// <since_tizen> 9 </since_tizen>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public override string ToString() =>
-            $"Type:{Type.ToString()}, Device:{Device.ToString()}, Name:{Name}, Id:{Id}";
+            $"Type:{Type.ToString()}, Device:{Device.ToString()}, Name:{Name}, Id:{Id}, NumberOfExtraStream:{NumberOfExtraStream}";
     }
 }
index a46ef05..e8eb89e 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 using System;
+using System.ComponentModel;
 using System.Runtime.InteropServices;
 using Native = Interop.CameraSettings;
 using static Interop.Camera;
@@ -1231,5 +1232,99 @@ namespace Tizen.Multimedia
             }
         }
         #endregion EXIF tag
+
+        /// <summary>
+        /// Gets the information of extra preview stream.
+        /// </summary>
+        /// <param name="streamId">The stream id.</param>
+        /// <since_tizen> 9 </since_tizen>
+        /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ExtraPreviewStreamInfo GetExtraPreviewStreamInfo(int streamId)
+        {
+            GetExtraPreviewStreamFormat(_camera.GetHandle(), streamId, out CameraPixelFormat format,
+                out int width, out int height, out int fps).ThrowIfFailed("Failed to get extra preview stream foramt");
+
+            return new ExtraPreviewStreamInfo(streamId, format, new Size(width, height), fps);
+        }
+
+        /// <summary>
+        /// Sets the information of extra preview stream.
+        /// </summary>
+        /// <param name="info">The extra preview stream information.</param>
+        /// <since_tizen> 9 </since_tizen>
+        /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetExtraPreviewStreamInfo(ExtraPreviewStreamInfo info)
+        {
+            SetExtraPreviewStreamFormat(_camera.GetHandle(), info.StreamId, info.Format,
+                info.Size.Width, info.Size.Height, info.Fps).ThrowIfFailed("Failed to set extra preview stream foramt");
+        }
+    }
+
+    /// <summary>
+    /// Provides the ability to get the information of extra preview stream.
+    /// </summary>
+    /// <since_tizen> 9 </since_tizen>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public struct ExtraPreviewStreamInfo
+    {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ExtraPreviewStreamInfo"/> class.
+        /// </summary>
+        /// <param name="streamId">The stream id.</param>
+        /// <param name="format">The preview format.</param>
+        /// <param name="size">The preview resolution.</param>
+        /// <param name="fps">The fps.</param>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ExtraPreviewStreamInfo(int streamId, CameraPixelFormat format, Size size, int fps)
+        {
+            StreamId = streamId;
+            Format = format;
+            Size = size;
+            Fps = fps;
+        }
+
+        /// <summary>
+        /// Gets the stream Id.
+        /// </summary>
+        /// <value>The stream Id.</value>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int StreamId { get; set;}
+
+        /// <summary>
+        /// Gets the extra preview format.
+        /// </summary>
+        /// <value></value>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public CameraPixelFormat Format { get; }
+
+        /// <summary>
+        /// Gets the extra preview resolution.
+        /// </summary>
+        /// <value></value>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Size Size { get; }
+
+        /// <summary>
+        /// Gets the fps.
+        /// </summary>
+        /// <value></value>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int Fps { get; }
+
+        /// <summary>
+        /// Returns a string that represents the current object.
+        /// </summary>
+        /// <returns>A string that represents the current object.</returns>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override string ToString() =>
+            $"StreamId:{StreamId}, Format:{Format.ToString()}, Resolution:{Size.Width}x{Size.Height}, Fps:{Fps}";
     }
 }
index ba79a8e..dc82ab3 100644 (file)
@@ -151,6 +151,15 @@ internal static partial class Interop
         [DllImport(Libraries.Camera, EntryPoint = "camera_get_flash_state")]
         internal static extern CameraError GetFlashState(CameraDevice device, out CameraFlashState state);
 
+        [DllImport(Libraries.Camera, EntryPoint = "camera_set_extra_preview_stream_format")]
+        internal static extern CameraError SetExtraPreviewStreamFormat(IntPtr handle, int streamId, CameraPixelFormat format,
+            int width, int height, int fps);
+
+        [DllImport(Libraries.Camera, EntryPoint = "camera_get_extra_preview_stream_format")]
+        internal static extern CameraError GetExtraPreviewStreamFormat(IntPtr handle, int streamId, out CameraPixelFormat format,
+            out int width, out int height, out int fps);
+
+
         [DllImport(Libraries.Camera, EntryPoint = "camera_set_preview_cb")]
         internal static extern CameraError SetPreviewCallback(IntPtr handle, PreviewCallback callback, IntPtr userData = default);
 
@@ -211,6 +220,7 @@ internal static partial class Interop
         [DllImport(Libraries.Camera, EntryPoint = "camera_attr_unset_hdr_capture_progress_cb")]
         internal static extern CameraError UnsetHdrCaptureProgressCallback(IntPtr handle);
 
+
         [NativeStruct("camera_image_data_s", Include="camera.h", PkgConfig="capi-media-camera")]
         [StructLayout(LayoutKind.Sequential)]
         internal struct StillImageDataStruct
@@ -345,11 +355,13 @@ internal static partial class Interop
 
             internal CameraDevice device;
 
-            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
-            internal char[] name;
+            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
+            internal string name;
+
+            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
+            internal string id;
 
-            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
-            internal char[] id;
+            internal int extraStreamNum;
         }
 
         [NativeStruct("camera_device_list_s", Include="camera_internal.h", PkgConfig="capi-media-camera")]