/*
* 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;
using System.Runtime.InteropServices;
namespace Tizen.Multimedia
{
///
/// Provides the ability to query the information of sound devices.
///
public class AudioDevice
{
private readonly int _id;
private readonly AudioDeviceType _type;
private readonly AudioDeviceIoDirection _ioDirection;
internal AudioDevice(IntPtr deviceHandle)
{
int ret = Interop.AudioDevice.GetDeviceId(deviceHandle, out _id);
MultimediaDebug.AssertNoError(ret);
ret = Interop.AudioDevice.GetDeviceName(deviceHandle, out var name);
MultimediaDebug.AssertNoError(ret);
Name = Marshal.PtrToStringAnsi(name);
ret = Interop.AudioDevice.GetDeviceType(deviceHandle, out _type);
MultimediaDebug.AssertNoError(ret);
ret = (int)Interop.AudioDevice.GetDeviceIoDirection(deviceHandle, out _ioDirection);
MultimediaDebug.AssertNoError(ret);
}
///
/// Gets the ID of the device.
///
/// The id of the device.
public int Id => _id;
///
/// Gets the name of the device.
///
/// The name of the device.
public string Name { get; }
///
/// Gets the type of the device.
///
/// The of the device.
public AudioDeviceType Type => _type;
///
/// Gets the IO direction of the device.
///
/// The IO direction of the device.
public AudioDeviceIoDirection IoDirection => _ioDirection;
///
/// Gets the state of the device.
///
/// The of the device.
public AudioDeviceState State
{
get
{
Interop.AudioDevice.GetDeviceState(Id, out var state).
Validate("Failed to get the state of the device");
return state;
}
}
///
/// Returns a string that represents the current object.
///
/// A string that represents the current object.
public override string ToString() =>
$"Id={Id}, Name={Name}, Type={Type}, IoDirection={IoDirection}, State={State}";
///
/// Compares an object to an instance of for equality.
///
/// A to compare.
/// true if the two devices are equal; otherwise, false.
public override bool Equals(object obj)
{
var rhs = obj as AudioDevice;
if (rhs == null)
{
return false;
}
return Id == rhs.Id;
}
///
/// Gets the hash code for this instance of .
///
/// The hash code for this instance of .
public override int GetHashCode()
{
return Id.GetHashCode();
}
}
}