From 517862ae6805a00aae0d12977b7250314f7aea54 Mon Sep 17 00:00:00 2001 From: coderhyme Date: Fri, 18 Aug 2017 11:16:40 +0900 Subject: [PATCH] [Multimedia] Sync with the original project Change-Id: I3c81f4bcc3b00a02c67f14967f890f112acf5772 Signed-off-by: coderhyme --- .../AudioIO/AudioCapture.cs | 64 +- .../AudioIO/AudioPlayback.cs | 51 +- .../Interop/Interop.AudioIO.cs | 5 +- .../Interop/Interop.TonePlayer.cs | 3 +- .../Interop/Interop.WavPlayer.cs | 2 +- .../TonePlayer/TonePlayer.cs | 5 +- .../WavPlayer/WavPlayer.cs | 22 +- .../Camera/CameraCapabilities.cs | 3 + .../Camera/CameraSettings.cs | 2 + .../Interop/Interop.MediaCodec.cs | 10 +- .../Interop/Interop.MediaTool.cs | 16 + .../MediaCodec/MediaCodec.cs | 137 ++-- .../Interop/Interop.AudioEffect.cs | 1 - .../Interop/Interop.Player.cs | 2 +- .../Player/BufferingProgressChangedEventArgs.cs | 4 + .../Player/DownloadProgress.cs | 5 + .../Player/EqualizerBand.cs | 5 +- .../Player/MediaBufferSource.cs | 1 + .../Player/MediaSource.cs | 1 + .../MediaStreamBufferStatusChangedEventArgs.cs | 5 + .../Player/MediaStreamConfiguration.cs | 1 + .../Player/MediaStreamSeekingOccurredEventArgs.cs | 9 +- .../Player/MediaStreamSource.cs | 3 +- .../Player/MediaUriSource.cs | 2 +- .../Player/PlaybackInterruptedEventArgs.cs | 5 + .../Player/Player.Events.cs | 290 +++++++++ .../Player/Player.Properties.cs | 403 ++++++++++++ src/Tizen.Multimedia.MediaPlayer/Player/Player.cs | 703 +-------------------- .../Player/PlayerDisplaySettings.cs | 7 + .../Player/PlayerEnums.cs | 4 +- .../Player/PlayerErrorOccurredEventArgs.cs | 4 + .../Player/StreamInfo.cs | 8 + .../Player/SubtitleUpdatedEventArgs.cs | 4 + .../Player/VideoStreamChangedEventArgs.cs | 8 +- .../Interop/Interop.Libc.cs | 18 +- .../Interop/Interop.MetadataEditor.cs | 18 +- .../Interop/Interop.MetadataExtractor.cs | 16 + .../Interop/Interop.Recorder.cs | 2 +- .../Interop/Interop.ScreenMirroring.cs | 2 +- .../NamespaceDoc.cs} | 19 +- .../ScreenMirroring/EventArgs.cs | 2 +- .../ScreenMirroring/InteropHelper.cs | 2 +- .../ScreenMirroring/ScreenMirroring.cs | 2 +- .../ScreenMirroring/ScreenMirroringAudioInfo.cs | 4 +- .../ScreenMirroring/ScreenMirroringEnums.cs | 2 +- .../ScreenMirroring/ScreenMirroringError.cs | 2 +- .../ScreenMirroring/ScreenMirroringVideoInfo.cs | 4 +- .../StreamRecorder/StreamRecorderErrorFactory.cs | 30 +- .../Interop/Interop.ThumbnailExtractor.cs | 16 + .../Interop/Interop.MediaVision.BarCode.cs | 2 +- .../Interop/Interop.MediaVision.Common.cs | 26 +- .../Interop/Interop.MediaVision.Face.cs | 2 +- .../Interop/Interop.MediaVision.Image.cs | 2 +- .../Interop/Interop.MediaVision.Surveillance.cs | 2 +- src/Tizen.Multimedia.Vision/MediaVision/Barcode.cs | 2 +- .../MediaVision/BarcodeDetectionConfiguration.cs | 2 +- .../MediaVision/BarcodeDetectionTarget.cs | 2 +- .../MediaVision/BarcodeDetector.cs | 2 +- .../MediaVision/BarcodeGenerationConfiguration.cs | 2 +- .../MediaVision/BarcodeGenerator.cs | 2 +- .../MediaVision/BarcodeImageConfiguration.cs | 2 +- .../MediaVision/BarcodeImageFormat.cs | 2 +- .../MediaVision/BarcodeType.cs | 2 +- .../MediaVision/Colorspace.cs | 2 +- .../MediaVision/EngineConfiguration.cs | 2 +- .../MediaVision/ErrorCorrectionLevel.cs | 2 +- .../MediaVision/EyeCondition.cs | 2 +- .../MediaVision/FaceDetectionConfiguration.cs | 2 +- .../MediaVision/FaceDetector.cs | 2 +- .../MediaVision/FaceRecognitionConfiguration.cs | 2 +- .../MediaVision/FaceRecognitionModel.cs | 2 +- .../MediaVision/FaceRecognitionModelType.cs | 2 +- .../MediaVision/FaceRecognitionResult.cs | 2 +- .../MediaVision/FaceRecognizer.cs | 20 +- .../MediaVision/FaceTracker.cs | 2 +- .../MediaVision/FaceTrackingModel.cs | 2 +- .../MediaVision/FaceTrackingResult.cs | 2 +- .../MediaVision/FacialExpression.cs | 2 +- .../MediaVision/ImageFillConfiguration.cs | 2 +- .../MediaVision/ImageObject.cs | 4 +- .../MediaVision/ImageRecognitionConfiguration.cs | 2 +- .../MediaVision/ImageRecognitionResult.cs | 2 +- .../MediaVision/ImageRecognizer.cs | 2 +- .../MediaVision/ImageTracker.cs | 2 +- .../MediaVision/ImageTrackingConfiguration.cs | 2 +- .../MediaVision/ImageTrackingModel.cs | 2 +- .../MediaVision/MediaVisionError.cs | 2 +- .../MediaVision/MediaVisionSource.cs | 4 +- .../MediaVision/MovementDetectedEventArgs.cs | 2 +- .../MediaVision/MovementDetectionConfiguration.cs | 2 +- .../MediaVision/MovementDetector.cs | 2 +- .../PersonAppearanceDetectedEventArgs.cs | 2 +- .../PersonAppearanceDetectionConfiguration.cs | 2 +- .../MediaVision/PersonAppearanceDetector.cs | 2 +- .../MediaVision/PersonRecognitionConfiguration.cs | 2 +- .../MediaVision/PersonRecognitionInfo.cs | 2 +- .../MediaVision/PersonRecognizedEventArgs.cs | 2 +- .../MediaVision/PersonRecognizer.cs | 2 +- .../MediaVision/QrConfiguration.cs | 2 +- src/Tizen.Multimedia.Vision/MediaVision/QrMode.cs | 2 +- .../MediaVision/Quadrangle.cs | 2 +- .../MediaVision/SurveillanceConfiguration.cs | 2 +- .../MediaVision/SurveillanceEngine.cs | 2 +- .../MediaVision/SurveillanceSource.cs | 2 +- .../NamespaceDoc.cs} | 20 +- src/Tizen.Multimedia/AssemblyAttrs.cs | 10 +- src/Tizen.Multimedia/AudioManager/AudioDevice.cs | 116 ++-- .../AudioDeviceConnectionChangedEventArgs.cs | 10 +- .../AudioDeviceStateChangedEventArgs.cs | 14 +- src/Tizen.Multimedia/AudioManager/AudioManager.cs | 231 +++---- ...ManagerEnumerations.cs => AudioManagerEnums.cs} | 179 +++--- ...ManagerErrorFactory.cs => AudioManagerError.cs} | 69 +- .../AudioManager/AudioPolicyException.cs | 50 ++ .../AudioManager/AudioStreamPolicy.cs | 418 ++++++------ .../AudioStreamPolicyFocusStateChangedEventArgs.cs | 72 +++ src/Tizen.Multimedia/AudioManager/AudioVolume.cs | 134 ++-- .../AudioManager/FocusStateChangedEventArgs.cs | 48 -- .../AudioManager/MaxVolumeLevel.cs | 46 +- .../StreamFocusStateChangedEventArgs.cs | 41 +- .../AudioManager/VolumeChangedEventArgs.cs | 14 +- src/Tizen.Multimedia/AudioManager/VolumeLevel.cs | 78 ++- .../Common.Internal/LibcSupport.cs | 17 +- .../Interop/AudioStreamPolicyHandle.cs | 42 ++ src/Tizen.Multimedia/Interop/Interop.Device.cs | 74 ++- src/Tizen.Multimedia/Interop/Interop.EvasObject.cs | 18 +- src/Tizen.Multimedia/Interop/Interop.Libc.cs | 18 +- src/Tizen.Multimedia/Interop/Interop.MediaTool.cs | 17 +- .../Interop/Interop.StreamPolicy.cs | 94 ++- src/Tizen.Multimedia/Interop/Interop.Volume.cs | 49 +- src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs | 274 ++++++++ .../MediaTool/ContainerMediaFormat.cs | 101 +++ src/Tizen.Multimedia/MediaTool/MediaFormat.cs | 699 +------------------- src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs | 207 ++++++ src/Tizen.Multimedia/MediaTool/MediaPacket.cs | 180 +----- src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs | 135 ++++ src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs | 272 ++++++++ src/Tizen.Multimedia/MediaView/MediaView.cs | 16 + 137 files changed, 3227 insertions(+), 2626 deletions(-) create mode 100644 src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs create mode 100644 src/Tizen.Multimedia.MediaPlayer/Player/Player.Properties.cs rename src/{Tizen.Multimedia.AudioIO/ValdiationUtil.cs => Tizen.Multimedia.Remoting/NamespaceDoc.cs} (61%) rename src/{Tizen.Multimedia.AudioIO/MultimediaDebug.cs => Tizen.Multimedia.Vision/NamespaceDoc.cs} (55%) rename src/Tizen.Multimedia/AudioManager/{AudioManagerEnumerations.cs => AudioManagerEnums.cs} (61%) mode change 100755 => 100644 rename src/Tizen.Multimedia/AudioManager/{AudioManagerErrorFactory.cs => AudioManagerError.cs} (62%) create mode 100644 src/Tizen.Multimedia/AudioManager/AudioPolicyException.cs create mode 100644 src/Tizen.Multimedia/AudioManager/AudioStreamPolicyFocusStateChangedEventArgs.cs delete mode 100644 src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs create mode 100644 src/Tizen.Multimedia/Interop/AudioStreamPolicyHandle.cs create mode 100644 src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs create mode 100644 src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs create mode 100644 src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs create mode 100644 src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs diff --git a/src/Tizen.Multimedia.AudioIO/AudioIO/AudioCapture.cs b/src/Tizen.Multimedia.AudioIO/AudioIO/AudioCapture.cs index 1284919..f61ef9e 100644 --- a/src/Tizen.Multimedia.AudioIO/AudioIO/AudioCapture.cs +++ b/src/Tizen.Multimedia.AudioIO/AudioIO/AudioCapture.cs @@ -16,23 +16,26 @@ using System; using System.Runtime.InteropServices; +using static Interop.AudioIO; namespace Tizen.Multimedia { /// /// Provides the ability to directly manage the system audio input devices. /// - /// The recorder privilege(http://tizen.org/privilege/recorder) is required. + /// http://tizen.org/privilege/recorder public abstract class AudioCaptureBase : IDisposable { /// - /// Specifies the minimum value allowed for the audio capture. + /// Specifies the minimum value allowed for the audio capture, in Hertz (Hz). /// + /// public static readonly int MinSampleRate = 8000; /// - /// Specifies the maximum value allowed for the audio capture. + /// Specifies the maximum value allowed for the audio capture, in Hertz (Hz). /// + /// public static readonly int MaxSampleRate = 48000; internal IntPtr _handle = IntPtr.Zero; @@ -55,7 +58,7 @@ namespace Tizen.Multimedia SampleType = sampleType; AudioIOUtil.ThrowIfError( - Interop.AudioIO.AudioInput.Create(SampleRate, (int)Channel, (int)SampleType, out _handle)); + AudioInput.Create(SampleRate, (int)Channel, (int)SampleType, out _handle)); RegisterStateChangedCallback(); } @@ -70,7 +73,7 @@ namespace Tizen.Multimedia /// public event EventHandler StateChanged; - private Interop.AudioIO.AudioStateChangedCallback _stateChangedCallback; + private AudioStateChangedCallback _stateChangedCallback; private void RegisterStateChangedCallback() { @@ -83,7 +86,7 @@ namespace Tizen.Multimedia }; AudioIOUtil.ThrowIfError( - Interop.AudioIO.AudioInput.SetStateChangedCallback(_handle, _stateChangedCallback, IntPtr.Zero)); + AudioInput.SetStateChangedCallback(_handle, _stateChangedCallback, IntPtr.Zero)); } #region Dispose support @@ -115,7 +118,7 @@ namespace Tizen.Multimedia } } - Interop.AudioIO.AudioInput.Destroy(_handle); + AudioInput.Destroy(_handle); _handle = IntPtr.Zero; _isDisposed = true; } @@ -138,7 +141,7 @@ namespace Tizen.Multimedia } /// - /// Gets the sample rate of the audio input data stream. + /// Gets the sample rate of the audio input data stream, in Hertz (Hz). /// public int SampleRate { get; } @@ -158,7 +161,7 @@ namespace Tizen.Multimedia /// The AudioPlayback has already been disposed. public int GetBufferSize() { - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioInput.GetBufferSize(_handle, out var size)); + AudioIOUtil.ThrowIfError(AudioInput.GetBufferSize(_handle, out var size)); return size; } @@ -175,7 +178,7 @@ namespace Tizen.Multimedia { ValidateState(AudioIOState.Idle); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioInput.Prepare(_handle), + AudioIOUtil.ThrowIfError(AudioInput.Prepare(_handle), "Failed to prepare the AudioCapture"); } @@ -184,7 +187,7 @@ namespace Tizen.Multimedia /// /// /// Operation failed due to internal error.\n - /// \n + /// -or-\n /// The current state is . /// /// @@ -192,7 +195,7 @@ namespace Tizen.Multimedia { ValidateState(AudioIOState.Running, AudioIOState.Paused); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioInput.Unprepare(_handle), + AudioIOUtil.ThrowIfError(AudioInput.Unprepare(_handle), "Failed to unprepare the AudioCapture"); } @@ -200,7 +203,7 @@ namespace Tizen.Multimedia /// Pauses buffering of audio data from the device. /// /// - /// The current state is .\n + /// The current state is .\n /// -or-\n /// The method is called in the event handler. /// @@ -213,13 +216,13 @@ namespace Tizen.Multimedia } ValidateState(AudioIOState.Running); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioInput.Pause(_handle)); + AudioIOUtil.ThrowIfError(AudioInput.Pause(_handle)); } /// /// Resumes buffering audio data from the device. /// /// - /// The current state is .\n + /// The current state is .\n /// -or-\n /// The method is called in the event handler. /// @@ -232,17 +235,17 @@ namespace Tizen.Multimedia } ValidateState(AudioIOState.Paused); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioInput.Resume(_handle)); + AudioIOUtil.ThrowIfError(AudioInput.Resume(_handle)); } /// /// Flushes and discards buffered audio data from the input stream. /// - /// The current state is . + /// The current state is . public void Flush() { ValidateState(AudioIOState.Running, AudioIOState.Paused); - int ret = Interop.AudioIO.AudioInput.Flush(_handle); + int ret = AudioInput.Flush(_handle); MultimediaDebug.AssertNoError(ret); } @@ -262,14 +265,9 @@ namespace Tizen.Multimedia throw new ArgumentNullException(nameof(streamPolicy)); } - if (streamPolicy.Handle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(streamPolicy)); - } - ValidateNotDisposed(); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioInput.SetStreamInfo(_handle, streamPolicy.Handle)); + AudioIOUtil.ThrowIfError(AudioInput.SetStreamInfo(_handle, streamPolicy.Handle)); } } @@ -286,9 +284,9 @@ namespace Tizen.Multimedia /// The audio channel type. /// The audio sample type. /// - /// is less than .\n + /// is less than .\n /// -or-\n - /// is greater than . + /// is greater than . /// /// /// is invalid.\n @@ -320,7 +318,7 @@ namespace Tizen.Multimedia byte[] buffer = new byte[count]; - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioInput.Read(_handle, buffer, count), + AudioIOUtil.ThrowIfError(AudioInput.Read(_handle, buffer, count), "Failed to read"); return buffer; @@ -346,9 +344,9 @@ namespace Tizen.Multimedia /// The audio channel type. /// The audio sample type. /// - /// is less than .\n + /// is less than .\n /// -or-\n - /// is greater than . + /// is greater than . /// /// /// is invalid.\n @@ -363,11 +361,11 @@ namespace Tizen.Multimedia _streamCallback = (IntPtr handle, uint length, IntPtr _) => { OnInputDataAvailable(handle, length); }; AudioIOUtil.ThrowIfError( - Interop.AudioIO.AudioInput.SetStreamCallback(_handle, _streamCallback, IntPtr.Zero), + AudioInput.SetStreamCallback(_handle, _streamCallback, IntPtr.Zero), $"Failed to initialize a { nameof(AsyncAudioCapture) }"); } - private Interop.AudioIO.AudioStreamCallback _streamCallback; + private AudioStreamCallback _streamCallback; private void OnInputDataAvailable(IntPtr handle, uint length) { @@ -379,12 +377,12 @@ namespace Tizen.Multimedia IntPtr ptr = IntPtr.Zero; try { - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioInput.Peek(_handle, out ptr, ref length)); + AudioIOUtil.ThrowIfError(AudioInput.Peek(_handle, out ptr, ref length)); byte[] buffer = new byte[length]; Marshal.Copy(ptr, buffer, 0, (int)length); - Interop.AudioIO.AudioInput.Drop(_handle); + AudioInput.Drop(_handle); DataAvailable?.Invoke(this, new AudioDataAvailableEventArgs(buffer)); } diff --git a/src/Tizen.Multimedia.AudioIO/AudioIO/AudioPlayback.cs b/src/Tizen.Multimedia.AudioIO/AudioIO/AudioPlayback.cs index 1a6b8a9..d8fd45e 100644 --- a/src/Tizen.Multimedia.AudioIO/AudioIO/AudioPlayback.cs +++ b/src/Tizen.Multimedia.AudioIO/AudioIO/AudioPlayback.cs @@ -15,6 +15,7 @@ */ using System; +using static Interop.AudioIO; namespace Tizen.Multimedia { @@ -23,7 +24,16 @@ namespace Tizen.Multimedia /// public class AudioPlayback : IDisposable { + /// + /// Specifies the minimum value allowed for the audio capture, in Hertz (Hz). + /// + /// public static readonly int MinSampleRate = 8000; + + /// + /// Specifies the maximum value allowed for the audio capture, in Hertz (Hz). + /// + /// public static readonly int MaxSampleRate = 48000; private IntPtr _handle = IntPtr.Zero; @@ -37,7 +47,7 @@ namespace Tizen.Multimedia /// public event EventHandler BufferAvailable; - private Interop.AudioIO.AudioStreamCallback _streamCallback; + private AudioStreamCallback _streamCallback; private void RegisterStreamCallback() { @@ -47,7 +57,7 @@ namespace Tizen.Multimedia }; AudioIOUtil.ThrowIfError( - Interop.AudioIO.AudioOutput.SetStreamChangedCallback(_handle, _streamCallback, IntPtr.Zero), + AudioOutput.SetStreamChangedCallback(_handle, _streamCallback, IntPtr.Zero), $"Failed to create {nameof(AudioPlayback)}"); } @@ -56,7 +66,7 @@ namespace Tizen.Multimedia /// public event EventHandler StateChanged; - private Interop.AudioIO.AudioStateChangedCallback _stateChangedCallback; + private AudioStateChangedCallback _stateChangedCallback; private void RegisterStateChangedCallback() { @@ -69,7 +79,7 @@ namespace Tizen.Multimedia }; AudioIOUtil.ThrowIfError( - Interop.AudioIO.AudioOutput.SetStateChangedCallback(_handle, _stateChangedCallback, IntPtr.Zero), + AudioOutput.SetStateChangedCallback(_handle, _stateChangedCallback, IntPtr.Zero), $"Failed to create {nameof(AudioPlayback)}"); } #endregion @@ -106,7 +116,7 @@ namespace Tizen.Multimedia SampleType = sampleType; AudioIOUtil.ThrowIfError( - Interop.AudioIO.AudioOutput.Create(SampleRate, (int)Channel, (int)SampleType, out _handle), + AudioOutput.Create(SampleRate, (int)Channel, (int)SampleType, out _handle), $"Failed to create {nameof(AudioPlayback)}"); RegisterStreamCallback(); @@ -147,7 +157,7 @@ namespace Tizen.Multimedia } } - Interop.AudioIO.AudioOutput.Destroy(_handle); + AudioOutput.Destroy(_handle); _handle = IntPtr.Zero; _isDisposed = true; } @@ -170,7 +180,7 @@ namespace Tizen.Multimedia } /// - /// Gets the sample rate of the audio output data stream. + /// Gets the sample rate of the audio output data stream, in Hertz (Hz). /// public int SampleRate { get; } @@ -195,7 +205,7 @@ namespace Tizen.Multimedia ValidateNotDisposed(); int audioType = 0; - int ret = Interop.AudioIO.AudioOutput.GetSoundType(_handle, out audioType); + int ret = AudioOutput.GetSoundType(_handle, out audioType); MultimediaDebug.AssertNoError(ret); return (AudioStreamType)audioType; @@ -208,13 +218,13 @@ namespace Tizen.Multimedia /// The AudioPlayback has already been disposed. public int GetBufferSize() { - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioOutput.GetBufferSize(_handle, out var size)); + AudioIOUtil.ThrowIfError(AudioOutput.GetBufferSize(_handle, out var size)); return size; } /// /// Drains buffered audio data from the output stream. - /// It blocks the calling thread until draining the stream buffer completely. (e.g end of playback) + /// It blocks the calling thread until draining the stream buffer completely. (e.g. end of playback) /// /// The AudioPlayback has already been disposed. /// The current state is . @@ -222,7 +232,7 @@ namespace Tizen.Multimedia { ValidateState(AudioIOState.Running, AudioIOState.Paused); - int ret = Interop.AudioIO.AudioOutput.Drain(_handle); + int ret = AudioOutput.Drain(_handle); MultimediaDebug.AssertNoError(ret); } @@ -250,7 +260,7 @@ namespace Tizen.Multimedia throw new ArgumentException("buffer has no data.(the Length is zero.)", nameof(buffer)); } - int ret = Interop.AudioIO.AudioOutput.Write(_handle, buffer, (uint)buffer.Length); + int ret = AudioOutput.Write(_handle, buffer, (uint)buffer.Length); AudioIOUtil.ThrowIfError(ret, "Failed to write buffer"); @@ -274,7 +284,7 @@ namespace Tizen.Multimedia { ValidateState(AudioIOState.Idle); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioOutput.Prepare(_handle), + AudioIOUtil.ThrowIfError(AudioOutput.Prepare(_handle), $"Failed to prepare the {nameof(AudioPlayback)}"); } @@ -292,7 +302,7 @@ namespace Tizen.Multimedia { ValidateState(AudioIOState.Running, AudioIOState.Paused); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioOutput.Unprepare(_handle), + AudioIOUtil.ThrowIfError(AudioOutput.Unprepare(_handle), $"Failed to unprepare the {nameof(AudioPlayback)}"); } @@ -315,7 +325,7 @@ namespace Tizen.Multimedia } ValidateState(AudioIOState.Running); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioOutput.Pause(_handle)); + AudioIOUtil.ThrowIfError(AudioOutput.Pause(_handle)); } /// @@ -337,7 +347,7 @@ namespace Tizen.Multimedia } ValidateState(AudioIOState.Paused); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioOutput.Resume(_handle)); + AudioIOUtil.ThrowIfError(AudioOutput.Resume(_handle)); } /// @@ -349,7 +359,7 @@ namespace Tizen.Multimedia { ValidateState(AudioIOState.Running, AudioIOState.Paused); - int ret = Interop.AudioIO.AudioOutput.Flush(_handle); + int ret = AudioOutput.Flush(_handle); MultimediaDebug.AssertNoError(ret); } @@ -373,14 +383,9 @@ namespace Tizen.Multimedia throw new ArgumentNullException(nameof(streamPolicy)); } - if (streamPolicy.Handle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(streamPolicy)); - } - ValidateNotDisposed(); - AudioIOUtil.ThrowIfError(Interop.AudioIO.AudioOutput.SetStreamInfo(_handle, streamPolicy.Handle)); + AudioIOUtil.ThrowIfError(AudioOutput.SetStreamInfo(_handle, streamPolicy.Handle)); } } } diff --git a/src/Tizen.Multimedia.AudioIO/Interop/Interop.AudioIO.cs b/src/Tizen.Multimedia.AudioIO/Interop/Interop.AudioIO.cs index 1685489..0b75bb8 100644 --- a/src/Tizen.Multimedia.AudioIO/Interop/Interop.AudioIO.cs +++ b/src/Tizen.Multimedia.AudioIO/Interop/Interop.AudioIO.cs @@ -16,6 +16,7 @@ using System; using System.Runtime.InteropServices; +using Tizen.Multimedia; internal static partial class Interop { @@ -42,7 +43,7 @@ internal static partial class Interop internal static extern int Destroy(IntPtr handle); [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_set_sound_stream_info")] - internal static extern int SetStreamInfo(IntPtr handle, IntPtr streamInfoHandle); + internal static extern int SetStreamInfo(IntPtr handle, AudioStreamPolicyHandle streamInfoHandle); [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_prepare")] internal static extern int Prepare(IntPtr handle); @@ -125,7 +126,7 @@ internal static partial class Interop internal static extern int Resume(IntPtr handle); [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_set_sound_stream_info")] - internal static extern int SetStreamInfo(IntPtr handle, IntPtr streamInfoHandle); + internal static extern int SetStreamInfo(IntPtr handle, AudioStreamPolicyHandle streamInfoHandle); [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_unprepare")] internal static extern int Unprepare(IntPtr handle); diff --git a/src/Tizen.Multimedia.AudioIO/Interop/Interop.TonePlayer.cs b/src/Tizen.Multimedia.AudioIO/Interop/Interop.TonePlayer.cs index 076a703..14dd2b8 100644 --- a/src/Tizen.Multimedia.AudioIO/Interop/Interop.TonePlayer.cs +++ b/src/Tizen.Multimedia.AudioIO/Interop/Interop.TonePlayer.cs @@ -14,7 +14,6 @@ * limitations under the License. */ -using System; using System.Runtime.InteropServices; using Tizen.Multimedia; @@ -23,7 +22,7 @@ internal static partial class Interop internal static partial class TonePlayer { [DllImport(Libraries.TonePlayer, EntryPoint = "tone_player_start_new")] - internal static extern TonePlayerError Start(ToneType tone, IntPtr streamInfoHandle, + internal static extern TonePlayerError Start(ToneType tone, AudioStreamPolicyHandle streamInfoHandle, int durationMs, out int id); [DllImport(Libraries.TonePlayer, EntryPoint = "tone_player_stop")] diff --git a/src/Tizen.Multimedia.AudioIO/Interop/Interop.WavPlayer.cs b/src/Tizen.Multimedia.AudioIO/Interop/Interop.WavPlayer.cs index a7f7a6e..0712ee1 100644 --- a/src/Tizen.Multimedia.AudioIO/Interop/Interop.WavPlayer.cs +++ b/src/Tizen.Multimedia.AudioIO/Interop/Interop.WavPlayer.cs @@ -26,7 +26,7 @@ internal static partial class Interop internal delegate void WavPlayerCompletedCallback(int playerId, IntPtr userData); [DllImport(Libraries.WavPlayer, EntryPoint = "wav_player_start_new")] - internal static extern WavPlayerError Start(string filePath, IntPtr streamInfoHandle, + internal static extern WavPlayerError Start(string filePath, AudioStreamPolicyHandle streamInfoHandle, WavPlayerCompletedCallback completedCallback, IntPtr userData, out int id); [DllImport(Libraries.WavPlayer, EntryPoint = "wav_player_stop")] diff --git a/src/Tizen.Multimedia.AudioIO/TonePlayer/TonePlayer.cs b/src/Tizen.Multimedia.AudioIO/TonePlayer/TonePlayer.cs index 51c92b4..4675814 100644 --- a/src/Tizen.Multimedia.AudioIO/TonePlayer/TonePlayer.cs +++ b/src/Tizen.Multimedia.AudioIO/TonePlayer/TonePlayer.cs @@ -17,6 +17,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Native = Interop.TonePlayer; namespace Tizen.Multimedia { @@ -88,7 +89,7 @@ namespace Tizen.Multimedia var tcs = new TaskCompletionSource(); - Interop.TonePlayer.Start(tone, streamPolicy.Handle, durationMilliseconds, out var id). + Native.Start(tone, streamPolicy.Handle, durationMilliseconds, out var id). Validate("Failed to play tone."); using (RegisterCancellationAction(tcs, cancellationToken, id)) @@ -127,7 +128,7 @@ namespace Tizen.Multimedia return cancellationToken.Register(() => { - Interop.TonePlayer.Stop(id).Validate("Failed to cancel"); + Native.Stop(id).Validate("Failed to cancel"); tcs.TrySetCanceled(); }); } diff --git a/src/Tizen.Multimedia.AudioIO/WavPlayer/WavPlayer.cs b/src/Tizen.Multimedia.AudioIO/WavPlayer/WavPlayer.cs index 954d6f3..4a42a41 100644 --- a/src/Tizen.Multimedia.AudioIO/WavPlayer/WavPlayer.cs +++ b/src/Tizen.Multimedia.AudioIO/WavPlayer/WavPlayer.cs @@ -18,6 +18,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Native = Interop.WavPlayer; namespace Tizen.Multimedia { @@ -39,7 +40,7 @@ namespace Tizen.Multimedia /// /// An internal error occurs. /// does not exists. - /// The format of is not supported. + /// The format of is not supported. /// has already been disposed of. public static Task StartAsync(string path, AudioStreamPolicy streamPolicy) { @@ -60,7 +61,7 @@ namespace Tizen.Multimedia /// /// An internal error occurs. /// does not exists. - /// The format of is not supported. + /// The format of is not supported. /// has already been disposed. public static Task StartAsync(string path, AudioStreamPolicy streamPolicy, CancellationToken cancellationToken) @@ -89,14 +90,17 @@ namespace Tizen.Multimedia { var tcs = new TaskCompletionSource(); - Interop.WavPlayer.WavPlayerCompletedCallback cb = (id_, _) => tcs.TrySetResult(true); + Native.WavPlayerCompletedCallback cb = (id_, _) => tcs.TrySetResult(true); - Interop.WavPlayer.Start(path, streamPolicy.Handle, cb, IntPtr.Zero, out var id). - Validate("Failed to play."); - - using (RegisterCancellationAction(tcs, cancellationToken, id)) + using (ObjectKeeper.Get(cb)) { - await tcs.Task; + Native.Start(path, streamPolicy.Handle, cb, IntPtr.Zero, out var id). + Validate("Failed to play."); + + using (RegisterCancellationAction(tcs, cancellationToken, id)) + { + await tcs.Task; + } } } @@ -110,7 +114,7 @@ namespace Tizen.Multimedia return cancellationToken.Register(() => { - Interop.WavPlayer.Stop(id).Validate("Failed to cancel"); + Native.Stop(id).Validate("Failed to cancel"); tcs.TrySetCanceled(); }); } diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraCapabilities.cs b/src/Tizen.Multimedia.Camera/Camera/CameraCapabilities.cs index ddfe4c7..bc79b65 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraCapabilities.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraCapabilities.cs @@ -281,6 +281,8 @@ namespace Tizen.Multimedia /// Retrieves all the fps by resolution supported by the camera. /// /// 3 + /// The width of required preview resolution. + /// The height of required preview resolution. /// /// It returns a list containing all the supported by resolution. /// @@ -294,6 +296,7 @@ namespace Tizen.Multimedia /// Retrieves all the fps by resolution supported by the camera. /// /// 3 + /// The size of required preview resolution. /// /// It returns a list containing all the supported by resolution. /// diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs b/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs index 318c73f..2005213 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs @@ -989,6 +989,7 @@ namespace Tizen.Multimedia { throw new NotSupportedException("Pan is not supported."); } + return _panRange.Value; } } @@ -1009,6 +1010,7 @@ namespace Tizen.Multimedia { throw new NotSupportedException("Tilt is not supported."); } + return _tiltRange.Value; } } diff --git a/src/Tizen.Multimedia.MediaCodec/Interop/Interop.MediaCodec.cs b/src/Tizen.Multimedia.MediaCodec/Interop/Interop.MediaCodec.cs index 5d484cc..0aad663 100644 --- a/src/Tizen.Multimedia.MediaCodec/Interop/Interop.MediaCodec.cs +++ b/src/Tizen.Multimedia.MediaCodec/Interop/Interop.MediaCodec.cs @@ -82,33 +82,33 @@ namespace Tizen.Multimedia.MediaCodec [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_input_buffer_used_cb")] internal static extern int SetInputBufferUsedCb(IntPtr handle, - InputBufferUsedCallback cb, IntPtr arg); + InputBufferUsedCallback cb, IntPtr arg = default(IntPtr)); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_input_buffer_used_cb")] internal static extern int UnsetInputBufferUsedCb(IntPtr handle); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_output_buffer_available_cb")] internal static extern int SetOutputBufferAvailableCb(IntPtr handle, - OutputBufferAvailableCallback cb, IntPtr arg); + OutputBufferAvailableCallback cb, IntPtr arg = default(IntPtr)); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_output_buffer_available_cb")] internal static extern int UnsetOutputBufferAvailableCb(IntPtr handle); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_error_cb")] - internal static extern int SetErrorCb(IntPtr handle, ErrorCallback cb, IntPtr arg); + internal static extern int SetErrorCb(IntPtr handle, ErrorCallback cb, IntPtr arg = default(IntPtr)); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_error_cb")] internal static extern int UnsetErrorCb(IntPtr handle); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_eos_cb")] - internal static extern int SetEosCb(IntPtr handle, EosCallback cb, IntPtr arg); + internal static extern int SetEosCb(IntPtr handle, EosCallback cb, IntPtr arg = default(IntPtr)); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_eos_cb")] internal static extern int UnsetEosCb(IntPtr handle); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_buffer_status_cb")] internal static extern int SetBufferStatusCb(IntPtr handle, BufferStatusCallback cb, - IntPtr arg); + IntPtr arg = default(IntPtr)); [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_buffer_status_cb")] internal static extern int UnsetBufferStatusCb(IntPtr handle); diff --git a/src/Tizen.Multimedia.MediaCodec/Interop/Interop.MediaTool.cs b/src/Tizen.Multimedia.MediaCodec/Interop/Interop.MediaTool.cs index 318153c..59d6e7b 100644 --- a/src/Tizen.Multimedia.MediaCodec/Interop/Interop.MediaTool.cs +++ b/src/Tizen.Multimedia.MediaCodec/Interop/Interop.MediaTool.cs @@ -1,3 +1,19 @@ +/* + * 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; diff --git a/src/Tizen.Multimedia.MediaCodec/MediaCodec/MediaCodec.cs b/src/Tizen.Multimedia.MediaCodec/MediaCodec/MediaCodec.cs index 0d37d31..38d5e0b 100644 --- a/src/Tizen.Multimedia.MediaCodec/MediaCodec/MediaCodec.cs +++ b/src/Tizen.Multimedia.MediaCodec/MediaCodec/MediaCodec.cs @@ -27,7 +27,7 @@ namespace Tizen.Multimedia.MediaCodec { private const int CodecTypeMask = 0xFFFF; private const int CodecKindMask = 0x3000; -// private const int CodecKindAudio = 0x1000; // Not used + // private const int CodecKindAudio = 0x1000; // Not used private const int CodecKindVideo = 0x2000; private IntPtr _handle; @@ -444,6 +444,7 @@ namespace Tizen.Multimedia.MediaCodec #region OutputAvailable event private EventHandler _outputAvailable; private Interop.MediaCodec.OutputBufferAvailableCallback _outputBufferAvailableCb; + private object _outputAvailableLock = new object(); /// /// Occurs when an output buffer is available. @@ -455,21 +456,27 @@ namespace Tizen.Multimedia.MediaCodec { ValidateNotDisposed(); - if (_outputAvailable == null) + lock (_outputAvailableLock) { - RegisterOutputAvailableCallback(); + if (_outputAvailable == null) + { + RegisterOutputAvailableCallback(); + } + _outputAvailable += value; } - _outputAvailable += value; - } remove { ValidateNotDisposed(); - _outputAvailable -= value; - if (_outputAvailable == null) + lock (_outputAvailableLock) { - UnregisterOutputAvailableCallback(); + _outputAvailable -= value; + if (_outputAvailable == null) + { + // We can remove handler first, because we know the method that unregisters callback does not throw. + UnregisterOutputAvailableCallback(); + } } } } @@ -478,26 +485,31 @@ namespace Tizen.Multimedia.MediaCodec { _outputBufferAvailableCb = (packetHandle, _) => { - OutputAvailableEventArgs args = null; + if (_outputAvailable == null) + { + Interop.MediaPacket.Destroy(packetHandle); + return; + } + OutputAvailableEventArgs args = null; try { args = new OutputAvailableEventArgs(packetHandle); } - catch (Exception) + catch (Exception e) { Interop.MediaPacket.Destroy(packetHandle); - // TODO should we throw it to unmanaged code? - throw; + MultimediaLog.Error(typeof(MediaCodec).FullName, "Failed to raise OutputAvailable event", e); } - //TODO dispose if no event handler registered - _outputAvailable?.Invoke(this, args); + if (args != null) + { + _outputAvailable?.Invoke(this, args); + } }; - int ret = Interop.MediaCodec.SetOutputBufferAvailableCb(_handle, - _outputBufferAvailableCb, IntPtr.Zero); + int ret = Interop.MediaCodec.SetOutputBufferAvailableCb(_handle, _outputBufferAvailableCb); MultimediaDebug.AssertNoError(ret); } @@ -538,15 +550,7 @@ namespace Tizen.Multimedia.MediaCodec InputProcessed?.Invoke(this, new InputProcessedEventArgs(packet)); }; - int ret = Interop.MediaCodec.SetInputBufferUsedCb(_handle, - _inputBufferUsedCb, IntPtr.Zero); - - MultimediaDebug.AssertNoError(ret); - } - - private void UnregisterInputProcessed() - { - int ret = Interop.MediaCodec.UnsetInputBufferUsedCb(_handle); + int ret = Interop.MediaCodec.SetInputBufferUsedCb(_handle, _inputBufferUsedCb); MultimediaDebug.AssertNoError(ret); } @@ -569,100 +573,38 @@ namespace Tizen.Multimedia.MediaCodec ErrorOccurred?.Invoke(this, new MediaCodecErrorOccurredEventArgs(error)); }; - int ret = Interop.MediaCodec.SetErrorCb(_handle, _errorCb, IntPtr.Zero); - - MultimediaDebug.AssertNoError(ret); - } - - private void UnregisterErrorOccurred() - { - int ret = Interop.MediaCodec.UnsetErrorCb(_handle); + int ret = Interop.MediaCodec.SetErrorCb(_handle, _errorCb); MultimediaDebug.AssertNoError(ret); } #endregion #region EosReached event - private EventHandler _eosReached; private Interop.MediaCodec.EosCallback _eosCb; - // TODO replace /// /// Occurs when the codec processes all input data. /// - public event EventHandler EosReached - { - add - { - ValidateNotDisposed(); - - if (_eosReached == null) - { - RegisterEosReached(); - } - _eosReached += value; - - } - remove - { - ValidateNotDisposed(); - - _eosReached -= value; - if (_eosReached == null) - { - UnregisterEosReached(); - } - } - } + public event EventHandler EosReached; private void RegisterEosReached() { - _eosCb = _ => _eosReached?.Invoke(this, EventArgs.Empty); + _eosCb = _ => EosReached?.Invoke(this, EventArgs.Empty); - int ret = Interop.MediaCodec.SetEosCb(_handle, _eosCb, IntPtr.Zero); + int ret = Interop.MediaCodec.SetEosCb(_handle, _eosCb); MultimediaDebug.AssertNoError(ret); } - private void UnregisterEosReached() - { - int ret = Interop.MediaCodec.UnsetEosCb(_handle); - - MultimediaDebug.AssertNoError(ret); - } #endregion #region BufferStatusChanged event - private EventHandler _bufferStatusChanged; private Interop.MediaCodec.BufferStatusCallback _bufferStatusCb; /// /// Occurs when the codec needs more data or has enough data. /// - public event EventHandler BufferStatusChanged - { - add - { - ValidateNotDisposed(); - - if (_bufferStatusChanged == null) - { - RegisterBufferStatusChanged(); - } - _bufferStatusChanged += value; - - } - remove - { - ValidateNotDisposed(); - - _bufferStatusChanged -= value; - if (_bufferStatusChanged == null) - { - UnregisterBufferStatusChanged(); - } - } - } + public event EventHandler BufferStatusChanged; private void RegisterBufferStatusChanged() { @@ -671,18 +613,11 @@ namespace Tizen.Multimedia.MediaCodec Debug.Assert(Enum.IsDefined(typeof(MediaCodecStatus), statusCode), $"{ statusCode } is not defined in MediaCodecStatus!"); - _bufferStatusChanged?.Invoke(this, + BufferStatusChanged?.Invoke(this, new BufferStatusChangedEventArgs((MediaCodecStatus)statusCode)); }; - int ret = Interop.MediaCodec.SetBufferStatusCb(_handle, _bufferStatusCb, IntPtr.Zero); - - MultimediaDebug.AssertNoError(ret); - } - - private void UnregisterBufferStatusChanged() - { - int ret = Interop.MediaCodec.UnsetBufferStatusCb(_handle); + int ret = Interop.MediaCodec.SetBufferStatusCb(_handle, _bufferStatusCb); MultimediaDebug.AssertNoError(ret); } diff --git a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.AudioEffect.cs b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.AudioEffect.cs index 10a935e..025b603 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.AudioEffect.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.AudioEffect.cs @@ -49,5 +49,4 @@ internal static partial class Interop [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_equalizer_is_available")] internal static extern PlayerErrorCode EqualizerIsAvailable(IntPtr player, out bool available); } - } diff --git a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs index b748044..d82aef5 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs @@ -100,7 +100,7 @@ internal static partial class Interop internal static extern PlayerErrorCode GetVolume(IntPtr player, out float left, out float right); [DllImport(Libraries.Player, EntryPoint = "player_set_sound_stream_info")] - internal static extern PlayerErrorCode SetAudioPolicyInfo(IntPtr player, IntPtr streamInfo); + internal static extern PlayerErrorCode SetAudioPolicyInfo(IntPtr player, AudioStreamPolicyHandle streamInfo); [DllImport(Libraries.Player, EntryPoint = "player_set_audio_latency_mode")] internal static extern PlayerErrorCode SetAudioLatencyMode(IntPtr player, AudioLatencyMode latencyMode); diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/BufferingProgressChangedEventArgs.cs b/src/Tizen.Multimedia.MediaPlayer/Player/BufferingProgressChangedEventArgs.cs index d7d88a8..959ec9e 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/BufferingProgressChangedEventArgs.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/BufferingProgressChangedEventArgs.cs @@ -37,6 +37,10 @@ namespace Tizen.Multimedia /// The percentage of the buffering. public int Percent { get; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() { return $"Percent={ Percent.ToString() }"; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/DownloadProgress.cs b/src/Tizen.Multimedia.MediaPlayer/Player/DownloadProgress.cs index d56dce6..bb5b7a9 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/DownloadProgress.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/DownloadProgress.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + namespace Tizen.Multimedia { @@ -53,6 +54,10 @@ namespace Tizen.Multimedia set; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() { return $"Start={ Start.ToString() }, Current={ Current.ToString() }"; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/EqualizerBand.cs b/src/Tizen.Multimedia.MediaPlayer/Player/EqualizerBand.cs index 59dc485..b64c00f 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/EqualizerBand.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/EqualizerBand.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; using System.Diagnostics; using Native = Interop.AudioEffect; @@ -56,9 +57,7 @@ namespace Tizen.Multimedia /// The value indicating new gain in decibel(dB). /// The player that this EqualizerBand belongs to has already been disposed of. /// - /// is less than .\n - /// -or-\n - /// is greater than . + /// is not inside of . /// public int Level { diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/MediaBufferSource.cs b/src/Tizen.Multimedia.MediaPlayer/Player/MediaBufferSource.cs index 2fa4cd6..a8982d4 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/MediaBufferSource.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/MediaBufferSource.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; using static Interop; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/MediaSource.cs b/src/Tizen.Multimedia.MediaPlayer/Player/MediaSource.cs index 428f1cb..fb147b5 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/MediaSource.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/MediaSource.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + namespace Tizen.Multimedia { /// diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamBufferStatusChangedEventArgs.cs b/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamBufferStatusChangedEventArgs.cs index 15d8e7a..be04411 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamBufferStatusChangedEventArgs.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamBufferStatusChangedEventArgs.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; namespace Tizen.Multimedia @@ -37,6 +38,10 @@ namespace Tizen.Multimedia /// public MediaStreamBufferStatus Status { get; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() { return $"Status : { Status.ToString() }"; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamConfiguration.cs b/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamConfiguration.cs index 5448e4e..f7c8abf 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamConfiguration.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamConfiguration.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; using System.Diagnostics; using static Interop; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSeekingOccurredEventArgs.cs b/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSeekingOccurredEventArgs.cs index e962250..f3aa874 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSeekingOccurredEventArgs.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSeekingOccurredEventArgs.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; namespace Tizen.Multimedia @@ -22,13 +23,13 @@ namespace Tizen.Multimedia /// public class MediaStreamSeekingOccurredEventArgs : EventArgs { - /// + /// /// Initializes a new instance of the MediaStreamSeekingOccurredEventArgs class. /// /// The value indicating the new position to seek. public MediaStreamSeekingOccurredEventArgs(ulong offset) { - Offset = offset; + Offset = offset; } /// @@ -36,6 +37,10 @@ namespace Tizen.Multimedia /// public ulong Offset { get; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() => $"Offset : { Offset.ToString() }"; } } diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSource.cs b/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSource.cs index 45946be..18e8873 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSource.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSource.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; using System.Collections.Generic; using System.Diagnostics; @@ -58,7 +59,7 @@ namespace Tizen.Multimedia private MediaStreamConfiguration CreateAudioConfiguration(AudioMediaFormat format) { - if( format == null ) + if (format == null) { return null; } diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/MediaUriSource.cs b/src/Tizen.Multimedia.MediaPlayer/Player/MediaUriSource.cs index 223a10e..e4c7d41 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/MediaUriSource.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/MediaUriSource.cs @@ -1,4 +1,3 @@ -/// Media Uri source /* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -14,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; using static Interop; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/PlaybackInterruptedEventArgs.cs b/src/Tizen.Multimedia.MediaPlayer/Player/PlaybackInterruptedEventArgs.cs index 8fe0082..0829466 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/PlaybackInterruptedEventArgs.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/PlaybackInterruptedEventArgs.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; namespace Tizen.Multimedia @@ -36,6 +37,10 @@ namespace Tizen.Multimedia /// public PlaybackInterruptionReason Reason { get; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() { return $"Reason : { Reason.ToString() }"; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs b/src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs new file mode 100644 index 0000000..a9f0f82 --- /dev/null +++ b/src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs @@ -0,0 +1,290 @@ +/* + * 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; +using System.Diagnostics; +using System.IO; +using System.Threading; +using static Interop; + +namespace Tizen.Multimedia +{ + public partial class Player + { + /// + /// Occurs when playback of a media is finished. + /// + public event EventHandler PlaybackCompleted; + private NativePlayer.PlaybackCompletedCallback _playbackCompletedCallback; + + /// + /// Occurs when playback of a media is interrupted. + /// + public event EventHandler PlaybackInterrupted; + private NativePlayer.PlaybackInterruptedCallback _playbackInterruptedCallback; + + /// + /// Occurs when any error occurs. + /// + /// The event handler will be executed on an internal thread. + public event EventHandler ErrorOccurred; + private NativePlayer.PlaybackErrorCallback _playbackErrorCallback; + + /// + /// Occurs when the video stream changed. + /// + /// The event handler will be executed on an internal thread. + public event EventHandler VideoStreamChanged; + private NativePlayer.VideoStreamChangedCallback _videoStreamChangedCallback; + + /// + /// Occurs when the subtitle is updated. + /// + /// The event handler will be executed on an internal thread. + public event EventHandler SubtitleUpdated; + private NativePlayer.SubtitleUpdatedCallback _subtitleUpdatedCallback; + + /// + /// Occurs when there is a change in the buffering status of streaming. + /// + public event EventHandler BufferingProgressChanged; + private NativePlayer.BufferingProgressCallback _bufferingProgressCallback; + + internal event EventHandler MediaStreamAudioBufferStatusChanged; + private NativePlayer.MediaStreamBufferStatusCallback _mediaStreamAudioBufferStatusChangedCallback; + + internal event EventHandler MediaStreamVideoBufferStatusChanged; + private NativePlayer.MediaStreamBufferStatusCallback _mediaStreamVideoBufferStatusChangedCallback; + + internal event EventHandler MediaStreamAudioSeekingOccurred; + private NativePlayer.MediaStreamSeekCallback _mediaStreamAudioSeekCallback; + + internal event EventHandler MediaStreamVideoSeekingOccurred; + private NativePlayer.MediaStreamSeekCallback _mediaStreamVideoSeekCallback; + + private bool _callbackRegistered; + + private void RegisterEvents() + { + if (_callbackRegistered) + { + return; + } + RegisterSubtitleUpdatedCallback(); + RegisterErrorOccurredCallback(); + RegisterPlaybackInterruptedCallback(); + RegisterVideoStreamChangedCallback(); + RegisterBufferingCallback(); + RegisterMediaStreamBufferStatusCallback(); + RegisterMediaStreamSeekCallback(); + RegisterPlaybackCompletedCallback(); + + _callbackRegistered = true; + } + + private void RegisterSubtitleUpdatedCallback() + { + _subtitleUpdatedCallback = (duration, text, _) => + { + Log.Debug(PlayerLog.Tag, "duration : " + duration + ", text : " + text); + SubtitleUpdated?.Invoke(this, new SubtitleUpdatedEventArgs(duration, text)); + }; + + NativePlayer.SetSubtitleUpdatedCb(Handle, _subtitleUpdatedCallback). + ThrowIfFailed("Failed to initialize the player"); + } + + private void RegisterPlaybackCompletedCallback() + { + _playbackCompletedCallback = _ => + { + Log.Debug(PlayerLog.Tag, "completed callback"); + PlaybackCompleted?.Invoke(this, EventArgs.Empty); + }; + NativePlayer.SetCompletedCb(Handle, _playbackCompletedCallback). + ThrowIfFailed("Failed to set PlaybackCompleted"); + } + + private void RegisterPlaybackInterruptedCallback() + { + _playbackInterruptedCallback = (code, _) => + { + if (!Enum.IsDefined(typeof(PlaybackInterruptionReason), code)) + { + return; + } + + if (code == PlaybackInterruptionReason.ResourceConflict) + { + OnUnprepared(); + } + + Log.Warn(PlayerLog.Tag, "interrupted reason : " + code); + PlaybackInterrupted?.Invoke(this, new PlaybackInterruptedEventArgs(code)); + }; + + NativePlayer.SetInterruptedCb(Handle, _playbackInterruptedCallback). + ThrowIfFailed("Failed to set PlaybackInterrupted"); + } + + private void RegisterErrorOccurredCallback() + { + _playbackErrorCallback = (code, _) => + { + //TODO handle service disconnected error. + Log.Warn(PlayerLog.Tag, "error code : " + code); + ErrorOccurred?.Invoke(this, new PlayerErrorOccurredEventArgs((PlayerError)code)); + }; + + NativePlayer.SetErrorCb(Handle, _playbackErrorCallback). + ThrowIfFailed("Failed to set PlaybackError"); + } + + #region VideoFrameDecoded event + + private EventHandler _videoFrameDecoded; + + private NativePlayer.VideoFrameDecodedCallback _videoFrameDecodedCallback; + + /// + /// Occurs when a video frame is decoded. + /// + /// + /// The event handler will be executed on an internal thread. + /// The in event args should be disposed after use. + /// + /// http://tizen.org/feature/multimedia.raw_video + /// The required feature is not supported. + /// + public event EventHandler VideoFrameDecoded + { + add + { + ValidationUtil.ValidateFeatureSupported(Features.RawVideo); + + _videoFrameDecoded += value; + } + remove + { + ValidationUtil.ValidateFeatureSupported(Features.RawVideo); + + _videoFrameDecoded -= value; + } + } + + private void RegisterVideoFrameDecodedCallback() + { + _videoFrameDecodedCallback = (packetHandle, _) => + { + var handler = _videoFrameDecoded; + if (handler != null) + { + Log.Debug(PlayerLog.Tag, "packet : " + packetHandle); + handler.Invoke(this, + new VideoFrameDecodedEventArgs(MediaPacket.From(packetHandle))); + } + else + { + MediaPacket.From(packetHandle).Dispose(); + } + }; + + NativePlayer.SetVideoFrameDecodedCb(Handle, _videoFrameDecodedCallback). + ThrowIfFailed("Failed to register the VideoFrameDecoded"); + } + #endregion + + private void RegisterVideoStreamChangedCallback() + { + ValidatePlayerState(PlayerState.Idle); + + _videoStreamChangedCallback = (width, height, fps, bitrate, _) => + { + Log.Debug(PlayerLog.Tag, "height : " + height + ", width : " + width + + ", fps : " + fps + ", bitrate : " + bitrate); + + VideoStreamChanged?.Invoke(this, new VideoStreamChangedEventArgs(height, width, fps, bitrate)); + }; + + NativePlayer.SetVideoStreamChangedCb(Handle, _videoStreamChangedCallback). + ThrowIfFailed("Failed to set the video stream changed callback"); + } + + private void RegisterBufferingCallback() + { + _bufferingProgressCallback = (percent, _) => + { + Log.Debug(PlayerLog.Tag, $"Buffering callback with percent { percent }"); + BufferingProgressChanged?.Invoke(this, new BufferingProgressChangedEventArgs(percent)); + }; + + NativePlayer.SetBufferingCb(Handle, _bufferingProgressCallback). + ThrowIfFailed("Failed to set BufferingProgress"); + } + + private void RegisterMediaStreamBufferStatusCallback() + { + _mediaStreamAudioBufferStatusChangedCallback = (status, _) => + { + Debug.Assert(Enum.IsDefined(typeof(MediaStreamBufferStatus), status)); + Log.Debug(PlayerLog.Tag, "audio buffer status : " + status); + MediaStreamAudioBufferStatusChanged?.Invoke(this, + new MediaStreamBufferStatusChangedEventArgs(status)); + }; + _mediaStreamVideoBufferStatusChangedCallback = (status, _) => + { + Debug.Assert(Enum.IsDefined(typeof(MediaStreamBufferStatus), status)); + Log.Debug(PlayerLog.Tag, "video buffer status : " + status); + MediaStreamVideoBufferStatusChanged?.Invoke(this, + new MediaStreamBufferStatusChangedEventArgs(status)); + }; + + RegisterMediaStreamBufferStatusCallback(StreamType.Audio, _mediaStreamAudioBufferStatusChangedCallback); + RegisterMediaStreamBufferStatusCallback(StreamType.Video, _mediaStreamVideoBufferStatusChangedCallback); + } + + private void RegisterMediaStreamBufferStatusCallback(StreamType streamType, + NativePlayer.MediaStreamBufferStatusCallback cb) + { + NativePlayer.SetMediaStreamBufferStatusCb(Handle, streamType, cb). + ThrowIfFailed("Failed to SetMediaStreamBufferStatus"); + } + + private void RegisterMediaStreamSeekCallback() + { + _mediaStreamAudioSeekCallback = (offset, _) => + { + Log.Debug(PlayerLog.Tag, "audio seeking offset : " + offset); + MediaStreamAudioSeekingOccurred?.Invoke(this, new MediaStreamSeekingOccurredEventArgs(offset)); + }; + _mediaStreamVideoSeekCallback = (offset, _) => + { + Log.Debug(PlayerLog.Tag, "video seeking offset : " + offset); + MediaStreamVideoSeekingOccurred?.Invoke(this, new MediaStreamSeekingOccurredEventArgs(offset)); + }; + + RegisterMediaStreamSeekCallback(StreamType.Audio, _mediaStreamAudioSeekCallback); + RegisterMediaStreamSeekCallback(StreamType.Video, _mediaStreamVideoSeekCallback); + } + + private void RegisterMediaStreamSeekCallback(StreamType streamType, NativePlayer.MediaStreamSeekCallback cb) + { + NativePlayer.SetMediaStreamSeekCb(Handle, streamType, cb). + ThrowIfFailed("Failed to SetMediaStreamSeek"); + } + } +} diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/Player.Properties.cs b/src/Tizen.Multimedia.MediaPlayer/Player/Player.Properties.cs new file mode 100644 index 0000000..a122492 --- /dev/null +++ b/src/Tizen.Multimedia.MediaPlayer/Player/Player.Properties.cs @@ -0,0 +1,403 @@ +/* + * 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; +using System.Diagnostics; +using System.IO; +using System.Threading; +using static Interop; + +namespace Tizen.Multimedia +{ + public partial class Player + { + private void RetrieveProperties() + { + NativePlayer.GetAudioLatencyMode(Handle, out _audioLatencyMode). + ThrowIfFailed("Failed to initialize the player"); + + NativePlayer.IsLooping(Handle, out _isLooping).ThrowIfFailed("Failed to initialize the player"); + } + + /// + /// Gets the native handle of the player. + /// + /// An IntPtr that contains the native handle of the player. + /// The player has already been disposed of. + public IntPtr Handle + { + get + { + ValidateNotDisposed(); + return _handle.DangerousGetHandle(); + } + } + + #region Network configuration + private string _cookie = ""; + private string _userAgent = ""; + + /// + /// Gets or Sets the cookie for streaming playback. + /// + /// To set, the player must be in the state. + /// The player is not in the valid state. + /// The player has already been disposed of. + /// The value to set is null. + public string Cookie + { + get + { + Log.Info(PlayerLog.Tag, "get cookie : " + _cookie); + return _cookie; + } + set + { + ValidatePlayerState(PlayerState.Idle); + + if (value == null) + { + throw new ArgumentNullException(nameof(value), "Cookie can't be null."); + } + + NativePlayer.SetStreamingCookie(Handle, value, value.Length). + ThrowIfFailed("Failed to set the cookie to the player"); + + _cookie = value; + } + } + + /// + /// Gets or Sets the user agent for streaming playback. + /// + /// To set, the player must be in the state. + /// The player is not in the valid state. + /// The player has already been disposed of. + /// The value to set is null. + public string UserAgent + { + get + { + Log.Info(PlayerLog.Tag, "get useragent : " + _userAgent); + return _userAgent; + } + set + { + ValidatePlayerState(PlayerState.Idle); + + if (value == null) + { + throw new ArgumentNullException(nameof(value), "UserAgent can't be null."); + } + + NativePlayer.SetStreamingUserAgent(Handle, value, value.Length). + ThrowIfFailed("Failed to set the user agent to the player"); + + _userAgent = value; + } + } + #endregion + + /// + /// Gets the state of the player. + /// + /// The current state of the player. + /// The player has already been disposed of. + public PlayerState State + { + get + { + ValidateNotDisposed(); + + if (IsPreparing()) + { + return PlayerState.Preparing; + } + + NativePlayer.GetState(Handle, out var state).ThrowIfFailed("Failed to retrieve the state of the player"); + + Debug.Assert(Enum.IsDefined(typeof(PlayerState), state)); + + return (PlayerState)state; + } + } + + private AudioLatencyMode _audioLatencyMode; + + /// + /// Gets or sets the audio latency mode. + /// + /// A that specifies the mode. The default is . + /// + /// If the mode is , + /// audio output interval can be increased so, it can keep more audio data to play. + /// But, state transition like pause or resume can be more slower than default(). + /// + /// The player has already been disposed of. + /// The value is not valid. + public AudioLatencyMode AudioLatencyMode + { + get + { + Log.Info(PlayerLog.Tag, "get audio latency mode : " + _audioLatencyMode); + return _audioLatencyMode; + } + set + { + ValidateNotDisposed(); + + if (_audioLatencyMode == value) + { + return; + } + ValidationUtil.ValidateEnum(typeof(AudioLatencyMode), value); + + NativePlayer.SetAudioLatencyMode(Handle, value). + ThrowIfFailed("Failed to set the audio latency mode of the player"); + + _audioLatencyMode = value; + } + } + + private bool _isLooping; + + /// + /// Gets or sets the looping state. + /// + /// true if the playback is looping; otherwise, false. The default value is false. + /// The player has already been disposed of. + public bool IsLooping + { + get + { + Log.Info(PlayerLog.Tag, "get looping : " + _isLooping); + return _isLooping; + } + set + { + ValidateNotDisposed(); + + if (_isLooping == value) + { + return; + } + + NativePlayer.SetLooping(Handle, value).ThrowIfFailed("Failed to set the looping state of the player"); + + _isLooping = value; + } + } + + #region Display methods + /// + /// Gets the display settings. + /// + /// A that specifies the display settings. + public PlayerDisplaySettings DisplaySettings { get; } + + private Display _display; + + private PlayerErrorCode SetDisplay(Display display) + { + if (display == null) + { + Log.Info(PlayerLog.Tag, "set display to none"); + return NativePlayer.SetDisplay(Handle, DisplayType.None, IntPtr.Zero); + } + + return display.ApplyTo(this); + } + + private void ReplaceDisplay(Display newDisplay) + { + _display?.SetOwner(null); + _display = newDisplay; + _display?.SetOwner(this); + } + + /// + /// Gets or sets the display. + /// + /// A that specifies the display. + /// The player must be in the state. + /// The player has already been disposed of. + /// The value has already been assigned to another player. + /// The player is not in the valid state. + public Display Display + { + get + { + return _display; + } + set + { + ValidatePlayerState(PlayerState.Idle); + + if (value?.Owner != null) + { + if (ReferenceEquals(this, value.Owner)) + { + return; + } + + throw new ArgumentException("The display has already been assigned to another."); + } + SetDisplay(value).ThrowIfFailed("Failed to set the display to the player"); + + ReplaceDisplay(value); + } + } + + PlayerErrorCode IDisplayable.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject) + { + Debug.Assert(IsDisposed == false); + + Debug.Assert(Enum.IsDefined(typeof(DisplayType), type)); + + return NativePlayer.SetDisplay(Handle, type, evasObject); + } + #endregion + + private PlayerTrackInfo _audioTrack; + + /// + /// Gets the track info for audio. + /// + /// A for audio. + public PlayerTrackInfo AudioTrackInfo + { + get + { + if (_audioTrack == null) + { + _audioTrack = new PlayerTrackInfo(this, StreamType.Audio); + } + return _audioTrack; + } + } + + private PlayerTrackInfo _subtitleTrackInfo; + + /// + /// Gets the track info for subtitle. + /// + /// A for subtitle. + public PlayerTrackInfo SubtitleTrackInfo + { + get + { + if (_subtitleTrackInfo == null) + { + _subtitleTrackInfo = new PlayerTrackInfo(this, StreamType.Text); + } + return _subtitleTrackInfo; + } + } + + private StreamInfo _streamInfo; + + /// + /// Gets the stream information. + /// + /// A for this player. + public StreamInfo StreamInfo + { + get + { + if (_streamInfo == null) + { + _streamInfo = new StreamInfo(this); + } + return _streamInfo; + } + } + + private readonly AudioEffect _audioEffect; + + /// + /// Gets the audio effect. + /// + /// http://tizen.org/feature/multimedia.custom_audio_effect + /// The required feature is not supported. + public AudioEffect AudioEffect + { + get + { + if (_audioEffect == null) + { + throw new NotSupportedException($"The feature({Features.AudioEffect}) is not supported."); + } + + return _audioEffect; + } + } + + /// + /// Gets or sets the mute state. + /// + /// true if the player is muted; otherwise, false. + /// The player has already been disposed of. + public bool Muted + { + get + { + bool value = false; + NativePlayer.IsMuted(Handle, out value).ThrowIfFailed("Failed to get the mute state of the player"); + + Log.Info(PlayerLog.Tag, "get mute : " + value); + + return value; + } + set + { + NativePlayer.SetMute(Handle, value).ThrowIfFailed("Failed to set the mute state of the player"); + } + } + + /// + /// Gets or sets the current volume. + /// + /// Valid volume range is from 0 to 1.0, inclusive. + /// The player has already been disposed of. + /// + /// is less than zero.\n + /// -or-\n + /// is greater than 1.0. + /// + public float Volume + { + get + { + float value = 0.0F; + NativePlayer.GetVolume(Handle, out value, out value). + ThrowIfFailed("Failed to get the volume of the player"); + return value; + } + set + { + if (value < 0F || 1.0F < value) + { + throw new ArgumentOutOfRangeException(nameof(value), value, + $"Valid volume range is 0 <= value <= 1.0, but got { value }."); + } + + NativePlayer.SetVolume(Handle, value, value). + ThrowIfFailed("Failed to set the volume of the player"); + } + } + } +} diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs b/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs index fd202df..1992c81 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs @@ -38,68 +38,15 @@ namespace Tizen.Multimedia /// It also provides functions to adjust the configurations of the player such as playback rate, volume, looping etc. /// Note that only one video player can be played at one time. /// - public class Player : IDisposable, IDisplayable + public partial class Player : IDisposable, IDisplayable { private PlayerHandle _handle; /// - /// Occurs when playback of a media is finished. - /// - public event EventHandler PlaybackCompleted; - private NativePlayer.PlaybackCompletedCallback _playbackCompletedCallback; - - /// - /// Occurs when playback of a media is interrupted. - /// - public event EventHandler PlaybackInterrupted; - private NativePlayer.PlaybackInterruptedCallback _playbackInterruptedCallback; - - /// - /// Occurs when any error occurs. - /// - /// The event handler will be executed on an internal thread. - public event EventHandler ErrorOccurred; - private NativePlayer.PlaybackErrorCallback _playbackErrorCallback; - - /// - /// Occurs when the video stream changed. - /// - /// The event handler will be executed on an internal thread. - public event EventHandler VideoStreamChanged; - private NativePlayer.VideoStreamChangedCallback _videoStreamChangedCallback; - - /// - /// Occurs when the subtitle is updated. - /// - /// The event handler will be executed on an internal thread. - public event EventHandler SubtitleUpdated; - private NativePlayer.SubtitleUpdatedCallback _subtitleUpdatedCallback; - - /// - /// Occurs when there is a change in the buffering status of streaming. - /// - public event EventHandler BufferingProgressChanged; - private NativePlayer.BufferingProgressCallback _bufferingProgressCallback; - - internal event EventHandler MediaStreamAudioBufferStatusChanged; - private NativePlayer.MediaStreamBufferStatusCallback _mediaStreamAudioBufferStatusChangedCallback; - - internal event EventHandler MediaStreamVideoBufferStatusChanged; - private NativePlayer.MediaStreamBufferStatusCallback _mediaStreamVideoBufferStatusChangedCallback; - - internal event EventHandler MediaStreamAudioSeekingOccurred; - private NativePlayer.MediaStreamSeekCallback _mediaStreamAudioSeekCallback; - - internal event EventHandler MediaStreamVideoSeekingOccurred; - private NativePlayer.MediaStreamSeekCallback _mediaStreamVideoSeekCallback; - - /// /// Initialize a new instance of the Player class. /// public Player() { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - NativePlayer.Create(out _handle).ThrowIfFailed("Failed to create player"); Debug.Assert(_handle != null); @@ -119,54 +66,6 @@ namespace Tizen.Multimedia DisplaySettings = PlayerDisplaySettings.Create(this); } - private void RetrieveProperties() - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - - NativePlayer.GetAudioLatencyMode(Handle, out _audioLatencyMode). - ThrowIfFailed("Failed to initialize the player"); - - NativePlayer.IsLooping(Handle, out _isLooping).ThrowIfFailed("Failed to initialize the player"); - - Log.Debug(PlayerLog.Tag, PlayerLog.Leave); - } - - private bool _callbackRegistered; - - private void RegisterCallbacks() - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - - if (_callbackRegistered) - { - return; - } - RegisterSubtitleUpdatedCallback(); - RegisterErrorOccurredCallback(); - RegisterPlaybackInterruptedCallback(); - RegisterVideoStreamChangedCallback(); - RegisterBufferingCallback(); - RegisterMediaStreamBufferStatusCallback(); - RegisterMediaStreamSeekCallback(); - RegisterPlaybackCompletedCallback(); - - _callbackRegistered = true; - } - - /// - /// Gets the native handle of the player. - /// - /// An IntPtr that contains the native handle of the player. - /// The player has already been disposed of. - public IntPtr Handle - { - get - { - ValidateNotDisposed(); - return _handle.DangerousGetHandle(); - } - } - internal void ValidatePlayerState(params PlayerState[] desiredStates) { Debug.Assert(desiredStates.Length > 0); @@ -183,320 +82,6 @@ namespace Tizen.Multimedia $"Current State : { curState }, Valid State : { string.Join(", ", desiredStates) }."); } - #region Properties - #region Network configuration - private string _cookie = ""; - private string _userAgent = ""; - - /// - /// Gets or Sets the cookie for streaming playback. - /// - /// To set, the player must be in the state. - /// The player is not in the valid state. - /// The player has already been disposed of. - /// The value to set is null. - public string Cookie - { - get - { - Log.Info(PlayerLog.Tag, "get cookie : " + _cookie); - return _cookie; - } - set - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - ValidatePlayerState(PlayerState.Idle); - - if (value == null) - { - Log.Error(PlayerLog.Tag, "cookie can't be null"); - throw new ArgumentNullException(nameof(value), "Cookie can't be null."); - } - - NativePlayer.SetStreamingCookie(Handle, value, value.Length). - ThrowIfFailed("Failed to set the cookie to the player"); - - _cookie = value; - Log.Debug(PlayerLog.Tag, PlayerLog.Leave); - } - } - - /// - /// Gets or Sets the user agent for streaming playback. - /// - /// To set, the player must be in the state. - /// The player is not in the valid state. - /// The player has already been disposed of. - /// The value to set is null. - public string UserAgent - { - get - { - Log.Info(PlayerLog.Tag, "get useragent : " + _userAgent); - return _userAgent; - } - set - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - ValidatePlayerState(PlayerState.Idle); - - if (value == null) - { - Log.Error(PlayerLog.Tag, "UserAgent can't be null"); - throw new ArgumentNullException(nameof(value), "UserAgent can't be null."); - } - - NativePlayer.SetStreamingUserAgent(Handle, value, value.Length). - ThrowIfFailed("Failed to set the user agent to the player"); - - _userAgent = value; - Log.Debug(PlayerLog.Tag, PlayerLog.Leave); - } - } - #endregion - - /// - /// Gets the state of the player. - /// - /// The current state of the player. - /// The player has already been disposed of. - public PlayerState State - { - get - { - ValidateNotDisposed(); - - if (IsPreparing()) - { - return PlayerState.Preparing; - } - - int state = 0; - NativePlayer.GetState(Handle, out state).ThrowIfFailed("Failed to retrieve the state of the player"); - - Debug.Assert(Enum.IsDefined(typeof(PlayerState), state)); - - return (PlayerState)state; - } - } - - private AudioLatencyMode _audioLatencyMode; - - /// - /// Gets or sets the audio latency mode. - /// - /// A that specifies the mode. The default is . - /// - /// If the mode is , - /// audio output interval can be increased so, it can keep more audio data to play. - /// But, state transition like pause or resume can be more slower than default(). - /// - /// The player has already been disposed of. - /// The value is not valid. - public AudioLatencyMode AudioLatencyMode - { - get - { - Log.Info(PlayerLog.Tag, "get audio latency mode : " + _audioLatencyMode); - return _audioLatencyMode; - } - set - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - ValidateNotDisposed(); - - if (_audioLatencyMode == value) - { - return; - } - ValidationUtil.ValidateEnum(typeof(AudioLatencyMode), value); - - NativePlayer.SetAudioLatencyMode(Handle, value). - ThrowIfFailed("Failed to set the audio latency mode of the player"); - - _audioLatencyMode = value; - } - } - - private bool _isLooping; - - /// - /// Gets or sets the looping state. - /// - /// true if the playback is looping; otherwise, false. The default value is false. - /// The player has already been disposed of. - public bool IsLooping - { - get - { - Log.Info(PlayerLog.Tag, "get looping : " + _isLooping); - return _isLooping; - } - set - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - ValidateNotDisposed(); - - if (_isLooping == value) - { - return; - } - - NativePlayer.SetLooping(Handle, value).ThrowIfFailed("Failed to set the looping state of the player"); - - _isLooping = value; - } - } - - #region Display methods - /// - /// Gets the display settings. - /// - /// A that specifies the display settings. - public PlayerDisplaySettings DisplaySettings { get; } - - private Display _display; - - private PlayerErrorCode SetDisplay(Display display) - { - if (display == null) - { - Log.Info(PlayerLog.Tag, "set display to none"); - return NativePlayer.SetDisplay(Handle, DisplayType.None, IntPtr.Zero); - } - - return display.ApplyTo(this); - } - - private void ReplaceDisplay(Display newDisplay) - { - _display?.SetOwner(null); - _display = newDisplay; - _display?.SetOwner(this); - } - - /// - /// Gets or sets the display. - /// - /// A that specifies the display. - /// The player must be in the state. - /// The player has already been disposed of. - /// The value has already been assigned to another player. - /// The player is not in the valid state. - public Display Display - { - get - { - return _display; - } - set - { - ValidatePlayerState(PlayerState.Idle); - - if (value?.Owner != null) - { - if (ReferenceEquals(this, value.Owner)) - { - return; - } - - throw new ArgumentException("The display has already been assigned to another."); - } - SetDisplay(value).ThrowIfFailed("Failed to set the display to the player"); - - ReplaceDisplay(value); - } - } - - PlayerErrorCode IDisplayable.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject) - { - Debug.Assert(IsDisposed == false); - - Debug.Assert(Enum.IsDefined(typeof(DisplayType), type)); - - return NativePlayer.SetDisplay(Handle, type, evasObject); - } - #endregion - - private PlayerTrackInfo _audioTrack; - - /// - /// Gets the track info for audio. - /// - /// A for audio. - public PlayerTrackInfo AudioTrackInfo - { - get - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - if (_audioTrack == null) - { - _audioTrack = new PlayerTrackInfo(this, StreamType.Audio); - } - return _audioTrack; - } - } - - private PlayerTrackInfo _subtitleTrackInfo; - - /// - /// Gets the track info for subtitle. - /// - /// A for subtitle. - public PlayerTrackInfo SubtitleTrackInfo - { - get - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - if (_subtitleTrackInfo == null) - { - _subtitleTrackInfo = new PlayerTrackInfo(this, StreamType.Text); - } - return _subtitleTrackInfo; - } - } - - private StreamInfo _streamInfo; - - /// - /// Gets the stream information. - /// - /// A for this player. - public StreamInfo StreamInfo - { - get - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - if (_streamInfo == null) - { - _streamInfo = new StreamInfo(this); - } - return _streamInfo; - } - } - - private readonly AudioEffect _audioEffect; - - /// - /// Gets the audio effect. - /// - /// http://tizen.org/feature/multimedia.custom_audio_effect - /// The required feature is not supported. - public AudioEffect AudioEffect - { - get - { - if (_audioEffect == null) - { - throw new NotSupportedException($"The feature({Features.AudioEffect}) is not supported."); - } - - return _audioEffect; - } - } - - #endregion - #region Dispose support private bool _disposed; @@ -505,7 +90,6 @@ namespace Tizen.Multimedia /// public void Dispose() { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); Dispose(true); } @@ -551,30 +135,6 @@ namespace Tizen.Multimedia #region Methods /// - /// Gets or sets the mute state. - /// - /// true if the player is muted; otherwise, false. - /// The player has already been disposed of. - public bool Muted - { - get - { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); - - bool value = false; - NativePlayer.IsMuted(Handle, out value).ThrowIfFailed("Failed to get the mute state of the player"); - - Log.Info(PlayerLog.Tag, "get mute : " + value); - - return value; - } - set - { - NativePlayer.SetMute(Handle, value).ThrowIfFailed("Failed to set the mute state of the player"); - } - } - - /// /// Gets the streaming download Progress. /// /// The containing current download progress. @@ -600,41 +160,6 @@ namespace Tizen.Multimedia return new DownloadProgress(start, current); } - #region Volume - /// - /// Gets or sets the current volume. - /// - /// Valid volume range is from 0 to 1.0, inclusive. - /// The player has already been disposed of. - /// - /// is less than zero.\n - /// -or-\n - /// is greater than 1.0. - /// - public float Volume - { - get - { - float value = 0.0F; - NativePlayer.GetVolume(Handle, out value, out value). - ThrowIfFailed("Failed to get the volume of the player"); - return value; - } - set - { - if (value < 0F || 1.0F < value) - { - throw new ArgumentOutOfRangeException(nameof(value), value, - $"Valid volume range is 0 <= value <= 1.0, but got { value }."); - } - - NativePlayer.SetVolume(Handle, value, value). - ThrowIfFailed("Failed to set the volume of the player"); - } - } - - #endregion - /// /// Sets the subtitle path for playback. /// @@ -702,7 +227,6 @@ namespace Tizen.Multimedia /// public void SetSubtitleOffset(int offset) { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); ValidatePlayerState(PlayerState.Playing, PlayerState.Paused); var err = NativePlayer.SetSubtitlePositionOffset(Handle, offset); @@ -718,13 +242,15 @@ namespace Tizen.Multimedia private void Prepare() { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); NativePlayer.Prepare(Handle).ThrowIfFailed("Failed to prepare the player"); } + /// + /// Called when the is invoked. + /// protected virtual void OnPreparing() { - RegisterCallbacks(); + RegisterEvents(); } /// @@ -799,6 +325,10 @@ namespace Tizen.Multimedia OnUnprepared(); } + /// + /// Called after the is unprepared. + /// + /// protected virtual void OnUnprepared() { _source?.DetachFrom(this); @@ -1075,7 +605,15 @@ namespace Tizen.Multimedia /// Applies the audio stream policy. /// /// The to apply. - /// The player must be in the state. + /// + /// The player must be in the state.\n + /// \n + /// does not support all .\n + /// Supported types are , , + /// , , + /// , , + /// and . + /// /// /// The player has already been disposed of.\n /// -or-\n @@ -1083,19 +621,17 @@ namespace Tizen.Multimedia /// /// The player is not in the valid state. /// is null. + /// + /// of is not supported by . + /// + /// public void ApplyAudioStreamPolicy(AudioStreamPolicy policy) { - Log.Debug(PlayerLog.Tag, PlayerLog.Enter); if (policy == null) { throw new ArgumentNullException(nameof(policy)); } - if (policy.Handle == IntPtr.Zero) - { - throw new ObjectDisposedException(nameof(policy)); - } - ValidatePlayerState(PlayerState.Idle); NativePlayer.SetAudioPolicyInfo(Handle, policy.Handle). @@ -1103,199 +639,6 @@ namespace Tizen.Multimedia } #endregion - #region Callback registrations - private void RegisterSubtitleUpdatedCallback() - { - _subtitleUpdatedCallback = (duration, text, _) => - { - Log.Debug(PlayerLog.Tag, "duration : " + duration + ", text : " + text); - SubtitleUpdated?.Invoke(this, new SubtitleUpdatedEventArgs(duration, text)); - }; - - NativePlayer.SetSubtitleUpdatedCb(Handle, _subtitleUpdatedCallback). - ThrowIfFailed("Failed to initialize the player"); - } - - private void RegisterPlaybackCompletedCallback() - { - _playbackCompletedCallback = _ => - { - Log.Debug(PlayerLog.Tag, "completed callback"); - PlaybackCompleted?.Invoke(this, EventArgs.Empty); - }; - NativePlayer.SetCompletedCb(Handle, _playbackCompletedCallback). - ThrowIfFailed("Failed to set PlaybackCompleted"); - } - - private void RegisterPlaybackInterruptedCallback() - { - _playbackInterruptedCallback = (code, _) => - { - if (!Enum.IsDefined(typeof(PlaybackInterruptionReason), code)) - { - return; - } - - if (code == PlaybackInterruptionReason.ResourceConflict) - { - OnUnprepared(); - } - - Log.Warn(PlayerLog.Tag, "interrupted reason : " + code); - PlaybackInterrupted?.Invoke(this, new PlaybackInterruptedEventArgs(code)); - }; - - NativePlayer.SetInterruptedCb(Handle, _playbackInterruptedCallback). - ThrowIfFailed("Failed to set PlaybackInterrupted"); - } - - private void RegisterErrorOccurredCallback() - { - _playbackErrorCallback = (code, _) => - { - //TODO handle service disconnected error. - Log.Warn(PlayerLog.Tag, "error code : " + code); - ErrorOccurred?.Invoke(this, new PlayerErrorOccurredEventArgs((PlayerError)code)); - }; - - NativePlayer.SetErrorCb(Handle, _playbackErrorCallback). - ThrowIfFailed("Failed to set PlaybackError"); - } - - #region VideoFrameDecoded event - - private EventHandler _videoFrameDecoded; - - private NativePlayer.VideoFrameDecodedCallback _videoFrameDecodedCallback; - - /// - /// Occurs when a video frame is decoded. - /// - /// - /// The event handler will be executed on an internal thread. - /// The in event args should be disposed after use. - /// - /// http://tizen.org/feature/multimedia.raw_video - /// The required feature is not supported. - /// - public event EventHandler VideoFrameDecoded - { - add - { - ValidationUtil.ValidateFeatureSupported(Features.RawVideo); - - _videoFrameDecoded += value; - } - remove - { - ValidationUtil.ValidateFeatureSupported(Features.RawVideo); - - _videoFrameDecoded -= value; - } - } - - private void RegisterVideoFrameDecodedCallback() - { - _videoFrameDecodedCallback = (packetHandle, _) => - { - var handler = _videoFrameDecoded; - if (handler != null) - { - Log.Debug(PlayerLog.Tag, "packet : " + packetHandle); - handler.Invoke(this, - new VideoFrameDecodedEventArgs(MediaPacket.From(packetHandle))); - } - else - { - MediaPacket.From(packetHandle).Dispose(); - } - }; - - NativePlayer.SetVideoFrameDecodedCb(Handle, _videoFrameDecodedCallback). - ThrowIfFailed("Failed to register the VideoFrameDecoded"); - } - #endregion - - private void RegisterVideoStreamChangedCallback() - { - ValidatePlayerState(PlayerState.Idle); - - _videoStreamChangedCallback = (width, height, fps, bitrate, _) => - { - Log.Debug(PlayerLog.Tag, "height : " + height + ", width : " + width - + ", fps : " + fps + ", bitrate : " + bitrate); - - VideoStreamChanged?.Invoke(this, new VideoStreamChangedEventArgs(height, width, fps, bitrate)); - }; - - NativePlayer.SetVideoStreamChangedCb(Handle, _videoStreamChangedCallback). - ThrowIfFailed("Failed to set the video stream changed callback"); - } - - private void RegisterBufferingCallback() - { - _bufferingProgressCallback = (percent, _) => - { - Log.Debug(PlayerLog.Tag, $"Buffering callback with percent { percent }"); - BufferingProgressChanged?.Invoke(this, new BufferingProgressChangedEventArgs(percent)); - }; - - NativePlayer.SetBufferingCb(Handle, _bufferingProgressCallback). - ThrowIfFailed("Failed to set BufferingProgress"); - } - - private void RegisterMediaStreamBufferStatusCallback() - { - _mediaStreamAudioBufferStatusChangedCallback = (status, _) => - { - Debug.Assert(Enum.IsDefined(typeof(MediaStreamBufferStatus), status)); - Log.Debug(PlayerLog.Tag, "audio buffer status : " + status); - MediaStreamAudioBufferStatusChanged?.Invoke(this, - new MediaStreamBufferStatusChangedEventArgs(status)); - }; - _mediaStreamVideoBufferStatusChangedCallback = (status, _) => - { - Debug.Assert(Enum.IsDefined(typeof(MediaStreamBufferStatus), status)); - Log.Debug(PlayerLog.Tag, "video buffer status : " + status); - MediaStreamVideoBufferStatusChanged?.Invoke(this, - new MediaStreamBufferStatusChangedEventArgs(status)); - }; - - RegisterMediaStreamBufferStatusCallback(StreamType.Audio, _mediaStreamAudioBufferStatusChangedCallback); - RegisterMediaStreamBufferStatusCallback(StreamType.Video, _mediaStreamVideoBufferStatusChangedCallback); - } - - private void RegisterMediaStreamBufferStatusCallback(StreamType streamType, - NativePlayer.MediaStreamBufferStatusCallback cb) - { - NativePlayer.SetMediaStreamBufferStatusCb(Handle, streamType, cb). - ThrowIfFailed("Failed to SetMediaStreamBufferStatus"); - } - - private void RegisterMediaStreamSeekCallback() - { - _mediaStreamAudioSeekCallback = (offset, _) => - { - Log.Debug(PlayerLog.Tag, "audio seeking offset : " + offset); - MediaStreamAudioSeekingOccurred?.Invoke(this, new MediaStreamSeekingOccurredEventArgs(offset)); - }; - _mediaStreamVideoSeekCallback = (offset, _) => - { - Log.Debug(PlayerLog.Tag, "video seeking offset : " + offset); - MediaStreamVideoSeekingOccurred?.Invoke(this, new MediaStreamSeekingOccurredEventArgs(offset)); - }; - - RegisterMediaStreamSeekCallback(StreamType.Audio, _mediaStreamAudioSeekCallback); - RegisterMediaStreamSeekCallback(StreamType.Video, _mediaStreamVideoSeekCallback); - } - - private void RegisterMediaStreamSeekCallback(StreamType streamType, NativePlayer.MediaStreamSeekCallback cb) - { - NativePlayer.SetMediaStreamSeekCb(Handle, streamType, cb). - ThrowIfFailed("Failed to SetMediaStreamSeek"); - } - #endregion - #region Preparing state private int _isPreparing; @@ -1321,6 +664,6 @@ namespace Tizen.Multimedia /// This method supports the product infrastructure and is not intended to be used directly from application code. /// protected static Exception GetException(int errorCode, string message) => - ((PlayerErrorCode) errorCode).GetException(message); + ((PlayerErrorCode)errorCode).GetException(message); } } diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs index 3504eb3..c661b08 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs @@ -25,6 +25,9 @@ namespace Tizen.Multimedia /// public class PlayerDisplaySettings { + /// + /// This constructor supports the product infrastructure and is not intended to be used directly from application code. + /// protected PlayerDisplaySettings(Player player) { if (player == null) @@ -37,6 +40,10 @@ namespace Tizen.Multimedia internal static PlayerDisplaySettings Create(Player player) => new PlayerDisplaySettings(player); + /// + /// Gets the player of this instance. + /// + /// The of this instance. protected Player Player { get; } /// diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs index efc1c1d..e52aaad 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs @@ -165,7 +165,7 @@ namespace Tizen.Multimedia /// /// Specifies display modes for /// - /// + /// public enum PlayerDisplayMode { /// @@ -195,7 +195,7 @@ namespace Tizen.Multimedia OriginalOrFull, /// - /// Region of interest, See . + /// Region of interest, See . /// Roi } diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerErrorOccurredEventArgs.cs b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerErrorOccurredEventArgs.cs index 6e72e95..206133f 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerErrorOccurredEventArgs.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerErrorOccurredEventArgs.cs @@ -36,6 +36,10 @@ namespace Tizen.Multimedia /// public PlayerError Error { get; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() { return $"Error={ Error.ToString() }"; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/StreamInfo.cs b/src/Tizen.Multimedia.MediaPlayer/Player/StreamInfo.cs index daa33bd..b31fb41 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/StreamInfo.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/StreamInfo.cs @@ -67,6 +67,10 @@ namespace Tizen.Multimedia set; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() => $"SampleRate={ SampleRate.ToString() }, Channels={ Channels.ToString() }, BitRate={ BitRate.ToString() }"; } @@ -132,6 +136,10 @@ namespace Tizen.Multimedia set; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() { return $"Fps={ Fps.ToString() }, BitRate={ BitRate.ToString() }, Size=[{ Size.ToString() }]"; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/SubtitleUpdatedEventArgs.cs b/src/Tizen.Multimedia.MediaPlayer/Player/SubtitleUpdatedEventArgs.cs index 0f1bee8..0aad452 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/SubtitleUpdatedEventArgs.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/SubtitleUpdatedEventArgs.cs @@ -38,6 +38,10 @@ namespace Tizen.Multimedia /// public string Text { get; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() { return $"Duration={ Duration.ToString() }, Text={ Text }"; diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/VideoStreamChangedEventArgs.cs b/src/Tizen.Multimedia.MediaPlayer/Player/VideoStreamChangedEventArgs.cs index ea54f34..327a565 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/VideoStreamChangedEventArgs.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/VideoStreamChangedEventArgs.cs @@ -1,6 +1,3 @@ -/// This File contains VideoStreamEventArgs class -/// -/// Copyright 2016 by Samsung Electronics, Inc., /* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -25,7 +22,6 @@ namespace Tizen.Multimedia /// public class VideoStreamChangedEventArgs : EventArgs { - /// /// Initializes a new instance of the VideoStreamChangedEventArgs class. /// @@ -51,6 +47,10 @@ namespace Tizen.Multimedia /// public int BitRate { get; } + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. public override string ToString() { return $"Size=({ Size.ToString() }), Fps={ Fps.ToString() }, BitRate={ BitRate.ToString() }"; diff --git a/src/Tizen.Multimedia.Metadata/Interop/Interop.Libc.cs b/src/Tizen.Multimedia.Metadata/Interop/Interop.Libc.cs index 3ace080..8e0fa30 100644 --- a/src/Tizen.Multimedia.Metadata/Interop/Interop.Libc.cs +++ b/src/Tizen.Multimedia.Metadata/Interop/Interop.Libc.cs @@ -1,4 +1,20 @@ -using System; +/* + * 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; internal static partial class Interop diff --git a/src/Tizen.Multimedia.Metadata/Interop/Interop.MetadataEditor.cs b/src/Tizen.Multimedia.Metadata/Interop/Interop.MetadataEditor.cs index c187e7b..6d54779 100644 --- a/src/Tizen.Multimedia.Metadata/Interop/Interop.MetadataEditor.cs +++ b/src/Tizen.Multimedia.Metadata/Interop/Interop.MetadataEditor.cs @@ -1,4 +1,20 @@ -using System; +/* + * 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.Multimedia; diff --git a/src/Tizen.Multimedia.Metadata/Interop/Interop.MetadataExtractor.cs b/src/Tizen.Multimedia.Metadata/Interop/Interop.MetadataExtractor.cs index 54a393f..d79e0dd 100644 --- a/src/Tizen.Multimedia.Metadata/Interop/Interop.MetadataExtractor.cs +++ b/src/Tizen.Multimedia.Metadata/Interop/Interop.MetadataExtractor.cs @@ -1,3 +1,19 @@ +/* + * 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.Multimedia; diff --git a/src/Tizen.Multimedia.Recorder/Interop/Interop.Recorder.cs b/src/Tizen.Multimedia.Recorder/Interop/Interop.Recorder.cs index b2f7ab8..514b9ad 100644 --- a/src/Tizen.Multimedia.Recorder/Interop/Interop.Recorder.cs +++ b/src/Tizen.Multimedia.Recorder/Interop/Interop.Recorder.cs @@ -74,7 +74,7 @@ internal static partial class Interop internal static extern RecorderError GetState(IntPtr handle, out RecorderState state); [DllImport(Libraries.Recorder, EntryPoint = "recorder_set_sound_stream_info")] - internal static extern RecorderError SetAudioStreamPolicy(IntPtr handle, IntPtr streamInfoHandle); + internal static extern RecorderError SetAudioStreamPolicy(IntPtr handle, AudioStreamPolicyHandle streamInfoHandle); [DllImport(Libraries.Recorder, EntryPoint = "recorder_set_error_cb")] internal static extern RecorderError SetErrorCallback(IntPtr handle, RecorderErrorCallback callback, IntPtr userData); diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.ScreenMirroring.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.ScreenMirroring.cs index 5c0a035..92d2cc8 100644 --- a/src/Tizen.Multimedia.Remoting/Interop/Interop.ScreenMirroring.cs +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.ScreenMirroring.cs @@ -16,7 +16,7 @@ using System; using System.Runtime.InteropServices; -using Tizen.Multimedia; +using Tizen.Multimedia.Remoting; internal static partial class Interop { diff --git a/src/Tizen.Multimedia.AudioIO/ValdiationUtil.cs b/src/Tizen.Multimedia.Remoting/NamespaceDoc.cs similarity index 61% rename from src/Tizen.Multimedia.AudioIO/ValdiationUtil.cs rename to src/Tizen.Multimedia.Remoting/NamespaceDoc.cs index d896ced..c5931e53 100644 --- a/src/Tizen.Multimedia.AudioIO/ValdiationUtil.cs +++ b/src/Tizen.Multimedia.Remoting/NamespaceDoc.cs @@ -14,18 +14,9 @@ * limitations under the License. */ -using System; - -namespace Tizen.Multimedia +/// +/// The System.Runtime.Remoting namespace provides classes and interfaces that work with remote process or device. +/// +namespace Tizen.Multimedia.Remoting { - 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); - } - } - } -} +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/ScreenMirroring/EventArgs.cs b/src/Tizen.Multimedia.Remoting/ScreenMirroring/EventArgs.cs index 81332b1..47fde2b 100644 --- a/src/Tizen.Multimedia.Remoting/ScreenMirroring/EventArgs.cs +++ b/src/Tizen.Multimedia.Remoting/ScreenMirroring/EventArgs.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Remoting { /// /// Provides data for the event. diff --git a/src/Tizen.Multimedia.Remoting/ScreenMirroring/InteropHelper.cs b/src/Tizen.Multimedia.Remoting/ScreenMirroring/InteropHelper.cs index 8e2a055..625854d 100644 --- a/src/Tizen.Multimedia.Remoting/ScreenMirroring/InteropHelper.cs +++ b/src/Tizen.Multimedia.Remoting/ScreenMirroring/InteropHelper.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Remoting { internal static class InteropHelper { diff --git a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroring.cs b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroring.cs index c81fcf3..a022af9 100644 --- a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroring.cs +++ b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroring.cs @@ -21,7 +21,7 @@ using System.Threading; using System.Threading.Tasks; using Native = Interop.ScreenMirroring; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Remoting { /// /// Provides the ability to connect to and disconnect from a screen mirroring source, diff --git a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringAudioInfo.cs b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringAudioInfo.cs index 28adf75..b4a226f 100644 --- a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringAudioInfo.cs +++ b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringAudioInfo.cs @@ -15,10 +15,10 @@ */ using System; -using static Tizen.Multimedia.InteropHelper; +using static Tizen.Multimedia.Remoting.InteropHelper; using Native = Interop.ScreenMirroring; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Remoting { /// /// Provides a means to retrieve the audio information which is negotiated with the source device. diff --git a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringEnums.cs b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringEnums.cs index eeaffad..91a4e9f 100644 --- a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringEnums.cs +++ b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringEnums.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Remoting { /// /// Specifies audio codecs for . diff --git a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringError.cs b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringError.cs index 805ca2a..7c76fd4 100644 --- a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringError.cs +++ b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringError.cs @@ -17,7 +17,7 @@ using System; using Tizen.Internals.Errors; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Remoting { internal enum ScreenMirroringErrorCode { diff --git a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringVideoInfo.cs b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringVideoInfo.cs index 62d4625..77ba41d 100644 --- a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringVideoInfo.cs +++ b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroringVideoInfo.cs @@ -15,10 +15,10 @@ */ using System; -using static Tizen.Multimedia.InteropHelper; +using static Tizen.Multimedia.Remoting.InteropHelper; using Native = Interop.ScreenMirroring; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Remoting { /// /// Provides a means to retrieve the video information which is negotiated with the source device. diff --git a/src/Tizen.Multimedia.StreamRecorder/StreamRecorder/StreamRecorderErrorFactory.cs b/src/Tizen.Multimedia.StreamRecorder/StreamRecorder/StreamRecorderErrorFactory.cs index d16b7c2..4cd95da 100644 --- a/src/Tizen.Multimedia.StreamRecorder/StreamRecorder/StreamRecorderErrorFactory.cs +++ b/src/Tizen.Multimedia.StreamRecorder/StreamRecorder/StreamRecorderErrorFactory.cs @@ -37,22 +37,24 @@ namespace Tizen.Multimedia internal static void ThrowException(int errorCode, string errorMessage = null, string paramName = null) { StreamRecorderError err = (StreamRecorderError)errorCode; - if(string.IsNullOrEmpty(errorMessage)) { + if (string.IsNullOrEmpty(errorMessage)) + { errorMessage = err.ToString(); } - switch((StreamRecorderError)errorCode) { - case StreamRecorderError.InvalidParameter: - throw new ArgumentException(errorMessage, paramName); - case StreamRecorderError.OutOfMemory: - throw new OutOfMemoryException(errorMessage); - case StreamRecorderError.PermissionDenied: - throw new UnauthorizedAccessException(errorMessage); - case StreamRecorderError.NotSupported: - throw new NotSupportedException(errorMessage); - case StreamRecorderError.InvalidState: - case StreamRecorderError.InvalidOperation: - case StreamRecorderError.OutOfStorage: - throw new InvalidOperationException(errorMessage); + switch ((StreamRecorderError)errorCode) + { + case StreamRecorderError.InvalidParameter: + throw new ArgumentException(errorMessage, paramName); + case StreamRecorderError.OutOfMemory: + throw new OutOfMemoryException(errorMessage); + case StreamRecorderError.PermissionDenied: + throw new UnauthorizedAccessException(errorMessage); + case StreamRecorderError.NotSupported: + throw new NotSupportedException(errorMessage); + case StreamRecorderError.InvalidState: + case StreamRecorderError.InvalidOperation: + case StreamRecorderError.OutOfStorage: + throw new InvalidOperationException(errorMessage); } } } diff --git a/src/Tizen.Multimedia.Util/Interop/Interop.ThumbnailExtractor.cs b/src/Tizen.Multimedia.Util/Interop/Interop.ThumbnailExtractor.cs index 53d73db..c1a02de 100644 --- a/src/Tizen.Multimedia.Util/Interop/Interop.ThumbnailExtractor.cs +++ b/src/Tizen.Multimedia.Util/Interop/Interop.ThumbnailExtractor.cs @@ -1,3 +1,19 @@ +/* + * 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; diff --git a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.BarCode.cs b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.BarCode.cs index 03a0013..b82df44 100644 --- a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.BarCode.cs +++ b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.BarCode.cs @@ -16,7 +16,7 @@ using System; using System.Runtime.InteropServices; -using Tizen.Multimedia; +using Tizen.Multimedia.Vision; /// /// Interop APIs diff --git a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Common.cs b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Common.cs index 771749f..377635f 100644 --- a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Common.cs +++ b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Common.cs @@ -16,7 +16,7 @@ using System; using System.Runtime.InteropServices; -using Tizen.Multimedia; +using Tizen.Multimedia.Vision; /// /// Interop APIs @@ -44,17 +44,17 @@ internal static partial class Interop } - internal static Tizen.Multimedia.Quadrangle ToApiStruct(this MediaVision.Quadrangle quadrangle) + internal static Quadrangle ToApiStruct(this MediaVision.Quadrangle quadrangle) { Tizen.Multimedia.Point[] points = new Tizen.Multimedia.Point[4]; for (int i = 0; i < 4; ++i) { points[i] = quadrangle.points[i].ToApiStruct(); } - return new Tizen.Multimedia.Quadrangle(points); + return new Quadrangle(points); } - internal static MediaVision.Quadrangle ToMarshalable(this Tizen.Multimedia.Quadrangle quadrangle) + internal static MediaVision.Quadrangle ToMarshalable(this Quadrangle quadrangle) { MediaVision.Point[] points = new MediaVision.Point[4]; for (int i = 0; i < 4; ++i) @@ -150,7 +150,7 @@ internal static partial class Interop internal static extern int GetWidth(IntPtr source, out uint imageWidth); [DllImport(Libraries.MediaVision, EntryPoint = "mv_source_get_colorspace")] - internal static extern int GetColorspace(IntPtr /* mv_source_h */ source, out Tizen.Multimedia.Colorspace colorspace); + internal static extern int GetColorspace(IntPtr /* mv_source_h */ source, out Colorspace colorspace); } /// @@ -165,28 +165,28 @@ internal static partial class Interop internal static extern int Destroy(IntPtr handle); [DllImport(Libraries.MediaVision, EntryPoint = "mv_engine_config_set_double_attribute")] - internal static extern Tizen.Multimedia.MediaVisionError SetDouble(IntPtr handle, string name, double value); + internal static extern MediaVisionError SetDouble(IntPtr handle, string name, double value); [DllImport(Libraries.MediaVision, EntryPoint = "mv_engine_config_set_int_attribute")] - internal static extern Tizen.Multimedia.MediaVisionError SetInt(IntPtr handle, string name, int value); + internal static extern MediaVisionError SetInt(IntPtr handle, string name, int value); [DllImport(Libraries.MediaVision, EntryPoint = "mv_engine_config_set_bool_attribute")] - internal static extern Tizen.Multimedia.MediaVisionError SetBool(IntPtr handle, string name, bool value); + internal static extern MediaVisionError SetBool(IntPtr handle, string name, bool value); [DllImport(Libraries.MediaVision, EntryPoint = "mv_engine_config_set_string_attribute")] - internal static extern Tizen.Multimedia.MediaVisionError SetString(IntPtr handle, string name, string value); + internal static extern MediaVisionError SetString(IntPtr handle, string name, string value); [DllImport(Libraries.MediaVision, EntryPoint = "mv_engine_config_get_double_attribute")] - internal static extern Tizen.Multimedia.MediaVisionError GetDouble(IntPtr handle, string name, out double value); + internal static extern MediaVisionError GetDouble(IntPtr handle, string name, out double value); [DllImport(Libraries.MediaVision, EntryPoint = "mv_engine_config_get_int_attribute")] - internal static extern Tizen.Multimedia.MediaVisionError GetInt(IntPtr handle, string name, out int value); + internal static extern MediaVisionError GetInt(IntPtr handle, string name, out int value); [DllImport(Libraries.MediaVision, EntryPoint = "mv_engine_config_get_bool_attribute")] - internal static extern Tizen.Multimedia.MediaVisionError GetBool(IntPtr handle, string name, out bool value); + internal static extern MediaVisionError GetBool(IntPtr handle, string name, out bool value); [DllImport(Libraries.MediaVision, EntryPoint = "mv_engine_config_get_string_attribute")] - internal static extern Tizen.Multimedia.MediaVisionError GetString(IntPtr handle, string name, out IntPtr value); + internal static extern MediaVisionError GetString(IntPtr handle, string name, out IntPtr value); } } } diff --git a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Face.cs b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Face.cs index 224caa8..9e0429e 100644 --- a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Face.cs +++ b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Face.cs @@ -16,7 +16,7 @@ using System; using System.Runtime.InteropServices; -using Tizen.Multimedia; +using Tizen.Multimedia.Vision; /// /// Interop APIs diff --git a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Image.cs b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Image.cs index 215331b..c0c3886 100644 --- a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Image.cs +++ b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Image.cs @@ -16,7 +16,7 @@ using System; using System.Runtime.InteropServices; -using Tizen.Multimedia; +using Tizen.Multimedia.Vision; /// /// Interop APIs diff --git a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Surveillance.cs b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Surveillance.cs index 5119730..cafffc3 100644 --- a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Surveillance.cs +++ b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Surveillance.cs @@ -16,7 +16,7 @@ using System; using System.Runtime.InteropServices; -using Tizen.Multimedia; +using Tizen.Multimedia.Vision; /// /// Interop APIs diff --git a/src/Tizen.Multimedia.Vision/MediaVision/Barcode.cs b/src/Tizen.Multimedia.Vision/MediaVision/Barcode.cs index 6735533..1fece11 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/Barcode.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/Barcode.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a detected barcode. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetectionConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetectionConfiguration.cs index 1da6986..3dd495f 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetectionConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetectionConfiguration.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of . diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetectionTarget.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetectionTarget.cs index 231dce5..3659b98 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetectionTarget.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetectionTarget.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies the target of . diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetector.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetector.cs index df4d6da..85cd90a 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetector.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeDetector.cs @@ -20,7 +20,7 @@ using System.Threading.Tasks; using InteropBarcode = Interop.MediaVision.BarcodeDetector; using Unmanaged = Interop.MediaVision; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to detect barcodes on image sources. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs index eb29a04..3be2d49 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs @@ -16,7 +16,7 @@ using Tizen.Common; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of instances. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs index b4be4a1..45c896e 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs @@ -17,7 +17,7 @@ using System; using InteropBarcode = Interop.MediaVision.BarcodeGenerator; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to generate barcodes and QR codes. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeImageConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeImageConfiguration.cs index 6227c88..40588d0 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeImageConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeImageConfiguration.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration for the image to be generated by . diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeImageFormat.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeImageFormat.cs index 5481510..b075bba 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeImageFormat.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeImageFormat.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies supported image formats for diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeType.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeType.cs index 2cc4283..c107c71 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeType.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeType.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies the supported barcode types. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/Colorspace.cs b/src/Tizen.Multimedia.Vision/MediaVision/Colorspace.cs index 79135e0..f7eee9b 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/Colorspace.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/Colorspace.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies colorspaces for MediaVision. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/EngineConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/EngineConfiguration.cs index 354205c..92c14e7 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/EngineConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/EngineConfiguration.cs @@ -19,7 +19,7 @@ using Tizen.System; using System.Runtime.InteropServices; using static Interop.MediaVision; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// A base class for configuration classes. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ErrorCorrectionLevel.cs b/src/Tizen.Multimedia.Vision/MediaVision/ErrorCorrectionLevel.cs index 7388c4f..ce5b750 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ErrorCorrectionLevel.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ErrorCorrectionLevel.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies the supported QR code error correction level. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/EyeCondition.cs b/src/Tizen.Multimedia.Vision/MediaVision/EyeCondition.cs index 7cf912f..0b48dc9 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/EyeCondition.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/EyeCondition.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies the eyes state types. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceDetectionConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceDetectionConfiguration.cs index cd08d30..1cb8aee 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceDetectionConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceDetectionConfiguration.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of instances. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceDetector.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceDetector.cs index c99d966..5b33fa3 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceDetector.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceDetector.cs @@ -18,7 +18,7 @@ using System; using System.Threading.Tasks; using InteropFace = Interop.MediaVision.Face; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to detect faces on image sources. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionConfiguration.cs index d3451f8..6e99b17 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionConfiguration.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of instances. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModel.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModel.cs index fc67b3d..d2aab08 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModel.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModel.cs @@ -19,7 +19,7 @@ using System.IO; using System.Runtime.InteropServices; using InteropModel = Interop.MediaVision.FaceRecognitionModel; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents the face recognition model interface. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModelType.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModelType.cs index f701f9e..f9c9671 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModelType.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModelType.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies the face recognition model learning algorithms. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionResult.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionResult.cs index 63d2fca..faa25be 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionResult.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionResult.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents result of operations. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognizer.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognizer.cs index ba52619..01d4a92 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognizer.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceRecognizer.cs @@ -19,7 +19,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using InteropFace = Interop.MediaVision.Face; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to recognize faces, face expressions and eye condition on image sources. @@ -303,15 +303,15 @@ namespace Tizen.Multimedia TaskCompletionSource tcsResult = new TaskCompletionSource(); - InteropFace.MvFaceFacialExpressionRecognizedCallback cb = (IntPtr sourceHandle, IntPtr engineCfgHandle, - global::Interop.MediaVision.Rectangle faceLocation, FacialExpression facialExpression, IntPtr _) => - { - Log.Info(MediaVisionLog.Tag, $"Facial expression recognized, expression : {facialExpression}"); - if (!tcsResult.TrySetResult(facialExpression)) - { - Log.Error(MediaVisionLog.Tag, "Failed to set facial result"); - } - }; + InteropFace.MvFaceFacialExpressionRecognizedCallback cb = (IntPtr sourceHandle, IntPtr engineCfgHandle, + global::Interop.MediaVision.Rectangle faceLocation, FacialExpression facialExpression, IntPtr _) => + { + Log.Info(MediaVisionLog.Tag, $"Facial expression recognized, expression : {facialExpression}"); + if (!tcsResult.TrySetResult(facialExpression)) + { + Log.Error(MediaVisionLog.Tag, "Failed to set facial result"); + } + }; using (var cbKeeper = ObjectKeeper.Get(cb)) { diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceTracker.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceTracker.cs index 4824579..8771dd2 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceTracker.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceTracker.cs @@ -19,7 +19,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using InteropFace = Interop.MediaVision.Face; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to track faces on image sources. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceTrackingModel.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceTrackingModel.cs index be9ae12..1471ae6 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceTrackingModel.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceTrackingModel.cs @@ -18,7 +18,7 @@ using System; using System.IO; using InteropModel = Interop.MediaVision.FaceTrackingModel; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents face tracking model. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FaceTrackingResult.cs b/src/Tizen.Multimedia.Vision/MediaVision/FaceTrackingResult.cs index 3ee5f6b..dcdc1c1 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FaceTrackingResult.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FaceTrackingResult.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents result of face tracking operation. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/FacialExpression.cs b/src/Tizen.Multimedia.Vision/MediaVision/FacialExpression.cs index c136d97..f6ee8f0 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/FacialExpression.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/FacialExpression.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies the expression types for faces. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ImageFillConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/ImageFillConfiguration.cs index 3b22467..db2065a 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ImageFillConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ImageFillConfiguration.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of fill operations of instances. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ImageObject.cs b/src/Tizen.Multimedia.Vision/MediaVision/ImageObject.cs index ac932c5..74daec1 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ImageObject.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ImageObject.cs @@ -18,7 +18,7 @@ using System; using System.IO; using InteropImage = Interop.MediaVision.Image; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents an image object. @@ -43,7 +43,7 @@ namespace Tizen.Multimedia /// Initializes a new instance of the class from the specified file. /// /// - /// ImageObject has been saved by can be loaded. + /// ImageObject has been saved by can be loaded. /// /// Path to the image object to load. /// is null. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognitionConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognitionConfiguration.cs index 15dbd2e..7856003 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognitionConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognitionConfiguration.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of . diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognitionResult.cs b/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognitionResult.cs index 0eafa1a..11a1a4c 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognitionResult.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognitionResult.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a result of RecognizeAsync operations of . diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognizer.cs b/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognizer.cs index ef9c27e..3bf41dd 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognizer.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ImageRecognizer.cs @@ -19,7 +19,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using InteropImage = Interop.MediaVision.Image; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to recognize images on image sources. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ImageTracker.cs b/src/Tizen.Multimedia.Vision/MediaVision/ImageTracker.cs index bcf07c1..894c3af 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ImageTracker.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ImageTracker.cs @@ -19,7 +19,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using InteropImage = Interop.MediaVision.Image; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to track images on image sources. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ImageTrackingConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/ImageTrackingConfiguration.cs index 042b64b..5aaab8c 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ImageTrackingConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ImageTrackingConfiguration.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of . diff --git a/src/Tizen.Multimedia.Vision/MediaVision/ImageTrackingModel.cs b/src/Tizen.Multimedia.Vision/MediaVision/ImageTrackingModel.cs index 8c86572..6d7ea29 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/ImageTrackingModel.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/ImageTrackingModel.cs @@ -18,7 +18,7 @@ using System; using System.IO; using InteropModel = Interop.MediaVision.ImageTrackingModel; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents the image tracking model interface. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionError.cs b/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionError.cs index 8298cfd..a35ae86 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionError.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionError.cs @@ -18,7 +18,7 @@ using System; using System.IO; using Tizen.Internals.Errors; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { internal static class MediaVisionLog { diff --git a/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs b/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs index 28ce4d9..9975eca 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs @@ -18,7 +18,7 @@ using System; using System.Diagnostics; using InteropSource = Interop.MediaVision.MediaSource; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents the media vision source to keep information on image or video frame data as raw buffer. @@ -41,7 +41,7 @@ namespace Tizen.Multimedia { fillAction(_handle); } - catch(Exception) + catch (Exception) { InteropSource.Destroy(_handle); _disposed = true; diff --git a/src/Tizen.Multimedia.Vision/MediaVision/MovementDetectedEventArgs.cs b/src/Tizen.Multimedia.Vision/MediaVision/MovementDetectedEventArgs.cs index 3456c5d..12c4f3a 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/MovementDetectedEventArgs.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/MovementDetectedEventArgs.cs @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides data for the event. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/MovementDetectionConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/MovementDetectionConfiguration.cs index a9aebe8..9a146b5 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/MovementDetectionConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/MovementDetectionConfiguration.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of . diff --git a/src/Tizen.Multimedia.Vision/MediaVision/MovementDetector.cs b/src/Tizen.Multimedia.Vision/MediaVision/MovementDetector.cs index d5861d0..f34562c 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/MovementDetector.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/MovementDetector.cs @@ -17,7 +17,7 @@ using System; using static Interop.MediaVision.Surveillance; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to detect movement on image sources. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetectedEventArgs.cs b/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetectedEventArgs.cs index 7c9576a..cd5d019 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetectedEventArgs.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetectedEventArgs.cs @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides data for the event. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetectionConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetectionConfiguration.cs index b4ef07b..2033d51 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetectionConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetectionConfiguration.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of instances. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetector.cs b/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetector.cs index ef6d305..bfde49e 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetector.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/PersonAppearanceDetector.cs @@ -17,7 +17,7 @@ using System; using static Interop.MediaVision.Surveillance; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to detect person appearance changes on image sources. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognitionConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognitionConfiguration.cs index dd179a3..10e6edd 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognitionConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognitionConfiguration.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a configuration of instances. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognitionInfo.cs b/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognitionInfo.cs index a7589c8..3cd326d 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognitionInfo.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognitionInfo.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a result of instances. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognizedEventArgs.cs b/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognizedEventArgs.cs index bbe65a9..dc48ec3 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognizedEventArgs.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognizedEventArgs.cs @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides data for the event. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognizer.cs b/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognizer.cs index e14e38c..5f191c4 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognizer.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/PersonRecognizer.cs @@ -17,7 +17,7 @@ using System; using static Interop.MediaVision.Surveillance; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to recognize person on image sources. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs index b090a38..5daaac7 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a QR configuration of . diff --git a/src/Tizen.Multimedia.Vision/MediaVision/QrMode.cs b/src/Tizen.Multimedia.Vision/MediaVision/QrMode.cs index 489a066..5721f9d 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/QrMode.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/QrMode.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Specifies the supported QR code encoding mode. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/Quadrangle.cs b/src/Tizen.Multimedia.Vision/MediaVision/Quadrangle.cs index 577b5cd..aff9ba3 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/Quadrangle.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/Quadrangle.cs @@ -16,7 +16,7 @@ using System; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Represents a region with 4 s. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceConfiguration.cs index a80ccc0..a81af9d 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceConfiguration.cs @@ -14,7 +14,7 @@ * limitations under the License. */ -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// SurveillanceEngineConfiguration is a base class for surveillance configurations. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceEngine.cs b/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceEngine.cs index f1ce4ec..52f715d 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceEngine.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceEngine.cs @@ -18,7 +18,7 @@ using System; using System.Runtime.InteropServices; using static Interop.MediaVision.Surveillance; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// SurveillanceEngine is a base class for surveillance event triggers. diff --git a/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceSource.cs b/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceSource.cs index 792243c..19c8d47 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceSource.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/SurveillanceSource.cs @@ -17,7 +17,7 @@ using System; using static Interop.MediaVision.Surveillance; -namespace Tizen.Multimedia +namespace Tizen.Multimedia.Vision { /// /// Provides the ability to push source to surveillance engines. diff --git a/src/Tizen.Multimedia.AudioIO/MultimediaDebug.cs b/src/Tizen.Multimedia.Vision/NamespaceDoc.cs similarity index 55% rename from src/Tizen.Multimedia.AudioIO/MultimediaDebug.cs rename to src/Tizen.Multimedia.Vision/NamespaceDoc.cs index 3e00569..e66f453 100644 --- a/src/Tizen.Multimedia.AudioIO/MultimediaDebug.cs +++ b/src/Tizen.Multimedia.Vision/NamespaceDoc.cs @@ -14,18 +14,12 @@ * limitations under the License. */ -using System.Diagnostics; - -namespace Tizen.Multimedia +/// +/// The Tizen.Multimedia.Vision namespace contains classes and interfaces that support vision processing including +/// face detection, face recognition, face tracking, barcode detection, barcode generation, flat image detection, +/// flat image recognition, flat image tracking, flat image features extraction, movement detection, +/// person appearance/disappearance detection and person recognition. +/// +namespace Tizen.Multimedia.Vision { - internal class MultimediaDebug - { - [Conditional("DEBUG")] - internal static void AssertNoError(int errorCode) - { - Debug.Assert(errorCode == (int)Internals.Errors.ErrorCode.None, - $"The API is supposed not to return an error! But it returns error({ errorCode }).", - "Implementation of core may have been changed, modify the call to throw if the return code is not ok."); - } - } } diff --git a/src/Tizen.Multimedia/AssemblyAttrs.cs b/src/Tizen.Multimedia/AssemblyAttrs.cs index c9f90b1..50e0b43 100644 --- a/src/Tizen.Multimedia/AssemblyAttrs.cs +++ b/src/Tizen.Multimedia/AssemblyAttrs.cs @@ -14,11 +14,17 @@ * limitations under the License. */ - // This file specifies any assembly atrributes. - // Note that InternalsVisibleToAttribute can be removed or added and needs to be only Multimedia packages only. +// This file specifies any assembly attributes. +// Note that InternalsVisibleToAttribute can be removed or added and needs to be Multimedia packages only. using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Tizen.Multimedia.AudioIO, " + + "PublicKey=0024000004800000940000000602000000240000525341310004000001000100d115b100424841" + + "6b12d21b626cfb17149c9303fe394693fd3b32d7872e89559a4fa96c98110c2e62eea48aca693b" + + "ddbe17094ca8ea2e2cd79970ca590fb672b9b371b5d7002076817321f62d6483ea50c56dbd1f37" + + "b185a4c24c47718876e6ae6d266508c551170d4cbdda3f82edaff9405ee3d7857282d8269e8e518d2f0fb2")] + [assembly: InternalsVisibleTo("Tizen.Multimedia.Camera, " + "PublicKey=0024000004800000940000000602000000240000525341310004000001000100d115b100424841" + "6b12d21b626cfb17149c9303fe394693fd3b32d7872e89559a4fa96c98110c2e62eea48aca693b" + diff --git a/src/Tizen.Multimedia/AudioManager/AudioDevice.cs b/src/Tizen.Multimedia/AudioManager/AudioDevice.cs index e085d9c..59d33bd 100755 --- a/src/Tizen.Multimedia/AudioManager/AudioDevice.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDevice.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -19,92 +19,102 @@ using System.Runtime.InteropServices; namespace Tizen.Multimedia { - internal static class AudioDeviceLog - { - internal const string Tag = "Tizen.Multimedia.AudioDevice"; - } - /// /// The Device API provides functions to query the information of sound devices. /// public class AudioDevice { private readonly int _id; - private readonly string _name; private readonly AudioDeviceType _type; private readonly AudioDeviceIoDirection _ioDirection; - private readonly AudioDeviceState _state; - private readonly IntPtr _handle; internal AudioDevice(IntPtr deviceHandle) { - _handle = deviceHandle; - int ret; - - ret = Interop.AudioDevice.GetDeviceId(_handle, out _id); - if (ret != 0) - { - Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device Id: " + (AudioManagerError)ret); - } - AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device Id"); - - IntPtr name; - ret = Interop.AudioDevice.GetDeviceName(_handle, out name); - if (ret != 0) - { - Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device name" + (AudioManagerError)ret); - } - AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device name"); + int ret = Interop.AudioDevice.GetDeviceId(deviceHandle, out _id); + MultimediaDebug.AssertNoError(ret); - _name = Marshal.PtrToStringAnsi(name); + ret = Interop.AudioDevice.GetDeviceName(deviceHandle, out var name); + MultimediaDebug.AssertNoError(ret); - ret = Interop.AudioDevice.GetDeviceType(_handle, out _type); - if (ret != 0) - { - Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device type" + (AudioManagerError)ret); - } - AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device type"); + Name = Marshal.PtrToStringAnsi(name); - ret = Interop.AudioDevice.GetDeviceIoDirection(_handle, out _ioDirection); - if (ret != 0) - { - Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device IoDirection" + (AudioManagerError)ret); - } - AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device IO Direction"); + ret = Interop.AudioDevice.GetDeviceType(deviceHandle, out _type); + MultimediaDebug.AssertNoError(ret); - ret = Interop.AudioDevice.GetDeviceState(_handle, out _state); - if (ret != 0) - { - Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device state" + (AudioManagerError)ret); - } - AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device state"); + ret = (int)Interop.AudioDevice.GetDeviceIoDirection(deviceHandle, out _ioDirection); + MultimediaDebug.AssertNoError(ret); } /// - /// The id of the device. + /// Gets the id of the device. /// + /// The id of the device. public int Id => _id; /// - /// The name of the device. + /// Gets the name of the device. /// - public string Name => _name; + /// The name of the device. + public string Name { get; } /// - /// The type of the device. + /// Gets the type of the device. /// + /// The of the device. public AudioDeviceType Type => _type; /// - /// The io direction of the device. + /// Gets the IO direction of the device. /// + /// The IO direction of the device. public AudioDeviceIoDirection IoDirection => _ioDirection; /// - /// The state of the device. + /// Gets the state of the device. + /// + /// The of the device. + public AudioDeviceState State + { + get + { + Interop.AudioDevice.GetDeviceState(Id, out var state). + Validate("Failed to get the state of the device"); + + return state; + } + } + + /// + /// Returns a string that represents the current object. /// - public AudioDeviceState State => _state; + /// A string that represents the current object. + public override string ToString() => + $"Id={Id}, Name={Name}, Type={Type}, IoDirection={IoDirection}, State={State}"; + + /// + /// Compares an object to an instance of for equality. + /// + /// A to compare. + /// true if the two devices are equal; otherwise, false. + public override bool Equals(object obj) + { + var rhs = obj as AudioDevice; + if (rhs == null) + { + return false; + } + + return Id == rhs.Id; + } + - internal IntPtr Handle => _handle; + /// + /// Gets the hash code for this instance of . + /// + /// The hash code for this instance of . + public override int GetHashCode() + { + return Id.GetHashCode(); + } } } diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionChangedEventArgs.cs index 9369a99..d23266c 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionChangedEventArgs.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -19,7 +19,7 @@ using System; namespace Tizen.Multimedia { /// - /// Class extending EventArgs which contains parameters to be passed to event handler of DeviceConnected event + /// Provides data for the event. /// public class AudioDeviceConnectionChangedEventArgs : EventArgs { @@ -30,13 +30,15 @@ namespace Tizen.Multimedia } /// - /// The object of sound device + /// Gets the device. /// + /// The . public AudioDevice Device { get; } /// - /// The state of device connection: (true = connected, false = disconnected) + /// Gets the connection state of the device. /// + /// true if the device is connected; otherwise, false. public bool IsConnected { get; } } } diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs index 41a5564..ba9e33a 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -19,24 +19,26 @@ using System; namespace Tizen.Multimedia { /// - /// Class extending EventArgs which contains parameters to be passed to event handler of DeviceInformationChanged event + /// Provides data for the event. /// public class AudioDeviceStateChangedEventArgs : EventArgs { internal AudioDeviceStateChangedEventArgs(AudioDevice device, AudioDeviceState changedState) { Device = device; - ChangedState = changedState; + State = changedState; } /// - /// The object of sound device + /// Gets the device. /// + /// The . public AudioDevice Device { get; } /// - /// The entry of sound device state + /// Gets the state of the device. /// - public AudioDeviceState ChangedState { get; } + /// The of the device. + public AudioDeviceState State { get; } } } diff --git a/src/Tizen.Multimedia/AudioManager/AudioManager.cs b/src/Tizen.Multimedia/AudioManager/AudioManager.cs index 1469637..e6191e5 100755 --- a/src/Tizen.Multimedia/AudioManager/AudioManager.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioManager.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -19,180 +19,185 @@ using System.Collections.Generic; namespace Tizen.Multimedia { - internal static class AudioManagerLog - { - internal const string Tag = "Tizen.Multimedia.AudioManager"; - } - /// - /// The Audio Manager class provides functions to get and set sound parameters like volume and devices. + /// Provides the ability to control volume levels and monitor audio devices. /// public static class AudioManager { - private static int _deviceConnectionChangedCallbackId = -1; - private static int _deviceStateChangedCallbackId = -1; - - private static Interop.SoundDeviceConnectionChangedCallback _audioDeviceConnectionChangedCallback; - private static Interop.SoundDeviceStateChangedCallback _audioDeviceStateChangedCallback; - - private static EventHandler _audioDeviceConnectionChanged; - private static EventHandler _audioDeviceStateChanged; - - /// - /// Constructor for AudioManager. Initializes the VolumeController property etc. - /// static AudioManager() { VolumeController = new AudioVolume(); } /// - /// Registers/Unregisters a function to be invoked when the state of connection of an Audio device was changed. + /// Gets the volume controller. /// - public static event EventHandler DeviceConnectionChanged + /// The . + public static AudioVolume VolumeController { get; } + + /// + /// Gets the all devices currently connected. + /// + /// The audio device options. + /// An IEnumerable<AudioDevice> that contains connected devices. + public static IEnumerable GetConnectedDevices() { - add + IntPtr deviceListHandle = IntPtr.Zero; + + try { - if (_audioDeviceConnectionChanged == null) + var ret = Interop.AudioDevice.GetDeviceList(AudioDeviceOptions.All, out deviceListHandle); + + List result = new List(); + + if (ret == AudioManagerError.NoData) { - RegisterAudioDeviceEvent(); - Tizen.Log.Info(AudioManagerLog.Tag, "DeviceConnectionChanged event registered"); + return result; } - _audioDeviceConnectionChanged += value; - Tizen.Log.Info(AudioManagerLog.Tag, "DeviceConnectionChanged event added"); - } - remove - { - if (_audioDeviceConnectionChanged?.GetInvocationList()?.GetLength(0) == 1) + + ret.Validate("Failed to get connected devices"); + + while (ret == AudioManagerError.None) { - UnregisterDeviceConnectionChangedEvent(); + ret = Interop.AudioDevice.GetNextDevice(deviceListHandle, out var deviceHandle); + + if (ret == AudioManagerError.NoData) + { + break; + } + + ret.Validate("Failed to get connected devices"); + + result.Add(new AudioDevice(deviceHandle)); } - _audioDeviceConnectionChanged -= value; - Tizen.Log.Info(AudioManagerLog.Tag, "DeviceConnectionChanged event removed"); + return result; + } + finally + { + Interop.AudioDevice.FreeDeviceList(deviceListHandle); } } + #region DeviceConnectionChanged event + private static int _deviceConnectionChangedCallbackId = -1; + + private static Interop.AudioDevice.ConnectionChangedCallback _audioDeviceConnectionChangedCallback; + private static EventHandler _audioDeviceConnectionChanged; + private static object _audioDeviceConnectionLock = new object(); + /// - /// Registers/Unregisters a callback function to be invoked when the state of an Audio sound device was changed. + /// Occurs when the state of connection of an audio device changes. /// - public static event EventHandler DeviceStateChanged + public static event EventHandler DeviceConnectionChanged { add { - if (_audioDeviceStateChanged == null) + lock (_audioDeviceConnectionLock) { - RegisterDeviceStateChangedEvent(); + if (_audioDeviceConnectionChanged == null) + { + RegisterAudioDeviceEvent(); + } + _audioDeviceConnectionChanged += value; } - _audioDeviceStateChanged += value; - Tizen.Log.Info(AudioManagerLog.Tag, "DeviceStateChanged event added"); } remove { - if (_audioDeviceStateChanged?.GetInvocationList()?.GetLength(0) == 1) + if (value == null) { - UnregisterDeviceStateChangedEvent(); + return; + } + + lock (_audioDeviceConnectionLock) + { + if (_audioDeviceConnectionChanged == value) + { + UnregisterDeviceConnectionChangedEvent(); + } + _audioDeviceConnectionChanged -= value; } - _audioDeviceStateChanged -= value; - Tizen.Log.Info(AudioManagerLog.Tag, "DeviceStateChanged event removed"); } } - /// - /// The VolumeController object (singleton) is-a part of SoundManager and its properties and methods are used via AudioManager - /// - public static AudioVolume VolumeController { get; } + private static void RegisterAudioDeviceEvent() + { + _audioDeviceConnectionChangedCallback = (IntPtr device, bool isConnected, IntPtr userData) => + { + _audioDeviceConnectionChanged?.Invoke(null, + new AudioDeviceConnectionChangedEventArgs(new AudioDevice(device), isConnected)); + }; + + Interop.AudioDevice.AddDeviceConnectionChangedCallback(AudioDeviceOptions.All, + _audioDeviceConnectionChangedCallback, IntPtr.Zero, out _deviceConnectionChangedCallbackId). + Validate("Unable to add device connection changed callback"); + } + + private static void UnregisterDeviceConnectionChangedEvent() + { + Interop.AudioDevice.RemoveDeviceConnectionChangedCallback(_deviceConnectionChangedCallbackId). + Validate("Unable to remove device connection changed callback"); + } + #endregion + + #region DeviceStateChanged event + private static int _deviceStateChangedCallbackId = -1; + + private static Interop.AudioDevice.StateChangedCallback _audioDeviceStateChangedCallback; + private static EventHandler _audioDeviceStateChanged; + private static object _audioDeviceStateLock = new object(); /// - /// Gets the list consisting of all devices currently connected. + /// Occurs when the state of an audio device changes. /// - /// The audio device options - /// The list of connected devices: IEnumerable of Device objects - public static IEnumerable GetCurrentDevices(AudioDeviceOptions options) + public static event EventHandler DeviceStateChanged { - List audioDeviceList = new List(); - IntPtr deviceListHandle; - IntPtr handlePosition; - AudioDeviceIoDirection ioDirection; - - int ret = Interop.AudioDevice.GetCurrentDeviceList(options, out deviceListHandle); - if (ret != (int)AudioManagerError.NoData) - { - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to get next device"); - } - while (ret == (int)AudioManagerError.None) + add { - ret = Interop.AudioDevice.GetNextDevice(deviceListHandle, out handlePosition); - if (ret == (int)AudioManagerError.NoData) + lock (_audioDeviceStateLock) { - break; + if (_audioDeviceStateChanged == null) + { + RegisterDeviceStateChangedEvent(); + } + _audioDeviceStateChanged += value; } - else if (ret != (int)AudioManagerError.None) + } + remove + { + if (value == null) { - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to get next device"); + return; } - if (options == AudioDeviceOptions.Input || (options == AudioDeviceOptions.Output)) + lock (_audioDeviceStateLock) { - ret = Interop.AudioDevice.GetDeviceIoDirection(handlePosition, out ioDirection); - if (ret != 0) + if (_audioDeviceStateChanged == value) { - Tizen.Log.Error(AudioManagerLog.Tag, "Unable to get device IoDirection" + (AudioManagerError)ret); - AudioManagerErrorFactory.CheckAndThrowException(ret, handlePosition, "Unable to get device IO Direction"); - } - else if (ioDirection == AudioDeviceIoDirection.InputAndOutput) - { - continue; + UnregisterDeviceStateChangedEvent(); } + _audioDeviceStateChanged -= value; } - audioDeviceList.Add(new AudioDevice(handlePosition)); } - return audioDeviceList; - } - - private static void RegisterAudioDeviceEvent() - { - _audioDeviceConnectionChangedCallback = (IntPtr device, bool isConnected, IntPtr userData) => - { - AudioDeviceConnectionChangedEventArgs eventArgs = new AudioDeviceConnectionChangedEventArgs(new AudioDevice(device), isConnected); - _audioDeviceConnectionChanged?.Invoke(null, eventArgs); - }; - int ret = Interop.AudioDevice.AddDeviceConnectionChangedCallback(AudioDeviceOptions.All, _audioDeviceConnectionChangedCallback, IntPtr.Zero, out _deviceConnectionChangedCallbackId); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to add device connection changed callback"); - Tizen.Log.Info(AudioManagerLog.Tag, "AudioDeviceConnectionChanged Event registered"); } private static void RegisterDeviceStateChangedEvent() { _audioDeviceStateChangedCallback = (IntPtr device, AudioDeviceState changedState, IntPtr userData) => { - AudioDeviceStateChangedEventArgs eventArgs = new AudioDeviceStateChangedEventArgs(new AudioDevice(device), changedState); - _audioDeviceStateChanged?.Invoke(null, eventArgs); + _audioDeviceStateChanged?.Invoke(null, + new AudioDeviceStateChangedEventArgs(new AudioDevice(device), changedState)); }; - int ret = Interop.AudioDevice.AddDeviceStateChangedCallback(AudioDeviceOptions.All, _audioDeviceStateChangedCallback, IntPtr.Zero, out _deviceStateChangedCallbackId); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to add device state changed callback"); - Tizen.Log.Info(AudioManagerLog.Tag, "AudioDeviceStateChangedEvent callback registered"); - } - private static void UnregisterDeviceConnectionChangedEvent() - { - if (_deviceConnectionChangedCallbackId > 0) - { - int ret = Interop.AudioDevice.RemoveDeviceConnectionChangedCallback(_deviceConnectionChangedCallbackId); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to remove device connection changed callback"); - Tizen.Log.Info(AudioManagerLog.Tag, "AudioDeviceConnectionChangedEvent callback unregistered"); - _deviceConnectionChangedCallbackId = -1; - } + Interop.AudioDevice.AddDeviceStateChangedCallback(AudioDeviceOptions.All, + _audioDeviceStateChangedCallback, IntPtr.Zero, out _deviceStateChangedCallbackId). + Validate("Failed to add device state changed event"); } private static void UnregisterDeviceStateChangedEvent() { - if (_deviceStateChangedCallbackId > 0) - { - int ret = Interop.AudioDevice.RemoveDeviceStateChangedCallback(_deviceStateChangedCallbackId); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to remove device state changed callback"); - Tizen.Log.Info(AudioManagerLog.Tag, "AudioDeviceStateChanged callback unregistered"); - _deviceStateChangedCallbackId = -1; - } + Interop.AudioDevice.RemoveDeviceStateChangedCallback(_deviceStateChangedCallbackId). + Validate("Failed to remove device state changed event"); } + #endregion } } diff --git a/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs b/src/Tizen.Multimedia/AudioManager/AudioManagerEnums.cs old mode 100755 new mode 100644 similarity index 61% rename from src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs rename to src/Tizen.Multimedia/AudioManager/AudioManagerEnums.cs index 6b50ee2..677a0cd --- a/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioManagerEnums.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -15,312 +15,341 @@ */ using System; + namespace Tizen.Multimedia { /// - /// Enumeration for audio device options. + /// Specifies the flag for audio device options. + /// + /// This enumeration has a attribute that allows a bitwise combination of its member values. + /// /// - public enum AudioDeviceOptions + [Flags] + internal enum AudioDeviceOptions { /// - /// Mask for input devices + /// Input devices. /// Input = 0x0001, /// - /// Mask for output devices + /// Output devices. /// Output = 0x0002, /// - /// Mask for input/output devices (both directions are available) + /// Input and output devices (both directions are available). /// InputAndOutput = 0x0004, /// - /// Mask for built-in devices + /// Built-in devices. /// Internal = 0x00010, /// - /// Mask for external devices + /// External devices. /// External = 0x0020, /// - /// Mask for deactivated devices + /// Deactivated devices. /// Deactivated = 0x1000, /// - /// Mask for activated devices + /// Activated devices. /// Activated = 0x2000, + /// - /// Mask for all devices + /// All devices. /// All = 0xFFFF } /// - /// Enumeration for audio device type. + /// Specifies audio device type. /// public enum AudioDeviceType { /// - /// Built-in speaker + /// Built-in speaker. /// BuiltinSpeaker, /// - /// Built-in receiver + /// Built-in receiver. /// BuiltinReceiver, /// - /// Built-in mic + /// Built-in microphone. /// BuiltinMic, /// - /// Audio jack that can be connected to wired accessory such as headphones and headsets + /// Audio jack that can be connected to wired accessory such as headphones and headsets. /// AudioJack, /// - /// Bluetooth Media (A2DP) + /// Bluetooth Media (A2DP). /// BluetoothMedia, /// - /// HDMI + /// HDMI. /// Hdmi, /// - /// Device for forwarding + /// Device for forwarding. /// Forwarding, /// - /// USB Audio + /// USB Audio. /// UsbAudio, /// - /// Bluetooth Voice (SCO) + /// Bluetooth Voice (SCO). /// BluetoothVoice } /// - /// Enumeration for audio device direction. + /// Specifies audio device direction. /// public enum AudioDeviceIoDirection { /// - /// Input device + /// Input device. /// Input, /// - /// Output device + /// Output device. /// Output, /// - /// Input/output device (both directions are available) + /// Input/output device (both directions are available). /// InputAndOutput } /// - /// Enumeration for audio device state. + /// Specifies audio device state. /// public enum AudioDeviceState { /// - /// Deactivated state + /// Deactivated state. /// Deactivated, /// - /// Activated state + /// Activated state. /// Activated } /// - /// Enumeration for audio volume type. + /// Specifies audio volume type. /// public enum AudioVolumeType { /// - /// Volume type for system + /// System. /// System, /// - /// Volume type for notification + /// Notification. /// Notification, /// - /// Volume type for alarm + /// Alarm. /// Alarm, /// - /// Volume type for ringtone + /// Ringtone. /// Ringtone, /// - /// Volume type for media + /// Media. /// Media, /// - /// Volume type for call + /// Call. /// Call, /// - /// Volume type for voip + /// VoIP. /// Voip, /// - /// Volume type for voice + /// Voice. /// Voice, /// - /// Volume type None + /// No volume exists. /// + /// None } /// - /// Enumeration for audio stream type. + /// Specifies audio stream type. /// public enum AudioStreamType { /// - /// Audio stream type for media + /// Media. /// Media, /// - /// Audio stream type for system + /// System. /// System, /// - /// Audio stream type for alarm + /// Alarm. /// Alarm, /// - /// Audio stream type for notification + /// Notification. /// Notification, /// - /// Audio stream type for emergency + /// Emergency. /// Emergency, /// - /// Audio stream type for voice information + /// Voice information. /// VoiceInformation, /// - /// Audio stream type for voice recognition + /// Voice recognition. /// VoiceRecognition, /// - /// Audio stream type for ringtone for VoIP + /// Ringtone for VoIP. /// RingtoneVoip, /// - /// Audio stream type for VoIP + /// VoIP. /// Voip, /// - /// Audio stream type for media only for external devices + /// Media only for external devices. /// MediaExternalOnly } /// - /// Enumeration for change reason of audio stream focus state. + /// Specifies change reason of audio stream focus state. /// public enum AudioStreamFocusChangedReason { /// - /// Changed by the stream type for media + /// Media. /// Media, /// - /// Changed by the stream type for system + /// System. /// System, /// - /// Changed by the stream type for alarm + /// Alarm. /// Alarm, /// - /// Changed by the stream type for notification + /// Notification. /// Notification, /// - /// Changed by the stream type for emergency + /// Emergency. /// Emergency, /// - /// Changed by the stream type for voice information + /// Voice information. /// VoiceInformation, /// - /// Changed by the stream type for voice recognition + /// Voice recognition. /// VoiceRecognition, /// - /// Changed by the stream type for ringtone + /// Ringtone. /// RingtoneVoip, /// - /// Changed by the stream type for VoIP + /// VoIP. /// Voip, /// - /// Changed by the stream type for voice-call or video-call + /// Voice-call or video-call. /// Call, /// - /// Changed by the stream type for media only for external devices + /// Media only for external devices. /// MediaExternalOnly } /// - /// Enumeration for audio stream focus options. + /// Specifies the flag for audio stream focus options. + /// + /// This enumeration has a attribute that allows a bitwise combination of its member values. + /// /// + [Flags] public enum AudioStreamFocusOptions { /// - /// Mask for playback focus + /// Playback focus. /// Playback = 0x0001, /// - /// Mask for recording focus + /// Recording focus. /// Recording = 0x0002 } /// - /// Enumeration for audio stream focus state. + /// Specifies audio stream focus state. /// public enum AudioStreamFocusState { /// - /// Focus state for release + /// Focus state for release. /// Released, /// - ///Focus state for acquisition + /// Focus state for acquisition. /// Acquired } /// - /// Enumeration for audio stream behavior + /// Specifies the flag for audio stream behaviors. + /// + /// This enumeration has a attribute that allows a bitwise combination of its member values. + /// /// [Flags] - public enum AudioStreamBehavior + public enum AudioStreamBehaviors { /// - /// Audio Stream Behavior NONE - /// - None = 0x0000, - /// - /// Audio Stream Behavior No Resume + /// No Resume. /// NoResume = 0x0001, /// - /// Audio Stream Behavior Fading + /// Fading. /// Fading = 0x0002 } + + + internal static class AudioManagerEnumExtensions + { + internal static bool IsValid(this AudioStreamFocusOptions value) + { + int mask = (int)(AudioStreamFocusOptions.Playback | AudioStreamFocusOptions.Recording); + + return (mask & (int)value) != 0; + } + + internal static bool IsValid(this AudioStreamBehaviors value) + { + int mask = (int)(AudioStreamBehaviors.NoResume | AudioStreamBehaviors.Fading); + + return ((~mask) & (int)value) == 0; + } + } + } diff --git a/src/Tizen.Multimedia/AudioManager/AudioManagerErrorFactory.cs b/src/Tizen.Multimedia/AudioManager/AudioManagerError.cs similarity index 62% rename from src/Tizen.Multimedia/AudioManager/AudioManagerErrorFactory.cs rename to src/Tizen.Multimedia/AudioManager/AudioManagerError.cs index 22fba2f..f990248 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioManagerErrorFactory.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioManagerError.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -19,11 +19,8 @@ using Tizen.Internals.Errors; namespace Tizen.Multimedia { - /// - /// Enumeration for sound manager's error codes. - /// - internal enum AudioManagerError{ - + internal enum AudioManagerError + { SoundManagerError = -0x01960000, /// /// Successful @@ -71,49 +68,47 @@ namespace Tizen.Multimedia InvalidState = SoundManagerError | 04 } - internal static class AudioManagerErrorFactory + internal static class AudioManagerErrorExtensions { - static internal void CheckAndThrowException(int error, string msg) + internal static void Validate(this AudioManagerError err, string msg) { - AudioManagerError e = (AudioManagerError) error; - switch (e) + if (err == AudioManagerError.None) + { + return; + } + + msg = msg ?? ""; + msg += $" : {err}."; + + switch (err) { - case AudioManagerError.None: - return; case AudioManagerError.OutOfMemory: - throw new InvalidOperationException("Out of Memory: " + msg); + throw new OutOfMemoryException(msg); + case AudioManagerError.InvalidParameter: - throw new ArgumentException("Invalid Parameter: " + msg); - case AudioManagerError.InvalidOperation: - throw new InvalidOperationException("Invalid Opertation: " + msg); + throw new ArgumentException(msg); + case AudioManagerError.PermissionDenied: - throw new InvalidOperationException("Permission Denied: " + msg); + throw new UnauthorizedAccessException(msg); + case AudioManagerError.NotSupported: - throw new InvalidOperationException("Not Supported: " + msg); + throw new NotSupportedException(msg); + + case AudioManagerError.Policy: + throw new AudioPolicyException(msg); + case AudioManagerError.NoData: - throw new InvalidOperationException("No Data: " + msg); + // TODO check when it is thrown + throw new InvalidOperationException(msg); + case AudioManagerError.Internal: - throw new InvalidOperationException("Internal Error: " + msg); - case AudioManagerError.Policy: - throw new InvalidOperationException("Noncomplaince with System Sound Policy error: " + msg); + case AudioManagerError.InvalidOperation: case AudioManagerError.NoPlayingSound: - throw new InvalidOperationException("No playing sound: " + msg); case AudioManagerError.InvalidState: - throw new InvalidOperationException("Invalid State: " + msg); - default: - throw new InvalidOperationException("Unknown Error Code: " + msg); - } - } + throw new InvalidOperationException(msg); - static internal void CheckAndThrowException(int error, IntPtr handle, string msg) - { - if (handle == IntPtr.Zero) - { - throw new InvalidOperationException("Invalid instance (object may have been disposed or released)"); - } - else - { - CheckAndThrowException(error, msg); + default: + throw new InvalidOperationException("Unknown Error : " + msg); } } } diff --git a/src/Tizen.Multimedia/AudioManager/AudioPolicyException.cs b/src/Tizen.Multimedia/AudioManager/AudioPolicyException.cs new file mode 100644 index 0000000..b0d4890 --- /dev/null +++ b/src/Tizen.Multimedia/AudioManager/AudioPolicyException.cs @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Multimedia +{ + /// + /// The exception that is thrown when noncompliance with the sound system policy happens. + /// + public class AudioPolicyException : InvalidOperationException + { + /// + /// Initializes a new instance of the class. + /// + public AudioPolicyException() + { + } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// The error message that explains the reason for the exception. + public AudioPolicyException(string message) : base(message) + { + } + + /// + /// Initializes a new instance of the class with a specified error message and inner exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception.. + public AudioPolicyException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs b/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs index b914c9c..f82dfb4 100755 --- a/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -15,320 +15,318 @@ */ using System; +using System.Diagnostics; namespace Tizen.Multimedia { - internal static class AudioStreamPolicyLog - { - internal const string Tag = "Tizen.Multimedia.AudioStreamPolicy"; - } - /// - /// The Stream Policy API provides functions to control a sound stream. + /// Provides the ability to control a sound stream. /// public class AudioStreamPolicy : IDisposable { - private static int _focusStateWatchCounter = 0; - private static EventHandler _focusStateWatchForPlayback; - private static EventHandler _focusStateWatchForRecording; - private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchCallback; - private static int _focusWatchCbId; - - private IntPtr _streamInfo; - private AudioStreamType _streamType; + private AudioStreamPolicyHandle _handle; private bool _disposed = false; - private EventHandler _focusStateChanged; - private Interop.SoundStreamFocusStateChangedCallback _focusStateChangedCallback; + private Interop.AudioStreamPolicy.FocusStateChangedCallback _focusStateChangedCallback; /// - /// Creates and returns an AudioStreamPolicy object + /// Initializes a new instance of the class with /// /// - /// To apply the stream policy according to this stream information, this object should be passed to other APIs - /// related to playback or recording. (e.g., player, wav-player, audio-io, etc.) + /// To apply the stream policy according to this stream information, the AudioStreamPolicy should + /// be passed to other APIs related to playback or recording. (e.g., , , etc.) /// - /// Type of sound stream for which policy needs to be created - /// StreamPolicy object + /// Type of sound stream for which policy needs to be created. public AudioStreamPolicy(AudioStreamType streamType) { - _streamType = streamType; + ValidationUtil.ValidateEnum(typeof(AudioStreamType), streamType, nameof(streamType)); - _focusStateChangedCallback = (IntPtr streamInfo, AudioStreamFocusOptions focusMask, AudioStreamFocusState focusState, int reason, int audioStreamBehavior, string extraInfo, IntPtr userData) => { - StreamFocusStateChangedEventArgs eventArgs = new StreamFocusStateChangedEventArgs((AudioStreamFocusChangedReason)reason, extraInfo); - _focusStateChanged?.Invoke(this, eventArgs); + _focusStateChangedCallback = (IntPtr streamInfo, AudioStreamFocusOptions focusMask, + AudioStreamFocusState state, AudioStreamFocusChangedReason reason, AudioStreamBehaviors behaviors, + string extraInfo, IntPtr userData) => + { + FocusStateChanged?.Invoke(this, + new AudioStreamPolicyFocusStateChangedEventArgs(focusMask, state, reason, behaviors, extraInfo)); }; - int ret = Interop.AudioStreamPolicy.CreateStreamInformation((int)streamType, _focusStateChangedCallback, IntPtr.Zero, out _streamInfo); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to create stream information"); - } - ~AudioStreamPolicy() - { - Dispose(false); - } + Interop.AudioStreamPolicy.Create(streamType, _focusStateChangedCallback, + IntPtr.Zero, out _handle).Validate("Unable to create stream information"); - /// - /// Registers the watch function to be invoked when the focus state for each sound stream type is changed regardless of the process. - /// - /// Remarks: You can set this only once per process. - /// - /// - public static event EventHandler PlaybackFocusStateWatch { - add { - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "############# _focusStateWatchCounter" + _focusStateWatchCounter); - if(_focusStateWatchCounter == 0) { - RegisterFocusStateWatchEvent(); - } - _focusStateWatchCounter++; - _focusStateWatchForPlayback += value; - } - remove { - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "############# _focusStateWatchCounter" + _focusStateWatchCounter); - _focusStateWatchForPlayback -= value; - _focusStateWatchCounter--; - if(_focusStateWatchCounter == 0) { - UnregisterFocusStateWatch(); - } - } + Debug.Assert(_handle != null); } /// - /// Registers the watch function to be invoked when the focus state for each sound stream type is changed regardless of the process. + /// Occurs when the state of focus that belongs to the current AudioStreamPolicy is changed. + /// /// - /// Remarks: You can set this only once per process. + /// The event is raised in the internal thread. /// - /// - public static event EventHandler RecordingFocusStateWatch { - add { - if(_focusStateWatchCounter == 0) { - RegisterFocusStateWatchEvent(); - } - _focusStateWatchCounter++; - _focusStateWatchForRecording += value; - } - remove { - _focusStateWatchForRecording -= value; - _focusStateWatchCounter--; - if(_focusStateWatchCounter == 0) { - UnregisterFocusStateWatch(); - } - } - } + public event EventHandler FocusStateChanged; /// - /// Registers function to be called when the state of focus that belongs to the current - /// streamInfo is changed. + /// Gets the . /// /// - /// Remarks: This function is issued in the internal thread of the sound manager. Therefore it is recommended not to call UI update function in this function. - /// Postcondition : Check PlaybackFocusState and RecordingFocusState in the registered event handler to figure out how the focus state of the StreamInfo has been changed. + /// If the of the current AudioStreamPolicy is , + /// it returns . /// - public event EventHandler StreamFocusStateChanged { - add { - _focusStateChanged += value; - } - remove { - _focusStateChanged -= value; - } - } - - /// - /// The sound type of the stream information. - /// - public AudioVolumeType VolumeType { - get { - AudioVolumeType soundType; - int ret = Interop.AudioStreamPolicy.GetSoundType(_streamInfo, out soundType); - if(ret != 0) { - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Unable to get sound type:" + (AudioManagerError)ret); + /// The of the policy instance. + public AudioVolumeType VolumeType + { + get + { + AudioVolumeType type; + var ret = Interop.AudioStreamPolicy.GetSoundType(Handle, out type); + if (ret == AudioManagerError.NoData) + { return AudioVolumeType.None; } - return soundType; + + ret.Validate("Failed to get volume type"); + + return type; } } + private AudioStreamFocusState GetFocusState(bool playback) + { + int ret = Interop.AudioStreamPolicy.GetFocusState(Handle, out var stateForPlayback, out var stateForRecording); + MultimediaDebug.AssertNoError(ret); + + return playback ? stateForPlayback : stateForRecording; + } + /// - /// The state of focus for playback. + /// Gets the state of focus for playback. /// - public AudioStreamFocusState PlaybackFocusState { - get { - AudioStreamFocusState stateForPlayback; - AudioStreamFocusState stateForRecording; - int ret = Interop.AudioStreamPolicy.GetFocusState(_streamInfo, out stateForPlayback, out stateForRecording); - if(ret != 0) { - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Unable to get focus state" + (AudioManagerError)ret); - return AudioStreamFocusState.Released; - } - return stateForPlayback; - } - } + /// The state of focus for playback. + public AudioStreamFocusState PlaybackFocusState => GetFocusState(true); /// - /// The state of focus for recording. + /// Gets the state of focus for recording. /// - public AudioStreamFocusState RecordingFocusState { - get { - AudioStreamFocusState stateForPlayback; - AudioStreamFocusState stateForRecording; - int ret = Interop.AudioStreamPolicy.GetFocusState(_streamInfo, out stateForPlayback, out stateForRecording); - if(ret != 0) { - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Unable to get focus state" + (AudioManagerError)ret); - return AudioStreamFocusState.Released; - } - return stateForRecording; - } - } + /// The state of focus for recording. + public AudioStreamFocusState RecordingFocusState => GetFocusState(false); /// - /// Auto focus reacquisition property + /// Gets or sets the auto focus reacquisition. /// + /// + /// true if the auto focus reacquisition is enabled; otherwise, false.\n + /// The default is true. + /// /// - /// The focus reacquistion is set as default. If you don't want to reacquire the focus you've lost automatically, disable the focus reacqusition setting by using this API and vice versa. + /// If you don't want to reacquire the focus you've lost automatically, + /// disable the focus reacquisition. /// - public bool FocusReacquisitionEnabled { - get { - bool enabled; - int ret = Interop.AudioStreamPolicy.GetFocusReacquisition(_streamInfo, out enabled); - if(ret != 0) { - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Unable to get focus reacquisition" + (AudioManagerError)ret); - return true; - } + public bool FocusReacquisitionEnabled + { + get + { + Interop.AudioStreamPolicy.GetFocusReacquisition(Handle, out var enabled). + Validate("Failed to get focus reacquisition state"); + return enabled; } - set { - int ret = Interop.AudioStreamPolicy.SetFocusReacquisition(_streamInfo, value); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set focus reacquisition"); + set + { + Interop.AudioStreamPolicy.SetFocusReacquisition(Handle, value). + Validate("Failed to set focus reacquisition"); } } - public IntPtr Handle { - get { - return _streamInfo; + internal AudioStreamPolicyHandle Handle + { + get + { + if (_disposed) + { + throw new ObjectDisposedException(nameof(AudioStreamPolicy)); + } + return _handle; } } /// /// Acquires the stream focus. /// - /// The focus mask that user wants to acquire - /// The required action for releaser - /// The Extra information for this request (optional, this can be null) - /// - /// Do not call this API within event handlers of FocuStateChanged and StreamFocusStateWatch else it will throw and exception - /// - public void AcquireFocus(AudioStreamFocusOptions options, AudioStreamBehavior audioStreamBehavior, string extraInformation) + /// The focuses that you want to acquire. + /// The requesting behaviors. + /// The extra information for this request. This value can be null. + public void AcquireFocus(AudioStreamFocusOptions options, AudioStreamBehaviors behaviors, string extraInfo) { - int ret = Interop.AudioStreamPolicy.AcquireFocus(_streamInfo, options, (int)audioStreamBehavior, extraInformation); - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Acquire focus return: " + ret); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to acquire focus"); + if (options == 0) + { + throw new ArgumentException("options can't be zero.", nameof(options)); + } + + if (options.IsValid() == false) + { + throw new ArgumentOutOfRangeException(nameof(options), options, "options contains a invalid bit."); + } + + if (behaviors.IsValid() == false) + { + throw new ArgumentOutOfRangeException(nameof(behaviors), behaviors, "behaviors contains a invalid bit."); + } + + Interop.AudioStreamPolicy.AcquireFocus(Handle, options, behaviors, extraInfo). + Validate("Failed to acquire focus"); } /// /// Releases the acquired focus. /// - /// The focus mask that user wants to release - /// The required action for acquirer - /// he Extra information for this request (optional, this can be null) - /// - /// Do not call this API within event handlers of FocuStateChanged and StreamFocusStateWatch else it will throw and exception - /// - public void ReleaseFocus(AudioStreamFocusOptions options, AudioStreamBehavior audioStreamBehavior, string extraInformation) + /// The focus mask that you want to release. + /// The requesting behaviors. + /// The extra information for this request. This value can be null. + public void ReleaseFocus(AudioStreamFocusOptions options, AudioStreamBehaviors behaviors, string extraInfo) { - int ret = Interop.AudioStreamPolicy.ReleaseFocus(_streamInfo, options, (int)audioStreamBehavior, extraInformation); - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Release focus return: " + ret); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to release focus"); + if (options == 0) + { + throw new ArgumentException("options can't be zero.", nameof(options)); + } + + if (options.IsValid() == false) + { + throw new ArgumentOutOfRangeException(nameof(options), options, "options contains a invalid bit."); + } + + if (behaviors.IsValid() == false) + { + throw new ArgumentOutOfRangeException(nameof(behaviors), behaviors, "behaviors contains a invalid bit."); + } + + Interop.AudioStreamPolicy.ReleaseFocus(Handle, options, behaviors, extraInfo). + Validate("Failed to release focus"); } /// /// Applies the stream routing. /// /// - /// If the stream has not been made yet, this setting will be applied when the stream starts to play. - /// Precondition: Call AddDeviceForStreamRouting() before calling this function. + /// If the stream has not been made yet, this will be applied when the stream starts to play. /// + /// + /// public void ApplyStreamRouting() { - int ret = Interop.AudioStreamPolicy.ApplyStreamRouting(_streamInfo); - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Apply Routing: " + (AudioManagerError)ret); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to apply stream routing"); + Interop.AudioStreamPolicy.ApplyStreamRouting(Handle).Validate("Failed to apply stream routing"); } /// - /// Adds the device to the stream information for the stream routing. + /// Adds a device for the stream routing. /// + /// The device to add. /// - /// Remarks: Use SoundManager.GetCurrentDeviceList() to get the device. - /// The available types of the StreamInfo for this API are SoundStreamTypeVoip and SoundStreamTypeMediaExternalOnly. - /// Postcondition: You can apply this setting by calling ApplyStreamRouting(). + /// The available is and . /// - /// The device item from the current sound devices list. - public void AddDeviceForStreamRouting(AudioDevice soundDevice) + /// + /// + public void AddDeviceForStreamRouting(AudioDevice device) { - int ret = Interop.AudioStreamPolicy.AddDeviceForStreamRouting(_streamInfo, soundDevice.Handle); - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Add stream routing: " + (AudioManagerError)ret); + if (device == null) + { + throw new ArgumentNullException(nameof(device)); + } + var ret = Interop.AudioStreamPolicy.AddDeviceForStreamRouting(Handle, device.Id); + + if (ret == AudioManagerError.NoData) + { + throw new ArgumentException("The device seems not connected.", nameof(device)); + } - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to add device for stream routing"); + ret.Validate("Failed to add device for stream routing"); } /// - /// Removes the device to the stream information for the stream routing. + /// Removes the device for the stream routing. /// + /// The device to remove. /// - /// Remarks: Use SoundManager.GetCurrentDeviceList() to get the device. - /// The available types of the StreamInfo for this API are SoundStreamTypeVoip and SoundStreamTypeMediaExternalOnly. - /// Postcondition: You can apply this setting by calling ApplyStreamRouting(). + /// The available is and . /// - /// The device item from the current sound devices list. - public void RemoveDeviceForStreamRouting(AudioDevice soundDevice) + public void RemoveDeviceForStreamRouting(AudioDevice device) { - int ret = Interop.AudioStreamPolicy.RemoveDeviceForStreamRouting(_streamInfo, soundDevice.Handle); - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "Remove stream routing: " + (AudioManagerError)ret); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to remove device for stream routing"); + if (device == null) + { + throw new ArgumentNullException(nameof(device)); + } + + Interop.AudioStreamPolicy.RemoveDeviceForStreamRouting(Handle, device.Id). + Validate("Failed to remove device for stream routing"); } + /// + /// Releases all resources used by the . + /// public void Dispose() { Dispose(true); - GC.SuppressFinalize(this); } + /// + /// Releases the unmanaged resources used by the . + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. protected virtual void Dispose(bool disposing) { - if(!_disposed) { - if(disposing) { - // to be used if there are any other disposable objects - } - if(_streamInfo != IntPtr.Zero) { - Interop.AudioStreamPolicy.DestroyStreamInformation(_streamInfo); // Destroy the handle - _streamInfo = IntPtr.Zero; + if (!_disposed) + { + if (_handle != null) + { + _handle.Dispose(); } _disposed = true; } } - private static void RegisterFocusStateWatchEvent() + #region Static events + + private static bool _isWatchCallbackRegistered; + private static EventHandler _streamFocusStateChanged; + private static Interop.AudioStreamPolicy.FocusStateWatchCallback _focusStateWatchCallback; + private static object _streamFocusEventLock = new object(); + + /// + /// Occurs when the focus state for stream types is changed regardless of the process. + /// + public static event EventHandler StreamFocusStateChanged { - _focusStateWatchCallback = (int id, AudioStreamFocusOptions options, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData) => { - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "############# _Inside _focusStateWatchCallback : id = " + id + "options = " + options); - FocusStateChangedEventArgs eventArgs = new FocusStateChangedEventArgs(focusState, reason, extraInfo); - if(options == AudioStreamFocusOptions.Playback) { - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "############# _eventArgs = " + eventArgs); - _focusStateWatchForPlayback?.Invoke(null, eventArgs); - } else if(options == AudioStreamFocusOptions.Recording) { - _focusStateWatchForRecording?.Invoke(null, eventArgs); - } else if(options == (AudioStreamFocusOptions.Playback | AudioStreamFocusOptions.Recording)) { - _focusStateWatchForPlayback?.Invoke(null, eventArgs); - _focusStateWatchForRecording?.Invoke(null, eventArgs); + add + { + lock (_streamFocusEventLock) + { + if (_isWatchCallbackRegistered == false) + { + RegisterFocusStateWatch(); + _isWatchCallbackRegistered = true; + } + _streamFocusStateChanged += value; } - }; - int ret = Interop.AudioStreamPolicy.AddFocusStateWatchCallback(AudioStreamFocusOptions.Playback | AudioStreamFocusOptions.Recording, _focusStateWatchCallback, IntPtr.Zero, out _focusWatchCbId); - Tizen.Log.Info(AudioStreamPolicyLog.Tag, "############# _AddFocusStateWatchCallback : ret = " + ret + " ID = " + _focusWatchCbId); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set focus state watch callback"); + } + remove + { + lock (_streamFocusEventLock) + { + _streamFocusStateChanged -= value; + } + } } - private static void UnregisterFocusStateWatch() + private static void RegisterFocusStateWatch() { - int ret = Interop.AudioStreamPolicy.RemoveFocusStateWatchCallback(_focusWatchCbId); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset focus state watch callback"); + _focusStateWatchCallback = (int id, AudioStreamFocusOptions options, AudioStreamFocusState focusState, + AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData) => + { + _streamFocusStateChanged?.Invoke(null, + new StreamFocusStateChangedEventArgs(options, focusState, reason, extraInfo)); + }; + + Interop.AudioStreamPolicy.AddFocusStateWatchCallback( + AudioStreamFocusOptions.Playback | AudioStreamFocusOptions.Recording, + _focusStateWatchCallback, IntPtr.Zero, out var cbId). + Validate("Failed to initialize focus state event"); } + #endregion } } diff --git a/src/Tizen.Multimedia/AudioManager/AudioStreamPolicyFocusStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioStreamPolicyFocusStateChangedEventArgs.cs new file mode 100644 index 0000000..c8b3e70 --- /dev/null +++ b/src/Tizen.Multimedia/AudioManager/AudioStreamPolicyFocusStateChangedEventArgs.cs @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Multimedia +{ + /// + /// Provides data for the event. + /// + public class AudioStreamPolicyFocusStateChangedEventArgs : EventArgs + { + internal AudioStreamPolicyFocusStateChangedEventArgs(AudioStreamFocusOptions options, + AudioStreamFocusState state, AudioStreamFocusChangedReason reason, + AudioStreamBehaviors behaviors, string extraInfo) + { + FocusOptions = options; + FocusState = state; + Reason = reason; + Behaviors = behaviors; + ExtraInfo = extraInfo; + } + + /// + /// Gets the focus options. + /// + /// The focus options. + public AudioStreamFocusOptions FocusOptions { get; } + + /// + /// Gets the focus state. + /// + /// The focus state. + public AudioStreamFocusState FocusState { get; } + + /// + /// Gets the reason for state change of the focus. + /// + /// The reason for state change of the focus. + public AudioStreamFocusChangedReason Reason { get; } + + /// + /// Gets the requested behaviors that should be followed + /// + /// The requested behaviors that should be followed. + public AudioStreamBehaviors Behaviors { get; } + + /// + /// Gets the extra information. + /// + /// + /// The extra information specified in or + /// . + /// + /// + /// + public string ExtraInfo { get; } + } +} diff --git a/src/Tizen.Multimedia/AudioManager/AudioVolume.cs b/src/Tizen.Multimedia/AudioManager/AudioVolume.cs index d87eab2..3ca2057 100755 --- a/src/Tizen.Multimedia/AudioManager/AudioVolume.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioVolume.cs @@ -1,36 +1,36 @@ - /* - * 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; namespace Tizen.Multimedia { - internal static class AudioVolumeLog - { - internal const string Tag = "Tizen.Multimedia.AudioVolume"; - } - /// - /// The AudioVolume API provides functions to check and control volumes. + /// Provides the ability to control the volume levels. /// + /// public class AudioVolume { - private static int _volumeChangedCallbackId = -1; + private const string Tag = "Tizen.Multimedia.AudioVolume"; + + private int _volumeChangedCallbackId = -1; private EventHandler _volumeChanged; - private Interop.SoundManagerVolumeChangedCallback _volumeChangedCallback; + private Interop.AudioVolume.VolumeChangedCallback _volumeChangedCallback; + + private object _eventLock = new object(); internal AudioVolume() { @@ -39,69 +39,87 @@ namespace Tizen.Multimedia } /// - /// Registers a function to be invoked when the volume level is changed. + /// Occurs when the volume level is changed. /// - public event EventHandler Changed { - add { - Tizen.Log.Info(AudioVolumeLog.Tag, "VolumeController Changed Event added...."); - if(_volumeChanged == null) { - RegisterVolumeChangedEvent(); + public event EventHandler Changed + { + add + { + lock (_eventLock) + { + if (_volumeChanged == null) + { + RegisterVolumeChangedEvent(); + } + _volumeChanged += value; } - _volumeChanged += value; } - remove { - Tizen.Log.Info(AudioVolumeLog.Tag, "VolumeController Changed Event removed...."); - if(_volumeChanged?.GetInvocationList()?.GetLength(0) == 1) { - UnregisterVolumeChangedEvent(); + remove + { + if (value == null) + { + return; + } + + lock (_eventLock) + { + if (_volumeChanged == value) + { + UnregisterVolumeChangedEvent(); + } + _volumeChanged -= value; } - _volumeChanged -= value; } } /// - /// The Audio Manager has predefined volume types.(system, notification, alarm, ringtone, media, call, voip, voice). - /// The volume type of the sound being currently played. + /// Gets the volume type of the sound being currently played. /// - public AudioVolumeType CurrentPlaybackType { - get { - AudioVolumeType currentType; - int ret = Interop.AudioVolume.GetCurrentSoundType(out currentType); - if(ret != 0) { - Tizen.Log.Info(AudioVolumeLog.Tag, "Unable to get current playback sound type" + (AudioManagerError)ret); + /// The volume type of the sound being currently played. + public AudioVolumeType CurrentPlaybackType + { + get + { + var ret = Interop.AudioVolume.GetCurrentSoundType(out var currentType); + if (ret == AudioManagerError.NoPlayingSound) + { return AudioVolumeType.None; } + ret.Validate("Failed to get current volume type"); + return currentType; } } /// - /// The indexer class which is used to get/set volume level specified for a particular sound type. + /// Gets the . /// - public VolumeLevel Level; + /// The . + public VolumeLevel Level { get; } /// - /// The indexer class which is used to get maximum volume level supported for a particular sound type. + /// Gets the . /// - public MaxVolumeLevel MaxLevel; + /// The . + public MaxVolumeLevel MaxLevel { get; } private void RegisterVolumeChangedEvent() { - _volumeChangedCallback = (AudioVolumeType type, uint volume, IntPtr userData) => { - VolumeChangedEventArgs eventArgs = new VolumeChangedEventArgs(type, volume); - _volumeChanged.Invoke(this, eventArgs); + _volumeChangedCallback = (AudioVolumeType type, uint volume, IntPtr userData) => + { + _volumeChanged?.Invoke(this, new VolumeChangedEventArgs(type, volume)); }; - int error = Interop.AudioVolume.AddVolumeChangedCallback(_volumeChangedCallback, IntPtr.Zero, out _volumeChangedCallbackId); - Tizen.Log.Info(AudioVolumeLog.Tag, "VolumeController Add Changed Event return id:" + _volumeChangedCallbackId + "error:" + error); - AudioManagerErrorFactory.CheckAndThrowException(error, "unable to add level changed callback"); + var error = Interop.AudioVolume.AddVolumeChangedCallback(_volumeChangedCallback, IntPtr.Zero, + out _volumeChangedCallbackId); + Log.Info(Tag, $"VolumeController callback id:{_volumeChangedCallbackId}"); + + error.Validate("Failed to add volume changed event"); } private void UnregisterVolumeChangedEvent() { - if (_volumeChangedCallbackId > 0) { - int error = Interop.AudioVolume.RemoveVolumeChangedCallback(_volumeChangedCallbackId); - Tizen.Log.Info(AudioVolumeLog.Tag, "VolumeController Remove Changed Event(id:" + _volumeChangedCallbackId + ") return error: " + error); - AudioManagerErrorFactory.CheckAndThrowException(error, "unable to remove level changed callback"); - } + Interop.AudioVolume.RemoveVolumeChangedCallback(_volumeChangedCallbackId). + Validate("Failed to remove volume changed event"); } } } diff --git a/src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs deleted file mode 100644 index cf17aae..0000000 --- a/src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs +++ /dev/null @@ -1,48 +0,0 @@ - /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; - -namespace Tizen.Multimedia -{ - /// - /// Class extending EventArgs and contains the necessary parameters to passed to FocusStateWatch event handler - /// - public class FocusStateChangedEventArgs : EventArgs - { - internal FocusStateChangedEventArgs(AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInformation) - { - FocusState = focusState; - FocusChangedReason = reason; - ExtraInformation = extraInformation; - } - - /// - /// The changed focus state - /// - public AudioStreamFocusState FocusState { get; } - - /// - /// The reason for state change of the focus - /// - public AudioStreamFocusChangedReason FocusChangedReason { get; } - - /// - /// The extra information - /// - public string ExtraInformation { get; } - } -} diff --git a/src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs b/src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs index 5e1ed72..931d9c1 100644 --- a/src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs +++ b/src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -18,29 +18,39 @@ using System; namespace Tizen.Multimedia { - internal static class MaxVolumeLog - { - internal const string Tag = "Tizen.Multimedia.MaxVolume"; - } - /// - /// This is a indexer class which is used to get the maximum volume level - /// supported for a particular sound type. + /// Provides a means to get max volume levels. /// public class MaxVolumeLevel { - public int this [AudioVolumeType type] { - get { - if(type == AudioVolumeType.None) - throw new ArgumentException("Wrong Audio volume type. Cannot get max volume level for AudioVolumeType.None"); - int maxVolume; - int ret = Interop.AudioVolume.GetMaxVolume(type, out maxVolume); - if(ret != 0) { - Tizen.Log.Info(MaxVolumeLog.Tag, "Max Level Error: " + (AudioManagerError)ret); - return -1; + internal MaxVolumeLevel() + { + } + + /// + /// Gets the max volume level of the specified + /// + /// The to query. + /// The maximum volume level. + /// is invalid. + /// is . + public int this[AudioVolumeType type] + { + get + { + ValidationUtil.ValidateEnum(typeof(AudioVolumeType), type, nameof(type)); + + if (type == AudioVolumeType.None) + { + throw new ArgumentOutOfRangeException(nameof(type), + "Cannot get max volume level for AudioVolumeType.None"); } + + Interop.AudioVolume.GetMaxVolume(type, out var maxVolume). + Validate("Failed to get the max volume level"); + return maxVolume; } } } -} \ No newline at end of file +} diff --git a/src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs index 225cbe4..fc00e92 100755 --- a/src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -19,25 +19,46 @@ using System; namespace Tizen.Multimedia { /// - /// Class extending EventArgs and contains the necessary parameters to passed to FocusStateChanged event handler + /// Provides data for the event. /// public class StreamFocusStateChangedEventArgs : EventArgs { - /* FIXME */ - internal StreamFocusStateChangedEventArgs(AudioStreamFocusChangedReason reason, string extraInformation) + internal StreamFocusStateChangedEventArgs(AudioStreamFocusOptions options, + AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo) { - FocusChangedReason = reason; - ExtraInformation = extraInformation; + FocusOptions = options; + FocusState = focusState; + Reason = reason; + ExtraInfo = extraInfo; } /// - /// The reason for state change of the focus + /// Gets the focus options. /// - public AudioStreamFocusChangedReason FocusChangedReason { get; } + /// The focus options. + public AudioStreamFocusOptions FocusOptions { get; } /// - /// The extra information + /// Gets the changed focus state. /// - public string ExtraInformation { get; } + /// The focus state. + public AudioStreamFocusState FocusState { get; } + + /// + /// Gets the reason for state change of the focus. + /// + /// The reason for state change of the focus. + public AudioStreamFocusChangedReason Reason { get; } + + /// + /// Gets the extra information. + /// + /// + /// The extra information specified in or + /// . + /// + /// + /// + public string ExtraInfo { get; } } } diff --git a/src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs index 1643976..f35481a 100755 --- a/src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -19,24 +19,26 @@ using System; namespace Tizen.Multimedia { /// - /// Extnded EventArgs which contains the parameteres to be passed to the AudioVolume Changed event + /// Provides data for the event. /// public class VolumeChangedEventArgs : EventArgs { internal VolumeChangedEventArgs(AudioVolumeType type, uint level) { Type = type; - Level = level; + Level = (int)level; } /// - /// The sound type of the changed volume + /// Gets the sound type that volume is changed. /// + /// The sound type that volume is changed. public AudioVolumeType Type { get; } /// - /// The new volume value + /// Gets the new volume. /// - public uint Level { get; } + /// The new volume level. + public int Level { get; } } } diff --git a/src/Tizen.Multimedia/AudioManager/VolumeLevel.cs b/src/Tizen.Multimedia/AudioManager/VolumeLevel.cs index a4aeaed..47cb155 100644 --- a/src/Tizen.Multimedia/AudioManager/VolumeLevel.cs +++ b/src/Tizen.Multimedia/AudioManager/VolumeLevel.cs @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -18,38 +18,68 @@ using System; namespace Tizen.Multimedia { - internal static class VolumeLevelLog - { - internal const string Tag = "Tizen.Multimedia.VolumeLevel"; - } /// - /// This is a indexer class which is used to get/set the volume level - /// specified for a particular sound type. + /// Provides a means to control volume levels. /// public class VolumeLevel { - public int this [AudioVolumeType type] { - get { - if(type == AudioVolumeType.None) - throw new ArgumentException("Wrong Audio volume type. Cannot get volume level for AudioVolumeType.None"); - int volume; - int ret = Interop.AudioVolume.GetVolume(type, out volume); - if(ret != 0) { - Tizen.Log.Info(VolumeLevelLog.Tag, "Get Level Error: " + (AudioManagerError)ret); - return -1; + internal VolumeLevel() + { + } + + /// + /// Gets or sets the volume level of the specified + /// + /// The to control. + /// The current volume level. + /// To set volumes, the specified privilege is required. + /// http://tizen.org/privilege/volume.set + /// is invalid. + /// + /// is . + /// -or- + /// is less than zero. + /// -or- + /// is greater than . + /// + /// Caller does not have required privilege to set volume. + public int this[AudioVolumeType type] + { + get + { + ValidationUtil.ValidateEnum(typeof(AudioVolumeType), type, nameof(type)); + + if (type == AudioVolumeType.None) + { + throw new ArgumentOutOfRangeException(nameof(type), + "Cannot get volume level for AudioVolumeType.None"); } + + Interop.AudioVolume.GetVolume(type, out var volume).Validate("Failed to get the volume level"); + return volume; } - set { - if(type == AudioVolumeType.None) - throw new ArgumentException("Wrong Audio volume type. Cannot set volume level for AudioVolumeType.None"); - int ret = Interop.AudioVolume.SetVolume(type, value); - if(ret != 0) { - Tizen.Log.Info(VolumeLevelLog.Tag, "Set Level Error: " + (AudioManagerError)ret); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set level"); + set + { + ValidationUtil.ValidateEnum(typeof(AudioVolumeType), type, nameof(value)); + + if (type == AudioVolumeType.None) + { + throw new ArgumentOutOfRangeException(nameof(type), + "Cannot set volume level for AudioVolumeType.None"); + } + + var ret = Interop.AudioVolume.SetVolume(type, value); + + if (ret == AudioManagerError.InvalidParameter) + { + throw new ArgumentOutOfRangeException(nameof(value), value, + $"valid volume level range is 0 <= x <= {nameof(MaxVolumeLevel)}[{nameof(AudioVolumeType)}]"); } + + ret.Validate("Failed to set the volume level"); } } } -} \ No newline at end of file +} diff --git a/src/Tizen.Multimedia/Common.Internal/LibcSupport.cs b/src/Tizen.Multimedia/Common.Internal/LibcSupport.cs index 0f11db1..c888cd7 100644 --- a/src/Tizen.Multimedia/Common.Internal/LibcSupport.cs +++ b/src/Tizen.Multimedia/Common.Internal/LibcSupport.cs @@ -1,4 +1,19 @@ - +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using System; namespace Tizen.Multimedia diff --git a/src/Tizen.Multimedia/Interop/AudioStreamPolicyHandle.cs b/src/Tizen.Multimedia/Interop/AudioStreamPolicyHandle.cs new file mode 100644 index 0000000..fbb6764 --- /dev/null +++ b/src/Tizen.Multimedia/Interop/AudioStreamPolicyHandle.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. + */ + +using System; +using System.Runtime.InteropServices; + +namespace Tizen.Multimedia +{ + internal class AudioStreamPolicyHandle : SafeHandle + { + protected AudioStreamPolicyHandle() : base(IntPtr.Zero, true) + { + } + + public override bool IsInvalid => handle == IntPtr.Zero; + + protected override bool ReleaseHandle() + { + var ret = Interop.AudioStreamPolicy.Destroy(handle); + if (ret != AudioManagerError.None) + { + Log.Debug(GetType().FullName, $"Failed to release native {GetType()}"); + return false; + } + + return true; + } + } +} diff --git a/src/Tizen.Multimedia/Interop/Interop.Device.cs b/src/Tizen.Multimedia/Interop/Interop.Device.cs index c8ae644..0cc2ecb 100644 --- a/src/Tizen.Multimedia/Interop/Interop.Device.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Device.cs @@ -1,53 +1,71 @@ -using System; +/* + * 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.Multimedia { internal static partial class Interop { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void SoundDeviceConnectionChangedCallback(IntPtr device, bool isConnected, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void SoundDeviceStateChangedCallback(IntPtr device, AudioDeviceState changedState, IntPtr userData); - internal static partial class AudioDevice { - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_list")] - internal static extern int GetCurrentDeviceList(AudioDeviceOptions deviceMask, out IntPtr deviceList); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ConnectionChangedCallback(IntPtr device, bool isConnected, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void StateChangedCallback(IntPtr device, AudioDeviceState changedState, IntPtr userData); + + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_list")] + internal static extern AudioManagerError GetDeviceList(AudioDeviceOptions deviceMask, out IntPtr deviceList); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_free_device_list")] - internal static extern int FreeDeviceList(IntPtr deviceList); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_free_device_list")] + internal static extern AudioManagerError FreeDeviceList(IntPtr deviceList); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_next_device")] - internal static extern int GetNextDevice(IntPtr deviceList, out IntPtr device); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_next_device")] + internal static extern AudioManagerError GetNextDevice(IntPtr deviceList, out IntPtr device); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_type")] + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_type")] internal static extern int GetDeviceType(IntPtr device, out AudioDeviceType type); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_io_direction")] - internal static extern int GetDeviceIoDirection(IntPtr device, out AudioDeviceIoDirection ioDirection); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_io_direction")] + internal static extern AudioManagerError GetDeviceIoDirection(IntPtr device, out AudioDeviceIoDirection ioDirection); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_id")] + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_id")] internal static extern int GetDeviceId(IntPtr device, out int id); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_name")] + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_name")] internal static extern int GetDeviceName(IntPtr device, out IntPtr name); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_state")] - internal static extern int GetDeviceState(IntPtr device, out AudioDeviceState state); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_state_by_id")] + internal static extern AudioManagerError GetDeviceState(int deviceId, out AudioDeviceState state); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_connection_changed_cb")] - internal static extern int AddDeviceConnectionChangedCallback(AudioDeviceOptions deviceMask, SoundDeviceConnectionChangedCallback callback, IntPtr userData, out int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_connection_changed_cb")] + internal static extern AudioManagerError AddDeviceConnectionChangedCallback( + AudioDeviceOptions deviceMask, ConnectionChangedCallback callback, IntPtr userData, out int id); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_connection_changed_cb")] - internal static extern int RemoveDeviceConnectionChangedCallback(int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_connection_changed_cb")] + internal static extern AudioManagerError RemoveDeviceConnectionChangedCallback(int id); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_state_changed_cb")] - internal static extern int AddDeviceStateChangedCallback(AudioDeviceOptions deviceMask, SoundDeviceStateChangedCallback callback, IntPtr userData, out int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_state_changed_cb")] + internal static extern AudioManagerError AddDeviceStateChangedCallback(AudioDeviceOptions deviceMask, + StateChangedCallback callback, IntPtr userData, out int id); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_state_changed_cb")] - internal static extern int RemoveDeviceStateChangedCallback(int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_state_changed_cb")] + internal static extern AudioManagerError RemoveDeviceStateChangedCallback(int id); } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia/Interop/Interop.EvasObject.cs b/src/Tizen.Multimedia/Interop/Interop.EvasObject.cs index 4a06dd0..69ae936 100644 --- a/src/Tizen.Multimedia/Interop/Interop.EvasObject.cs +++ b/src/Tizen.Multimedia/Interop/Interop.EvasObject.cs @@ -1,4 +1,20 @@ -using System; +/* + * 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.Multimedia diff --git a/src/Tizen.Multimedia/Interop/Interop.Libc.cs b/src/Tizen.Multimedia/Interop/Interop.Libc.cs index 7e9cb41..5c25fda 100644 --- a/src/Tizen.Multimedia/Interop/Interop.Libc.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Libc.cs @@ -1,4 +1,20 @@ -using System; +/* + * 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.Multimedia diff --git a/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs b/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs index e72f8c2..e7992f3 100644 --- a/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs +++ b/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs @@ -1,3 +1,19 @@ +/* + * 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; @@ -28,7 +44,6 @@ namespace Tizen.Multimedia [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_set_buffer_size")] internal static extern int SetBufferSize(IntPtr handle, ulong size); - [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_allocated_buffer_size")] internal static extern int GetAllocatedBufferSize(IntPtr handle, out int size); diff --git a/src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs b/src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs index 9a7c59c..0ab53a2 100644 --- a/src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs +++ b/src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs @@ -1,55 +1,85 @@ -using System; +/* + * 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.Multimedia { internal static partial class Interop { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void SoundStreamFocusStateChangedCallback(IntPtr streamInfo, AudioStreamFocusOptions focusMask, AudioStreamFocusState focusState, int reason, int audioStreamBehavior, string extraInfo, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void SoundStreamFocusStateWatchCallback(int id, AudioStreamFocusOptions focusMask, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData); - internal static partial class AudioStreamPolicy { - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_create_stream_information")] - internal static extern int CreateStreamInformation(int streamType, SoundStreamFocusStateChangedCallback callback, IntPtr userData, out IntPtr streamInfo); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void FocusStateChangedCallback(IntPtr streamInfo, AudioStreamFocusOptions focusMask, + AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, + AudioStreamBehaviors audioStreamBehavior, string extraInfo, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void FocusStateWatchCallback(int id, AudioStreamFocusOptions focusMask, + AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, + IntPtr userData); + + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_create_stream_information")] + internal static extern AudioManagerError Create(AudioStreamType streamType, + FocusStateChangedCallback callback, IntPtr userData, out AudioStreamPolicyHandle streamInfo); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_destroy_stream_information")] - internal static extern int DestroyStreamInformation(IntPtr streamInfo); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_destroy_stream_information")] + internal static extern AudioManagerError Destroy(IntPtr streamInfo); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_for_stream_routing")] - internal static extern int AddDeviceForStreamRouting(IntPtr streamInfo, IntPtr device); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_id_for_stream_routing")] + internal static extern AudioManagerError AddDeviceForStreamRouting( + AudioStreamPolicyHandle streamInfo, int deviceId); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_for_stream_routing")] - internal static extern int RemoveDeviceForStreamRouting(IntPtr streamInfo, IntPtr device); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_id_for_stream_routing")] + internal static extern AudioManagerError RemoveDeviceForStreamRouting( + AudioStreamPolicyHandle streamInfo, int device); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_apply_stream_routing")] - internal static extern int ApplyStreamRouting(IntPtr streamInfo); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_apply_stream_routing")] + internal static extern AudioManagerError ApplyStreamRouting(AudioStreamPolicyHandle streamInfo); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_acquire_focus")] - internal static extern int AcquireFocus(IntPtr streamInfo, AudioStreamFocusOptions focusMask, int audioStreamBehavior, string extraInfo); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_acquire_focus")] + internal static extern AudioManagerError AcquireFocus(AudioStreamPolicyHandle streamInfo, + AudioStreamFocusOptions focusMask, AudioStreamBehaviors audioStreamBehavior, string extraInfo); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_release_focus")] - internal static extern int ReleaseFocus(IntPtr streamInfo, AudioStreamFocusOptions focusMask, int audioStreamBehavior, string extraInfo); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_release_focus")] + internal static extern AudioManagerError ReleaseFocus(AudioStreamPolicyHandle streamInfo, + AudioStreamFocusOptions focusMask, AudioStreamBehaviors audioStreamBehavior, string extraInfo); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_focus_state")] - internal static extern int GetFocusState(IntPtr streaInfo, out AudioStreamFocusState stateForPlayback, out AudioStreamFocusState stateForRecording); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_focus_state")] + internal static extern int GetFocusState(AudioStreamPolicyHandle streamInfo, + out AudioStreamFocusState stateForPlayback, out AudioStreamFocusState stateForRecording); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_set_focus_reacquisition")] - internal static extern int SetFocusReacquisition(IntPtr streamInfo, bool enable); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_set_focus_reacquisition")] + internal static extern AudioManagerError SetFocusReacquisition(AudioStreamPolicyHandle streamInfo, + bool enable); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_focus_reacquisition")] - internal static extern int GetFocusReacquisition(IntPtr streamInfo, out bool enabled); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_focus_reacquisition")] + internal static extern AudioManagerError GetFocusReacquisition(AudioStreamPolicyHandle streamInfo, + out bool enabled); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_sound_type")] - internal static extern int GetSoundType(IntPtr streamInfo, out AudioVolumeType soundType); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_sound_type")] + internal static extern AudioManagerError GetSoundType(AudioStreamPolicyHandle streamInfo, + out AudioVolumeType soundType); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_focus_state_watch_cb")] - internal static extern int AddFocusStateWatchCallback(AudioStreamFocusOptions focusMask, SoundStreamFocusStateWatchCallback callback, IntPtr userData, out int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_focus_state_watch_cb")] + internal static extern AudioManagerError AddFocusStateWatchCallback(AudioStreamFocusOptions focusMask, + FocusStateWatchCallback callback, IntPtr userData, out int id); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_focus_state_watch_cb")] + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_focus_state_watch_cb")] internal static extern int RemoveFocusStateWatchCallback(int id); } } diff --git a/src/Tizen.Multimedia/Interop/Interop.Volume.cs b/src/Tizen.Multimedia/Interop/Interop.Volume.cs index 1b3f205..cae490e 100644 --- a/src/Tizen.Multimedia/Interop/Interop.Volume.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Volume.cs @@ -1,32 +1,49 @@ -using System; +/* + * 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.Multimedia { internal static partial class Interop { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void SoundManagerVolumeChangedCallback(AudioVolumeType type, uint volume, IntPtr userData); - internal static partial class AudioVolume { - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_max_volume")] - internal static extern int GetMaxVolume(AudioVolumeType type, out int max); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VolumeChangedCallback(AudioVolumeType type, uint volume, IntPtr userData); + + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_max_volume")] + internal static extern AudioManagerError GetMaxVolume(AudioVolumeType type, out int max); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_set_volume")] - internal static extern int SetVolume(AudioVolumeType type, int volume); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_set_volume")] + internal static extern AudioManagerError SetVolume(AudioVolumeType type, int volume); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_volume")] - internal static extern int GetVolume(AudioVolumeType type, out int volume); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_volume")] + internal static extern AudioManagerError GetVolume(AudioVolumeType type, out int volume); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_current_sound_type")] - internal static extern int GetCurrentSoundType(out AudioVolumeType type); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_current_sound_type")] + internal static extern AudioManagerError GetCurrentSoundType(out AudioVolumeType type); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_volume_changed_cb")] - internal static extern int AddVolumeChangedCallback(SoundManagerVolumeChangedCallback callback, IntPtr userData, out int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_volume_changed_cb")] + internal static extern AudioManagerError AddVolumeChangedCallback(VolumeChangedCallback callback, + IntPtr userData, out int id); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_volume_changed_cb")] - internal static extern int RemoveVolumeChangedCallback(int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_volume_changed_cb")] + internal static extern AudioManagerError RemoveVolumeChangedCallback(int id); } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs b/src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs new file mode 100644 index 0000000..60e1a54 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs @@ -0,0 +1,274 @@ +/* + * 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 Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// Represents an audio media format. This class cannot be inherited. + /// + public sealed class AudioMediaFormat : MediaFormat + { + + /// + /// Initializes a new instance of the AudioMediaFormat class with the specified mime type, + /// channel, sample rate, bit and bit rate. + /// + /// The mime type of the format. + /// The channel value of the format. + /// The sample rate value of the format. + /// The bit value of the format. + /// The bit rate value of the format. + /// is invalid(i.e. undefined value). + /// + /// , , or is less than zero. + /// + public AudioMediaFormat(MediaFormatAudioMimeType mimeType, + int channel, int sampleRate, int bit, int bitRate) + : this(mimeType, channel, sampleRate, bit, bitRate, MediaFormatAacType.None) + { + } + + /// + /// Initializes a new instance of the AudioMediaFormat class with the specified mime type, + /// channel, sample rate, bit, bit rate and aac type. + /// + /// The mime type of the format. + /// The channel value of the format. + /// The sample rate value of the format. + /// The bit value of the format. + /// The bit rate value of the format. + /// The AAC bitstream format(ADIF or ADTS). + /// + /// or is invalid(i.e. undefined value).\n + /// -or-\n + /// is not , but is one of aac types. + /// + /// + /// , , or is less than zero. + /// + public AudioMediaFormat(MediaFormatAudioMimeType mimeType, + int channel, int sampleRate, int bit, int bitRate, MediaFormatAacType aacType) + : base(MediaFormatType.Audio) + { + if (!Enum.IsDefined(typeof(MediaFormatAudioMimeType), mimeType)) + { + throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); + } + if (channel < 0) + { + throw new ArgumentOutOfRangeException("Channel value can't be negative."); + } + if (sampleRate < 0) + { + throw new ArgumentOutOfRangeException("Sample rate value can't be negative."); + } + if (bit < 0) + { + throw new ArgumentOutOfRangeException("Bit value can't be negative."); + } + if (bitRate < 0) + { + throw new ArgumentOutOfRangeException("Bit rate value can't be negative."); + } + if (!Enum.IsDefined(typeof(MediaFormatAacType), aacType)) + { + throw new ArgumentException($"Invalid aac type value : { (int)aacType }"); + } + if (!IsAacSupportedMimeType(mimeType) && aacType != MediaFormatAacType.None) + { + throw new ArgumentException("Aac is supported only with aac mime types."); + } + + MimeType = mimeType; + Channel = channel; + SampleRate = sampleRate; + Bit = bit; + BitRate = bitRate; + AacType = aacType; + } + + /// + /// Initializes a new instance of the AudioMediaFormat class from a native handle. + /// + /// A native handle. + internal AudioMediaFormat(IntPtr handle) + : base(MediaFormatType.Audio) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + MediaFormatAudioMimeType mimeType; + int channel = 0; + int sampleRate = 0; + int bit = 0; + int bitRate = 0; + MediaFormatAacType aacType; + GetInfo(handle, out mimeType, out channel, out sampleRate, out bit, out bitRate); + + if (IsAacSupportedMimeType(mimeType)) + { + GetAacType(handle, out aacType); + } + else + { + aacType = MediaFormatAacType.None; + } + + MimeType = mimeType; + Channel = channel; + SampleRate = sampleRate; + Bit = bit; + BitRate = bitRate; + AacType = aacType; + } + + /// + /// Returns an indication whether a specified mime type is a aac type. + /// + /// A mime type. + private static bool IsAacSupportedMimeType(MediaFormatAudioMimeType mimeType) + { + return mimeType == MediaFormatAudioMimeType.AacLC || + mimeType == MediaFormatAudioMimeType.AacHE || + mimeType == MediaFormatAudioMimeType.AacHEPS; + } + + /// + /// Retrieves audio properties of media format from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for mime type. + /// An out parameter for channel. + /// An out parameter for sample rate. + /// An out parameter for bit. + /// An out parameter for bit rate. + private static void GetInfo(IntPtr handle, out MediaFormatAudioMimeType mimeType, + out int channel, out int sampleRate, out int bit, out int bitRate) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int mimeTypeValue = 0; + + int ret = Interop.MediaFormat.GetAudioInfo(handle, + out mimeTypeValue, out channel, out sampleRate, out bit, out bitRate); + + mimeType = (MediaFormatAudioMimeType)mimeTypeValue; + + MultimediaDebug.AssertNoError(ret); + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatAudioMimeType), mimeType), + "Invalid audio mime type!"); + } + + /// + /// Retrieves aac type value from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for aac type. + private static void GetAacType(IntPtr handle, out MediaFormatAacType aacType) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int aacTypeValue = 0; + + int ret = Interop.MediaFormat.GetAudioAacType(handle, out aacTypeValue); + + MultimediaDebug.AssertNoError(ret); + + aacType = (MediaFormatAacType)aacTypeValue; + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatAacType), aacType), "Invalid aac type!"); + } + + internal override void AsNativeHandle(IntPtr handle) + { + Debug.Assert(Type == MediaFormatType.Audio); + + int ret = Interop.MediaFormat.SetAudioMimeType(handle, (int)MimeType); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioChannel(handle, Channel); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioSampleRate(handle, SampleRate); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioBit(handle, Bit); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioAverageBps(handle, BitRate); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioAacType(handle, (int)AacType); + MultimediaDebug.AssertNoError(ret); + } + + /// + /// Gets the mime type of the current format. + /// + public MediaFormatAudioMimeType MimeType { get; } + + /// + /// Gets the channel value of the current format. + /// + public int Channel { get; } + + /// + /// Gets the sample rate value of the current format. + /// + public int SampleRate { get; } + + /// + /// Gets the bit value of the current format. + /// + public int Bit { get; } + + /// + /// Gets the bit rate value of the current format. + /// + public int BitRate { get; } + + /// + /// Gets the aac type of the current format. + /// + public MediaFormatAacType AacType { get; } + + public override string ToString() + { + return $@"MimeTyp={ MimeType.ToString() }, Channel={ Channel.ToString() }, SampleRate= + { SampleRate }, Bit={ Bit.ToString() }, BitRate={ BitRate.ToString() }, AacType={ AacType.ToString() }"; + } + + public override bool Equals(object obj) + { + var rhs = obj as AudioMediaFormat; + if (rhs == null) + { + return false; + } + + return MimeType == rhs.MimeType && Channel == rhs.Channel && SampleRate == rhs.SampleRate && + Bit == rhs.Bit && BitRate == rhs.BitRate; + } + + public override int GetHashCode() + { + return new { MimeType, Channel, SampleRate, Bit, BitRate }.GetHashCode(); + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs b/src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs new file mode 100644 index 0000000..0669184 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs @@ -0,0 +1,101 @@ +/* + * 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 Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// Represents a container media format. This class cannot be inherited. + /// + public sealed class ContainerMediaFormat : MediaFormat + { + /// + /// Initializes a new instance of the ContainerMediaFormat class. + /// + /// The mime type of the container format. + /// mimeType is invalid(i.e. undefined value). + public ContainerMediaFormat(MediaFormatContainerMimeType mimeType) + : base(MediaFormatType.Container) + { + if (!Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType)) + { + throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); + } + MimeType = mimeType; + } + + /// + /// Initializes a new instance of the ContainerMediaFormat class from a native handle. + /// + /// A native media format handle. + internal ContainerMediaFormat(IntPtr handle) + : base(MediaFormatType.Container) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int mimeType = 0; + + int ret = Interop.MediaFormat.GetContainerMimeType(handle, out mimeType); + + MultimediaDebug.AssertNoError(ret); + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType), + "Invalid container mime type!"); + + MimeType = (MediaFormatContainerMimeType)mimeType; + } + + /// + /// Gets the mime type of the current format. + /// + public MediaFormatContainerMimeType MimeType + { + get; + } + + internal override void AsNativeHandle(IntPtr handle) + { + Debug.Assert(Type == MediaFormatType.Container); + + int ret = Interop.MediaFormat.SetContainerMimeType(handle, (int)MimeType); + + MultimediaDebug.AssertNoError(ret); + } + + public override string ToString() + { + return $"MimeType={ MimeType.ToString() }"; + } + + public override bool Equals(object obj) + { + var rhs = obj as ContainerMediaFormat; + if (rhs == null) + { + return false; + } + + return MimeType == rhs.MimeType; + } + + public override int GetHashCode() + { + return (int)MimeType; + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaFormat.cs b/src/Tizen.Multimedia/MediaTool/MediaFormat.cs index 5a2092b..f83b205 100755 --- a/src/Tizen.Multimedia/MediaTool/MediaFormat.cs +++ b/src/Tizen.Multimedia/MediaTool/MediaFormat.cs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + using System; using System.Diagnostics; using Tizen.Internals.Errors; @@ -107,702 +108,4 @@ namespace Tizen.Multimedia /// A native handle to be written. internal abstract void AsNativeHandle(IntPtr handle); } - - /// - /// Represents a container media format. This class cannot be inherited. - /// - public sealed class ContainerMediaFormat : MediaFormat - { - /// - /// Initializes a new instance of the ContainerMediaFormat class. - /// - /// The mime type of the container format. - /// mimeType is invalid(i.e. undefined value). - public ContainerMediaFormat(MediaFormatContainerMimeType mimeType) - : base(MediaFormatType.Container) - { - if (!Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType)) - { - throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); - } - MimeType = mimeType; - } - - /// - /// Initializes a new instance of the ContainerMediaFormat class from a native handle. - /// - /// A native media format handle. - internal ContainerMediaFormat(IntPtr handle) - : base(MediaFormatType.Container) - { - Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - - int mimeType = 0; - - int ret = Interop.MediaFormat.GetContainerMimeType(handle, out mimeType); - - MultimediaDebug.AssertNoError(ret); - - Debug.Assert(Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType), - "Invalid container mime type!"); - - MimeType = (MediaFormatContainerMimeType)mimeType; - } - - /// - /// Gets the mime type of the current format. - /// - public MediaFormatContainerMimeType MimeType - { - get; - } - - internal override void AsNativeHandle(IntPtr handle) - { - Debug.Assert(Type == MediaFormatType.Container); - - int ret = Interop.MediaFormat.SetContainerMimeType(handle, (int)MimeType); - - MultimediaDebug.AssertNoError(ret); - } - - public override string ToString() - { - return $"MimeType={ MimeType.ToString() }"; - } - - public override bool Equals(object obj) - { - var rhs = obj as ContainerMediaFormat; - if (rhs == null) - { - return false; - } - - return MimeType == rhs.MimeType; - } - - public override int GetHashCode() - { - return (int)MimeType; - } - } - - /// - /// Represents a video media format. This class cannot be inherited. - /// - public sealed class VideoMediaFormat : MediaFormat - { - private const int DefaultFrameRate = 0; - private const int DefaultBitRate = 0; - - /// - /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, width and height. - /// - /// The mime type of the format. - /// The width value of the format. - /// The height value of the format - /// mimeType is invalid(i.e. undefined value). - /// width, or height is less than zero. - public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height) - : this(mimeType, width, height, DefaultFrameRate) - { - } - - /// - /// Initializes a new instance of the VideoMediaFormat class with the specified mime type and size. - /// - /// The mime type of the format. - /// The size of the format. - /// mimeType is invalid(i.e. undefined value). - /// width, or height is less than zero. - public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size) - : this(mimeType, size, DefaultFrameRate) - { - } - - /// - /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, - /// width, height and frame rate. - /// - /// The mime type of the format. - /// The width value of the format. - /// The height value of the format - /// The frame rate of the format. - /// mimeType is invalid(i.e. undefined value). - /// width, height or frameRate is less than zero. - public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, - int frameRate) - : this(mimeType, width, height, frameRate, DefaultBitRate) - { - } - - /// - /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, - /// width, height and frame rate. - /// - /// The mime type of the format. - /// The video size of the format. - /// The frame rate of the format. - /// mimeType is invalid(i.e. undefined value). - /// width, height or frameRate is less than zero. - public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size, - int frameRate) - : this(mimeType, size, frameRate, DefaultBitRate) - { - } - - /// - /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, - /// width, height, frame rate and bit rate. - /// - /// The mime type of the format. - /// The width value of the format. - /// The height value of the format - /// The frame rate of the format. - /// The bit rate of the format. - /// mimeType is invalid(i.e. undefined value). - /// width, height, frameRate or bitRate is less than zero. - public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, - int frameRate, int bitRate) - : this(mimeType, new Size(width, height), frameRate, bitRate) - { - } - - /// - /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, - /// size, frame rate and bit rate. - /// - /// The mime type of the format. - /// The size of the format. - /// The frame rate of the format. - /// The bit rate of the format. - /// mimeType is invalid(i.e. undefined value). - /// width, height, frameRate or bitRate is less than zero. - public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size, - int frameRate, int bitRate) - : base(MediaFormatType.Video) - { - if (!Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType)) - { - throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); - } - if (size.Width < 0) - { - throw new ArgumentOutOfRangeException(nameof(size), size.Width, "Size.Width value can't be less than zero."); - } - if (size.Height < 0) - { - throw new ArgumentOutOfRangeException(nameof(size), size.Height, "Size.Height value can't be less than zero."); - } - if (frameRate < 0) - { - throw new ArgumentOutOfRangeException(nameof(frameRate), frameRate, "Frame rate can't be less than zero."); - } - if (bitRate < 0) - { - throw new ArgumentOutOfRangeException(nameof(bitRate), bitRate, "Bit rate value can't be less than zero."); - } - - MimeType = mimeType; - Size = size; - FrameRate = frameRate; - BitRate = bitRate; - } - - /// - /// Initializes a new instance of the VideoMediaForma class from a native handle. - /// - /// A native handle. - internal VideoMediaFormat(IntPtr handle) - : base(MediaFormatType.Video) - { - Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - - int width = 0; - int height = 0; - int bitRate = 0; - int frameRate = 0; - MediaFormatVideoMimeType mimeType; - GetInfo(handle, out width, out height, out bitRate, out mimeType); - - GetFrameRate(handle, out frameRate); - - MimeType = mimeType; - Size = new Size(width, height); - FrameRate = frameRate; - BitRate = bitRate; - } - - /// - /// Retrieves video properties of media format from a native handle. - /// - /// A native handle that properties are retrieved from. - /// An out parameter for width. - /// An out parameter for height. - /// An out parameter for bit rate. - /// An out parameter for mime type. - private static void GetInfo(IntPtr handle, out int width, out int height, out int bitRate, - out MediaFormatVideoMimeType mimeType) - { - Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - - int mimeTypeValue = 0; - int maxBps = 0; - - int ret = Interop.MediaFormat.GetVideoInfo(handle, - out mimeTypeValue, out width, out height, out bitRate, out maxBps); - - MultimediaDebug.AssertNoError(ret); - - mimeType = (MediaFormatVideoMimeType)mimeTypeValue; - - Debug.Assert(Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType), - "Invalid video mime type!"); - } - - /// - /// Retrieves frame rate from a native handle. - /// - /// A native handle that properties are retrieved from. - /// An out parameter for frame rate. - private static void GetFrameRate(IntPtr handle, out int frameRate) - { - Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - - int ret = Interop.MediaFormat.GetVideoFrameRate(handle, out frameRate); - - MultimediaDebug.AssertNoError(ret); - } - - internal override void AsNativeHandle(IntPtr handle) - { - Debug.Assert(Type == MediaFormatType.Video); - - int ret = Interop.MediaFormat.SetVideoMimeType(handle, (int)MimeType); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetVideoWidth(handle, Size.Width); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetVideoHeight(handle, Size.Height); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetVideoAverageBps(handle, BitRate); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetVideoFrameRate(handle, FrameRate); - MultimediaDebug.AssertNoError(ret); - } - - /// - /// Gets the mime type of the current format. - /// - public MediaFormatVideoMimeType MimeType { get; } - - /// - /// Gets the size of the current format. - /// - public Size Size { get; } - - /// - /// Gets the frame rate value of the current format. - /// - public int FrameRate { get; } - - /// - /// Gets the bit rate value of the current format. - /// - public int BitRate { get; } - - public override string ToString() - { - return $@"MimeType={ MimeType.ToString() }, Size=({ Size.ToString() }), FrameRate= - { FrameRate.ToString() }, BitRate={ BitRate.ToString() }"; - } - - public override bool Equals(object obj) - { - var rhs = obj as VideoMediaFormat; - if (rhs == null) - { - return false; - } - - return MimeType == rhs.MimeType && Size == rhs.Size && - FrameRate == rhs.FrameRate && BitRate == rhs.BitRate; - } - - public override int GetHashCode() - { - return new { MimeType, Size, FrameRate, BitRate }.GetHashCode(); - } - } - - /// - /// Represents an audio media format. This class cannot be inherited. - /// - public sealed class AudioMediaFormat : MediaFormat - { - - /// - /// Initializes a new instance of the AudioMediaFormat class with the specified mime type, - /// channel, sample rate, bit and bit rate. - /// - /// The mime type of the format. - /// The channel value of the format. - /// The sample rate value of the format. - /// The bit value of the format. - /// The bit rate value of the format. - /// is invalid(i.e. undefined value). - /// - /// , , or is less than zero. - /// - public AudioMediaFormat(MediaFormatAudioMimeType mimeType, - int channel, int sampleRate, int bit, int bitRate) - : this(mimeType, channel, sampleRate, bit, bitRate, MediaFormatAacType.None) - { - } - - /// - /// Initializes a new instance of the AudioMediaFormat class with the specified mime type, - /// channel, sample rate, bit, bit rate and aac type. - /// - /// The mime type of the format. - /// The channel value of the format. - /// The sample rate value of the format. - /// The bit value of the format. - /// The bit rate value of the format. - /// The AAC bitstream format(ADIF or ADTS). - /// - /// or is invalid(i.e. undefined value).\n - /// -or-\n - /// is not , but is one of aac types. - /// - /// - /// , , or is less than zero. - /// - public AudioMediaFormat(MediaFormatAudioMimeType mimeType, - int channel, int sampleRate, int bit, int bitRate, MediaFormatAacType aacType) - : base(MediaFormatType.Audio) - { - if (!Enum.IsDefined(typeof(MediaFormatAudioMimeType), mimeType)) - { - throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); - } - if (channel < 0) - { - throw new ArgumentOutOfRangeException("Channel value can't be negative."); - } - if (sampleRate < 0) - { - throw new ArgumentOutOfRangeException("Sample rate value can't be negative."); - } - if (bit < 0) - { - throw new ArgumentOutOfRangeException("Bit value can't be negative."); - } - if (bitRate < 0) - { - throw new ArgumentOutOfRangeException("Bit rate value can't be negative."); - } - if (!Enum.IsDefined(typeof(MediaFormatAacType), aacType)) - { - throw new ArgumentException($"Invalid aac type value : { (int)aacType }"); - } - if (!IsAacSupportedMimeType(mimeType) && aacType != MediaFormatAacType.None) - { - throw new ArgumentException("Aac is supported only with aac mime types."); - } - - MimeType = mimeType; - Channel = channel; - SampleRate = sampleRate; - Bit = bit; - BitRate = bitRate; - AacType = aacType; - } - - /// - /// Initializes a new instance of the AudioMediaFormat class from a native handle. - /// - /// A native handle. - internal AudioMediaFormat(IntPtr handle) - : base(MediaFormatType.Audio) - { - Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - - MediaFormatAudioMimeType mimeType; - int channel = 0; - int sampleRate = 0; - int bit = 0; - int bitRate = 0; - MediaFormatAacType aacType; - GetInfo(handle, out mimeType, out channel, out sampleRate, out bit, out bitRate); - - if (IsAacSupportedMimeType(mimeType)) - { - GetAacType(handle, out aacType); - } - else - { - aacType = MediaFormatAacType.None; - } - - MimeType = mimeType; - Channel = channel; - SampleRate = sampleRate; - Bit = bit; - BitRate = bitRate; - AacType = aacType; - } - - /// - /// Returns an indication whether a specified mime type is a aac type. - /// - /// A mime type. - private static bool IsAacSupportedMimeType(MediaFormatAudioMimeType mimeType) - { - return mimeType == MediaFormatAudioMimeType.AacLC || - mimeType == MediaFormatAudioMimeType.AacHE || - mimeType == MediaFormatAudioMimeType.AacHEPS; - } - - /// - /// Retrieves audio properties of media format from a native handle. - /// - /// A native handle that properties are retrieved from. - /// An out parameter for mime type. - /// An out parameter for channel. - /// An out parameter for sample rate. - /// An out parameter for bit. - /// An out parameter for bit rate. - private static void GetInfo(IntPtr handle, out MediaFormatAudioMimeType mimeType, - out int channel, out int sampleRate, out int bit, out int bitRate) - { - Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - - int mimeTypeValue = 0; - - int ret = Interop.MediaFormat.GetAudioInfo(handle, - out mimeTypeValue, out channel, out sampleRate, out bit, out bitRate); - - mimeType = (MediaFormatAudioMimeType)mimeTypeValue; - - MultimediaDebug.AssertNoError(ret); - - Debug.Assert(Enum.IsDefined(typeof(MediaFormatAudioMimeType), mimeType), - "Invalid audio mime type!"); - } - - /// - /// Retrieves aac type value from a native handle. - /// - /// A native handle that properties are retrieved from. - /// An out parameter for aac type. - private static void GetAacType(IntPtr handle, out MediaFormatAacType aacType) - { - Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - - int aacTypeValue = 0; - - int ret = Interop.MediaFormat.GetAudioAacType(handle, out aacTypeValue); - - MultimediaDebug.AssertNoError(ret); - - aacType = (MediaFormatAacType)aacTypeValue; - - Debug.Assert(Enum.IsDefined(typeof(MediaFormatAacType), aacType), "Invalid aac type!"); - } - - internal override void AsNativeHandle(IntPtr handle) - { - Debug.Assert(Type == MediaFormatType.Audio); - - int ret = Interop.MediaFormat.SetAudioMimeType(handle, (int)MimeType); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetAudioChannel(handle, Channel); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetAudioSampleRate(handle, SampleRate); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetAudioBit(handle, Bit); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetAudioAverageBps(handle, BitRate); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetAudioAacType(handle, (int)AacType); - MultimediaDebug.AssertNoError(ret); - } - - /// - /// Gets the mime type of the current format. - /// - public MediaFormatAudioMimeType MimeType { get; } - - /// - /// Gets the channel value of the current format. - /// - public int Channel { get; } - - /// - /// Gets the sample rate value of the current format. - /// - public int SampleRate { get; } - - /// - /// Gets the bit value of the current format. - /// - public int Bit { get; } - - /// - /// Gets the bit rate value of the current format. - /// - public int BitRate { get; } - - /// - /// Gets the aac type of the current format. - /// - public MediaFormatAacType AacType { get; } - - public override string ToString() - { - return $@"MimeTyp={ MimeType.ToString() }, Channel={ Channel.ToString() }, SampleRate= - { SampleRate }, Bit={ Bit.ToString() }, BitRate={ BitRate.ToString() }, AacType={ AacType.ToString() }"; - } - - public override bool Equals(object obj) - { - var rhs = obj as AudioMediaFormat; - if (rhs == null) - { - return false; - } - - return MimeType == rhs.MimeType && Channel == rhs.Channel && SampleRate == rhs.SampleRate && - Bit == rhs.Bit && BitRate == rhs.BitRate; - } - - public override int GetHashCode() - { - return new { MimeType, Channel, SampleRate, Bit, BitRate }.GetHashCode(); - } - } - - /// - /// Represents a text media format. This class cannot be inherited. - /// - public sealed class TextMediaFormat : MediaFormat - { - /// - /// Initializes a new instance of the TextMediaFormat class with the specified mime type - /// and text type. - /// - /// The mime type of the format. - /// The text type of the format. - /// - /// mimeType or textType is invalid(i.e. undefined value). - public TextMediaFormat(MediaFormatTextMimeType mimeType, MediaFormatTextType textType) - : base(MediaFormatType.Text) - { - if (!Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType)) - { - throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); - } - if (!Enum.IsDefined(typeof(MediaFormatTextType), textType)) - { - throw new ArgumentException($"Invalid text type value : { (int)textType }"); - } - MimeType = mimeType; - TextType = textType; - } - - /// - /// Initializes a new instance of the TextMediaFormat class from a native handle. - /// - /// A native handle. - internal TextMediaFormat(IntPtr handle) - : base(MediaFormatType.Text) - { - Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - - MediaFormatTextMimeType mimeType; - MediaFormatTextType textType; - - GetInfo(handle, out mimeType, out textType); - - MimeType = mimeType; - TextType = textType; - } - - /// - /// Retrieves text properties of media format from a native handle. - /// - /// A native handle that properties are retrieved from. - /// An out parameter for mime type. - /// An out parameter for text type. - private static void GetInfo(IntPtr handle, out MediaFormatTextMimeType mimeType, - out MediaFormatTextType textType) - { - int mimeTypeValue = 0; - int textTypeValue = 0; - - int ret = Interop.MediaFormat.GetTextInfo(handle, out mimeTypeValue, out textTypeValue); - - MultimediaDebug.AssertNoError(ret); - - mimeType = (MediaFormatTextMimeType)mimeTypeValue; - textType = (MediaFormatTextType)textTypeValue; - - Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType), - "Invalid text mime type!"); - Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextType), textType), - "Invalid text type!"); - } - - internal override void AsNativeHandle(IntPtr handle) - { - Debug.Assert(Type == MediaFormatType.Text); - - int ret = Interop.MediaFormat.SetTextMimeType(handle, (int)MimeType); - MultimediaDebug.AssertNoError(ret); - - ret = Interop.MediaFormat.SetTextType(handle, (int)TextType); - MultimediaDebug.AssertNoError(ret); - } - - /// - /// Gets the mime type of the current format. - /// - public MediaFormatTextMimeType MimeType { get; } - - /// - /// Gets the text type of the current format. - /// - public MediaFormatTextType TextType { get; } - - public override string ToString() - { - return $"MimeType={ MimeType.ToString() }, TextType={ TextType.ToString() }"; - } - - public override bool Equals(object obj) - { - var rhs = obj as TextMediaFormat; - if (rhs == null) - { - return false; - } - - return MimeType == rhs.MimeType && TextType == rhs.TextType; - } - - public override int GetHashCode() - { - return new { MimeType, TextType }.GetHashCode(); - } - } } diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs b/src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs new file mode 100644 index 0000000..dcdb6a1 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs @@ -0,0 +1,207 @@ +/* + * 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.Runtime.InteropServices; +using System.Threading; +using Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// Represents a packet for multimedia. + /// + public abstract partial class MediaPacket : IDisposable + { + private readonly LockState _lock = new LockState(); + + /// + /// Validate the current object is not locked. + /// + /// The MediaPacket has already been disposed of. + /// The MediaPacket is in use by another module. + private void ValidateNotLocked() + { + ValidateNotDisposed(); + + if (_lock.IsLocked) + { + throw new InvalidOperationException("Can't perform any writing operation." + + "The packet is in use, internally."); + } + } + + /// + /// Provides a thread-safe lock state controller. + /// + private sealed class LockState + { + const int LOCKED = 1; + const int UNLOCKED = 0; + + private int _locked = UNLOCKED; + + internal void SetLock() + { + if (Interlocked.CompareExchange(ref _locked, LOCKED, UNLOCKED) == LOCKED) + { + throw new InvalidOperationException("The packet is already locked."); + } + } + + internal void SetUnlock() + { + if (Interlocked.CompareExchange(ref _locked, UNLOCKED, LOCKED) == UNLOCKED) + { + Debug.Fail("The packet to unlock is not locked. " + + "There must be an error somewhere that a lock isn't disposed correctly."); + } + } + + internal bool IsLocked + { + get + { + return Interlocked.CompareExchange(ref _locked, 0, 0) == LOCKED; + } + } + } + + /// + /// Provides a thread-safe lock controller. + /// + /// + /// using (var lock = BaseMediaPacket.Lock(mediaPacket)) + /// { + /// .... + /// } + /// + internal sealed class Lock : IDisposable + { + private readonly MediaPacket _packet; + private readonly GCHandle _gcHandle; + private int _lockCount; + + internal static Lock Get(MediaPacket packet) + { + Debug.Assert(packet != null); + + lock (packet) + { + Lock lck = FromHandle(packet._handle); + + if (lck == null) + { + lck = new Lock(packet); + } + + lck._lockCount++; + + return lck; + } + } + + private Lock(MediaPacket packet) + { + Debug.Assert(packet != null, "The packet is null!"); + + packet.ValidateNotDisposed(); + + _packet = packet; + + _packet._lock.SetLock(); + + _gcHandle = GCHandle.Alloc(this); + + SetExtra(GCHandle.ToIntPtr(_gcHandle)); + } + + internal static Lock FromHandle(IntPtr handle) + { + Debug.Assert(handle != IntPtr.Zero); + + IntPtr extra = GetExtra(handle); + + if (extra == IntPtr.Zero) + { + return null; + } + + return (Lock)GCHandle.FromIntPtr(extra).Target; + } + + private void SetExtra(IntPtr ptr) + { + int ret = Interop.MediaPacket.SetExtra(_packet._handle, ptr); + + MultimediaDebug.AssertNoError(ret); + } + + private static IntPtr GetExtra(IntPtr handle) + { + IntPtr value; + + int ret = Interop.MediaPacket.GetExtra(handle, out value); + + MultimediaDebug.AssertNoError(ret); + + return value; + } + + internal IntPtr GetHandle() + { + return _packet.GetHandle(); + } + + internal MediaPacket MediaPacket + { + get + { + return _packet; + } + } + + private bool _isDisposed = false; + + public void Dispose() + { + if (!_isDisposed) + { + lock (_packet) + { + _lockCount--; + + if (_lockCount == 0) + { + SetExtra(IntPtr.Zero); + + if (_gcHandle.IsAllocated) + { + _gcHandle.Free(); + } + + //We can assure that at this point '_packet' is always locked by this lock. + _packet._lock.SetUnlock(); + } + } + + _isDisposed = true; + } + } + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacket.cs b/src/Tizen.Multimedia/MediaTool/MediaPacket.cs index 4755d96..c2ffe33 100644 --- a/src/Tizen.Multimedia/MediaTool/MediaPacket.cs +++ b/src/Tizen.Multimedia/MediaTool/MediaPacket.cs @@ -25,7 +25,7 @@ namespace Tizen.Multimedia /// /// Represents a packet for multimedia. /// - public abstract class MediaPacket : IDisposable + public abstract partial class MediaPacket : IDisposable { private IntPtr _handle = IntPtr.Zero; @@ -467,21 +467,6 @@ namespace Tizen.Multimedia } /// - /// Validate the current object is not locked. - /// - /// The MediaPacket has already been disposed of. - /// The MediaPacket is in use by another module. - private void ValidateNotLocked() - { - ValidateNotDisposed(); - - if (_lock.IsLocked) - { - throw new InvalidOperationException("Can't perform any writing operation." + - "The packet is in use, internally."); - } - } - /// /// Ensures whether the packet is writable. /// /// The MediaPacket already has been disposed of. @@ -558,169 +543,6 @@ namespace Tizen.Multimedia return new MediaPacketBuffer(this, dataHandle, size); } - #region Lock operations - private readonly LockState _lock = new LockState(); - - /// - /// Provides a thread-safe lock state controller. - /// - private sealed class LockState - { - const int LOCKED = 1; - const int UNLOCKED = 0; - - private int _locked = UNLOCKED; - - internal void SetLock() - { - if (Interlocked.CompareExchange(ref _locked, LOCKED, UNLOCKED) == LOCKED) - { - throw new InvalidOperationException("The packet is already locked."); - } - } - - internal void SetUnlock() - { - if (Interlocked.CompareExchange(ref _locked, UNLOCKED, LOCKED) == UNLOCKED) - { - Debug.Fail("The packet to unlock is not locked. " + - "There must be an error somewhere that a lock isn't disposed correctly."); - } - } - - internal bool IsLocked - { - get - { - return Interlocked.CompareExchange(ref _locked, 0, 0) == LOCKED; - } - } - } - - /// - /// Provides a thread-safe lock controller. - /// - /// - /// using (var lock = BaseMediaPacket.Lock(mediaPacket)) - /// { - /// .... - /// } - /// - internal sealed class Lock : IDisposable - { - private readonly MediaPacket _packet; - private readonly GCHandle _gcHandle; - private int _lockCount; - - internal static Lock Get(MediaPacket packet) - { - Debug.Assert(packet != null); - - lock (packet) - { - Lock lck = FromHandle(packet._handle); - - if (lck == null) - { - lck = new Lock(packet); - } - - lck._lockCount++; - - return lck; - } - } - - private Lock(MediaPacket packet) - { - Debug.Assert(packet != null, "The packet is null!"); - - packet.ValidateNotDisposed(); - - _packet = packet; - - _packet._lock.SetLock(); - - _gcHandle = GCHandle.Alloc(this); - - SetExtra(GCHandle.ToIntPtr(_gcHandle)); - } - - internal static Lock FromHandle(IntPtr handle) - { - Debug.Assert(handle != IntPtr.Zero); - - IntPtr extra = GetExtra(handle); - - if (extra == IntPtr.Zero) - { - return null; - } - - return (Lock)GCHandle.FromIntPtr(extra).Target; - } - - private void SetExtra(IntPtr ptr) - { - int ret = Interop.MediaPacket.SetExtra(_packet._handle, ptr); - - MultimediaDebug.AssertNoError(ret); - } - - private static IntPtr GetExtra(IntPtr handle) - { - IntPtr value; - - int ret = Interop.MediaPacket.GetExtra(handle, out value); - - MultimediaDebug.AssertNoError(ret); - - return value; - } - - internal IntPtr GetHandle() - { - return _packet.GetHandle(); - } - - internal MediaPacket MediaPacket - { - get - { - return _packet; - } - } - - private bool _isDisposed = false; - - public void Dispose() - { - if (!_isDisposed) - { - lock (_packet) - { - _lockCount--; - - if (_lockCount == 0) - { - SetExtra(IntPtr.Zero); - - if (_gcHandle.IsAllocated) - { - _gcHandle.Free(); - } - - //We can assure that at this point '_packet' is always locked by this lock. - _packet._lock.SetUnlock(); - } - } - - _isDisposed = true; - } - } - } - #endregion - /// /// Creates an object of the MediaPacket with the specified . /// diff --git a/src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs b/src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs new file mode 100644 index 0000000..3f28fe9 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/TextMediaFormat.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; +using System.Diagnostics; +using Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// Represents a text media format. This class cannot be inherited. + /// + public sealed class TextMediaFormat : MediaFormat + { + /// + /// Initializes a new instance of the TextMediaFormat class with the specified mime type + /// and text type. + /// + /// The mime type of the format. + /// The text type of the format. + /// + /// mimeType or textType is invalid(i.e. undefined value). + public TextMediaFormat(MediaFormatTextMimeType mimeType, MediaFormatTextType textType) + : base(MediaFormatType.Text) + { + if (!Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType)) + { + throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); + } + if (!Enum.IsDefined(typeof(MediaFormatTextType), textType)) + { + throw new ArgumentException($"Invalid text type value : { (int)textType }"); + } + MimeType = mimeType; + TextType = textType; + } + + /// + /// Initializes a new instance of the TextMediaFormat class from a native handle. + /// + /// A native handle. + internal TextMediaFormat(IntPtr handle) + : base(MediaFormatType.Text) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + MediaFormatTextMimeType mimeType; + MediaFormatTextType textType; + + GetInfo(handle, out mimeType, out textType); + + MimeType = mimeType; + TextType = textType; + } + + /// + /// Retrieves text properties of media format from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for mime type. + /// An out parameter for text type. + private static void GetInfo(IntPtr handle, out MediaFormatTextMimeType mimeType, + out MediaFormatTextType textType) + { + int mimeTypeValue = 0; + int textTypeValue = 0; + + int ret = Interop.MediaFormat.GetTextInfo(handle, out mimeTypeValue, out textTypeValue); + + MultimediaDebug.AssertNoError(ret); + + mimeType = (MediaFormatTextMimeType)mimeTypeValue; + textType = (MediaFormatTextType)textTypeValue; + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType), + "Invalid text mime type!"); + Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextType), textType), + "Invalid text type!"); + } + + internal override void AsNativeHandle(IntPtr handle) + { + Debug.Assert(Type == MediaFormatType.Text); + + int ret = Interop.MediaFormat.SetTextMimeType(handle, (int)MimeType); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetTextType(handle, (int)TextType); + MultimediaDebug.AssertNoError(ret); + } + + /// + /// Gets the mime type of the current format. + /// + public MediaFormatTextMimeType MimeType { get; } + + /// + /// Gets the text type of the current format. + /// + public MediaFormatTextType TextType { get; } + + public override string ToString() + { + return $"MimeType={ MimeType.ToString() }, TextType={ TextType.ToString() }"; + } + + public override bool Equals(object obj) + { + var rhs = obj as TextMediaFormat; + if (rhs == null) + { + return false; + } + + return MimeType == rhs.MimeType && TextType == rhs.TextType; + } + + public override int GetHashCode() + { + return new { MimeType, TextType }.GetHashCode(); + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs b/src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs new file mode 100644 index 0000000..4890dd1 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs @@ -0,0 +1,272 @@ +/* + * 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 Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// Represents a video media format. This class cannot be inherited. + /// + public sealed class VideoMediaFormat : MediaFormat + { + private const int DefaultFrameRate = 0; + private const int DefaultBitRate = 0; + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, width and height. + /// + /// The mime type of the format. + /// The width value of the format. + /// The height value of the format + /// mimeType is invalid(i.e. undefined value). + /// width, or height is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height) + : this(mimeType, width, height, DefaultFrameRate) + { + } + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type and size. + /// + /// The mime type of the format. + /// The size of the format. + /// mimeType is invalid(i.e. undefined value). + /// width, or height is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size) + : this(mimeType, size, DefaultFrameRate) + { + } + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, + /// width, height and frame rate. + /// + /// The mime type of the format. + /// The width value of the format. + /// The height value of the format + /// The frame rate of the format. + /// mimeType is invalid(i.e. undefined value). + /// width, height or frameRate is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, + int frameRate) + : this(mimeType, width, height, frameRate, DefaultBitRate) + { + } + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, + /// width, height and frame rate. + /// + /// The mime type of the format. + /// The video size of the format. + /// The frame rate of the format. + /// mimeType is invalid(i.e. undefined value). + /// width, height or frameRate is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size, + int frameRate) + : this(mimeType, size, frameRate, DefaultBitRate) + { + } + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, + /// width, height, frame rate and bit rate. + /// + /// The mime type of the format. + /// The width value of the format. + /// The height value of the format + /// The frame rate of the format. + /// The bit rate of the format. + /// mimeType is invalid(i.e. undefined value). + /// width, height, frameRate or bitRate is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, + int frameRate, int bitRate) + : this(mimeType, new Size(width, height), frameRate, bitRate) + { + } + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, + /// size, frame rate and bit rate. + /// + /// The mime type of the format. + /// The size of the format. + /// The frame rate of the format. + /// The bit rate of the format. + /// mimeType is invalid(i.e. undefined value). + /// width, height, frameRate or bitRate is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size, + int frameRate, int bitRate) + : base(MediaFormatType.Video) + { + if (!Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType)) + { + throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); + } + if (size.Width < 0) + { + throw new ArgumentOutOfRangeException(nameof(size), size.Width, "Size.Width value can't be less than zero."); + } + if (size.Height < 0) + { + throw new ArgumentOutOfRangeException(nameof(size), size.Height, "Size.Height value can't be less than zero."); + } + if (frameRate < 0) + { + throw new ArgumentOutOfRangeException(nameof(frameRate), frameRate, "Frame rate can't be less than zero."); + } + if (bitRate < 0) + { + throw new ArgumentOutOfRangeException(nameof(bitRate), bitRate, "Bit rate value can't be less than zero."); + } + + MimeType = mimeType; + Size = size; + FrameRate = frameRate; + BitRate = bitRate; + } + + /// + /// Initializes a new instance of the VideoMediaForma class from a native handle. + /// + /// A native handle. + internal VideoMediaFormat(IntPtr handle) + : base(MediaFormatType.Video) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int width = 0; + int height = 0; + int bitRate = 0; + int frameRate = 0; + MediaFormatVideoMimeType mimeType; + GetInfo(handle, out width, out height, out bitRate, out mimeType); + + GetFrameRate(handle, out frameRate); + + MimeType = mimeType; + Size = new Size(width, height); + FrameRate = frameRate; + BitRate = bitRate; + } + + /// + /// Retrieves video properties of media format from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for width. + /// An out parameter for height. + /// An out parameter for bit rate. + /// An out parameter for mime type. + private static void GetInfo(IntPtr handle, out int width, out int height, out int bitRate, + out MediaFormatVideoMimeType mimeType) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int mimeTypeValue = 0; + int maxBps = 0; + + int ret = Interop.MediaFormat.GetVideoInfo(handle, + out mimeTypeValue, out width, out height, out bitRate, out maxBps); + + MultimediaDebug.AssertNoError(ret); + + mimeType = (MediaFormatVideoMimeType)mimeTypeValue; + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType), + "Invalid video mime type!"); + } + + /// + /// Retrieves frame rate from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for frame rate. + private static void GetFrameRate(IntPtr handle, out int frameRate) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int ret = Interop.MediaFormat.GetVideoFrameRate(handle, out frameRate); + + MultimediaDebug.AssertNoError(ret); + } + + internal override void AsNativeHandle(IntPtr handle) + { + Debug.Assert(Type == MediaFormatType.Video); + + int ret = Interop.MediaFormat.SetVideoMimeType(handle, (int)MimeType); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetVideoWidth(handle, Size.Width); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetVideoHeight(handle, Size.Height); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetVideoAverageBps(handle, BitRate); + MultimediaDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetVideoFrameRate(handle, FrameRate); + MultimediaDebug.AssertNoError(ret); + } + + /// + /// Gets the mime type of the current format. + /// + public MediaFormatVideoMimeType MimeType { get; } + + /// + /// Gets the size of the current format. + /// + public Size Size { get; } + + /// + /// Gets the frame rate value of the current format. + /// + public int FrameRate { get; } + + /// + /// Gets the bit rate value of the current format. + /// + public int BitRate { get; } + + public override string ToString() + { + return $@"MimeType={ MimeType.ToString() }, Size=({ Size.ToString() }), FrameRate= + { FrameRate.ToString() }, BitRate={ BitRate.ToString() }"; + } + + public override bool Equals(object obj) + { + var rhs = obj as VideoMediaFormat; + if (rhs == null) + { + return false; + } + + return MimeType == rhs.MimeType && Size == rhs.Size && + FrameRate == rhs.FrameRate && BitRate == rhs.BitRate; + } + + public override int GetHashCode() + { + return new { MimeType, Size, FrameRate, BitRate }.GetHashCode(); + } + } +} diff --git a/src/Tizen.Multimedia/MediaView/MediaView.cs b/src/Tizen.Multimedia/MediaView/MediaView.cs index 41d351a..08e532f 100755 --- a/src/Tizen.Multimedia/MediaView/MediaView.cs +++ b/src/Tizen.Multimedia/MediaView/MediaView.cs @@ -1,3 +1,19 @@ +/* + * 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 ElmSharp; -- 2.7.4