There is a certain requirement that the display needs to be extensible.
Some api has been modified to make apis consistent.
Change-Id: I766fdeb2d7bba0a891c46862fe64e826da60b26d
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Name: csapi-multimedia
Summary: Tizen Multimedia API for C#
-Version: 1.0.54
+Version: 1.0.55
Release: 0
Group: Development/Libraries
License: Apache-2.0
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
-using System.Collections;
+
namespace Tizen.Multimedia
{
static internal class CameraLog
/// <privilege>
/// http://tizen.org/privilege/camera
/// </privilege>
- public class Camera : IDisposable
+ public class Camera : IDisposable, IDisplayable<CameraError>
{
private IntPtr _handle = IntPtr.Zero;
private bool _disposed = false;
Feature = new CameraFeatures(this);
Setting = new CameraSettings(this);
- Display = new CameraDisplay(this);
+ DisplaySettings = new CameraDisplaySettings(this);
RegisterCallbacks();
/// <summary>
/// Get/set various camera display properties.
/// </summary>
- public CameraDisplay Display { get; }
+ public CameraDisplaySettings DisplaySettings{ get; }
+
+ private Display _display;
+
+ private CameraError SetDisplay(Display display)
+ {
+ if (display == null)
+ {
+ return Interop.CameraDisplay.SetTarget(GetHandle(), DisplayType.None, IntPtr.Zero);
+ }
+
+ return display.ApplyTo(this);
+ }
+
+ private void ReplaceDisplay(Display newDisplay)
+ {
+ if (_display != null)
+ {
+ _display.Owner = null;
+ }
+ _display = newDisplay;
+ if (_display != null)
+ {
+ _display.Owner = this;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets the display type and handle to show preview images.
+ /// The camera must be in the <see cref="CameraState.Created"/> state.
+ /// </summary>
+ /// <remarks>
+ /// This must be set before StartPreview() method.
+ /// In Custom ROI display mode, DisplayRoiArea property must be set before calling this method.
+ /// </remarks>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
+ public Display Display
+ {
+ get
+ {
+ return _display;
+ }
+ set
+ {
+ ValidateState(CameraState.Created);
+
+ if (value != null && value.Owner != null)
+ {
+ if (ReferenceEquals(this, value.Owner))
+ {
+ return;
+ }
+ else
+ {
+ throw new ArgumentException("The display has already been assigned to another.");
+ }
+ }
+ CameraErrorFactory.ThrowIfError(SetDisplay(value), "Failed to set the camera display");
+
+ ReplaceDisplay(value);
+ }
+ }
+
+ CameraError IDisplayable<CameraError>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject)
+ {
+ Debug.Assert(_disposed == false);
+
+ Debug.Assert(Enum.IsDefined(typeof(DisplayType), type));
+
+ return Interop.CameraDisplay.SetTarget(GetHandle(), type, evasObject);
+ }
/// <summary>
/// Gets the state of the camera.
/// <summary>
/// Starts capturing and drawing preview frames on the screen.
- /// The display handle must be set using <see cref="CameraDisplay.SetInfo"/>
+ /// The display handle must be set using <see cref="CameraDisplaySettings.SetInfo"/>
/// before using this method.
/// If needed set fps <see cref="CameraSettings.PreviewFps"/>, preview resolution
/// <see cref="CameraSettings.PreviewResolution"/>, or preview format <see cref="CameraSettings.PreviewPixelFormat"/>
/// It allows to set and get various display properties such as
/// rotation, display visibility and display mode.
/// </summary>
- public class CameraDisplay
+ public class CameraDisplaySettings
{
internal readonly Camera _camera;
- internal CameraDisplay(Camera camera)
+ internal CameraDisplaySettings(Camera camera)
{
_camera = camera;
}
value.X, value.Y, value.Width, value.Height), "Failed to set display roi area.");
}
}
-
- /// <summary>
- /// Sets the display type and handle to show preview images.
- /// The camera must be in the <see cref="CameraState.Created"/> state.
- /// </summary>
- /// <param name="displayType">Display type.</param>
- /// <param name="preview">MediaView object to display preview.</param>
- /// <remarks>
- /// This method must be called before StartPreview() method.
- /// In Custom ROI display mode, DisplayRoiArea property must be set before calling this method.
- /// </remarks>
- /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
- /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
- /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
- public void SetInfo(CameraDisplayType displayType, MediaView displayHandle)
- {
- _camera.ValidateState(CameraState.Created);
-
- ValidationUtil.ValidateEnum(typeof(CameraDisplayType), displayType);
-
- CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.SetInfo(_camera.GetHandle(), displayType, displayHandle),
- "Failed to set the camera display.");
- }
}
}
}
/// <summary>
- /// Enumeration for Camera display type.
- /// </summary>
- public enum CameraDisplayType
- {
- /// <summary>
- /// Overlay surface display.
- /// </summary>
- Overlay,
- /// <summary>
- /// Evas object surface display.
- /// </summary>
- Evas,
- /// <summary>
- /// This disposes off buffers.
- /// </summary>
- None
- }
-
- /// <summary>
/// Enumeration for the facing direction of camera module .
/// </summary>
public enum CameraFacingDirection
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using ElmSharp;
+
+namespace Tizen.Multimedia
+{
+ internal enum DisplayType
+ {
+ /// <summary>
+ /// Overlay surface display
+ /// </summary>
+ Overlay,
+
+ /// <summary>
+ /// Evas image object surface display
+ /// </summary>
+ Surface,
+
+ /// <summary>
+ /// This disposes off buffers
+ /// </summary>
+ None,
+ }
+
+ internal interface IDisplayable<ErrorType>
+ {
+ ErrorType ApplyEvasDisplay(DisplayType type, EvasObject evasObject);
+ }
+
+ /// <summary>
+ /// Provides means to wrap various display types.
+ /// </summary>
+ /// <seealso cref="Player"/>
+ /// <seealso cref="Camera"/>
+ /// <seealso cref="ScreenMirroring"/>
+ public class Display
+ {
+ private Display(DisplayType type, EvasObject target)
+ {
+ if (target == null)
+ {
+ throw new ArgumentNullException(nameof(target));
+ }
+
+ if (target == IntPtr.Zero)
+ {
+ throw new ArgumentException("The evas object is not realized.");
+ }
+
+ Type = type;
+ EvasObject = target;
+ }
+
+ /// <summary>
+ /// Initialize a new instance of the <see cref="Display"/> class with a <see cref="MediaView"/> class.
+ /// </summary>
+ public Display(MediaView mediaView) : this(DisplayType.Surface, mediaView)
+ {
+ }
+
+ /// <summary>
+ /// Initialize a new instance of the <see cref="Display"/> class with a <see cref="Window"/> class.
+ /// </summary>
+ public Display(Window window) : this(DisplayType.Overlay, window)
+ {
+ }
+
+ private EvasObject EvasObject { get; }
+
+ private DisplayType Type { get; }
+
+ internal object Owner
+ {
+ get;
+ set;
+ }
+
+ internal ErrorType ApplyTo<ErrorType>(IDisplayable<ErrorType> target)
+ {
+ return target.ApplyEvasDisplay(Type, EvasObject);
+ }
+ }
+}
internal static extern CameraError SetRoiArea(IntPtr handle, int x, int y, int width, int height);
[DllImport(Libraries.Camera, EntryPoint = "camera_set_display")]
- internal static extern CameraError SetInfo(IntPtr handle, CameraDisplayType displayType, IntPtr displayHandle);
+ internal static extern CameraError SetTarget(IntPtr handle, DisplayType displayType, IntPtr displayHandle);
}
}
-}
\ No newline at end of file
+}
internal static extern PlayerErrorCode SetUri(IntPtr player, string uri);
[DllImport(Libraries.Player, EntryPoint = "player_set_display")]
- internal static extern PlayerErrorCode SetDisplay(IntPtr player, PlayerDisplayType type, IntPtr display);
+ internal static extern PlayerErrorCode SetDisplay(IntPtr player, DisplayType type, IntPtr display);
[DllImport(Libraries.Player, EntryPoint = "player_start")]
internal static extern PlayerErrorCode Start(IntPtr player);
/// It also provides functions to adjust the configurations of the player such as playback rate, volume, looping etc.
/// Note that only one video player can be played at one time.
/// </remarks>
- public class Player : IDisposable
+ public class Player : IDisposable, IDisplayable<PlayerErrorCode>
{
private PlayerHandle _handle;
RetrieveProperties();
AudioEffect = new AudioEffect(this);
+ DisplaySettings = new PlayerDisplaySettings(this);
+
+ RegisterVideoFrameDecodedCallback();
}
private void RetrieveProperties()
RegisterMediaStreamBufferStatusCallback();
RegisterMediaStreamSeekCallback();
RegisterPlaybackCompletedCallback();
- RegisterVideoFrameDecodedCallback();
_callbackRegistered = true;
}
}
#region Display methods
- private PlayerDisplay _display;
+ /// <summary>
+ /// Gets the display settings.
+ /// </summary>
+ /// <value>A <see cref="PlayerDisplaySettings"/> that specifies the display settings.</value>
+ public PlayerDisplaySettings DisplaySettings { get; }
+
+ private Display _display;
- private PlayerErrorCode SetDisplay(PlayerDisplay display)
+ private PlayerErrorCode SetDisplay(Display display)
{
Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
if (display == null)
{
Log.Info(PlayerLog.Tag, "set display to none");
- return Interop.Player.SetDisplay(Handle, PlayerDisplayType.None, IntPtr.Zero);
+ return Interop.Player.SetDisplay(Handle, DisplayType.None, IntPtr.Zero);
}
- Log.Info(PlayerLog.Tag, "set display to " + display.Type + " (" + display.EvasObject + ")");
-
- Debug.Assert(Enum.IsDefined(typeof(PlayerDisplayType), display.Type));
- Debug.Assert(display.EvasObject != null);
- return Interop.Player.SetDisplay(Handle, display.Type, display.EvasObject);
+ return display.ApplyTo(this);
}
- private void ReplaceDisplay(PlayerDisplay newDisplay)
+ private void ReplaceDisplay(Display newDisplay)
{
if (_display != null)
{
- _display.Player = null;
+ _display.Owner = null;
}
_display = newDisplay;
if (_display != null)
{
- _display.Player = this;
- Log.Info(PlayerLog.Tag, "replace display to " + newDisplay.Type + " (" + newDisplay.EvasObject + ")");
+ _display.Owner = this;
}
}
/// <summary>
/// Gets or sets the display.
/// </summary>
- /// <value>A <see cref="PlayerDisplay"/> that specifies the display configurations.</value>
+ /// <value>A <see cref="Multimedia.Display"/> that specifies the display.</value>
/// <remarks>The player must be in the <see cref="PlayerState.Idle"/> state.</remarks>
/// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
/// <exception cref="ArgumentException">The value has already been assigned to another player.</exception>
/// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
- public PlayerDisplay Display
+ public Display Display
{
get
{
Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
ValidatePlayerState(PlayerState.Idle);
- if (value != null && value.Player != null)
+ if (value != null && value.Owner != null)
{
- if (ReferenceEquals(this, value.Player))
+ if (ReferenceEquals(this, value.Owner))
{
return;
}
else
{
- throw new ArgumentException("The display has already been assigned to another player.");
+ throw new ArgumentException("The display has already been assigned to another.");
}
}
Log.Debug(PlayerLog.Tag, PlayerLog.Leave);
}
}
+
+ PlayerErrorCode IDisplayable<PlayerErrorCode>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject)
+ {
+ Debug.Assert(IsDisposed == false);
+
+ Debug.Assert(Enum.IsDefined(typeof(DisplayType), type));
+
+ return Interop.Player.SetDisplay(Handle, type, evasObject);
+ }
#endregion
private PlayerTrackInfo _audioTrack;
{
Interlocked.Exchange(ref _isPreparing, 0);
}
+
#endregion
}
}
* limitations under the License.
*/
using System;
-using ElmSharp;
+using System.Diagnostics;
namespace Tizen.Multimedia
{
- //TODO reimplementation needed
/// <summary>
/// Provides means to configure display settings for video <see cref="Player"/>.
/// </summary>
- public class PlayerDisplay
+ public class PlayerDisplaySettings
{
- private PlayerDisplay(PlayerDisplayType type, EvasObject target)
+ internal PlayerDisplaySettings(Player player)
{
- if (target == null)
- {
- Log.Error(PlayerLog.Tag, "evas object is null");
- throw new ArgumentNullException(nameof(target));
- }
+ Debug.Assert(player != null);
- if (target == IntPtr.Zero)
- {
- Log.Error(PlayerLog.Tag, "The evas object is not realized.");
- throw new ArgumentException("The evas object is not realized.");
- }
-
- Type = type;
- EvasObject = target;
+ Player = player;
}
- public PlayerDisplay(Window window) : this(PlayerDisplayType.Overlay, window)
- {
- }
-
- public PlayerDisplay(Image image) : this(PlayerDisplayType.Surface, image)
- {
- }
-
- public EvasObject EvasObject { get; }
-
- internal PlayerDisplayType Type { get; }
-
- /// <summary>
- /// Gets the player that the display is assigned to.
- /// </summary>
- public Player Player
+ private Player Player
{
get;
- internal set;
- }
-
- private void ValidatePlayer()
- {
- if (Player == null)
- {
- Log.Error(PlayerLog.Tag, "The display is not assigned, yet.");
- throw new InvalidOperationException("The display is not assigned, yet.");
- }
-
- Player.ValidateNotDisposed();
}
private PlayerDisplayMode _displayMode = PlayerDisplayMode.LetterBox;
}
set
{
- ValidatePlayer();
-
if (_displayMode == value)
{
return;
}
set
{
- ValidatePlayer();
-
if (_isVisible == value)
{
return;
}
set
{
- ValidatePlayer();
-
if (_rotation == value)
{
return;
/// <exception cref="ArgumentOutOfRangeException">width or height is less than or equal to zero.</exception>
public void SetRoi(Rectangle roi)
{
- ValidatePlayer();
-
if (_displayMode != PlayerDisplayMode.Roi)
{
throw new InvalidOperationException("Mode is not set to Roi");
}
}
- internal enum PlayerDisplayType
- {
- /// <summary>
- /// Overlay surface display
- /// </summary>
- Overlay,
-
- /// <summary>
- /// Evas image object surface display
- /// </summary>
- Surface,
-
- /// <summary>
- /// This disposes off buffers
- /// </summary>
- None,
- }
-
/// <summary>
/// Specifies audio latency modes for <see cref="Player"/> .
/// </summary>
/// <summary>
/// Specifies display rotation modes for <see cref="Player"/>.
/// </summary>
- /// <seealso cref="PlayerDisplay.Rotation"/>
+ /// <seealso cref="Display.Rotation"/>
public enum PlayerDisplayRotation
{
/// <summary>
/// <summary>
/// Specifies display modes for <see cref="Player"/>
/// </summary>
- /// <seealso cref="PlayerDisplay.Mode"/>
+ /// <seealso cref="Display.Mode"/>
public enum PlayerDisplayMode
{
/// <summary>
OriginalOrFull,
/// <summary>
- /// Region of interest, See <see cref="PlayerDisplay.SetRoi(Rectangle)"/>.
+ /// Region of interest, See <see cref="Display.SetRoi(Rectangle)"/>.
/// </summary>
Roi
}
* limitations under the License.
*/
using System;
+using System.Diagnostics;
using System.Threading.Tasks;
namespace Tizen.Multimedia
/// start, pause, and resume the screen mirroring sink, set the resolution or display,
/// register state change callback function.
/// </summary>
- public class ScreenMirroring : IDisposable
+ public class ScreenMirroring : IDisposable, IDisplayable<int>
{
internal VideoInformation _videoInfo;
internal AudioInformation _audioInfo;
internal IntPtr _handle;
internal string _ip;
internal string _port;
- internal SurfaceType _type;
- internal MediaView _display;
private bool _disposed = false;
private EventHandler<StateChangedEventArgs> _stateChanged;
/// <param name="ip">Ip.</param>
/// <param name="port">Port.</param>
/// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
- public ScreenMirroring(SurfaceType type, MediaView display, string ip, string port)
+ public ScreenMirroring(Display display, string ip, string port)
{
int ret = Interop.ScreenMirroring.Create(out _handle);
if (ret != (int)ScreenMirroringError.None)
// initiate values
_ip = ip;
_port = port;
- _type = type;
- _display = display;
// Set ip and port
int ret1 = Interop.ScreenMirroring.SetIpAndPort(_handle, _ip, _port);
ScreenMirroringErrorFactory.ThrowException(ret, "set ip and port failed");
}
- // Set display
- int ret2 = Interop.ScreenMirroring.SetDisplay(_handle, (int)_type, _display);
- if (ret2 != (int)ScreenMirroringError.None)
- {
- Log.Error(ScreenMirroringLog.LogTag, "Set display failed" + (ScreenMirroringError)ret2);
- ScreenMirroringErrorFactory.ThrowException(ret, "set display failed");
- }
+ Display = display;
// AudioInfo
_audioInfo = new AudioInformation();
}
}
+ private Display _display;
+
+ private int ApplyDisplay(Display display)
+ {
+ return display.ApplyTo(this);
+ }
+
+ private void ReplaceDisplay(Display newDisplay)
+ {
+ if (_display != null)
+ {
+ _display.Owner = null;
+ }
+ _display = newDisplay;
+ if (_display != null)
+ {
+ _display.Owner = this;
+ }
+ }
+
/// <summary>
/// Sets the display.
/// This must be called before prepare() and after create().
/// </summary>
/// <example> If only one handle is used for toggling between more than two source devices,
- /// then this API ahould be used to assign the parameters to the handle.
+ /// then this API should be used to assign the parameters to the handle.
/// </example>
- /// <param name="type">Type.</param>
- /// <param name="display">Display.</param>
- /// <remarks> Display Handle creates using mediaview class </remarks>
/// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
- public void SetDisplay(SurfaceType type, MediaView display)
+ public Display Display
{
- int ret = Interop.ScreenMirroring.SetDisplay(_handle, (int)type, display);
- if (ret != (int)ScreenMirroringError.None)
+ get
{
- Log.Error(ScreenMirroringLog.LogTag, "Set display failed" + (ScreenMirroringError)ret);
- ScreenMirroringErrorFactory.ThrowException(ret, "set display failed");
+ return _display;
}
+ set
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(nameof(Display));
+ }
+
+ int ret = ApplyDisplay(value);
+ if (ret != (int)ScreenMirroringError.None)
+ {
+ Log.Error(ScreenMirroringLog.LogTag, "Set display failed" + (ScreenMirroringError)ret);
+ ScreenMirroringErrorFactory.ThrowException(ret, "set display failed");
+ }
+ }
+ }
+
+ int IDisplayable<int>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject)
+ {
+ Debug.Assert(_disposed == false);
+
+ Debug.Assert(Enum.IsDefined(typeof(DisplayType), type));
+
+ return Interop.ScreenMirroring.SetDisplay(_handle, (int)type, evasObject);
}
/// <summary>
/// </summary>
H264
}
- /// <summary>
- /// Enumeration for display surface type.
- /// </summary>
- public enum SurfaceType
- {
- /// <summary>
- /// Use overlay surface to display streaming multimedia data
- /// </summary>
- Overlay,
- /// <summary>
- /// Use Evas pixmap surface to display streaming multimedia data
- /// </summary>
- Evas
- }
/// <summary>
/// Enumeration for screen mirroring resolution.
/// </summary>
InvalidOperation = ScreenMirroringError.InvalidOperation
}
-}
\ No newline at end of file
+}
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Compile Include="Camera\Camera.cs" />
<Compile Include="Camera\CameraCapturingEventArgs.cs" />
<Compile Include="Camera\CameraDeviceStateChangedEventArgs.cs" />
- <Compile Include="Camera\CameraDisplay.cs" />
+ <Compile Include="Camera\CameraDisplaySettings.cs" />
<Compile Include="Camera\CameraEnums.cs" />
<Compile Include="Camera\CameraErrorFactory.cs" />
<Compile Include="Camera\CameraErrorOccurredEventArgs.cs" />
<Compile Include="Camera\PreviewEventArgs.cs" />
<Compile Include="Camera\SinglePlane.cs" />
<Compile Include="Camera\TriplePlane.cs" />
+ <Compile Include="Common\Display.cs" />
<Compile Include="Common\IBufferOwner.cs" />
<Compile Include="Common\IMediaBuffer.cs" />
<Compile Include="Common\MultimediaDebug.cs" />
<Compile Include="Player\MediaUriSource.cs" />
<Compile Include="Player\PlaybackInterruptedEventArgs.cs" />
<Compile Include="Player\Player.cs" />
- <Compile Include="Player\PlayerDisplay.cs" />
+ <Compile Include="Player\PlayerDisplaySettings.cs" />
<Compile Include="Player\PlayerEnums.cs" />
<Compile Include="Player\PlayerError.cs" />
<Compile Include="Player\PlayerErrorOccurredEventArgs.cs" />