From 4156975c6d4003439061582e9eb3a00529e4fba4 Mon Sep 17 00:00:00 2001 From: Sidharth Gupta Date: Wed, 25 May 2016 17:01:03 +0900 Subject: [PATCH] [AudioManager] Fix AudioStreamPolicy and AudioVolume errors - Setting current volume type to none should unset the current type. - Completed event implementation in AudioStreamPolicy constructor. - sound_manager_set_focus_state_watch_cb() can only be called once. So use "all" mask and filter callback events and invoke. - Removed unnecessary 'using' statements. Signed-off-by: Sidharth Gupta Change-Id: I948760d66a08c3c54d18deef1d1571c415dc9c35 --- src/Tizen.Multimedia/AudioManager/AudioDevice.cs | 4 - .../AudioDeviceConnectionStateChangedEventArgs.cs | 3 - .../AudioDevicePropertyChangedEventArgs.cs | 3 - src/Tizen.Multimedia/AudioManager/AudioManager.cs | 5 +- .../AudioManager/AudioManagerEnumerations.cs | 9 +- .../AudioManager/AudioStreamPolicy.cs | 114 ++++++++------------- .../AudioManager/FocusStateChangedEventArgs.cs | 26 ++--- .../AudioManager/MaxVolumeLevel.cs | 5 +- .../StreamFocusStateChangedEventArgs.cs | 5 +- src/Tizen.Multimedia/AudioManager/Volume.cs | 13 ++- .../AudioManager/VolumeChangedEventArgs.cs | 3 - src/Tizen.Multimedia/AudioManager/VolumeLevel.cs | 9 +- 12 files changed, 66 insertions(+), 133 deletions(-) diff --git a/src/Tizen.Multimedia/AudioManager/AudioDevice.cs b/src/Tizen.Multimedia/AudioManager/AudioDevice.cs index 9d75af5..3d0b5f7 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioDevice.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDevice.cs @@ -1,8 +1,4 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Runtime.InteropServices; diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionStateChangedEventArgs.cs index 10b2fbe..e911707 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionStateChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionStateChangedEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { diff --git a/src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs index 43b761a..46f8875 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { diff --git a/src/Tizen.Multimedia/AudioManager/AudioManager.cs b/src/Tizen.Multimedia/AudioManager/AudioManager.cs index 88292af..64eba84 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioManager.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioManager.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Tizen.Multimedia { @@ -51,7 +48,7 @@ namespace Tizen.Multimedia public static Volume VolumeController { get; - internal set; + private set; } /// diff --git a/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs b/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs index 467b605..b4e1695 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Tizen; -using Tizen.Internals.Errors; - -namespace Tizen.Multimedia +namespace Tizen.Multimedia { /// /// Enumeration for sound device mask. diff --git a/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs b/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs index 4dcd5b9..ddab06f 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { @@ -17,13 +14,11 @@ namespace Tizen.Multimedia private static int _focusStateWatchCounter = 0; private static EventHandler _focusStateWatchForPlayback; - private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchForPlaybackCallback; + private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchCallback; private static EventHandler _focusStateWatchForRecording; - private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchForRecordingCallback; private EventHandler _focusStateChanged; private Interop.SoundStreamFocusStateChangedCallback _focusStateChangedCallback; - - + /// /// Auto focus reacquisition property /// @@ -107,8 +102,8 @@ namespace Tizen.Multimedia _streamType = streamType; _focusStateChangedCallback = (IntPtr streamInfo, int reason, string extraInfo, IntPtr userData) => { - //_focusStateChangedEventArgs = new FocusStateChangedEventArgs(reason, extraInfo); - // _focusStateChanged.Invoke(this, _focusStateChangedEventArgs); + StreamFocusStateChangedEventArgs eventArgs = new StreamFocusStateChangedEventArgs((AudioStreamFocusChangedReason)reason, extraInfo); + _focusStateChanged?.Invoke(this, eventArgs); }; int ret = Interop.StreamPolicy.CreateStreamInformation((int)streamType, _focusStateChangedCallback, IntPtr.Zero, out _streamInfo); @@ -119,7 +114,7 @@ namespace Tizen.Multimedia /// Acquires the stream focus. /// /// The focus mask that user wants to acquire - /// he Extra information for this request (optional, this can be null) + /// 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 /// @@ -205,42 +200,24 @@ namespace Tizen.Multimedia { add { - if (AudioStreamPolicy._focusStateWatchForPlayback == null) + if (_focusStateWatchCounter == 0) { - RegisterPlaybackFocusStateWatchEvent(); + RegisterFocusStateWatchEvent(); } _focusStateWatchCounter++; - AudioStreamPolicy._focusStateWatchForPlayback += value; + _focusStateWatchForPlayback += value; } remove { - AudioStreamPolicy._focusStateWatchForPlayback -= value; + _focusStateWatchForPlayback -= value; _focusStateWatchCounter--; - if (AudioStreamPolicy._focusStateWatchForPlayback == null && _focusStateWatchCounter == 0) + if (_focusStateWatchCounter == 0) { - UnregisterFocusStateWatchForPlaybackEvent(); + UnregisterFocusStateWatch(); } - } - } - - private static void RegisterPlaybackFocusStateWatchEvent() - { - AudioStreamPolicy._focusStateWatchForPlaybackCallback = (AudioStreamFocusOptions options, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData) => - { - FocusStateChangedEventArgs eventArgs = new FocusStateChangedEventArgs(options, focusState, reason, extraInfo); - AudioStreamPolicy._focusStateWatchForPlayback.Invoke(null, eventArgs); - }; - int ret = Interop.StreamPolicy.SetFocusStateWatchCallback(AudioStreamFocusOptions.Playback, AudioStreamPolicy._focusStateWatchForPlaybackCallback, IntPtr.Zero); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set focus state watch callback for playback"); - } - - private static void UnregisterFocusStateWatchForPlaybackEvent() - { - int ret = Interop.StreamPolicy.UnsetFocusStateWatchCallback(); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset focus state watch callback for playback"); - } - + } + /// /// Registers the watch function to be invoked when the focus state for each sound stream type is changed regardless of the process. /// @@ -251,40 +228,51 @@ namespace Tizen.Multimedia { add { - if (AudioStreamPolicy._focusStateWatchForRecording == null) + if (_focusStateWatchCounter == 0) { - RegisterRecordingFocusStateWatchEvent(); + RegisterFocusStateWatchEvent(); } _focusStateWatchCounter++; - AudioStreamPolicy._focusStateWatchForRecording += value; + _focusStateWatchForRecording += value; } remove { - AudioStreamPolicy._focusStateWatchForRecording -= value; + _focusStateWatchForRecording -= value; _focusStateWatchCounter--; - if (AudioStreamPolicy._focusStateWatchForRecording == null && _focusStateWatchCounter == 0) + if (_focusStateWatchCounter == 0) { - UnregisterFocusStateWatchForRecordingEvent(); + UnregisterFocusStateWatch(); } - } } - private static void RegisterRecordingFocusStateWatchEvent() + private static void RegisterFocusStateWatchEvent() { - AudioStreamPolicy._focusStateWatchForRecordingCallback = (AudioStreamFocusOptions options, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData) => - { - FocusStateChangedEventArgs eventArgs = new FocusStateChangedEventArgs(options, focusState, reason, extraInfo); - AudioStreamPolicy._focusStateWatchForRecording.Invoke(null, eventArgs); - }; - int ret = Interop.StreamPolicy.SetFocusStateWatchCallback(AudioStreamFocusOptions.Recording, AudioStreamPolicy._focusStateWatchForRecordingCallback, IntPtr.Zero); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set focus state watch callback for recording"); + _focusStateWatchCallback = (AudioStreamFocusOptions options, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData) => + { + FocusStateChangedEventArgs eventArgs = new FocusStateChangedEventArgs(focusState, reason, extraInfo); + if (options == AudioStreamFocusOptions.Playback) + { + _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); + } + }; + int ret = Interop.StreamPolicy.SetFocusStateWatchCallback(AudioStreamFocusOptions.Playback | AudioStreamFocusOptions.Recording, _focusStateWatchCallback, IntPtr.Zero); + AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set focus state watch callback"); } - private static void UnregisterFocusStateWatchForRecordingEvent() + private static void UnregisterFocusStateWatch() { - int ret = Interop.StreamPolicy.UnsetFocusStateWatchCallback(); - AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset focus state watch callback for recording"); + int ret = Interop.StreamPolicy.UnsetFocusStateWatchCallback(); + AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset focus state watch callback"); } /// @@ -298,32 +286,14 @@ namespace Tizen.Multimedia { add { - if (_focusStateChanged == null) - { - RegisterFocusStateChangedEvent(); - } _focusStateChanged += value; } remove { _focusStateChanged -= value; - } - - } - - public void RegisterFocusStateChangedEvent() - { - _focusStateChangedCallback = (IntPtr streamInfo, int reason, string extraInfo, IntPtr userData) => - { - StreamFocusStateChangedEventArgs eventArgs = new StreamFocusStateChangedEventArgs((AudioStreamFocusChangedReason)reason, extraInfo); - _focusStateChanged.Invoke(this, eventArgs); - }; - } - - ~AudioStreamPolicy() { Dispose(false); diff --git a/src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs index dc90e1e..a0aa765 100644 --- a/src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { @@ -10,50 +7,47 @@ namespace Tizen.Multimedia /// public class FocusStateChangedEventArgs : EventArgs { - private AudioStreamFocusOptions _focusMask; private AudioStreamFocusState _focusState; private AudioStreamFocusChangedReason _reason; private string _extraInformation; - internal FocusStateChangedEventArgs(AudioStreamFocusOptions focusMask, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInformation) + internal FocusStateChangedEventArgs(AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInformation) { - _focusMask = focusMask; _focusState = focusState; _reason = reason; _extraInformation = extraInformation; } /// - /// The changed focus mask + /// The changed focus state /// - public AudioStreamFocusOptions FocusMask + public AudioStreamFocusState FocusState { get { - return _focusMask; + return _focusState; } - } /// - /// The changed focus state + /// The reason for state change of the focus /// - public AudioStreamFocusState FocusState + public AudioStreamFocusChangedReason FocusChangedReason { get { - return _focusState; + return _reason; } } /// - /// The reason for state change of the focus + /// The extra information /// - public AudioStreamFocusChangedReason FocusChangedReason + public string ExtraInformation { get { - return _reason; + return _extraInformation; } } } diff --git a/src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs b/src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs index bd9a58c..2b65f55 100644 --- a/src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs +++ b/src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { @@ -15,7 +12,7 @@ namespace Tizen.Multimedia int ret = Interop.Volume.GetMaxVolume(type, out maxVolume); if (ret != 0) { - AudioManagerErrorFactory.CheckAndThrowException(ret, "unable to get max volume"); + AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to get max volume"); Console.WriteLine("Max Volume Error: " + (AudioManagerError)ret); } diff --git a/src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs index 5e0e2b5..8e8ddc0 100644 --- a/src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { @@ -34,7 +31,7 @@ namespace Tizen.Multimedia /// /// The extra information /// - public string ExtraInfo + public string ExtraInfoformation { get { diff --git a/src/Tizen.Multimedia/AudioManager/Volume.cs b/src/Tizen.Multimedia/AudioManager/Volume.cs index cbc12c8..a8c5278 100644 --- a/src/Tizen.Multimedia/AudioManager/Volume.cs +++ b/src/Tizen.Multimedia/AudioManager/Volume.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { @@ -36,10 +33,16 @@ namespace Tizen.Multimedia } set - { + { int ret = Interop.Volume.SetCurrentSoundType(value); + if (ret != 0) + { + if (value == AudioType.None) + { + ret = Interop.Volume.UnsetCurrentType(); + } + } AudioManagerErrorFactory.CheckAndThrowException(ret, "unable to set current sound type"); - } } diff --git a/src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs index dea5b95..65edae4 100644 --- a/src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { diff --git a/src/Tizen.Multimedia/AudioManager/VolumeLevel.cs b/src/Tizen.Multimedia/AudioManager/VolumeLevel.cs index 8df2341..4bfa6a7 100644 --- a/src/Tizen.Multimedia/AudioManager/VolumeLevel.cs +++ b/src/Tizen.Multimedia/AudioManager/VolumeLevel.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tizen.Multimedia { @@ -15,7 +12,7 @@ namespace Tizen.Multimedia int ret = Interop.Volume.GetVolume(type, out volume); if (ret != 0) { - AudioManagerErrorFactory.CheckAndThrowException(ret, "unable to get volume"); + AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to get volume"); Console.WriteLine("Get Volume Error: " + (AudioManagerError)ret); } @@ -26,12 +23,10 @@ namespace Tizen.Multimedia int ret = Interop.Volume.SetVolume(type, value); if (ret != 0) { - AudioManagerErrorFactory.CheckAndThrowException(ret, "unable to set volume"); + AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set volume"); Console.WriteLine("Set Volume Error: " + (AudioManagerError)ret); } } - - } } } -- 2.7.4