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 public class AudioDevice
27 private readonly int _id;
28 private readonly AudioDeviceType _type;
29 private readonly AudioDeviceIoDirection _ioDirection;
31 internal AudioDevice(IntPtr deviceHandle)
33 int ret = Interop.AudioDevice.GetDeviceId(deviceHandle, out _id);
34 MultimediaDebug.AssertNoError(ret);
36 ret = Interop.AudioDevice.GetDeviceName(deviceHandle, out var name);
37 MultimediaDebug.AssertNoError(ret);
39 Name = Marshal.PtrToStringAnsi(name);
41 ret = Interop.AudioDevice.GetDeviceType(deviceHandle, out _type);
42 MultimediaDebug.AssertNoError(ret);
44 ret = (int)Interop.AudioDevice.GetDeviceIoDirection(deviceHandle, out _ioDirection);
45 MultimediaDebug.AssertNoError(ret);
49 /// Gets the ID of the device.
51 /// <value>The id of the device.</value>
55 /// Gets the name of the device.
57 /// <value>The name of the device.</value>
58 public string Name { get; }
61 /// Gets the type of the device.
63 /// <value>The <see cref="AudioDeviceType"/> of the device.</value>
64 public AudioDeviceType Type => _type;
67 /// Gets the IO direction of the device.
69 /// <value>The IO direction of the device.</value>
70 public AudioDeviceIoDirection IoDirection => _ioDirection;
73 /// Gets the state of the device.
75 /// <value>The <see cref="AudioDeviceState"/> of the device.</value>
76 public AudioDeviceState State
80 Interop.AudioDevice.GetDeviceState(Id, out var state).
81 Validate("Failed to get the state of the device");
88 /// Returns a string that represents the current object.
90 /// <returns>A string that represents the current object.</returns>
91 public override string ToString() =>
92 $"Id={Id}, Name={Name}, Type={Type}, IoDirection={IoDirection}, State={State}";
95 /// Compares an object to an instance of <see cref="AudioDevice"/> for equality.
97 /// <param name="obj">A <see cref="Object"/> to compare.</param>
98 /// <returns>true if the two devices are equal; otherwise, false.</returns>
99 public override bool Equals(object obj)
101 var rhs = obj as AudioDevice;
112 /// Gets the hash code for this instance of <see cref="AudioDevice"/>.
114 /// <returns>The hash code for this instance of <see cref="AudioDevice"/>.</returns>
115 public override int GetHashCode()
117 return Id.GetHashCode();