From 8bee3b086da6909d53361da7b0e2b1610d0fbdd9 Mon Sep 17 00:00:00 2001 From: Haesu Gwon Date: Mon, 6 Sep 2021 15:25:39 +0900 Subject: [PATCH] [MediaContent] Support ebook format (#3374) * [MediaContent] Support ebook format --- .../Interop/Interop.BookInfo.cs | 46 +++++++++++++ .../Interop/Interop.MediaInfo.cs | 3 + .../Tizen.Content.MediaContent.csproj | 1 + .../Tizen.Content.MediaContent/BookInfo.cs | 77 ++++++++++++++++++++++ .../Tizen.Content.MediaContent/Enums.cs | 9 ++- .../Tizen.Content.MediaContent/MediaInfo.cs | 3 + .../Tizen.Content.MediaContent/MediaInfoCommand.cs | 49 ++++++++++++++ src/Tizen.Multimedia/AssemblyAttrs.cs | 2 + 8 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 src/Tizen.Content.MediaContent/Interop/Interop.BookInfo.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookInfo.cs diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.BookInfo.cs b/src/Tizen.Content.MediaContent/Interop/Interop.BookInfo.cs new file mode 100644 index 0000000..4bc192c --- /dev/null +++ b/src/Tizen.Content.MediaContent/Interop/Interop.BookInfo.cs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 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.Runtime.InteropServices; +using Tizen.Content.MediaContent; + +internal static partial class Interop +{ + internal static partial class BookInfo + { + [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_destroy")] + internal static extern MediaContentError Destroy(IntPtr handle); + + [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_media_id")] + internal static extern MediaContentError GetMediaId(IntPtr handle, out IntPtr mediaId); + + [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_subject")] + internal static extern MediaContentError GetSubject(IntPtr handle, out IntPtr subject); + + [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_author")] + internal static extern MediaContentError GetAuthor(IntPtr handle, out IntPtr author); + + [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_date")] + internal static extern MediaContentError GetDate(IntPtr handle, out IntPtr date); + + [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_publisher")] + internal static extern MediaContentError GetPublisher(IntPtr handle, out IntPtr publisher); + + [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_path_with_keyword")] + internal static extern MediaContentError GetPathByKeyword(string keyword, out IntPtr path, out uint length); + } +} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs b/src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs index fe3bae0..89cfeb4 100644 --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs @@ -81,6 +81,9 @@ internal static partial class Interop [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_audio")] internal static extern MediaContentError GetAudio(MediaInfoHandle handle, out IntPtr audioHandle); + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_book")] + internal static extern MediaContentError GetBook(MediaInfoHandle handle, out IntPtr bookHandle); + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_id")] internal static extern MediaContentError GetMediaId(MediaInfoHandle mediaInformationHandle, out IntPtr mediaId); diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj index 7a96416..e404a79 100644 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj @@ -5,6 +5,7 @@ + diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookInfo.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookInfo.cs new file mode 100644 index 0000000..fbd8bf3 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookInfo.cs @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 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.Diagnostics; + +namespace Tizen.Content.MediaContent +{ + /// + /// Represents the book information for the media. + /// + /// 9 + public class BookInfo : MediaInfo + { + internal BookInfo(Interop.MediaInfoHandle handle) : base(handle) + { + IntPtr bookHandle = IntPtr.Zero; + + try + { + Interop.MediaInfo.GetBook(handle, out bookHandle).ThrowIfError("Failed to retrieve data"); + + Debug.Assert(bookHandle != IntPtr.Zero); + + Subject = InteropHelper.GetString(bookHandle, Interop.BookInfo.GetSubject); + Author = InteropHelper.GetString(bookHandle, Interop.BookInfo.GetAuthor); + DatePublished = InteropHelper.GetString(bookHandle, Interop.BookInfo.GetDate); + Publisher = InteropHelper.GetString(bookHandle, Interop.BookInfo.GetPublisher); + } + finally + { + Interop.BookInfo.Destroy(bookHandle).ThrowIfError("Failed to destroy book handle"); + } + } + + /// + /// Gets the subject of the book. + /// + /// The subject. + /// 9 + public string Subject { get; } + + /// + /// Gets the author of the book. + /// + /// The author. + /// 9 + public string Author { get; } + + /// + /// Gets the published date, formatted as a string. + /// + /// The published date. + /// 9 + public string DatePublished { get; } + + /// + /// Gets the publisher of the book. + /// + /// The publisher. + /// 9 + public string Publisher { get; } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs index 5a5e19c..ea4bad1 100644 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs @@ -122,7 +122,14 @@ namespace Tizen.Content.MediaContent /// /// The type of other. /// - Other = 4 + Other = 4, + + /// + /// The type of book. + /// + /// + /// 9 + Book = 5 } /// diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs index c8301ad..1ad0158 100644 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs @@ -233,6 +233,9 @@ namespace Tizen.Content.MediaContent case MediaType.Video: return new VideoInfo(handle); + + case MediaType.Book: + return new BookInfo(handle); } return new MediaInfo(handle); diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs index 38f7d93..33e6891 100644 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Tizen.System; @@ -472,6 +473,54 @@ namespace Tizen.Content.MediaContent } /// + /// Retrieves all matched ebook paths with given . + /// + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The keyword to search. + /// A list of ebook paths which contain . + /// is null. + /// The is disconnected. + /// The has already been disposed. + /// An error occurred while executing the command. + /// The caller has no required privilege. + /// 9 + public MediaDataReader SelectEbookPath(string keyword) + { + ValidateDatabase(); + + IntPtr path = IntPtr.Zero; + uint length = 0; + + ValidationUtil.ValidateNotNullOrEmpty(keyword, nameof(keyword)); + + try + { + Interop.BookInfo.GetPathByKeyword(keyword, out path, out length). + ThrowIfError("Failed to get path by keyword"); + + var list = new List(); + var current = path; + for (int i = 0; i < length; i++) + { + list.Add(Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(current))); + current = (IntPtr)((long)current + Marshal.SizeOf(typeof(IntPtr))); + } + + return new MediaDataReader(list); + } + finally + { + var current = path; + for (int i = 0; i < length; i++) + { + Tizen.Multimedia.LibcSupport.Free(Marshal.ReadIntPtr(current)); + current = (IntPtr)((long)current + Marshal.SizeOf(typeof(IntPtr))); + } + } + } + + /// /// Deletes the media from the database. /// /// http://tizen.org/privilege/content.write diff --git a/src/Tizen.Multimedia/AssemblyAttrs.cs b/src/Tizen.Multimedia/AssemblyAttrs.cs index 37a6060..51179d6 100644 --- a/src/Tizen.Multimedia/AssemblyAttrs.cs +++ b/src/Tizen.Multimedia/AssemblyAttrs.cs @@ -19,6 +19,8 @@ using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Tizen.Content.MediaContent, " + PublicKey.Value)] + [assembly: InternalsVisibleTo("Tizen.Multimedia.AudioIO, " + PublicKey.Value)] [assembly: InternalsVisibleTo("Tizen.Multimedia.Camera, " + PublicKey.Value)] -- 2.7.4