From adfa46dd772afd5514fe96955d7dc62b469e2393 Mon Sep 17 00:00:00 2001 From: coderhyme Date: Fri, 3 Feb 2017 16:36:03 +0900 Subject: [PATCH] [MetadataExtractor] Refactoring Change-Id: Ief6bb5921c0da8d02bcdcbc89f53c85e04b7f6e6 Signed-off-by: coderhyme --- .../Common/ObjectDescriptionBuilder.cs | 59 ++ .../Interop/Interop.MetadataExtractor.cs | 80 ++- src/Tizen.Multimedia/MetadataExtractor/Artwork.cs | 40 +- src/Tizen.Multimedia/MetadataExtractor/Frame.cs | 43 -- src/Tizen.Multimedia/MetadataExtractor/Metadata.cs | 437 +++++++----- .../MetadataExtractor/MetadataEnums.cs | 60 -- .../MetadataExtractor/MetadataExtractor.cs | 737 ++++++++------------- .../MetadataExtractor/MetadataExtractorAttr.cs | 57 ++ .../MetadataExtractor/MetadataExtractorError.cs | 62 ++ .../MetadataExtractorErrorFactory.cs | 55 -- .../MetadataExtractor/Synclyrics.cs | 38 +- src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj | 215 +----- src/Tizen.Multimedia/Tizen.Multimedia.csproj | 357 ++-------- 13 files changed, 891 insertions(+), 1349 deletions(-) create mode 100644 src/Tizen.Multimedia/Common/ObjectDescriptionBuilder.cs delete mode 100755 src/Tizen.Multimedia/MetadataExtractor/Frame.cs delete mode 100755 src/Tizen.Multimedia/MetadataExtractor/MetadataEnums.cs create mode 100644 src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorAttr.cs create mode 100644 src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorError.cs delete mode 100755 src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorErrorFactory.cs diff --git a/src/Tizen.Multimedia/Common/ObjectDescriptionBuilder.cs b/src/Tizen.Multimedia/Common/ObjectDescriptionBuilder.cs new file mode 100644 index 0000000..96f1f68 --- /dev/null +++ b/src/Tizen.Multimedia/Common/ObjectDescriptionBuilder.cs @@ -0,0 +1,59 @@ +/* + * 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 System.Reflection; +using System.Text; + +namespace Tizen.Multimedia +{ + /// + /// Represents a point in 2D space. + /// + internal static class ObjectDescriptionBuilder + { + internal static string BuildWithProperties(object obj) + { + StringBuilder sb = new StringBuilder(); + + foreach (var property in obj.GetType().GetRuntimeProperties()) + { + object value = property.GetValue(obj); + + sb.Append(property.Name).Append("="); + + bool isObjectType = Convert.GetTypeCode(value) == TypeCode.Object; + + if (isObjectType) + { + sb.Append("[").Append(value).Append("]"); + } + else + { + sb.Append(value); + } + + sb.Append(", "); + } + if (sb.Length >= 2) + { + sb.Remove(sb.Length - 1, 2); + } + + return sb.ToString(); + } + } +} diff --git a/src/Tizen.Multimedia/Interop/Interop.MetadataExtractor.cs b/src/Tizen.Multimedia/Interop/Interop.MetadataExtractor.cs index 5599ad5..54a393f 100755 --- a/src/Tizen.Multimedia/Interop/Interop.MetadataExtractor.cs +++ b/src/Tizen.Multimedia/Interop/Interop.MetadataExtractor.cs @@ -1,35 +1,55 @@ -using System; +using System; using System.Runtime.InteropServices; +using Tizen.Multimedia; internal static partial class Interop { - internal static partial class MetadataExtractor - { - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_create")] - internal static extern int Create(out IntPtr handle); - - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_set_path")] - internal static extern int SetPath(IntPtr handle, string path); - - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_set_buffer")] - internal static extern int SetBuffer(IntPtr handle, IntPtr buffer, int size); - - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_destroy")] - internal static extern int Destroy(IntPtr handle); - - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_metadata")] - internal static extern int GetMetadata(IntPtr handle, int attribute, out string value); - - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_artwork")] - internal static extern int GetArtwork(IntPtr handle, out IntPtr artwork, out int size, out string mimeType); - - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_frame")] - internal static extern int GetFrame(IntPtr handle, out IntPtr frame, out int size); - - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_synclyrics")] - internal static extern int GetSynclyrics(IntPtr handle, int index, out uint timeStamp, out string lyrics); - - [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_frame_at_time")] - internal static extern int GetFrameAtTime(IntPtr handle, uint timeStamp, bool isAccurate, out IntPtr frame, out int size); - } + internal static partial class MetadataExtractor + { + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_create")] + internal static extern MetadataExtractorError Create(out IntPtr handle); + + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_set_path")] + internal static extern MetadataExtractorError SetPath(IntPtr handle, string path); + + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_set_buffer")] + internal static extern MetadataExtractorError SetBuffer(IntPtr handle, IntPtr buffer, int size); + + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_destroy")] + internal static extern MetadataExtractorError Destroy(IntPtr handle); + + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_metadata")] + private static extern MetadataExtractorError GetMetadata(IntPtr handle, MetadataExtractorAttr attribute, out IntPtr value); + + internal static string GetMetadata(IntPtr handle, MetadataExtractorAttr attr) + { + IntPtr valuePtr = IntPtr.Zero; + + try + { + var ret = GetMetadata(handle, attr, out valuePtr); + MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get value for " + attr); + return Marshal.PtrToStringAnsi(valuePtr); + } + finally + { + Libc.Free(valuePtr); + } + } + + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_artwork")] + internal static extern MetadataExtractorError GetArtwork(IntPtr handle, out IntPtr artwork, + out int size, out IntPtr mimeType); + + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_frame")] + internal static extern MetadataExtractorError GetFrame(IntPtr handle, out IntPtr frame, out int size); + + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_synclyrics")] + internal static extern MetadataExtractorError GetSynclyrics(IntPtr handle, int index, + out uint timeStamp, out IntPtr lyrics); + + [DllImport(Libraries.MetadataExtractor, EntryPoint = "metadata_extractor_get_frame_at_time")] + internal static extern MetadataExtractorError GetFrameAtTime(IntPtr handle, uint timeStamp, + bool isAccurate, out IntPtr frame, out int size); + } } diff --git a/src/Tizen.Multimedia/MetadataExtractor/Artwork.cs b/src/Tizen.Multimedia/MetadataExtractor/Artwork.cs index edaed93..da76853 100755 --- a/src/Tizen.Multimedia/MetadataExtractor/Artwork.cs +++ b/src/Tizen.Multimedia/MetadataExtractor/Artwork.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -14,32 +14,30 @@ * limitations under the License. */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Tizen.Multimedia -{ +{ /// - /// This class provides properties of the artwork information of the given media + /// Represents artwork information of media. /// public class Artwork - { - internal Artwork(byte[] artworkData, string mimeType) - { - ArtworkData = artworkData; - MimeType = mimeType; - } + { /// - /// The encoded artwork image + /// Initialize a new instance of the Artwork class with the specified data and mimeType. /// - public readonly byte[] ArtworkData; - + public Artwork(byte[] data, string mimeType) + { + Data = data; + MimeType = mimeType; + } + + /// + /// The encoded artwork image. + /// + public byte[] Data { get; } + /// - /// The mime type of artwork + /// The mime type of artwork. /// - public readonly string MimeType; - } + public string MimeType { get; } + } } diff --git a/src/Tizen.Multimedia/MetadataExtractor/Frame.cs b/src/Tizen.Multimedia/MetadataExtractor/Frame.cs deleted file mode 100755 index e3a5b16..0000000 --- a/src/Tizen.Multimedia/MetadataExtractor/Frame.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* -* 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 System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tizen.Multimedia -{ - /// - /// This class provides properties of the frame data of the given video file - /// - public class Frame - { - internal Frame(byte[] frameData) - { - FrameData = frameData; - } - /// - /// The raw frame data - /// - /// - /// Provided raw data is RGB888 format. - /// - public readonly byte[] FrameData; - } -} diff --git a/src/Tizen.Multimedia/MetadataExtractor/Metadata.cs b/src/Tizen.Multimedia/MetadataExtractor/Metadata.cs index bf7a3d1..977e84c 100755 --- a/src/Tizen.Multimedia/MetadataExtractor/Metadata.cs +++ b/src/Tizen.Multimedia/MetadataExtractor/Metadata.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -14,236 +14,353 @@ * limitations under the License. */ - using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics; +using static Interop.MetadataExtractor; namespace Tizen.Multimedia -{ +{ /// - /// This class provides properties of the metadata information of the given media + /// Represents video metadata information. /// - public class Metadata - { - internal Metadata(MetadataBundle metadata) - { - Duration = metadata.Duration; - VideoBitrate = metadata.VideoBitrate; - VideoFPS = metadata.VideoFPS; - VideoWidth = metadata.VideoWidth; - VideoHeight = metadata.VideoHeight; - VideoStreamCount = metadata.Videostreamcount; - AudioBitrate = metadata.AudioBitrate; - AudioChannels = metadata.AudioChannels; - AudioSamplerate = metadata.AudioSamplerate; - AudioBitPerSample = metadata.Audiobitpersample; - AudioStreamCount = metadata.Audiostreamcount; - Artist = metadata.Artist; - Title = metadata.Title; - Album = metadata.Album; - AlbumArtist = metadata.AlbumArtist; - Genre = metadata.Genre; - Author = metadata.Author; - Copyright = metadata.Copyright; - Date = metadata.Date; - Description = metadata.Description; - Comment = metadata.Comment; - TrackNumber = metadata.Tracknumber; - Classification = metadata.Classification; - Rating = metadata.Rating; - Longitude = metadata.Longitude; - Latitude = metadata.Latitude; - Altitude = metadata.Altitude; - Conductor = metadata.Conductor; - Unsynclyric = metadata.Unsynclyric; - SyncLyricNumber = metadata.SyncLyricNumber; - RecordingDate = metadata.Recordingdate; - Rotate = metadata.Rotate; - VideoCodec = metadata.VideoCodec; - AudioCodec = metadata.AudioCodec; - Content360 = metadata.content360; - } + public class VideoMetadata + { + + protected VideoMetadata() + { + } + + internal VideoMetadata(IntPtr handle) + { + Debug.Assert(handle != IntPtr.Zero); + + StreamCount = GetMetadata(handle, MetadataExtractorAttr.VideoStreamCount); + + if (StreamCount == null || (StreamCount != null && StreamCount.Equals("0") == false)) + { + Bitrate = GetMetadata(handle, MetadataExtractorAttr.VideoBitrate); + Fps = GetMetadata(handle, MetadataExtractorAttr.VideoFps); + Width = GetMetadata(handle, MetadataExtractorAttr.VideoWidth); + Height = GetMetadata(handle, MetadataExtractorAttr.VideoHeight); + Codec = GetMetadata(handle, MetadataExtractorAttr.VideoCodec); + } + + _description = new Lazy(() => ObjectDescriptionBuilder.BuildWithProperties(this)); + } + /// - /// Duration + /// Gets the bitrate. /// - public readonly string Duration; + /// A string representing the bitrate, or null if the information does not exists. + public string Bitrate { get; } + /// - /// Video bitrate + /// Gets the video FPS. /// - public readonly string VideoBitrate; + /// A string representing the fps, or null if the information does not exists. + public string Fps { get; } + + /// + /// Gets the width of the video. + /// + /// A string representing the width, or null if the information does not exists. + public string Width { get; } + + /// + /// Gets the height of the video. + /// + /// A string representing the height, or null if the information does not exists. + public string Height { get; } + + /// + /// Get the codec type of the video. + /// + /// A string representing the codec type, or null if the information does not exists. + public string Codec { get; } + /// - /// Video FPS + /// Gets the video stream count. /// - public readonly string VideoFPS; + /// A string representing the video stream count, or null if the information does not exists. + public string StreamCount { get; } + + private Lazy _description; + + public override string ToString() + { + return _description.Value; + } + + } + + /// + /// Represents audio metadata information. + /// + public class AudioMetadata + { + + protected AudioMetadata() + { + } + + internal AudioMetadata(IntPtr handle) + { + Debug.Assert(handle != IntPtr.Zero); + + StreamCount = GetMetadata(handle, MetadataExtractorAttr.AudioStreamCount); + + if (StreamCount == null || (StreamCount != null && !StreamCount.Equals("0"))) + { + Bitrate = GetMetadata(handle, MetadataExtractorAttr.AudioBitrate); + Channels = GetMetadata(handle, MetadataExtractorAttr.AudioChannels); + Samplerate = GetMetadata(handle, MetadataExtractorAttr.AudioSamplerate); + BitPerSample = GetMetadata(handle, MetadataExtractorAttr.AudioBitPerSample); + Codec = GetMetadata(handle, MetadataExtractorAttr.AudioCodec); + } + + _description = new Lazy(() => ObjectDescriptionBuilder.BuildWithProperties(this)); + } + /// - /// Video width + /// Gets the audio bitrate. /// - public readonly string VideoWidth; + /// A string representing the bitrate, or null if the information does not exists. + public string Bitrate { get; } + /// - /// Video height + /// Gets the audio channels. /// - public readonly string VideoHeight; + /// A string representing the audio channels, or null if the information does not exists. + public string Channels { get; } + /// - /// Video stream existence + /// Gets the audio sample rate. /// - public readonly string VideoStreamCount; + /// A string representing the sample rate, or null if the information does not exists. + public string Samplerate { get; } + /// - /// Audio bitrate + /// Gets the bit per sample of the audio. /// - public readonly string AudioBitrate; + /// A string representing the bit oer sample, or null if the information does not exists. + public string BitPerSample { get; } + /// - /// Audio channels + /// Gets the audio stream count. /// - public readonly string AudioChannels; + /// A string representing the audio stream count, or null if the information does not exists. + public string StreamCount { get; } + /// - /// Audio samplerate + /// Audio codec type /// - public readonly string AudioSamplerate; + public string Codec { get; } + + private Lazy _description; + + public override string ToString() + { + return _description.Value; + } + } + + /// + /// Represents metadata information of a media. + /// + public class Metadata + { + + protected Metadata() + { + } + + internal Metadata(IntPtr handle) + { + Debug.Assert(handle != IntPtr.Zero); + + Video = new VideoMetadata(handle); + Audio = new AudioMetadata(handle); + + Duration = GetMetadata(handle, MetadataExtractorAttr.Duration); + Artist = GetMetadata(handle, MetadataExtractorAttr.Artist); + Title = GetMetadata(handle, MetadataExtractorAttr.Title); + Album = GetMetadata(handle, MetadataExtractorAttr.Album); + AlbumArtist = GetMetadata(handle, MetadataExtractorAttr.AlbumArtist); + Genre = GetMetadata(handle, MetadataExtractorAttr.Genre); + Author = GetMetadata(handle, MetadataExtractorAttr.Author); + Copyright = GetMetadata(handle, MetadataExtractorAttr.Copyright); + ReleaseDate = GetMetadata(handle, MetadataExtractorAttr.ReleaseDate); + Description = GetMetadata(handle, MetadataExtractorAttr.Description); + Comment = GetMetadata(handle, MetadataExtractorAttr.Comment); + TrackNumber = GetMetadata(handle, MetadataExtractorAttr.TrackNum); + Classification = GetMetadata(handle, MetadataExtractorAttr.Classification); + Rating = GetMetadata(handle, MetadataExtractorAttr.Rating); + Longitude = GetMetadata(handle, MetadataExtractorAttr.Longitude); + Latitude = GetMetadata(handle, MetadataExtractorAttr.Latitude); + Altitude = GetMetadata(handle, MetadataExtractorAttr.Altitude); + Conductor = GetMetadata(handle, MetadataExtractorAttr.Conductor); + UnsyncLyric = GetMetadata(handle, MetadataExtractorAttr.UnSyncLyrics); + SyncLyricCount = GetMetadata(handle, MetadataExtractorAttr.SyncLyricsNum); + RecordingDate = GetMetadata(handle, MetadataExtractorAttr.RecordingDate); + Rotation = GetMetadata(handle, MetadataExtractorAttr.Rotate); + Content360 = GetMetadata(handle, MetadataExtractorAttr.ContentFor360); + + _description = new Lazy(() => ObjectDescriptionBuilder.BuildWithProperties(this)); + } + /// - /// Audio bit per sample + /// Gets the duration of the media. /// - public readonly string AudioBitPerSample; + /// A string representing the duration, or null if the information does not exists. + public string Duration { get; } + /// - /// Audio stream existence + /// Gets the video metadata. /// - public readonly string AudioStreamCount; + public VideoMetadata Video { get; } + /// - /// Artist + /// Gets the audio metadata. /// - public readonly string Artist; + public AudioMetadata Audio { get; } + /// - /// Title + /// Gets the artist of the media. /// - public readonly string Title; + /// A string representing the artist, or null if the information does not exists. + public string Artist { get; } + /// - /// Album name + /// Gets the title of the media. /// - public readonly string Album; + /// A string representing the title, or null if the information does not exists. + public string Title { get; } + /// - /// Album artist + /// Gets the album name of the media. /// - public readonly string AlbumArtist; + /// A string representing the album name, or null if the information does not exists. + public string Album { get; } + /// - /// Genre + /// Gets the album artist of the media. /// - public readonly string Genre; + /// A string representing the album artist, or null if the information does not exists. + public string AlbumArtist { get; } + /// - /// Author + /// Gets the genre of the media. /// - public readonly string Author; + /// A string representing the genre, or null if the information does not exists. + public string Genre { get; } + /// - /// Copyright + /// Gets the author of the media. /// - public readonly string Copyright; + /// A string representing the author, or null if the information does not exists. + public string Author { get; } + /// - /// Release date + /// Gets the copyright of the media. /// - public readonly string Date; + /// A string representing the copyright, or null if the information does not exists. + public string Copyright { get; } + /// - /// Description + /// Gets the release date of the media. /// - public readonly string Description; + /// A string representing the release date, or null if the information does not exists. + public string ReleaseDate { get; } + /// - /// Comment + /// Gets the description of the media. /// - public readonly string Comment; + /// A string representing the description, or null if the information does not exists. + public string Description { get; } + /// - /// Track number information + /// Gets the comment of the media. /// - public readonly string TrackNumber; + /// A string representing the comment, or null if the information does not exists. + public string Comment { get; } + /// - /// Classification + /// Gets the track number of the media. /// - public readonly string Classification; + /// A string representing the track number, or null if the information does not exists. + public string TrackNumber { get; } + /// - /// Rating + /// Gets the classification of the media. /// - public readonly string Rating; + /// A string representing the classification, or null if the information does not exists. + public string Classification { get; } + /// - /// Longitude + /// Gets the rating of the media. /// - public readonly string Longitude; + /// A string representing the rating, or null if the information does not exists. + public string Rating { get; } + /// - /// Latitude + /// Gets the longitude of the media. /// - public readonly string Latitude; + /// A string representing the longitude, or null if the information does not exists. + public string Longitude { get; } + /// - /// Altitude + /// Gets the latitude of the media. /// - public readonly string Altitude; + /// A string representing the latitude, or null if the information does not exists. + public string Latitude { get; } + /// - /// Conductor + /// Gets the altitude of the media. /// - public readonly string Conductor; + /// A string representing the altitude, or null if the information does not exists. + public string Altitude { get; } + /// - /// Unsynchronized lyrics + /// Gets the conductor of the media. /// - public readonly string Unsynclyric; + /// A string representing the conductor, or null if the information does not exists. + public string Conductor { get; } + /// - /// Synchronized lyrics number + /// Gets the unsynchronized lyrics of the media. /// - public readonly string SyncLyricNumber; + /// A string representing the unsynchronized lyrics, or null if the information does not exists. + public string UnsyncLyric { get; } + /// - /// Recording date + /// Gets the number of synchronized lyrics of the media. /// - public readonly string RecordingDate; + /// A string representing the number of the synchronized lyrics, or null if the information does not exists. + public string SyncLyricCount { get; } + /// - /// Rotate(orientation) information + /// Gets the recording date of the media. /// - public readonly string Rotate; + /// A string representing the recording date, or null if the information does not exists. + public string RecordingDate { get; } + /// - /// Video codec type + /// Gets the rotate(orientation) information of the media. /// - public readonly string VideoCodec; + /// A string representing the rotation information, or null if the information does not exists. + public string Rotation { get; } + /// - /// Audio codec type + /// Gets the information for 360 content of the media. /// - public readonly string AudioCodec; - /// - /// 360 content information - /// - public readonly string Content360; - } - - internal class MetadataBundle - { - internal string Duration; - internal string VideoBitrate; - internal string VideoFPS; - internal string VideoWidth; - internal string VideoHeight; - internal string Videostreamcount; - internal string AudioBitrate; - internal string AudioChannels; - internal string AudioSamplerate; - internal string Audiobitpersample; - internal string Audiostreamcount; - internal string Artist; - internal string Title; - internal string Album; - internal string AlbumArtist; - internal string Genre; - internal string Author; - internal string Copyright; - internal string Date; - internal string Description; - internal string Comment; - internal string Tracknumber; - internal string Classification; - internal string Rating; - internal string Longitude; - internal string Latitude; - internal string Altitude; - internal string Conductor; - internal string Unsynclyric; - internal string SyncLyricNumber; - internal string Recordingdate; - internal string Rotate; - internal string VideoCodec; - internal string AudioCodec; - internal string content360; - } + /// A string representing the information for 360 content, or null if the information does not exists. + public string Content360 { get; } + + private Lazy _description; + + public override string ToString() + { + return _description.Value; + } + } } diff --git a/src/Tizen.Multimedia/MetadataExtractor/MetadataEnums.cs b/src/Tizen.Multimedia/MetadataExtractor/MetadataEnums.cs deleted file mode 100755 index 0b6d955..0000000 --- a/src/Tizen.Multimedia/MetadataExtractor/MetadataEnums.cs +++ /dev/null @@ -1,60 +0,0 @@ -/* -* 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; - -namespace Tizen.Multimedia -{ - public enum MetadataExtractorAttr - { - METADATA_DURATION, //Duration - METADATA_VIDEO_BITRATE, //VideoBitrate - METADATA_VIDEO_FPS, //VideoFPS - METADATA_VIDEO_WIDTH, //VideoWidth - METADATA_VIDEO_HEIGHT, //VideoHeight - METADATA_HAS_VIDEO, //Videostreamcount - METADATA_AUDIO_BITRATE, //AudioBitrate - METADATA_AUDIO_CHANNELS, //AudioChannels - METADATA_AUDIO_SAMPLERATE, //AudioSamplerate - METADATA_AUDIO_BITPERSAMPLE, //Audiobitpersample - METADATA_HAS_AUDIO, //Audiostreamcount - METADATA_ARTIST, //Artist - METADATA_TITLE, //Title - METADATA_ALBUM, //Album - METADATA_ALBUM_ARTIST, //Album_Artist - METADATA_GENRE, //Genre - METADATA_AUTHOR, //Author - METADATA_COPYRIGHT, //Copyright - METADATA_DATE, //Date - METADATA_DESCRIPTION, //Description - METADATA_COMMENT, //Comment - METADATA_TRACK_NUM, //Tracknumberinfo - METADATA_CLASSIFICATION, //Classification - METADATA_RATING, //Rating - METADATA_LONGITUDE, //Longitude - METADATA_LATITUDE, //Latitude - METADATA_ALTITUDE, //Altitude - METADATA_CONDUCTOR, //Conductor - METADATA_UNSYNCLYRICS, //Unsynchronizedlyric - METADATA_SYNCLYRICS_NUM, //Synchronizedlyric(time/lyricset)number - METADATA_RECDATE, //Recordingdate - METADATA_ROTATE, //Rotate(Orientation)Information - METADATA_VIDEO_CODEC, //VideoCodec - METADATA_AUDIO_CODEC, //AudioCodec - METADATA_360, //360contentInformation - } -} diff --git a/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractor.cs b/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractor.cs index 70e3e01..17b8021 100755 --- a/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractor.cs +++ b/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractor.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -14,470 +14,285 @@ * limitations under the License. */ - using System; -using System.Threading.Tasks; using System.Runtime.InteropServices; namespace Tizen.Multimedia { - static internal class MetadataExtractorLog - { - internal const string LogTag = "Tizen.Multimedia.MetadataExtractor"; - } - /// - /// The Metadata extractor class provides a set of functions to get the metadata of the input media file - /// - public class MetadataExtractor : IDisposable - { - private bool _disposed = false; - internal IntPtr _handle = IntPtr.Zero; - /// - /// Metadata extractor constructor - /// - /// the path to extract metadata - public MetadataExtractor(string path) - { - int ret; - - if (path == null) - { - Log.Error(MetadataExtractorLog.LogTag, "Path is NULL"); - MetadataExtractorErrorFactory.ThrowException((int)MetadataExtractorError.InvalidParameter, "Path is NULL"); - } - else - { - ret = Interop.MetadataExtractor.Create(out _handle); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to create metadata" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to create metadata"); - } - ret = Interop.MetadataExtractor.SetPath(_handle, path); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to set path" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to set path"); - } - } - } - /// - /// Metadata extractor constructor - /// - /// the buffer to extract metadata - public MetadataExtractor(byte[] buffer) - { - int ret; - - if (buffer == null || buffer.Length == 0) - { - Log.Error(MetadataExtractorLog.LogTag, "buffer is null"); - MetadataExtractorErrorFactory.ThrowException((int)MetadataExtractorError.InvalidParameter, "buffer is null"); - } - else + static internal class MetadataExtractorLog + { + internal const string Tag = "Tizen.Multimedia.MetadataExtractor"; + } + + /// + /// Provides a set of functions to get the metadata from a media file. + /// + public class MetadataExtractor : IDisposable + { + private bool _disposed = false; + private IntPtr _handle = IntPtr.Zero; + private IntPtr _buffer = IntPtr.Zero; + + private void Create(Func initFunc) + { + MetadataExtractorRetValidator.ThrowIfError( + Interop.MetadataExtractor.Create(out _handle), "Failed to create metadata"); + + try + { + MetadataExtractorRetValidator.ThrowIfError(initFunc(), "Failed to init"); + + _metadata = new Lazy(() => new Metadata(Handle)); + } + catch + { + Release(); + throw; + } + } + + /// + /// Initialize a new instance of the MetadataExtractor class with the specified path. + /// + /// The path for the file to extract metadata. + /// is null. + public MetadataExtractor(string path) + { + if (path == null) + { + throw new ArgumentNullException(nameof(path)); + } + + Create(()=> Interop.MetadataExtractor.SetPath(_handle, path)); + } + + /// + /// Initialize a new instance of the MetadataExtractor class with the specified buffer. + /// + /// The buffer to extract metadata. + /// is null. + /// The length of is zero. + public MetadataExtractor(byte[] buffer) + { + if (buffer == null) + { + throw new ArgumentNullException(nameof(buffer)); + } + + if (buffer.Length == 0) + { + throw new ArgumentException("buffer length is zero.", nameof(buffer)); + } + + _buffer = Marshal.AllocHGlobal(buffer.Length); + Marshal.Copy(buffer, 0, _buffer, buffer.Length); + + Create(() => Interop.MetadataExtractor.SetBuffer(_handle, _buffer, buffer.Length)); + } + + private IntPtr Handle + { + get + { + if (_disposed) + { + throw new ObjectDisposedException(nameof(MetadataExtractor)); + } + + return _handle; + } + } + + private Lazy _metadata; + + /// + /// Retrieves the . + /// + /// A for the give source. + /// Internal process error is occurred. + /// The has been already disposed of. + public Metadata GetMetadata() + { + if (_disposed) + { + throw new ObjectDisposedException(nameof(MetadataExtractor)); + } + + return _metadata.Value; + } + + /// + /// Gets the artwork image in the source. + /// + /// A if it exists, otherwise null. + /// Internal process error is occurred. + /// The has been already disposed of. + public Artwork GetArtwork() + { + IntPtr data = IntPtr.Zero; + IntPtr mimeType = IntPtr.Zero; + + try + { + int size = 0; + + var ret = Interop.MetadataExtractor.GetArtwork(Handle, out data, out size, out mimeType); + MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get value"); + + if (size > 0) + { + var buf = new byte[size]; + Marshal.Copy(data, buf, 0, size); + + return new Artwork(buf, Marshal.PtrToStringAnsi(mimeType)); + } + + return null; + } + finally + { + Interop.Libc.Free(data); + Interop.Libc.Free(mimeType); + } + } + + /// + /// Gets the sync lyrics of the source. + /// + /// The index of lyrics to retrieve. + /// A object if is valid, otherwise null. + /// Internal process error is occurred. + /// The has been already disposed of. + public SyncLyrics GetSyncLyrics(int index) + { + IntPtr lyrics = IntPtr.Zero; + + try + { + uint timestamp = 0; + + var ret = Interop.MetadataExtractor.GetSynclyrics(Handle, index, out timestamp, out lyrics); + MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get sync lyrics"); + + if (lyrics == IntPtr.Zero) + { + return null; + } + + return new SyncLyrics(Marshal.PtrToStringAnsi(lyrics), timestamp); + } + finally + { + Interop.Libc.Free(lyrics); + } + } + + /// + /// Gets the frame of a video media. + /// + /// The raw thumbnail data in RGB888 if it exists, otherwise null. + /// Internal process error is occurred. + /// The has been already disposed of. + public byte[] GetVideoThumbnail() + { + IntPtr data = IntPtr.Zero; + + try + { + int size = 0; + + var ret = Interop.MetadataExtractor.GetFrame(Handle, out data, out size); + MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get value"); + + if (size == 0) + { + return null; + } + + var buf = new byte[size]; + Marshal.Copy(data, buf, 0, size); + + return buf; + } + finally { - int size = buffer.Length; - IntPtr buf = Marshal.AllocHGlobal(size); - Marshal.Copy(buffer, 0, buf, size); - - ret = Interop.MetadataExtractor.Create(out _handle); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to create metadata" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to create metadata"); - } - - ret = Interop.MetadataExtractor.SetBuffer(_handle, buf, size); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to set buffer" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to set buffer"); - } - } - - } - /// - /// Gets metadata - /// - /// Metadata object - /// When internal process error is occured - public Metadata GetMetadata() - { - int ret; - Metadata _metadata; - MetadataBundle _metaBundle = new MetadataBundle(); - - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_DURATION, out _metaBundle.Duration); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_HAS_VIDEO, out _metaBundle.Videostreamcount); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - if (_metaBundle.Videostreamcount == null || (_metaBundle.Videostreamcount != null && !_metaBundle.Videostreamcount.Equals("0"))) - { - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_VIDEO_BITRATE, out _metaBundle.VideoBitrate); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_VIDEO_FPS, out _metaBundle.VideoFPS); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_VIDEO_WIDTH, out _metaBundle.VideoWidth); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_VIDEO_HEIGHT, out _metaBundle.VideoHeight); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_VIDEO_CODEC, out _metaBundle.VideoCodec); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - } - - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_HAS_AUDIO, out _metaBundle.Audiostreamcount); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - if (_metaBundle.Audiostreamcount == null || (_metaBundle.Audiostreamcount != null && !_metaBundle.Audiostreamcount.Equals("0"))) - { - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_AUDIO_BITRATE, out _metaBundle.AudioBitrate); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_AUDIO_CHANNELS, out _metaBundle.AudioChannels); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_AUDIO_SAMPLERATE, out _metaBundle.AudioSamplerate); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_AUDIO_BITPERSAMPLE, out _metaBundle.Audiobitpersample); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_AUDIO_CODEC, out _metaBundle.AudioCodec); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - } - - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_ARTIST, out _metaBundle.Artist); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_TITLE, out _metaBundle.Title); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_ALBUM, out _metaBundle.Album); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_ALBUM_ARTIST, out _metaBundle.AlbumArtist); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_GENRE, out _metaBundle.Genre); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_AUTHOR, out _metaBundle.Author); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_COPYRIGHT, out _metaBundle.Copyright); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_DATE, out _metaBundle.Date); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_DESCRIPTION, out _metaBundle.Description); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_COMMENT, out _metaBundle.Comment); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_TRACK_NUM, out _metaBundle.Tracknumber); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_CLASSIFICATION, out _metaBundle.Classification); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_RATING, out _metaBundle.Rating); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_LONGITUDE, out _metaBundle.Longitude); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_LATITUDE, out _metaBundle.Latitude); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_ALTITUDE, out _metaBundle.Altitude); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_CONDUCTOR, out _metaBundle.Conductor); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_UNSYNCLYRICS, out _metaBundle.Unsynclyric); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_SYNCLYRICS_NUM, out _metaBundle.SyncLyricNumber); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_RECDATE, out _metaBundle.Recordingdate); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_ROTATE, out _metaBundle.Rotate); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - ret = Interop.MetadataExtractor.GetMetadata(_handle, (int)MetadataExtractorAttr.METADATA_360, out _metaBundle.content360); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - - _metadata = new Metadata(_metaBundle); - - return _metadata; - } - /// - /// Gets the artwork image in a media file - /// - /// Artwork object - /// When internal process error is occured - public Artwork GetArtwork() - { - int ret; - Artwork _artwork; - IntPtr getArtworkData; - int getSize; - byte[] tmpBuf; - string getMimeType; - - ret = Interop.MetadataExtractor.GetArtwork(_handle, out getArtworkData, out getSize, out getMimeType); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - - if (getSize > 0) - { - tmpBuf = new byte[getSize]; - Marshal.Copy(getArtworkData, tmpBuf, 0, getSize); - - _artwork = new Artwork(tmpBuf, getMimeType); - } - else - { - _artwork = new Artwork(null, null); - } - - return _artwork; - } - /// - /// Gets the synclyrics of a media file - /// - /// The index of time/lyrics to set - /// Synclyrics object - /// When the invalid parameter value is set. - /// When internal process error is occured - public Synclyrics GetSynclyrics(int index) - { - int ret; - Synclyrics _lyrics; - uint getTimestamp; - string getLyrics; - - ret = Interop.MetadataExtractor.GetSynclyrics(_handle, index, out getTimestamp, out getLyrics); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - - _lyrics = new Synclyrics(getLyrics, getTimestamp); - - return _lyrics; - } - /// - /// Gets the frame of a video media file - /// - /// Frame object - /// When internal process error is occured - public Frame GetFrame() - { - int ret; - Frame _frame; - IntPtr getFameData; - int getSize; - byte[] tmpBuf; - - ret = Interop.MetadataExtractor.GetFrame(_handle, out getFameData, out getSize); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - - tmpBuf = new byte[getSize]; - Marshal.Copy(getFameData, tmpBuf, 0, getSize); - - _frame = new Frame(tmpBuf); - - return _frame; - } - /// - /// Gets the frame of a video media - /// - /// The timestamp in milliseconds - /// If @c true the user can get an accurate frame for the given timestamp,\n - /// otherwise @c false if the user can only get the nearest i-frame of the video rapidly - /// Frame object - /// When the invalid parameter value is set. - /// When internal process error is occured - public Frame GetFrameAtTime(uint timeStamp, bool accurate) - { - int ret; - Frame _frame; - IntPtr getFameData; - int getSize; - byte[] tmpBuf; - - ret = Interop.MetadataExtractor.GetFrameAtTime(_handle, timeStamp, accurate, out getFameData, out getSize); - if (ret != (int)MetadataExtractorError.None) - { - Log.Error(MetadataExtractorLog.LogTag, "Failed to get value" + (MetadataExtractorError)ret); - MetadataExtractorErrorFactory.ThrowException(ret, "Failed to get value"); - } - - tmpBuf = new byte[getSize]; - Marshal.Copy(getFameData, tmpBuf, 0, getSize); - - _frame = new Frame(tmpBuf); - - return _frame; - } - - /// - /// Metadata Extractor destructor - /// - ~MetadataExtractor() - { - Dispose(false); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposed) - { - if (disposing) - { - // To be used if there are any other disposable objects - } - if (_handle != IntPtr.Zero) - { - Interop.MetadataExtractor.Destroy(_handle); - _handle = IntPtr.Zero; - } - _disposed = true; - } - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - } + Interop.Libc.Free(data); + } + } + + /// + /// Gets the frame of a video media. + /// + /// The timestamp in milliseconds. + /// true to get an accurate frame for the given timestamp, + /// otherwise false to get the nearest i-frame of the video rapidly. + /// The raw frame data in RGB888 if a frame at specified time exists, otherwise null. + /// When internal process error is occured + /// The has been already disposed of. + public byte[] GetFrameAt(uint timeStamp, bool accurate) + { + IntPtr data = IntPtr.Zero; + + try + { + int size = 0; + + var ret = Interop.MetadataExtractor.GetFrameAtTime(Handle, timeStamp, accurate, out data, out size); + MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get value"); + + if (size == 0) + { + return null; + } + + var buf = new byte[size]; + Marshal.Copy(data, buf, 0, size); + + return buf; + } + finally + { + Interop.Libc.Free(data); + } + } + + /// + /// Metadata Extractor destructor + /// + ~MetadataExtractor() + { + Dispose(false); + } + + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + Release(); + _disposed = true; + } + } + + private void Release() + { + if (_buffer != IntPtr.Zero) + { + Marshal.FreeHGlobal(_buffer); + } + + if (_handle != IntPtr.Zero) + { + var ret = Interop.MetadataExtractor.Destroy(_handle); + Log.Error(MetadataExtractorLog.Tag, $"DestroyHandle failed : {ret}."); + + _handle = IntPtr.Zero; + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + } } diff --git a/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorAttr.cs b/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorAttr.cs new file mode 100644 index 0000000..8388dec --- /dev/null +++ b/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorAttr.cs @@ -0,0 +1,57 @@ +/* +* 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. +*/ + +namespace Tizen.Multimedia +{ + internal enum MetadataExtractorAttr + { + Duration, + VideoBitrate, + VideoFps, + VideoWidth, + VideoHeight, + VideoStreamCount, + AudioBitrate, + AudioChannels, + AudioSamplerate, + AudioBitPerSample, + AudioStreamCount, + Artist, + Title, + Album, + AlbumArtist, + Genre, + Author, + Copyright, + ReleaseDate, + Description, + Comment, + TrackNum, + Classification, + Rating, + Longitude, + Latitude, + Altitude, + Conductor, + UnSyncLyrics, + SyncLyricsNum, + RecordingDate, + Rotate, + VideoCodec, + AudioCodec, + ContentFor360, + } +} diff --git a/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorError.cs b/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorError.cs new file mode 100644 index 0000000..9902b33 --- /dev/null +++ b/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorError.cs @@ -0,0 +1,62 @@ +/* +* 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 System.IO; +using Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// Enumeration for metadata extractor's error codes. + /// + internal enum MetadataExtractorError + { + None = ErrorCode.None, + InvalidParameter = ErrorCode.InvalidParameter, + OutOfMemory = ErrorCode.OutOfMemory, + FileExists = ErrorCode.FileExists, + PermissionDenied = ErrorCode.PermissionDenied, + TizenMetadataExtractorError = -0x01930000, + OperationFailed = TizenMetadataExtractorError | 0x01 // Invalid operation + }; + + internal static class MetadataExtractorRetValidator + { + internal static void ThrowIfError(MetadataExtractorError error, string errorMessage) + { + switch (error) + { + case MetadataExtractorError.InvalidParameter: + throw new ArgumentException(errorMessage); + + case MetadataExtractorError.FileExists: + throw new FileNotFoundException(errorMessage); + + case MetadataExtractorError.PermissionDenied: + throw new UnauthorizedAccessException(errorMessage); + + case MetadataExtractorError.OutOfMemory: + throw new OutOfMemoryException(); + + case MetadataExtractorError.OperationFailed: + throw new InvalidOperationException(errorMessage); + } + } + } +} + diff --git a/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorErrorFactory.cs b/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorErrorFactory.cs deleted file mode 100755 index 9b34ab5..0000000 --- a/src/Tizen.Multimedia/MetadataExtractor/MetadataExtractorErrorFactory.cs +++ /dev/null @@ -1,55 +0,0 @@ -/* -* 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 Tizen.Internals.Errors; - -namespace Tizen.Multimedia -{ - /// - /// Enumeration for metadata extractor's error codes. - /// - internal enum MetadataExtractorError - { - None = ErrorCode.None, // Success - InvalidParameter = ErrorCode.InvalidParameter, // Invalid parameter - OutOfMemory = ErrorCode.OutOfMemory, // Out of memory - FileExists = ErrorCode.FileExists, // File does not exist - PermissionDenied = ErrorCode.PermissionDenied, // Permission deny - TizenMetadataExtractorError = -0x01930000, - MetadataExtractorErrorOperationFailed = TizenMetadataExtractorError | 0x01 // Invalid operation - }; - - internal static class MetadataExtractorErrorFactory - { - internal static void ThrowException(int errorCode, string errorMessage = null, string paramName = null) - { - switch ((MetadataExtractorError)errorCode) - { - case MetadataExtractorError.InvalidParameter: - throw new ArgumentException("[" + errorCode.ToString() + "]" + errorMessage, paramName); - - case MetadataExtractorError.OutOfMemory: - case MetadataExtractorError.FileExists: - case MetadataExtractorError.PermissionDenied: - case MetadataExtractorError.MetadataExtractorErrorOperationFailed: - throw new InvalidOperationException("[" + errorCode.ToString() + "]" + errorMessage); - } - } - } -} - diff --git a/src/Tizen.Multimedia/MetadataExtractor/Synclyrics.cs b/src/Tizen.Multimedia/MetadataExtractor/Synclyrics.cs index 080f307..620b251 100755 --- a/src/Tizen.Multimedia/MetadataExtractor/Synclyrics.cs +++ b/src/Tizen.Multimedia/MetadataExtractor/Synclyrics.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -14,32 +14,30 @@ * limitations under the License. */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Tizen.Multimedia -{ +{ /// - /// This class provides properties of the synchronized lyrics information of the given media + /// Represents synchronized lyrics information of media. /// - public class Synclyrics - { - internal Synclyrics(string lyrics, uint timestamp) - { - Lyrics = lyrics; - Timestamp = timestamp; - } + public class SyncLyrics + { + /// + /// Initialize a new instance of the MetadataExtractor class with the specified lyrics and timestamp. + /// + public SyncLyrics(string lyrics, uint timestamp) + { + Lyrics = lyrics; + Timestamp = timestamp; + } + /// /// The lyrics of the index /// - public readonly string Lyrics; + public string Lyrics { get; } + /// /// The time information of the index /// - public readonly uint Timestamp; - } + public uint Timestamp { get; } + } } diff --git a/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj b/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj index e6dbb28..336310e 100755 --- a/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj +++ b/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj @@ -45,220 +45,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/Tizen.Multimedia/Tizen.Multimedia.csproj b/src/Tizen.Multimedia/Tizen.Multimedia.csproj index 2bbe0e7..3e35bcd 100755 --- a/src/Tizen.Multimedia/Tizen.Multimedia.csproj +++ b/src/Tizen.Multimedia/Tizen.Multimedia.csproj @@ -1,285 +1,72 @@ - - - - Debug - AnyCPU - {0CE698B0-4849-4096-9D7F-30E611F50DAD} - Library - Properties - Tizen.Multimedia - Tizen.Multimedia - 512 - - - .NETStandard - v1.3 - .NETStandard,Version=v1.3 - false - true - $(NoWarn);1701;1702 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - true - - - Tizen.Multimedia.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) - <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) - true - - + + + + Debug + AnyCPU + {0CE698B0-4849-4096-9D7F-30E611F50DAD} + Library + Properties + Tizen.Multimedia + Tizen.Multimedia + 512 + + + .NETStandard + v1.3 + .NETStandard,Version=v1.3 + false + true + $(NoWarn);1701;1702 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + Tizen.Multimedia.snk + + + + + + + + + + + + + + + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + -- 2.7.4