From: Sangchul Lee Date: Tue, 3 Mar 2020 02:37:35 +0000 (+0900) Subject: Revert "[AudioManager] Remove deprecated symbols (#1395)" (#1438) X-Git-Tag: accepted/tizen/unified/20210219.040944~838 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ea15e1b721bb6678f9e1074bd7a0463263059f7;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Revert "[AudioManager] Remove deprecated symbols (#1395)" (#1438) This reverts commit 10637a6853b4d0334acad1a61fc634677f60ce6c. --- diff --git a/src/Tizen.Multimedia/AudioManager/AudioDevice.cs b/src/Tizen.Multimedia/AudioManager/AudioDevice.cs index 773a04a..bf4ec24 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioDevice.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDevice.cs @@ -78,6 +78,23 @@ namespace Tizen.Multimedia public AudioDeviceIoDirection IoDirection => _ioDirection; /// + /// Gets the state of the device. + /// + /// The of the device. + /// 3 + [Obsolete("Deprecated since API level 5. Please use the IsRunning property instead.")] + public AudioDeviceState State + { + get + { + Interop.AudioDevice.GetDeviceState(Id, out var state). + ThrowIfError("Failed to get the state of the device"); + + return state; + } + } + + /// /// Gets the running state of the device. /// /// true if the audio stream of device is running actually; otherwise, false. diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceOptions.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceOptions.cs index 5500757..8a32950 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioDeviceOptions.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioDeviceOptions.cs @@ -53,6 +53,18 @@ namespace Tizen.Multimedia External = 0x0020, /// + /// Deactivated devices. + /// + [Obsolete("Deprecated since API level 5.")] + Deactivated = 0x1000, + + /// + /// Activated devices. + /// + [Obsolete("Deprecated since API level 5.")] + Activated = 0x2000, + + /// /// All devices. /// All = 0xFFFF diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceRunningChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceRunningChangedEventArgs.cs old mode 100644 new mode 100755 diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceState.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceState.cs new file mode 100644 index 0000000..85991d4 --- /dev/null +++ b/src/Tizen.Multimedia/AudioManager/AudioDeviceState.cs @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Multimedia +{ + /// + /// Specifies the audio device states. + /// + /// 3 + [Obsolete("Deprecated since API level 5.")] + public enum AudioDeviceState + { + /// + /// Deactivated state. + /// + Deactivated, + + /// + /// Activated state. + /// + Activated + } +} diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs new file mode 100644 index 0000000..34eb612 --- /dev/null +++ b/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Multimedia +{ + /// + /// Provides data for the event. + /// + /// 3 + [Obsolete("Deprecated since API level 5. Please use the AudioDeviceRunningChangedEventArgs class instead.")] + public class AudioDeviceStateChangedEventArgs : EventArgs + { + internal AudioDeviceStateChangedEventArgs(AudioDevice device, AudioDeviceState changedState) + { + Device = device; + State = changedState; + } + + /// + /// Gets the device. + /// + /// The . + /// 3 + public AudioDevice Device { get; } + + /// + /// Gets the state of the device. + /// + /// The of the device. + /// 4 + public AudioDeviceState State { get; } + } +} diff --git a/src/Tizen.Multimedia/AudioManager/AudioManager.cs b/src/Tizen.Multimedia/AudioManager/AudioManager.cs index 2f566bf..890c319 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioManager.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioManager.cs @@ -152,6 +152,78 @@ namespace Tizen.Multimedia } #endregion + #region DeviceStateChanged event + private static int _deviceStateChangedCallbackId = -1; + +#pragma warning disable CS0618 // Type or member is obsolete + + private static Interop.AudioDevice.StateChangedCallback _audioDeviceStateChangedCallback; + private static EventHandler _audioDeviceStateChanged; + private static readonly object _audioDeviceStateLock = new object(); + + /// + /// Occurs when the state of an audio device changes. + /// + /// 3 + [Obsolete("Deprecated since API level 5. Please use the DeviceRunningStateChanged property instead.")] + public static event EventHandler DeviceStateChanged + { + add + { + if (value == null) + { + return; + } + + lock (_audioDeviceStateLock) + { + if (_audioDeviceStateChanged == null) + { + RegisterDeviceStateChangedEvent(); + } + _audioDeviceStateChanged += value; + } + } + remove + { + if (value == null) + { + return; + } + + lock (_audioDeviceStateLock) + { + if (_audioDeviceStateChanged == value) + { + UnregisterDeviceStateChangedEvent(); + } + _audioDeviceStateChanged -= value; + } + } + } + + private static void RegisterDeviceStateChangedEvent() + { + _audioDeviceStateChangedCallback = (device, changedState, _) => + { + _audioDeviceStateChanged?.Invoke(null, + new AudioDeviceStateChangedEventArgs(new AudioDevice(device), changedState)); + }; + + Interop.AudioDevice.AddDeviceStateChangedCallback(AudioDeviceOptions.All, + _audioDeviceStateChangedCallback, IntPtr.Zero, out _deviceStateChangedCallbackId). + ThrowIfError("Failed to add device state changed event"); + } + +#pragma warning restore CS0618 // Type or member is obsolete + + private static void UnregisterDeviceStateChangedEvent() + { + Interop.AudioDevice.RemoveDeviceStateChangedCallback(_deviceStateChangedCallbackId). + ThrowIfError("Failed to remove device state changed event"); + } + #endregion + #region DeviceRunningStateChanged event private static int _deviceRunningChangedCallbackId = -1; private static Interop.AudioDevice.RunningChangedCallback _audioDeviceRunningChangedCallback; diff --git a/src/Tizen.Multimedia/Interop/Interop.Device.cs b/src/Tizen.Multimedia/Interop/Interop.Device.cs index 17f92f3..00e0459 100755 --- a/src/Tizen.Multimedia/Interop/Interop.Device.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Device.cs @@ -26,6 +26,11 @@ namespace Tizen.Multimedia [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void ConnectionChangedCallback(IntPtr device, bool isConnected, IntPtr userData); +#pragma warning disable CS0618 // Type or member is obsolete + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void StateChangedCallback(IntPtr device, AudioDeviceState changedState, IntPtr userData); +#pragma warning restore CS0618 // Type or member is obsolete + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void RunningChangedCallback(IntPtr device, bool isRunning, IntPtr userData); @@ -51,6 +56,11 @@ namespace Tizen.Multimedia [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_name")] internal static extern int GetDeviceName(IntPtr device, out IntPtr name); +#pragma warning disable CS0618 // Type or member is obsolete + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_state_by_id")] + internal static extern AudioManagerError GetDeviceState(int deviceId, out AudioDeviceState state); +#pragma warning restore CS0618 // Type or member is obsolete + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_is_device_running_by_id")] internal static extern AudioManagerError IsDeviceRunning(int deviceId, out bool isRunning); @@ -91,6 +101,13 @@ namespace Tizen.Multimedia [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_connection_changed_cb")] internal static extern AudioManagerError RemoveDeviceConnectionChangedCallback(int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_state_changed_cb")] + internal static extern AudioManagerError AddDeviceStateChangedCallback(AudioDeviceOptions deviceMask, + StateChangedCallback callback, IntPtr userData, out int id); + + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_state_changed_cb")] + internal static extern AudioManagerError RemoveDeviceStateChangedCallback(int id); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_running_changed_cb")] internal static extern AudioManagerError AddDeviceRunningChangedCallback(AudioDeviceOptions deviceMask, RunningChangedCallback callback, IntPtr userData, out int id);