From: Sangchul Lee Date: Tue, 3 Sep 2019 03:10:20 +0000 (+0900) Subject: [AudioManager] Add properties for the preferred device (#987) X-Git-Tag: 5.5_M2~99 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c05cfedbfe61d66ffdfefe61e0bb41df720dd9a;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [AudioManager] Add properties for the preferred device (#987) * [AudioManager] Add properties for the preferred device to AudioStreamPolicy class Signed-off-by: Sangchul Lee * fixup! [AudioManager] Add properties for the preferred device to AudioStreamPolicy class * fixup! [AudioManager] Add properties for the preferred device to AudioStreamPolicy class * [AudioManager] Use null-conditional operator and ?? operator Signed-off-by: Sangchul Lee * [AudioManager] Remove codes checking device id of preferred device handle Native API is now changed to return error if there's a difference of preferred deivce id between server and stream info. handle. Signed-off-by: Sangchul Lee * fixup! [AudioManager] Remove codes checking device id of preferred device handle Signed-off-by: Sangchul Lee --- diff --git a/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs b/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs index 0309e92..5a50f73 100644 --- a/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs +++ b/src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs @@ -28,6 +28,9 @@ namespace Tizen.Multimedia private AudioStreamPolicyHandle _handle; private bool _disposed = false; private Interop.AudioStreamPolicy.FocusStateChangedCallback _focusStateChangedCallback; + private static AudioDevice _inputDevice = null; + private static AudioDevice _outputDevice = null; + private const string Tag = "Tizen.Multimedia.AudioStreamPolicy"; /// /// Initializes a new instance of the class with . @@ -305,6 +308,84 @@ namespace Tizen.Multimedia } /// + /// Gets or sets the preferred input device. + /// + /// + /// The instance.
+ /// The default is null which means any device is not set on this property. + ///
+ /// + /// This property is to set a specific built-in device when the system has multiple devices of the same built-in device type. + /// When there's only one device for a built-in device type in the system, nothing will happen even if this property is set successfully. + /// + /// A device is not for input. + /// An internal error occurs. + /// A device is not supported by this instance. + /// The has already been disposed of. + /// + /// 6 + public AudioDevice PreferredInputDevice + { + get + { + /* This P/Invoke intends to validate if the core audio system + * is normal. Otherwise, it'll throw an error here. */ + Interop.AudioStreamPolicy.GetPreferredDevice(Handle, out var inDeviceId, out _). + ThrowIfError("Failed to get preferred input device"); + + Log.Debug(Tag, $"preferred input device id:{inDeviceId}"); + + return _inputDevice; + } + set + { + Interop.AudioStreamPolicy.SetPreferredDevice(Handle, AudioDeviceIoDirection.Input, value?.Id ?? 0). + ThrowIfError("Failed to set preferred input device"); + + _inputDevice = value; + } + } + + /// + /// Gets or sets the preferred output device. + /// + /// + /// The instance.
+ /// The default is null which means any device is not set on this property. + ///
+ /// + /// This property is to set a specific built-in device when the system has multiple devices of the same built-in device type. + /// When there's only one device for a built-in device type in the system, nothing will happen even if this property is set successfully. + /// + /// A device is not for output. + /// An internal error occurs. + /// A device is not supported by this instance. + /// The has already been disposed of. + /// + /// 6 + public AudioDevice PreferredOutputDevice + { + get + { + /* This P/Invoke intends to validate if the core audio system + * is normal. Otherwise, it'll throw an error here. */ + Interop.AudioStreamPolicy.GetPreferredDevice(Handle, out _, out var outDeviceId). + ThrowIfError("Failed to get preferred output device"); + + Log.Debug(Tag, $"preferred output device id:{outDeviceId}"); + + return _outputDevice; + } + set + { + Interop.AudioStreamPolicy.SetPreferredDevice(Handle, AudioDeviceIoDirection.Output, value?.Id ?? 0). + ThrowIfError("Failed to set preferred output device"); + + _outputDevice = value; + } + } + + /// /// Checks if any stream from the current AudioStreamPolicy is using the device. /// /// true if any audio stream from the current AudioStreamPolicy is using the device; otherwise, false. diff --git a/src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs b/src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs index 5c0dc0a..ede3562 100644 --- a/src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs +++ b/src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs @@ -51,6 +51,12 @@ namespace Tizen.Multimedia [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_apply_stream_routing")] internal static extern AudioManagerError ApplyStreamRouting(AudioStreamPolicyHandle streamInfo); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_set_stream_preferred_device_id")] + internal static extern AudioManagerError SetPreferredDevice(AudioStreamPolicyHandle streamInfo, AudioDeviceIoDirection direction, int deviceId); + + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_stream_preferred_device")] + internal static extern AudioManagerError GetPreferredDevice(AudioStreamPolicyHandle streamInfo, out int inDeviceId, out int outDeviceId); + [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_acquire_focus")] internal static extern AudioManagerError AcquireFocus(AudioStreamPolicyHandle streamInfo, AudioStreamFocusOptions focusMask, AudioStreamBehaviors audioStreamBehavior, string extraInfo);