From dfe282f43511c84a306e51d6b227970853073312 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 3 Feb 2017 09:59:26 +0900 Subject: [PATCH] [ThumbnailExtractor] Add thumbnail extractor api thumbnail-util capi base Change-Id: I87136b4c25784af8b0b8e2ae8fc37a0a7d4aa82c Signed-off-by: Minje Ahn --- packaging/csapi-multimedia.spec | 2 +- src/Tizen.Multimedia/Interop/Interop.Libraries.cs | 1 + .../Interop/Interop.ThumbnailExtractor.cs | 27 + .../ThumbnailExtractor/ThumbnailData.cs | 46 ++ .../ThumbnailExtractor/ThumbnailExtractor.cs | 211 ++++++++ .../ThumbnailExtractorErrorFactory.cs | 57 +++ src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj | 74 +-- src/Tizen.Multimedia/Tizen.Multimedia.csproj | 544 +++++++++++---------- 8 files changed, 656 insertions(+), 306 deletions(-) create mode 100755 src/Tizen.Multimedia/Interop/Interop.ThumbnailExtractor.cs create mode 100755 src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailData.cs create mode 100755 src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailExtractor.cs create mode 100755 src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailExtractorErrorFactory.cs diff --git a/packaging/csapi-multimedia.spec b/packaging/csapi-multimedia.spec index b64ab95..aa97af9 100644 --- a/packaging/csapi-multimedia.spec +++ b/packaging/csapi-multimedia.spec @@ -1,6 +1,6 @@ Name: csapi-multimedia Summary: Tizen Multimedia API for C# -Version: 1.0.29 +Version: 1.0.30 Release: 0 Group: Development/Libraries License: Apache-2.0 diff --git a/src/Tizen.Multimedia/Interop/Interop.Libraries.cs b/src/Tizen.Multimedia/Interop/Interop.Libraries.cs index 660d6a6..861b91e 100755 --- a/src/Tizen.Multimedia/Interop/Interop.Libraries.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Libraries.cs @@ -31,5 +31,6 @@ internal static partial class Interop public const string Libc = "libc.so.6"; public const string Camera = "libcapi-media-camera.so.0"; public const string StreamRecorder = "libcapi-media-streamrecorder.so.0"; + public const string ThumbnailExtractor = "libcapi-media-thumbnail-util.so"; } } diff --git a/src/Tizen.Multimedia/Interop/Interop.ThumbnailExtractor.cs b/src/Tizen.Multimedia/Interop/Interop.ThumbnailExtractor.cs new file mode 100755 index 0000000..81b9224 --- /dev/null +++ b/src/Tizen.Multimedia/Interop/Interop.ThumbnailExtractor.cs @@ -0,0 +1,27 @@ +using System; +using Tizen.Multimedia; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class ThumbnailExtractor + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void ThumbnailExtractCallback(ThumbnailExtractorError error, string requestId, int thumbWidth, int thumbHeight, IntPtr thumbData, int thumbSize, IntPtr userData); + + [DllImport(Libraries.ThumbnailExtractor, EntryPoint = "thumbnail_util_create")] + internal static extern ThumbnailExtractorError Create(out IntPtr handle); + + [DllImport(Libraries.ThumbnailExtractor, EntryPoint = "thumbnail_util_extract")] + internal static extern ThumbnailExtractorError Extract(IntPtr handle, ThumbnailExtractCallback callback, IntPtr userData, out IntPtr requestId); + + [DllImport(Libraries.ThumbnailExtractor, EntryPoint = "thumbnail_util_set_path")] + internal static extern ThumbnailExtractorError SetPath(IntPtr handle, string path); + + [DllImport(Libraries.ThumbnailExtractor, EntryPoint = "thumbnail_util_set_size")] + internal static extern ThumbnailExtractorError SetSize(IntPtr handle, int width, int height); + + [DllImport(Libraries.ThumbnailExtractor, EntryPoint = "thumbnail_util_destroy")] + internal static extern ThumbnailExtractorError Destroy(IntPtr handle); + } +} diff --git a/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailData.cs b/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailData.cs new file mode 100755 index 0000000..80e39c5 --- /dev/null +++ b/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailData.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. +*/ + + +namespace Tizen.Multimedia +{ + /// + /// This class provides properties of the thumbnail of the given media + /// + public class ThumbnailData + { + internal ThumbnailData(byte[] thumbnailData, int width, int height) + { + Thumbnail = thumbnailData; + Width = width; + Height = height; + } + /// + /// The thumbnail data + /// + public byte[] Thumbnail { get; } + + /// + /// The width of the thumbnail + /// + public int Width { get; } + + /// + /// The height of the thumbnail + /// + public int Height { get; } + } +} diff --git a/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailExtractor.cs b/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailExtractor.cs new file mode 100755 index 0000000..49f6241 --- /dev/null +++ b/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailExtractor.cs @@ -0,0 +1,211 @@ +/* +* 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.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace Tizen.Multimedia +{ + static internal class ThumbnailExtractorLog + { + internal const string LogTag = "Tizen.Multimedia.ThumbnailExtractor"; + } + /// + /// The Thumbnail extractor class provides a set of functions to extract the thumbnail data of the input media file + /// + public class ThumbnailExtractor : IDisposable + { + private bool _disposed = false; + internal IntPtr _handle = IntPtr.Zero; + /// + /// Thumbnail extractor constructor + /// + /// + /// If you need a thumbnail of a specified size, use ThumbnailExtractor(path, width, height). + /// + /// The path of the media file to extract the thumbnail data + public ThumbnailExtractor(string path) + { + ThumbnailExtractorError ret = ThumbnailExtractorError.None; + + if (path == null) + { + Log.Error(ThumbnailExtractorLog.LogTag, "Path is NULL"); + throw new ArgumentNullException(nameof(path)); + } + else + { + ret = Interop.ThumbnailExtractor.Create(out _handle); + if (ret != ThumbnailExtractorError.None) + { + Log.Error(ThumbnailExtractorLog.LogTag, "Failed to create constructor" + ret); + ThumbnailExtractorErrorFactory.ThrowException(ret, "Failed to create constructor"); + } + ret = Interop.ThumbnailExtractor.SetPath(_handle, path); + if (ret != ThumbnailExtractorError.None) + { + Log.Error(ThumbnailExtractorLog.LogTag, "Failed to set path" + ret); + Interop.ThumbnailExtractor.Destroy(_handle); + _handle = IntPtr.Zero; + ThumbnailExtractorErrorFactory.ThrowException(ret, "Failed to set path"); + } + } + } + /// + /// Thumbnail extractor constructor + /// + /// + /// If you need default size thumbnail, use ThumbnailExtractor(path). Default size is 320x240. + /// If the set width is not a multiple of 8, it can be changed by inner process. + /// The width will be a multiple of 8 greater than the set value. + /// + /// The path of the media file to extract the thumbnail data + /// The width of the thumbnail + /// The height of the thumbnail + public ThumbnailExtractor(string path, int width, int height) + { + ThumbnailExtractorError ret = ThumbnailExtractorError.None; + + if (path == null) + { + throw new ArgumentNullException(nameof(path), "Path is NULL"); + } + else if (width <= 0) + { + throw new ArgumentOutOfRangeException(nameof(width), "Wrong width [" + width + "]"); + } + else if (height <= 0) + { + throw new ArgumentOutOfRangeException(nameof(height), "Wrong width [" + height + "]"); + } + + ret = Interop.ThumbnailExtractor.Create(out _handle); + if (ret != ThumbnailExtractorError.None) + { + Log.Error(ThumbnailExtractorLog.LogTag, "Failed to create constructor" + ret); + ThumbnailExtractorErrorFactory.ThrowException(ret, "Failed to create constructor"); + } + + try + { + ret = Interop.ThumbnailExtractor.SetPath(_handle, path); + if (ret != ThumbnailExtractorError.None) + { + Log.Error(ThumbnailExtractorLog.LogTag, "Failed to set path" + ret); + ThumbnailExtractorErrorFactory.ThrowException(ret, "Failed to set path"); + } + ret = Interop.ThumbnailExtractor.SetSize(_handle, width, height); + if (ret != ThumbnailExtractorError.None) + { + Log.Error(ThumbnailExtractorLog.LogTag, "Failed to set size" + ret); + ThumbnailExtractorErrorFactory.ThrowException(ret, "Failed to set size"); + } + } + catch (Exception) + { + Interop.ThumbnailExtractor.Destroy(_handle); + _handle = IntPtr.Zero; + } + } + + private Task ExtractRequest() + { + if (_handle == IntPtr.Zero) + { + throw new ObjectDisposedException(nameof(ThumbnailExtractor), "Failed to extract thumbnail"); + } + + IntPtr id = IntPtr.Zero; + var task = new TaskCompletionSource(); + + Interop.ThumbnailExtractor.ThumbnailExtractCallback extractCallback = (ThumbnailExtractorError error, + string requestId, + int thumbWidth, + int thumbHeight, + IntPtr thumbData, + int thumbSize, + IntPtr userData) => + { + if (error == ThumbnailExtractorError.None) + { + byte[] tmpBuf = new byte[thumbSize]; + Marshal.Copy(thumbData, tmpBuf, 0, thumbSize); + Interop.Libc.Free(thumbData); + task.TrySetResult(new ThumbnailData(tmpBuf, thumbWidth, thumbHeight)); + } + else + { + Log.Error(ThumbnailExtractorLog.LogTag, "Failed to extract thumbnail" + error); + task.SetException(new InvalidOperationException("["+ error +"] Fail to create thumbnail")); + } + }; + ThumbnailExtractorError res = Interop.ThumbnailExtractor.Extract(_handle, extractCallback, IntPtr.Zero, out id); + if (id != IntPtr.Zero) + { + Interop.Libc.Free(id); + id = IntPtr.Zero; + } + if (res != ThumbnailExtractorError.None) + { + Log.Error(ThumbnailExtractorLog.LogTag, "Failed to extract thumbnail" + res); + ThumbnailExtractorErrorFactory.ThrowException(res, "Failed to extract thumbnail"); + } + + return task.Task; + } + /// + /// Extract thumbnail + /// + /// ThumbData object + public async Task Extract() + { + return await ExtractRequest(); + } + + /// + /// Thumbnail Utility destructor + /// + ~ThumbnailExtractor() + { + Dispose(false); + } + + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + // To be used if there are any other disposable objects + } + if (_handle != IntPtr.Zero) + { + Interop.ThumbnailExtractor.Destroy(_handle); + _handle = IntPtr.Zero; + } + _disposed = true; + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + } +} diff --git a/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailExtractorErrorFactory.cs b/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailExtractorErrorFactory.cs new file mode 100755 index 0000000..a7974ce --- /dev/null +++ b/src/Tizen.Multimedia/ThumbnailExtractor/ThumbnailExtractorErrorFactory.cs @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +using System; +using System.IO; +using Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// Enumeration for thumbnail extractor's error codes. + /// + internal enum ThumbnailExtractorError + { + None = ErrorCode.None, // Success + InvalidParameter = ErrorCode.InvalidParameter, // Invalid parameter + OutOfMemory = ErrorCode.OutOfMemory, // Out of memory + InvalidOperation = ErrorCode.InvalidOperation, // Invalid operation + FileNoSpaceOnDevice = ErrorCode.FileNoSpaceOnDevice, // No space left on device + PermissionDenied = ErrorCode.PermissionDenied, // Permission deny + }; + + internal static class ThumbnailExtractorErrorFactory + { + internal static void ThrowException(ThumbnailExtractorError errorCode, string errorMessage = null, string paramName = null) + { + switch (errorCode) + { + case ThumbnailExtractorError.InvalidParameter: + throw new ArgumentException("[" + errorCode.ToString() + "]" + errorMessage, paramName); + case ThumbnailExtractorError.OutOfMemory: + throw new OutOfMemoryException("[" + errorCode.ToString() + "]" + errorMessage); + case ThumbnailExtractorError.InvalidOperation: + throw new InvalidOperationException("[" + errorCode.ToString() + "]" + errorMessage); + case ThumbnailExtractorError.FileNoSpaceOnDevice: + throw new IOException("[" + errorCode.ToString() + "] No space to write on the device"); + case ThumbnailExtractorError.PermissionDenied: + throw new UnauthorizedAccessException("[" + errorCode.ToString() + "]" + errorMessage); + } + } + } +} + diff --git a/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj b/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj index a8c095d..e6dbb28 100755 --- a/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj +++ b/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj @@ -45,12 +45,12 @@ - - - - - - + + + + + + @@ -78,9 +78,9 @@ - + - + @@ -99,7 +99,7 @@ - + @@ -166,31 +166,31 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -245,7 +245,7 @@ - + @@ -255,6 +255,10 @@ + + + + diff --git a/src/Tizen.Multimedia/Tizen.Multimedia.csproj b/src/Tizen.Multimedia/Tizen.Multimedia.csproj index c877923..2bbe0e7 100755 --- a/src/Tizen.Multimedia/Tizen.Multimedia.csproj +++ b/src/Tizen.Multimedia/Tizen.Multimedia.csproj @@ -1,281 +1,285 @@ - - - - Debug - AnyCPU - {0CE698B0-4849-4096-9D7F-30E611F50DAD} - Library - Properties - Tizen.Multimedia - Tizen.Multimedia - 512 - - - .NETStandard - v1.3 - .NETStandard,Version=v1.3 - false - true - $(NoWarn);1701;1702 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - true - - - Tizen.Multimedia.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + {0CE698B0-4849-4096-9D7F-30E611F50DAD} + Library + Properties + Tizen.Multimedia + Tizen.Multimedia + 512 + + + .NETStandard + v1.3 + .NETStandard,Version=v1.3 + false + true + $(NoWarn);1701;1702 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + Tizen.Multimedia.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + --> + + --> - <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) - <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) - true - - \ No newline at end of file + --> + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + -- 2.7.4