[AudioManager] Fix AudioStreamPolicy and AudioVolume errors
authorSidharth Gupta <sid92.gupta@samsung.com>
Wed, 25 May 2016 08:01:03 +0000 (17:01 +0900)
committerSidharth Gupta <sid92.gupta@samsung.com>
Wed, 25 May 2016 11:17:52 +0000 (20:17 +0900)
- 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 <sid92.gupta@samsung.com>
Change-Id: I948760d66a08c3c54d18deef1d1571c415dc9c35

12 files changed:
src/Tizen.Multimedia/AudioManager/AudioDevice.cs
src/Tizen.Multimedia/AudioManager/AudioDeviceConnectionStateChangedEventArgs.cs
src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs
src/Tizen.Multimedia/AudioManager/AudioManager.cs
src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs
src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs
src/Tizen.Multimedia/AudioManager/FocusStateChangedEventArgs.cs
src/Tizen.Multimedia/AudioManager/MaxVolumeLevel.cs
src/Tizen.Multimedia/AudioManager/StreamFocusStateChangedEventArgs.cs
src/Tizen.Multimedia/AudioManager/Volume.cs
src/Tizen.Multimedia/AudioManager/VolumeChangedEventArgs.cs
src/Tizen.Multimedia/AudioManager/VolumeLevel.cs

index 9d75af5..3d0b5f7 100644 (file)
@@ -1,8 +1,4 @@
 using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 using System.Runtime.InteropServices;
 
 
index 88292af..64eba84 100644 (file)
@@ -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;
         }
 
         /// <summary>
index 467b605..b4e1695 100644 (file)
@@ -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
 {    
     /// <summary>
     /// Enumeration for sound device mask.
index 4dcd5b9..ddab06f 100644 (file)
@@ -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<FocusStateChangedEventArgs> _focusStateWatchForPlayback;
-        private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchForPlaybackCallback;
+        private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchCallback;
         private static EventHandler<FocusStateChangedEventArgs> _focusStateWatchForRecording;
-        private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchForRecordingCallback;
         private EventHandler<StreamFocusStateChangedEventArgs> _focusStateChanged;
         private Interop.SoundStreamFocusStateChangedCallback _focusStateChangedCallback;
-         
-
+\r
         /// <summary>
         /// Auto focus reacquisition property
         /// </summary>
@@ -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.
         /// </summary>
         /// <param name="focusMask">The focus mask that user wants to acquire</param>
-        /// <param name="?">he Extra information for this request (optional, this can be null)</param>
+        /// <param name="extraInformation">The Extra information for this request (optional, this can be null)</param>
         /// <remarks>
         /// Do not call this API within event handlers of FocuStateChanged and StreamFocusStateWatch else it will throw and exception
         /// </remarks>
@@ -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");
-        }
-
+        }\r
+\r
         /// <summary>
         /// Registers the watch function to be invoked when the focus state for each sound stream type is changed regardless of the process.
         /// <remarks> 
@@ -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)\r
+                    {\r
+                        _focusStateWatchForPlayback?.Invoke(null, eventArgs);\r
+                    }
+                    else if (options == AudioStreamFocusOptions.Recording)\r
+                    {\r
+                        _focusStateWatchForRecording?.Invoke(null, eventArgs);\r
+                    }\r
+                    else if (options == (AudioStreamFocusOptions.Playback | AudioStreamFocusOptions.Recording))\r
+                    {\r
+                        _focusStateWatchForPlayback?.Invoke(null, eventArgs);\r
+                        _focusStateWatchForRecording?.Invoke(null, eventArgs);\r
+                    }
+                };
+            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();\r
+            AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset focus state watch callback");
         }
 
         /// <summary>
@@ -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);
index dc90e1e..a0aa765 100644 (file)
@@ -1,7 +1,4 @@
 using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
 \r
 namespace Tizen.Multimedia\r
 {\r
@@ -10,50 +7,47 @@ namespace Tizen.Multimedia
     /// </summary>\r
     public class FocusStateChangedEventArgs : EventArgs\r
     {\r
-        private AudioStreamFocusOptions _focusMask;\r
         private AudioStreamFocusState _focusState;\r
         private AudioStreamFocusChangedReason _reason;\r
         private string _extraInformation;\r
 \r
-        internal FocusStateChangedEventArgs(AudioStreamFocusOptions focusMask, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInformation)\r
+        internal FocusStateChangedEventArgs(AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInformation)\r
         {\r
-            _focusMask = focusMask;\r
             _focusState = focusState;\r
             _reason = reason;\r
             _extraInformation = extraInformation;\r
         }\r
 \r
         /// <summary>\r
-        /// The changed focus mask\r
+        /// The changed focus state\r
         /// </summary>\r
-        public AudioStreamFocusOptions FocusMask\r
+        public AudioStreamFocusState FocusState \r
         {\r
             get\r
             {\r
-                return _focusMask;\r
+                return _focusState;\r
             }\r
-\r
         }\r
 \r
         /// <summary>\r
-        /// The changed focus state\r
+        /// The reason for state change of the focus\r
         /// </summary>\r
-        public AudioStreamFocusState FocusState \r
+        public AudioStreamFocusChangedReason FocusChangedReason \r
         {\r
             get\r
             {\r
-                return _focusState;\r
+                return _reason;\r
             }\r
         }\r
 \r
         /// <summary>\r
-        /// The reason for state change of the focus\r
+        /// The extra information\r
         /// </summary>\r
-        public AudioStreamFocusChangedReason FocusChangedReason \r
+        public string ExtraInformation\r
         {\r
             get\r
             {\r
-                return _reason;\r
+                return _extraInformation;\r
             }\r
         }\r
     }\r
index bd9a58c..2b65f55 100644 (file)
@@ -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);
                 }
 
index 5e0e2b5..8e8ddc0 100644 (file)
@@ -1,7 +1,4 @@
 using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
 \r
 namespace Tizen.Multimedia\r
 {\r
@@ -34,7 +31,7 @@ namespace Tizen.Multimedia
         /// <summary>\r
         /// The extra information\r
         /// </summary>\r
-        public string ExtraInfo \r
+        public string ExtraInfoformation\r
         {\r
             get\r
             {\r
index cbc12c8..a8c5278 100644 (file)
@@ -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)\r
+                {\r
+                    if (value == AudioType.None)\r
+                    {\r
+                        ret = Interop.Volume.UnsetCurrentType();\r
+                    }\r
+                }
                 AudioManagerErrorFactory.CheckAndThrowException(ret, "unable to set current sound type");
-
             } 
         }
 
index dea5b95..65edae4 100644 (file)
@@ -1,7 +1,4 @@
 using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
 \r
 namespace Tizen.Multimedia\r
 {\r
index 8df2341..4bfa6a7 100644 (file)
@@ -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);
                 }               
             }
-
-
         } 
     }
 }