[Audio] Use Add/Remove callback CAPI instead of deprecated set/unset API
authorJeongho Mok <jho.mok@samsung.com>
Wed, 28 Dec 2016 08:20:14 +0000 (17:20 +0900)
committerJeongho Mok <jho.mok@samsung.com>
Wed, 28 Dec 2016 12:31:26 +0000 (21:31 +0900)
Change-Id: I553580c8ee01927a445caf5274a4179116017a9e

src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs [moved from src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs with 75% similarity]
src/Tizen.Multimedia/AudioManager/AudioManager.cs
src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs
src/Tizen.Multimedia/AudioManager/AudioVolume.cs
src/Tizen.Multimedia/Interop/Interop.Device.cs
src/Tizen.Multimedia/Interop/Interop.Volume.cs
src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj
src/Tizen.Multimedia/Tizen.Multimedia.csproj

@@ -21,12 +21,12 @@ namespace Tizen.Multimedia
     /// <summary>\r
     /// Class extending EventArgs which contains parameters to be passed to event handler of DeviceInformationChanged event\r
     /// </summary>\r
-    public class AudioDevicePropertyChangedEventArgs : EventArgs\r
+    public class AudioDeviceStateChangedEventArgs : EventArgs\r
     {\r
-        internal AudioDevicePropertyChangedEventArgs(AudioDevice device, AudioDeviceProperty changedInfo)\r
+        internal AudioDeviceStateChangedEventArgs(AudioDevice device, AudioDeviceState changedState)\r
         {\r
             Device = device;\r
-            ChangedInfo = changedInfo;\r
+            ChangedState = changedState;\r
         }\r
 \r
         /// <summary>\r
@@ -35,8 +35,8 @@ namespace Tizen.Multimedia
         public AudioDevice Device { get; }\r
 \r
         /// <summary>\r
-        /// The entry of sound device information\r
+        /// The entry of sound device state\r
         /// </summary>\r
-        public AudioDeviceProperty ChangedInfo { get; }\r
+        public AudioDeviceState ChangedState { get; }\r
     }\r
 }\r
index 411db5b..15a0f74 100644 (file)
@@ -29,27 +29,14 @@ namespace Tizen.Multimedia
     /// </summary>
     public static class AudioManager
     {
-        private static int _deviceConnectedCounter = 0;
-        private static int _deviceInformationChanged = 0;
+        private static int _deviceConnectionChangedCallbackId = -1;
+        private static int _deviceStateChangedCallbackId = -1;
 
-        private static Interop.SoundDeviceConnectedCallback _audioDeviceConnectedCallback;
-        private static Interop.SoundDeviceInformationChangedCallback _audioDeviceInformationChangedCallback;
+        private static Interop.SoundDeviceConnectionChangedCallback _audioDeviceConnectionChangedCallback;
+        private static Interop.SoundDeviceStateChangedCallback _audioDeviceStateChangedCallback;
 
-        private static EventHandler<AudioDeviceConnectionChangedEventArgs> _audioDeviceConnected;
-        private static EventHandler<AudioDeviceConnectionChangedEventArgs> _stateActivatedDeviceConnected;
-        private static EventHandler<AudioDeviceConnectionChangedEventArgs> _stateDeactivatedDeviceConnected;
-        private static EventHandler<AudioDeviceConnectionChangedEventArgs> _typeExternalDeviceConnected;
-        private static EventHandler<AudioDeviceConnectionChangedEventArgs> _typeInternalDeviceConnected;
-        private static EventHandler<AudioDeviceConnectionChangedEventArgs> _ioDirectionInDeviceConnected;
-        private static EventHandler<AudioDeviceConnectionChangedEventArgs> _ioDirectionOutDeviceConnected;
-
-        private static EventHandler<AudioDevicePropertyChangedEventArgs> _audioDeviceInformationChanged;
-        private static EventHandler<AudioDevicePropertyChangedEventArgs> _stateActivatedDeviceInformationChanged;
-        private static EventHandler<AudioDevicePropertyChangedEventArgs> _stateDeactivatedDeviceInformationChanged;
-        private static EventHandler<AudioDevicePropertyChangedEventArgs> _typeExternalDeviceInformationChanged;
-        private static EventHandler<AudioDevicePropertyChangedEventArgs> _typeInternalDeviceInformationChanged;
-        private static EventHandler<AudioDevicePropertyChangedEventArgs> _ioDirectionInDeviceInformationChanged;
-        private static EventHandler<AudioDevicePropertyChangedEventArgs> _ioDirectionOutDeviceInformationChanged;
+        private static EventHandler<AudioDeviceConnectionChangedEventArgs> _audioDeviceConnectionChanged;
+        private static EventHandler<AudioDeviceStateChangedEventArgs> _audioDeviceStateChanged;
 
         /// <summary>
         /// Constructor for AudioManager. Initializes the VolumeController property etc.
@@ -66,375 +53,47 @@ namespace Tizen.Multimedia
         {
             add
             {
-                if (_audioDeviceConnected == null)
+                if (_audioDeviceConnectionChanged == null)
                 {
-                    RegisterAudioDeviceEvent(AudioDeviceOptions.All);
+                    RegisterAudioDeviceEvent();
                     Tizen.Log.Info(AudioManagerLog.Tag, "DeviceConnectionChanged event registered");
                 }
-                _deviceConnectedCounter++;
-                _audioDeviceConnected += value;
+                _audioDeviceConnectionChanged += value;
                 Tizen.Log.Info(AudioManagerLog.Tag, "DeviceConnectionChanged event added");
             }
             remove
             {
-                _deviceConnectedCounter--;
-                _audioDeviceConnected -= value;
-                if (_deviceConnectedCounter == 0)
+                if (_audioDeviceConnectionChanged?.GetInvocationList()?.GetLength(0) == 1)
                 {
-                    UnregisterDeviceConnectedEvent();
+                    UnregisterDeviceConnectionChangedEvent();
                 }
+                _audioDeviceConnectionChanged -= value;
                 Tizen.Log.Info(AudioManagerLog.Tag, "DeviceConnectionChanged event removed");
             }
         }
 
         /// <summary>
-        /// Registers/Unregisters a function to be invoked when the connection of an activated audio device is changed.
+        /// Registers/Unregisters a callback function to be invoked when the state of an Audio sound device was changed.
         /// </summary>
-        public static event EventHandler<AudioDeviceConnectionChangedEventArgs> ActivatedDeviceConnectionChanged
+        public static event EventHandler<AudioDeviceStateChangedEventArgs> DeviceStateChanged
         {
             add
             {
-                if (_stateActivatedDeviceConnected == null)
+                if (_audioDeviceStateChanged == null)
                 {
-                    RegisterAudioDeviceEvent(AudioDeviceOptions.Activated);
+                    RegisterDeviceStateChangedEvent();
                 }
-                _deviceConnectedCounter++;
-                _stateActivatedDeviceConnected += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "ActivatedDeviceConnectionChanged event added");
+                _audioDeviceStateChanged += value;
+                Tizen.Log.Info(AudioManagerLog.Tag, "DeviceStateChanged event added");
             }
             remove
             {
-                _deviceConnectedCounter--;
-                _stateActivatedDeviceConnected -= value;
-                if (_deviceConnectedCounter == 0)
+                if (_audioDeviceStateChanged?.GetInvocationList()?.GetLength(0) == 1)
                 {
-                    UnregisterDeviceConnectedEvent();
+                    UnregisterDeviceStateChangedEvent();
                 }
-                Tizen.Log.Info(AudioManagerLog.Tag, "ActivatedDeviceConnectionChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a function to be invoked when the connection of an deactivated audio device is changed
-        /// </summary>
-        public static event EventHandler<AudioDeviceConnectionChangedEventArgs> DeactivatedDeviceConnectionChanged
-        {
-            add
-            {
-                if (_stateDeactivatedDeviceConnected == null)
-                {
-                    RegisterAudioDeviceEvent(AudioDeviceOptions.Deactivated);
-                }
-                _deviceConnectedCounter++;
-                _stateDeactivatedDeviceConnected += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "DeactivatedDeviceConnectionChanged event added");
-            }
-            remove
-            {
-                _deviceConnectedCounter--;
-                _stateDeactivatedDeviceConnected -= value;
-                if (_deviceConnectedCounter == 0)
-                {
-                    UnregisterDeviceConnectedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "DeactivatedDeviceConnectionChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a function to be invoked when the connection of an external audio device is changed
-        /// </summary>
-        public static event EventHandler<AudioDeviceConnectionChangedEventArgs> ExternalDeviceConnectionChanged
-        {
-            add
-            {
-                if (_typeExternalDeviceConnected == null)
-                {
-                    RegisterAudioDeviceEvent(AudioDeviceOptions.External);
-                }
-                _deviceConnectedCounter++;
-                _typeExternalDeviceConnected += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "ExternalDeviceConnectionChanged event added");
-            }
-            remove
-            {
-                _deviceConnectedCounter--;
-                _typeExternalDeviceConnected -= value;
-                if (_deviceConnectedCounter == 0)
-                {
-                    UnregisterDeviceConnectedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "ExternalDeviceConnectionChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a function to be invoked when the connection of an internal audio device is changed
-        /// </summary>
-        public static event EventHandler<AudioDeviceConnectionChangedEventArgs> InternalDeviceConnectionChanged
-        {
-            add
-            {
-                if (_typeInternalDeviceConnected == null)
-                {
-                    RegisterAudioDeviceEvent(AudioDeviceOptions.Internal);
-                }
-                _deviceConnectedCounter++;
-                _typeInternalDeviceConnected += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "InternalDeviceConnectionChanged event added");
-            }
-            remove
-            {
-                _deviceConnectedCounter--;
-                _typeInternalDeviceConnected -= value;
-                if (_deviceConnectedCounter == 0)
-                {
-                    UnregisterDeviceConnectedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "InternalDeviceConnectionChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a function to be invoked when the connection of an input audio device is changed.
-        /// </summary>
-        public static event EventHandler<AudioDeviceConnectionChangedEventArgs> InputDeviceConnectionChanged
-        {
-            add
-            {
-                if (_ioDirectionInDeviceConnected == null)
-                {
-                    RegisterAudioDeviceEvent(AudioDeviceOptions.Input);
-                }
-                _deviceConnectedCounter++;
-                _ioDirectionInDeviceConnected += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "InputDeviceConnectionChanged event added");
-            }
-            remove
-            {
-                _deviceConnectedCounter--;
-                _ioDirectionInDeviceConnected -= value;
-                if (_deviceConnectedCounter == 0)
-                {
-                    UnregisterDeviceConnectedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "InputDeviceConnectionChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a function to be invoked when the connection of an output audio device is changed
-        /// </summary>
-        public static event EventHandler<AudioDeviceConnectionChangedEventArgs> OutputDeviceConnectionChanged
-        {
-            add
-            {
-                if (_ioDirectionOutDeviceConnected == null)
-                {
-                    RegisterAudioDeviceEvent(AudioDeviceOptions.Output);
-                }
-                _deviceConnectedCounter++;
-                _ioDirectionOutDeviceConnected += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "OutputDeviceConnectionChanged event added");
-            }
-            remove
-            {
-                _deviceConnectedCounter--;
-                _ioDirectionOutDeviceConnected -= value;
-                if (_deviceConnectedCounter == 0)
-                {
-                    UnregisterDeviceConnectedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "OutputDeviceConnectionChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a callback function to be invoked when the property of an Audio sound device was changed.
-        /// </summary>
-        public static event EventHandler<AudioDevicePropertyChangedEventArgs> DevicePropertyChanged
-        {
-            add
-            {
-                if (_audioDeviceInformationChanged == null)
-                {
-                    RegisterDeviceInformationChangedEvent(AudioDeviceOptions.All);
-                }
-                _deviceInformationChanged++;
-                _audioDeviceInformationChanged += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "DevicePropertyChanged event added");
-            }
-            remove
-            {
-                _deviceInformationChanged--;
-                _audioDeviceInformationChanged -= value;
-                if (_deviceInformationChanged == 0)
-                {
-                    UnregisterDeviceInformationChangedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "DevicePropertyChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a callback function to be invoked when the property of a activated audio device was changed.
-        /// </summary>
-        public static event EventHandler<AudioDevicePropertyChangedEventArgs> ActivatedDevicePropertyChanged
-        {
-            add
-            {
-                if (_stateActivatedDeviceInformationChanged == null)
-                {
-                    RegisterDeviceInformationChangedEvent(AudioDeviceOptions.Activated);
-                }
-                _deviceInformationChanged++;
-                _stateActivatedDeviceInformationChanged += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "ActivatedDevicePropertyChanged event added");
-            }
-            remove
-            {
-                _deviceInformationChanged--;
-                _stateActivatedDeviceInformationChanged -= value;
-                if (_deviceInformationChanged == 0)
-                {
-                    UnregisterDeviceInformationChangedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "ActivatedDevicePropertyChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a callback function to be invoked when the property of a deactivated audio device was changed.
-        /// </summary>
-        public static event EventHandler<AudioDevicePropertyChangedEventArgs> DeactivatedDevicePropertyChanged
-        {
-            add
-            {
-                if (_stateDeactivatedDeviceInformationChanged == null)
-                {
-                    RegisterDeviceInformationChangedEvent(AudioDeviceOptions.Deactivated);
-                }
-                _deviceInformationChanged++;
-                _stateDeactivatedDeviceInformationChanged += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "DeactivatedDevicePropertyChanged event added");
-            }
-            remove
-            {
-                _deviceInformationChanged--;
-                _stateDeactivatedDeviceInformationChanged -= value;
-                if (_deviceInformationChanged == 0)
-                {
-                    UnregisterDeviceInformationChangedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "DeactivatedDeviceProperty Changed event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a callback function to be invoked when the property of a external audio device was changed.
-        /// </summary>
-        public static event EventHandler<AudioDevicePropertyChangedEventArgs> ExternalDevicePropertyChanged
-        {
-            add
-            {
-                if (_typeExternalDeviceInformationChanged == null)
-                {
-                    RegisterDeviceInformationChangedEvent(AudioDeviceOptions.External);
-                }
-                _deviceInformationChanged++;
-                _typeExternalDeviceInformationChanged += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "ExternalDevicePropertyChanged event added");
-            }
-            remove
-            {
-                _deviceInformationChanged--;
-                _typeExternalDeviceInformationChanged -= value;
-                if (_deviceInformationChanged == 0)
-                {
-                    UnregisterDeviceInformationChangedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "ExternalDevicePropertyChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a callback function to be invoked when the property of a internal audio device was changed.
-        /// </summary>
-        public static event EventHandler<AudioDevicePropertyChangedEventArgs> InternalDevicePropertyChanged
-        {
-            add
-            {
-                if (_typeInternalDeviceInformationChanged == null)
-                {
-                    RegisterDeviceInformationChangedEvent(AudioDeviceOptions.Internal);
-                }
-                _deviceInformationChanged++;
-                _typeInternalDeviceInformationChanged += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "InternalDevicePropertyChanged event added");
-            }
-            remove
-            {
-                _deviceInformationChanged--;
-                _typeInternalDeviceInformationChanged -= value;
-                if (_deviceInformationChanged == 0)
-                {
-                    UnregisterDeviceInformationChangedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "InternalDevicePropertyChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a callback function to be invoked when the property of a input audio device was changed.
-        /// </summary>
-        public static event EventHandler<AudioDevicePropertyChangedEventArgs> InputDevicePropertyChanged
-        {
-            add
-            {
-                if (_ioDirectionInDeviceInformationChanged == null)
-                {
-                    RegisterDeviceInformationChangedEvent(AudioDeviceOptions.Input);
-                }
-                _deviceInformationChanged++;
-                _ioDirectionInDeviceInformationChanged += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "InputDevicePropertyChanged event added");
-            }
-            remove
-            {
-                _deviceInformationChanged--;
-                _ioDirectionInDeviceInformationChanged -= value;
-                if (_deviceInformationChanged == 0)
-                {
-                    UnregisterDeviceInformationChangedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "InputDevicePropertyChanged event removed");
-            }
-        }
-
-        /// <summary>
-        /// Registers/Unregisters a callback function to be invoked when the property of a output audio device was changed.
-        /// </summary>
-        public static event EventHandler<AudioDevicePropertyChangedEventArgs> OutputDevicePropertyChanged
-        {
-            add
-            {
-                if (_ioDirectionOutDeviceInformationChanged == null)
-                {
-                    RegisterDeviceInformationChangedEvent(AudioDeviceOptions.Output);
-                }
-                _deviceInformationChanged++;
-                _ioDirectionOutDeviceInformationChanged += value;
-                Tizen.Log.Info(AudioManagerLog.Tag, "OutputDevicePropertyChanged event added");
-            }
-            remove
-            {
-                _deviceInformationChanged--;
-                _ioDirectionOutDeviceInformationChanged -= value;
-                if (_deviceInformationChanged == 0)
-                {
-                    UnregisterDeviceInformationChangedEvent();
-                }
-                Tizen.Log.Info(AudioManagerLog.Tag, "OutputDevicePropertyChanged event removed");
+                _audioDeviceStateChanged -= value;
+                Tizen.Log.Info(AudioManagerLog.Tag, "DeviceStateChanged event removed");
             }
         }
 
@@ -473,98 +132,50 @@ namespace Tizen.Multimedia
             return audioDeviceList;
         }
 
-        private static void RegisterAudioDeviceEvent(AudioDeviceOptions option)
+        private static void RegisterAudioDeviceEvent()
         {
-            _audioDeviceConnectedCallback = (IntPtr device, bool isConnected, IntPtr userData) =>
+            _audioDeviceConnectionChangedCallback = (IntPtr device, bool isConnected, IntPtr userData) =>
             {
-                int audioOption = (int) userData;
-
                 AudioDeviceConnectionChangedEventArgs eventArgs = new AudioDeviceConnectionChangedEventArgs(new AudioDevice(device), isConnected);
-
-                switch ((AudioDeviceOptions)audioOption)
-                {
-                    case AudioDeviceOptions.All:
-                        _audioDeviceConnected?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Activated:
-                        _stateActivatedDeviceConnected?.Invoke(null, eventArgs); ;
-                        break;
-                    case AudioDeviceOptions.Deactivated:
-                        _stateDeactivatedDeviceConnected?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.External:
-                        _typeExternalDeviceConnected?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Internal:
-                        _typeInternalDeviceConnected?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Input:
-                        _ioDirectionInDeviceConnected?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Output:
-                        _ioDirectionOutDeviceConnected?.Invoke(null, eventArgs);
-                        break;
-                    default:
-                        return;
-                }
+                _audioDeviceConnectionChanged?.Invoke(null, eventArgs);
             };
-            int ret = Interop.AudioDevice.SetDeviceConnectedCallback(option, _audioDeviceConnectedCallback, (IntPtr) option);
-            AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set device connected callback");
-            Tizen.Log.Info(AudioManagerLog.Tag, "AudioDeviceConnected Event registered");
+            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 RegisterDeviceInformationChangedEvent(AudioDeviceOptions option)
+        private static void RegisterDeviceStateChangedEvent()
         {
-            _audioDeviceInformationChangedCallback = (IntPtr device, AudioDeviceProperty property, IntPtr userData) =>
+            _audioDeviceStateChangedCallback = (IntPtr device, AudioDeviceState changedState, IntPtr userData) =>
             {
-                int audioOption = (int)userData;
-
-                AudioDevicePropertyChangedEventArgs eventArgs = new AudioDevicePropertyChangedEventArgs(new AudioDevice(device), property);
-
-                switch ((AudioDeviceOptions)audioOption)
-                {
-                    case AudioDeviceOptions.All:
-                        _audioDeviceInformationChanged?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Activated:
-                        _stateActivatedDeviceInformationChanged?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Deactivated:
-                        _stateDeactivatedDeviceInformationChanged?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.External:
-                        _typeExternalDeviceInformationChanged?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Internal:
-                        _typeInternalDeviceInformationChanged?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Input:
-                        _ioDirectionInDeviceInformationChanged?.Invoke(null, eventArgs);
-                        break;
-                    case AudioDeviceOptions.Output:
-                        _ioDirectionOutDeviceInformationChanged?.Invoke(null, eventArgs);
-                        break;
-                    default:
-                        return;
-                }
+                AudioDeviceStateChangedEventArgs eventArgs = new AudioDeviceStateChangedEventArgs(new AudioDevice(device), changedState);
+                _audioDeviceStateChanged?.Invoke(null, eventArgs);
             };
-            int ret = Interop.AudioDevice.SetDeviceInformationChangedCallback(option, _audioDeviceInformationChangedCallback, (IntPtr) option);
-            AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set device property changed callback");
-            Tizen.Log.Info(AudioManagerLog.Tag, "AudioDevicePropertyChangedEvent callback registered");
+            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 UnregisterDeviceConnectedEvent()
+        private static void UnregisterDeviceConnectionChangedEvent()
         {
-            int ret = Interop.AudioDevice.UnsetDeviceConnectedCallback();
-            AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset device connected callback");
-            Tizen.Log.Info(AudioManagerLog.Tag, "AudioDeviceConnectedEvent callback unregistered");
+            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;
+            }
         }
 
-        private static void UnregisterDeviceInformationChangedEvent()
+        private static void UnregisterDeviceStateChangedEvent()
         {
-            int ret = Interop.AudioDevice.UnsetDeviceInformationChangedCallback();
-            AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset device property changed callback");
-            Tizen.Log.Info(AudioManagerLog.Tag, "AudioDevicePropertyChanged callback unregistered");
+            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;
+            }
         }
     }
 }
index 34d06c9..3e75e9a 100644 (file)
@@ -77,9 +77,9 @@ namespace Tizen.Multimedia
         /// </summary>
         AudioJack,
         /// <summary>
-        /// Bluetooth
+        /// Bluetooth Media (A2DP)
         /// </summary>
-        Bluetooth,
+        BluetoothMedia,
         /// <summary>
         /// HDMI
         /// </summary>
@@ -91,7 +91,11 @@ namespace Tizen.Multimedia
         /// <summary>
         /// USB Audio
         /// </summary>
-        UsbAudio
+        UsbAudio,
+        /// <summary>
+        /// Bluetooth Voice (SCO)
+        /// </summary>
+        BluetoothVoice
     }
 
     /// <summary>
@@ -129,21 +133,6 @@ namespace Tizen.Multimedia
     }
 
     /// <summary>
-    /// Enumeration for changed property of audio device.
-    /// </summary>
-    public enum AudioDeviceProperty
-    {
-        /// <summary>
-        /// State of the device was changed
-        /// </summary>
-        State,
-        /// <summary>
-        /// IO direction of the device was changed
-        /// </summary>
-        IoDirection
-    }
-
-    /// <summary>
     /// Enumeration for audio type.
     /// </summary>
     public enum AudioVolumeType
index 0e0da46..3ad9abd 100644 (file)
@@ -28,6 +28,7 @@ namespace Tizen.Multimedia
     /// </summary>
     public class AudioVolume
     {
+        private static int _volumeChangedCallbackId = -1;
         private EventHandler<VolumeChangedEventArgs> _volumeChanged;
         private Interop.SoundManagerVolumeChangedCallback _volumeChangedCallback;
 
@@ -50,10 +51,10 @@ namespace Tizen.Multimedia
             }
             remove {
                 Tizen.Log.Info(AudioVolumeLog.Tag, "VolumeController Changed Event removed....");
-                _volumeChanged -= value;
-                if(_volumeChanged == null) {
+                if(_volumeChanged?.GetInvocationList()?.GetLength(0) == 1) {
                     UnregisterVolumeChangedEvent();
                 }
+                _volumeChanged -= value;
             }
         }
 
@@ -98,16 +99,18 @@ namespace Tizen.Multimedia
                 VolumeChangedEventArgs eventArgs = new VolumeChangedEventArgs(type, volume);
                 _volumeChanged.Invoke(this, eventArgs);
             };
-            int error = Interop.AudioVolume.SetVolumeChangedCallback(_volumeChangedCallback, IntPtr.Zero);
+            int error = Interop.AudioVolume.AddVolumeChangedCallback(_volumeChangedCallback, IntPtr.Zero, out _volumeChangedCallbackId);
             Tizen.Log.Info(AudioVolumeLog.Tag, "VolumeController Changed Event return:" + error);
-            AudioManagerErrorFactory.CheckAndThrowException(error, "unable to set level changed callback");
+            AudioManagerErrorFactory.CheckAndThrowException(error, "unable to add level changed callback");
         }
 
         private void UnregisterVolumeChangedEvent()
         {
-            int error = Interop.AudioVolume.UnsetVolumeChangedCallback();
-            Tizen.Log.Info(AudioVolumeLog.Tag, "VolumeController Changed Unset Event return: " + error);
-            AudioManagerErrorFactory.CheckAndThrowException(error, "unable to unset level changed callback");
+            if (_volumeChangedCallbackId > 0) {
+                int error = Interop.AudioVolume.RemoveVolumeChangedCallback(_volumeChangedCallbackId);
+                Tizen.Log.Info(AudioVolumeLog.Tag, "VolumeController Changed remove Event return: " + error);
+                AudioManagerErrorFactory.CheckAndThrowException(error, "unable to remove level changed callback");
+            }
         }
     }
-}
\ No newline at end of file
+}
index 0bd8a2c..12f9607 100644 (file)
@@ -5,14 +5,14 @@ using Tizen.Multimedia;
 internal static partial class Interop\r
 {\r
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r
-    internal delegate void SoundDeviceConnectedCallback(IntPtr device, bool isConnected, IntPtr userData);\r
+    internal delegate void SoundDeviceConnectionChangedCallback(IntPtr device, bool isConnected, IntPtr userData);\r
 \r
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r
-    internal delegate void SoundDeviceInformationChangedCallback(IntPtr device, AudioDeviceProperty changedInfo, IntPtr userData);\r
+    internal delegate void SoundDeviceStateChangedCallback(IntPtr device, AudioDeviceState changedState, IntPtr userData);\r
 \r
     internal static partial class AudioDevice\r
     {\r
-        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_current_device_list")]\r
+        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_list")]\r
         internal static extern int GetCurrentDeviceList(AudioDeviceOptions deviceMask, out IntPtr deviceList);\r
 \r
         [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_free_device_list")]\r
@@ -36,16 +36,16 @@ internal static partial class Interop
         [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_state")]\r
         internal static extern int GetDeviceState(IntPtr device, out AudioDeviceState state);\r
 \r
-        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_set_device_connected_cb")]\r
-        internal static extern int SetDeviceConnectedCallback(AudioDeviceOptions deviceMask, SoundDeviceConnectedCallback callback, IntPtr userData);\r
+        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_connection_changed_cb")]\r
+        internal static extern int AddDeviceConnectionChangedCallback(AudioDeviceOptions deviceMask, SoundDeviceConnectionChangedCallback callback, IntPtr userData, out int id);\r
 \r
-        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_unset_device_connected_cb")]\r
-        internal static extern int UnsetDeviceConnectedCallback();\r
+        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_connection_changed_cb")]\r
+        internal static extern int RemoveDeviceConnectionChangedCallback(int id);\r
 \r
-        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_set_device_information_changed_cb")]\r
-        internal static extern int SetDeviceInformationChangedCallback(AudioDeviceOptions deviceMask, SoundDeviceInformationChangedCallback callback, IntPtr userData);\r
+        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_state_changed_cb")]\r
+        internal static extern int AddDeviceStateChangedCallback(AudioDeviceOptions deviceMask, SoundDeviceStateChangedCallback callback, IntPtr userData, out int id);\r
 \r
-        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_unset_device_information_changed_cb")]\r
-        internal static extern int UnsetDeviceInformationChangedCallback();\r
+        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_state_changed_cb")]\r
+        internal static extern int RemoveDeviceStateChangedCallback(int id);\r
     }\r
-}
\ No newline at end of file
+}\r
index b6fa87d..4b26776 100644 (file)
@@ -27,10 +27,10 @@ internal static partial class Interop
         [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_unset_current_sound_type")]\r
         internal static extern int UnsetCurrentType();\r
 \r
-        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_set_volume_changed_cb")]\r
-        internal static extern int SetVolumeChangedCallback(SoundManagerVolumeChangedCallback callback, IntPtr userData);\r
+        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_volume_changed_cb")]\r
+        internal static extern int AddVolumeChangedCallback(SoundManagerVolumeChangedCallback callback, IntPtr userData, out int id);\r
 \r
-        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_unset_volume_changed_cb")]\r
-        internal static extern int UnsetVolumeChangedCallback();\r
+        [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_volume_changed_cb")]\r
+        internal static extern int RemoveVolumeChangedCallback(int id);\r
     }\r
-}
\ No newline at end of file
+}\r
index d36f713..3003bbe 100755 (executable)
     <Compile Include="Interop\Interop.RecorderCapability.cs" />
     <Compile Include="AudioManager\AudioDevice.cs" />
     <Compile Include="AudioManager\AudioDeviceConnectionChangedEventArgs.cs" />
-    <Compile Include="AudioManager\AudioDevicePropertyChangedEventArgs.cs" />
+    <Compile Include="AudioManager\AudioDeviceStateChangedEventArgs.cs" />
     <Compile Include="AudioManager\AudioManager.cs" />
     <Compile Include="AudioManager\AudioManagerEnumerations.cs" />
     <Compile Include="AudioManager\AudioManagerErrorFactory.cs" />
index fd2950a..097a4e8 100755 (executable)
     <Compile Include="Interop\Interop.RecorderCapability.cs" />\r
     <Compile Include="AudioManager\AudioDevice.cs" />\r
     <Compile Include="AudioManager\AudioDeviceConnectionChangedEventArgs.cs" />\r
-    <Compile Include="AudioManager\AudioDevicePropertyChangedEventArgs.cs" />\r
+    <Compile Include="AudioManager\AudioDeviceStateChangedEventArgs.cs" />\r
     <Compile Include="AudioManager\AudioManager.cs" />\r
     <Compile Include="AudioManager\AudioManagerEnumerations.cs" />\r
     <Compile Include="AudioManager\AudioManagerErrorFactory.cs" />\r
     <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>\r
     <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>\r
   </PropertyGroup>\r
-</Project>
\ No newline at end of file
+</Project>