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
22 internal static class AudioDeviceLog
24 internal const string Tag = "Tizen.Multimedia.AudioDevice";
28 /// The Device API provides functions to query the information of sound devices.
30 public class AudioDevice
32 private readonly int _id;
33 private readonly string _name;
34 private readonly AudioDeviceType _type;
35 private readonly AudioDeviceIoDirection _ioDirection;
36 private readonly AudioDeviceState _state;
37 private readonly IntPtr _handle;
39 internal AudioDevice(IntPtr deviceHandle)
41 _handle = deviceHandle;
44 ret = Interop.AudioDevice.GetDeviceId(_handle, out _id);
47 Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device Id: " + (AudioManagerError)ret);
49 AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device Id");
52 ret = Interop.AudioDevice.GetDeviceName(_handle, out name);
55 Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device name" + (AudioManagerError)ret);
57 AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device name");
59 _name = Marshal.PtrToStringAnsi(name);
61 ret = Interop.AudioDevice.GetDeviceType(_handle, out _type);
64 Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device type" + (AudioManagerError)ret);
66 AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device type");
68 ret = Interop.AudioDevice.GetDeviceIoDirection(_handle, out _ioDirection);
71 Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device IoDirection" + (AudioManagerError)ret);
73 AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device IO Direction");
75 ret = Interop.AudioDevice.GetDeviceState(_handle, out _state);
78 Tizen.Log.Error(AudioDeviceLog.Tag, "Unable to get device state" + (AudioManagerError)ret);
80 AudioManagerErrorFactory.CheckAndThrowException(ret, _handle, "Unable to get device state");
84 /// The id of the device.
89 /// The name of the device.
91 public string Name => _name;
94 /// The type of the device.
96 public AudioDeviceType Type => _type;
99 /// The io direction of the device.
101 public AudioDeviceIoDirection IoDirection => _ioDirection;
104 /// The state of the device.
106 public AudioDeviceState State => _state;
108 internal IntPtr Handle => _handle;