From 29e258de5e57520fd4023e822d766382e947e1bb Mon Sep 17 00:00:00 2001 From: Jeongho Mok Date: Wed, 28 Dec 2016 17:20:14 +0900 Subject: [PATCH] [Audio] Use Add/Remove callback CAPI instead of deprecated set/unset API Change-Id: I553580c8ee01927a445caf5274a4179116017a9e --- ...Args.cs => AudioDeviceStateChangedEventArgs.cs} | 10 +- src/Tizen.Multimedia/AudioManager/AudioManager.cs | 491 +++------------------ .../AudioManager/AudioManagerEnumerations.cs | 25 +- src/Tizen.Multimedia/AudioManager/AudioVolume.cs | 19 +- src/Tizen.Multimedia/Interop/Interop.Device.cs | 24 +- src/Tizen.Multimedia/Interop/Interop.Volume.cs | 10 +- src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj | 2 +- src/Tizen.Multimedia/Tizen.Multimedia.csproj | 4 +- 8 files changed, 94 insertions(+), 491 deletions(-) rename src/Tizen.Multimedia/AudioManager/{AudioDevicePropertyChangedEventArgs.cs => AudioDeviceStateChangedEventArgs.cs} (75%) diff --git a/src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs similarity index 75% rename from src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs rename to src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs index 813d765..34bc165 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioDevicePropertyChangedEventArgs.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs @@ -21,12 +21,12 @@ namespace Tizen.Multimedia /// /// Class extending EventArgs which contains parameters to be passed to event handler of DeviceInformationChanged event /// - public class AudioDevicePropertyChangedEventArgs : EventArgs + public class AudioDeviceStateChangedEventArgs : EventArgs { - internal AudioDevicePropertyChangedEventArgs(AudioDevice device, AudioDeviceProperty changedInfo) + internal AudioDeviceStateChangedEventArgs(AudioDevice device, AudioDeviceState changedState) { Device = device; - ChangedInfo = changedInfo; + ChangedState = changedState; } /// @@ -35,8 +35,8 @@ namespace Tizen.Multimedia public AudioDevice Device { get; } /// - /// The entry of sound device information + /// The entry of sound device state /// - public AudioDeviceProperty ChangedInfo { get; } + public AudioDeviceState ChangedState { get; } } } diff --git a/src/Tizen.Multimedia/AudioManager/AudioManager.cs b/src/Tizen.Multimedia/AudioManager/AudioManager.cs index 411db5b..15a0f74 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioManager.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioManager.cs @@ -29,27 +29,14 @@ namespace Tizen.Multimedia /// 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 _audioDeviceConnected; - private static EventHandler _stateActivatedDeviceConnected; - private static EventHandler _stateDeactivatedDeviceConnected; - private static EventHandler _typeExternalDeviceConnected; - private static EventHandler _typeInternalDeviceConnected; - private static EventHandler _ioDirectionInDeviceConnected; - private static EventHandler _ioDirectionOutDeviceConnected; - - private static EventHandler _audioDeviceInformationChanged; - private static EventHandler _stateActivatedDeviceInformationChanged; - private static EventHandler _stateDeactivatedDeviceInformationChanged; - private static EventHandler _typeExternalDeviceInformationChanged; - private static EventHandler _typeInternalDeviceInformationChanged; - private static EventHandler _ioDirectionInDeviceInformationChanged; - private static EventHandler _ioDirectionOutDeviceInformationChanged; + private static EventHandler _audioDeviceConnectionChanged; + private static EventHandler _audioDeviceStateChanged; /// /// 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"); } } /// - /// 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. /// - public static event EventHandler ActivatedDeviceConnectionChanged + public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a function to be invoked when the connection of an deactivated audio device is changed - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a function to be invoked when the connection of an external audio device is changed - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a function to be invoked when the connection of an internal audio device is changed - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a function to be invoked when the connection of an input audio device is changed. - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a function to be invoked when the connection of an output audio device is changed - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a callback function to be invoked when the property of an Audio sound device was changed. - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a callback function to be invoked when the property of a activated audio device was changed. - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a callback function to be invoked when the property of a deactivated audio device was changed. - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a callback function to be invoked when the property of a external audio device was changed. - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a callback function to be invoked when the property of a internal audio device was changed. - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a callback function to be invoked when the property of a input audio device was changed. - /// - public static event EventHandler 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"); - } - } - - /// - /// Registers/Unregisters a callback function to be invoked when the property of a output audio device was changed. - /// - public static event EventHandler 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; + } } } } diff --git a/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs b/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs index 34d06c9..3e75e9a 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioManagerEnumerations.cs @@ -77,9 +77,9 @@ namespace Tizen.Multimedia /// AudioJack, /// - /// Bluetooth + /// Bluetooth Media (A2DP) /// - Bluetooth, + BluetoothMedia, /// /// HDMI /// @@ -91,7 +91,11 @@ namespace Tizen.Multimedia /// /// USB Audio /// - UsbAudio + UsbAudio, + /// + /// Bluetooth Voice (SCO) + /// + BluetoothVoice } /// @@ -129,21 +133,6 @@ namespace Tizen.Multimedia } /// - /// Enumeration for changed property of audio device. - /// - public enum AudioDeviceProperty - { - /// - /// State of the device was changed - /// - State, - /// - /// IO direction of the device was changed - /// - IoDirection - } - - /// /// Enumeration for audio type. /// public enum AudioVolumeType diff --git a/src/Tizen.Multimedia/AudioManager/AudioVolume.cs b/src/Tizen.Multimedia/AudioManager/AudioVolume.cs index 0e0da46..3ad9abd 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioVolume.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioVolume.cs @@ -28,6 +28,7 @@ namespace Tizen.Multimedia /// public class AudioVolume { + private static int _volumeChangedCallbackId = -1; private EventHandler _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 +} diff --git a/src/Tizen.Multimedia/Interop/Interop.Device.cs b/src/Tizen.Multimedia/Interop/Interop.Device.cs index 0bd8a2c..12f9607 100644 --- a/src/Tizen.Multimedia/Interop/Interop.Device.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Device.cs @@ -5,14 +5,14 @@ using Tizen.Multimedia; internal static partial class Interop { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void SoundDeviceConnectedCallback(IntPtr device, bool isConnected, IntPtr userData); + internal delegate void SoundDeviceConnectionChangedCallback(IntPtr device, bool isConnected, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void SoundDeviceInformationChangedCallback(IntPtr device, AudioDeviceProperty changedInfo, IntPtr userData); + internal delegate void SoundDeviceStateChangedCallback(IntPtr device, AudioDeviceState changedState, IntPtr userData); internal static partial class AudioDevice { - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_current_device_list")] + [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_list")] internal static extern int GetCurrentDeviceList(AudioDeviceOptions deviceMask, out IntPtr deviceList); [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_free_device_list")] @@ -36,16 +36,16 @@ internal static partial class Interop [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_state")] internal static extern int GetDeviceState(IntPtr device, out AudioDeviceState state); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_set_device_connected_cb")] - internal static extern int SetDeviceConnectedCallback(AudioDeviceOptions deviceMask, SoundDeviceConnectedCallback callback, IntPtr userData); + [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); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_unset_device_connected_cb")] - internal static extern int UnsetDeviceConnectedCallback(); + [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_connection_changed_cb")] + internal static extern int RemoveDeviceConnectionChangedCallback(int id); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_set_device_information_changed_cb")] - internal static extern int SetDeviceInformationChangedCallback(AudioDeviceOptions deviceMask, SoundDeviceInformationChangedCallback callback, IntPtr userData); + [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); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_unset_device_information_changed_cb")] - internal static extern int UnsetDeviceInformationChangedCallback(); + [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_state_changed_cb")] + internal static extern int RemoveDeviceStateChangedCallback(int id); } -} \ No newline at end of file +} diff --git a/src/Tizen.Multimedia/Interop/Interop.Volume.cs b/src/Tizen.Multimedia/Interop/Interop.Volume.cs index b6fa87d..4b26776 100644 --- a/src/Tizen.Multimedia/Interop/Interop.Volume.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Volume.cs @@ -27,10 +27,10 @@ internal static partial class Interop [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_unset_current_sound_type")] internal static extern int UnsetCurrentType(); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_set_volume_changed_cb")] - internal static extern int SetVolumeChangedCallback(SoundManagerVolumeChangedCallback callback, IntPtr userData); + [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_add_volume_changed_cb")] + internal static extern int AddVolumeChangedCallback(SoundManagerVolumeChangedCallback callback, IntPtr userData, out int id); - [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_unset_volume_changed_cb")] - internal static extern int UnsetVolumeChangedCallback(); + [DllImportAttribute(Libraries.SoundManager, EntryPoint = "sound_manager_remove_volume_changed_cb")] + internal static extern int RemoveVolumeChangedCallback(int id); } -} \ No newline at end of file +} diff --git a/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj b/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj index d36f713..3003bbe 100755 --- a/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj +++ b/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj @@ -208,7 +208,7 @@ - + diff --git a/src/Tizen.Multimedia/Tizen.Multimedia.csproj b/src/Tizen.Multimedia/Tizen.Multimedia.csproj index fd2950a..097a4e8 100755 --- a/src/Tizen.Multimedia/Tizen.Multimedia.csproj +++ b/src/Tizen.Multimedia/Tizen.Multimedia.csproj @@ -205,7 +205,7 @@ - + @@ -270,4 +270,4 @@ <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) true - \ No newline at end of file + -- 2.7.4