2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
20 namespace Tizen.Multimedia
23 /// Provides the ability to query the information of sound devices.
25 /// <since_tizen> 3 </since_tizen>
26 public class AudioDevice
28 private readonly int _id;
29 private readonly AudioDeviceType _type;
30 private readonly AudioDeviceIoDirection _ioDirection;
32 internal AudioDevice(IntPtr deviceHandle)
34 int ret = Interop.AudioDevice.GetDeviceId(deviceHandle, out _id);
35 MultimediaDebug.AssertNoError(ret);
37 ret = Interop.AudioDevice.GetDeviceName(deviceHandle, out var name);
38 MultimediaDebug.AssertNoError(ret);
40 Name = Marshal.PtrToStringAnsi(name);
42 ret = Interop.AudioDevice.GetDeviceType(deviceHandle, out _type);
43 MultimediaDebug.AssertNoError(ret);
45 ret = Interop.AudioDevice.GetDeviceIoDirection(deviceHandle, out _ioDirection);
46 MultimediaDebug.AssertNoError(ret);
50 /// Gets the ID of the device.
52 /// <value>The id of the device.</value>
53 /// <since_tizen> 3 </since_tizen>
57 /// Gets the name of the device.
59 /// <value>The name of the device.</value>
60 /// <since_tizen> 3 </since_tizen>
61 public string Name { get; }
64 /// Gets the type of the device.
66 /// <value>The <see cref="AudioDeviceType"/> of the device.</value>
67 /// <since_tizen> 3 </since_tizen>
68 public AudioDeviceType Type => _type;
71 /// Gets the IO direction of the device.
73 /// <value>The IO direction of the device.</value>
74 /// <since_tizen> 3 </since_tizen>
75 public AudioDeviceIoDirection IoDirection => _ioDirection;
78 /// Gets the state of the device.
80 /// <value>The <see cref="AudioDeviceState"/> of the device.</value>
81 /// <since_tizen> 3 </since_tizen>
82 [Obsolete("Deprecated since API level 5. Please use the IsRunning property instead.")]
83 public AudioDeviceState State
87 Interop.AudioDevice.GetDeviceState(Id, out var state).
88 ThrowIfError("Failed to get the state of the device");
95 /// Gets the running state of the device.
97 /// <value>true if the audio stream of device is running actually; otherwise, false.</value>
98 /// <since_tizen> 5 </since_tizen>
103 Interop.AudioDevice.IsDeviceRunning(_id, out bool isRunning).
104 ThrowIfError("Failed to get the running state of the device");
111 /// Returns a string that represents the current object.
113 /// <returns>A string that represents the current object.</returns>
114 /// <since_tizen> 4 </since_tizen>
115 public override string ToString() =>
116 $"Id={Id}, Name={Name}, Type={Type}, IoDirection={IoDirection}, IsRunning={IsRunning}";
119 /// Compares an object to an instance of <see cref="AudioDevice"/> for equality.
121 /// <param name="obj">A <see cref="Object"/> to compare.</param>
122 /// <returns>true if the two devices are equal; otherwise, false.</returns>
123 /// <since_tizen> 4 </since_tizen>
124 public override bool Equals(object obj)
126 var rhs = obj as AudioDevice;
136 /// Gets the hash code for this instance of <see cref="AudioDevice"/>.
138 /// <returns>The hash code for this instance of <see cref="AudioDevice"/>.</returns>
139 /// <since_tizen> 4 </since_tizen>
140 public override int GetHashCode()
142 return Id.GetHashCode();