From 085198668a1992e077e9ef682e8720e55ec3a20b Mon Sep 17 00:00:00 2001 From: hsgwon Date: Wed, 3 Apr 2019 15:38:19 +0900 Subject: [PATCH] [MediaController] Add new API for Season, Episode, Resolution (#769) * [MediaController] Add new API for Season, Episode, Resolution - Changed return type of Season, Episode property - Changed internal API signature - Changed instance method to static method and struct to class --- .../Interop/Interop.MediaControllerPlaylist.cs | 21 +++ .../MediaController/InternalEnums.cs | 3 + .../MediaController/MediaControlMetadata.cs | 154 +++++++++++++++++++++ .../MediaController/MediaControlPlaylist.cs | 3 + .../MediaController/MediaControlServer.cs | 8 +- 5 files changed, 188 insertions(+), 1 deletion(-) diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs index c20eb6f..0214594 100644 --- a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs @@ -80,6 +80,24 @@ internal static partial class Interop internal static extern MediaControllerError GetServerMetadata(MediaControllerClientHandle handle, string serverName, out IntPtr metadata); + [DllImport(Libraries.MediaController, EntryPoint = "mc_metadata_encode_season")] + internal static extern MediaControllerError EncodeSeason(int number, string title, out string encoded); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_metadata_encode_episode")] + internal static extern MediaControllerError EncodeEpisode(int number, string title, out string encoded); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_metadata_encode_resolution")] + internal static extern MediaControllerError EncodeResolution(uint width, uint height, out string encoded); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_metadata_decode_season")] + internal static extern MediaControllerError DecodeSeason(string season, out int number, out string title); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_metadata_decode_episode")] + internal static extern MediaControllerError DecodeEpisode(string episode, out int number, out string title); + + + [DllImport(Libraries.MediaController, EntryPoint = "mc_metadata_decode_resolution")] + internal static extern MediaControllerError DecodeResolution(string episode, out uint width, out uint height); [DllImport(Libraries.MediaController, EntryPoint = "mc_playlist_create")] internal static extern MediaControllerError CreatePlaylist(string name, out IntPtr handle); @@ -87,6 +105,9 @@ internal static partial class Interop [DllImport(Libraries.MediaController, EntryPoint = "mc_playlist_destroy")] internal static extern MediaControllerError DestroyPlaylist(IntPtr handle); + [DllImport(Libraries.MediaController, EntryPoint = "mc_playlist_get_playlist")] + internal static extern MediaControllerError GetPlaylistHandle(string name, string playlistName, out IntPtr playlistHandle); + [DllImport(Libraries.MediaController, EntryPoint = "mc_playlist_clone")] internal static extern MediaControllerError ClonePlaylist(IntPtr source, IntPtr destination); diff --git a/src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs b/src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs index 70dbdab..f3820f3 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs @@ -77,5 +77,8 @@ namespace Tizen.Multimedia.Remoting Description, TrackNumber, Picture, + Season, + Episode, + Resolution } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlMetadata.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlMetadata.cs index ebee980..2ab0f8c 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlMetadata.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlMetadata.cs @@ -49,6 +49,15 @@ namespace Tizen.Multimedia.Remoting Description = Native.GetMetadata(handle, MediaControllerNativeAttribute.Description); TrackNumber = Native.GetMetadata(handle, MediaControllerNativeAttribute.TrackNumber); AlbumArtPath = Native.GetMetadata(handle, MediaControllerNativeAttribute.Picture); + + EncodedSeason = Native.GetMetadata(handle, MediaControllerNativeAttribute.Season); + Season = DecodeSeason(EncodedSeason); + + EncodedEpisode = Native.GetMetadata(handle, MediaControllerNativeAttribute.Episode); + Episode = DecodeEpisode(EncodedEpisode); + + EncodedResolution = Native.GetMetadata(handle, MediaControllerNativeAttribute.Resolution); + Resolution = DecodeResolution(EncodedResolution); } /// @@ -116,5 +125,150 @@ namespace Tizen.Multimedia.Remoting /// /// 4 public string AlbumArtPath { get; set; } + + /// + /// Gets or sets the season information. + /// + /// + /// 6 + public SeriesInformation Season + { + get => DecodeSeason(EncodedSeason); + set => EncodedSeason = EncodeSeason(value); + } + + /// + /// Gets or sets the episode information. + /// + /// + /// 6 + public SeriesInformation Episode + { + get => DecodeEpisode(EncodedEpisode); + set => EncodedEpisode = EncodeEpisode(value); + } + + /// + /// Gets or sets the content resolution. + /// + /// + /// 6 + public Size Resolution + { + get => DecodeResolution(EncodedResolution); + set => EncodedResolution = EncodeResolution(value.Width, value.Height); + } + + // Native CAPI used only encoded string to gets or sets Season, Episode, Resolution. + // But encoded string is not useful for user, so we don't offer as it is. + // It'll be used internally. + internal string EncodedSeason { get; private set; } + + internal string EncodedEpisode { get; private set; } + + internal string EncodedResolution { get; private set; } + + private static string EncodeSeason(SeriesInformation information) + { + Native.EncodeSeason(information.Number, information.Title, out string encodedSeason). + ThrowIfError("Failed to encode season"); + + return encodedSeason; + } + + private static string EncodeEpisode(SeriesInformation information) + { + Native.EncodeEpisode(information.Number, information.Title, out string encodedEpisode). + ThrowIfError("Failed to encode episode"); + + return encodedEpisode; + } + + private static string EncodeResolution(int width, int height) + { + Native.EncodeResolution((uint)width, (uint)height, out string encodedResolution). + ThrowIfError("Failed to encode resolution"); + + return encodedResolution; + } + + private static SeriesInformation DecodeSeason(string encodedSeason) + { + int number = 0; + string title = null; + + if (encodedSeason != null) + { + Native.DecodeSeason(encodedSeason, out number, out title). + ThrowIfError("Failed to decode season"); + } + + return new SeriesInformation(number, title); + } + + private static SeriesInformation DecodeEpisode(string encodedEpisode) + { + int number = 0; + string title = null; + + if (encodedEpisode != null) + { + Native.DecodeEpisode(encodedEpisode, out number, out title). + ThrowIfError("Failed to decode episode"); + } + + return new SeriesInformation(number, title); + } + + private static Size DecodeResolution(string encodedResolution) + { + uint width = 0, height = 0; + + if (encodedResolution != null) + { + Native.DecodeResolution(encodedResolution, out width, out height). + ThrowIfError("Failed to decode resolution"); + } + + return new Size((int)width, (int)height); + } + } + + /// + /// Represents properties for the video series information. + /// + /// 6 + public class SeriesInformation + { + /// + /// Initializes a new instance of the class. + /// + /// The number of this video of all series. + /// The title. + /// 6 + public SeriesInformation(int number, string title) + { + Number = number; + Title = title; + } + + /// + /// Gets or sets the number of this video of all series. + /// + /// 6 + public int Number { get; } + + /// + /// Gets or sets the title. + /// + /// 6 + public string Title { get; } + + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. + /// 6 + public override string ToString() => $"Number={Number.ToString()}, Title={Title}"; } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs index d5cecdc..2583fd4 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs @@ -241,6 +241,9 @@ namespace Tizen.Multimedia.Remoting AddMetadataToNative(index, MediaControllerNativeAttribute.Picture, metadata.AlbumArtPath); AddMetadataToNative(index, MediaControllerNativeAttribute.Title, metadata.Title); AddMetadataToNative(index, MediaControllerNativeAttribute.TrackNumber, metadata.TrackNumber); + AddMetadataToNative(index, MediaControllerNativeAttribute.Season, metadata.EncodedSeason); + AddMetadataToNative(index, MediaControllerNativeAttribute.Episode, metadata.EncodedEpisode); + AddMetadataToNative(index, MediaControllerNativeAttribute.Resolution, metadata.EncodedResolution); } /// diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs index 1d10bf3..d786528 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs @@ -195,7 +195,10 @@ namespace Tizen.Multimedia.Remoting private static void SetMetadata(MediaControllerNativeAttribute attribute, string value) { - Native.SetMetadata(Handle, attribute, value).ThrowIfError($"Failed to set metadata({attribute})."); + if (value != null) + { + Native.SetMetadata(Handle, attribute, value).ThrowIfError($"Failed to set metadata({attribute})."); + } } /// @@ -227,6 +230,9 @@ namespace Tizen.Multimedia.Remoting SetMetadata(MediaControllerNativeAttribute.Description, metadata.Description); SetMetadata(MediaControllerNativeAttribute.TrackNumber, metadata.TrackNumber); SetMetadata(MediaControllerNativeAttribute.Picture, metadata.AlbumArtPath); + SetMetadata(MediaControllerNativeAttribute.Season, metadata.EncodedSeason); + SetMetadata(MediaControllerNativeAttribute.Episode, metadata.EncodedEpisode); + SetMetadata(MediaControllerNativeAttribute.Resolution, metadata.EncodedResolution); Native.UpdateMetadata(Handle).ThrowIfError("Failed to set metadata."); } -- 2.7.4