From cb7e42b681a80322961b325a339c50374f3601cf Mon Sep 17 00:00:00 2001 From: coderhyme Date: Sat, 19 Aug 2017 11:56:03 +0900 Subject: [PATCH] [MediaContent] Redesigned API. Change-Id: Ia7ba7d6040076b40d908a558682c4384433271ff Signed-off-by: coderhyme --- .../Interop/Interop.Album.cs | 60 ++ .../Interop/Interop.AudioInfo.cs | 70 ++ .../Interop/Interop.AudioInformation.cs | 118 -- ...nterop.MediaBookmark.cs => Interop.Bookmark.cs} | 34 +- .../Interop/{Interop.Glib.cs => Interop.Common.cs} | 8 +- .../{Interop.MediaFace.cs => Interop.Face.cs} | 26 +- .../{Interop.MediaFilter.cs => Interop.Filter.cs} | 33 +- .../{Interop.MediaFolder.cs => Interop.Folder.cs} | 22 +- .../Interop/Interop.Group.cs | 44 + .../Interop/Interop.ImageInfo.cs | 61 ++ .../Interop/Interop.ImageInformation.cs | 91 -- .../Interop/Interop.Libc.cs | 1 - .../Interop/Interop.Libraries.cs | 2 - .../Interop/Interop.MediaContent.cs | 15 +- .../Interop/Interop.MediaContentHandle.cs | 46 + .../Interop/Interop.MediaGroup.cs | 81 -- .../Interop/Interop.MediaInfo.cs | 236 ++++ .../Interop/Interop.MediaInformation.cs | 287 ----- ...nterop.MediaPlaylist.cs => Interop.Playlist.cs} | 53 +- ...{Interop.MediaStorage.cs => Interop.Storage.cs} | 34 +- .../{Interop.MediaTag.cs => Interop.Tag.cs} | 52 +- .../Interop/Interop.VideoInfo.cs | 67 ++ .../Interop/Interop.VideoInformation.cs | 115 -- .../Tizen.Content.MediaContent.csproj | 1 + .../Tizen.Content.MediaContent/Album.cs | 235 +--- .../Tizen.Content.MediaContent/AlbumCommand.cs | 195 ++++ .../Tizen.Content.MediaContent/AudioInfo.cs | 144 +++ .../Tizen.Content.MediaContent/AudioInformation.cs | 455 -------- .../Tizen.Content.MediaContent/Bookmark.cs | 68 ++ .../Tizen.Content.MediaContent/BookmarkCommand.cs | 208 ++++ .../Tizen.Content.MediaContent/Columns.cs | 838 +++++++++++++++ .../Tizen.Content.MediaContent/CommandHelper.cs | 183 ++++ .../ContentCollection.cs | 50 - .../Tizen.Content.MediaContent/ContentColumns.cs | 1130 -------------------- .../Tizen.Content.MediaContent/ContentDatabase.cs | 714 ------------- .../Tizen.Content.MediaContent/ContentEventArgs.cs | 113 -- .../Tizen.Content.MediaContent/ContentFilter.cs | 365 ------- .../Tizen.Content.MediaContent/ContentManager.cs | 268 ----- .../Tizen.Content.MediaContent/Enums.cs | 167 +++ .../Tizen.Content.MediaContent/EventArgs.cs | 135 +++ .../Tizen.Content.MediaContent/FaceInfo.cs | 89 ++ .../Tizen.Content.MediaContent/FaceInfoCommand.cs | 139 +++ .../Tizen.Content.MediaContent/FaceRect.cs | 59 - .../Tizen.Content.MediaContent/Features.cs | 31 + .../Tizen.Content.MediaContent/Folder.cs | 79 ++ .../Tizen.Content.MediaContent/FolderCommand.cs | 193 ++++ .../Tizen.Content.MediaContent/Group.cs | 137 --- .../Tizen.Content.MediaContent/ImageInfo.cs | 121 +++ .../Tizen.Content.MediaContent/ImageInformation.cs | 347 ------ .../Tizen.Content.MediaContent/InteropHelper.cs | 80 ++ .../Tizen.Content.MediaContent/MediaBookmark.cs | 129 --- .../Tizen.Content.MediaContent/MediaCommand.cs | 143 +++ .../MediaContentEnums.cs | 411 ------- .../MediaContentError.cs | 92 +- .../Tizen.Content.MediaContent/MediaDatabase.cs | 466 ++++++++ .../MediaDatabaseException.cs | 62 ++ .../Tizen.Content.MediaContent/MediaFace.cs | 226 ---- .../Tizen.Content.MediaContent/MediaFolder.cs | 330 ------ .../Tizen.Content.MediaContent/MediaInfo.cs | 264 +++++ .../MediaInfoColumnKey.cs | 131 +++ .../Tizen.Content.MediaContent/MediaInfoCommand.cs | 1129 +++++++++++++++++++ .../MediaInfoUpdateValues.cs | 73 ++ .../Tizen.Content.MediaContent/MediaInformation.cs | 897 ---------------- .../Tizen.Content.MediaContent/NamespaceDoc.cs | 26 + .../Tizen.Content.MediaContent/ObjectKeeper.cs | 77 ++ .../Tizen.Content.MediaContent/PlayList.cs | 388 ++----- .../Tizen.Content.MediaContent/PlaylistCommand.cs | 872 +++++++++++++++ .../Tizen.Content.MediaContent/PlaylistMember.cs | 42 + .../Tizen.Content.MediaContent/QueryArguments.cs | 282 +++++ .../RecordNotFoundException.cs | 51 + .../Tizen.Content.MediaContent/Rectangle.cs | 130 +++ .../Tizen.Content.MediaContent/Storage.cs | 233 +--- .../Tizen.Content.MediaContent/StorageCommand.cs | 197 ++++ .../Tizen.Content.MediaContent/Tag.cs | 226 +--- .../Tizen.Content.MediaContent/TagCommand.cs | 471 ++++++++ .../UnsupportedContentException.cs | 51 + .../Tizen.Content.MediaContent/ValdiationUtil.cs | 44 + .../Tizen.Content.MediaContent/VideoInfo.cs | 137 +++ .../Tizen.Content.MediaContent/VideoInformation.cs | 431 -------- 79 files changed, 8301 insertions(+), 7810 deletions(-) create mode 100644 src/Tizen.Content.MediaContent/Interop/Interop.Album.cs create mode 100644 src/Tizen.Content.MediaContent/Interop/Interop.AudioInfo.cs delete mode 100755 src/Tizen.Content.MediaContent/Interop/Interop.AudioInformation.cs rename src/Tizen.Content.MediaContent/Interop/{Interop.MediaBookmark.cs => Interop.Bookmark.cs} (55%) mode change 100755 => 100644 rename src/Tizen.Content.MediaContent/Interop/{Interop.Glib.cs => Interop.Common.cs} (73%) mode change 100755 => 100644 rename src/Tizen.Content.MediaContent/Interop/{Interop.MediaFace.cs => Interop.Face.cs} (80%) mode change 100755 => 100644 rename src/Tizen.Content.MediaContent/Interop/{Interop.MediaFilter.cs => Interop.Filter.cs} (50%) mode change 100755 => 100644 rename src/Tizen.Content.MediaContent/Interop/{Interop.MediaFolder.cs => Interop.Folder.cs} (84%) mode change 100755 => 100644 create mode 100644 src/Tizen.Content.MediaContent/Interop/Interop.Group.cs create mode 100644 src/Tizen.Content.MediaContent/Interop/Interop.ImageInfo.cs delete mode 100755 src/Tizen.Content.MediaContent/Interop/Interop.ImageInformation.cs create mode 100644 src/Tizen.Content.MediaContent/Interop/Interop.MediaContentHandle.cs delete mode 100755 src/Tizen.Content.MediaContent/Interop/Interop.MediaGroup.cs create mode 100644 src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs delete mode 100755 src/Tizen.Content.MediaContent/Interop/Interop.MediaInformation.cs rename src/Tizen.Content.MediaContent/Interop/{Interop.MediaPlaylist.cs => Interop.Playlist.cs} (73%) mode change 100755 => 100644 rename src/Tizen.Content.MediaContent/Interop/{Interop.MediaStorage.cs => Interop.Storage.cs} (65%) mode change 100755 => 100644 rename src/Tizen.Content.MediaContent/Interop/{Interop.MediaTag.cs => Interop.Tag.cs} (67%) mode change 100755 => 100644 create mode 100644 src/Tizen.Content.MediaContent/Interop/Interop.VideoInfo.cs delete mode 100755 src/Tizen.Content.MediaContent/Interop/Interop.VideoInformation.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AlbumCommand.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AudioInfo.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AudioInformation.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Bookmark.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookmarkCommand.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Columns.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/CommandHelper.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentCollection.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentColumns.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentDatabase.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentEventArgs.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentFilter.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentManager.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/EventArgs.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceInfo.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceInfoCommand.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceRect.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Features.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Folder.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FolderCommand.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Group.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ImageInfo.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ImageInformation.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/InteropHelper.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaBookmark.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaCommand.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaContentEnums.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabase.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabaseException.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaFace.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaFolder.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoColumnKey.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoUpdateValues.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInformation.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/NamespaceDoc.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ObjectKeeper.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistCommand.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistMember.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/QueryArguments.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/RecordNotFoundException.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Rectangle.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/StorageCommand.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/TagCommand.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/UnsupportedContentException.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ValdiationUtil.cs create mode 100644 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/VideoInfo.cs delete mode 100755 src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/VideoInformation.cs diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.Album.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Album.cs new file mode 100644 index 0000000..38bece8 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Album.cs @@ -0,0 +1,60 @@ +/* + * 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.Runtime.InteropServices; +using Tizen.Content.MediaContent; + +internal static partial class Interop +{ + internal static partial class Album + { + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_album_count_from_db")] + internal static extern MediaContentError GetAlbumCountFromDb(FilterHandle filter, out int count); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_media_count_from_db")] + internal static extern MediaContentError GetMediaCountFromDb(int albumId, FilterHandle filter, out int count); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_destroy")] + internal static extern MediaContentError Destroy(IntPtr album); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_clone")] + internal static extern MediaContentError Clone(out IntPtr dst, IntPtr src); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_album_id")] + internal static extern MediaContentError GetId(IntPtr album, out int albumId); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_name")] + internal static extern MediaContentError GetName(IntPtr album, out IntPtr value); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_artist")] + internal static extern MediaContentError GetArtist(IntPtr album, out IntPtr value); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_album_art")] + internal static extern MediaContentError GetAlbumArt(IntPtr album, out IntPtr value); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_album_from_db")] + internal static extern MediaContentError GetAlbumFromDb(int albumId, out IntPtr album); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_foreach_album_from_db")] + internal static extern MediaContentError ForeachAlbumFromDb(FilterHandle filter, + Common.ItemCallback cb, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_album_foreach_media_from_db")] + internal static extern MediaContentError ForeachMediaFromDb(int albumId, FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); + } +} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.AudioInfo.cs b/src/Tizen.Content.MediaContent/Interop/Interop.AudioInfo.cs new file mode 100644 index 0000000..f61f134 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Interop/Interop.AudioInfo.cs @@ -0,0 +1,70 @@ +/* + * 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.Runtime.InteropServices; +using Tizen.Content.MediaContent; + +internal static partial class Interop +{ + internal static partial class AudioInfo + { + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError Destroy(IntPtr handle); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_album", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetAlbum(IntPtr handle, out IntPtr albumName); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_artist", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetArtist(IntPtr handle, out IntPtr artistName); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_album_artist", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetAlbumArtist(IntPtr handle, out IntPtr albumArtistName); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_genre", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetGenre(IntPtr handle, out IntPtr genreName); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_composer", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetComposer(IntPtr handle, out IntPtr composerName); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_year", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetYear(IntPtr handle, out IntPtr year); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_recorded_date", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetRecordedDate(IntPtr handle, out IntPtr recordedDate); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_copyright", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetCopyright(IntPtr handle, out IntPtr copyright); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_track_num", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetTrackNum(IntPtr handle, out IntPtr trackNum); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_bit_rate", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetBitRate(IntPtr handle, out int bitRate); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_bitpersample", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetBitPerSample(IntPtr handle, out int bitPerSample); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_sample_rate", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetSampleRate(IntPtr handle, out int sampleRate); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_channel", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetChannel(IntPtr handle, out int channel); + + [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_duration", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetDuration(IntPtr handle, out int duration); + } +} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.AudioInformation.cs b/src/Tizen.Content.MediaContent/Interop/Interop.AudioInformation.cs deleted file mode 100755 index ccdf20c..0000000 --- a/src/Tizen.Content.MediaContent/Interop/Interop.AudioInformation.cs +++ /dev/null @@ -1,118 +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.Runtime.InteropServices; -using Tizen.Content.MediaContent; - -internal static partial class Interop -{ - internal static partial class AudioInformation - { - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_destroy", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Destroy(IntPtr media); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_clone", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Clone(out SafeAudioInformationHandle dst, SafeAudioInformationHandle src); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_media_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetMediaId(SafeAudioInformationHandle audioInformationHandle, out IntPtr mediaId); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_album", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAlbum(SafeAudioInformationHandle audioInformationHandle, out IntPtr albumName); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_artist", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetArtist(SafeAudioInformationHandle audioInformationHandle, out IntPtr artistName); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_album_artist", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAlbumArtist(SafeAudioInformationHandle audioInformationHandle, out IntPtr albumArtistName); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_genre", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetGenre(SafeAudioInformationHandle audioInformationHandle, out IntPtr genreName); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_composer", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetComposer(SafeAudioInformationHandle audioInformationHandle, out IntPtr composerName); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_year", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetYear(SafeAudioInformationHandle audioInformationHandle, out IntPtr year); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_recorded_date", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetRecordedDate(SafeAudioInformationHandle audioInformationHandle, out IntPtr recordedDate); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_copyright", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetCopyright(SafeAudioInformationHandle audioInformationHandle, out IntPtr copyright); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_track_num", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetTrackNum(SafeAudioInformationHandle audioInformationHandle, out IntPtr trackNum); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_bit_rate", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetBitRate(SafeAudioInformationHandle audioInformationHandle, out int bitRate); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_bitpersample", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetBitPerSample(SafeAudioInformationHandle audioInformationHandle, out int bitPerSample); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_sample_rate", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetSampleRate(SafeAudioInformationHandle audioInformationHandle, out int sampleRate); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_channel", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetChannel(SafeAudioInformationHandle audioInformationHandle, out int channel); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_duration", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetDuration(SafeAudioInformationHandle audioInformationHandle, out int duration); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_played_count", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetPlayedCount(SafeAudioInformationHandle audioInformationHandle, out int playedCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_played_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetPlayedTime(SafeAudioInformationHandle audioInformationHandle, out int playedTime); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_get_played_position", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetPlayedPosition(SafeAudioInformationHandle audioInformationHandle, out int playedPosition); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_set_played_count", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetPlayedCount(SafeAudioInformationHandle audioInformationHandle, int playedCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_set_played_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetPlayedTime(SafeAudioInformationHandle audioInformationHandle, int playedTime); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_set_played_position", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetPlayedPosition(SafeAudioInformationHandle audioInformationHandle, int playedPosition); - - [DllImport(Libraries.MediaContent, EntryPoint = "audio_meta_update_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError UpdateToDB(IntPtr audioInformationHandle); - - internal sealed class SafeAudioInformationHandle : SafeHandle - { - public SafeAudioInformationHandle() - : base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return this.handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - AudioInformation.Destroy(this.handle); - this.SetHandle(IntPtr.Zero); - return true; - } - } - } -} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaBookmark.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Bookmark.cs old mode 100755 new mode 100644 similarity index 55% rename from src/Tizen.Content.MediaContent/Interop/Interop.MediaBookmark.cs rename to src/Tizen.Content.MediaContent/Interop/Interop.Bookmark.cs index 6639fbb..3ea9f99 --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaBookmark.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Bookmark.cs @@ -14,37 +14,49 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; using Tizen.Content.MediaContent; internal partial class Interop { - internal static partial class MediaBookmark + internal static partial class Bookmark { - [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_insert_to_db")] - internal static extern MediaContentError InsertToDb(string media_id, uint time, string thumbnail_path); + [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_create")] + internal static extern MediaContentError Create(string mediaId, int time, out IntPtr handle); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_insert_to_db_v2")] + internal static extern MediaContentError Insert(IntPtr handle); [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_delete_from_db")] - internal static extern MediaContentError DeleteFromDb(int bookmark_id); + internal static extern MediaContentError Delete(int id); [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_get_bookmark_count_from_db")] - internal static extern MediaContentError GetBookmarkCountFromDb(IntPtr filter, out int bookmark_count); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_clone")] - internal static extern MediaContentError Clone(out IntPtr dst, IntPtr src); + internal static extern MediaContentError GetCount(FilterHandle filter, out int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_destroy")] internal static extern MediaContentError Destroy(IntPtr bookmark); [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_get_bookmark_id")] - internal static extern MediaContentError GetBookmarkId(IntPtr bookmark, out int bookmark_id); + internal static extern MediaContentError GetId(IntPtr bookmark, out int id); [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_get_marked_time")] - internal static extern MediaContentError GetMarkedTime(IntPtr bookmark, out uint marked_time); + internal static extern MediaContentError GetMarkedTime(IntPtr bookmark, out int time); [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_get_thumbnail_path")] internal static extern MediaContentError GetThumbnailPath(IntPtr bookmark, out IntPtr filePath); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_set_thumbnail_path")] + internal static extern MediaContentError SetThumbnailPath(IntPtr bookmark, string filePath); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_get_name")] + internal static extern MediaContentError GetName(IntPtr bookmark, out IntPtr name); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_set_name")] + internal static extern MediaContentError SetName(IntPtr bookmark, string name); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_bookmark_foreach_bookmark_from_db")] + internal static extern MediaContentError ForeachFromDb(FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.Glib.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Common.cs old mode 100755 new mode 100644 similarity index 73% rename from src/Tizen.Content.MediaContent/Interop/Interop.Glib.cs rename to src/Tizen.Content.MediaContent/Interop/Interop.Common.cs index 81afefd..d6dc8a9 --- a/src/Tizen.Content.MediaContent/Interop/Interop.Glib.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Common.cs @@ -14,18 +14,14 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; internal static partial class Interop { - internal static partial class Glib + internal static partial class Common { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool GSourceFunc(IntPtr userData); - - [DllImport(Libraries.Glib, EntryPoint = "g_idle_add", CallingConvention = CallingConvention.Cdecl)] - internal static extern uint IdleAdd(GSourceFunc d, IntPtr data); + internal delegate bool ItemCallback(IntPtr itemHandle, IntPtr data); } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaFace.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Face.cs old mode 100755 new mode 100644 similarity index 80% rename from src/Tizen.Content.MediaContent/Interop/Interop.MediaFace.cs rename to src/Tizen.Content.MediaContent/Interop/Interop.Face.cs index ce88a2c..ca3df6b --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaFace.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Face.cs @@ -14,7 +14,6 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; using Tizen.Content.MediaContent; @@ -30,39 +29,44 @@ internal static partial class Interop internal static extern MediaContentError Destroy(IntPtr face); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_get_face_id")] - internal static extern MediaContentError GetFaceId(IntPtr face, out IntPtr face_id); + internal static extern MediaContentError GetId(IntPtr face, out IntPtr faceId); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_get_media_id")] - internal static extern MediaContentError GetMediaId(IntPtr face, out IntPtr media_id); + internal static extern MediaContentError GetMediaId(IntPtr face, out IntPtr mediaId); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_get_face_rect")] - internal static extern MediaContentError GetFaceRect(IntPtr face, out int rect_x, out int rect_y, out int rect_w, out int IntPtr); + internal static extern MediaContentError GetFaceRect(IntPtr face, + out int x, out int y, out int w, out int h); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_get_orientation")] - internal static extern MediaContentError GetOrientation(IntPtr face, out int orientation); + internal static extern MediaContentError GetOrientation(IntPtr face, out Orientation orientation); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_get_tag")] internal static extern MediaContentError GetTag(IntPtr face, out IntPtr tag); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_create")] - internal static extern MediaContentError Create(string media_id, out IntPtr face); + internal static extern MediaContentError Create(string mediaId, out IntPtr face); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_set_face_rect")] - internal static extern MediaContentError SetFaceRect(IntPtr face, int rect_x, int rect_y, int rect_w, int IntPtr); + internal static extern MediaContentError SetFaceRect(IntPtr face, int x, int y, int w, int h); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_set_orientation")] - internal static extern MediaContentError SetOrientation(IntPtr face, int orientation); + internal static extern MediaContentError SetOrientation(IntPtr face, Orientation orientation); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_set_tag")] internal static extern MediaContentError SetTag(IntPtr face, string tag); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_insert_to_db")] - internal static extern MediaContentError InsertToDb(IntPtr face); + internal static extern MediaContentError InsertToDb(IntPtr handle); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_update_to_db")] - internal static extern MediaContentError UpdateToDb(IntPtr face); + internal static extern MediaContentError Update(IntPtr face); [DllImport(Libraries.MediaContent, EntryPoint = "media_face_delete_from_db")] - internal static extern MediaContentError DeleteFromDb(string face_id); + internal static extern MediaContentError DeleteFromDb(string faceId); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_face_foreach_face_from_db")] + internal static extern MediaContentError ForeachFromDb(FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaFilter.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Filter.cs old mode 100755 new mode 100644 similarity index 50% rename from src/Tizen.Content.MediaContent/Interop/Interop.MediaFilter.cs rename to src/Tizen.Content.MediaContent/Interop/Interop.Filter.cs index f66986b..d265681 --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaFilter.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Filter.cs @@ -14,9 +14,9 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; +using Tizen; using Tizen.Content.MediaContent; internal static partial class Interop @@ -24,33 +24,32 @@ internal static partial class Interop internal static partial class Filter { [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_create")] - internal static extern MediaContentError Create(out IntPtr filter); + internal static extern MediaContentError Create(out FilterHandle filter); [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_destroy")] internal static extern MediaContentError Destroy(IntPtr filter); [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_set_offset")] - internal static extern MediaContentError SetOffset(IntPtr filter, int offset, int count); + internal static extern MediaContentError SetOffset(FilterHandle filter, int offset, int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_set_condition")] - internal static extern MediaContentError SetCondition(IntPtr filter, string condition, ContentCollation type); + internal static extern MediaContentError SetCondition(FilterHandle filter, string condition, + Collation type); - [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_set_order")] - internal static extern MediaContentError SetOrder(IntPtr filter, ContentOrder order, string keyword, ContentCollation type); + [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_set_order_v2")] + internal static extern MediaContentError SetOrder(FilterHandle filter, string orderExpression); [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_set_storage")] - internal static extern MediaContentError SetStorage(IntPtr filter, string storageId); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_get_offset")] - internal static extern MediaContentError GetOffset(IntPtr filter, out int offset, out int count); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_get_condition")] - internal static extern MediaContentError GetCondition(IntPtr filter, out IntPtr condition, out ContentCollation type); + internal static extern MediaContentError SetStorage(FilterHandle filter, string storageId); + } - [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_get_order")] - internal static extern MediaContentError GetOrder(IntPtr filter, out ContentOrder order, out IntPtr keyword, out ContentCollation type); + internal class FilterHandle : MediaContentCriticalHandle + { + public static readonly FilterHandle Null = new FilterHandle(); - [DllImport(Libraries.MediaContent, EntryPoint = "media_filter_get_storage")] - internal static extern MediaContentError GetStorage(IntPtr filter, out IntPtr storageId); + protected override MediaContentError DestroyHandle() + { + return Filter.Destroy(handle); + } } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaFolder.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Folder.cs old mode 100755 new mode 100644 similarity index 84% rename from src/Tizen.Content.MediaContent/Interop/Interop.MediaFolder.cs rename to src/Tizen.Content.MediaContent/Interop/Interop.Folder.cs index 8ba231d..dbd9890 --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaFolder.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Folder.cs @@ -24,10 +24,10 @@ internal static partial class Interop internal static partial class Folder { [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_get_folder_count_from_db")] - internal static extern MediaContentError GetFolderCountFromDb(IntPtr filter, out int folder_count); + internal static extern MediaContentError GetFolderCountFromDb(FilterHandle filter, out int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_get_media_count_from_db")] - internal static extern MediaContentError GetMediaCountFromDb(string folder_id, IntPtr filter, out int media_count); + internal static extern MediaContentError GetMediaCountFromDb(string folder_id, FilterHandle filter, out int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_clone")] internal static extern MediaContentError Clone(out IntPtr dst, IntPtr src); @@ -49,10 +49,10 @@ internal static partial class Interop internal static extern MediaContentError GetName(IntPtr folder, out IntPtr folder_name); [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_get_modified_time")] - internal static extern MediaContentError GetModifiedTime(IntPtr folder, out DateTime date); + internal static extern MediaContentError GetModifiedTime(IntPtr folder, out IntPtr date); [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_get_storage_type")] - internal static extern MediaContentError GetStorageType(IntPtr folder, out ContentStorageType storage_type); + internal static extern MediaContentError GetStorageType(IntPtr folder, out StorageType storage_type); [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_get_storage_id")] internal static extern MediaContentError GetStorageId(IntPtr folder, out IntPtr storage_id); @@ -61,7 +61,7 @@ internal static partial class Interop internal static extern MediaContentError GetOrder(IntPtr folder, out int order); [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_get_folder_from_db")] - internal static extern MediaContentError GetFolderFromDb(string folder_id, out IntPtr folder); + internal static extern MediaContentError GetFolderFromDb(string id, out IntPtr folder); [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_set_name")] internal static extern MediaContentError SetName(IntPtr folder, string name); @@ -72,16 +72,12 @@ internal static partial class Interop [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_update_to_db")] internal static extern MediaContentError UpdateToDb(IntPtr folder); - //Callbacks - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaFolderCallback(IntPtr folderHandle, IntPtr data); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaInfoCallback(IntPtr handle, IntPtr data); - [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_foreach_folder_from_db")] - internal static extern MediaContentError ForeachFolderFromDb(IntPtr filter, MediaFolderCallback callback, IntPtr user_data); + internal static extern MediaContentError ForeachFolderFromDb(FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_foreach_media_from_db")] - internal static extern MediaContentError ForeachMediaFromDb(string folder_id, IntPtr filter, MediaInfoCallback callback, IntPtr user_data); + internal static extern MediaContentError ForeachMediaFromDb(string id, FilterHandle filter, + Common.ItemCallback callback, IntPtr user_data); } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.Group.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Group.cs new file mode 100644 index 0000000..f949364 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Group.cs @@ -0,0 +1,44 @@ +/* + * 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.Runtime.InteropServices; +using Tizen.Content.MediaContent; + +internal static partial class Interop +{ + internal static partial class Group + { + [DllImport(Libraries.MediaContent, EntryPoint = "media_group_get_group_count_from_db")] + internal static extern MediaContentError GetGroupCount(FilterHandle filter, + MediaInfoColumnKey group, out int count); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_group_get_media_count_from_db")] + internal static extern MediaContentError GetMediaCount(string groupName, + MediaInfoColumnKey groupType, FilterHandle filter, out int count); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool MediaGroupCallback(string groupName, IntPtr data); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_group_foreach_group_from_db")] + internal static extern MediaContentError ForeachGroup(FilterHandle filter, + MediaInfoColumnKey group, MediaGroupCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_group_foreach_media_from_db")] + internal static extern MediaContentError ForeachMedia(string groupName, MediaInfoColumnKey group, + FilterHandle filter, Common.ItemCallback callback, IntPtr userData = default(IntPtr)); + } +} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.ImageInfo.cs b/src/Tizen.Content.MediaContent/Interop/Interop.ImageInfo.cs new file mode 100644 index 0000000..c7d5ff8 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Interop/Interop.ImageInfo.cs @@ -0,0 +1,61 @@ +/* + * 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.Runtime.InteropServices; +using Tizen.Content.MediaContent; + +internal static partial class Interop +{ + internal static partial class ImageInfo + { + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError Destroy(IntPtr media); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_orientation", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetOrientation(IntPtr handle, out Orientation orientation); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_date_taken", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetDateTaken(IntPtr handle, out IntPtr dateTaken); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_burst_id", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetBurstId(IntPtr handle, out IntPtr burstId); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_exposure_time", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetExposureTime(IntPtr handle, out IntPtr exposureTime); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_fnumber", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetFNumber(IntPtr handle, out double fNumber); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_iso", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetISO(IntPtr handle, out int iso); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_model", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetModel(IntPtr handle, out IntPtr model); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_is_burst_shot", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError IsBurstShot(IntPtr handle, out bool isBurstShot); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_media_id", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetMediaId(IntPtr handle, out IntPtr mediaId); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_width", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetWidth(IntPtr handle, out int width); + + [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_height", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetHeight(IntPtr handle, out int width); + } +} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.ImageInformation.cs b/src/Tizen.Content.MediaContent/Interop/Interop.ImageInformation.cs deleted file mode 100755 index cbcfffb..0000000 --- a/src/Tizen.Content.MediaContent/Interop/Interop.ImageInformation.cs +++ /dev/null @@ -1,91 +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.Runtime.InteropServices; -using Tizen.Content.MediaContent; - -internal static partial class Interop -{ - internal static partial class ImageInformation - { - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_destroy", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Destroy(IntPtr media); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_clone", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Clone(out SafeImageInformationHandle dst, SafeImageInformationHandle src); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_orientation", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetOrientation(SafeImageInformationHandle imageInformationHandle, out MediaContentOrientation orientation); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_date_taken", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetDateTaken(SafeImageInformationHandle imageInformationHandle, out IntPtr dateTaken); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_burst_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetBurstId(SafeImageInformationHandle imageInformationHandle, out IntPtr burstId); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_exposure_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetExposureTime(SafeImageInformationHandle imageInformationHandle, out IntPtr exposureTime); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_fnumber", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetFNumber(SafeImageInformationHandle imageInformationHandle, out double fNumber); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_iso", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetISO(SafeImageInformationHandle imageInformationHandle, out int iso); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_model", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetModel(SafeImageInformationHandle imageInformationHandle, out IntPtr model); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_is_burst_shot", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError IsBurstShot(SafeImageInformationHandle imageInformationHandle, out bool isBurstShot); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_set_orientation", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetOrientation(SafeImageInformationHandle imageInformationHandle, MediaContentOrientation orientation); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_media_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetMediaId(SafeImageInformationHandle imageInformationHandle, out IntPtr mediaId); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_width", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetWidth(SafeImageInformationHandle imageInformationHandle, out int width); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_get_height", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetHeight(SafeImageInformationHandle imageInformationHandle, out int width); - - [DllImport(Libraries.MediaContent, EntryPoint = "image_meta_update_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError UpdateToDB(IntPtr imageInformationHandle); - - internal sealed class SafeImageInformationHandle : SafeHandle - { - public SafeImageInformationHandle() - : base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return this.handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - ImageInformation.Destroy(this.handle); - this.SetHandle(IntPtr.Zero); - return true; - } - } - } -} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.Libc.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Libc.cs index c9e7ff8..825599e 100755 --- a/src/Tizen.Content.MediaContent/Interop/Interop.Libc.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Libc.cs @@ -14,7 +14,6 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.Libraries.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Libraries.cs index a2d161e..67fdba7 100755 --- a/src/Tizen.Content.MediaContent/Interop/Interop.Libraries.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Libraries.cs @@ -14,13 +14,11 @@ * limitations under the License. */ - internal static partial class Interop { internal static partial class Libraries { public const string MediaContent = "libcapi-content-media-content.so.0"; - public const string Glib = "libglib-2.0.so.0"; public const string Libc = "libc.so.6"; } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaContent.cs b/src/Tizen.Content.MediaContent/Interop/Interop.MediaContent.cs index 02205f1..a90817c 100755 --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaContent.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.MediaContent.cs @@ -14,12 +14,10 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; using Tizen.Content.MediaContent; - internal static partial class Interop { internal static partial class Content @@ -36,19 +34,22 @@ internal static partial class Interop [DllImport(Libraries.MediaContent, EntryPoint = "media_content_cancel_scan_folder")] internal static extern MediaContentError CancelScanFolder(string folderPath); - // Callback [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void MediaScanCompletedCallback(MediaContentError error, IntPtr data); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void MediaContentDBUpdatedCallback(MediaContentError error, int pid, MediaContentUpdateItemType updateItem, MediaContentDBUpdateType updateType, MediaContentType mediaType, string uuid, string filePath, string mimeType, IntPtr data); + internal delegate void MediaContentDBUpdatedCallback(MediaContentError error, int pid, ItemType updateItem, + OperationType updateType, MediaType mediaType, string uuid, string filePath, string mimeType, IntPtr data); [DllImport(Libraries.MediaContent, EntryPoint = "media_content_scan_folder")] - internal static extern MediaContentError ScanFolder(string folderPath, bool is_recursive, MediaScanCompletedCallback scanCompletedCallback, IntPtr userData); + internal static extern MediaContentError ScanFolder(string folderPath, + bool recursive, MediaScanCompletedCallback scanCompletedCallback, IntPtr userData = default(IntPtr)); [DllImport(Libraries.MediaContent, EntryPoint = "media_content_add_db_updated_cb")] - internal static extern MediaContentError AddDbUpdatedCb(MediaContentDBUpdatedCallback mediaContentDBUpdatedCallback, IntPtr userData, out IntPtr noti_handle); + internal static extern MediaContentError AddDbUpdatedCb(MediaContentDBUpdatedCallback mediaContentDBUpdatedCallback, + IntPtr userData, out IntPtr notiHandle); [DllImport(Libraries.MediaContent, EntryPoint = "media_content_remove_db_updated_cb")] - internal static extern MediaContentError RemoveDbUpdatedCb(IntPtr noti_handle); + internal static extern MediaContentError RemoveDbUpdatedCb(IntPtr notiHandle); } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaContentHandle.cs b/src/Tizen.Content.MediaContent/Interop/Interop.MediaContentHandle.cs new file mode 100644 index 0000000..09c8481 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Interop/Interop.MediaContentHandle.cs @@ -0,0 +1,46 @@ +/* + * 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.Runtime.InteropServices; +using Tizen; +using Tizen.Content.MediaContent; + +internal static partial class Interop +{ + internal abstract class MediaContentCriticalHandle : CriticalHandle + { + public MediaContentCriticalHandle() : base(IntPtr.Zero) + { + } + + public override bool IsInvalid => handle == IntPtr.Zero; + + protected override bool ReleaseHandle() + { + var result = DestroyHandle(); + if (result != MediaContentError.None) + { + Log.Error(GetType().Name, $"Failed to destroy handle : {result}"); + return false; + } + + return true; + } + + protected abstract MediaContentError DestroyHandle(); + } +} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaGroup.cs b/src/Tizen.Content.MediaContent/Interop/Interop.MediaGroup.cs deleted file mode 100755 index c879bcc..0000000 --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaGroup.cs +++ /dev/null @@ -1,81 +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.Runtime.InteropServices; -using Tizen.Content.MediaContent; - -internal static partial class Interop -{ - internal static partial class Group - { - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_album_count_from_db")] - internal static extern MediaContentError MediaAlbumGetAlbumCountFromDb(IntPtr filter, out int album_count); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_media_count_from_db")] - internal static extern MediaContentError MediaAlbumGetMediaCountFromDb(int album_id, IntPtr filter, out int media_count); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_destroy")] - internal static extern MediaContentError MediaAlbumDestroy(IntPtr album); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_clone")] - internal static extern MediaContentError MediaAlbumClone(out IntPtr dst, IntPtr src); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_album_id")] - internal static extern MediaContentError MediaAlbumGetAlbumId(IntPtr album, out int album_id); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_name")] - internal static extern MediaContentError MediaAlbumGetName(IntPtr album, out IntPtr album_name); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_artist")] - internal static extern MediaContentError MediaAlbumGetArtist(IntPtr album, out IntPtr artist); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_album_art")] - internal static extern MediaContentError MediaAlbumGetAlbumArt(IntPtr album, out IntPtr album_art); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_get_album_from_db")] - internal static extern MediaContentError MediaAlbumGetAlbumFromDb(int album_id, out IntPtr album); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_group_get_group_count_from_db")] - internal static extern MediaContentError GetGroupCountFromDb(IntPtr filter, MediaGroupType group, out int group_count); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_group_get_media_count_from_db")] - internal static extern MediaContentError GetMediaCountFromDb(string group_name, MediaGroupType group, IntPtr filter, out int media_count); - - //Callbacks - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaInfoCallback(IntPtr mediaInformation, IntPtr data); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaGroupCallback(string groupName, IntPtr data); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaAlbumCallback(IntPtr albumHandle, IntPtr data); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_foreach_album_from_db")] - internal static extern MediaContentError MediaAlbumForeachAlbumFromDb(IntPtr filter, MediaAlbumCallback callback, IntPtr user_data); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_album_foreach_media_from_db")] - internal static extern MediaContentError MediaAlbumForeachMediaFromDb(int albumId, IntPtr filter, MediaInfoCallback callback, IntPtr user_data); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_group_foreach_group_from_db")] - internal static extern MediaContentError ForeachGroupFromDb(IntPtr filter, MediaGroupType group, MediaGroupCallback callback, IntPtr user_data); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_group_foreach_media_from_db")] - internal static extern MediaContentError ForeachMediaFromDb(string groupName, MediaGroupType group, IntPtr filter, MediaInfoCallback callback, IntPtr user_data); - } -} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs b/src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs new file mode 100644 index 0000000..244e98a --- /dev/null +++ b/src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs @@ -0,0 +1,236 @@ +/* + * 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.Runtime.InteropServices; +using Tizen.Content.MediaContent; + +internal static partial class Interop +{ + internal static partial class MediaInfo + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ThumbnailCompletedCallback(MediaContentError error, string filePath, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void FaceDetectionCompletedCallback(MediaContentError error, int count, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void InsertCompletedCallback(MediaContentError error, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void InsertBurstShotCompletedCallback(MediaContentError error, IntPtr userData); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_insert_to_db")] + internal static extern MediaContentError Insert(string filePath, out MediaInfoHandle info); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_insert_batch_to_db")] + internal static extern MediaContentError BatchInsert(string[] filePathArray, int arrayLength, + InsertCompletedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_insert_burst_shot_to_db")] + internal static extern MediaContentError BurstShotInsert(string[] filePathArray, int arrayLength, + InsertBurstShotCompletedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_delete_from_db")] + internal static extern MediaContentError Delete(string mediaId); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_delete_batch_from_db")] + internal static extern MediaContentError BatchDelete(FilterHandle filter); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_destroy")] + internal static extern MediaContentError Destroy(IntPtr handle); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_count_from_db")] + internal static extern MediaContentError GetMediaCount(FilterHandle filter, out int mediaCount); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_foreach_media_from_db")] + internal static extern MediaContentError ForeachMedia(FilterHandle filter, Common.ItemCallback callback, + IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_tag_count_from_db")] + internal static extern MediaContentError GetTagCount(string mediaId, FilterHandle filter, out int tagCount); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_foreach_tag_from_db")] + internal static extern MediaContentError ForeachTags(string mediaId, FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_bookmark_count_from_db")] + internal static extern MediaContentError GetBookmarkCount(string mediaId, FilterHandle filter, out int bookmarkCount); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_foreach_bookmark_from_db")] + internal static extern MediaContentError ForeachBookmarks(string mediaId, FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_face_count_from_db")] + internal static extern MediaContentError GetFaceCount(string mediaId, FilterHandle filter, out int bookmarkCount); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_foreach_face_from_db")] + internal static extern MediaContentError ForeachFaces(string mediaId, FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_image")] + internal static extern MediaContentError GetImage(MediaInfoHandle handle, out IntPtr imageHandle); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_video")] + internal static extern MediaContentError GetVideo(MediaInfoHandle handle, out IntPtr videoHandle); + + [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_media_id")] + internal static extern MediaContentError GetMediaId(MediaInfoHandle mediaInformationHandle, out IntPtr mediaId); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_file_path")] + internal static extern MediaContentError GetFilePath(MediaInfoHandle mediaInformationHandle, out IntPtr filePath); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_display_name")] + internal static extern MediaContentError GetDisplayName(MediaInfoHandle mediaInformationHandle, out IntPtr name); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_type")] + internal static extern MediaContentError GetMediaType(MediaInfoHandle mediaInformationHandle, out MediaType type); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_mime_type")] + internal static extern MediaContentError GetMimeType(MediaInfoHandle mediaInformationHandle, out IntPtr mimeType); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_size")] + internal static extern MediaContentError GetSize(MediaInfoHandle mediaInformationHandle, out long size); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_added_time")] + internal static extern MediaContentError GetAddedTime(MediaInfoHandle handle, out IntPtr posixTime); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_modified_time")] + internal static extern MediaContentError GetModifiedTime(MediaInfoHandle handle, out IntPtr posixTime); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_timeline")] + internal static extern MediaContentError GetTimeline(MediaInfoHandle handle, out IntPtr posixTime); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_thumbnail_path")] + internal static extern MediaContentError GetThumbnailPath(MediaInfoHandle mediaInformationHandle, out IntPtr filePath); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_description")] + internal static extern MediaContentError GetDescription(MediaInfoHandle mediaInformationHandle, out IntPtr description); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_longitude")] + internal static extern MediaContentError GetLongitude(MediaInfoHandle mediaInformationHandle, out double longitude); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_latitude")] + internal static extern MediaContentError GetLatitude(MediaInfoHandle mediaInformationHandle, out double latitude); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_altitude")] + internal static extern MediaContentError GetAltitude(MediaInfoHandle mediaInformationHandle, out double altitude); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_weather")] + internal static extern MediaContentError GetWeather(MediaInfoHandle mediaInformationHandle, out IntPtr weather); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_rating")] + internal static extern MediaContentError GetRating(MediaInfoHandle mediaInformationHandle, out int rating); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_favorite")] + internal static extern MediaContentError GetFavorite(MediaInfoHandle mediaInformationHandle, out bool favorite); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_provider")] + internal static extern MediaContentError GetProvider(MediaInfoHandle mediaInformationHandle, out IntPtr provider); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_title")] + internal static extern MediaContentError GetTitle(MediaInfoHandle mediaInformationHandle, out IntPtr title); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_category")] + internal static extern MediaContentError GetCategory(MediaInfoHandle mediaInformationHandle, out IntPtr category); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_location_tag")] + internal static extern MediaContentError GetLocationTag(MediaInfoHandle mediaInformationHandle, out IntPtr locationTag); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_age_rating")] + internal static extern MediaContentError GetAgeRating(MediaInfoHandle mediaInformationHandle, out IntPtr ageRating); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_storage_id")] + internal static extern MediaContentError GetStorageId(MediaInfoHandle mediaInformationHandle, out IntPtr storageId); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_is_drm")] + internal static extern MediaContentError IsDrm(MediaInfoHandle mediaInformationHandle, out bool isDrm); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_storage_type")] + internal static extern MediaContentError GetStorageType(MediaInfoHandle mediaInformationHandle, out StorageType storageType); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_from_db")] + internal static extern MediaContentError GetMediaFromDB(string mediaId, out MediaInfoHandle handle); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_weather")] + internal static extern MediaContentError SetWeather(MediaInfoHandle mediaInformationHandle, string weather); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_favorite")] + internal static extern MediaContentError SetFavorite(MediaInfoHandle mediaInformationHandle, bool favorite); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_provider")] + internal static extern MediaContentError SetProvider(MediaInfoHandle mediaInformationHandle, string provider); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_category")] + internal static extern MediaContentError SetCategory(MediaInfoHandle mediaInformationHandle, string category); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_location_tag")] + internal static extern MediaContentError SetLocationTag(MediaInfoHandle mediaInformationHandle, string locationTag); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_age_rating")] + internal static extern MediaContentError SetAgeRating(MediaInfoHandle mediaInformationHandle, string ageRating); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_update_to_db")] + internal static extern MediaContentError UpdateToDB(MediaInfoHandle mediaInformationHandle); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_move_to_db")] + internal static extern MediaContentError MoveToDB(MediaInfoHandle mediaInformationHandle, string dstPath); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_create_thumbnail")] + internal static extern MediaContentError CreateThumbnail(MediaInfoHandle handle, + ThumbnailCompletedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_cancel_thumbnail")] + internal static extern MediaContentError CancelThumbnail(MediaInfoHandle mediaInformationHandle); + + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_start_face_detection")] + internal static extern MediaContentError StartFaceDetection(MediaInfoHandle handle, + FaceDetectionCompletedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_info_cancel_face_detection")] + internal static extern MediaContentError CancelFaceDetection(MediaInfoHandle handle); + } + + internal sealed class MediaInfoHandle : SafeHandle + { + public MediaInfoHandle() + : base(IntPtr.Zero, true) + { + } + + public MediaInfoHandle(IntPtr handle) + : this() + { + SetHandle(handle); + } + + public override bool IsInvalid + { + get { return handle == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + MediaInfo.Destroy(handle); + return true; + } + } +} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaInformation.cs b/src/Tizen.Content.MediaContent/Interop/Interop.MediaInformation.cs deleted file mode 100755 index 5d994fc..0000000 --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaInformation.cs +++ /dev/null @@ -1,287 +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.Runtime.InteropServices; -using Tizen.Content.MediaContent; - -internal static partial class Interop -{ - internal static partial class MediaInformation - { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void MediaThumbnailCompletedCallback(MediaContentError error, string filePath, IntPtr UserData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaTagCallback(IntPtr tagHandle, IntPtr UserData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaBookmarkCallback(IntPtr bookmarkHandle, IntPtr UserData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaFaceCallback(IntPtr bookmarkHandle, IntPtr UserData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void MediaInsertCompletedCallback(MediaContentError error, IntPtr UserData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void MediaInsertBurstShotCompletedCallback(MediaContentError error, IntPtr UserData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaInformationCallback(IntPtr mediaInformationHandle, IntPtr UserData); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_insert_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Insert(string filePath, out SafeMediaInformationHandle info); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_insert_batch_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError BatchInsert(string[] filePathArray, int arrayLength, MediaInsertCompletedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_insert_burst_shot_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError BurstShotInsert(string[] filePathArray, int arrayLength, MediaInsertBurstShotCompletedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_delete_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Delete(string mediaId); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_delete_batch_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError BatchDelete(IntPtr filter); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_destroy", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Destroy(IntPtr mediaInformationHandle); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_clone", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Clone(out SafeMediaInformationHandle dst, IntPtr src); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_count_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetMediaCount(IntPtr filter, out int mediaCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_foreach_media_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAllMedia(IntPtr filter, MediaInformationCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_tag_count_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetTagCount(string mediaId, IntPtr filter, out int tagCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_foreach_tag_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAllTags(string mediaId, IntPtr filter, MediaTagCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_bookmark_count_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetBookmarkCount(string mediaId, IntPtr filter, out int bookmarkCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_foreach_bookmark_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAllBookmarks(string mediaId, IntPtr filter, MediaBookmarkCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_face_count_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetFaceCount(string mediaId, IntPtr filter, out int bookmarkCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_foreach_face_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAllFaces(string mediaId, IntPtr filter, MediaFaceCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_image", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetImage(IntPtr mediaInformationHandle, out Interop.ImageInformation.SafeImageInformationHandle image); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_video", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetVideo(IntPtr mediaInformationHandle, out Interop.VideoInformation.SafeVideoInformationHandle video); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_audio", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAudio(IntPtr mediaInformationHandle, out Interop.AudioInformation.SafeAudioInformationHandle audio); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetMediaId(SafeMediaInformationHandle mediaInformationHandle, out IntPtr mediaId); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_file_path", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetFilePath(SafeMediaInformationHandle mediaInformationHandle, out IntPtr filePath); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_display_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetDisplayName(SafeMediaInformationHandle mediaInformationHandle, out IntPtr name); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_type", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetMediaType(SafeMediaInformationHandle mediaInformationHandle, out MediaContentType type); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_mime_type", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetMimeType(SafeMediaInformationHandle mediaInformationHandle, out IntPtr mimeType); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_size", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetSize(SafeMediaInformationHandle mediaInformationHandle, out long size); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_added_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAddedTime(SafeMediaInformationHandle mediaInformationHandle, out int addedTime); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_modified_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetModifiedTime(SafeMediaInformationHandle mediaInformationHandle, out int time); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_timeline", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetTimeline(SafeMediaInformationHandle mediaInformationHandle, out int time); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_thumbnail_path", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetThumbnailPath(SafeMediaInformationHandle mediaInformationHandle, out IntPtr filePath); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_description", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetDescription(SafeMediaInformationHandle mediaInformationHandle, out IntPtr description); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_longitude", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetLongitude(SafeMediaInformationHandle mediaInformationHandle, out double longitude); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_latitude", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetLatitude(SafeMediaInformationHandle mediaInformationHandle, out double latitude); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_altitude", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAltitude(SafeMediaInformationHandle mediaInformationHandle, out double altitude); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_weather", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetWeather(SafeMediaInformationHandle mediaInformationHandle, out IntPtr weather); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_rating", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetRating(SafeMediaInformationHandle mediaInformationHandle, out int rating); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_favorite", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetFavorite(SafeMediaInformationHandle mediaInformationHandle, out bool favorite); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_author", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAuthor(SafeMediaInformationHandle mediaInformationHandle, out IntPtr author); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_provider", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetProvider(SafeMediaInformationHandle mediaInformationHandle, out IntPtr provider); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_content_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetContentName(SafeMediaInformationHandle mediaInformationHandle, out IntPtr contentName); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_title", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetTitle(SafeMediaInformationHandle mediaInformationHandle, out IntPtr title); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_category", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetCategory(SafeMediaInformationHandle mediaInformationHandle, out IntPtr category); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_location_tag", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetLocationTag(SafeMediaInformationHandle mediaInformationHandle, out IntPtr locationTag); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_age_rating", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAgeRating(SafeMediaInformationHandle mediaInformationHandle, out IntPtr ageRating); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_keyword", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetKeyword(SafeMediaInformationHandle mediaInformationHandle, out IntPtr keyword); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_storage_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetStorageId(SafeMediaInformationHandle mediaInformationHandle, out IntPtr storageId); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_is_drm", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError IsDrm(SafeMediaInformationHandle mediaInformationHandle, out bool isDrm); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_storage_type", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetStorageType(SafeMediaInformationHandle mediaInformationHandle, out ContentStorageType storageType); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_played_count", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetPlayedCount(SafeMediaInformationHandle mediaInformationHandle, out int playedCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_played_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetPlayedAt(SafeMediaInformationHandle mediaInformationHandle, out int playedTime); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_from_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetMediaFromDB(string mediaId, out SafeMediaInformationHandle mediaInformationHandle); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_increase_played_count", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError IncreasePlayedCount(SafeMediaInformationHandle mediaInformationHandle); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_played_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetPlayedAt(SafeMediaInformationHandle mediaInformationHandle); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_display_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetDisplayName(SafeMediaInformationHandle mediaInformationHandle, string displayName); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_description", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetDescription(SafeMediaInformationHandle mediaInformationHandle, string description); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_longitude", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetLongitude(SafeMediaInformationHandle mediaInformationHandle, double longitude); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_latitude", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetLatitude(SafeMediaInformationHandle mediaInformationHandle, double latitude); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_altitude", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetAltitude(SafeMediaInformationHandle mediaInformationHandle, double altitude); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_weather", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetWeather(SafeMediaInformationHandle mediaInformationHandle, string weather); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_rating", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetRating(SafeMediaInformationHandle mediaInformationHandle, int rating); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_favorite", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetFavorite(SafeMediaInformationHandle mediaInformationHandle, bool favorite); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_author", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetAuthor(SafeMediaInformationHandle mediaInformationHandle, string author); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_provider", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetProvider(SafeMediaInformationHandle mediaInformationHandle, string provider); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_content_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetContentName(SafeMediaInformationHandle mediaInformationHandle, string contentName); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_category", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetCategory(SafeMediaInformationHandle mediaInformationHandle, string category); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_location_tag", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetLocationTag(SafeMediaInformationHandle mediaInformationHandle, string locationTag); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_age_rating", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetAgeRating(SafeMediaInformationHandle mediaInformationHandle, string ageRating); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_keyword", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetKeyword(SafeMediaInformationHandle mediaInformationHandle, string keyword); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_update_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError UpdateToDB(IntPtr mediaInformationHandle); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_refresh_metadata_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError RefreshMetadataToDB(string mediaId); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_set_added_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetAddedTime(SafeMediaInformationHandle mediaInformationHandle, int addedTime); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_move_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError MoveToDB(SafeMediaInformationHandle mediaInformationHandle, string dstPath); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_create_thumbnail", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError CreateThumbnail(SafeMediaInformationHandle mediaInformationHandle, MediaThumbnailCompletedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_info_cancel_thumbnail", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError CancelThumbnail(SafeMediaInformationHandle mediaInformationHandle); - - internal sealed class SafeMediaInformationHandle : SafeHandle - { - public SafeMediaInformationHandle(IntPtr handle) - : base(handle, true) - { - } - public SafeMediaInformationHandle() - : base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return this.handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - MediaInformation.Destroy(this.handle); - this.SetHandle(IntPtr.Zero); - return true; - } - } - } -} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaPlaylist.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Playlist.cs old mode 100755 new mode 100644 similarity index 73% rename from src/Tizen.Content.MediaContent/Interop/Interop.MediaPlaylist.cs rename to src/Tizen.Content.MediaContent/Interop/Interop.Playlist.cs index 25a9ccf..4f136eb --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaPlaylist.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Playlist.cs @@ -14,7 +14,6 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; using Tizen.Content.MediaContent; @@ -23,20 +22,27 @@ internal static partial class Interop { internal static partial class Playlist { + [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_create")] + internal static extern MediaContentError Create(out IntPtr handle); + [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_get_playlist_count_from_db")] - internal static extern MediaContentError GetPlaylistCountFromDb(IntPtr filter, out int playlist_count); + internal static extern MediaContentError GetPlaylistCount(FilterHandle filter, out int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_get_media_count_from_db")] - internal static extern MediaContentError GetMediaCountFromDb(int playlist_id, IntPtr filter, out int media_count); + internal static extern MediaContentError GetMediaCountFromDb(int playlistId, + FilterHandle filter, out int count); - [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_insert_to_db")] - internal static extern MediaContentError InsertToDb(string name, out IntPtr playlist); + [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_insert_to_db_v2")] + internal static extern MediaContentError Insert(IntPtr playlist); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_delete_from_db")] - internal static extern MediaContentError DeleteFromDb(int playlist_id); + internal static extern MediaContentError Delete(int id); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_update_to_db_v2")] + internal static extern MediaContentError Update(int id, IntPtr playlist); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_get_playlist_from_db")] - internal static extern MediaContentError GetPlaylistFromDb(int playlist_id, out IntPtr playlist); + internal static extern MediaContentError GetPlaylistFromDb(int id, out IntPtr playlist); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_destroy")] internal static extern MediaContentError Destroy(IntPtr playlist); @@ -45,13 +51,13 @@ internal static partial class Interop internal static extern MediaContentError Clone(out IntPtr dst, IntPtr src); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_get_playlist_id")] - internal static extern MediaContentError GetPlaylistId(IntPtr playlist, out int playlist_id); + internal static extern MediaContentError GetId(IntPtr playlist, out int id); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_get_name")] - internal static extern MediaContentError GetName(IntPtr playlist, out IntPtr playlist_name); + internal static extern MediaContentError GetName(IntPtr playlist, out IntPtr name); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_set_name")] - internal static extern MediaContentError SetName(IntPtr playlist, string playlist_name); + internal static extern MediaContentError SetName(IntPtr playlist, string name); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_get_thumbnail_path")] internal static extern MediaContentError GetThumbnailPath(IntPtr playlist, out IntPtr filePath); @@ -60,37 +66,32 @@ internal static partial class Interop internal static extern MediaContentError SetThumbnailPath(IntPtr playlist, string filePath); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_set_play_order")] - internal static extern MediaContentError SetPlayOrder(IntPtr playlist, int playlist_member_id, int play_order); + internal static extern MediaContentError SetPlayOrder(IntPtr playlist, int memberId, int order); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_add_media")] - internal static extern MediaContentError AddMedia(IntPtr playlist, string media_id); + internal static extern MediaContentError AddMedia(IntPtr playlist, string mediaId); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_remove_media")] - internal static extern MediaContentError RemoveMedia(IntPtr playlist, int playlist_member_id); + internal static extern MediaContentError RemoveMedia(IntPtr playlist, int memberId); - [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_get_play_order")] - internal static extern MediaContentError GetPlayOrder(IntPtr playlist, int playlist_member_id, out int play_order); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_update_to_db")] - internal static extern MediaContentError UpdateToDb(IntPtr playlist); + [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_get_play_order_v2")] + internal static extern MediaContentError GetPlayOrder(int playlistId, int memberId, out int order); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_import_from_file")] - internal static extern MediaContentError ImportFromFile(string playlist_name, string filePath, out IntPtr playlist); + internal static extern MediaContentError ImportFromFile(string path, string name, out IntPtr playlist); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_export_to_file")] internal static extern MediaContentError ExportToFile(IntPtr playlist, string filePath); - //Callbacks - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaPlaylistCallback(IntPtr playListHandle, IntPtr data); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool PlaylistMemberCallback(int playListMemberId, IntPtr mediaInformation, IntPtr data); + internal delegate bool PlaylistMemberCallback(int memberId, IntPtr mediaInfo, IntPtr data); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_foreach_playlist_from_db")] - internal static extern MediaContentError ForeachPlaylistFromDb(IntPtr filter, MediaPlaylistCallback callback, IntPtr user_data); + internal static extern MediaContentError ForeachPlaylistFromDb(FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_foreach_media_from_db")] - internal static extern MediaContentError ForeachMediaFromDb(int playlist_id, IntPtr filter, PlaylistMemberCallback callback, IntPtr user_data); + internal static extern MediaContentError ForeachMediaFromDb(int playlistId, FilterHandle filter, + PlaylistMemberCallback callback, IntPtr userData = default(IntPtr)); } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaStorage.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Storage.cs old mode 100755 new mode 100644 similarity index 65% rename from src/Tizen.Content.MediaContent/Interop/Interop.MediaStorage.cs rename to src/Tizen.Content.MediaContent/Interop/Interop.Storage.cs index b17768e..c3eb7dc --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaStorage.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Storage.cs @@ -14,53 +14,41 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; using Tizen.Content.MediaContent; internal static partial class Interop { - internal static partial class Storage + internal static class Storage { [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_get_storage_info_from_db")] - internal static extern MediaContentError GetStorageInfoFromDb(string storage_id, out IntPtr storage); + internal static extern MediaContentError GetStorageInfoFromDb(string id, out IntPtr storage); [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_get_storage_count_from_db")] - internal static extern MediaContentError GetStorageCountFromDb(IntPtr filter, out int storage_count); + internal static extern MediaContentError GetStorageCountFromDb(FilterHandle filter, out int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_get_media_count_from_db")] - internal static extern MediaContentError GetMediaCountFromDb(string storage_id, IntPtr filter, out int media_count); + internal static extern MediaContentError GetMediaCountFromDb(string id, FilterHandle filter, out int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_destroy")] internal static extern MediaContentError Destroy(IntPtr storage); - [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_clone")] - internal static extern MediaContentError Clone(out IntPtr dst, IntPtr src); - [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_get_id")] - internal static extern MediaContentError GetId(IntPtr storage, out IntPtr storage_id); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_get_name")] - internal static extern MediaContentError GetName(IntPtr storage, out IntPtr storage_name); + internal static extern MediaContentError GetId(IntPtr storage, out IntPtr id); [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_get_path")] - internal static extern MediaContentError GetPath(IntPtr storage, out IntPtr storage_path); + internal static extern MediaContentError GetPath(IntPtr storage, out IntPtr path); [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_get_type")] - internal static extern MediaContentError GetType(IntPtr storage, out ContentStorageType storage_type); - - //Callbacks - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaStorageCallback(IntPtr mediaStorageHandle, IntPtr data); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaInfoCallback(IntPtr mediaInformation, IntPtr data); + internal static extern MediaContentError GetType(IntPtr storage, out StorageType type); [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_foreach_storage_from_db")] - internal static extern MediaContentError ForeachStorageFromDb(IntPtr filter, MediaStorageCallback callback, IntPtr user_data); + internal static extern MediaContentError ForeachStorageFromDb(FilterHandle filter, Common.ItemCallback callback, + IntPtr userData = default(IntPtr)); [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_foreach_media_from_db")] - internal static extern MediaContentError ForeachMediaFromDb(string storage_id, IntPtr filter, MediaInfoCallback callback, IntPtr user_data); + internal static extern MediaContentError ForeachMediaFromDb(string id, FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.MediaTag.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Tag.cs old mode 100755 new mode 100644 similarity index 67% rename from src/Tizen.Content.MediaContent/Interop/Interop.MediaTag.cs rename to src/Tizen.Content.MediaContent/Interop/Interop.Tag.cs index 9895b62..596ec94 --- a/src/Tizen.Content.MediaContent/Interop/Interop.MediaTag.cs +++ b/src/Tizen.Content.MediaContent/Interop/Interop.Tag.cs @@ -14,7 +14,6 @@ * limitations under the License. */ - using System; using System.Runtime.InteropServices; using Tizen.Content.MediaContent; @@ -23,56 +22,51 @@ internal static partial class Interop { internal static partial class Tag { + [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_create")] + internal static extern MediaContentError Create(out IntPtr handle); + [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_insert_to_db")] - internal static extern MediaContentError InsertToDb(string tag_name, out IntPtr tag); + internal static extern MediaContentError Insert(string name, out IntPtr handle); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_delete_from_db")] - internal static extern MediaContentError DeleteFromDb(int tag_id); + internal static extern MediaContentError Delete(int tagId); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_update_to_db_v2")] + internal static extern MediaContentError Update(int tagId, IntPtr tag); + + [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_get_tag_from_db")] + internal static extern MediaContentError GetTagFromDb(int tagId, out IntPtr tag); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_get_tag_count_from_db")] - internal static extern MediaContentError GetTagCountFromDb(IntPtr filter, out int tag_count); + internal static extern MediaContentError GetTagCount(FilterHandle filter, out int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_get_media_count_from_db")] - internal static extern MediaContentError GetMediaCountFromDb(int tag_id, IntPtr filter, out int media_count); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_clone")] - internal static extern MediaContentError Clone(out IntPtr dst, IntPtr src); + internal static extern MediaContentError GetMediaCount(int tagId, FilterHandle filter, out int count); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_destroy")] internal static extern MediaContentError Destroy(IntPtr tag); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_get_tag_id")] - internal static extern MediaContentError GetTagId(IntPtr tag, out int tag_id); + internal static extern MediaContentError GetId(IntPtr tag, out int value); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_get_name")] - internal static extern MediaContentError GetName(IntPtr tag, out IntPtr tag_name); + internal static extern MediaContentError GetName(IntPtr tag, out IntPtr value); - [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_get_tag_from_db")] - internal static extern MediaContentError GetTagFromDb(int tag_id, out IntPtr tag); + [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_set_name")] + internal static extern MediaContentError SetName(IntPtr tag, string value); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_add_media")] - internal static extern MediaContentError AddMedia(IntPtr tag, string media_id); + internal static extern MediaContentError AddMedia(IntPtr tag, string mediaId); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_remove_media")] - internal static extern MediaContentError RemoveMedia(IntPtr tag, string media_id); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_set_name")] - internal static extern MediaContentError SetName(IntPtr tag, string tag_name); - - [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_update_to_db")] - internal static extern MediaContentError UpdateToDb(IntPtr tag); - - //Callbacks - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaInfoCallback(IntPtr mediaInformation, IntPtr data); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool MediaTagCallback(IntPtr tag, IntPtr data); + internal static extern MediaContentError RemoveMedia(IntPtr tag, string mediaId); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_foreach_tag_from_db")] - internal static extern MediaContentError ForeachTagFromDb(IntPtr filter, MediaTagCallback callback, IntPtr user_data); + internal static extern MediaContentError ForeachTagFromDb(FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); [DllImport(Libraries.MediaContent, EntryPoint = "media_tag_foreach_media_from_db")] - internal static extern MediaContentError ForeachMediaFromDb(int tag_id, IntPtr filter, MediaInfoCallback callback, IntPtr user_data); + internal static extern MediaContentError ForeachMediaFromDb(int tagId, FilterHandle filter, + Common.ItemCallback callback, IntPtr userData = default(IntPtr)); } } diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.VideoInfo.cs b/src/Tizen.Content.MediaContent/Interop/Interop.VideoInfo.cs new file mode 100644 index 0000000..4fc7f94 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Interop/Interop.VideoInfo.cs @@ -0,0 +1,67 @@ +/* + * 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.Runtime.InteropServices; +using Tizen.Content.MediaContent; + +internal static partial class Interop +{ + internal static partial class VideoInfo + { + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError Destroy(IntPtr handle); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_album", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetAlbum(IntPtr handle, out IntPtr albumName); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_artist", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetArtist(IntPtr handle, out IntPtr artistName); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_album_artist", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetAlbumArtist(IntPtr handle, out IntPtr albumArtistName); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_genre", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetGenre(IntPtr handle, out IntPtr genreName); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_composer", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetComposer(IntPtr handle, out IntPtr composerName); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_year", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetYear(IntPtr handle, out IntPtr year); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_recorded_date", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetRecordedDate(IntPtr handle, out IntPtr recordedDate); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_copyright", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetCopyright(IntPtr handle, out IntPtr copyright); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_track_num", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetTrackNum(IntPtr handle, out IntPtr trackNum); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_bit_rate", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetBitRate(IntPtr handle, out int bitRate); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_duration", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetDuration(IntPtr handle, out int duration); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_width", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetWidth(IntPtr handle, out int width); + + [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_height", CallingConvention = CallingConvention.Cdecl)] + internal static extern MediaContentError GetHeight(IntPtr handle, out int width); + } +} diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.VideoInformation.cs b/src/Tizen.Content.MediaContent/Interop/Interop.VideoInformation.cs deleted file mode 100755 index 8138990..0000000 --- a/src/Tizen.Content.MediaContent/Interop/Interop.VideoInformation.cs +++ /dev/null @@ -1,115 +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.Runtime.InteropServices; -using Tizen.Content.MediaContent; - -internal static partial class Interop -{ - internal static partial class VideoInformation - { - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_destroy", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Destroy(IntPtr media); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_clone", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError Clone(out SafeVideoInformationHandle dst, SafeVideoInformationHandle src); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_media_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetMediaId(SafeVideoInformationHandle videoInformationHandle, out IntPtr mediaId); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_album", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAlbum(SafeVideoInformationHandle videoInformationHandle, out IntPtr albumName); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_artist", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetArtist(SafeVideoInformationHandle videoInformationHandle, out IntPtr artistName); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_album_artist", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetAlbumArtist(SafeVideoInformationHandle videoInformationHandle, out IntPtr albumArtistName); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_genre", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetGenre(SafeVideoInformationHandle videoInformationHandle, out IntPtr genreName); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_composer", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetComposer(SafeVideoInformationHandle videoInformationHandle, out IntPtr composerName); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_year", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetYear(SafeVideoInformationHandle videoInformationHandle, out IntPtr year); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_recorded_date", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetRecordedDate(SafeVideoInformationHandle videoInformationHandle, out IntPtr recordedDate); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_copyright", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetCopyright(SafeVideoInformationHandle videoInformationHandle, out IntPtr copyright); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_track_num", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetTrackNum(SafeVideoInformationHandle videoInformationHandle, out IntPtr trackNum); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_bit_rate", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetBitRate(SafeVideoInformationHandle videoInformationHandle, out int bitRate); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_duration", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetDuration(SafeVideoInformationHandle videoInformationHandle, out int duration); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_width", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetWidth(SafeVideoInformationHandle videoInformationHandle, out int width); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_height", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetHeight(SafeVideoInformationHandle videoInformationHandle, out int width); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_played_count", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetPlayedCount(SafeVideoInformationHandle videoInformationHandle, out int playedCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_played_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetPlayedTime(SafeVideoInformationHandle videoInformationHandle, out int playedTime); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_get_played_position", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError GetPlayedPosition(SafeVideoInformationHandle videoInformationHandle, out int playedPosition); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_set_played_count", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetPlayedCount(SafeVideoInformationHandle videoInformationHandle, int playedCount); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_set_played_time", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetPlayedTime(SafeVideoInformationHandle videoInformationHandle, int playedTime); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_set_played_position", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError SetPlayedPosition(SafeVideoInformationHandle videoInformationHandle, int playedPosition); - - [DllImport(Libraries.MediaContent, EntryPoint = "video_meta_update_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern MediaContentError UpdateToDB(IntPtr videoInformationHandle); - - internal sealed class SafeVideoInformationHandle : SafeHandle - { - public SafeVideoInformationHandle() - : base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return this.handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - VideoInformation.Destroy(this.handle); - this.SetHandle(IntPtr.Zero); - return true; - } - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj index 5ed2f1f..60809fb 100644 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Album.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Album.cs index 3763483..659c3fa 100755 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Album.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Album.cs @@ -1,224 +1,69 @@ -/* -* 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. -*/ - - +/* + * 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.Runtime.InteropServices; -using System.Threading.Tasks; namespace Tizen.Content.MediaContent { /// - /// An album is a logical collection or grouping of related audio files. It is also used for filtering media items. - /// The Media Album API allows to manage media albums which contains all video and audio items from the same album. + /// Represents a logical collection grouping of related media info. /// - public class Album : ContentCollection + /// + public class Album { - private IntPtr _albumHandle = IntPtr.Zero; - - private IntPtr Handle + internal Album(IntPtr handle) { - get - { - if (_albumHandle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(Album)); - } + Id = InteropHelper.GetValue(handle, Interop.Album.GetId); - return _albumHandle; - } + Artist = InteropHelper.GetString(handle, Interop.Album.GetArtist); + AlbumArtPath = InteropHelper.GetString(handle, Interop.Album.GetAlbumArt); + Name = InteropHelper.GetString(handle, Interop.Album.GetName); } - /// - /// The media album ID - /// - /// 3 - public int Id - { - get - { - int id = 0; - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumGetAlbumId(Handle, out id), "Failed to get value"); - - return id; - } - } + internal static Album FromHandle(IntPtr handle) => new Album(handle); /// - /// The name of the media artist - /// If the media content has no album info, the property returns empty string. + /// Get the id of the album. /// - /// 3 - public string Artist - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumGetArtist(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } + /// The unique id of the album. + public int Id { get; } /// - /// The path of the media album art + /// Gets the artist name of the album. /// - /// 3 - public string Art - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumGetAlbumArt(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } + /// The artist name. + public string Artist { get; } /// - /// The name of the media album - /// If the media content has no album info, the property returns empty string. + /// Gets the path to the album art. /// - /// 3 - public string Name - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumGetName(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - internal Album(IntPtr handle) - { - _albumHandle = handle; - } + /// The path to the album art. + public string AlbumArtPath { get; } /// - /// Gets the number of MediaInformation Items for the given album present in the media database. - /// If NULL is passed to the filter, no filtering is applied. + /// Gets the name of the album. /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// The number of media contents matching the filter passed - public override int GetMediaInformationCount(ContentFilter filter) - { - int mediaCount = 0; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumGetMediaCountFromDb(Id, handle, out mediaCount), "Failed to get count"); - - return mediaCount; - } - - public override void Dispose() - { - if (_albumHandle != IntPtr.Zero) - { - Interop.Group.MediaAlbumDestroy(_albumHandle); - _albumHandle = IntPtr.Zero; - } - } + /// The album name. + public string Name { get; } /// - /// Iterates through the media files with a filter in the given media album from the media database. - /// This function gets all media files associated with the given media album and meeting desired filter option. - /// If NULL is passed to the filter, no filtering is applied. + /// Returns a string representation of the album. /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// List of content media items matching the passed filter - public override IEnumerable GetMediaInformations(ContentFilter filter) - { - List mediaContents = new List(); - - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - Interop.Group.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) => - { - Interop.MediaInformation.SafeMediaInformationHandle newHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone"); - - MediaContentType type; - Interop.MediaInformation.GetMediaType(newHandle, out type); - if (type == MediaContentType.Image) - { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information"); - - mediaContents.Add(new ImageInformation(imageInfo, newHandle)); - } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information"); - - mediaContents.Add(new AudioInformation(audioInfo, newHandle)); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information"); - - mediaContents.Add(new VideoInformation(videoInfo, newHandle)); - } - else if (type == MediaContentType.Others) - { - mediaContents.Add(new MediaInformation(newHandle)); - } - - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumForeachMediaFromDb(Id, handle, callback, IntPtr.Zero), "Failed to get information"); - - return mediaContents; - } + /// A string representation of the current album. + public override string ToString() => + $"Id={Id}, Name={Name}, Artist={Artist}, AlbumArtPath={AlbumArtPath}"; } } diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AlbumCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AlbumCommand.cs new file mode 100644 index 0000000..e2a2037 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AlbumCommand.cs @@ -0,0 +1,195 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Provides commands to manage albums in the database. + /// + /// + public class AlbumCommand : MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + public AlbumCommand(MediaDatabase database) : base(database) + { + } + + /// + /// Retrieves the number of albums. + /// + /// The number of albums. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count() + { + return Count(null); + } + + /// + /// Retrieves the number of albums with . + /// + /// The criteria to use to filter. This value can be null. + /// The number of albums. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count(CountArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Count(Interop.Album.GetAlbumCountFromDb, arguments); + } + + /// + /// Retrieves all the albums. + /// + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select() + { + return Select(null); + } + + /// + /// Retrieves the albums with . + /// + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select(SelectArguments filter) + { + ValidateDatabase(); + + return CommandHelper.Select(filter, Interop.Album.ForeachAlbumFromDb, Album.FromHandle); + } + + /// + /// Retrieves an album with an album id. + /// + /// The id of the album to query with. + /// The if exists, otherwise null. + /// The is disconnected. + /// The has already been disposed of. + /// is equal to or less than zero. + /// An error occurred while executing the command. + public Album Select(int albumId) + { + ValidateDatabase(); + + if (albumId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(albumId), albumId, + "The album id can't be equal to or less than zero."); + } + + IntPtr handle = IntPtr.Zero; + try + { + Interop.Album.GetAlbumFromDb(albumId, out handle).ThrowIfError("Failed to query"); + + return handle == IntPtr.Zero ? null : new Album(handle); + } + finally + { + Interop.Album.Destroy(handle); + } + } + + /// + /// Retrieves the number of media info that belongs to the album. + /// + /// The id of the album to query with. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// is equal to or less than zero. + /// An error occurred while executing the command. + public int CountMember(int albumId) + { + return CountMember(albumId, null); + } + + /// + /// Retrieves the number of media info that belongs to the album with .. + /// + /// The id of the album to count media. + /// The criteria to use to filter. This value can be null. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// is equal to or less than zero. + /// An error occurred while executing the command. + public int CountMember(int albumId, CountArguments arguments) + { + ValidateDatabase(); + + if (albumId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(albumId), albumId, + "The album id can't be equal to or less than zero."); + } + + return CommandHelper.Count(Interop.Album.GetMediaCountFromDb, albumId, arguments); + } + + /// + /// Retrieves the media info of an album. + /// + /// The id of the album to select media. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader SelectMember(int albumId) + { + return SelectMember(albumId, null); + } + + /// + /// Retrieves the media info of an album with . + /// + /// The id of the album to query with. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader SelectMember(int albumId, SelectArguments filter) + { + ValidateDatabase(); + + if (albumId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(albumId), albumId, + "The album id can't be equal to or less than zero."); + } + + return CommandHelper.SelectMedia(Interop.Album.ForeachMediaFromDb, albumId, filter); + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AudioInfo.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AudioInfo.cs new file mode 100644 index 0000000..3d0db51 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AudioInfo.cs @@ -0,0 +1,144 @@ +/* + * 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.Diagnostics; + +namespace Tizen.Content.MediaContent +{ + /// + /// Represents an audio media information. + /// + public class AudioInfo : MediaInfo + { + internal AudioInfo(Interop.MediaInfoHandle handle) : base(handle) + { + IntPtr audioHandle = IntPtr.Zero; + + try + { + Interop.MediaInfo.GetAudio(handle, out audioHandle).ThrowIfError("Failed to retrieve data"); + + Debug.Assert(audioHandle != IntPtr.Zero); + + Album = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetAlbum); + Artist = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetArtist); + AlbumArtist = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetAlbumArtist); + Genre = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetGenre); + Composer = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetComposer); + Year = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetYear); + DateRecorded = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetRecordedDate); + Copyright = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetCopyright); + TrackNumber = InteropHelper.GetString(audioHandle, Interop.AudioInfo.GetTrackNum); + + BitRate = InteropHelper.GetValue(audioHandle, Interop.AudioInfo.GetBitRate); + BitPerSample = InteropHelper.GetValue(audioHandle, Interop.AudioInfo.GetBitPerSample); + SampleRate = InteropHelper.GetValue(audioHandle, Interop.AudioInfo.GetSampleRate); + Channels = InteropHelper.GetValue(audioHandle, Interop.AudioInfo.GetChannel); + + Duration = InteropHelper.GetValue(audioHandle, Interop.AudioInfo.GetDuration); + } + finally + { + Interop.AudioInfo.Destroy(audioHandle); + } + } + + /// + /// Gets the album name. + /// + /// The album from the metadata. + public string Album { get; } + + /// + /// Gets the artist name. + /// + /// The artist from the metadata. + public string Artist { get; } + + /// + /// Gets the album artist name. + /// + /// The album artist from the metadata. + public string AlbumArtist { get; } + + /// + /// Gets the genre. + /// + /// The genre from the metadata. + public string Genre { get; } + + /// + /// Gets the composer. + /// + /// The composer from the metadata. + public string Composer { get; } + + /// + /// Gets the year. + /// + /// The year from the metadata. + public string Year { get; } + + /// + /// Gets the recorded date. + /// + /// The recorded date from the metadata. + public string DateRecorded { get; } + + /// + /// Gets the copyright. + /// + /// The copyright from the metadata. + public string Copyright { get; } + + /// + /// Gets the track number. + /// + /// The track number from the metadata. + public string TrackNumber { get; } + + /// + /// Gets the bit rate in bit per second. + /// + /// The bit rate in bit per second. + public int BitRate { get; } + + /// + /// Gets the bit per sample. + /// + /// The bit per sample. + public int BitPerSample { get; } + + /// + /// Gets the sample rate in hertz. + /// + /// The sample rate in hertz. + public int SampleRate { get; } + + /// + /// Gets the number of channels. + /// + /// The number of channels. + public int Channels { get; } + + /// + /// Gets the track duration in milliseconds. + /// + /// The track duration in milliseconds. + public int Duration { get; } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AudioInformation.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AudioInformation.cs deleted file mode 100755 index e5fc8d8..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/AudioInformation.cs +++ /dev/null @@ -1,455 +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.Runtime.InteropServices; -using System.Threading.Tasks; -using System.Collections.ObjectModel; - -namespace Tizen.Content.MediaContent -{ - /// - /// AudioContent class API gives the information related to the audio media stored in the device - /// Its purpose is threefold: - /// - to provide information about audio content - /// - to organize audio content logically(grouping) - /// - public class AudioInformation : MediaInformation - { - private readonly Interop.AudioInformation.SafeAudioInformationHandle _handle; - - /// - /// Gets the ID of the media. - /// - /// 3 - public string MediaId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetMediaId(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the album name. - /// If the media content has no album info, the property returns empty string. - /// - /// 3 - public string Album - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetAlbum(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the artist name. - /// If the media content has no album info, the property returns empty string. - /// - /// 3 - public string Artist - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetArtist(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the album artist name. - /// If the media content has no album info, the property returns empty string. - /// - /// 3 - public string AlbumArtist - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetAlbumArtist(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the genre. - /// If the media content has no album info, the property returns empty string. - /// - /// 3 - public string Genre - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetGenre(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the composer name. - /// If the value is an empty string, the property returns "Unknown". - /// If the media content has no album info, the property returns empty string. - /// - /// 3 - public string Composer - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetComposer(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the year. - /// If the media content has no album info, the property returns empty string. - /// - /// 3 - public string Year - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetYear(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the recorded date. - /// - /// 3 - public string RecordedDate - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetRecordedDate(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the copyright. - /// If the media content has no copyright information, the property returns empty string. - /// - /// 3 - public string Copyright - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetCopyright(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the track number. - /// If the media content has no track information, the property returns empty string. - /// - /// 3 - public string TrackNumber - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetTrackNum(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the bitrate in bit per second [bps]. - /// - /// 3 - public int BitRate - { - get - { - int bitrate = 0; - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetBitRate(_handle, out bitrate), "Failed to get value"); - - return bitrate; - } - } - - /// - /// Gets bit per sample. - /// - /// 3 - public int BitPerSample - { - get - { - int bitPerSample = 0; - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetBitPerSample(_handle, out bitPerSample), "Failed to get value"); - - return bitPerSample; - } - } - - /// - /// Gets the sample rate in hz. - /// - /// 3 - public int SampleRate - { - get - { - int sampleRate = 0; - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetSampleRate(_handle, out sampleRate), "Failed to get value"); - - return sampleRate; - } - } - - /// - /// Gets the channel. - /// - /// 3 - public int Channel - { - get - { - int channel = 0; - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetChannel(_handle, out channel), "Failed to get value"); - - return channel; - } - } - - /// - /// Gets the track duration in Milliseconds. - /// - /// 3 - public int Duration - { - get - { - int duration = 0; - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.GetDuration(_handle, out duration), "Failed to get value"); - - return duration; - } - } - - /// - /// Gets the number of MediaBookmark for the passed filter in the given media ID from the media database. - /// If NULL is passed to the filter, no filtering is applied. - /// - /// 3 - /// - /// int count - /// The Filter for matching Bookmarks - public int GetMediaBookmarkCount(ContentFilter filter) - { - int count = 0; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetBookmarkCount(MediaId, handle, out count), "Failed to get count"); - - return count; - } - - /// - /// Returns the MediaBookmarks for the given media info from the media database. - /// If NULL is passed to the filter, no filtering is applied. - /// - /// 3 - /// - /// Task to get all the Bookmarks - /// - /// filter for the Tags - public IEnumerable GetMediaBookmarks(ContentFilter filter) - { - Collection coll = new Collection(); - IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero; - Interop.MediaInformation.MediaBookmarkCallback callback = (IntPtr handle, IntPtr userData) => - { - IntPtr newHandle = IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.MediaBookmark.Clone(out newHandle, handle), "Failed to clone"); - - coll.Add(new MediaBookmark(newHandle)); - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAllBookmarks(MediaId, filterHandle, callback, IntPtr.Zero), "Failed to get value"); - - return coll; - } - - /// - /// Adds a MediaBookmark to the audio - /// - /// 3 - /// Offset of the audio in seconds - /// - /// Task with newly added MediaBookmark instance. - /// - public MediaBookmark AddBookmark(uint offset) - { - MediaBookmark result = null; - ContentManager.Database.Insert(MediaId, offset, null); - ContentFilter bookmarkfilter = new ContentFilter(); - bookmarkfilter.Condition = ContentColumns.Bookmark.Offset + " = " + offset; - IEnumerable bookmarksList = null; - bookmarksList = GetMediaBookmarks(bookmarkfilter); - foreach (MediaBookmark bookmark in bookmarksList) - { - if (bookmark.Offset == offset) - { - result = bookmark; - break; - } - } - - bookmarkfilter.Dispose(); - return result; - } - - /// - /// Deletes a MediaBookmark item from the media database. - /// - /// 3 - /// The MediaBookmark instance to be deleted - public void DeleteBookmark(MediaBookmark bookmark) - { - ContentManager.Database.Delete(bookmark); - } - - internal IntPtr AudioHandle - { - get - { - return _handle.DangerousGetHandle(); - } - } - - internal AudioInformation(Interop.AudioInformation.SafeAudioInformationHandle handle, Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle) - : base(mediaInformationHandle) - { - _handle = handle; - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Bookmark.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Bookmark.cs new file mode 100644 index 0000000..aee5128 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Bookmark.cs @@ -0,0 +1,68 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Represents a media bookmark that allows you to mark interesting moment + /// in media(video and audio) to enable fast searching. + /// + public class Bookmark + { + internal Bookmark(IntPtr handle) + { + Id = InteropHelper.GetValue(handle, Interop.Bookmark.GetId); + ThumbnailPath = InteropHelper.GetString(handle, Interop.Bookmark.GetThumbnailPath); + Offset = InteropHelper.GetValue(handle, Interop.Bookmark.GetMarkedTime); + Name = InteropHelper.GetString(handle, Interop.Bookmark.GetName); + } + + /// + /// Gets the id of the bookmark. + /// + /// The id of the bookmark. + public int Id { get; } + + /// + /// Gets the thumbnail path of the bookmark. + /// + /// The thumbnail path of the bookmark. + public string ThumbnailPath { get; } + + /// + /// Gets the offset in milliseconds. + /// + /// The offset of the bookmark in media in milliseconds. + public int Offset { get; } + + /// + /// Gets the name of the bookmark. + /// + /// The name of the bookmark. + public string Name { get; } + + internal static Bookmark FromHandle(IntPtr handle) => new Bookmark(handle); + + /// + /// Returns a string representation of the bookmark. + /// + /// A string representation of the current bookmark. + public override string ToString() => + $"Id={Id}, Name={Name}, ThumbnailPath={ThumbnailPath}, Offset={Offset}"; + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookmarkCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookmarkCommand.cs new file mode 100644 index 0000000..fd13fc9 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookmarkCommand.cs @@ -0,0 +1,208 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Provides commands to manage bookmarks in database. + /// + /// + public class BookmarkCommand : MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + public BookmarkCommand(MediaDatabase database) : base(database) + { + } + + /// + /// Retrieves the number of bookmarks. + /// + /// The number of bookmarks. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count() + { + return Count(null); + } + + /// + /// Retrieves the number of bookmarks with . + /// + /// The criteria to use to filter. This value can be null. + /// The number of bookmarks. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count(CountArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Count(Interop.Bookmark.GetCount, arguments); + } + + /// + /// Inserts new bookmark into the database with the specified media and offset. + /// + /// http://tizen.org/privilege/content.write + /// The media id to be associated with. + /// The time offset in milliseconds. + /// The instance that contains the record information inserted. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// The caller has no required privilege. + public Bookmark Insert(string mediaId, int offset) + { + return Insert(mediaId, offset, null); + } + + /// + /// Inserts new bookmark into the database with the specified media id, offset and name. + /// + /// http://tizen.org/privilege/content.write + /// The media id to be associated with. + /// The time offset in milliseconds. + /// The name of the bookmark. This value can be null. + /// The instance that contains the record information inserted. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// The caller has no required privilege. + public Bookmark Insert(string mediaId, int offset, string name) + { + return Insert(mediaId, offset, name, null); + } + + /// + /// Inserts new bookmark into the database with the specified media id, offset, name and thumbnail path. + /// + /// http://tizen.org/privilege/content.write + /// + /// Thumbnail may be useful only when the media is video. + /// + /// The media id to be associated with. + /// The time offset in milliseconds. + /// The name of the bookmark. This value can be null. + /// The thumbnail path of the bookmark. This value can be null. + /// The instance that contains the record information inserted. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// The caller has no required privilege. + public Bookmark Insert(string mediaId, int offset, string name, string thumbnailPath) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + Interop.Bookmark.Create(mediaId, offset, out var handle).ThrowIfError("Failed to insert new bookmark"); + + try + { + Interop.Bookmark.SetName(handle, name).ThrowIfError("Failed to insert new bookmark"); + + if (thumbnailPath != null) + { + Interop.Bookmark.SetThumbnailPath(handle, thumbnailPath). + ThrowIfError("Failed to insert new bookmark"); + } + + Interop.Bookmark.Insert(handle).ThrowIfError("Failed to insert new bookmark"); + + return new Bookmark(handle); + } + finally + { + Interop.Bookmark.Destroy(handle); + } + } + + /// + /// Deletes a bookmark from the database. + /// + /// http://tizen.org/privilege/content.write + /// The bookmark id to delete. + /// true if the matched record was found and deleted, otherwise false. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than zero. + /// The caller has no required privilege. + public bool Delete(int bookmarkId) + { + ValidateDatabase(); + + if (bookmarkId < 0) + { + throw new ArgumentOutOfRangeException(nameof(bookmarkId), bookmarkId, + "Bookmark id shouldn't be negative."); + } + + if (CommandHelper.Count(Interop.Bookmark.GetCount, $"{BookmarkColumns.Id}={bookmarkId}") == 0) + { + return false; + } + + CommandHelper.Delete(Interop.Bookmark.Delete, bookmarkId); + + return true; + } + + + /// + /// Retrieves the bookmarks. + /// + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select() + { + return Select(null); + } + + /// + /// Retrieves the bookmarks with . + /// + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select(SelectArguments filter) + { + ValidateDatabase(); + + return CommandHelper.Select(filter, Interop.Bookmark.ForeachFromDb, Bookmark.FromHandle); + } + + } + +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Columns.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Columns.cs new file mode 100644 index 0000000..d4ae50c --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Columns.cs @@ -0,0 +1,838 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Provides the column names that can be used for Select and Count commands. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static class MediaInfoColumns + { + /// + /// Gets the column name for the id of media. + /// + /// The column name for the id of media. + /// The value type is string. + /// + public static string Id => "MEDIA_ID"; + + /// + /// Gets the column name for the path of media. + /// + /// The column name for the file path of media. + /// The value type is string. + /// + public static string Path => "MEDIA_PATH"; + + /// + /// Gets the column name for display name of media. + /// + /// The column name for the display name of media. + /// The value type is string. + /// + public static string DisplayName => "MEDIA_DISPLAY_NAME"; + + /// + /// Gets the column name for the type of media. + /// + /// The column name for the type of media. + /// + /// The value type is integer. + /// The value should be an integer that is one of values. + /// + /// + public static string MediaType => "MEDIA_TYPE"; + + /// + /// Gets the column name for the mime type of media. + /// + /// The column name for the mime type of media. + /// The value type is string. + /// + public static string MimeType => "MEDIA_MIME_TYPE"; + + /// + /// Gets the column name for the file size of media. + /// + /// The column name for the file size of media. + /// The value type is integer. + /// + public static string FileSize => "MEDIA_SIZE"; + + /// + /// Gets the column name for the date added of media. + /// + /// The column name for the date added of media. + /// + /// The value type is integer. + /// needs to be converted into the unix time. + /// + /// + /// + public static string DateAdded => "MEDIA_ADDED_TIME"; + + /// + /// Gets the column name for the date modified of media. + /// + /// The column name for the date modified of media. + /// + /// The value type is integer. + /// needs to be converted into the unix time. + /// + /// + /// + public static string DateModified => "MEDIA_MODIFIED_TIME"; + + /// + /// Gets the column name for the timeline of media. + /// + /// The column name for the timeline of media. + /// + /// The value type is integer. + /// needs to be converted into the unix time. + /// + /// + /// + public static string Timeline => "MEDIA_TIMELINE"; + + /// + /// Gets the column name for the thumbnail path of media. + /// + /// The column name for the thumbnail path of media. + /// + /// The value type is string. + /// + /// + public static string ThumbnailPath => "MEDIA_THUMBNAIL_PATH"; + + /// + /// Gets the column name for the title of media. + /// + /// The column name for the title of media. + /// + /// The value type is string. + /// + /// + public static string Title => "MEDIA_TITLE"; + + /// + /// Gets the column name for the album of media. + /// + /// The column name for the album of media. + /// + /// The value type is string. + /// + /// + public static string Album => "MEDIA_ALBUM"; + + /// + /// Gets the column name for the artist of media. + /// + /// The column name for the artist of media. + /// + /// The value type is string. + /// + /// + /// + public static string Artist => "MEDIA_ARTIST"; + + /// + /// Gets the column name for the album artist of media. + /// + /// The column name for the album artist of media. + /// + /// The value type is string. + /// + /// + /// + public static string AlbumArtist => "MEDIA_ALBUM_ARTIST"; + + /// + /// Gets the column name for the genre of media. + /// + /// The column name for the genre of media. + /// + /// The value type is string. + /// + /// + /// + public static string Genre => "MEDIA_GENRE"; + + /// + /// Gets the column name for the composer of media. + /// + /// The column name for the composer of media. + /// + /// The value type is string. + /// + /// + /// + public static string Composer => "MEDIA_COMPOSER"; + + /// + /// Gets the column name for the year of media. + /// + /// The column name for the year of media. + /// + /// The value type is string. + /// + /// + /// + public static string Year => "MEDIA_YEAR"; + + /// + /// Gets the column name for the date recorded of media. + /// + /// The column name for the date recorded of media. + /// + /// The value type is string. + /// + /// + /// + public static string DateRecorded => "MEDIA_RECORDED_DATE"; + + /// + /// Gets the column name for the copyright of media. + /// + /// The column name for the copyright of media. + /// + /// The value type is string. + /// + /// + /// + public static string Copyright => "MEDIA_COPYRIGHT"; + + /// + /// Gets the column name for the track number of media. + /// + /// The column name for the track number of media. + /// + /// The value type is string. + /// + /// + /// + public static string TrackNumber => "MEDIA_TRACK_NUM"; + + /// + /// Gets the column name for the description of media. + /// + /// The column name for the description of media. + /// + /// The value type is string. + /// + /// + public static string Description => "MEDIA_DESCRIPTION"; + + /// + /// Gets the column name for the bit rate of media. + /// + /// The column name for the bit rate of media. + /// + /// The value type is integer. + /// + /// + /// + public static string BitRate => "MEDIA_BITRATE"; + + /// + /// Gets the column name for the bit per sample of media. + /// + /// The column name for the bit per sample of media. + /// + /// The value type is integer. + /// + /// + public static string BitPerSample => "MEDIA_BITPERSAMPLE"; + + /// + /// Gets the column name for the sample rate of media. + /// + /// The column name for the sample rate of media. + /// + /// The value type is integer. + /// + /// + public static string SampleRate => "MEDIA_SAMPLERATE"; + + /// + /// Gets the column name for the channels of media. + /// + /// The column name for the channels of media. + /// + /// The value type is integer. + /// + /// + public static string Channels => "MEDIA_CHANNEL"; + + /// + /// Gets the column name for the duration of media. + /// + /// The column name for the duration of media. + /// + /// The value type is integer. + /// + /// + /// + public static string Duration => "MEDIA_DURATION"; + + /// + /// Gets the column name for the longitude of media. + /// + /// The column name for the longitude of media. + /// + /// The value type is real. + /// + /// + public static string Longitude => "MEDIA_LONGITUDE"; + + /// + /// Gets the column name for the latitude of media. + /// + /// The column name for the latitude of media. + /// + /// The value type is real. + /// + /// + public static string Latitude => "MEDIA_LATITUDE"; + + /// + /// Gets the column name for the altitude of media. + /// + /// The column name for the altitude of media. + /// + /// The value type is real. + /// + /// + public static string Altitude => "MEDIA_ALTITUDE"; + + /// + /// Gets the column name for the width of media. + /// + /// The column name for the width of media. + /// + /// The value type is integer. + /// + /// + /// + public static string Width => "MEDIA_WIDTH"; + + /// + /// Gets the column name for the height of media. + /// + /// The column name for the height of media. + /// + /// The value type is integer. + /// + /// + /// + public static string Height => "MEDIA_HEIGHT"; + + /// + /// Gets the column name for the date taken of media. + /// + /// The column name for the date taken of media. + /// + /// The value type is integer. + /// + /// + public static string DateTaken => "MEDIA_DATETAKEN"; + + /// + /// Gets the column name for the orientation of media. + /// + /// The column name for the orientation of media. + /// + /// The value type is integer. + /// The value should be an integer that is one of values. + /// + /// + /// + public static string Orientation => "MEDIA_ORIENTATION"; + + /// + /// Gets the column name for the burst id of media. + /// + /// The column name for the burst id of media. + /// + /// The value type is string. + /// + /// + public static string BurstId => "BURST_ID"; + + /// + /// Gets the column name for the rating of media. + /// + /// The column name for the rating of media. + /// + /// The value type is integer. + /// + /// + public static string Rating => "MEDIA_RATING"; + + /// + /// Gets the column name for the favorite status of media. + /// + /// The column name for the favorite status of media. + /// + /// The value type is integer(1 : true, 0 : false). + /// + /// + public static string Favorite => "MEDIA_FAVOURITE"; + + /// + /// Gets the column name for the provider of media. + /// + /// The column name for the provider of media. + /// + /// The value type is string. + /// + /// + public static string Provider => "MEDIA_PROVIDER"; + + /// + /// Gets the column name for the category of media. + /// + /// The column name for the category of media. + /// + /// The value type is string. + /// + /// + public static string Category => "MEDIA_CATEGORY"; + + + /// + /// Gets the column name for the location tag of media. + /// + /// The column name for the location tag of media. + /// + /// The value type is string. + /// + /// + public static string LocationTag => "MEDIA_LOCATION_TAG"; + + /// + /// Gets the column name for the age rating of media. + /// + /// The column name for the age rating of media. + /// + /// The value type is string. + /// + /// > + public static string AgeRating => "MEDIA_AGE_RATING"; + + /// + /// Gets the column name for the weather information of media. + /// + /// The column name for the weather information of media. + /// + /// The value type is string. + /// + /// + public static string Weather => "MEDIA_WEATHER"; + + /// + /// Gets the column name for the drm of media. + /// + /// The column name for the drm of media. + /// + /// The value type is integer(1 : true, 0 : false). + /// + /// + public static string IsDrm => "MEDIA_IS_DRM"; + + /// + /// Gets the column name for the storage type of media. + /// + /// The column name for the storage type of media. + /// + /// The value type is integer. + /// The value should be an integer that is one of values. + /// + /// + public static string StorageType => "MEDIA_STORAGE_TYPE"; + + /// + /// Gets the column name for the exposure time of media. + /// + /// The column name for the exposure time of media. + /// + /// The value type is integer. + /// + /// + public static string ExposureTime => "MEDIA_EXPOSURE_TIME"; + + /// + /// Gets the column name for the FNumber of media. + /// + /// The column name for the FNumber of media. + /// + /// The value type is integer. + /// + /// + public static string FNumber => "MEDIA_FNUMBER"; + + /// + /// Gets the column name for the iso of media. + /// + /// The column name for the iso of media. + /// + /// The value type is integer. + /// + /// + public static string Iso => "MEDIA_ISO"; + + /// + /// Gets the column name for the model of media. + /// + /// The column name for the model of media. + /// + /// The value type is string. + /// + /// + public static string Model => "MEDIA_MODEL"; + } + + + /// + /// Provides the folder column names that can be used for Select and Count commands. + /// + /// + /// + /// + /// + /// + /// + public static class AlbumColumns + { + /// + /// Gets the column name for the name of album. + /// + /// The column name for the name of album. + /// + /// The value type is string. + /// + /// + public static string Name => "MEDIA_ALBUM"; + + /// + /// Gets the column name for the artist of album. + /// + /// The column name for the artist of album. + /// + /// The value type is string. + /// + /// + public static string Artist => "MEDIA_ARTIST"; + } + + /// + /// Provides the folder column names that can be used for Select and Count commands. + /// + /// + /// + /// + /// + /// + /// + public static class FolderColumns + { + /// + /// Gets the column name for the id of folder. + /// + /// The column name for the id of folder. + /// + /// The value type is string. + /// + /// + public static string Id => "FOLDER_ID"; + + /// + /// Gets the column name for the path of folder. + /// + /// The column name for the path of folder. + /// + /// The value type is string. + /// + /// + public static string Path => "FOLDER_PATH"; + + /// + /// Gets the column name for the name of folder. + /// + /// The column name for the name of folder. + /// + /// The value type is string. + /// + /// + public static string Name => "FOLDER_NAME"; + + /// + /// Gets the column name for the storage type of folder. + /// + /// The column name for the storage type of folder. + /// + /// The value type is integer. + /// The value should be an integer that is one of values. + /// + /// + public static string StorageType => "FOLDER_STORAGE_TYPE"; + } + + /// + /// Provides the playlist column names that can be used for Select and Count commands. + /// + /// + /// + /// + /// + /// + /// + public static class PlaylistColumns + { + /// + /// Gets the column name for the name of playlist. + /// + /// The column name for the name of playlist. + /// + /// The value type is string. + /// + /// + public static string Name => "PLAYLIST_NAME"; + + /// + /// Gets the column name for the id of playlist. + /// + /// The column name for the id of playlist. + /// + /// The value type is integer. + /// + /// + public static string Id => "PLAYLIST_ID"; + + /// + /// Gets the column name for the member order of playlist. + /// + /// The column name for the member order of playlist. + /// + /// The value type is integer. + /// + /// + public static string MemberOrder => "PLAYLIST_MEMBER_ORDER"; + + /// + /// Gets the column name for the number of members of playlist. + /// + /// The column name for the number of members of playlist. + /// + /// The value type is integer. + /// + /// + /// + public static string Count => "PLAYLIST_MEDIA_COUNT"; + } + + /// + /// Provides the tag column names that can be used for . + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static class TagColumns + { + /// + /// Gets the column name for the name of tag. + /// + /// The column name for the name of tag. + /// + /// The value type is string. + /// + /// + public static string Name => "TAG_NAME"; + + /// + /// Gets the column name for the number of media of tag. + /// + /// The column name for the number of media of tag. + /// + /// The value type is integer. + /// + /// + /// + public static string Count => "TAG_MEDIA_COUNT"; + + /// + /// Gets the column name for the id of tag. + /// + /// The column name for the id of tag. + /// + /// The value type is integer. + /// + /// + public static string Id => "TAG_ID"; + } + + /// + /// Provides the bookmark column names that can be used for Select and Count commands. + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static class BookmarkColumns + { + /// + /// Gets the column name for offset of bookmark. + /// + /// The column name for the offset of bookmark. + /// + /// The value type is integer. + /// + /// + public static string Offset => "BOOKMARK_MARKED_TIME"; + + /// + /// Gets the column name for the id of bookmark. + /// + /// The column name for the id of bookmark. + /// + /// The value type is integer. + /// + /// + public static string Id => "BOOKMARK_ID"; + + /// + /// Gets the column name for the name of bookmark. + /// + /// The column name for the name of bookmark. + /// + /// The value type is string. + /// + /// + public static string Name => "BOOKMARK_NAME"; + } + + /// + /// Provides the face info column names that can be used for Select and Count commands. + /// + /// + /// + /// + /// + /// + /// + /// + public static class FaceInfoColumns + { + /// + /// Gets the column name for the tag of face info. + /// + /// The column name for the tag of face info. + /// + /// The value type is string. + /// + /// + public static string Tag => "MEDIA_FACE_TAG"; + + /// + /// Gets the column name for the id of face info. + /// + /// The column name for the id of face info. + /// + /// The value type is string. + /// + /// + public static string Id => "MEDIA_FACE_ID"; + } + + /// + /// Provides the storage column names that can be used for Select and Count commands. + /// + /// + /// + /// + /// + /// + /// + public static class StorageColumns + { + /// + /// Gets the column name for the id of storage. + /// + /// The column name for the id of storage. + /// + /// The value type is string. + /// + /// + public static string Id => "STORAGE_ID"; + + /// + /// Gets the column name for the path of storage. + /// + /// The column name for the path of storage. + /// + /// The value type is string. + /// + /// + public static string Path => "STORAGE_PATH"; + + /// + /// Gets the column name for the type of storage. + /// + /// The column name for the type of storage. + /// + /// The value type is integer. + /// The value should be an integer that is one of values. + /// + /// + public static string Type => "MEDIA_STORAGE_TYPE"; + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/CommandHelper.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/CommandHelper.cs new file mode 100644 index 0000000..b244cf5 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/CommandHelper.cs @@ -0,0 +1,183 @@ +/* + * 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 FilterHandle = Interop.FilterHandle; + +namespace Tizen.Content.MediaContent +{ + internal static class CommandHelper + { + internal delegate MediaContentError CountFunc(FilterHandle filter, out int count); + + internal delegate MediaContentError CountFunc(T param, FilterHandle filter, + out int count); + + internal static int Count(CountFunc countFunc, CountArguments arguments) + { + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + countFunc(filter, out var count).ThrowIfError("Failed to query count"); + return count; + } + } + + internal static int Count(CountFunc countFunc, string filter) + { + return Count(countFunc, new CountArguments { FilterExpression = filter }); + } + + internal static int Count(CountFunc countFunc, T param, CountArguments arguments) + { + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + countFunc(param, filter, out var count).ThrowIfError("Failed to query count"); + return count; + } + } + + internal static void Delete(Func func, T param) + { + func(param).ThrowIfError("Failed to execute the command"); + } + + internal delegate MediaContentError ForeachFunc(T param, FilterHandle filter, + Interop.Common.ItemCallback callback, IntPtr data = default(IntPtr)); + + internal static MediaDataReader SelectMedia(ForeachFunc func, T param, + SelectArguments arguments) + { + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + var items = new List(); + Exception exception = null; + + func(param, filter, (mediaInfoHandle, _) => + { + try + { + items.Add(MediaInfo.FromHandle(mediaInfoHandle)); + return true; + } + catch (Exception e) + { + exception = e; + return false; + } + }).ThrowIfError("Failed to query"); + + if (exception != null) + { + throw exception; + } + + return new MediaDataReader(items); + } + } + + internal delegate MediaContentError ForeachFunc(FilterHandle filter, + Interop.Common.ItemCallback callback, IntPtr data = default(IntPtr)); + + internal static MediaDataReader Select(SelectArguments arguments, + ForeachFunc foreachFunc, + Func factoryFunc) + { + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + Exception caught = null; + var items = new List(); + + foreachFunc(filter, (itemHandle, _) => + { + try + { + items.Add(factoryFunc(itemHandle)); + return true; + } + catch (Exception e) + { + caught = e; + return false; + } + }).ThrowIfError("Failed to execute query"); + + if (caught != null) + { + throw caught; + } + + return new MediaDataReader(items); + } + } + + + internal delegate MediaContentError CloneFunc(out IntPtr output, IntPtr input); + + internal static IntPtr SelectScalar(ForeachFunc foreachFunc, string filterExpression, + CloneFunc cloneFunc) + { + using (var filter = QueryArguments.CreateNativeHandle(filterExpression)) + { + IntPtr handle = IntPtr.Zero; + + foreachFunc(filter, (itemHandle, _) => + { + cloneFunc(out handle, itemHandle); + return false; + }).ThrowIfError("Failed to execute query"); + + return handle; + } + } + + internal delegate MediaContentError ForeachMemberFunc(TParam param, + FilterHandle filter, Interop.Common.ItemCallback callback, IntPtr data = default(IntPtr)); + + internal static MediaDataReader SelectMembers(TParam param, + SelectArguments arguments, ForeachMemberFunc foreachFunc, + Func factoryFunc) + { + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + Exception caught = null; + var items = new List(); + + foreachFunc(param, filter, (itemHandle, _) => + { + try + { + items.Add(factoryFunc(itemHandle)); + + return true; + } + catch (Exception e) + { + caught = e; + return false; + } + }).ThrowIfError("Failed to execute query"); + + if (caught != null) + { + throw caught; + } + + return new MediaDataReader(items); + } + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentCollection.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentCollection.cs deleted file mode 100755 index 2e4ae7e..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentCollection.cs +++ /dev/null @@ -1,50 +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.Threading.Tasks; - -namespace Tizen.Content.MediaContent -{ - public abstract class ContentCollection : IDisposable - { - /// - /// Gets the media count for this content store matching the passed filter - /// - /// 3 - /// the media filter - /// Media count - public abstract int GetMediaInformationCount(ContentFilter filter); - - /// - /// Destroys the unmanaged handles. - /// Call Dispose API once Contentcollection operations are completed. - /// - /// 3 - public abstract void Dispose(); - - /// - /// Gets the media matching the passed filter for this content store, asynchronously - /// - /// 3 - /// The media filter - /// Task with Media Information list - public abstract IEnumerable GetMediaInformations(ContentFilter filter); - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentColumns.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentColumns.cs deleted file mode 100755 index 6c10037..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentColumns.cs +++ /dev/null @@ -1,1130 +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. -*/ - - - -namespace Tizen.Content.MediaContent -{ - /// - /// A ContentColumns class defines the keyword used for filter condition or sorting. - /// - public static class ContentColumns - { - /// - /// Media column set. \n - /// You can use this define to set the condition of media filter and order keyword. - /// - public class Media - { - /// - /// Media UUID - /// - /// 4 - public static string Id - { - get - { - return "MEDIA_ID"; - } - } - - /// - /// Media path - /// - /// 4 - public static string Path - { - get - { - return "MEDIA_PATH"; - } - } - - /// - /// Display name - /// - /// 4 - public static string DisplayName - { - get - { - return "MEDIA_DISPLAY_NAME"; - } - } - - /// - /// The type of media (0-image, 1-video, 2-sound, 3-music, 4-other) - /// - /// 4 - public static string MediaType - { - get - { - return "MEDIA_TYPE"; - } - } - - /// - /// Mime type - /// - /// 4 - public static string MimeType - { - get - { - return "MEDIA_MIME_TYPE"; - } - } - - - /// - /// File size - /// - /// 4 - public static string Size - { - get - { - return "MEDIA_SIZE"; - } - } - - /// - /// Added time - /// - /// 4 - public static string AddedTime - { - get - { - return "MEDIA_ADDED_TIME"; - } - } - - /// - /// Modified time - /// - /// 4 - public static string ModifiedTime - { - get - { - return "MEDIA_MODIFIED_TIME"; - } - } - - /// - /// Timeline. Normally, creation date of media - /// - /// 4 - public static string Timeline - { - get - { - return "MEDIA_TIMELINE"; - } - } - - /// - /// The path of thumbnail - /// - /// 4 - public static string ThumbnailPath - { - get - { - return "MEDIA_THUMBNAIL_PATH"; - } - } - - /// - /// Title - /// - /// 4 - public static string Title - { - get - { - return "MEDIA_TITLE"; - } - } - - /// - /// Album name - /// - /// 4 - public static string Album - { - get - { - return "MEDIA_ALBUM"; - } - } - - /// - /// Artist - /// - /// 4 - public static string Artist - { - get - { - return "MEDIA_ARTIST"; - } - } - - /// - /// Album artist - /// - /// 4 - public static string AlbumArtist - { - get - { - return "MEDIA_ALBUM_ARTIST"; - } - } - - /// - /// Genre - /// - /// 4 - public static string Genre - { - get - { - return "MEDIA_GENRE"; - } - } - - /// - /// Composer - /// - /// 4 - public static string Composer - { - get - { - return "MEDIA_COMPOSER"; - } - } - - /// - /// Release year - /// - /// 4 - public static string Year - { - get - { - return "MEDIA_YEAR"; - } - } - - /// - /// Recorded date - /// - /// 4 - public static string RecordedDate - { - get - { - return "MEDIA_RECORDED_DATE"; - } - } - - /// - /// Copyright - /// - /// 4 - public static string Copyright - { - get - { - return "MEDIA_COPYRIGHT"; - } - } - - /// - /// Track Number - /// - /// 4 - public static string TrackNumber - { - get - { - return "MEDIA_TRACK_NUM"; - } - } - - /// - /// Description - /// - /// 4 - public static string Description - { - get - { - return "MEDIA_DESCRIPTION"; - } - } - - /// - /// Bitrate - /// - /// 4 - public static string Bitrate - { - get - { - return "MEDIA_BITRATE"; - } - } - - /// - /// Bit per sample - /// - /// 4 - public static string BitPerSample - { - get - { - return "MEDIA_BITPERSAMPLE"; - } - } - - /// - /// Samplerate - /// - /// 4 - public static string Samplerate - { - get - { - return "MEDIA_SAMPLERATE"; - } - } - - /// - /// Channel - /// - /// 4 - public static string Channel - { - get - { - return "MEDIA_CHANNEL"; - } - } - - /// - /// Duration - /// - /// 4 - public static string Duration - { - get - { - return "MEDIA_DURATION"; - } - } - - /// - /// Longitude - /// - /// 4 - public static string Longitude - { - get - { - return "MEDIA_LONGITUDE"; - } - } - - /// - /// Latitude - /// - /// 4 - public static string Latitude - { - get - { - return "MEDIA_LATITUDE"; - } - } - - /// - /// Altitude - /// - /// 4 - public static string Altitude - { - get - { - return "MEDIA_ALTITUDE"; - } - } - /// - /// Width - /// - /// 4 - public static string Width - { - get - { - return "MEDIA_WIDTH"; - } - } - - /// - /// Height - /// - /// 4 - public static string Height - { - get - { - return "MEDIA_HEIGHT"; - } - } - - /// - /// Datetaken - /// - /// 4 - public static string Datetaken - { - get - { - return "MEDIA_DATETAKEN"; - } - } - - /// - /// Orientation - /// - /// 4 - public static string Orientation - { - get - { - return "MEDIA_ORIENTATION"; - } - } - - /// - /// Burst shot ID - /// - /// 4 - public static string BurstId - { - get - { - return "BURST_ID"; - } - } - - /// - /// Played count - /// - /// 4 - public static string PlayedCount - { - get - { - return "MEDIA_PLAYED_COUNT"; - } - } - - /// - /// Last played time - /// - /// 4 - public static string PlayedTime - { - get - { - return "MEDIA_LAST_PLAYED_TIME"; - } - } - - /// - /// Last played position - /// - /// 4 - public static string PlayedPosition - { - get - { - return "MEDIA_LAST_PLAYED_POSITION"; - } - } - - /// - /// Rating - /// - /// 4 - public static string Rating - { - get - { - return "MEDIA_RATING"; - } - } - - /// - /// Favourite - /// - /// 4 - public static string Favourite - { - get - { - return "MEDIA_FAVOURITE"; - } - } - - /// - /// Author - /// - /// 4 - public static string Author - { - get - { - return "MEDIA_AUTHOR"; - } - } - - /// - /// Provider - /// - /// 4 - public static string Provider - { - get - { - return "MEDIA_PROVIDER"; - } - } - /// - /// Content name - /// - /// 4 - public static string ContentName - { - get - { - return "MEDIA_CONTENT_NAME"; - } - } - - /// - /// Category - /// - /// 4 - public static string Category - { - get - { - return "MEDIA_CATEGORY"; - } - } - /// - /// Location tag - /// - /// 4 - public static string LocationTag - { - get - { - return "MEDIA_LOCATION_TAG"; - } - } - - /// - /// Age rating - /// - /// 4 - public static string AgeRating - { - get - { - return "MEDIA_AGE_RATING"; - } - } - - /// - /// Keyword - /// - /// 4 - public static string Keyword - { - get - { - return "MEDIA_KEYWORD"; - } - } - - /// - /// Weather - /// - /// 4 - public static string Weather - { - get - { - return "MEDIA_WEATHER"; - } - } - - /// - /// Whether DRM(1) or not(0) - /// - /// 4 - public static string IsDRM - { - get - { - return "MEDIA_IS_DRM"; - } - } - - /// - /// Storage type - /// - /// 4 - public static string StorageType - { - get - { - return "MEDIA_STORAGE_TYPE"; - } - } - - /// - /// Exposure time - /// - /// 4 - public static string ExposureTime - { - get - { - return "MEDIA_EXPOSURE_TIME"; - } - } - - /// - /// f-number - /// - /// 4 - public static string FNumber - { - get - { - return "MEDIA_FNUMBER"; - } - } - - /// - /// ISO - /// - /// 4 - public static string Iso - { - get - { - return "MEDIA_ISO"; - } - } - - /// - /// Model - /// - /// 4 - public static string Model - { - get - { - return "MEDIA_MODEL"; - } - } - - /// - /// 360 content - /// - /// 4 - public static string Media360 - { - get - { - return "MEDIA_360"; - } - } - - /// - /// Keyword for pinyin - /// - public class Pinyin - { - /// - /// File name (pinyin) - /// - /// 4 - public static string FileName - { - get - { - return "MEDIA_FILE_NAME_PINYIN"; - } - } - - /// - /// Title (pinyin) - /// - /// 4 - public static string Title - { - get - { - return "MEDIA_TITLE_PINYIN"; - } - } - - /// - /// Album (pinyin) - /// - /// 4 - public static string Album - { - get - { - return "MEDIA_ALBUM_PINYIN"; - } - } - - /// - /// Artist (pinyin) - /// - /// 4 - public static string Artist - { - get - { - return "MEDIA_ARTIST_PINYIN"; - } - } - - /// - /// Album artist (pinyin) - /// - /// 4 - public static string AlbumArtist - { - get - { - return "MEDIA_ALBUM_ARTIST_PINYIN"; - } - } - - /// - /// Genre (pinyin) - /// - /// 4 - public static string Genre - { - get - { - return "MEDIA_GENRE_PINYIN"; - } - } - - /// - /// Composer (pinyin) - /// - /// 4 - public static string Composer - { - get - { - return "MEDIA_COMPOSER_PINYIN"; - } - } - - /// - /// Copyright (pinyin) - /// - /// 4 - public static string Copyright - { - get - { - return "MEDIA_COPYRIGHT_PINYIN"; - } - } - - /// - /// Description (pinyin) - /// - /// 4 - public static string Description - { - get - { - return "MEDIA_DESCRIPTION_PINYIN"; - } - } - - /// - /// Author (pinyin) - /// - /// 4 - public static string Author - { - get - { - return "MEDIA_AUTHOR_PINYIN"; - } - } - - /// - /// Provider (pinyin) - /// - /// 4 - public static string Provider - { - get - { - return "MEDIA_PROVIDER_PINYIN"; - } - } - - /// - /// Content name (pinyin) - /// - /// 4 - public static string ContentName - { - get - { - return "MEDIA_CONTENT_NAME_PINYIN"; - } - } - - /// - /// Category (pinyin) - /// - /// 4 - public static string Category - { - get - { - return "MEDIA_CATEGORY_PINYIN"; - } - } - - /// - /// Location tag (pinyin) - /// - /// 4 - public static string LocationTag - { - get - { - return "MEDIA_LOCATION_TAG_PINYIN"; - } - } - - /// - /// Age rating (pinyin) - /// - /// 4 - public static string AgeRating - { - get - { - return "MEDIA_AGE_RATING_PINYIN"; - } - } - - /// - /// Keyword (pinyin) - /// - /// 4 - public static string Keyword - { - get - { - return "MEDIA_KEYWORD_PINYIN"; - } - } - } - } - - /// - /// Folder column set. \n - /// You can use this define to set the condition of folder filter and order keyword. - /// - public class Folder - { - - /// - ///Folder UUID - /// - /// 4 - public static string Id - { - get - { - return "FOLDER_ID"; - } - } - - /// - /// Folder path - /// - /// 4 - public static string Path - { - get - { - return "FOLDER_PATH"; - } - } - - /// - /// Folder name - /// - /// 4 - public static string Name - { - get - { - return "FOLDER_NAME"; - } - } - - /// - /// Folder modified time - /// - /// 4 - public static string ModifiedTime - { - get - { - return "FOLDER_MODIFIED_TIME"; - } - } - - /// - /// Folder storage type - /// - /// 4 - public static string StorageType - { - get - { - return "FOLDER_STORAGE_TYPE"; - } - } - - /// - /// Keyword for pinyin - /// - public class Pinyin - { - /// - /// Folder name (pinyin) - /// - /// 4 - public static string Name - { - get - { - return "FOLDER_NAME_PINYIN"; - } - } - - } - - /// - /// Folder order. Default is 0 - /// - /// 4 - public static string Order - { - get - { - return "FOLDER_ORDER"; - } - } - - /// - /// Parent folder UUID - /// - /// 4 - public static string ParentId - { - get - { - return "FOLDER_PARENT_FOLDER_ID"; - } - } - } - - /// - /// Playlist column set. \n - /// You can use this define to set the condition of playlist filter and order keyword. - /// - public class Playlist - { - /// - /// Playlist name - /// - /// 4 - public static string Name - { - get - { - return "PLAYLIST_NAME"; - } - } - /// - /// Playlist member's play order - /// - /// 4 - public static string Order - { - get - { - return "PLAYLIST_MEMBER_ORDER"; - } - } - - /// - /// Count of media in the playlist - /// - /// 4 - public static string Count - { - get - { - return "PLAYLIST_MEDIA_COUNT"; - } - } - } - - /// - /// Tag column set. \n - /// You can use this define to set the condition of tag filter and order keyword. - /// - public class Tag - { - /// - /// Tag name - /// - /// 4 - public static string Name - { - get - { - return "TAG_NAME"; - } - } - - /// - /// Count of media in the tag - /// - /// 4 - public static string Count - { - get - { - return "TAG_MEDIA_COUNT"; - } - } - } - - /// - /// Bookmark column set. \n - /// You can use this define to set the condition of bookmark filter and order keyword. - /// - public class Bookmark - { - /// - /// Bookmarked offset - /// - /// 4 - public static string Offset - { - get - { - return "BOOKMARK_MARKED_TIME"; - } - } - } - - /// - /// Storage column set. \n - /// You can use this define to set the condition of storage filter and order keyword. - /// - public class Storage - { - /// - /// Storage UUID - /// - /// 4 - public static string Id - { - get - { - return "STORAGE_ID"; - } - } - - /// - /// Storage path - /// - /// 4 - public static string Path - { - get - { - return "STORAGE_PATH"; - } - } - } - - /// - /// Face column set. \n - /// You can use this define to set the condition of face filter and order keyword. - /// - public class Face - { - /// - /// face tag - /// - /// 4 - public static string Tag - { - get - { - return "MEDIA_FACE_TAG"; - } - } - } - } -} \ No newline at end of file diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentDatabase.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentDatabase.cs deleted file mode 100755 index e2389a3..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentDatabase.cs +++ /dev/null @@ -1,714 +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.Threading.Tasks; -/// -/// The Media Content API provides functions, enumerations used in the entire Content Service. -/// -/// -/// The Media Content API provides functions and enumerations used in the entire Content Service. -/// The information about media items i.e.image, audio and video, are managed in the content database -/// and operations that involve database requires an active connection with the media content service. -/// During media scanning, Media Service extract media information automatically. media information -/// include basic file info like path, size, modified time etc and some metadata like ID3tag, EXIF, -/// thumbnail, etc. (thumbnail extracted only in Internal and SD card storage. -/// Media content services do not manage hidden files. -/// The API provides functions for connecting (media_content_connect()) and disconnecting(media_content_disconnect()) -/// from the media content service. -/// - - -namespace Tizen.Content.MediaContent -{ - /// - /// ContentDatabase class is the interface class for managing the ContentCollection and MediaInformation from/to the database. - /// This class allows usre to access/create/update db operations for media content. - /// - public class ContentDatabase - { - private static IntPtr _updateHandle = IntPtr.Zero; - - /// - /// Connect to the media database to search, insert, remove or modify media information. - /// - /// 4 - /// - /// For information security, disconnect() after use media database. - /// - public static void Connect() - { - MediaContentValidator.ThrowIfError(Interop.Content.Connect(), "Connect failed"); - } - - /// - /// Disconnect from the media database. - /// - /// 4 - public static void Disconnect() - { - MediaContentValidator.ThrowIfError(Interop.Content.Disconnect(), "Disconnect failed"); - } - - private static readonly Interop.Content.MediaContentDBUpdatedCallback s_contentUpdatedCallback = ( - MediaContentError error, - int pid, - MediaContentUpdateItemType updateItem, - MediaContentDBUpdateType updateType, - MediaContentType mediaType, - string uuid, - string filePath, - string mimeType, - IntPtr userData) => - { - _contentUpdated?.Invoke( - null, new ContentUpdatedEventArgs(error, pid, updateItem, updateType, mediaType, uuid, filePath, mimeType)); - }; - - private static event EventHandler _contentUpdated; - /// - /// ContentUpdated event is triggered when the media DB changes. - /// - /// 3 - /// - /// A ContentUpdatedEventArgs object that contains information about the update operation. - public static event EventHandler ContentUpdated - { - add - { - if (_contentUpdated == null) - { - MediaContentValidator.ThrowIfError( - Interop.Content.AddDbUpdatedCb(s_contentUpdatedCallback, IntPtr.Zero, out _updateHandle), "Failed to set callback"); - } - - _contentUpdated += value; - } - - remove - { - _contentUpdated -= value; - if (_contentUpdated == null) - { - MediaContentValidator.ThrowIfError( - Interop.Content.RemoveDbUpdatedCb(_updateHandle), "Failed to unset callback"); - } - } - } - - /// - /// Gets the count of ContentCollections for the ContentCollectionType and passed filter from the media database. - /// - /// 3 - /// The media filter - /// The count of contents present in the media database for a ContentSourceType - public int GetCount(ContentFilter filter) where T : class - { - int count = 0; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaGroupType groupType = MediaGroupType.DisplayName; - if (handle != IntPtr.Zero) - { - groupType = filter.GroupType; - } - - if (typeof(T) == typeof(MediaInformation)) - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetMediaCount(handle, out count), "Failed to get count"); - } - else if (typeof(T) == typeof(MediaBookmark)) - { - MediaContentValidator.ThrowIfError( - Interop.MediaBookmark.GetBookmarkCountFromDb(handle, out count), "Failed to get count"); - } - else if (typeof(T) == typeof(Album)) - { - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumGetAlbumCountFromDb(handle, out count), "Failed to get count"); - } - else if (typeof(T) == typeof(MediaFolder)) - { - MediaContentValidator.ThrowIfError( - Interop.Folder.GetFolderCountFromDb(handle, out count), "Failed to get count"); - } - else if (typeof(T) == typeof(Storage)) - { - MediaContentValidator.ThrowIfError( - Interop.Storage.GetStorageCountFromDb(handle, out count), "Failed to get count"); - } - else if (typeof(T) == typeof(Tag)) - { - MediaContentValidator.ThrowIfError( - Interop.Tag.GetTagCountFromDb(handle, out count), "Failed to get count"); - } - else if (typeof(T) == typeof(PlayList)) - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.GetPlaylistCountFromDb(handle, out count), "Failed to get count"); - } - else if (typeof(T) == typeof(Group)) - { - MediaContentValidator.ThrowIfError( - Interop.Group.GetGroupCountFromDb(handle, groupType, out count), "Failed to get count"); - } - else - { - throw new ArgumentException("Wrong type"); - } - - return count; - } - - /// - /// Gets the MediaInformation object for the passed media Id. - /// - /// 3 - /// The media id to fetch the respective MediaInformation instance - /// MediaInformation instance for the associated id.It throws Exception for invalid Id. - public MediaInformation Select(string id) - { - Interop.MediaInformation.SafeMediaInformationHandle mediaHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetMediaFromDB(id, out mediaHandle), "Failed to get information"); - - MediaContentType type; - MediaInformation res; - Interop.MediaInformation.GetMediaType(mediaHandle, out type); - if (type == MediaContentType.Image) - { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaHandle.DangerousGetHandle(), out imageInfo), "Failed to get image information"); - - res = new ImageInformation(imageInfo, mediaHandle); - } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaHandle.DangerousGetHandle(), out audioInfo), "Failed to get audio information"); - - res = new AudioInformation(audioInfo, mediaHandle); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaHandle.DangerousGetHandle(), out videoInfo), "Failed to get video information"); - - res = new VideoInformation(videoInfo, mediaHandle); - } - else - { - res = new MediaInformation(mediaHandle); - } - - return res; - } - - /// - /// Gets the ContentCollection object for the passed media Id. - /// Applicable for MediaFolder and Storage types. - /// - /// 3 - /// The ContentCollection id to fetch the respective MediaInformation instance - /// ContentCollection instance for the associated id.It throws Exception for invalid Id. - public T Select(string id) where T : ContentCollection - { - ContentCollection result = null; - IntPtr handle = IntPtr.Zero; - - if (typeof(T) == typeof(MediaFolder)) - { - MediaContentValidator.ThrowIfError( - Interop.Folder.GetFolderFromDb(id, out handle), "Failed to get information"); - - if (handle != IntPtr.Zero) - { - result = new MediaFolder(handle); - return (T)result; - } - - } - else if (typeof(T) == typeof(Storage)) - { - MediaContentValidator.ThrowIfError( - Interop.Storage.GetStorageInfoFromDb(id, out handle), "Failed to get information"); - - if (handle != IntPtr.Zero) - { - result = new Storage(handle); - return (T)result; - } - } - - return null; - } - - - /// - /// Gets the ContentCollection object for the passed media Id. - /// Applicable for PlayList, Album and Tag types. - /// - /// 3 - /// The ContentCollection id to fetch the respective MediaInformation instance - /// ContentCollection instance for the associated id.It throws Exception for invalid Id. - public T Select(int id) where T : ContentCollection - { - ContentCollection result = null; - IntPtr handle = IntPtr.Zero; - - if (typeof(T) == typeof(PlayList)) - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.GetPlaylistFromDb(id, out handle), "Failed to get information"); - - if (handle != IntPtr.Zero) - { - result = new PlayList(handle); - return (T)result; - } - } - else if (typeof(T) == typeof(Album)) - { - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumGetAlbumFromDb(id, out handle), "Failed to get information"); - - if (handle != IntPtr.Zero) - { - result = new Album(handle); - return (T)result; - } - } - else if (typeof(T) == typeof(Tag)) - { - MediaContentValidator.ThrowIfError( - Interop.Tag.GetTagFromDb(id, out handle), "Failed to get information"); - - if (handle != IntPtr.Zero) - { - result = new Tag(handle); - return (T)result; - } - } - - return null; - } - - private static IEnumerable ForEachFolder(ContentFilter filter) - { - List result = new List(); - Interop.Folder.MediaFolderCallback callback = (IntPtr handle, IntPtr data) => - { - IntPtr newHandle = IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Folder.Clone(out newHandle, handle), "Failed to clone"); - - result.Add(new MediaFolder(newHandle)); - return true; - }; - IntPtr filterHandle = filter != null ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Folder.ForeachFolderFromDb(filterHandle, callback, IntPtr.Zero), "Failed to get information"); - - return result; - } - - private static IEnumerable ForEachAlbum(ContentFilter filter) - { - List result = new List(); - Interop.Group.MediaAlbumCallback callback = (IntPtr handle, IntPtr data) => - { - IntPtr newHandle = IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumClone(out newHandle, handle), "Failed to clone"); - - result.Add(new Album(newHandle)); - return true; - }; - IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Group.MediaAlbumForeachAlbumFromDb(filterHandle, callback, IntPtr.Zero), "Failed to get information"); - - return result; - } - - private static IEnumerable ForEachGroup(ContentFilter filter) - { - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaGroupType groupType; - if (filter == null) - { - groupType = MediaGroupType.DisplayName; - } - else - { - groupType = filter.GroupType; - } - - List result = new List(); - Interop.Group.MediaGroupCallback callback = (string groupName, IntPtr data) => - { - result.Add(new Group(groupName, groupType)); - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Group.ForeachGroupFromDb(handle, groupType, callback, IntPtr.Zero), "Failed to get information"); - - return result; - } - - private static IEnumerable ForEachStorage(ContentFilter filter) - { - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - List result = new List(); - Interop.Storage.MediaStorageCallback callback = (IntPtr storageHandle, IntPtr data) => - { - IntPtr newHandle = IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Storage.Clone(out newHandle, storageHandle), "Failed to clone"); - - result.Add(new Storage(newHandle)); - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Storage.ForeachStorageFromDb(handle, callback, IntPtr.Zero), "Failed to get information"); - - return result; - } - - private static IEnumerable ForEachTag(ContentFilter filter) - { - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - - List result = new List(); - Interop.Tag.MediaTagCallback callback = (IntPtr tagHandle, IntPtr data) => - { - IntPtr newHandle = IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Tag.Clone(out newHandle, tagHandle), "Failed to clone"); - - result.Add(new Tag(newHandle)); - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Tag.ForeachTagFromDb(handle, callback, IntPtr.Zero), "Failed to get information"); - - return result; - } - - private static IEnumerable ForEachPlayList(ContentFilter filter) - { - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - - List result = new List(); - Interop.Playlist.MediaPlaylistCallback callback = (IntPtr playListHandle, IntPtr data) => - { - IntPtr newHandle = IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Playlist.Clone(out newHandle, playListHandle), "Failed to clone"); - - result.Add(new PlayList(newHandle)); - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Playlist.ForeachPlaylistFromDb(handle, callback, IntPtr.Zero), "Failed to get information"); - - return result; - } - - /// - /// Returns the ContentCollections with optional filter from the media database. - /// - /// 3 - /// - /// This function gets all ContentCollections matching the given filter. If NULL is passed to the filter, no filtering is applied. - /// - /// Filter for content items - /// - /// Task with the list of the ContentCollection - /// - public IEnumerable SelectAll(ContentFilter filter) - { - if (typeof(T) == typeof(MediaInformation)) - { - IEnumerable mediaList = GetMediaInformations(filter); - return (IEnumerable)mediaList; - } - else if (typeof(T) == typeof(Album)) - { - IEnumerable collectionList = ForEachAlbum(filter); - return (IEnumerable)collectionList; - } - else if (typeof(T) == typeof(MediaFolder)) - { - IEnumerable collectionList = ForEachFolder(filter); - return (IEnumerable)collectionList; - } - else if (typeof(T) == typeof(Group)) - { - IEnumerable collectionList = ForEachGroup(filter); - return (IEnumerable)collectionList; - } - else if (typeof(T) == typeof(Storage)) - { - IEnumerable collectionList = ForEachStorage(filter); - return (IEnumerable)collectionList; - } - else if (typeof(T) == typeof(Tag)) - { - IEnumerable collectionList = ForEachTag(filter); - return (IEnumerable)collectionList; - } - else if (typeof(T) == typeof(PlayList)) - { - IEnumerable collectionList = ForEachPlayList(filter); - return (IEnumerable)collectionList; - } - - return null; - } - - /// - /// Returns media from the media database. - /// This function gets all media meeting the given filter - /// - /// 3 - /// The media filter - /// List of media - private IEnumerable GetMediaInformations(ContentFilter filter) - { - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - List mediaInformationList = new List(); - Interop.MediaInformation.MediaInformationCallback callback = (IntPtr mediaHandle, IntPtr userData) => - { - Interop.MediaInformation.SafeMediaInformationHandle newHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone"); - - MediaContentType type; - Interop.MediaInformation.GetMediaType(newHandle, out type); - if (type == MediaContentType.Image) - { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information"); - - mediaInformationList.Add(new ImageInformation(imageInfo, newHandle)); - } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information"); - - mediaInformationList.Add(new AudioInformation(audioInfo, newHandle)); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information"); - - mediaInformationList.Add(new VideoInformation(videoInfo, newHandle)); - } - else if (type == MediaContentType.Others) - { - mediaInformationList.Add(new MediaInformation(newHandle)); - } - - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAllMedia(handle, callback, IntPtr.Zero), "Failed to get media information"); - - return mediaInformationList; - } - - /// - /// Deletes a MediaInformation from the media database. - /// - /// 3 - /// The MediaInformation to be deleted - public void Delete(MediaInformation mediaInfo) - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Delete(mediaInfo.MediaId), "Failed to remove information"); - } - - - /// - /// Deletes a content collection from the media database. - /// Applicable for Tag and PlayList only. - /// For other types ArgumentException is thrown. - /// - /// 3 - /// The ContentCollection instance to be deleted - public void Delete(ContentCollection contentcollection) - { - Type type = contentcollection.GetType(); - - if (type == typeof(Tag)) - { - MediaContentValidator.ThrowIfError( - Interop.Tag.DeleteFromDb(((Tag)contentcollection).Id), "Failed to remove information"); - } - else if (type == typeof(PlayList)) - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.DeleteFromDb(((PlayList)contentcollection).Id), "Failed to remove information"); - } - else - { - throw new ArgumentException("The type of content collection is wrong"); - } - } - - internal void Delete(MediaBookmark bookmark) - { - MediaContentValidator.ThrowIfError( - Interop.MediaBookmark.DeleteFromDb(bookmark.Id), "Failed to remove information"); - } - - internal void Delete(MediaFace face) - { - MediaContentValidator.ThrowIfError( - Interop.Face.DeleteFromDb(face.Id), "Failed to remove face information"); - } - - /// - /// Updates a content collection in the media database - /// Applicable for Tag, PlayList and MediagFolder types only. - /// - /// 3 - /// The content collection to be updated - public void Update(ContentCollection contentCollection) - { - Type type = contentCollection.GetType(); - if (type == typeof(Tag)) - { - MediaContentValidator.ThrowIfError( - Interop.Tag.UpdateToDb(((Tag)contentCollection).Handle), "Failed to update DB"); - } - else if (type == typeof(PlayList)) - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.UpdateToDb(((PlayList)contentCollection).Handle), "Failed to update DB"); - } - else if (type == typeof(MediaFolder)) - { - MediaContentValidator.ThrowIfError( - Interop.Folder.UpdateToDb(((MediaFolder)contentCollection).Handle), "Failed to update DB"); - } - else - { - throw new ArgumentException("The type of content collection is wrong"); - } - } - - /// - /// Updates a media information instance in the media database - /// - /// 3 - /// The MediaInformation object to be updated - public void Update(MediaInformation mediaInfo) - { - Type type = mediaInfo.GetType(); - if (type == typeof(ImageInformation)) - { - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.UpdateToDB(((ImageInformation)mediaInfo).ImageHandle), "Failed to update DB"); - - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.UpdateToDB(mediaInfo.MediaHandle), "Failed to update DB"); - } - else if (type == typeof(AudioInformation)) - { - MediaContentValidator.ThrowIfError( - Interop.AudioInformation.UpdateToDB(((AudioInformation)mediaInfo).AudioHandle), "Failed to update DB"); - - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.UpdateToDB(mediaInfo.MediaHandle), "Failed to update DB"); - } - else if (type == typeof(VideoInformation)) - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.UpdateToDB(((VideoInformation)mediaInfo).VideoHandle), "Failed to update DB"); - - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.UpdateToDB(mediaInfo.MediaHandle), "Failed to update DB"); - } - else if (type == typeof(MediaInformation)) - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.UpdateToDB(mediaInfo.MediaHandle), "Failed to update DB"); - } - else - { - throw new ArgumentException("Invalid information type"); - } - } - - internal void Update(MediaFace face) - { - MediaContentValidator.ThrowIfError(Interop.Face.UpdateToDb(face.Handle), "Failed to update DB"); - } - - /// - /// Inserts a content collection to the media database. - /// Applicable for Tag and PlayList types only. - /// - /// 3 - /// The content collection to be inserted - public void Insert(ContentCollection contentCollection) - { - Type type = contentCollection.GetType(); - IntPtr handle = IntPtr.Zero; - if (type == typeof(Tag)) - { - MediaContentValidator.ThrowIfError( - Interop.Tag.InsertToDb(((Tag)contentCollection).Name, out handle), "Failed to insert collection"); - ((Tag)contentCollection).Handle = handle; - } - else if (type == typeof(PlayList)) - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.InsertToDb(((PlayList)contentCollection).Name, out handle), "Failed to insert collection"); - ((PlayList)contentCollection).Handle = handle; - } - else - { - throw new ArgumentException("collection type is wrong"); - } - } - - internal void Insert(string mediaId, uint offset, string thumbnailPath) - { - MediaContentValidator.ThrowIfError( - Interop.MediaBookmark.InsertToDb(mediaId, offset, thumbnailPath), "Failed to insert information"); - } - - internal void Insert(MediaFace face) - { - MediaContentValidator.ThrowIfError( - Interop.Face.InsertToDb(((MediaFace)face).Handle), "Failed to insert information"); - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentEventArgs.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentEventArgs.cs deleted file mode 100755 index 283fc87..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentEventArgs.cs +++ /dev/null @@ -1,113 +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.Content.MediaContent -{ - /// - /// Event arguments passed when content is updated in the media database - /// - public class ContentUpdatedEventArgs : EventArgs - { - internal ContentUpdatedEventArgs(MediaContentError error, int pid, MediaContentUpdateItemType updateItem, - MediaContentDBUpdateType updateType, MediaContentType mediaType, string uuid, string filePath, string mimeType) - { - Error = error; - Pid = pid; - UpdateItem = updateItem; - UpdateType = updateType; - MediaType = mediaType; - Uuid = uuid; - FilePath = filePath; - MimeType = mimeType; - } - /// - /// The error code - /// - /// 3 - public MediaContentError Error - { - get; - internal set; - } - - /// - /// The PID which publishes notification - /// - /// 3 - public int Pid - { - get; set; - } - - /// - /// The update item of notification - /// - /// 3 - public MediaContentUpdateItemType UpdateItem - { - get; set; - } - - /// - /// The update type of notification - /// - /// 3 - public MediaContentDBUpdateType UpdateType - { - get; set; - } - - /// - /// The type of the media content - /// - /// 3 - public MediaContentType MediaType - { - get; set; - } - - /// - /// The UUID of media or directory, which is updated - /// - /// 3 - public string Uuid - { - get; set; - } - - /// - /// The path of the media or directory - /// - /// 3 - public string FilePath - { - get; set; - } - - /// - /// The mime type of the media info - /// - /// 3 - public string MimeType - { - get; set; - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentFilter.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentFilter.cs deleted file mode 100755 index 97d4998..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentFilter.cs +++ /dev/null @@ -1,365 +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.Runtime.InteropServices; - -namespace Tizen.Content.MediaContent -{ - /// - /// The Content Filter API provides functions to manage media filters. - /// - /// - /// A Content filter is required for filtering information associated with Media Folder, Tag, Audio, MediaBookmark and Media Information on basis of details like offset, count, order and condition for searching. - /// It provide functionality to set properties associated with a given content filter. - /// Setting content filter properties helps to limit the number of filtered items as following: - /// - /// - /// Offset - Used to set starting position of the filter's search - /// - /// - /// Count - Used to set number of items to be searched from offset - /// - /// - /// Condition - Used to set keyword which user want to search - /// - /// - /// Order - Used to set type of media to be ordered by the filter - /// - /// - /// Searchable expression can use one of the following forms: - /// - /// - /// column = value - /// - /// - /// column > value - /// - /// - /// column >= value - /// - /// - /// column < value - /// - /// - /// column <= value - /// - /// - /// value = column - /// - /// - /// value >= column - /// - /// - /// value < column - /// - /// - /// value <= column - /// - /// - /// column IN (value) - /// - /// - /// column IN(value-list) - /// - /// - /// column NOT IN(value) - /// - /// - /// column NOT IN(value-list) - /// - /// - /// column LIKE value - /// - /// - /// expression1 AND expression2 OR expression3 - /// - /// - /// Note that if you want to set qoutation(" ' " or " " ") as value of LIKE operator, you should use two times.(" '' " or " "" ") \n And the optional ESCAPE clause is supported. Both percent symbol("%") and underscore symbol("_") are used in the LIKE pattern. - /// If these characters are used as value of LIKE operation, then the expression following the ESCAPE caluse of sqlite. - /// - public class ContentFilter : IDisposable - { - private IntPtr _filterHandle = IntPtr.Zero; - private bool _disposedValue = false; - private ContentCollation _conditionCollate = ContentCollation.Default; - private ContentCollation _orderCollate = ContentCollation.Default; - private ContentOrder _orderType = ContentOrder.Asc; - private string _orderKeyword = null; - private string _conditionMsg = null; - - internal IntPtr Handle - { - get - { - if (_filterHandle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(ContentFilter)); - } - - return _filterHandle; - } - } - /// - /// The start position of the given filter Starting from zero. - /// Please note that count value has to be set properly for correct result. - /// - /// 3 - public int Offset - { - get - { - int offset; - int count; - MediaContentValidator.ThrowIfError( - Interop.Filter.GetOffset(Handle, out offset, out count), "Failed to get offset"); - - return offset; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Filter.SetOffset(Handle, value, this.Count), "Failed to set offset"); - } - } - - public ContentFilter() - { - MediaContentValidator.ThrowIfError( - Interop.Filter.Create(out _filterHandle), "Failed to Create Filter handle."); - } - - /// - /// The number of items to be searched with respect to the offset - /// - /// 3 - public int Count - { - get - { - int offset; - int count; - MediaContentValidator.ThrowIfError( - Interop.Filter.GetOffset(Handle, out offset, out count), "Failed to get count"); - - return count; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Filter.SetOffset(Handle, this.Offset, value), "Failed to set count"); - } - } - - /// - /// Gets the media filter content order and order keyword. - /// - /// 3 - public ContentOrder Order - { - get - { - return _orderType; - } - - set - { - if (_orderKeyword != null) - { - MediaContentValidator.ThrowIfError( - Interop.Filter.SetOrder(Handle, value, _orderKeyword, _orderCollate), "Failed to set order"); - } - - _orderType = value; - } - } - - /// - /// The search order keyword - /// - /// 3 - public string OrderKey - { - get - { - ContentOrder order; - IntPtr val = IntPtr.Zero; - ContentCollation type; - try - { - MediaContentValidator.ThrowIfError( - Interop.Filter.GetOrder(Handle, out order, out val, out type), "Failed to GetOrder for OrderKey"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Filter.SetOrder(Handle, _orderType, value, _orderCollate), "Failed to set OrderKey"); - - _orderKeyword = value; - } - } - - /// - /// The collate type for comparing two strings - /// - /// 3 - public ContentCollation OrderCollationType - { - get - { - return _orderCollate; - } - - set - { - if (_orderKeyword != null) - { - MediaContentValidator.ThrowIfError( - Interop.Filter.SetOrder(Handle, _orderType, _orderKeyword, value), "Failed to set collation"); - } - - _orderCollate = value; - } - } - - /// - /// Gets/Sets the condition for the given filter. - /// - /// 3 - public string Condition - { - get - { - IntPtr val = IntPtr.Zero; - ContentCollation type; - try - { - MediaContentValidator.ThrowIfError( - Interop.Filter.GetCondition(Handle, out val, out type), "Failed to get condition"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Filter.SetCondition(Handle, value, _conditionCollate), "Failed to set condition"); - - _conditionMsg = value; - } - } - - /// - /// The collate type for comparing two strings - /// - /// 3 - public ContentCollation ConditionCollationType - { - get - { - return _conditionCollate; - } - - set - { - if (_conditionMsg != null) - { - MediaContentValidator.ThrowIfError( - Interop.Filter.SetCondition(Handle, _conditionMsg, value), "Failed to set collation"); - } - - _conditionCollate = value; - } - } - - /// - /// Sets the storage id for the given filter. - /// You can use this property when you want to search items only in the specific storage - /// - /// 3 - public string StorageId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Filter.GetStorage(Handle, out val), "Failed to get condition"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Filter.SetStorage(Handle, value), "Failed to set condition"); - } - } - - /// - /// The type of the media group - /// - /// 3 - public MediaGroupType GroupType { get; set; } - - /// - /// Dispose API for closing the internal resources. - /// This function can be used to stop all effects started by Vibrate(). - /// - /// 3 - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - if (_filterHandle != IntPtr.Zero) - { - Interop.Filter.Destroy(_filterHandle); - _filterHandle = IntPtr.Zero; - } - - _disposedValue = true; - } - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentManager.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentManager.cs deleted file mode 100755 index 6044b87..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentManager.cs +++ /dev/null @@ -1,268 +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.Threading.Tasks; -using System.Threading; - -/// -/// The Media Content API provides functions, enumerations used in the entire Content Service. -/// -/// -/// The Media Content API provides functions and enumerations used in the entire Content Service. -/// The information about media items i.e.image, audio and video, are managed in the content database -/// and operations that involve database requires an active connection with the media content service. -/// During media scanning, Media Service extract media information automatically. media information -/// include basic file info like path, size, modified time etc and some metadata like ID3tag, EXIF, -/// thumbnail, etc. (thumbnail extracted only in Internal and SD card storage. -/// Media content services do not manage hidden files. -/// The API provides functions for connecting (media_content_connect()) and disconnecting(media_content_disconnect()) -/// from the media content service. -/// - - -namespace Tizen.Content.MediaContent -{ - /// - /// ContentManager class is the interface class for accessing the ContentCollection and MediaInformation. - /// This class allows usre to create/update db operations for media content. - /// - public static class ContentManager - { - private static readonly ContentDatabase s_contentDB = new ContentDatabase(); - - /// - /// Database instance to do all the Database oprtions for media content management. - /// - /// 3 - public static ContentDatabase Database - { - get - { - return s_contentDB; - } - } - - /// - /// Requests to scan a media file. - /// - /// 3 - /// File path of the media to be scanned - /// A reference to the MediaInformation object scanned - /// - /// This function requests to scan a media file to the media server. If media file is not registered to DB yet, - /// that media file information will be added to the media DB. If it is already registered to the DB, - /// then this tries to refresh information. If requested file does not exist on file system, - /// information of the media file will be removed from the media DB. - /// - public static void Scan(string filePath) - { - MediaContentValidator.ThrowIfError(Interop.Content.ScanFile(filePath), "Failed scan"); - } - - /// - /// Inserts a media to the media database - /// - /// 3 - /// File path of the media to be inserted - /// the MediaInformation instance about added media path - public static MediaInformation AddMediaInformation(string filePath) - { - Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Insert(filePath, out mediaInformationHandle), "Failed to Insert MediaInformation to DB"); - - MediaContentType type; - MediaInformation res; - Interop.MediaInformation.GetMediaType(mediaInformationHandle, out type); - if (type == MediaContentType.Image) - { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaInformationHandle.DangerousGetHandle(), out imageInfo), "Failed to get image information"); - - res = new ImageInformation(imageInfo, mediaInformationHandle); - } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaInformationHandle.DangerousGetHandle(), out audioInfo), "Failed to get audio information"); - - res = new AudioInformation(audioInfo, mediaInformationHandle); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaInformationHandle.DangerousGetHandle(), out videoInfo), "Failed to get video information"); - - res = new VideoInformation(videoInfo, mediaInformationHandle); - } - else - { - res = new MediaInformation(mediaInformationHandle); - } - - return res; - } - - /// - /// Requests to scan a media folder, asynchronously. - /// - /// 3 - /// The folder path - /// Indicate sif the folder is to recursively scanned. Default value: true - /// - /// This function requests to scan a media folder to the media server with given completed callback function. - /// The sub folders are also scanned,if there are sub folders in that folder. - /// If any folder must not be scanned, a blank file ".scan_ignore" has to be created in that folder. - /// - /// Task with scanning result - public static Task ScanFolderAsync(string folderPath, bool recursive = true) - { - var task = new TaskCompletionSource(); - - Interop.Content.MediaScanCompletedCallback scanCompleted = (MediaContentError scanResult, IntPtr data) => - { - MediaContentValidator.ThrowIfError(scanResult, "Failed to scan"); - task.SetResult(scanResult); - }; - - MediaContentValidator.ThrowIfError( - Interop.Content.ScanFolder(folderPath, recursive, scanCompleted, IntPtr.Zero), "Failed to scan"); - - return task.Task; - } - - internal static Interop.Content.MediaScanCompletedCallback scanCompletedWithToken = null; - internal static Object l = new Object(); - /// - /// Requests to scan a media folder, asynchronously. - /// - /// 3 - /// The folder path - /// Cancellation token required to cancel the current scan - /// Indicate sif the folder is to recursively scanned. Default value: true - /// - /// This function requests to scan a media folder to the media server with given completed callback function. - /// The sub folders are also scanned,if there are sub folders in that folder. - /// If any folder must not be scanned, a blank file ".scan_ignore" has to be created in that folder. - /// - /// Task with scanning result - public static Task ScanFolderAsync(string folderPath, CancellationToken cancellationToken, bool recursive = true) - { - var task = new TaskCompletionSource(); - bool taskCompleted = false; - - cancellationToken.Register(() => - { - lock (l) - { - if (!taskCompleted) - { - taskCompleted = true; - MediaContentValidator.ThrowIfError( - Interop.Content.CancelScanFolder(folderPath), "Failed CancelScanFolder"); - - task.SetCanceled(); - } - } - }); - scanCompletedWithToken = (MediaContentError scanResult, IntPtr data) => - { - lock (l) - { - if (!taskCompleted) - { - taskCompleted = true; - MediaContentValidator.ThrowIfError(scanResult, "Failed scan"); - task.SetResult((int)scanResult); - } - } - }; - - MediaContentValidator.ThrowIfError( - Interop.Content.ScanFolder(folderPath, recursive, scanCompletedWithToken, IntPtr.Zero), "Failed to scan"); - - return task.Task; - - } - - /// - /// Inserts media files into the media database, asynchronously. - /// - /// 3 - /// The path array to the media files - /// - /// Task with the result of batch insertion - /// - public static Task AddMediaInformationBatchAsync(IEnumerable filePaths) - { - var task = new TaskCompletionSource(); - string[] paths = ((List)filePaths).ToArray(); - Interop.MediaInformation.MediaInsertCompletedCallback callback = (MediaContentError error, IntPtr userData) => - { - MediaContentValidator.ThrowIfError(error, "Failed to batch insert"); - task.SetResult((int)error); - }; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.BatchInsert(paths, paths.Length, callback, IntPtr.Zero), "Failed to add batch media"); - - return task.Task; - } - - /// - /// Inserts the burst shot images into the media database, asynchronously. - /// - /// 3 - /// The path array to the burst shot images - /// - /// Task with the result of the burstshot insertion - /// - public static Task AddBurstShotImagesAsync(IEnumerable filePaths) - { - var task = new TaskCompletionSource(); - string[] paths = ((List)filePaths).ToArray(); - Interop.MediaInformation.MediaInsertBurstShotCompletedCallback callback = (MediaContentError error, IntPtr userData) => - { - MediaContentValidator.ThrowIfError(error, "Failed to add burstshot"); - task.SetResult((int)error); - }; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.BurstShotInsert(paths, paths.Length, callback, IntPtr.Zero), "Failed to add burst shots to db"); - - return task.Task; - } - - /// - /// Deletes media files from the media database. The media files for deletion can be specified as a condition in a filter. - /// This function deletes the media items from the content storage.Normally, deleting media files in the database are done automatically by the media server, - /// without calling this function.This function is only called when the media server is busy and user needs to get quick result of deleting. - /// - /// 3 - /// The content filter to which media will be matched - public static void RemoveMediaInformationBatch(ContentFilter filter) - { - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.BatchDelete(handle), "Failed to remove items"); - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs new file mode 100644 index 0000000..525fddc --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs @@ -0,0 +1,167 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Specifies how the strings are compared. + /// + internal enum Collation + { + /// + /// Default collation, binary. + /// + Default, + /// + /// Case-insensitive. + /// + NoCase, + /// + /// Trailing space characters are ignored. + /// + Rtrim, + /// + /// Localized, NoCase also applied. + /// + Localized + } + + /// + /// Specifies storage types. + /// + public enum StorageType + { + /// + /// The device's internal storage. + /// + Internal = 0, + + /// + /// The device's external storage like sd card. + /// + External = 1, + + /// + /// The external usb storage. + /// + ExternalUsb = 2 + } + + /// + /// Specifies database operation types. + /// + public enum OperationType + { + /// + /// Insert operation. + /// + Insert, + + /// + /// Delete operation. + /// + Delete, + + /// + /// Update operation. + /// + Update + } + + internal enum ItemType + { + File, + Directory + } + + /// + /// Specifies types of . + /// + public enum MediaType + { + /// + /// The type of an image. + /// + /// + Image = 0, + + /// + /// The type of a video. + /// + /// + Video = 1, + + /// + /// The type of sound. + /// + /// + Sound = 2, + + /// + /// The type of music. + /// + /// + Music = 3, + + /// + /// The type of other. + /// + Other = 4 + } + + /// + /// Specifies orientation types of media. + /// + public enum Orientation + { + /// + /// None. + /// + Rotate0 = 0, + /// + /// Normal. + /// + Normal = 1, + /// + /// Rotate 90 degrees. + /// + Rotate90 = 6, + /// + /// Rotate 180 degrees. + /// + Rotate180 = 3, + /// + /// Rotate 270 degrees. + /// + Rotate270 = 8, + /// + /// Flip horizontal. + /// + FlipHorizontal = 2, + /// + /// Flip vertical. + /// + FlipVertical = 4, + /// + /// Transpose. + /// + Transpose = 5, + /// + /// Transverse. + /// + Transverse = 7, + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/EventArgs.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/EventArgs.cs new file mode 100644 index 0000000..b8f49fd --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/EventArgs.cs @@ -0,0 +1,135 @@ +/* + * 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.Content.MediaContent +{ + + /// + /// Provides data for the event. + /// + public class MediaInfoUpdatedEventArgs : EventArgs + { + internal MediaInfoUpdatedEventArgs(int pid, + OperationType operationType, MediaType mediaType, string id, string path, string mimeType) + { + ProcessId = pid; + OperationType = operationType; + Id = id; + Path = path; + + MediaType = mediaType; + MimeType = mimeType; + } + + /// + /// Gets the process id which triggers the event. + /// + /// The process id which triggers the event. + public int ProcessId + { + get; + } + + /// + /// Gets the operation type. + /// + /// The operation type which triggers the event. + public OperationType OperationType + { + get; + } + + /// + /// Gets the id of the media updated. + /// + /// The id of the media updated. + public string Id + { + get; + } + + /// + /// Gets the path of the media updated. + /// + /// The path of the media updated. + public string Path + { + get; + } + + /// + /// Gets the type of the media updated. + /// + /// The of the media updated. + public MediaType MediaType + { + get; + } + + /// + /// The mime type of the media updated. + /// + /// The mime type of the media updated. + public string MimeType + { + get; + } + } + + + /// + /// Provides data for the event. + /// + public class FolderUpdatedEventArgs : EventArgs + { + internal FolderUpdatedEventArgs(OperationType operationType, string id, string path) + { + OperationType = operationType; + Id = id; + Path = path; + } + + /// + /// Gets the operation type. + /// + /// The operation type which triggers the event. + public OperationType OperationType + { + get; + } + + /// + /// Gets the id of the folder updated. + /// + /// The id of the folder updated. + public string Id + { + get; + } + + /// + /// Gets the path of the folder updated. + /// + /// The path of the folder updated. + public string Path + { + get; + } + } + +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceInfo.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceInfo.cs new file mode 100644 index 0000000..bdbf132 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceInfo.cs @@ -0,0 +1,89 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Represents the face information for media. + /// + public class FaceInfo + { + internal FaceInfo(IntPtr handle) + { + Id = InteropHelper.GetString(handle, Interop.Face.GetId); + MediaInfoId = InteropHelper.GetString(handle, Interop.Face.GetMediaId); + + Tag = InteropHelper.GetString(handle, Interop.Face.GetTag); + Orientation = InteropHelper.GetValue(handle, Interop.Face.GetOrientation); + + Rect = GetRect(handle); + } + + private static Rectangle GetRect(IntPtr faceHandle) + { + Interop.Face.GetFaceRect(faceHandle, out var x, out var y, out var width, out var height). + ThrowIfError("Failed to get rect for the face info"); + + return new Rectangle(x, y, width, height); + } + + /// + /// Gets the region. + /// + /// The region of face in the media. + /// + /// The coordinates of the rectangle are orientation-applied values. + /// + public Rectangle Rect { get; } + + /// + /// Gets the id of face info. + /// + public string Id { get; } + + /// + /// Gets the media id that the face info is added. + /// + /// The media id that the face info is added. + public string MediaInfoId { get; } + + /// + /// Gets the tag name. + /// + /// The tag name of face info. + public string Tag { get; } + + /// + /// Gets the orientation of face info. + /// + /// The orientation of face info. + public Orientation Orientation { get; } + + internal static FaceInfo FromHandle(IntPtr handle) + { + return new FaceInfo(handle); + } + + /// + /// Returns a string representation of the face info. + /// + /// A string representation of the current face info. + public override string ToString() => + $"Id={Id}, MediaInfoId={MediaInfoId}, Rect=({Rect}), Tag={Tag}"; + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceInfoCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceInfoCommand.cs new file mode 100644 index 0000000..45b4ae2 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceInfoCommand.cs @@ -0,0 +1,139 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Provides commands to manage face infos in the database. + /// + /// + public class FaceInfoCommand : MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + public FaceInfoCommand(MediaDatabase database) : base(database) + { + } + + /// + /// Deletes a face info from the database. + /// + /// http://tizen.org/privilege/content.write + /// The face info id to delete. + /// true if the matched record was found and deleted, otherwise false. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// The caller has no required privilege. + public bool Delete(string faceInfoId) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId)); + + var reader = Select(new SelectArguments { FilterExpression = $"{FaceInfoColumns.Id}='{faceInfoId}'" }); + + if (reader.Read() == false) + { + return false; + } + + CommandHelper.Delete(Interop.Face.DeleteFromDb, faceInfoId); + return true; + } + + /// + /// Retrieves the face info. + /// + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select() + { + return Select(null); + } + + /// + /// Retrieves the face info with . + /// + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select(SelectArguments filter) + { + ValidateDatabase(); + + return CommandHelper.Select(filter, Interop.Face.ForeachFromDb, FaceInfo.FromHandle); + } + + /// + /// Updates a tag with the specified tag. + /// + /// http://tizen.org/privilege/content.write + /// The face info id to update. + /// The tag value for update. + /// true if the matched record was found and updated, otherwise false. + /// Only values set in are updated. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// The caller has no required privilege. + public bool UpdateTag(string faceInfoId, string tag) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId)); + + if (tag == null) + { + throw new ArgumentNullException(nameof(tag)); + } + + var handle = CommandHelper.SelectScalar(Interop.Face.ForeachFromDb, $"{FaceInfoColumns.Id}='{faceInfoId}'", + Interop.Face.Clone); + + if (handle == IntPtr.Zero) + { + return false; + } + + try + { + Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to update(setting tag)"); + + Interop.Face.Update(handle).ThrowIfError("Failed to update(executing query)"); + return true; + } + finally + { + Interop.Face.Destroy(handle); + } + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceRect.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceRect.cs deleted file mode 100755 index 93298a9..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FaceRect.cs +++ /dev/null @@ -1,59 +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. -*/ - - - -namespace Tizen.Content.MediaContent -{ - /// - /// FaceRect represents a rectangle dimension to create a Face in an image. - /// It is used to create or tag a MediaFace in an image file. - /// - public class FaceRect - { - public FaceRect(int x, int y, int width, int height) - { - X = x; - Y = y; - Width = width; - Height = height; - } - - /// - /// X coordinate of the FaceRect - /// - /// 3 - public readonly int X; - - /// - /// Y coordinate of the FaceRect - /// - /// 3 - public readonly int Y; - - /// - /// Width of the FaceRect - /// - /// 3 - public readonly int Width; - - /// - /// Height of the FaceRect - /// - /// 3 - public readonly int Height; - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Features.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Features.cs new file mode 100644 index 0000000..245a94a --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Features.cs @@ -0,0 +1,31 @@ +/* + * 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 Tizen.System; + +static internal class Features +{ + internal const string FaceRecognition = "http://tizen.org/feature/vision.face_recognition"; + + internal static bool IsSupported(string key) + { + if (SystemInfo.TryGetValue(key, out bool value)) + { + return value; + } + return false; + } +} \ No newline at end of file diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Folder.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Folder.cs new file mode 100644 index 0000000..d48ead4 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Folder.cs @@ -0,0 +1,79 @@ +/* +* 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.Content.MediaContent +{ + /// + /// Represents the folder information for media. + /// + /// + /// A is used to organize media content files i.e. image, audio, video files, + /// in the physical storage of the device. + /// + public class Folder + { + internal Folder(IntPtr handle) + { + Id = InteropHelper.GetString(handle, Interop.Folder.GetFolderId); + Path = InteropHelper.GetString(handle, Interop.Folder.GetPath); + Name = InteropHelper.GetString(handle, Interop.Folder.GetName); + + StorageType = InteropHelper.GetValue(handle, Interop.Folder.GetStorageType); + StorageId = InteropHelper.GetString(handle, Interop.Folder.GetStorageId); + } + + internal static Folder FromHandle(IntPtr handle) => new Folder(handle); + + /// + /// Gets the id of folder. + /// + /// The unique id of folder. + public string Id { get; } + + /// + /// Gets the path of folder. + /// + /// The path of folder. + public string Path { get; } + + /// + /// Gets the name of folder. + /// + /// The name of folder. + public string Name { get; } + + /// + /// Gets the of the storage that the folder exists. + /// + /// The of the storage that the folder exists. + public StorageType StorageType { get; } + + /// + /// Gets the storage id of the storage that the folder exists. + /// + /// The storage id of the storage that the folder exists. + public string StorageId { get; } + + /// + /// Returns a string representation of the folder. + /// + /// A string representation of the current folder. + public override string ToString() => + $"Id={Id}, Name={Name}, Path={Path}, StorageType={StorageType}, StorageId={StorageType}"; + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FolderCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FolderCommand.cs new file mode 100644 index 0000000..05c7fb3 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/FolderCommand.cs @@ -0,0 +1,193 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Provides commands to manage folders and query related media items in the database. + /// + public class FolderCommand : MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + public FolderCommand(MediaDatabase database) : base(database) + { + } + + /// + /// Retrieves the number of folders. + /// + /// The number of folders. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count() + { + return Count(null); + } + + /// + /// Retrieves the number of folders with . + /// + /// The criteria to use to filter. This value can be null. + /// The number of folders. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count(CountArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Count(Interop.Folder.GetFolderCountFromDb, arguments); + } + + /// + /// Retrieves the folders. + /// + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select() + { + return Select(arguments: null); + } + + /// + /// Retrieves the folders with . + /// + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select(SelectArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Select(arguments, Interop.Folder.ForeachFolderFromDb, Folder.FromHandle); + } + + /// + /// Retrieves the folder. + /// + /// The folder id to query with. + /// The instance if the matched record was found in the database, otherwise null. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public Folder Select(string folderId) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId)); + + Interop.Folder.GetFolderFromDb(folderId, out var handle).ThrowIfError("Failed to query"); + + if (handle == IntPtr.Zero) + { + return null; + } + + try + { + return new Folder(handle); + } + finally + { + Interop.Folder.Destroy(handle); + } + } + + /// + /// Retrieves the number of media info under the folder. + /// + /// The id of the folder to count media in the folder. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountMedia(string folderId) + { + return CountMedia(folderId, null); + } + + /// + /// Retrieves the number of media info under the folder with . + /// + /// The id of the folder to count media in the folder. + /// The criteria to use to filter. This value can be null. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountMedia(string folderId, CountArguments arguments) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId)); + + return CommandHelper.Count(Interop.Folder.GetMediaCountFromDb, folderId, arguments); + } + + /// + /// Retrieves the media info under the folder. + /// + /// The id of the folder to select media in the folder. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectMedia(string folderId) + { + return SelectMedia(folderId, null); + } + + /// + /// Retrieves the media info under the folder with . + /// + /// The id of the folder to select media in the folder. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectMedia(string folderId, SelectArguments filter) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId)); + + return CommandHelper.SelectMedia(Interop.Folder.ForeachMediaFromDb, folderId, filter); + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Group.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Group.cs deleted file mode 100755 index d037f3b..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Group.cs +++ /dev/null @@ -1,137 +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.Threading.Tasks; - -namespace Tizen.Content.MediaContent -{ - /// - /// A Media Group represents logical grouping of media files with respect to their group name. - /// It is also used for filtering media items. - /// - public class Group : ContentCollection - { - private readonly string _groupName; - private readonly MediaGroupType _groupType; - private bool _disposedValue = false; - - /// - /// The name of the media group - /// - /// 3 - public string Name - { - get { return _groupName; } - } - - internal Group(string name, MediaGroupType groupType) - { - _groupName = name; - _groupType = groupType; - } - - public override void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - _disposedValue = true; - } - } - - /// - /// Gets the count of the media info for the given media group present in the media database. - /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// The number of media contents matching the filter passed - public override int GetMediaInformationCount(ContentFilter filter) - { - int mediaCount = 0; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Group.GetMediaCountFromDb(Name, _groupType, handle, out mediaCount), "Failed to GetMediaCountFromDb"); - - return mediaCount; - } - - - /// - /// Iterates through the media files with an optional filter in the given group from the media database. - /// This function gets all media files associated with the given group and meeting desired filter option. - /// If NULL is passed to the filter, no filtering is applied. - /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// List of content media items matching the passed filter - public override IEnumerable GetMediaInformations(ContentFilter filter) - { - List mediaContents = new List(); - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - Interop.Group.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) => - { - Interop.MediaInformation.SafeMediaInformationHandle newHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone MediaInformation instance"); - - MediaContentType type; - Interop.MediaInformation.GetMediaType(newHandle, out type); - if (type == MediaContentType.Image) - { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information"); - - mediaContents.Add(new ImageInformation(imageInfo, newHandle)); - } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information"); - - mediaContents.Add(new AudioInformation(audioInfo, newHandle)); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information"); - - mediaContents.Add(new VideoInformation(videoInfo, newHandle)); - } - else if (type == MediaContentType.Others) - { - mediaContents.Add(new MediaInformation(newHandle)); - } - - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Group.ForeachMediaFromDb(Name, _groupType, handle, callback, IntPtr.Zero), "Failed to get media information for the group"); - - return mediaContents; - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ImageInfo.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ImageInfo.cs new file mode 100644 index 0000000..5ea5416 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ImageInfo.cs @@ -0,0 +1,121 @@ +/* + * 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.Diagnostics; + +namespace Tizen.Content.MediaContent +{ + /// + /// Represents the image media stored in the device. + /// + public class ImageInfo : MediaInfo + { + internal ImageInfo(Interop.MediaInfoHandle handle) : base(handle) + { + IntPtr imageHandle = IntPtr.Zero; + + try + { + Interop.MediaInfo.GetImage(handle, out imageHandle).ThrowIfError("Failed to retrieve data"); + + Debug.Assert(imageHandle != IntPtr.Zero); + + Width = InteropHelper.GetValue(imageHandle, Interop.ImageInfo.GetWidth); + Height = InteropHelper.GetValue(imageHandle, Interop.ImageInfo.GetHeight); + + Orientation = InteropHelper.GetValue(imageHandle, Interop.ImageInfo.GetOrientation); + + DateTaken = InteropHelper.GetString(imageHandle, Interop.ImageInfo.GetDateTaken); + BurstId = InteropHelper.GetString(imageHandle, Interop.ImageInfo.GetBurstId); + ExposureTime = InteropHelper.GetString(imageHandle, Interop.ImageInfo.GetExposureTime); + + FNumber = InteropHelper.GetValue(imageHandle, Interop.ImageInfo.GetFNumber); + Iso = InteropHelper.GetValue(imageHandle, Interop.ImageInfo.GetISO); + + Model = InteropHelper.GetString(imageHandle, Interop.ImageInfo.GetModel); + + IsBurstShot = InteropHelper.GetValue(imageHandle, Interop.ImageInfo.IsBurstShot); + + } + finally + { + Interop.ImageInfo.Destroy(imageHandle); + } + } + + /// + /// Gets the image width in pixels. + /// + /// The image width in pixels. + public int Width { get; } + + /// + /// Gets the image height in pixels. + /// + /// The image height in pixels. + public int Height { get; } + + /// + /// Gets the orientation of image. + /// + /// The orientation of image. + public Orientation Orientation { get; } + + /// + /// Gets the date of the creation time as a formatted string. + /// + /// The date of the creation time as a formatted string. + public string DateTaken { get; } + + /// + /// Gets the burst shot id. + /// + /// The burst shot id if it is a burst shot, otherwise an empty string. + /// + public string BurstId { get; } + + /// + /// Gets the exposure time from exif. + /// + /// The exposure time from exif. + public string ExposureTime { get; } + + /// + /// Gets the FNumber from exif. + /// + /// The FNumber from exif. + public double FNumber { get; } + + /// + /// Gets the iso from exif. + /// + /// The iso from exif. + public int Iso { get; } + + /// + /// Gets the model from exif. + /// + /// The model from exif. + public string Model { get; } + + /// + /// Gets the value indicating whether the media is a burst shot image. + /// + /// true if the media is a burst shot image, otherwise false. + public bool IsBurstShot { get; } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ImageInformation.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ImageInformation.cs deleted file mode 100755 index e6922d3..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ImageInformation.cs +++ /dev/null @@ -1,347 +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.Threading.Tasks; -using System.Collections.ObjectModel; -using System.Runtime.InteropServices; - -namespace Tizen.Content.MediaContent -{ - /// - /// ImageContent class API gives the information related to the image media stored in the device - public class ImageInformation : MediaInformation - { - private readonly Interop.ImageInformation.SafeImageInformationHandle _handle; - - /// - /// Gets the id of the media. - /// - /// 3 - public string MediaId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetMediaId(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the image width in pixels. - /// - /// 3 - public int Width - { - get - { - int width = 0; - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetWidth(_handle, out width), "Failed to get value"); - - return width; - } - } - - /// - /// Gets the image height in pixels. - /// - /// 3 - public int Height - { - get - { - int height = 0; - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetHeight(_handle, out height), "Failed to get value"); - - return height; - } - } - - /// - /// Image orientation. - /// - /// 3 - public MediaContentOrientation Orientation - { - get - { - MediaContentOrientation orientation = MediaContentOrientation.NotAvailable; - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetOrientation(_handle, out orientation), "Failed to get value"); - - return orientation; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.SetOrientation(_handle, value), "Failed to set value"); - } - } - - /// - /// Gets the image creation time in seconds, since the Epoch. - /// - /// 3 - public string TakenDate - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetDateTaken(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the burst shot ID. - /// If BurstId is null, this is not a burst shot - /// - /// 3 - public string BurstId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetBurstId(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the exposure time from exif. - /// - /// 3 - public string ExposureTime - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetExposureTime(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the fnumber from exif. - /// - /// 3 - public double FNumber - { - get - { - double fNumber = 0.0; - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetFNumber(_handle, out fNumber), "Failed to get value"); - - return fNumber; - } - } - - /// - /// Gets the iso from exif. - /// - /// 3 - public int Iso - { - get - { - int iso = 0; - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetISO(_handle, out iso), "Failed to get value"); - - return iso; - } - } - - /// - /// Gets the model from exif. - /// - /// 3 - public string Model - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.GetModel(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Checks whether the media is a burst shot image. - /// The value is true if the media is a burst shot image, - /// otherwise false if the media is not a burst shot image. - /// - /// 3 - public bool IsBurstShot - { - get - { - bool isBurst = false; - MediaContentValidator.ThrowIfError( - Interop.ImageInformation.IsBurstShot(_handle, out isBurst), "Failed to get value"); - - return isBurst; - } - } - - /// - /// Iterates through the media faces with filter in the given media file from the media database. - /// If NULL is passed to the filter, no filtering is applied. - /// - /// 3 - /// - /// Task to get all the MediaFaces - /// filter for the Tags - public IEnumerable GetMediaFaces(ContentFilter filter) - { - Collection coll = new Collection(); - - Interop.MediaInformation.MediaFaceCallback callback = (IntPtr faceHandle, IntPtr userData) => - { - IntPtr newHandle = IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Face.Clone(out newHandle, faceHandle), "Failed to clone Tag"); - - coll.Add(new MediaFace(newHandle)); - return true; - }; - IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAllFaces(MediaId, filterHandle, callback, IntPtr.Zero), "Failed to get value"); - - return coll; - } - - /// - /// Gets the number of faces for the passed filter in the given media ID from the media database. - /// - /// 3 - /// - /// int count - /// The Filter for matching Face - public int GetMediaFaceCount(ContentFilter filter) - { - int count = 0; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetFaceCount(MediaId, handle, out count), "Failed to get value"); - - return count; - } - - - /// - /// Inserts a MediaFace item to the media database - /// - /// 3 - /// The image on which face is to be added - /// The dimensions of the face - /// The MediaFace instance - public MediaFace AddFace(ImageInformation image, FaceRect rect) - { - MediaFace face = new MediaFace(image, rect); - ContentManager.Database.Insert(face); - return face; - } - - /// - /// Deletes the MediaFace from the media database. - /// - /// 3 - /// The face instance to be deleted - public void DeleteFace(MediaFace face) - { - ContentManager.Database.Delete(face); - } - - /// - /// Updates the MediaFace in the media database - /// - /// 3 - /// The MediaFace object to be updated - public void UpdateFace(MediaFace face) - { - ContentManager.Database.Update(face); - } - - internal IntPtr ImageHandle - { - get - { - return _handle.DangerousGetHandle(); - } - } - - internal ImageInformation(Interop.ImageInformation.SafeImageInformationHandle handle, Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle) - : base(mediaInformationHandle) - { - _handle = handle; - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/InteropHelper.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/InteropHelper.cs new file mode 100644 index 0000000..1d9d933 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/InteropHelper.cs @@ -0,0 +1,80 @@ +/* + * 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.Runtime.InteropServices; + +namespace Tizen.Content.MediaContent +{ + internal static class InteropHelper + { + internal delegate MediaContentError GetStringFunc(T handle, out IntPtr value); + + internal static string GetString(T handle, GetStringFunc func) + { + IntPtr val = IntPtr.Zero; + try + { + func(handle, out val).ThrowIfError("Failed to get value"); + + if (val == IntPtr.Zero) + { + return string.Empty; + } + + return Marshal.PtrToStringAnsi(val); + } + finally + { + Interop.Libc.Free(val); + } + } + + internal delegate MediaContentError GetValueFunc(T handle, out TValue value); + + internal static TValue GetValue(T handle, GetValueFunc func) + { + func(handle, out var val).ThrowIfError("Failed to get value"); + + return val; + } + + internal static TValue GetValue(IntPtr handle, GetValueFunc func) + { + func(handle, out var val).ThrowIfError("Failed to get value"); + + return val; + } + + internal static TValue GetValue(Interop.MediaInfoHandle handle, + GetValueFunc func) + { + func(handle, out var val).ThrowIfError("Failed to get value"); + + return val; + } + + internal static DateTimeOffset GetDateTime(T handle, + GetValueFunc func) + { + IntPtr time = IntPtr.Zero; + + func(handle, out time).ThrowIfError("Failed to get value"); + + return DateTimeOffset.FromUnixTimeSeconds(time.ToInt64()); + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaBookmark.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaBookmark.cs deleted file mode 100755 index 07e14bb..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaBookmark.cs +++ /dev/null @@ -1,129 +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.Runtime.InteropServices; - -namespace Tizen.Content.MediaContent -{ - /// - /// A MediaBookmark allows you to mark interesting moment in a media(video and audio) to enable fast searching. - /// The MediaBookmark Information API provides functions to get information about bookmarks associated with video and audio items. - /// - public class MediaBookmark : IDisposable - { - private IntPtr _bookmarkHandle = IntPtr.Zero; - private bool _disposedValue = false; - - private IntPtr Handle - { - get - { - if (_bookmarkHandle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(MediaBookmark)); - } - - return _bookmarkHandle; - } - } - internal MediaBookmark(IntPtr handle) - { - _bookmarkHandle = handle; - } - - ~MediaBookmark() - { - Dispose(false); - } - /// - /// The media bookmark ID - /// - /// 3 - public int Id - { - get - { - int id; - MediaContentValidator.ThrowIfError( - Interop.MediaBookmark.GetBookmarkId(Handle, out id), "Failed to get bookmark id"); - - return id; - } - } - - /// - /// The thumbnail path of media bookmark - /// - /// 3 - public string ThumbnailPath - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaBookmark.GetThumbnailPath(Handle, out val), "Failed to get bookmark thumbnail"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// The bookmark time offset (in milliseconds) - /// - /// 3 - public uint Offset - { - get - { - uint offset; - MediaContentValidator.ThrowIfError( - Interop.MediaBookmark.GetMarkedTime(Handle, out offset), "Failed to get bookmarked time"); - - return offset; - } - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - if (_bookmarkHandle != IntPtr.Zero) - { - Interop.MediaBookmark.Destroy(_bookmarkHandle); - _bookmarkHandle = IntPtr.Zero; - } - - _disposedValue = true; - } - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaCommand.cs new file mode 100644 index 0000000..5ae3bf5 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaCommand.cs @@ -0,0 +1,143 @@ +/* + * 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; + +namespace Tizen.Content.MediaContent +{ + /// + /// is a base class for command classes. + /// + public abstract class MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + protected MediaCommand(MediaDatabase database) + { + Database = database ?? throw new ArgumentNullException(nameof(database)); + + if (database.IsDisposed) + { + throw new ObjectDisposedException(nameof(database)); + } + } + + internal void ValidateDatabase() + { + Database.ValidateState(); + } + + /// + /// Gets the . + /// + /// The which commands execute on. + public MediaDatabase Database { get; } + } + + /// + /// Provides a means of reading results obtained by executing a query. + /// + public interface IMediaDataReader + { + /// + /// Advances to the next record. + /// + /// true if there are more rows; otherwise false. + bool Read(); + + /// + /// Gets the current record. + /// + /// The current record object. + object Current { get; } + } + + /// + /// Provides a means of reading results obtained by executing a query. + /// + /// + public class MediaDataReader : IMediaDataReader, IDisposable + { + private readonly IEnumerator _enumerator; + + internal MediaDataReader(IEnumerable items) + { + _enumerator = items.GetEnumerator(); + } + + /// + /// Gets the current record. + /// + /// The current record if the position is valid; otherwise null. + public TRecord Current + { + get + { + ValidateNotDisposed(); + return _enumerator.Current; + } + } + + /// + /// Advances to the next record. + /// + /// true if there are more rows; otherwise false. + public bool Read() + { + ValidateNotDisposed(); + return _enumerator.MoveNext(); + } + + object IMediaDataReader.Current => Current; + + #region IDisposable Support + private bool _disposed = false; + + /// + /// Disposes of the resources (other than memory) used by the MediaDataReader. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + _disposed = true; + } + } + + /// + /// Releases all resources used by the current instance. + /// + public void Dispose() + { + Dispose(true); + } + + internal void ValidateNotDisposed() + { + if (_disposed) + { + throw new ObjectDisposedException(GetType().Name); + } + } + #endregion + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaContentEnums.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaContentEnums.cs deleted file mode 100755 index 2c59329..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaContentEnums.cs +++ /dev/null @@ -1,411 +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. -*/ - - - -namespace Tizen.Content.MediaContent -{ - /// - /// Enumeration for ordering - /// - /// 3 - public enum ContentOrder - { - /// - /// Ascending order - /// - /// 3 - Asc, - /// - /// Descending order - /// - /// 3 - Desc - } - - /// - /// Enumeration for collations. - /// - /// 3 - public enum ContentCollation - { - /// - /// Default collation BINARY - /// - /// 3 - Default, - /// - /// Collation NOCASE, not case sensitive - /// - /// 3 - Nocase, - /// - /// Collation RTRIM, trailing space characters are ignored - /// - /// 3 - Rtim, - /// - /// Collation LOCALIZATION, NOCASE also applied - /// - /// 3 - Localized - } - - /// - /// Enumeration for a media group. - /// - /// 3 - public enum MediaGroupType - { - /// - /// Media group ID for display name - /// - /// 3 - DisplayName, - /// - /// Media group ID for a media type - /// - /// 3 - Type, - /// - /// Media group ID for a mime type - /// - /// 3 - MimeType, - /// - /// Media group ID for content size - /// - /// 3 - Size, - /// - /// Media group ID for the added time - /// - /// 3 - AddedTime, - /// - /// Media group ID for the modified time - /// - /// 3 - ModifiedTime, - /// - /// Media group ID for a content title - /// - /// 3 - Title, - /// - /// Media group ID for an artist - /// - /// 3 - Artist, - /// - /// Media group ID for an album artist - /// - /// 3 - AlbumArtist, - /// - /// Media group ID for a genre - /// - /// 3 - Genre, - /// - /// Media group ID for a composer - /// - /// 3 - Composer, - /// - /// Media group ID for a year - /// - /// 3 - Year, - /// - /// Media group ID for the recorded date - /// - /// 3 - RecordedDate, - /// - /// Media group ID for the copyright - /// - /// 3 - Copyright, - /// - /// Media group ID for a track number - /// - /// 3 - Tracknum, - /// - /// Media group ID for a description - /// - /// 3 - Description, - /// - /// Media group ID for the longitude - /// - /// 3 - Longitude, - /// - /// Media group ID for the latitude - /// - /// 3 - Latitude, - /// - /// Media group ID for the altitude - /// - /// 3 - Altitude, - /// - /// Media group ID for the burst shot - /// - /// 3 - BurstImage, - /// - /// Media group ID for a rating - /// - /// 3 - Rating, - /// - /// Media group ID for an author - /// - /// 3 - Author, - /// - /// Media group ID for a provide - /// - /// 3 - Provider, - /// - /// Media group ID for the content name - /// - /// 3 - ContentName, - /// - /// Media group ID for a category - /// - /// 3 - Category, - /// - /// Media group ID for a location tag - /// - /// 3 - LocationTag, - /// - /// Media group ID for an age rating - /// - /// 3 - AgeRating, - /// - /// Media group ID for a keyword - /// - /// 3 - Keyword, - /// - /// Media group ID for the weather - /// - /// 3 - Weather, - /// - /// Invalid media group ID - /// - /// 3 - Max - } - - /// - /// Enum to give the type of storage. - /// - /// 3 - public enum ContentStorageType : int - { - /// - /// The device's internal storage - /// - /// 3 - Internal = 0, - /// - /// The device's external storage like sd card - /// - /// 3 - External = 1, - /// - /// The external USB storage - /// - /// 3 - ExternalUSB = 2 - }; - - /// - /// Enums for media database update type - /// - /// 3 - public enum MediaContentDBUpdateType - { - /// - /// Updating the database with inserts. - /// - /// 3 - Insert, - /// - /// Updating the database with removes. - /// - /// 3 - Delete, - /// - /// Updating the database with updates. - /// - /// 3 - Update - } - - /// - /// Enums for the type of item updated in media database - /// - /// 3 - public enum MediaContentUpdateItemType - { - /// - /// The file information is updated. - /// - /// 3 - File, - /// - /// The folder information and the file information included in the folder are updated. - /// - /// 3 - Directory - } - - /// - /// Enums for content collection types - /// - /// 3 - public enum ContentCollectionType - { - /// - ///Content Collection type folder - /// - /// 3 - Folder, - /// - ///Content Collection type storage - /// - /// 3 - Storage, - /// - /// Content Collection type album - /// - /// 3 - Album, - /// - ///Content Collection type playlist - /// - /// 3 - PlayList, - /// - ///Content Collection type tag - /// - /// 3 - Tag, - /// - ///Content Collection type group - /// - /// 3 - Group - } - /// - /// Enum to give the type of media information. - /// - /// 3 - public enum MediaContentType : int - { - /// - /// The type of an image. - /// - /// 3 - Image = 0, - /// - /// The type of a video. - /// - /// 3 - Video = 1, - /// - /// The type of sound. - /// - /// 3 - Sound = 2, - /// - /// The type of music. - /// - /// 3 - Music = 3, - /// - /// The type of other. - /// - /// 3 - Others = 4 - }; - - /// - /// Enum to give the orientation type of the media. - /// - /// 3 - public enum MediaContentOrientation : int - { - /// - /// Not available. - /// - /// 3 - NotAvailable = 0, - /// - /// Normal. - /// - /// 3 - Normal = 1, - /// - /// Flip horizontal. - /// - /// 3 - HFlip = 2, - /// - /// Rotate 180 degrees. - /// - /// 3 - Rot180 = 3, - /// - /// Flip vertical. - /// - /// 3 - VFlip = 4, - /// - /// Transpose. - /// - /// 3 - Transpose = 5, - /// - /// Rotate 90 degrees. - /// - /// 3 - Rot90 = 6, - /// - /// Transverse. - /// - /// 3 - Transverse = 7, - /// - /// Rotate 270 degrees. - /// - /// 3 - Rot270 = 8 - }; -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaContentError.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaContentError.cs index 421c370..5e0cd5d 100755 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaContentError.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaContentError.cs @@ -1,32 +1,28 @@ -/* -* 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. -*/ - +/* + * 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.Diagnostics; using System.IO; +using System.Linq; using Tizen.Internals.Errors; namespace Tizen.Content.MediaContent { - /// - /// Enumeration for media content's error code - /// - /// 3 - /// error occurs when the device does not support the function. - public enum MediaContentError + internal enum MediaContentError { None = ErrorCode.None, InvalidParameter = ErrorCode.InvalidParameter, @@ -42,38 +38,56 @@ namespace Tizen.Content.MediaContent NotSupported = ErrorCode.NotSupported, } - internal class MediaContentValidator + internal static class MediaContentErrorExtensions { - internal const string LogTag = "Tizen.Content.MediaContent"; + internal static MediaContentError Ignore(this MediaContentError err, params MediaContentError[] ignores) + { + if (ignores.Contains(err)) + { + return MediaContentError.None; + } + return err; + } - internal static void ThrowIfError(MediaContentError err, string msg) + + internal static void ThrowIfError(this MediaContentError err, string msg) { + if (err == MediaContentError.None) + { + return; + } + + throw err.AsException(msg); + } + + internal static Exception AsException(this MediaContentError err, string msg) + { + Debug.Assert(err != MediaContentError.None); + switch (err) { case MediaContentError.InvalidParameter: - throw new ArgumentException(msg); + return new ArgumentException($"{msg}."); case MediaContentError.OutOfMemory: - throw new OutOfMemoryException(msg); + return new OutOfMemoryException($"{msg}."); case MediaContentError.InvalidOperation: - throw new InvalidOperationException(msg); + return new InvalidOperationException($"{msg}."); case MediaContentError.FileNoSpaceOnDevice: - throw new IOException(msg); + return new IOException($"{msg} : {err}."); case MediaContentError.PermissionDenied: - throw new UnauthorizedAccessException(msg); + return new UnauthorizedAccessException($"{msg}."); case MediaContentError.DatabaseFailed: - throw new InvalidOperationException("[DB Failed]" + msg); + return new MediaDatabaseException(MediaDatabaseError.OperationFailed); case MediaContentError.DatabaseBusy: - throw new InvalidOperationException("[DB Busy]" + msg); + return new MediaDatabaseException(MediaDatabaseError.DatabaseBusy); case MediaContentError.NetworkFailed: - throw new InvalidOperationException("[Network Error]" + msg); + return new InvalidOperationException($"{msg} : {err}."); case MediaContentError.UnsupportedContent: - throw new PlatformNotSupportedException(msg); - } - } + return new UnsupportedContentException(); - internal static string CheckString(string value) - { - return (value != null) ? value : ""; + default: + return new InvalidOperationException($"Unknown Error : {err.ToString()}, {msg}."); + } } } } diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabase.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabase.cs new file mode 100644 index 0000000..d9a152e --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabase.cs @@ -0,0 +1,466 @@ +/* + * 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.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Tizen.Content.MediaContent +{ + /// + /// Provides the ability to connect to and manage the database. + /// + public class MediaDatabase : IDisposable + { + /// + /// Initializes a new instance of the class. + /// + public MediaDatabase() + { + } + + private object _lock = new object(); + + /// + /// Connects to the database. + /// + /// The database is already connected. + /// The has already been disposed of. + /// An error occurred while connecting. + public void Connect() + { + ValidateNotDisposed(); + + lock (_lock) + { + if (IsConnected) + { + throw new InvalidOperationException("The database is already connected."); + } + + Interop.Content.Connect().ThrowIfError("Failed to connect"); + + IsConnected = true; + } + } + + /// + /// Disconnects from the media database. + /// + /// The database is not connected. + /// The has already been disposed of. + /// An error occurred while connecting. + public void Disconnect() + { + ValidateNotDisposed(); + + lock (_lock) + { + if (!IsConnected) + { + throw new InvalidOperationException("The database is not connected."); + } + + Interop.Content.Disconnect().ThrowIfError("Failed to disconnect"); + + IsConnected = false; + } + } + + private static readonly Interop.Content.MediaContentDBUpdatedCallback _mediaInfoUpdatedCb = ( + MediaContentError error, int pid, ItemType updateItem, OperationType updateType, + MediaType mediaType, string uuid, string filePath, string mimeType, IntPtr _) => + { + if (updateItem == ItemType.Directory) + { + return; + } + + _mediaInfoUpdated?.Invoke( + null, new MediaInfoUpdatedEventArgs(pid, updateType, mediaType, uuid, filePath, mimeType)); + }; + + private static IntPtr _mediaInfoUpdatedHandle = IntPtr.Zero; + private static event EventHandler _mediaInfoUpdated; + private static readonly object _mediaInfoUpdatedLock = new object(); + + /// + /// Occurs when there is a change for media in the database. + /// + public static event EventHandler MediaInfoUpdated + { + add + { + lock (_mediaInfoUpdatedLock) + { + if (_mediaInfoUpdated == null) + { + Interop.Content.AddDbUpdatedCb(_mediaInfoUpdatedCb, IntPtr.Zero, + out _mediaInfoUpdatedHandle).ThrowIfError("Failed to register an event handler"); + } + + _mediaInfoUpdated += value; + } + } + remove + { + if (value == null) + { + return; + } + + lock (_mediaInfoUpdatedLock) + { + if (_mediaInfoUpdated == value) + { + Interop.Content.RemoveDbUpdatedCb(_mediaInfoUpdatedHandle).ThrowIfError("Failed to unregister"); + } + + _mediaInfoUpdated -= value; + } + } + } + + + private static readonly Interop.Content.MediaContentDBUpdatedCallback _folderUpdatedCb = ( + MediaContentError error, int pid, ItemType updateItem, OperationType updateType, + MediaType mediaType, string uuid, string filePath, string mimeType, IntPtr _) => + { + if (updateItem == ItemType.File) + { + return; + } + + _folderUpdated?.Invoke(null, new FolderUpdatedEventArgs(updateType, uuid, filePath)); + }; + + private static IntPtr _folderUpdatedHandle = IntPtr.Zero; + private static event EventHandler _folderUpdated; + private static readonly object _folderUpdatedLock = new object(); + + /// + /// Occurs when there is a change for folder in the database. + /// + public static event EventHandler FolderUpdated + { + add + { + lock (_folderUpdatedLock) + { + if (_folderUpdated == null) + { + Interop.Content.AddDbUpdatedCb(_folderUpdatedCb, IntPtr.Zero, + out _folderUpdatedHandle).ThrowIfError("Failed to register an event handler"); + } + + _folderUpdated += value; + } + } + remove + { + if (value == null) + { + return; + } + + lock (_folderUpdatedLock) + { + if (_folderUpdated == value) + { + Interop.Content.RemoveDbUpdatedCb(_folderUpdatedHandle).ThrowIfError("Failed to unregister"); + } + + _folderUpdated -= value; + } + } + } + + /// + /// Requests to scan a media file. + /// + /// The path of the media to be scanned. + /// + /// It requests to scan a media file to the media server.\n + /// If the specified file is not registered to the database yet, + /// the media file information will be added to the database.\n + /// If it is already registered to the database, the media information is refreshed.\n + /// If the specified file does not exist, + /// the record of the media file will be deleted from the database.\n + /// \n + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The database is not connected. + /// The has already been disposed of. + /// is null. + /// + /// is a zero-length string, contains only white space.\n + /// -or-\n + /// contains a hidden path that starts with '.'.\n + /// -or-\n + /// contains a directory containing the ".scan_ignore" file. + /// + /// The caller has no required privilege. + public void ScanFile(string path) + { + ValidateState(); + + ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path)); + + Interop.Content.ScanFile(path).Ignore(MediaContentError.InvalidParameter).ThrowIfError("Failed to scan"); + } + + /// + /// Requests to scan a folder, recursively. + /// + /// + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The path to scan. + /// Folders that contains a file named ".scan_ignore" will not be scanned. + /// A task that represents the asynchronous scan operation. + /// The database is not connected. + /// The has already been disposed of. + /// The caller has no required privilege. + /// is null. + /// + /// is a zero-length string, contains only white space.\n + /// -or-\n + /// contains a hidden path that starts with '.'.\n + /// -or-\n + /// contains a directory containing the ".scan_ignore" file. + /// + public Task ScanFolderAsync(string folderPath) + { + return ScanFolderAsync(folderPath, true); + } + + /// + /// Requests to scan a folder. + /// + /// + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The path to scan. + /// The value indicating if the folder is to recursively scanned. + /// Folders that contains a file named ".scan_ignore" will not be scanned. + /// A task that represents the asynchronous scan operation. + /// The database is not connected. + /// The has already been disposed of. + /// The caller has no required privilege. + /// is null. + /// + /// is a zero-length string, contains only white space.\n + /// -or-\n + /// contains a hidden path that starts with '.'.\n + /// -or-\n + /// contains a directory containing the ".scan_ignore" file. + /// + public Task ScanFolderAsync(string folderPath, bool recursive) + { + return ScanFolderAsync(folderPath, recursive, CancellationToken.None); + } + + /// + /// Requests to scan a folder, recursively. + /// + /// + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The path to scan. + /// The token to stop scanning. + /// Folders that contains a file named ".scan_ignore" will not be scanned. + /// A task that represents the asynchronous scan operation. + /// The database is not connected. + /// The has already been disposed of. + /// The caller has no required privilege. + /// is null. + /// + /// is a zero-length string, contains only white space.\n + /// -or-\n + /// contains a hidden path that starts with '.'.\n + /// -or-\n + /// contains a directory containing the ".scan_ignore" file. + /// + public Task ScanFolderAsync(string folderPath, CancellationToken cancellationToken) + { + return ScanFolderAsync(folderPath, true, cancellationToken); + } + + /// + /// Requests to scan a folder, recursively. + /// + /// + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The path to scan. + /// The value indicating if the folder is to recursively scanned. + /// The token to stop scanning. + /// Folders that contains a file named ".scan_ignore" will not be scanned. + /// A task that represents the asynchronous scan operation. + /// The database is not connected. + /// The has already been disposed of. + /// The caller has no required privilege. + /// is null. + /// + /// is a zero-length string, contains only white space.\n + /// -or-\n + /// contains a hidden path that starts with '.'.\n + /// -or-\n + /// contains a directory containing the ".scan_ignore" file. + /// + public Task ScanFolderAsync(string folderPath, bool recursive, CancellationToken cancellationToken) + { + ValidateState(); + + ValidationUtil.ValidateNotNullOrEmpty(folderPath, nameof(folderPath)); + + return cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) : + ScanFolderAsyncCore(folderPath, recursive, cancellationToken); + } + + private async Task ScanFolderAsyncCore(string folderPath, bool recursive, CancellationToken cancellationToken) + { + var tcs = new TaskCompletionSource(); + + using (var cbKeeper = ObjectKeeper.Get(GetScanCompletedCallback(tcs))) + using (RegisterCancellationAction(tcs, folderPath, cancellationToken)) + { + + Interop.Content.ScanFolder(folderPath, recursive, cbKeeper.Target) + .ThrowIfError("Failed to scan"); + + await tcs.Task; + } + } + + private static Interop.Content.MediaScanCompletedCallback GetScanCompletedCallback(TaskCompletionSource tcs) + { + return (scanResult, _) => + { + if (scanResult == MediaContentError.None) + { + tcs.TrySetResult(true); + } + else + { + tcs.TrySetException(scanResult.AsException("Failed to scan")); + } + }; + } + + private static IDisposable RegisterCancellationAction(TaskCompletionSource tcs, + string folderPath, CancellationToken cancellationToken) + { + if (cancellationToken.CanBeCanceled == false) + { + return null; + } + + return cancellationToken.Register(() => + { + if (tcs.Task.IsCompleted) + { + return; + } + + Interop.Content.CancelScanFolder(folderPath).ThrowIfError("Failed to cancel scanning"); + tcs.TrySetCanceled(); + }); + } + + internal bool IsConnected { get; set; } + + internal void ValidateState() + { + ValidateNotDisposed(); + + if (IsConnected == false) + { + throw new InvalidOperationException("Database is not connected."); + } + } + + private void ValidateNotDisposed() + { + if (IsDisposed) + { + throw new ObjectDisposedException(nameof(MediaDatabase)); + } + } + + #region IDisposable Support + private bool _disposed = false; + + /// + /// Disposes of the resources (other than memory) used by the MediaDatabase. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (IsConnected) + { + var disconnectResult = Interop.Content.Disconnect(); + + if (disconnectResult != MediaContentError.None) + { + Log.Warn(nameof(MediaDatabase), $"Failed to disconnect {disconnectResult.ToString()}."); + } + } + + _disposed = true; + } + } + + /// + /// Releases all resources. + /// + public void Dispose() + { + Dispose(true); + } + + /// + /// Gets the value indicating whether the database has been disposed of. + /// + /// true if the database has been disposed of; otherwise, false. + public bool IsDisposed => _disposed; + #endregion + + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabaseException.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabaseException.cs new file mode 100644 index 0000000..34723ba --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabaseException.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; + +namespace Tizen.Content.MediaContent +{ + /// + /// Specifies database errors. + /// + public enum MediaDatabaseError + { + /// + /// Operation failed. + /// + OperationFailed, + + /// + /// Operation failed because the database is busy. + /// + DatabaseBusy + } + + /// + /// The exception that is thrown when an database operation failed. + /// + public class MediaDatabaseException : Exception + { + internal MediaDatabaseException(MediaDatabaseError error) : this(error, error.ToString()) + { + } + + internal MediaDatabaseException(MediaDatabaseError error, string message) : this(error, message, null) + { + } + + internal MediaDatabaseException(MediaDatabaseError error, string message, Exception innerException) : + base(message, innerException) + { + Error = error; + } + + /// + /// Gets the error that causes the exception. + /// + /// The that causes the exception. + public MediaDatabaseError Error { get; } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaFace.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaFace.cs deleted file mode 100755 index 134ab1f..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaFace.cs +++ /dev/null @@ -1,226 +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.Runtime.InteropServices; - -namespace Tizen.Content.MediaContent -{ - /// - /// The Media Face Information API provides functions to manage the face information in the image files. - /// - public class MediaFace : IDisposable - { - private IntPtr _faceHandle = IntPtr.Zero; - private bool _disposedValue = false; - internal IntPtr Handle - { - get - { - if (_faceHandle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(MediaFace)); - } - - return _faceHandle; - } - } - - - internal MediaFace(IntPtr handle) - { - _faceHandle = handle; - } - - /// - /// Create Face for Given Image - /// - /// 3 - /// - ///image item through which FaceRect has to be tagged. - /// - ///Position about the detacted face in the media - internal MediaFace(MediaInformation image, FaceRect rect) - { - MediaContentValidator.ThrowIfError( - Interop.Face.Create(image.MediaId, out _faceHandle), "Failed to create MediaFace"); - - try - { - MediaContentValidator.ThrowIfError( - Interop.Face.SetFaceRect(Handle, rect.X, rect.Y, rect.Width, rect.Height), "Failed to set Rect to MediaFace"); - } - catch (Exception) - { - Interop.Face.Destroy(_faceHandle); - throw; - } - } - - ~MediaFace() - { - Dispose(false); - } - - /// - /// The Media Face Information API provides functions to manage the face information in the image files. - /// - /// 3 - public FaceRect Rect - { - get - { - int x; - int y; - int width; - int height; - MediaContentValidator.ThrowIfError( - Interop.Face.GetFaceRect(Handle, out x, out y, out width, out height), "Failed to get Rect for the Face"); - - return new FaceRect(x, y, width, height); - } - - set - { - FaceRect rect = (FaceRect)value; - MediaContentValidator.ThrowIfError( - Interop.Face.SetFaceRect(Handle, rect.X, rect.Y, rect.Width, rect.Height), "Failed to set Rect for the Face"); - } - } - - /// - /// Face id. - /// - /// 3 - public string Id - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Face.GetFaceId(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Media uuid from the face - /// - /// 3 - public string MediaInformationId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Face.GetMediaId(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - /// - /// Tag name for the MediaFace. - /// - /// 3 - public string Tag - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Face.GetTag(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Face.SetTag(Handle, value), "Failed to set value"); - } - } - - /// - /// Orientation Value for the face - /// - /// 3 - public MediaContentOrientation Orientation - { - get - { - int orientation; - MediaContentValidator.ThrowIfError( - Interop.Face.GetOrientation(Handle, out orientation), "Failed to value"); - - return (MediaContentOrientation)orientation; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Face.SetOrientation(Handle, (int)value), "Failed to set value"); - } - } - - /// - /// Dispose API for closing the internal resources. - /// - /// 3 - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - if (_faceHandle != IntPtr.Zero) - { - Interop.Face.Destroy(_faceHandle); - _faceHandle = IntPtr.Zero; - } - - _disposedValue = true; - } - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaFolder.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaFolder.cs deleted file mode 100755 index af120ca..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaFolder.cs +++ /dev/null @@ -1,330 +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.Runtime.InteropServices; -using System.Threading.Tasks; - -namespace Tizen.Content.MediaContent -{ - /// - /// A Folder is used to organize media content files i.e. image, audio, video files, in the physical storage of the device. - /// The Media Folder API provides functions to get basic information about existing folders e.g. folder name, path and storage type. - /// It also provides functions to get information related to media items present in the folder. - /// - public class MediaFolder : ContentCollection - { - private IntPtr _folderHandle = IntPtr.Zero; - private bool _disposedValue = false; - internal IntPtr Handle - { - get - { - if (_folderHandle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(MediaFolder)); - } - - return _folderHandle; - } - } - /// - /// The ID of the media folder. For each MediaFolder this id is unique. - /// - /// 3 - public string Id - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Folder.GetFolderId(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// ParentId of the MediaFolder that is the ID of the upper media folder (parent folder). - /// - /// 3 - public string ParentId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Folder.GetParentFolderId(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// The path of the media folder - /// - /// 3 - public string FolderPath - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Folder.GetPath(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// The name of the media folder - /// - /// 3 - public string Name - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Folder.GetName(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Folder.SetName(Handle, value), "Failed to set value"); - } - } - - /// - /// The storage type of the media folder. - /// Storage types give information about the location of storage like Internal memory, USB or External Storage etc... - /// - /// 3 - public ContentStorageType StorageType - { - get - { - ContentStorageType type; - MediaContentValidator.ThrowIfError( - Interop.Folder.GetStorageType(Handle, out type), "Failed to get value"); - - return type; - } - } - - /// - /// The storage id of the media folder - /// - /// 3 - public string StorageId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Folder.GetStorageId(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// The modified date of the media folder - /// - /// 3 - public DateTime ModifiedTime - { - get - { - DateTime date; - MediaContentValidator.ThrowIfError( - Interop.Folder.GetModifiedTime(Handle, out date), "Failed to get value"); - - return date; - } - } - - /// - /// The folder order value. Get/Set the folder viewing order. - /// Default Order value is zero. - /// If you set the order value for each folder, you can sort in ascending or descending order as the set order values using the filter. - /// - /// 3 - public int Order - { - get - { - int order; - MediaContentValidator.ThrowIfError( - Interop.Folder.GetOrder(Handle, out order), "Failed to get value"); - - return order; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Folder.SetOrder(Handle, value), "Failed to set value"); - } - } - - internal MediaFolder(IntPtr handle) - { - _folderHandle = handle; - } - - /// - /// Gets the count of media files for the passed filter in the given folder from the media database. - /// If NULL is passed to the filter, no filtering is applied. - /// - /// 3 - /// ContentFilter used to match media content from teh media database. - /// The number of media contents matching the filter passed - public override int GetMediaInformationCount(ContentFilter filter) - { - int mediaCount; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Folder.GetMediaCountFromDb(Id, handle, out mediaCount), "Failed to get count"); - - return mediaCount; - } - - ~MediaFolder() - { - Dispose(false); - } - - public override void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - if (_folderHandle != IntPtr.Zero) - { - Interop.Folder.Destroy(_folderHandle); - _folderHandle = IntPtr.Zero; - } - - _disposedValue = true; - } - } - - /// - /// Iterates through the media files with an filter in the given folder from the media database. - /// This function gets all media files associated with the given folder and meeting desired filter option. - /// If NULL is passed to the filter, no filtering is applied. - /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// List of content media items matching the passed filter - public override IEnumerable GetMediaInformations(ContentFilter filter) - { - List mediaContents = new List(); - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - - Interop.Folder.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) => - { - Interop.MediaInformation.SafeMediaInformationHandle newHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone"); - - MediaContentType type; - Interop.MediaInformation.GetMediaType(newHandle, out type); - if (type == MediaContentType.Image) - { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information"); - - mediaContents.Add(new ImageInformation(imageInfo, newHandle)); - } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information"); - - mediaContents.Add(new AudioInformation(audioInfo, newHandle)); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information"); - - mediaContents.Add(new VideoInformation(videoInfo, newHandle)); - } - else if (type == MediaContentType.Others) - { - mediaContents.Add(new MediaInformation(newHandle)); - } - - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Folder.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero), "Failed to get information"); - - return mediaContents; - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs new file mode 100644 index 0000000..0072d38 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs @@ -0,0 +1,264 @@ +/* + * 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.Content.MediaContent +{ + + /// + /// Represents the information related to the media stored. + /// + /// + /// + public class MediaInfo + { + internal MediaInfo(Interop.MediaInfoHandle handle) + { + Id = InteropHelper.GetString(handle, Interop.MediaInfo.GetMediaId); + + Path = InteropHelper.GetString(handle, Interop.MediaInfo.GetFilePath); + DisplayName = InteropHelper.GetString(handle, Interop.MediaInfo.GetDisplayName); + + MediaType = InteropHelper.GetValue(handle, Interop.MediaInfo.GetMediaType); + + MimeType = InteropHelper.GetString(handle, Interop.MediaInfo.GetMimeType); + + FileSize = InteropHelper.GetValue(handle, Interop.MediaInfo.GetSize); + + DateAdded = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetAddedTime); + DateModified = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetModifiedTime); + Timeline = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetTimeline); + + ThumbnailPath = InteropHelper.GetString(handle, Interop.MediaInfo.GetThumbnailPath); + Description = InteropHelper.GetString(handle, Interop.MediaInfo.GetDescription); + + Longitude = InteropHelper.GetValue(handle, Interop.MediaInfo.GetLongitude); + Latitude = InteropHelper.GetValue(handle, Interop.MediaInfo.GetLatitude); + Altitude = InteropHelper.GetValue(handle, Interop.MediaInfo.GetAltitude); + + Weather = InteropHelper.GetString(handle, Interop.MediaInfo.GetWeather); + Rating = InteropHelper.GetValue(handle, Interop.MediaInfo.GetRating); + IsFavorite = InteropHelper.GetValue(handle, Interop.MediaInfo.GetFavorite); + Provider = InteropHelper.GetString(handle, Interop.MediaInfo.GetProvider); + Title = InteropHelper.GetString(handle, Interop.MediaInfo.GetTitle); + Category = InteropHelper.GetString(handle, Interop.MediaInfo.GetCategory); + LocationTag = InteropHelper.GetString(handle, Interop.MediaInfo.GetLocationTag); + AgeRating = InteropHelper.GetString(handle, Interop.MediaInfo.GetAgeRating); + StorageId = InteropHelper.GetString(handle, Interop.MediaInfo.GetStorageId); + IsDrm = InteropHelper.GetValue(handle, Interop.MediaInfo.IsDrm); + + StorageType = InteropHelper.GetValue(handle, Interop.MediaInfo.GetStorageType); + } + + /// + /// Gets the id of media. + /// + /// The unique id of media. + public string Id { get; } + + /// + /// Gets the path to media. + /// + /// The full path of the media file. + public string Path { get; } + + /// + /// Gets the name of media. + /// + /// The base name of the media file. + public string DisplayName { get; } + + /// + /// Gets the of media. + /// + /// The of media. + public MediaType MediaType { get; } + + /// + /// Gets the mime type from media. + /// + /// The mime type of media. + public string MimeType { get; } + + /// + /// Gets the file size of media in bytes. + /// + /// The file size of media in bytes. + public long FileSize { get; } + + /// + /// Gets the date of addition of media. + /// + /// The date of addition of media. + public DateTimeOffset DateAdded { get; } + + /// + /// Gets the date of modification of media. + /// + /// The date of modification of media. + public DateTimeOffset DateModified { get; } + + /// + /// Gets the timeline of media. + /// + /// + /// The creation date if the file has the creation information (like recorded date or Image creation date), + /// otherwise the modified date. + /// + public DateTimeOffset Timeline { get; } + + /// + /// Gets the thumbnail of media. + /// + /// The thumbnail path of media. + public string ThumbnailPath { get; } + + /// + /// Gets the description of media. + /// + /// The description from the metadata. + public string Description { get; } + + /// + /// Gets the longitude of media. + /// + /// The longitude. + public double Longitude { get; } + + /// + /// Gets the latitude of media. + /// + /// The latitude. + public double Latitude { get; } + + /// + /// Gets the altitude of media. + /// + /// The altitude. + public double Altitude { get; } + + /// + /// Gets the weather information of media. + /// + /// The weather information which a user sets. + public string Weather { get; } + + /// + /// Gets the rating of media. + /// + /// The rating from the metadata. + public int Rating { get; } + + /// + /// Gets the favorite status of media. + /// + /// true if media is set as favorite, otherwise false. + public bool IsFavorite { get; } + + /// + /// Gets the provider of media. + /// + /// The provider which a user sets. + public string Provider { get; } + + /// + /// Gets the title of media. + /// + /// The title of media. + public string Title { get; } + + /// + /// Gets the category of media. + /// + /// The category which a user sets. + public string Category { get; } + + /// + /// Gets the location tag of media. + /// + /// The location tag which a user sets. + public string LocationTag { get; } + + /// + /// Gets the age rating of media. + /// + /// The age rating which a user sets. + public string AgeRating { get; } + + /// + /// Gets the storage id of the storage that the media is stored on. + /// + /// The storage id of the storage that the media is stored on. + public string StorageId { get; } + + /// + /// Gets the value indicating whether the media is DRM-protected. + /// + /// A bool value indicating whether the media is DRM-protected. + public bool IsDrm { get; } + + /// + /// Gets the storage type of the storage that the media is stored on. + /// + /// The storage type of the storage that the media is stored on. + public StorageType StorageType { get; } + + /// + /// Returns a string representation of the media info. + /// + /// A string representation of the current media info. + public override string ToString() => $"Id={Id}, Path={Path}, MediaType={MediaType}"; + + internal static MediaInfo FromHandle(Interop.MediaInfoHandle handle) + { + if (handle == null || handle.IsInvalid) + { + return null; + } + + var type = InteropHelper.GetValue(handle, Interop.MediaInfo.GetMediaType); + + switch (type) + { + case MediaType.Image: + return new ImageInfo(handle); + + case MediaType.Music: + case MediaType.Sound: + return new AudioInfo(handle); + + case MediaType.Video: + return new VideoInfo(handle); + } + + return new MediaInfo(handle); + } + + internal static MediaInfo FromHandle(IntPtr handle) + { + var safeHandle = new Interop.MediaInfoHandle(handle); + try + { + return FromHandle(safeHandle); + } + finally + { + safeHandle.SetHandleAsInvalid(); + } + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoColumnKey.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoColumnKey.cs new file mode 100644 index 0000000..8c6d799 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoColumnKey.cs @@ -0,0 +1,131 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Specifies group keys for . + /// + public enum MediaInfoColumnKey + { + /// + /// Display name. + /// + DisplayName, + /// + /// Media type. + /// + Type, + /// + /// Mime type. + /// + MimeType, + /// + /// File size. + /// + Size, + /// + /// Date added. + /// + DateAdded, + /// + /// Date modified. + /// + DateModified, + /// + /// Content title. + /// + Title, + /// + /// Artist. + /// + Artist, + /// + /// Album artist. + /// + AlbumArtist, + /// + /// Genre. + /// + Genre, + /// + /// Composer. + /// + Composer = 10, + /// + /// Year. + /// + Year, + /// + /// Date recorded. + /// + DateRecorded, + /// + /// Copyright. + /// + Copyright, + /// + /// Track number. + /// + TrackNumber, + /// + /// Description. + /// + Description, + /// + /// Longitude. + /// + Longitude, + /// + /// Latitude. + /// + Latitude, + /// + /// Altitude. + /// + Altitude, + /// + /// Burst shot. + /// + BurstImage, + /// + /// Rating. + /// + Rating = 20, + + /// + /// Provider. + /// + Provider = 22, + + /// + /// Category. + /// + Category = 24, + /// + /// Location tag. + /// + LocationTag, + /// + /// Age rating. + /// + AgeRating, + /// + /// Weather. + /// + Weather = 28 + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs new file mode 100644 index 0000000..f74d8b1 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs @@ -0,0 +1,1129 @@ +/* + * 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.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Tizen.Content.MediaContent +{ + /// + /// Provides commands to manage media info and query related items in the database. + /// + public class MediaInfoCommand : MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + public MediaInfoCommand(MediaDatabase database) : base(database) + { + } + + /// + /// Retrieves the number of the bookmarks added to the media. + /// + /// The media id to count bookmarks added to the media. + /// The number of bookmarks. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountBookmark(string mediaId) + { + return CountBookmark(mediaId, null); + } + + /// + /// Retrieves the number of the bookmarks added to the media with . + /// + /// The media id to count bookmarks added to the media. + /// The criteria to use to filter. This value can be null. + /// The number of bookmarks. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountBookmark(string mediaId, CountArguments arguments) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return CommandHelper.Count(Interop.MediaInfo.GetBookmarkCount, mediaId, arguments); + } + + /// + /// Retrieves the bookmarks added to the media. + /// + /// The media id to select bookmarks added to the media. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectBookmark(string mediaId) + { + return SelectBookmark(mediaId, null); + } + + /// + /// Retrieves the bookmarks added to the media with . + /// + /// The media id to select bookmarks added to the media. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectBookmark(string mediaId, SelectArguments filter) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return CommandHelper.SelectMembers(mediaId, filter, Interop.MediaInfo.ForeachBookmarks, + Bookmark.FromHandle); + } + + + /// + /// Retrieves the number of the face info added to or detected from the media. + /// + /// The media id to count face info added to the media. + /// The number of face info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountFaceInfo(string mediaId) + { + return CountFaceInfo(mediaId, null); + } + + /// + /// Retrieves the number of the face info added to or detected from the media with filter. + /// + /// The media id to count face info added to the media. + /// The criteria to use to filter. This value can be null. + /// The number of face info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountFaceInfo(string mediaId, CountArguments arguments) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return CommandHelper.Count(Interop.MediaInfo.GetFaceCount, mediaId, arguments); + } + + /// + /// Retrieves the face info added to or detected from the media. + /// + /// The media id to select face info added to the media. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectFaceInfo(string mediaId) + { + return SelectFaceInfo(mediaId, null); + } + + /// + /// Retrieves the face info added to or detected from the media with . + /// + /// The media id to select face info added to the media. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectFaceInfo(string mediaId, SelectArguments arguments) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return CommandHelper.SelectMembers(mediaId, arguments, Interop.MediaInfo.ForeachFaces, + FaceInfo.FromHandle); + } + + /// + /// Retrieves the number of tags that the media has. + /// + /// The number of tags. + /// The media id to count tags added to the media. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountTag(string mediaId) + { + return CountTag(mediaId, null); + } + + /// + /// Retrieves the number of tags that the media has with . + /// + /// The media id to count tags added to the media. + /// The criteria to use to filter. This value can be null. + /// The number of tags. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountTag(string mediaId, CountArguments arguments) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return CommandHelper.Count(Interop.MediaInfo.GetTagCount, mediaId, arguments); + } + + /// + /// Retrieves the tags that the media has. + /// + /// The media id to select tags added to the media. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectTag(string mediaId) + { + return SelectTag(mediaId, null); + } + + /// + /// Retrieves the tags that the media has with . + /// + /// The media id to select tags added to the media. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectTag(string mediaId, SelectArguments filter) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return CommandHelper.SelectMembers(mediaId, filter, Interop.MediaInfo.ForeachTags, + Tag.FromHandle); + } + + + /// + /// Retrieves the number of the media info. + /// + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int CountMedia() + { + return CountMedia(null); + } + + /// + /// Retrieves the number of the media info with . + /// + /// The criteria to use to filter. This value can be null. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int CountMedia(CountArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Count(Interop.MediaInfo.GetMediaCount, arguments); + } + + /// + /// Retrieves the media. + /// + /// The media id to retrieve. + /// The instance if the matched record was found in the database, otherwise null. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaInfo SelectMedia(string mediaId) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + Interop.MediaInfo.GetMediaFromDB(mediaId, out var handle).Ignore(MediaContentError.InvalidParameter). + ThrowIfError("Failed to query"); + + try + { + return MediaInfo.FromHandle(handle); + } + finally + { + handle.Dispose(); + } + } + + /// + /// Retrieves the number of values grouped by the specified column with . + /// + /// The column key. + /// The number of groups. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is invalid. + public int CountGroupBy(MediaInfoColumnKey columnKey) + { + return CountGroupBy(columnKey, null); + } + + /// + /// Retrieves the number of values grouped by the specified column with . + /// + /// The column key. + /// The criteria to use to filter. This value can be null. + /// The number of groups. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is invalid. + public int CountGroupBy(MediaInfoColumnKey columnKey, CountArguments arguments) + { + ValidateDatabase(); + + ValidationUtil.ValidateEnum(typeof(MediaInfoColumnKey), columnKey, nameof(columnKey)); + + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + Interop.Group.GetGroupCount(filter, columnKey, out var count).ThrowIfError("Failed to query count"); + return count; + } + } + + /// + /// Retrieves the group values of the specified column. + /// + /// The column key. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is invalid. + public MediaDataReader SelectGroupBy(MediaInfoColumnKey columnKey) + { + return SelectGroupBy(columnKey, null); + } + + /// + /// Retrieves the group values of the specified column. with . + /// + /// The column key. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is invalid. + public MediaDataReader SelectGroupBy(MediaInfoColumnKey columnKey, SelectArguments arguments) + { + ValidateDatabase(); + + ValidationUtil.ValidateEnum(typeof(MediaInfoColumnKey), columnKey, nameof(columnKey)); + + List list = new List(); + + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + Interop.Group.ForeachGroup(filter, columnKey, (name, _) => + { + list.Add(name); + + return true; + }).ThrowIfError("Failed to query"); + + return new MediaDataReader(list); + } + } + + /// + /// Retrieves all the media. + /// + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader SelectMedia() + { + return SelectMedia(arguments: null); + } + + /// + /// Retrieves the media with . + /// + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader SelectMedia(SelectArguments arguments) + { + ValidateDatabase(); + + return new MediaDataReader(QueryMedia(arguments)); + } + + private static List QueryMedia(SelectArguments arguments) + { + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + List list = new List(); + + Exception caught = null; + + Interop.MediaInfo.ForeachMedia(filter, (handle, _) => + { + try + { + list.Add(MediaInfo.FromHandle(handle)); + return true; + } + catch (Exception e) + { + caught = e; + return false; + } + }); + + if (caught != null) + { + throw caught; + } + + return list; + } + } + + /// + /// Deletes a media from the database. + /// + /// http://tizen.org/privilege/content.write + /// The media id to delete. + /// true if the matched record was found and deleted, otherwise false. + /// or can be used instead. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// The caller has no required privilege. + public bool Delete(string mediaId) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + if (CommandHelper.Count( + Interop.MediaInfo.GetMediaCount, $"{MediaInfoColumns.Id}='{mediaId}'") == 0) + { + return false; + } + + CommandHelper.Delete(Interop.MediaInfo.Delete, mediaId); + return true; + } + + /// + /// Adds media to the database. + /// + /// The file path to add. + /// The instance that contains the record information in the database. + /// + /// If the media already exists in the database, it returns existing information.\n + /// \n + /// or can be used instead.\n + /// \n + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// + /// is a zero-length string, contains only white space.\n + /// -or-\n + /// contains a hidden path that starts with '.'.\n + /// -or-\n + /// contains a directory containing the ".scan_ignore" file. + /// + /// does not exists. + /// The caller has no required privilege. + public MediaInfo Add(string path) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path)); + + if (File.Exists(path) == false) + { + throw new FileNotFoundException("destination is not valid path.", path); + } + + if (File.GetAttributes(path).HasFlag(FileAttributes.Hidden)) + { + throw new ArgumentException($"{nameof(path)} contains a hidden path.", nameof(path)); + } + + Interop.MediaInfoHandle handle = null; + + try + { + Interop.MediaInfo.Insert(path, out handle).ThrowIfError("Failed to insert"); + + return MediaInfo.FromHandle(handle); + } + finally + { + if (handle != null) + { + handle.Dispose(); + } + } + } + + private static void ValidatePaths(IEnumerable paths) + { + if (paths == null) + { + throw new ArgumentNullException(nameof(paths)); + } + + if (paths.Count() > 300) + { + throw new ArgumentException("Too many paths to add."); + } + + foreach (var path in paths) + { + if (path == null) + { + throw new ArgumentException($"{nameof(paths)} contains null.", nameof(paths)); + } + + if (File.Exists(path) == false) + { + throw new FileNotFoundException($"{nameof(paths)} contains a path that does not exist. Path={path}.", path); + } + } + + } + + /// + /// Adds media files into the media database. + /// + /// + /// The paths that already exist in the database will be ignored.\n + /// At most 300 items can be added at once.\n + /// \n + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The paths of the media files to add. + /// A task that represents the asynchronous add operation. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// + /// contains null.\n + /// -or-\n + /// contains invalid path.\n + /// -or-\n + /// The number of is 300 or more items. + /// + /// contains a path that does not exist. + /// The caller has no required privilege. + public async Task AddAsync(IEnumerable paths) + { + ValidateDatabase(); + + ValidatePaths(paths); + + var pathArray = paths.ToArray(); + var tcs = new TaskCompletionSource(); + + Interop.MediaInfo.InsertCompletedCallback callback = (error, _) => + { + if (error == MediaContentError.None) + { + tcs.TrySetResult(true); + } + else + { + tcs.TrySetException(error.AsException("Failed to add")); + } + }; + + using (ObjectKeeper.Get(callback)) + { + Interop.MediaInfo.BatchInsert(pathArray, pathArray.Length, callback).ThrowIfError("Failed to add"); + + await tcs.Task; + } + } + + /// + /// Adds burst shot images into the media database. + /// + /// The paths of the burst shot images to add. + /// A task that represents the asynchronous add operation. + /// + /// The paths that already exist in the database.\n + /// At most 300 items can be added at once. + /// \n + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// + /// contains null.\n + /// -or-\n + /// contains invalid path.\n + /// -or-\n + /// The number of is 300 or more items. + /// + /// contains a path that does not exist. + /// The caller has no required privilege. + public async Task AddBurstShotImagesAsync(IEnumerable paths) + { + ValidateDatabase(); + + ValidatePaths(paths); + + var tcs = new TaskCompletionSource(); + string[] pathArray = paths.ToArray(); + + Interop.MediaInfo.InsertBurstShotCompletedCallback callback = (error, _) => + { + if (error == MediaContentError.None) + { + tcs.TrySetResult(true); + } + else + { + tcs.TrySetException(error.AsException("Failed to add burst shot images")); + } + }; + + using (ObjectKeeper.Get(callback)) + { + Interop.MediaInfo.BurstShotInsert(pathArray, pathArray.Length, callback). + ThrowIfError("Failed to add burst shots to db"); + + await tcs.Task; + } + } + + private static void SetUpdateValue(Interop.MediaInfoHandle handle, T value, + Func func) + { + if (value != null) + { + func(handle, value).ThrowIfError("Failed to update"); + } + } + + + private static void SetUpdateValue(Interop.MediaInfoHandle handle, Nullable value, + Func func) where T : struct + { + if (value.HasValue) + { + func(handle, value.Value).ThrowIfError("Failed to update"); + } + } + + /// + /// Updates a media with the specified values. + /// + /// http://tizen.org/privilege/content.write + /// The media id to update. + /// The values for update. + /// true if the matched record was found and updated, otherwise false. + /// Only values set in are updated. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// + /// is null.\n + /// -or-\n + /// is null. + /// + /// is a zero-length string, contains only white space. + /// The caller has no required privilege. + public bool Update(string mediaId, MediaInfoUpdateValues values) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + + if (CommandHelper.Count( + Interop.MediaInfo.GetMediaCount, $"{MediaInfoColumns.Id}='{mediaId}'") == 0) + { + return false; + } + + Interop.MediaInfo.GetMediaFromDB(mediaId, out var handle).ThrowIfError("Failed to update"); + + if (handle.IsInvalid) + { + return false; + } + + try + { + SetUpdateValue(handle, values.Weather, Interop.MediaInfo.SetWeather); + SetUpdateValue(handle, values.IsFavorite, Interop.MediaInfo.SetFavorite); + SetUpdateValue(handle, values.Provider, Interop.MediaInfo.SetProvider); + SetUpdateValue(handle, values.Category, Interop.MediaInfo.SetCategory); + SetUpdateValue(handle, values.LocationTag, Interop.MediaInfo.SetLocationTag); + SetUpdateValue(handle, values.AgeRating, Interop.MediaInfo.SetAgeRating); + + Interop.MediaInfo.UpdateToDB(handle).ThrowIfError("Failed to update"); + return true; + } + finally + { + handle.Dispose(); + } + } + + /// + /// Updates the path of the media to the specified destination path in the database. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The media id to move. + /// The path that the media has been moved to. + /// true if the matched record was found and updated, otherwise false. + /// + /// Usually, it is used after the media file is moved to another path.\n + /// \n + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// + /// is null.\n + /// -or-\n + /// is null. + /// + /// + /// is a zero-length string, contains only white space.\n + /// -or-\n + /// is a zero-length string, contains only white space.\n + /// -or-\n + /// contains a hidden directory that starts with '.'.\n + /// -or-\n + /// contains a directory containing the ".scan_ignore" file. + /// + /// does not exists. + /// The caller has no required privilege. + public bool Move(string mediaId, string newPath) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + ValidationUtil.ValidateNotNullOrEmpty(newPath, nameof(newPath)); + + if (File.Exists(newPath) == false) + { + throw new FileNotFoundException("destination is not valid path.", newPath); + } + + if (File.GetAttributes(newPath).HasFlag(FileAttributes.Hidden)) + { + throw new ArgumentException($"{nameof(newPath)} contains a hidden path.", nameof(newPath)); + } + + //TODO can be improved if MoveToDB supports result value. + Interop.MediaInfo.GetMediaFromDB(mediaId, out var handle). + Ignore(MediaContentError.InvalidParameter).ThrowIfError("Failed to move"); + + if (handle.IsInvalid) + { + return false; + } + + try + { + Interop.MediaInfo.MoveToDB(handle, newPath).ThrowIfError("Failed to move"); + } + finally + { + handle.Dispose(); + } + + return true; + } + + #region CreateThumbnailAsync + /// + /// Creates a thumbnail image for the given media. + /// If a thumbnail already exists for the given media, the existing path will be returned. + /// + /// http://tizen.org/privilege/content.write + /// The media id to create thumbnail. + /// A task that represents the asynchronous operation. The task result contains the thumbnail path. + /// + /// The is disconnected.\n + /// -or-\n + /// An internal error occurred while executing. + /// + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// does not exist in the database. + /// + /// is a zero-length string, contains only white space. + /// + /// The file of the media does not exists; moved or deleted. + /// + /// Thumbnail is not available for the given media.\n + /// -or-\n + /// The media is in external usb storage( is ). + /// + public Task CreateThumbnailAsync(string mediaId) + { + return CreateThumbnailAsync(mediaId, CancellationToken.None); + } + + /// + /// Creates a thumbnail image for the given media. + /// If a thumbnail already exists for the given media, the existing path will be returned. + /// + /// http://tizen.org/privilege/content.write + /// The media id to create thumbnail. + /// The token to cancel the operation. + /// A task that represents the asynchronous operation. The task result contains the thumbnail path. + /// + /// The is disconnected.\n + /// -or-\n + /// An internal error occurred while executing. + /// + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// does not exist in the database. + /// + /// is a zero-length string, contains only white space. + /// + /// The file of the media does not exists; moved or deleted. + /// + /// Thumbnail is not available for the given media.\n + /// -or-\n + /// The media is in external usb storage( is ). + /// + public Task CreateThumbnailAsync(string mediaId, CancellationToken cancellationToken) + { + ValidateDatabase(); + + return cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) : + CreateThumbnailAsyncCore(mediaId, cancellationToken); + } + + private async Task CreateThumbnailAsyncCore(string mediaId, CancellationToken cancellationToken) + { + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + var tcs = new TaskCompletionSource(); + + Interop.MediaInfo.GetMediaFromDB(mediaId, out var handle).ThrowIfError("Failed to create thumbnail"); + + if (handle.IsInvalid) + { + throw new RecordNotFoundException("Media does not exist."); + } + + using (handle) + { + if (InteropHelper.GetValue(handle, Interop.MediaInfo.GetStorageType) == StorageType.ExternalUsb) + { + throw new UnsupportedContentException("The media is in external usb storage."); + } + + var path = InteropHelper.GetString(handle, Interop.MediaInfo.GetFilePath); + + if (File.Exists(path) == false) + { + throw new FileNotFoundException($"The media file does not exist. Path={path}.", path); + } + + using (RegisterCancelThumbnail(cancellationToken, tcs, handle)) + using (var cbKeeper = ObjectKeeper.Get(GetCreateThumbnailCallback(tcs))) + { + Interop.MediaInfo.CreateThumbnail(handle, cbKeeper.Target).ThrowIfError("Failed to create thumbnail"); + + return await tcs.Task; + } + } + } + + private static Interop.MediaInfo.ThumbnailCompletedCallback GetCreateThumbnailCallback( + TaskCompletionSource tcs) + { + return (error, path, _) => + { + if (error != MediaContentError.None) + { + tcs.TrySetException(error.AsException("Failed to create thumbnail")); + } + else + { + tcs.TrySetResult(path); + } + }; + } + + private static IDisposable RegisterCancelThumbnail(CancellationToken cancellationToken, + TaskCompletionSource tcs, Interop.MediaInfoHandle handle) + { + if (cancellationToken.CanBeCanceled == false) + { + return null; + } + + return cancellationToken.Register(() => + { + if (tcs.Task.IsCompleted) + { + return; + } + + Interop.MediaInfo.CancelThumbnail(handle).ThrowIfError("Failed to cancel"); + tcs.TrySetCanceled(); + }); + } + #endregion + + #region DetectFaceAsync + /// + /// Detects faces from the given media. + /// If a thumbnail already exists for the given media, the existing path will be returned. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/feature/vision.face_recognition + /// The media id to create thumbnail. + /// A task that represents the asynchronous add operation. The task result contains the number of faces detected. + /// + /// The is disconnected.\n + /// -or-\n + /// An internal error occurred while executing. + /// + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// does not exist in the database. + /// + /// is a zero-length string, contains only white space. + /// + /// The file of the media does not exists; moved or deleted. + /// Feace detection is not available for the given media. + /// The required feature is not supported. + /// The caller has no required privilege. + public Task DetectFaceAsync(string mediaId) + { + return DetectFaceAsync(mediaId, CancellationToken.None); + } + + /// + /// Creates a thumbnail image for the given media. + /// If a thumbnail already exists for the given media, the existing path will be returned. + /// + /// + /// Media in external storage is not supported, with the exception of MMC. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/feature/vision.face_recognition + /// The media id to create thumbnail. + /// The token to cancel the operation. + /// A task that represents the asynchronous operation. The task result contains the number of faces detected. + /// + /// The is disconnected.\n + /// -or-\n + /// An internal error occurred while executing. + /// + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// does not exist in the database. + /// + /// is a zero-length string, contains only white space. + /// + /// The file of the media does not exists; moved or deleted. + /// + /// Face detection is not available for the given media.\n + /// -or-\n + /// The media is in external usb storage( is ). + /// + /// The required feature is not supported. + public Task DetectFaceAsync(string mediaId, CancellationToken cancellationToken) + { + if (Features.IsSupported(Features.FaceRecognition) == false) + { + throw new NotSupportedException($"The feature({Features.FaceRecognition}) is not supported."); + } + + ValidateDatabase(); + + return cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) : + DetectFaceAsyncCore(mediaId, cancellationToken); + } + + private static async Task DetectFaceAsyncCore(string mediaId, CancellationToken cancellationToken) + { + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + var tcs = new TaskCompletionSource(); + + Interop.MediaInfo.GetMediaFromDB(mediaId, out var handle).ThrowIfError("Failed to detect faces"); + + if (handle.IsInvalid) + { + throw new RecordNotFoundException("Media does not exist."); + } + + using (handle) + { + if (InteropHelper.GetValue(handle, Interop.MediaInfo.GetStorageType) == StorageType.ExternalUsb) + { + throw new UnsupportedContentException("The media is in external usb storage."); + } + + if (InteropHelper.GetValue(handle, Interop.MediaInfo.GetMediaType) != MediaType.Image) + { + throw new UnsupportedContentException("Only image is supported."); + } + + var path = InteropHelper.GetString(handle, Interop.MediaInfo.GetFilePath); + + if (File.Exists(path) == false) + { + throw new FileNotFoundException($"The media file does not exist. Path={path}.", path); + } + + using (RegisterCancelFaceDetection(cancellationToken, tcs, handle)) + using (var cbKeeper = ObjectKeeper.Get(GetFaceDetectionCallback(tcs))) + { + Interop.MediaInfo.StartFaceDetection(handle, cbKeeper.Target).ThrowIfError("Failed to detect faces"); + + return await tcs.Task; + } + } + } + + private static Interop.MediaInfo.FaceDetectionCompletedCallback GetFaceDetectionCallback( + TaskCompletionSource tcs) + { + return (error, count, _) => + { + if (error != MediaContentError.None) + { + tcs.TrySetException(error.AsException("Failed to detect faces")); + } + else + { + tcs.TrySetResult(count); + } + }; + } + + private static IDisposable RegisterCancelFaceDetection(CancellationToken cancellationToken, + TaskCompletionSource tcs, Interop.MediaInfoHandle handle) + { + if (cancellationToken.CanBeCanceled == false) + { + return null; + } + + return cancellationToken.Register(() => + { + if (tcs.Task.IsCompleted) + { + return; + } + + Interop.MediaInfo.CancelFaceDetection(handle).ThrowIfError("Failed to cancel"); + tcs.TrySetCanceled(); + }); + } + #endregion + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoUpdateValues.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoUpdateValues.cs new file mode 100644 index 0000000..9947f38 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoUpdateValues.cs @@ -0,0 +1,73 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Provides means to set values used for the update command. + /// + /// + /// The values only set in the object will be affected to the update command. + /// + /// + public class MediaInfoUpdateValues + { + /// + /// Gets or sets the weather information for update. + /// + /// If the value is null, the update operation will have no effect on the field. + /// A string for weather; the field will not be updated if null. + public string Weather { get; set; } + + /// + /// Gets or sets the favorite status for update. + /// + /// If the value is null, the update operation will have no effect on the field. + /// A value indicating whether the media is favorite; the field will not be updated if null. + public bool? IsFavorite { get; set; } + + /// + /// Gets or sets the provider information for update. + /// + /// If the value is null, the update operation will have no effect on the field. + /// A string for provider; the field will not be updated if null. + public string Provider { get; set; } + + /// + /// Gets or sets the category information for update. + /// + /// If the value is null, the update operation will have no effect on the field. + /// A string for category; the field will not be updated if null. + public string Category { get; set; } + + + /// + /// Gets or sets the location tag for update. + /// + /// If the value is null, the update operation will have no effect on the field. + /// A string for location tag; the field will not be updated if null. + public string LocationTag { get; set; } + + /// + /// Gets or sets the age rating information for update. + /// + /// If the value is null, the update operation will have no effect on the field. + /// A string for age rating; the field will not be updated if null. + public string AgeRating { get; set; } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInformation.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInformation.cs deleted file mode 100755 index 49b1788..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInformation.cs +++ /dev/null @@ -1,897 +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.Collections.ObjectModel; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; - -namespace Tizen.Content.MediaContent -{ - /// - /// MediaContent class API gives the information related to the media stored in the device - /// - /// The API's provide the functionlity to insert, clone, delete, get the number and content of files from DB. - /// You can get and set properties and parameters such as storage type, provider, and category of media info, - /// handling with thumbnail and updating media info to DB. - public class MediaInformation - { - private readonly Interop.MediaInformation.SafeMediaInformationHandle _handle; - - /// - /// Gets the count of media tags for the passed filter in the given mediaId from the media database. - /// - /// 3 - /// - /// int count - /// The Filter for matching Tags - public int GetTagCount(ContentFilter filter) - { - int count = 0; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetTagCount(MediaId, handle, out count), "Failed to get count"); - - return count; - } - - /// - /// Moves the media info to the given destination path in the media database. - /// - /// 3 - /// - /// void - /// The Destination path - public void Move(string destination) - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.MoveToDB(_handle, destination), "Failed to move"); - } - - /// - /// Refreshes the media metadata to the media database. - /// - /// 3 - /// - /// void - public void Refresh() - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.RefreshMetadataToDB(MediaId), "Failed to refresh"); - } - - /// - /// Creates a thumbnail image for the given media, asynchronously - /// If a thumbnail already exists for the given media, then the path of thumbnail will be returned. - /// - /// 3 - /// - /// Task for creation of Thumbnail - public Task CreateThumbnailAsync() - { - var task = new TaskCompletionSource(); - Interop.MediaInformation.MediaThumbnailCompletedCallback thumbnailResult = (MediaContentError createResult, string path, IntPtr userData) => - { - if (createResult != MediaContentError.None) - { - task.SetException(new InvalidOperationException("Failed to create thumbnail:" + createResult)); - } - - task.SetResult(path); - }; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.CreateThumbnail(_handle, thumbnailResult, IntPtr.Zero), "Failed to create thumbnail"); - - return task.Task; - } - - /// - /// Creates a thumbnail image for the given media, asynchronously - /// which can be cancelled - /// If a thumbnail already exists for the given media, then the path of thumbnail will be returned. - /// - /// 3 - /// Token to cancel the requested operation - /// - /// Task for creation of Thumbnail - /// - public Task CreateThumbnailAsync(CancellationToken cancellationToken) - { - var task = new TaskCompletionSource(); - cancellationToken.Register(() => - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.CancelThumbnail(_handle), "Failed to cancel"); - - task.SetCanceled(); - }); - - Interop.MediaInformation.MediaThumbnailCompletedCallback thumbnailResult = (MediaContentError createResult, string path, IntPtr userData) => - { - if (createResult != MediaContentError.None) - { - task.SetException(new InvalidOperationException("Failed to create thumbnail:" + createResult)); - } - - task.SetResult(path); - }; - - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.CreateThumbnail(_handle, thumbnailResult, IntPtr.Zero), "Failed to create thumbnail"); - - return task.Task; - } - - /// - /// Iterates through the media tag in the given media info from the media database. - /// - /// 3 - /// - /// Task to get all the Tags - /// The filter for the Tags - public IEnumerable GetTags(ContentFilter filter) - { - Collection coll = new Collection(); - - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - Interop.MediaInformation.MediaTagCallback tagsCallback = (IntPtr tagHandle, IntPtr userData) => - { - IntPtr newHandle; - MediaContentValidator.ThrowIfError( - Interop.Tag.Clone(out newHandle, tagHandle), "Failed to clone"); - coll.Add(new Tag(newHandle)); - - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAllTags(MediaId, handle, tagsCallback, IntPtr.Zero), "Failed to get information"); - - return coll; - } - - /// - /// Gets the ID of the media. - /// - /// 3 - public virtual string MediaId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetMediaId(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the path to the media. - /// - /// 3 - public string FilePath - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetFilePath(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Name of the media. - /// - /// 3 - public string DisplayName - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetDisplayName(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetDisplayName(_handle, value), "failed to set value"); - } - } - - /// - /// Gets the content type of the media. - /// - /// 3 - public MediaContentType MediaType - { - get - { - MediaContentType contentType = MediaContentType.Others; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetMediaType(_handle, out contentType), "Failed to get value"); - - return contentType; - } - } - - /// - /// Gets the MIME type from the media. - /// - /// 3 - public string MimeType - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetMimeType(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the media file size in bytes. - /// - /// 3 - public long Size - { - get - { - long size; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetSize(_handle, out size), "Failed to get value"); - - return size; - } - } - - /// - /// Addition time of the media. - /// - /// 3 - public DateTime AddedAt - { - get - { - int time; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAddedTime(_handle, out time), "Failed to get value"); - - DateTime utc = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(time), DateTimeKind.Utc); - - return utc.ToLocalTime(); - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetAddedTime(_handle, (int)value.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds), "failed to set time"); - } - } - - /// - /// Gets the date of modification of media. - /// - /// 3 - public DateTime ModifiedAt - { - get - { - int time; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetModifiedTime(_handle, out time), "Failed to get value"); - - DateTime utc = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(time), DateTimeKind.Utc); - - return utc.ToLocalTime(); - } - } - - /// - /// Gets the timeline of media. - /// - /// 3 - public DateTime TimeLine - { - get - { - int time; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetTimeline(_handle, out time), "Failed to get value"); - - DateTime utc = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(time), DateTimeKind.Utc); - - return utc.ToLocalTime(); - } - } - - /// - /// Gets the thumbnail of media. - /// - /// 3 - public string ThumbnailPath - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetThumbnailPath(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Description of media. - /// If the media info has no description, the property returns empty string. - /// - /// 3 - public string Description - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetDescription(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetDescription(_handle, value), "failed to set value"); - } - } - - /// - /// Longitude of media. - /// Default Value is 0.0. - /// - /// 3 - public double Longitude - { - get - { - double longitude = 0.0; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetLongitude(_handle, out longitude), "Failed to get value"); - - return longitude; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetLongitude(_handle, value), "failed to set value"); - } - } - - /// - /// Latitude of media. - /// Default Value is 0.0. - /// - /// 3 - public double Latitude - { - get - { - double latitude = 0.0; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetLatitude(_handle, out latitude), "Failed to get value"); - - return latitude; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetLatitude(_handle, value), "failed to set value"); - } - } - - /// - /// Altitude of media. - /// Default Value is 0.0. - /// - /// 3 - public double Altitude - { - get - { - double altitude = 0.0; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAltitude(_handle, out altitude), "Failed to get value"); - - return altitude; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetAltitude(_handle, value), "failed to set value"); - } - } - - /// - /// Weather information of media. - /// - /// 3 - public string Weather - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetWeather(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetWeather(_handle, value), "failed to set value"); - } - } - - /// - /// Rating of media. - /// - /// 3 - public int Rating - { - get - { - int rating = 0; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetRating(_handle, out rating), "Failed to get value"); - return rating; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetRating(_handle, value), "failed to set value"); - } - } - - /// - /// Favorite status of media. - /// true if media info is set as favorite, otherwise false if media info is not set as favorite. - /// - /// 3 - public bool IsFavourite - { - get - { - bool isFavourtite = false; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetFavorite(_handle, out isFavourtite), "Failed to get value"); - - return isFavourtite; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetFavorite(_handle, value), "failed to set value"); - } - } - - /// - /// Author of media. - /// - /// 3 - public string Author - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAuthor(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetAuthor(_handle, value), "failed to set value"); - } - } - - /// - /// Provider of media. - /// - /// 3 - public string Provider - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetProvider(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetProvider(_handle, value), "failed to set value"); - } - } - - /// - /// Content name of media. - /// - /// 3 - public string ContentName - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetContentName(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetContentName(_handle, value), "failed to set value"); - } - } - - /// - /// Gets the title of media. - /// If the media content has no title, the property returns empty string. - /// - /// 3 - public string Title - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetTitle(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Category of media. - /// - /// 3 - public string Category - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetCategory(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetCategory(_handle, value), "failed to set value"); - } - } - - /// - /// location tag of media. - /// - /// 3 - public string LocationTag - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetLocationTag(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetLocationTag(_handle, value), "failed to set value"); - } - } - - /// - /// Age Rating of media. - /// - /// 3 - public string AgeRating - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAgeRating(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetAgeRating(_handle, value), "Failed to set value"); - } - } - - /// - /// Keyword of media. - /// - /// 3 - public string Keyword - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetKeyword(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetKeyword(_handle, value), "failed to set value"); - } - } - - /// - /// Gets the storage id of media. - /// - /// 3 - public string StorageId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetStorageId(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Checks whether the media is protected via DRM. - /// - /// 3 - public bool IsDrm - { - get - { - bool isDRM = false; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.IsDrm(_handle, out isDRM), "Failed to get value"); - - return isDRM; - } - } - - /// - /// Gets the storage type of media. - /// - /// 3 - public ContentStorageType StorageType - { - get - { - ContentStorageType storageType = ContentStorageType.Internal; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetStorageType(_handle, out storageType), "Failed to get value"); - - return storageType; - } - } - - /// - /// Number which represents how many times given content has been played. - /// While Setting the played count, it will only be incremented by 1, the value provided will be ignored. - /// - /// 3 - public int PlayedCount - { - get - { - int playedCount = 0; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetPlayedCount(_handle, out playedCount), "Failed to get value"); - - return playedCount; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.IncreasePlayedCount(_handle), "failed to set value"); - } - } - - /// - /// Content's latest played(opened) time of the media file. - /// for set the current time is automatically taken from the system, the value provided will be ignored. - /// - /// 3 - public DateTime PlayedAt - { - get - { - int time; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetPlayedAt(_handle, out time), "Failed to get value"); - - DateTime utc = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(time), DateTimeKind.Utc); - - return utc.ToLocalTime(); - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.SetPlayedAt(_handle), "failed to set value"); - } - } - - internal IntPtr MediaHandle - { - get - { - return _handle.DangerousGetHandle(); - } - } - - internal MediaInformation(Interop.MediaInformation.SafeMediaInformationHandle handle) - { - _handle = handle; - } - } -} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/NamespaceDoc.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/NamespaceDoc.cs new file mode 100644 index 0000000..7df929a --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/NamespaceDoc.cs @@ -0,0 +1,26 @@ +/* + * 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. + */ + +/// +/// The Tizen.Content.MediaContent namespace provides types used in the entire content service. +/// The information about media items(i.e. image, audio and video) are managed in the content database +/// and operations that involve database require an active connection with the media content service. +/// During media scanning, Media content service extracts media information automatically. Media information +/// includes basic file info like path, size, modified time etc and some metadata like ID3 tag, EXIF, +/// thumbnail, etc. (thumbnail extracted only in Internal and SD card storage. +/// +/// Media content service does not manage hidden files. +namespace Tizen.Content.MediaContent { } \ No newline at end of file diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ObjectKeeper.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ObjectKeeper.cs new file mode 100644 index 0000000..06d9b8c --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ObjectKeeper.cs @@ -0,0 +1,77 @@ +/* + * 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.Runtime.InteropServices; + +namespace Tizen.Content.MediaContent +{ + internal abstract class ObjectKeeper : IDisposable + { + private ObjectKeeper() + { + } + + public abstract void Dispose(); + + public static ObjectKeeperImpl Get(T target) + { + return new ObjectKeeperImpl(target); + } + + internal class ObjectKeeperImpl : ObjectKeeper + { + private readonly GCHandle _handle; + + internal ObjectKeeperImpl(T obj) + { + Target = obj; + _handle = GCHandle.Alloc(obj); + } + + ~ObjectKeeperImpl() + { + Dispose(false); + } + + private bool disposedValue = false; + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + _handle.Free(); + } + + disposedValue = true; + } + } + + public override void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + public T Target + { + get; + } + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlayList.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlayList.cs index e440707..beabf44 100755 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlayList.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlayList.cs @@ -1,341 +1,153 @@ -/* -* 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. -*/ - +/* + * 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.Runtime.InteropServices; -using System.Threading.Tasks; namespace Tizen.Content.MediaContent { /// - /// The PlayList API provides functions to manage media playlists. + /// Represents a playlist that is a group of media(usually songs). /// - /// - /// A PlayList is a list of songs which can be played in some sequence i.e. sequential or shuffled order. - /// The Media PlayList API provides functions to insert, delete or updates a media playlist in the database. - /// - public class PlayList : ContentCollection + public class Playlist { - private readonly IDictionary _dictionary = new Dictionary(); - private IntPtr _playlistHandle = IntPtr.Zero; - internal IntPtr Handle + internal Playlist(IntPtr handle) { - get - { - if (_playlistHandle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(PlayList)); - } - - return _playlistHandle; - } + Name = InteropHelper.GetString(handle, Interop.Playlist.GetName); + ThumbnailPath = InteropHelper.GetString(handle, Interop.Playlist.GetThumbnailPath); - set - { - _playlistHandle = value; - } + Id = InteropHelper.GetValue(handle, Interop.Playlist.GetId); } - private void RefreshPlaylistDictionary() - { - _dictionary.Clear(); - Interop.Playlist.PlaylistMemberCallback callback = (int memberId, IntPtr mediaHandle, IntPtr data) => - { - Interop.MediaInformation.SafeMediaInformationHandle newHandle; - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone media"); - - Interop.MediaInformation.GetMediaId(newHandle, out val); - _dictionary.Add(Marshal.PtrToStringAnsi(val), memberId); - return true; - } - finally - { - Interop.Libc.Free(val); - } - }; - MediaContentValidator.ThrowIfError( - Interop.Playlist.ForeachMediaFromDb(Id, IntPtr.Zero, callback, IntPtr.Zero), "Failed to get playlist items"); - } + internal static Playlist FromHandle(IntPtr handle) => new Playlist(handle); /// - /// The ID of the media playlist + /// Gets the ID of the playlist. /// - /// 3 - public int Id - { - get - { - int id; - MediaContentValidator.ThrowIfError( - Interop.Playlist.GetPlaylistId(Handle, out id), "Failed to get value"); + /// The unique id of the playlist. + public int Id { get; } - return id; - } - } - - internal string _playListName; /// - /// The playlist name + /// Gets the name of the playlist. /// - /// 3 - public string Name - { - get - { - return _playListName; - } + /// The name of the playlist. + public string Name { get; } - set - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.SetName(Handle, value), "Failed to set value"); - _playListName = value; - } - } /// - /// The path of the thumbnail + /// Gets the path to the thumbnail. /// - /// 3 - public string ThumbnailPath - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.GetThumbnailPath(Handle, out val), "Failed to get value"); - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.SetThumbnailPath(Handle, value), "Failed to set value"); - } - } + /// The path to the thumbnail. + public string ThumbnailPath { get; } /// - /// The constructor to create a new playlist with the given name in the media database. + /// Returns a string representation of the playlist. /// - /// 3 - /// The name of the inserted playlist - public PlayList(string name) - { - _playListName = name; - } - - internal PlayList(IntPtr handle) - { - _playlistHandle = handle; - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.GetName(handle, out val), "Failed to get value"); - _playListName = Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - - /// - /// Adds a new media info to the playlist. - /// - /// 3 - /// The AudioContent obect to be added - public void AddItem(MediaInformation mediaContent) - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.AddMedia(Handle, mediaContent.MediaId), "Failed to add item"); - } - - /// - /// Removes the playlist members related with the media from the given playlist. - /// - /// 3 - /// The AudioContent object to be removed - public void RemoveItem(MediaInformation media) - { - int memberId = 0; - RefreshPlaylistDictionary(); - _dictionary.TryGetValue(media.MediaId, out memberId); - MediaContentValidator.ThrowIfError( - Interop.Playlist.RemoveMedia(Handle, memberId), "Failed to remove item"); - } + /// A string representation of the current playlist. + public override string ToString() => + $"Id={Id}, Name={Name}, ThumbnailPath={ThumbnailPath}"; + } + /// + /// Provides means to set values used for the update command. + /// + /// + /// The values only set in the object will be affected to the update command. + /// + /// + public class PlaylistUpdateValues + { /// - /// Sets the playing order in the playlist. + /// Gets or sets the name of playlist for update. /// - /// 3 - /// The playlist reference - /// The playing order - public void SetPlayOrder(MediaInformation media, int playOrder) - { - int memberId; - RefreshPlaylistDictionary(); - _dictionary.TryGetValue(media.MediaId, out memberId); - MediaContentValidator.ThrowIfError( - Interop.Playlist.SetPlayOrder(Handle, memberId, playOrder), "Failed to set play order"); - } + /// If the value is null, the update operation will have no effect on the field. + /// A string for name; the field will not be updated if null. + public string Name { get; set; } /// - /// Gets the playing order in the playlist for the passed member id. + /// Gets or sets the thumbnail path of playlist for update. /// - /// 3 - /// The MediaInformation instance - /// The number of play order - public int GetPlayOrder(MediaInformation media) - { - int playOrder; - int memberId; - RefreshPlaylistDictionary(); - _dictionary.TryGetValue(media.MediaId, out memberId); - MediaContentValidator.ThrowIfError( - Interop.Playlist.GetPlayOrder(Handle, memberId, out playOrder), "Failed to get play order"); - - return playOrder; - } + /// If the value is null, the update operation will have no effect on the field. + /// A string for thumbnail path; the field will not be updated if null. + public string ThumbnailPath { get; set; } + } + /// + /// Represents an order of a member of a playlist. + /// + public class PlayOrder + { /// - /// Imports the playlist from m3u playlist file. + /// Initializes a new instance of the class with the specified member id and order value. /// - /// 3 - /// The name of the playlist to save - /// The path to import the playlist file - /// The imported PlayList object - public static PlayList Import(string name, string filePath) + /// The id of member. + /// The order value. + /// + /// is less than or equal to zero.\n + /// -or-\n + /// is less than zero. + /// + public PlayOrder(int memberId, int orderValue) { - PlayList playList = null; - IntPtr playlistHandle; - - MediaContentValidator.ThrowIfError( - Interop.Playlist.ImportFromFile(name, filePath, out playlistHandle), "Failed to import"); - - playList = new PlayList(name); - playList.Handle = playlistHandle; - return playList; + MemberId = memberId; + Value = orderValue; } - /// - /// Exports the playlist to m3u playlist file. - /// - /// 3 - /// The playlist instance to export - /// The path to save exported playlist - /// path The path to export the playlist - public static void Export(PlayList list, string filePath) - { - MediaContentValidator.ThrowIfError( - Interop.Playlist.ExportToFile(list.Handle, filePath), "Failed to export playlist:" + filePath); - } + private int _memberId; /// - /// Gets the number of the media info for the given playlist present in the media database. + /// Gets or sets the member id. /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// The number of media contents matching the filter passed - public override int GetMediaInformationCount(ContentFilter filter) + /// The member id. + /// + /// is less than or equal to zero. + /// + public int MemberId { - int mediaCount; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Playlist.GetMediaCountFromDb(Id, handle, out mediaCount), "Failed to get media count"); - - return mediaCount; - } - - public override void Dispose() - { - if (_playlistHandle != IntPtr.Zero) + get => _memberId; + set { - Interop.Playlist.Destroy(_playlistHandle); - _playlistHandle = IntPtr.Zero; + if (value <= 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, + "Member id can't be less than or equal to zero."); + } + _memberId = value; } } + private int _value; + /// - /// Iterates through the media files with an optional filter in the given audio playlist from the media database. - /// This function gets all media files associated with the given media playlist and meeting desired filter option. - /// If NULL is passed to the filter, no filtering is applied. + /// Gets or sets the value indicating the order of the member in a playlist. /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// List of content media items matching the passed filter - public override IEnumerable GetMediaInformations(ContentFilter filter) + /// A integer value indicating the order of the member in a playlist. + /// + /// is less than zero. + /// + public int Value { - List mediaContents = new List(); - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - Interop.Playlist.PlaylistMemberCallback callback = (int memberId, IntPtr mediaHandle, IntPtr data) => + get => _value; + set { - Interop.MediaInformation.SafeMediaInformationHandle newHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone media"); - - MediaContentType type; - Interop.MediaInformation.GetMediaType(newHandle, out type); - if (type == MediaContentType.Image) + if (value < 0) { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information"); - - mediaContents.Add(new ImageInformation(imageInfo, newHandle)); + throw new ArgumentOutOfRangeException(nameof(value), value, + "Order can't be less than zero."); } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information"); - - mediaContents.Add(new AudioInformation(audioInfo, newHandle)); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information"); - - mediaContents.Add(new VideoInformation(videoInfo, newHandle)); - } - else if (type == MediaContentType.Others) - { - mediaContents.Add(new MediaInformation(newHandle)); - } - - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Playlist.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero), "Failed to get media information"); - - return mediaContents; + _value = value; + } } } } diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistCommand.cs new file mode 100644 index 0000000..94d90b0 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistCommand.cs @@ -0,0 +1,872 @@ +/* + * 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.IO; +using System.Linq; + +namespace Tizen.Content.MediaContent +{ + /// + /// Provides commands to manage playlists in the database. + /// + /// + public class PlaylistCommand : MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + public PlaylistCommand(MediaDatabase database) : base(database) + { + } + + /// + /// Retrieves the number of playlists. + /// + /// The number of playlists. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count() + { + return Count(null); + } + + /// + /// Retrieves the number of playlists with . + /// + /// The criteria to use to filter. This value can be null. + /// The number of playlists. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count(CountArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Count(Interop.Playlist.GetPlaylistCount, arguments); + } + + /// + /// Retrieves the play order of the member. + /// + /// The playlist id. + /// The member id of the playlist. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// + /// is less than or equal to zero.\n + /// -or-\n + /// is less than or equal to zero. + /// + public int GetPlayOrder(int playlistId, int memberId) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + if (memberId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(memberId), memberId, + "Member id can't be less than or equal to zero."); + } + + Interop.Playlist.GetPlayOrder(playlistId, memberId, out var order).ThrowIfError("Failed to query"); + + return order; + } + + /// + /// Deletes a playlist from the database. + /// + /// http://tizen.org/privilege/content.write + /// The playlist id to delete. + /// true if the matched record was found and deleted, otherwise false. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + /// The caller has no required privilege. + public bool Delete(int playlistId) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + if (Select(playlistId) == null) + { + return false; + } + + CommandHelper.Delete(Interop.Playlist.Delete, playlistId); + return true; + } + + /// + /// Inserts a playlist into the database from the specified m3u file. + /// + /// + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/content.write + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The name of playlist. + /// The path to a m3u file to import. + /// The instance that contains the record information inserted. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// + /// is null.\n + /// -or-\n + /// is null. + /// + /// + /// is a zero-length string.\n + /// -or-\n + /// is a zero-length string, contains only white space. + /// + /// does not exists. + /// The caller has no required privilege. + public Playlist InsertFromFile(string name, string path) + { + ValidateDatabase(); + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (name.Length == 0) + { + throw new ArgumentException("Playlist name can't be an empty string."); + } + + ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path)); + + if (File.Exists(path) == false) + { + throw new FileNotFoundException("The specified path does not exists.", path); + } + + IntPtr handle = IntPtr.Zero; + Interop.Playlist.ImportFromFile(path, name, out handle).ThrowIfError("Failed to insert"); + + try + { + return new Playlist(handle); + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Playlist.Destroy(handle); + } + } + } + /// + /// Exports a playlist to a m3u file. + /// + /// + /// If the file already exists in the file system, then it will be overwritten.\n + /// \n + /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.\n + /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. + /// + /// http://tizen.org/privilege/mediastorage + /// http://tizen.org/privilege/externalstorage + /// The playlist id to export. + /// The path to a m3u file. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// is less than or equal to zero. + /// No matching playlist exists. + /// The caller has no required privilege. + public void ExportToFile(int playlistId, string path) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path)); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + IntPtr handle = IntPtr.Zero; + try + { + Interop.Playlist.GetPlaylistFromDb(playlistId, out handle).ThrowIfError("Failed to query"); + + if (handle == IntPtr.Zero) + { + throw new RecordNotFoundException("No matching playlist exists."); + } + + Interop.Playlist.ExportToFile(handle, path).ThrowIfError("Failed to export"); + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Playlist.Destroy(handle); + } + } + } + + /// + /// Inserts a playlist into the database with the specified name. + /// + /// http://tizen.org/privilege/content.write + /// The name of playlist. + /// The instance that contains the record information inserted. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string. + /// The caller has no required privilege. + public Playlist Insert(string name) + { + return Insert(name, null); + } + + /// + /// Inserts a playlist into the database with the specified name and thumbnail path. + /// + /// http://tizen.org/privilege/content.write + /// The name of playlist. + /// The path of thumbnail for playlist. This value can be null. + /// The instance that contains the record information inserted. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string. + /// The caller has no required privilege. + public Playlist Insert(string name, string thumbnailPath) + { + ValidateDatabase(); + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (name.Length == 0) + { + throw new ArgumentException("Playlist name can't be an empty string."); + } + + IntPtr handle = IntPtr.Zero; + Interop.Playlist.Create(out handle).ThrowIfError("Failed to insert"); + + try + { + Interop.Playlist.SetName(handle, name).ThrowIfError("Failed to insert"); + + if (thumbnailPath != null) + { + Interop.Playlist.SetThumbnailPath(handle, thumbnailPath).ThrowIfError("Failed to insert"); + } + + Interop.Playlist.Insert(handle).ThrowIfError("Failed to insert"); + return new Playlist(handle); + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Playlist.Destroy(handle); + } + } + } + + /// + /// Retrieves the playlists. + /// + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select() + { + return Select(null); + } + + /// + /// Retrieves the playlists with . + /// + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select(SelectArguments filter) + { + ValidateDatabase(); + + return CommandHelper.Select(filter, Interop.Playlist.ForeachPlaylistFromDb, + Playlist.FromHandle); + } + + /// + /// Retrieves the playlist with the specified playlist id. + /// + /// The playlist id to select. + /// The instance if the matched record was found in the database, otherwise null. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public Playlist Select(int playlistId) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + IntPtr handle = IntPtr.Zero; + + try + { + Interop.Playlist.GetPlaylistFromDb(playlistId, out handle).ThrowIfError("Failed to query"); + + if (handle == IntPtr.Zero) + { + return null; + } + + return new Playlist(handle); + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Playlist.Destroy(handle); + } + } + } + + /// + /// Retrieves the number of media info of the playlist. + /// + /// The playlist id to count media added to the playlist. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public int CountMember(int playlistId) + { + return CountMember(playlistId, null); + } + + /// + /// Retrieves the number of media info of the playlist with . + /// + /// The playlist id to count media added to the playlist. + /// The criteria to use to filter. This value can be null. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public int CountMember(int playlistId, CountArguments arguments) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + return CommandHelper.Count(Interop.Playlist.GetMediaCountFromDb, playlistId, arguments); + + } + + private static List GetMembers(int playlistId, SelectArguments arguments) + { + using (var filter = QueryArguments.ToNativeHandle(arguments)) + { + Exception caught = null; + List list = new List(); + + Interop.Playlist.ForeachMediaFromDb(playlistId, filter, (memberId, mediaInfoHandle, _) => + { + try + { + list.Add(new PlaylistMember(memberId, MediaInfo.FromHandle(mediaInfoHandle))); + + return true; + } + catch (Exception e) + { + caught = e; + return false; + } + }).ThrowIfError("Failed to query"); + + if (caught != null) + { + throw caught; + } + + return list; + } + } + + /// + /// Retrieves the member id of the media in the playlist. + /// + /// The playlist id. + /// The media id. + /// The member id if the member was found in the playlist, otherwise -1. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + /// is null. + /// is a zero-length string, contains only white space. + public int GetMemberId(int playlistId, string mediaId) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + var reader = SelectMember(playlistId, new SelectArguments() + { + FilterExpression = $"{MediaInfoColumns.Id}='{mediaId}'" + }); + reader.Read(); + + return reader.Current?.MemberId ?? -1; + } + + /// + /// Retrieves the media info of the playlist. + /// + /// The playlist id to query with. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public MediaDataReader SelectMember(int playlistId) + { + return SelectMember(playlistId, null); + } + + /// + /// Retrieves the media info of the playlist with . + /// + /// The playlist id to query with. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public MediaDataReader SelectMember(int playlistId, SelectArguments filter) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + return new MediaDataReader(GetMembers(playlistId, filter)); + } + + /// + /// Updates a playlist with the specified values. + /// + /// http://tizen.org/privilege/content.write + /// The playlist id to update. + /// The values for update. + /// true if the matched record was found and updated, otherwise false. + /// Only values set in are updated. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is less than or equal to zero. + /// The caller has no required privilege. + public bool Update(int playlistId, PlaylistUpdateValues values) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + + if (CommandHelper.Count( + Interop.Playlist.GetPlaylistCount, $"{PlaylistColumns.Id}={playlistId}") == 0) + { + return false; + } + + Interop.Playlist.Create(out var handle).ThrowIfError("Failed to update"); + + try + { + if (values.Name != null) + { + Interop.Playlist.SetName(handle, values.Name).ThrowIfError("Failed to update"); + } + + if (values.ThumbnailPath != null) + { + Interop.Playlist.SetThumbnailPath(handle, values.ThumbnailPath).ThrowIfError("Failed to update"); + } + + Interop.Playlist.Update(playlistId, handle).ThrowIfError("Failed to update"); + return true; + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Playlist.Destroy(handle); + } + } + } + + /// + /// Adds media to a playlist. + /// + /// The playlist id that the media will be added to. + /// The media id to add to the playlist. + /// true if the matched record was found and updated, otherwise false. + /// The invalid media id will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// is less than or equal to zero. + public bool AddMember(int playlistId, string mediaId) + { + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return AddMembers(playlistId, new string[] { mediaId }); + } + + /// + /// Adds a media set to a playlist. + /// + /// The playlist id that the media will be added to. + /// The collection of media id to add to the playlist. + /// true if the matched record was found and updated, otherwise false. + /// The invalid media ids will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// + /// has no element.\n + /// -or-\n + /// contains null value.\n + /// -or-\n + /// contains a zero-length string or white space.\n + /// + /// is less than or equal to zero. + public bool AddMembers(int playlistId, IEnumerable mediaIds) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + if (mediaIds == null) + { + throw new ArgumentNullException(nameof(mediaIds)); + } + + if (mediaIds.Count() == 0) + { + throw new ArgumentException("mediaIds has no element.", nameof(mediaIds)); + } + + if (CommandHelper.Count( + Interop.Playlist.GetPlaylistCount, $"{PlaylistColumns.Id}={playlistId}") == 0) + { + return false; + } + + IntPtr handle = IntPtr.Zero; + Interop.Playlist.Create(out handle).ThrowIfError("Failed to add member"); + + try + { + foreach (var mediaId in mediaIds) + { + if (mediaId == null) + { + throw new ArgumentException("Media id should not be null.", nameof(mediaIds)); + } + + if (string.IsNullOrWhiteSpace(mediaId)) + { + throw new ArgumentException("Media id should not be empty.", nameof(mediaId)); + } + + Interop.Playlist.AddMedia(handle, mediaId).ThrowIfError("Failed to add member"); + } + + Interop.Playlist.Update(playlistId, handle).ThrowIfError("Failed to add member"); + return true; + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Playlist.Destroy(handle); + } + } + } + + /// + /// Removes a member from a playlist. + /// + /// The playlist id. + /// The member id to be removed. + /// true if the matched record was found and updated, otherwise false. + /// The invalid id will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// + /// is less than or equal to zero.\n + /// -or-\n + /// is less than or equal to zero.\n + /// + public bool RemoveMember(int playlistId, int memberId) + { + if (memberId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(memberId), memberId, + "Member id can't be less than or equal to zero."); + } + + return RemoveMembers(playlistId, new int[] { memberId }); + } + + /// + /// Removes a media set from a playlist. + /// + /// The playlist id. + /// The collection of member id to remove from to the playlist. + /// true if the matched record was found and updated, otherwise false. + /// The invalid ids will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// + /// has no element.\n + /// -or-\n + /// contains a value which is less than or equal to zero. + /// + /// is less than or equal to zero. + public bool RemoveMembers(int playlistId, IEnumerable memberIds) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + if (memberIds == null) + { + throw new ArgumentNullException(nameof(memberIds)); + } + + if (memberIds.Count() == 0) + { + throw new ArgumentException("memberIds has no element.", nameof(memberIds)); + } + + if (CommandHelper.Count( + Interop.Playlist.GetPlaylistCount, $"{PlaylistColumns.Id}={playlistId}") == 0) + { + return false; + } + + IntPtr handle = IntPtr.Zero; + Interop.Playlist.Create(out handle).ThrowIfError("Failed to add member"); + + try + { + foreach (var memberId in memberIds) + { + if (memberId <= 0) + { + throw new ArgumentException(nameof(memberIds), + "Member id can't be less than or equal to zero."); + } + + Interop.Playlist.RemoveMedia(handle, memberId).ThrowIfError("Failed to add member"); + } + + Interop.Playlist.Update(playlistId, handle).ThrowIfError("Failed to add member"); + return true; + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Playlist.Destroy(handle); + } + } + } + + /// + /// Updates a play order of a playlist. + /// + /// The playlist id. + /// The to apply. + /// true if the matched record was found and updated, otherwise false. + /// The that is invalid will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is less than or equal to zero. + public bool UpdatePlayOrder(int playlistId, PlayOrder playOrder) + { + if (playOrder == null) + { + throw new ArgumentNullException(nameof(playOrder)); + } + return UpdatePlayOrders(playlistId, new PlayOrder[] { playOrder }); + } + + /// + /// Updates play orders of a playlist. + /// + /// The playlist id. + /// The collection of to apply. + /// true if the matched record was found and updated, otherwise false. + /// The that is invalid will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// + /// has no element.\n + /// -or-\n + /// contains a null value. + /// + /// is less than or equal to zero. + public bool UpdatePlayOrders(int playlistId, IEnumerable orders) + { + ValidateDatabase(); + + if (playlistId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, + "Playlist id can't be less than or equal to zero."); + } + + if (orders == null) + { + throw new ArgumentNullException(nameof(orders)); + } + + if (orders.Count() == 0) + { + throw new ArgumentException("memberIds has no element.", nameof(orders)); + } + + if (CommandHelper.Count( + Interop.Playlist.GetPlaylistCount, $"{PlaylistColumns.Id}={playlistId}") == 0) + { + return false; + } + + IntPtr handle = IntPtr.Zero; + Interop.Playlist.Create(out handle).ThrowIfError("Failed to add member"); + + try + { + foreach (var order in orders) + { + if (order == null) + { + throw new ArgumentException(nameof(orders), + "orders should not contain null value."); + } + Interop.Playlist.SetPlayOrder(handle, order.MemberId, order.Value).ThrowIfError("Failed to add member"); + } + + Interop.Playlist.Update(playlistId, handle).ThrowIfError("Failed to add member"); + return true; + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Playlist.Destroy(handle); + } + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistMember.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistMember.cs new file mode 100644 index 0000000..e0d047c --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistMember.cs @@ -0,0 +1,42 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Represents a member of . + /// + public class PlaylistMember + { + /// + /// Gets the member id. + /// + /// The member id of playlist. + public int MemberId { get; } + + /// + /// Gets the media info of the member. + /// + /// The of the member. + public MediaInfo MediaInfo { get; } + + internal PlaylistMember(int memberId, MediaInfo mediaInfo) + { + MemberId = memberId; + MediaInfo = mediaInfo; + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/QueryArguments.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/QueryArguments.cs new file mode 100644 index 0000000..b249158 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/QueryArguments.cs @@ -0,0 +1,282 @@ +/* + * 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.Diagnostics; +using FilterHandle = Interop.FilterHandle; + +namespace Tizen.Content.MediaContent +{ + /// + /// Base class for query arguments. + /// + /// + /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist + /// and MediaInfo on basis of details like limit, order and condition. + /// + public class QueryArguments + { + private string _filter; + + /// + /// Gets or sets the filtering expression that is applied. + /// + /// A string that represents a filtering expression applied when data is retrieved. + /// + /// Expressions for the filter can be one of the following forms: + /// + /// column = value + /// column > value + /// column >= value + /// column < value + /// column <= value + /// value = column + /// value >= column + /// value < column + /// value <= column + /// column IN (value) + /// column IN(value-list) + /// column NOT IN(value) + /// column NOT IN(value-list) + /// column LIKE value + /// expression COLLATE NOCASE + /// expression COLLATE RTRIM + /// expression COLLATE LOCALIZED + /// expression1 AND expression2 OR expression3 ... + /// + /// + /// Note that if you want to set quotation(" ' " or " " ") as value of LIKE operator, you should use two times.(" '' " or " "" "). + /// And the optional ESCAPE clause is supported. Both percent symbol("%") and underscore symbol("_") are used in the LIKE pattern. + /// If these characters are used as value of LIKE operation, then the expression following the ESCAPE clause of sqlite will be ignored.\n + /// \n + /// For example,\n + /// - column LIKE('#%') ESCAPE('#') - "#" is escape character, it will be ignored. + /// + /// is a zero-length string, contains only white space. + /// + /// + /// + /// + /// + /// + /// + public string FilterExpression + { + get => _filter; + set + { + if (value != null) + { + ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value)); + } + + _filter = value; + } + } + + private string _storageId; + + /// + /// Gets or sets the storage id for the given filter. + /// You can use this property when you want to search items only in the specific storage. + /// + /// The storage id to restrict storage to search, or null for all storages. + /// is a zero-length string, contains only white space. + public string StorageId + { + get => _storageId; + set + { + if (value != null) + { + ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value)); + } + + _storageId = value; + } + } + + internal static FilterHandle ToNativeHandle(QueryArguments arguments) + { + if (arguments == null || arguments.IsEmpty()) + { + return FilterHandle.Null; + } + + Interop.Filter.Create(out var handle).ThrowIfError("Failed to apply arguments."); + + try + { + arguments.FillHandle(handle); + } + catch (Exception) + { + handle.Dispose(); + throw; + } + + return handle; + } + + internal static FilterHandle CreateNativeHandle(string filterExpression) + { + Debug.Assert(filterExpression != null); + + Interop.Filter.Create(out var handle).ThrowIfError("Failed to apply arguments."); + + Interop.Filter.SetCondition(handle, filterExpression, Collation.Default). + ThrowIfError("Failed to create filter handle."); + + return handle; + } + + internal virtual bool IsEmpty() + { + return StorageId == null && FilterExpression == null; + } + + internal virtual void FillHandle(FilterHandle handle) + { + if (FilterExpression != null) + { + Interop.Filter.SetCondition(handle, FilterExpression, Collation.Default). + ThrowIfError("Failed to create filter handle(condition)"); + } + + if (StorageId != null) + { + Interop.Filter.SetStorage(handle, StorageId). + ThrowIfError("Failed to create filter handle(storage id)"); ; + } + } + } + + /// + /// Provides the ability to filter the result of a Select command. + /// + /// + /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist + /// and MediaInfo. + /// + public class SelectArguments : QueryArguments + { + private int _startRowIndex; + + /// + /// Gets or sets the starting row position of a query(starting from zero). + /// + /// An integer value that indicates the starting row position of a query. + /// is less than zero.\n + public int StartRowIndex + { + get => _startRowIndex; + set + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "StartRowIndex can't be less than zero."); + } + + _startRowIndex = value; + } + } + + private int _totalRowCount; + + /// + /// Gets or sets the number of rows to be retrieved. + /// + /// An integer value that indicates the limit of rows of the result. + /// is less than zero. + public int TotalRowCount + { + get => _totalRowCount; + set + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "TotalRowCount can't be less than zero."); + } + + _totalRowCount = value; + } + } + + private string _sortOrder; + + /// + /// Gets or sets the sort order of the results. + /// + /// The expression for the sort order. + /// + /// Expressions for the sort order can be:\n + /// column [COLLATE NOCASE/RTRIM/LOCALIZED] [ASC/DESC], column2 ... + /// + /// is a zero-length string, contains only white space. + /// + /// + /// + /// + /// + /// + /// + public string SortOrder + { + get => _sortOrder; + set + { + if (value != null) + { + ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value)); + } + + _sortOrder = value; + } + } + + internal override bool IsEmpty() + { + return base.IsEmpty() && StartRowIndex == 0 && TotalRowCount == 0 && SortOrder == null; + } + + internal override void FillHandle(FilterHandle handle) + { + base.FillHandle(handle); + + if (StartRowIndex != 0 || TotalRowCount != 0) + { + Interop.Filter.SetOffset(handle, StartRowIndex, TotalRowCount). + ThrowIfError("Failed to create filter handle(limit)"); + } + + if (SortOrder != null) + { + Interop.Filter.SetOrder(handle, SortOrder).ThrowIfError("Failed to create filter handle(order)"); + } + } + } + + /// + /// Provides the ability to filter the result of a Count command. + /// + /// + /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist + /// and MediaInfo. + /// + public class CountArguments : QueryArguments + { + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/RecordNotFoundException.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/RecordNotFoundException.cs new file mode 100644 index 0000000..452fb0f --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/RecordNotFoundException.cs @@ -0,0 +1,51 @@ +/* + * 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.Content.MediaContent +{ + /// + /// The exception that is thrown when no record is found in the database. + /// + public class RecordNotFoundException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public RecordNotFoundException() : base("No record found.") + { + } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// The message that describes the error. + public RecordNotFoundException(string message) : base(message) + { + } + + /// + /// Initializes a new instance of the class with a specified error message + /// and a reference to the inner exception that is the cause of this exception. + /// + /// The message that describes the error. + /// The exception that is the cause of the current exception. + public RecordNotFoundException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Rectangle.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Rectangle.cs new file mode 100644 index 0000000..29d437b --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Rectangle.cs @@ -0,0 +1,130 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Represents location of the object bounded by rectangle defined by + /// coordinates of top left corner, width and height. + /// + public struct Rectangle + { + /// + /// Initializes a new instance of the Rectangle with the specified values. + /// + /// The x-coordinate of the upper-left corner of the rectangle. + /// The y-coordinate of the upper-left corner of the rectangle. + /// The Width of the rectangle. + /// The Height of the rectangle. + public Rectangle(int x, int y, int width, int height) + { + X = x; + Y = y; + Width = width; + Height = height; + } + + /// + /// Gets or sets the x-coordinate of the upper-left corner of the rectangle. + /// + /// The x-coordinate of the upper-left edge of the rectangle. + public int X { get; set; } + + /// + /// Gets or sets the y-coordinate of the upper-left corner of the rectangle. + /// + /// The y-coordinate of the upper-left edge of the rectangle. + public int Y { get; set; } + + /// + /// Gets or sets the width of the rectangle. + /// + /// The width of the rectangle. + public int Width { get; set; } + + /// + /// Gets or sets the height of the rectangle. + /// + /// The height of the rectangle. + public int Height { get; set; } + + /// + /// Gets the x-coordinate of the left edge of the rectangle. + /// + /// The x-coordinate of the left edge of the rectangle. + public int Left => X; + + /// + /// Gets the y-coordinate of the top edge of the rectangle. + /// + /// The y-coordinate of the top edge of the rectangle. + public int Top => Y; + + /// + /// Gets the x-coordinate of the right edge of the rectangle. + /// + /// The x-coordinate of the right edge of the rectangle. + public int Right => X + Width; + + /// + /// Gets the y-coordinate of the bottom edge of the rectangle. + /// + /// The y-coordinate of the bottom edge of the rectangle. + public int Bottom => Y + Height; + + /// + /// Returns a string representation of the rectangle. + /// + /// A string representation of the current rectangle. + public override string ToString() => + $"X={X.ToString()}, Y={Y.ToString()}, Width={Width.ToString()}, Height={Height.ToString()}"; + + /// + /// Returns the hash code for this Rectangle structure. + /// + /// An integer that represents the hash code for this rectangle. + public override int GetHashCode() => new { X, Y, Width, Height }.GetHashCode(); + + /// + /// Tests whether obj is a Rectangle structure with the same location and size of this Rectangle structure. + /// + /// A to compare. + /// + /// true if obj is a Rectangle structure and its X, Y, Width and Height properties are + /// equal to the corresponding properties of this Rectangle structure; otherwise, false. + /// + public override bool Equals(object obj) => obj is Rectangle && this == (Rectangle)obj; + + /// + /// Tests whether two Rectangle structures have equal location and size. + /// + /// A to compare. + /// A to compare. + /// true if the two Rectangle structures have equal X, Y, Width, and Height properties; otherwise, false. + public static bool operator ==(Rectangle rect1, Rectangle rect2) + => rect1.X == rect2.X && rect1.Y == rect2.Y && rect1.Width == rect2.Width && rect1.Height == rect2.Height; + + /// + /// Tests whether two Rectangle structures differ in location or size. + /// + /// A to compare. + /// A to compare. + /// true if any of the X, Y, Width or Height properties of the two Rectangle structures are unequal; otherwise false. + public static bool operator !=(Rectangle rect1, Rectangle rect2) => !(rect1 == rect2); + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Storage.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Storage.cs index b6935ef..840d673 100755 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Storage.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Storage.cs @@ -1,219 +1,64 @@ -/* -* 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. -*/ - - +/* + * 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.Runtime.InteropServices; -using System.Threading.Tasks; namespace Tizen.Content.MediaContent { /// - /// A Storage allows you to manage external storage. - /// The system generates the storage id when the external storage is added.And the system manages the media information in each of the storage by using storage id. - /// So you can get the information from the storage that you want to view. + /// Represents the storage information for media. /// - public class Storage : ContentCollection + /// + /// The system generates the storage id when the external storage is added. and manages the media information + /// in each of the storage by using storage id. + /// + public class Storage { - private IntPtr _storageHandle = IntPtr.Zero; - private IntPtr Handle + internal Storage(IntPtr handle) { - get - { - if (_storageHandle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(Storage)); - } - - return _storageHandle; - } + Path = InteropHelper.GetString(handle, Interop.Storage.GetPath); + Id = InteropHelper.GetString(handle, Interop.Storage.GetId); + Type = InteropHelper.GetValue(handle, Interop.Storage.GetType); } - /// - /// The storage id of the media storage - /// - /// 3 - public string Id - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Storage.GetId(Handle, out val), "Failed to get value"); - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } + internal static Storage FromHandle(IntPtr handle) => new Storage(handle); /// - /// The storage path of the media storage + /// Gets the id of the storage. /// - /// 3 - public string StoragePath - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Storage.GetPath(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } + /// The unique id of the storage. + public string Id { get; } /// - /// The storage name of the media storage + /// Gets the path of the storage. /// - /// 3 - public string Name - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Storage.GetName(Handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } + /// The path of the storage. + public string Path { get; } /// - /// The storage type of the media storage + /// Gets the type of the storage. /// - /// 3 - public ContentStorageType StorageType - { - get - { - ContentStorageType storageType; - MediaContentValidator.ThrowIfError( - Interop.Storage.GetType(Handle, out storageType), "Failed to get value"); - - return storageType; - } - } - - internal Storage(IntPtr handle) - { - _storageHandle = handle; - } - - /// - /// Gets the count of media files for the passed filter in the given storage from the media database. - /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// The number of media contents matching the filter passed - public override int GetMediaInformationCount(ContentFilter filter) - { - int mediaCount; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Storage.GetMediaCountFromDb(Id, handle, out mediaCount), "Failed to get count"); - - return mediaCount; - } - - public override void Dispose() - { - if (_storageHandle != IntPtr.Zero) - { - Interop.Storage.Destroy(_storageHandle); - _storageHandle = IntPtr.Zero; - } - } + /// The type of the storage. + public StorageType Type { get; } /// - /// Iterates through the media files with an optional filter in the given storage from the media database. - /// This function gets all media files associated with the given storage and meeting desired filter option. - /// If NULL is passed to the filter, no filtering is applied. + /// Returns a string representation of the storage. /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// List of content media items matching the passed filter - public override IEnumerable GetMediaInformations(ContentFilter filter) - { - List mediaContents = new List(); - - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - Interop.Storage.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) => - { - Interop.MediaInformation.SafeMediaInformationHandle newHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone media"); - - MediaContentType type; - Interop.MediaInformation.GetMediaType(newHandle, out type); - if (type == MediaContentType.Image) - { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information"); - - mediaContents.Add(new ImageInformation(imageInfo, newHandle)); - } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information"); - - mediaContents.Add(new AudioInformation(audioInfo, newHandle)); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information"); - - mediaContents.Add(new VideoInformation(videoInfo, newHandle)); - } - else if (type == MediaContentType.Others) - { - mediaContents.Add(new MediaInformation(newHandle)); - } - - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.Storage.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero), "Failed to get information"); - - return mediaContents; - } + /// A string representation of the current storage. + public override string ToString() => + $"Id={Id}, Path={Path}, Type={Type}"; } } diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/StorageCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/StorageCommand.cs new file mode 100644 index 0000000..6975660 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/StorageCommand.cs @@ -0,0 +1,197 @@ +/* + * 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.Content.MediaContent +{ + /// + /// Provides commands to manage external storages in the database. + /// + /// + /// Internal storage is not managed. + /// + /// + public class StorageCommand : MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + public StorageCommand(MediaDatabase database) : base(database) + { + } + + /// + /// Retrieves the number of storages. + /// + /// The number of storages. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count() => Count(arguments: null); + + /// + /// Retrieves the number of storages with . + /// + /// The criteria to use to filter. This value can be null. + /// The number of storages filtered. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count(CountArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Count(Interop.Storage.GetStorageCountFromDb, arguments); + } + + /// + /// Retrieves the storage with the specified id. + /// + /// The storage id to select. + /// The instance if the matched record was found in the database, otherwise null. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public Storage Select(string storageId) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(storageId, nameof(storageId)); + + IntPtr handle = IntPtr.Zero; + + try + { + Interop.Storage.GetStorageInfoFromDb(storageId, out handle).ThrowIfError("Failed to query"); + + return handle == IntPtr.Zero ? null : new Storage(handle); + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Storage.Destroy(handle); + } + } + } + + /// + /// Retrieves all the storages. + /// + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select() => Select(arguments: null); + + /// + /// Retrieves the storages with . + /// + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select(SelectArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Select(arguments, Interop.Storage.ForeachStorageFromDb, Storage.FromHandle); + } + + private bool Exists(string storageId) + { + ValidateDatabase(); + + ValidationUtil.ValidateNotNullOrEmpty(storageId, nameof(storageId)); + + return Count(new CountArguments { FilterExpression = $"{StorageColumns.Id}='{storageId}'" }) != 0; + } + + /// + /// Retrieves the number of media info of the storage. + /// + /// The storage id. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountMedia(string storageId) => CountMedia(storageId, null); + + /// + /// Retrieves the number of media info of the storage with . + /// + /// The storage id to query with. + /// The criteria to use to filter. This value can be null. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public int CountMedia(string storageId, CountArguments arguments) + { + if (Exists(storageId) == false) + { + return 0; + } + + return CommandHelper.Count(Interop.Storage.GetMediaCountFromDb, storageId, arguments); + } + + /// + /// Retrieves the media info of the storage. + /// + /// The storage id. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectMedia(string storageId) => SelectMedia(storageId, null); + + /// + /// Retrieves the media info of the storage with . + /// + /// The storage id. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + public MediaDataReader SelectMedia(string storageId, SelectArguments filter) + { + if (Exists(storageId) == false) + { + return new MediaDataReader(new MediaInfo[0]); + } + + return CommandHelper.SelectMedia(Interop.Storage.ForeachMediaFromDb, storageId, filter); + } + + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Tag.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Tag.cs index 181b763..43dd24e 100755 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Tag.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Tag.cs @@ -1,217 +1,55 @@ -/* -* 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. -*/ - +/* + * 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.Runtime.InteropServices; -using System.Threading.Tasks; namespace Tizen.Content.MediaContent { /// - /// A Tag is a special piece of information that may be associated with media content items. - /// Tagging allows a user to organize large number of items into logical groups providing a simplified and faster way of accessing media content items. + /// Represents a special piece of information that may be associated with media.\n + /// Tagging allows a user to organize large number of items into logical groups providing + /// a simplified and faster way of accessing media items. /// - public class Tag : ContentCollection + public class Tag { - private IntPtr _tagHandle = IntPtr.Zero; - private string _tagName = ""; - - internal IntPtr Handle + internal Tag(IntPtr handle) { - get - { - if (_tagHandle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(Tag)); - } - - return _tagHandle; - } - - set - { - _tagHandle = value; - } - } - /// - /// The ID of the media tag - /// - /// 3 - public int Id - { - get - { - int id; - MediaContentValidator.ThrowIfError( - Interop.Tag.GetTagId(Handle, out id), "Failed to get value"); - return id; - } + Name = InteropHelper.GetString(handle, Interop.Tag.GetName); + Id = InteropHelper.GetValue(handle, Interop.Tag.GetId); } /// - /// The name of the tag + /// Gets the id of the tag. /// - /// 3 - public string Name - { - get - { - return _tagName; - } - - set - { - MediaContentValidator.ThrowIfError( - Interop.Tag.SetName(Handle, value), "Failed to set value"); - _tagName = value; - } - } - - internal Tag(IntPtr tagHandle) - { - _tagHandle = tagHandle; - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.Tag.GetName(Handle, out val), "Failed to get value"); - _tagName = Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } + /// The unique id of the tag. + public int Id { get; } /// - /// Creates a Tag object which can be inserted to the media database using ContentManager:InsertToDatabaseAsync(ContentCollection) + /// Gets the name of the tag. /// - /// 3 - /// The name of the media tag - public Tag(string tagName) - { - _tagName = tagName; - } + /// The name of the tag. + public string Name { get; } - /// - /// Adds a new media info to the tag. - /// - /// 3 - /// The media info which is added - public void AddItem(MediaInformation mediaContent) - { - MediaContentValidator.ThrowIfError( - Interop.Tag.AddMedia(Handle, mediaContent.MediaId), "Failed to add item"); - } + internal static Tag FromHandle(IntPtr handle) => new Tag(handle); /// - /// Removes the media info from the given tag. + /// Returns a string representation of the tag. /// - /// 3 - /// The media info which is removed - public void RemoveItem(MediaInformation mediaContent) - { - MediaContentValidator.ThrowIfError( - Interop.Tag.RemoveMedia(Handle, mediaContent.MediaId), "Failed to remove item"); - } + /// A string representation of the current tag. + public override string ToString() => $"Id={Id}, Name={Name}"; - /// - /// Gets the number of media files for the passed filter in the given tag from the media database. - /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// The number of media contents matching the filter passed - public override int GetMediaInformationCount(ContentFilter filter) - { - int mediaCount; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.Tag.GetMediaCountFromDb(Id, handle, out mediaCount), "Failed to get count"); - - return mediaCount; - } - - public override void Dispose() - { - if (_tagHandle != IntPtr.Zero) - { - Interop.Tag.Destroy(_tagHandle); - _tagHandle = IntPtr.Zero; - } - } - - /// - /// Iterates through media items for a given tag from the media database. - /// This function gets all media items associated with a given tag and meeting a desired filter. - /// If NULL is passed to the filter, no filtering is applied. - /// - /// 3 - /// ContentFilter used to match media content from the media database. - /// List of content media items matching the passed filter - public override IEnumerable GetMediaInformations(ContentFilter filter) - { - List mediaContents = new List(); - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - - Interop.Tag.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) => - { - Interop.MediaInformation.SafeMediaInformationHandle newHandle; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone media"); - - MediaContentType type; - Interop.MediaInformation.GetMediaType(newHandle, out type); - if (type == MediaContentType.Image) - { - Interop.ImageInformation.SafeImageInformationHandle imageInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information"); - - mediaContents.Add(new ImageInformation(imageInfo, newHandle)); - } - else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound)) - { - Interop.AudioInformation.SafeAudioInformationHandle audioInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information"); - - mediaContents.Add(new AudioInformation(audioInfo, newHandle)); - } - else if (type == MediaContentType.Video) - { - Interop.VideoInformation.SafeVideoInformationHandle videoInfo; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information"); - - mediaContents.Add(new VideoInformation(videoInfo, newHandle)); - } - else if (type == MediaContentType.Others) - { - mediaContents.Add(new MediaInformation(newHandle)); - } - - return true; - }; - - MediaContentValidator.ThrowIfError( - Interop.Tag.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero), "Failed to get information"); - - return mediaContents; - } } } diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/TagCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/TagCommand.cs new file mode 100644 index 0000000..37730ec --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/TagCommand.cs @@ -0,0 +1,471 @@ +/* + * 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; + +namespace Tizen.Content.MediaContent +{ + /// + /// Provides commands to manage tags in the database. + /// + /// + public class TagCommand : MediaCommand + { + /// + /// Initializes a new instance of the class with the specified . + /// + /// A that the commands run on. + /// is null. + /// has already been disposed of. + public TagCommand(MediaDatabase database) : base(database) + { + } + + /// + /// Retrieves the number of tags. + /// + /// The number of tags. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count() + { + return Count(arguments: null); + } + + /// + /// Retrieves the number of tags with . + /// + /// The criteria to use to filter. This value can be null. + /// The number of tags filtered. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public int Count(CountArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Count(Interop.Tag.GetTagCount, arguments); + } + + + /// + /// Deletes a tag from the database. + /// + /// http://tizen.org/privilege/content.write + /// The tag id to delete. + /// true if the matched record was found and deleted, otherwise false. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + /// The caller has no required privilege. + public bool Delete(int tagId) + { + ValidateDatabase(); + + if (tagId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(tagId), tagId, + "Tag id can't be less than or equal to zero."); + } + + if (CommandHelper.Count(Interop.Tag.GetTagCount, $"{TagColumns.Id}={tagId}") == 0) + { + return false; + } + + CommandHelper.Delete(Interop.Tag.Delete, tagId); + return true; + } + + + /// + /// Inserts a tag into the database with the specified name. + /// + /// http://tizen.org/privilege/content.write + /// The name of tag. + /// The instance that contains the record information inserted. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// The caller has no required privilege. + public Tag Insert(string name) + { + ValidateDatabase(); + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (name.Length == 0) + { + throw new ArgumentException("Tag name can't be an empty string."); + } + + Interop.Tag.Insert(name, out var handle).ThrowIfError("Failed to insert a new tag"); + + try + { + return new Tag(handle); + } + finally + { + Interop.Tag.Destroy(handle); + } + } + + /// + /// Updates a tag with the specified name. + /// + /// http://tizen.org/privilege/content.write + /// The tag id to update. + /// The new name. + /// true if the matched record was found and updated, otherwise false. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is less than or equal to zero. + /// The caller has no required privilege. + public bool UpdateName(int tagId, string name) + { + ValidateDatabase(); + + if (tagId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(tagId), tagId, + "Tag id can't be less than or equal to zero."); + } + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (CommandHelper.Count(Interop.Tag.GetTagCount, $"{TagColumns.Id}={tagId}") == 0) + { + return false; + } + + Interop.Tag.Create(out var handle).ThrowIfError("Failed to update"); + + try + { + Interop.Tag.SetName(handle, name).ThrowIfError("Failed to update"); + Interop.Tag.Update(tagId, handle).ThrowIfError("Failed to update"); + + return true; + } + finally + { + Interop.Tag.Destroy(handle); + } + } + + /// + /// Retrieves the tag with the specified id. + /// + /// The tag id to select. + /// The instance if the matched record was found in the database, otherwise null. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public Tag Select(int tagId) + { + ValidateDatabase(); + + if (tagId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(tagId), tagId, + "Tag id can't be less than or equal to zero."); + } + + IntPtr handle = IntPtr.Zero; + + try + { + Interop.Tag.GetTagFromDb(tagId, out handle).ThrowIfError("Failed to query"); + + if (handle == IntPtr.Zero) + { + return null; + } + return new Tag(handle); + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Tag.Destroy(handle); + } + } + + } + + /// + /// Retrieves all the tags. + /// + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select() + { + return Select(arguments: null); + } + + /// + /// Retrieves the tags with . + /// + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + public MediaDataReader Select(SelectArguments arguments) + { + ValidateDatabase(); + + return CommandHelper.Select(arguments, Interop.Tag.ForeachTagFromDb, Tag.FromHandle); + } + + /// + /// Retrieves the number of media info of the tag. + /// + /// The tag id. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public int CountMedia(int tagId) + { + return CountMedia(tagId, null); + } + + /// + /// Retrieves the number of media info of the tag with . + /// + /// The tag id to query with. + /// The criteria to use to filter. This value can be null. + /// The number of media info. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public int CountMedia(int tagId, CountArguments arguments) + { + ValidateDatabase(); + + if (tagId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(tagId), tagId, + "Tag id can't be less than or equal to zero."); + } + + return CommandHelper.Count(Interop.Tag.GetMediaCount, tagId, arguments); + } + + /// + /// Retrieves the media info of the tag. + /// + /// The tag id. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public MediaDataReader SelectMedia(int tagId) + { + return SelectMedia(tagId, null); + } + + /// + /// Retrieves the media info of the tag with . + /// + /// The tag id. + /// The criteria to use to filter. This value can be null. + /// The containing the results. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is less than or equal to zero. + public MediaDataReader SelectMedia(int tagId, SelectArguments filter) + { + ValidateDatabase(); + + if (tagId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(tagId), tagId, + "Tag id can't be less than or equal to zero."); + } + + return CommandHelper.SelectMedia(Interop.Tag.ForeachMediaFromDb, tagId, filter); + } + + private bool UpdateMember(int tagId, IEnumerable mediaIds, + Func func) + { + ValidateDatabase(); + + if (tagId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(tagId), tagId, + "Tag id can't be less than or equal to zero."); + } + + if (mediaIds == null) + { + throw new ArgumentNullException(nameof(mediaIds)); + } + + if (mediaIds.Count() == 0) + { + throw new ArgumentException("mediaIds has no element.", nameof(mediaIds)); + } + + if (CommandHelper.Count(Interop.Tag.GetTagCount, $"{TagColumns.Id}={tagId}") == 0) + { + return false; + } + + IntPtr handle = IntPtr.Zero; + Interop.Tag.Create(out handle).ThrowIfError("Failed to initialize update member operation"); + + try + { + foreach (var mediaId in mediaIds) + { + if (mediaId == null) + { + throw new ArgumentException("Media id should not be null.", nameof(mediaIds)); + } + + if (string.IsNullOrWhiteSpace(mediaId)) + { + throw new ArgumentException("Media id should not be a zero-length string.", nameof(mediaId)); + } + + func(handle, mediaId).ThrowIfError("Failed to update member"); + } + + Interop.Tag.Update(tagId, handle).ThrowIfError("Failed to run member update"); + return true; + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.Tag.Destroy(handle); + } + } + } + + /// + /// Adds media to a tag. + /// + /// The tag id that the media will be added to. + /// The media id to add to the tag. + /// true if the matched record was found and updated, otherwise false. + /// The invalid media id will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// is less than or equal to zero. + public bool AddMedia(int tagId, string mediaId) + { + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return AddMedia(tagId, new string[] { mediaId }); + } + + /// + /// Adds a media set to a tag. + /// + /// The tag id that the media will be added to. + /// The media id to add to the tag. + /// true if the matched record was found and updated, otherwise false. + /// The invalid media ids will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// + /// has no element.\n + /// -or-\n + /// contains null value.\n + /// -or-\n + /// contains a zero-length string, contains only white space.\n + /// + /// is less than or equal to zero. + public bool AddMedia(int tagId, IEnumerable mediaIds) + { + return UpdateMember(tagId, mediaIds, Interop.Tag.AddMedia); + } + + /// + /// Removes media from a tag. + /// + /// The tag id. + /// The media id to remove from the tag. + /// true if the matched record was found and updated, otherwise false. + /// The invalid media id will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// is a zero-length string, contains only white space. + /// is less than or equal to zero. + public bool RemoveMedia(int tagId, string mediaId) + { + ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); + + return RemoveMedia(tagId, new string[] { mediaId }); + } + + /// + /// Removes a media set from a tag. + /// + /// The tag id. + /// The collection of media id to remove from the tag. + /// true if the matched record was found and updated, otherwise false. + /// The invalid ids will be ignored. + /// The is disconnected. + /// The has already been disposed of. + /// An error occurred while executing the command. + /// is null. + /// + /// has no element.\n + /// -or-\n + /// contains null value.\n + /// -or-\n + /// contains a zero-length string or white space.\n + /// + /// is less than or equal to zero. + public bool RemoveMedia(int tagId, IEnumerable mediaIds) + { + return UpdateMember(tagId, mediaIds, Interop.Tag.RemoveMedia); + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/UnsupportedContentException.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/UnsupportedContentException.cs new file mode 100644 index 0000000..a0b1b69 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/UnsupportedContentException.cs @@ -0,0 +1,51 @@ +/* + * 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.Content.MediaContent +{ + /// + /// The exception that is thrown when a requested operation is not supported for content. + /// + public class UnsupportedContentException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public UnsupportedContentException() : base("The operation is not supported for the given media.") + { + } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// The message that describes the error. + public UnsupportedContentException(string message) : base(message) + { + } + + /// + /// Initializes a new instance of the class with a specified error message + /// and a reference to the inner exception that is the cause of this exception. + /// + /// The message that describes the error. + /// The exception that is the cause of the current exception. + public UnsupportedContentException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ValdiationUtil.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ValdiationUtil.cs new file mode 100644 index 0000000..30c3644 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ValdiationUtil.cs @@ -0,0 +1,44 @@ +/* + * 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.Content.MediaContent +{ + internal static class ValidationUtil + { + internal static void ValidateEnum(Type enumType, object value, string paramName) + { + if (!Enum.IsDefined(enumType, value)) + { + throw new ArgumentException($"Invalid { enumType.Name } value : { value }", paramName); + } + } + + internal static void ValidateNotNullOrEmpty(string value, string paramName) + { + if (value == null) + { + throw new ArgumentNullException(paramName); + } + + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException($"{paramName} is a zero-length string.", paramName); + } + } + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/VideoInfo.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/VideoInfo.cs new file mode 100644 index 0000000..bca5890 --- /dev/null +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/VideoInfo.cs @@ -0,0 +1,137 @@ +/* + * 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.Diagnostics; + +namespace Tizen.Content.MediaContent +{ + /// + /// Represents a video media information. + /// + public class VideoInfo : MediaInfo + { + internal VideoInfo(Interop.MediaInfoHandle handle) : base(handle) + { + IntPtr videoHandle = IntPtr.Zero; + + try + { + Interop.MediaInfo.GetVideo(handle, out videoHandle).ThrowIfError("Failed to retrieve data"); + + Debug.Assert(videoHandle != IntPtr.Zero); + + Album = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetAlbum); + Artist = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetArtist); + AlbumArtist = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetAlbumArtist); + Genre = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetGenre); + Composer = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetComposer); + Year = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetYear); + DateRecorded = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetRecordedDate); + Copyright = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetCopyright); + TrackNumber = InteropHelper.GetString(videoHandle, Interop.VideoInfo.GetTrackNum); + + BitRate = InteropHelper.GetValue(videoHandle, Interop.VideoInfo.GetBitRate); + Duration = InteropHelper.GetValue(videoHandle, Interop.VideoInfo.GetDuration); + Width = InteropHelper.GetValue(videoHandle, Interop.VideoInfo.GetWidth); + Height = InteropHelper.GetValue(videoHandle, Interop.VideoInfo.GetHeight); + } + finally + { + Interop.VideoInfo.Destroy(videoHandle); + } + } + + /// + /// Gets the album name. + /// + /// The album name from the metadata. + public string Album { get; } + + /// + /// Gets the artist name. + /// + /// The artist name from the metadata. + public string Artist { get; } + + /// + /// Gets the album artist name. + /// + /// The album artist name from the metadata. + public string AlbumArtist { get; } + + /// + /// Gets the genre. + /// + /// The genre name from the metadata. + public string Genre { get; } + + /// + /// Gets the composer name. + /// + /// The composer name from the metadata. + public string Composer { get; } + + /// + /// Gets the year. + /// + /// The year from the metadata. + public string Year { get; } + + /// + /// Gets the recorded date. + /// + /// The recorded date information from the metadata if exists; otherwise, the modified date of the file. + public string DateRecorded { get; } + + /// + /// Gets the copyright notice. + /// + /// The copyright notice from the metadata. + public string Copyright { get; } + + /// + /// Gets the track number. + /// + /// The track number from the metadata. + public string TrackNumber { get; } + + /// + /// Gets the bitrate in bit per second. + /// + /// The bit rate of the video. + public int BitRate { get; } + + /// + /// Gets the track duration in milliseconds. + /// + /// The track duration of the video in milliseconds. + public int Duration { get; } + + /// + /// Gets the video width in pixels. + /// + /// The width of the video in pixels. + public int Width { get; } + + /// + /// Gets the video height in pixels. + /// + /// The height of the video in pixels. + public int Height { get; } + + } +} diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/VideoInformation.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/VideoInformation.cs deleted file mode 100755 index da48d28..0000000 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/VideoInformation.cs +++ /dev/null @@ -1,431 +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.Runtime.InteropServices; -using System.Threading.Tasks; -using System.Collections.ObjectModel; - -namespace Tizen.Content.MediaContent -{ - /// - /// VideoContent class API gives the information related to the image media stored in the device - /// - public class VideoInformation : MediaInformation - { - /// - /// Gets the ID of the media. - /// - /// 3 - public string MediaId - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetMediaId(_handle, out val), "Failed to get value"); - - return Marshal.PtrToStringAnsi(val); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the album name. - /// If the media content has no album information, the property returns empty string. - /// - /// 3 - public string Album - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetAlbum(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the artist name. - /// If the media content has no artist information, the property returns empty string. - /// - /// 3 - public string Artist - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetArtist(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the album artist name. - /// If the media content has no album artist information, the property returns empty string. - /// - /// 3 - public string AlbumArtist - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetAlbumArtist(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the genre name. - /// If the media content has no genre information, the property returns empty string. - /// - /// 3 - public string Genre - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetGenre(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the composer name. - /// If the media content has no composer information, the property returns empty string. - /// - /// 3 - public string Composer - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetComposer(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the year. - /// If the media content has no year information, the property returns empty string. - /// - /// 3 - public string Year - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetYear(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the recorded date. - /// - /// 3 - public string RecordedDate - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetRecordedDate(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the copyright notice. - /// If the media content has no copyright information, the property returns empty string. - /// - /// 3 - public string Copyright - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetCopyright(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the track number. - /// If the media content has no track information, the property returns empty string. - /// - /// 3 - public string TrackNumber - { - get - { - IntPtr val = IntPtr.Zero; - try - { - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetTrackNum(_handle, out val), "Failed to get value"); - - return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val)); - } - finally - { - Interop.Libc.Free(val); - } - } - } - - /// - /// Gets the bitrate in bit per second [bps]. - /// - /// 3 - public int BitRate - { - get - { - int bitrate = 0; - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetBitRate(_handle, out bitrate), "Failed to get value"); - - return bitrate; - } - } - - /// - /// Gets the track duration in Milliseconds. - /// - /// 3 - public int Duration - { - get - { - int duration = 0; - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetDuration(_handle, out duration), "Failed to get value"); - - return duration; - } - } - - /// - /// Gets the video width in pixels. - /// - /// 3 - public int Width - { - get - { - int width = 0; - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetWidth(_handle, out width), "Failed to get value"); - - return width; - } - } - - /// - /// Gets the video height in pixels. - /// - /// 3 - public int Height - { - get - { - int height = 0; - MediaContentValidator.ThrowIfError( - Interop.VideoInformation.GetHeight(_handle, out height), "Failed to get value"); - - return height; - } - } - - /// - /// Gets the number of bookmarks for the passed filter in the given media ID from the media database. - /// - /// 3 - /// - /// int count - /// The Filter for matching Bookmarks - public int GetMediaBookmarkCount(ContentFilter filter) - { - int count = 0; - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetBookmarkCount(MediaId, handle, out count), "Failed to get count"); - - return count; - } - - /// - /// Iterates through the media bookmark in the given media info from the media database. - /// - /// 3 - /// - /// Task to get all the Bookmarks - /// filter for the Tags - public IEnumerable GetMediaBookmarks(ContentFilter filter) - { - Collection result = new Collection(); - IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero; - Interop.MediaInformation.MediaBookmarkCallback callback = (IntPtr handle, IntPtr userData) => - { - IntPtr newHandle = IntPtr.Zero; - MediaContentValidator.ThrowIfError( - Interop.MediaBookmark.Clone(out newHandle, handle), "Failed to clone Tag"); - result.Add(new MediaBookmark(newHandle)); - return true; - }; - MediaContentValidator.ThrowIfError( - Interop.MediaInformation.GetAllBookmarks(MediaId, filterHandle, callback, IntPtr.Zero), "Failed to get value"); - - return result; - } - - /// - /// Adds a bookmark to the video - /// - /// 3 - /// Offset of the video in seconds - /// Thumbnail path for the bookmark - /// Task with added MediaBookmark instance - public MediaBookmark AddBookmark(uint offset, string thumbnailPath) - { - MediaBookmark result = null; - ContentManager.Database.Insert(MediaId, offset, thumbnailPath); - ContentFilter bookmarkfilter = new ContentFilter(); - bookmarkfilter.Condition = ContentColumns.Bookmark.Offset + " = " + offset; - IEnumerable bookmarksList = null; - bookmarksList = GetMediaBookmarks(bookmarkfilter); - foreach (MediaBookmark bookmark in bookmarksList) - { - if (bookmark.Offset == offset) - { - result = bookmark; - break; - } - } - - bookmarkfilter.Dispose(); - return result; - } - - /// - /// Deletes a bookmark from the media database. - /// For other types Unsupported exception is thrown. - /// - /// 3 - /// The bookmark to be deleted - public void DeleteBookmark(MediaBookmark bookmark) - { - ContentManager.Database.Delete(bookmark); - } - - internal IntPtr VideoHandle - { - get - { - return _handle.DangerousGetHandle(); - } - } - - private readonly Interop.VideoInformation.SafeVideoInformationHandle _handle; - - internal VideoInformation(Interop.VideoInformation.SafeVideoInformationHandle handle, Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle) - : base(mediaInformationHandle) - { - _handle = handle; - } - } -} -- 2.7.4