2020-08-18 03:49:37 +02:00
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
|
using Ryujinx.Cpu;
|
2018-08-17 01:47:36 +02:00
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-12-18 06:33:36 +01:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2018-09-23 20:11:46 +02:00
|
|
|
|
using System;
|
2018-03-12 20:29:06 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
2018-03-12 20:29:06 +01:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
class AudioDeviceServer : IpcService
|
2018-03-12 20:29:06 +01:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
private const int AudioDeviceNameSize = 0x100;
|
2018-04-18 03:52:20 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
private IAudioDevice _impl;
|
2018-04-19 05:19:22 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
public AudioDeviceServer(IAudioDevice impl)
|
|
|
|
|
{
|
|
|
|
|
_impl = impl;
|
2018-03-12 20:29:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(0)]
|
2019-07-12 03:13:43 +02:00
|
|
|
|
// ListAudioDeviceName() -> (u32, buffer<bytes, 6>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode ListAudioDeviceName(ServiceCtx context)
|
2018-03-12 20:29:06 +01:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
string[] deviceNames = _impl.ListAudioDeviceName();
|
2018-03-12 20:29:06 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
long position = context.Request.ReceiveBuff[0].Position;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
long size = context.Request.ReceiveBuff[0].Size;
|
2018-03-12 20:29:06 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
long basePosition = position;
|
2018-03-12 20:29:06 +01:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
int count = 0;
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
foreach (string name in deviceNames)
|
2018-03-12 20:29:06 +01:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
2018-03-12 20:29:06 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if ((position - basePosition) + buffer.Length > size)
|
2018-03-12 20:29:06 +01:00
|
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
2018-04-24 22:14:26 +02:00
|
|
|
|
|
2018-03-12 20:29:06 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
|
context.Memory.Write((ulong)position, buffer);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, position + buffer.Length, AudioDeviceNameSize - buffer.Length);
|
2018-03-12 20:29:06 +01:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
position += AudioDeviceNameSize;
|
|
|
|
|
count++;
|
2018-03-12 20:29:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
context.ResponseData.Write(count);
|
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-03-12 20:29:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(1)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// SetAudioDeviceOutputVolume(f32 volume, buffer<bytes, 5> name)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode SetAudioDeviceOutputVolume(ServiceCtx context)
|
2018-03-12 20:29:06 +01:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
float volume = context.RequestData.ReadSingle();
|
2018-03-12 20:29:06 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
long position = context.Request.SendBuff[0].Position;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
long size = context.Request.SendBuff[0].Size;
|
2018-03-12 20:29:06 +01:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, size);
|
2018-04-24 22:14:26 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
return _impl.SetAudioDeviceOutputVolume(deviceName, volume);
|
|
|
|
|
}
|
2018-03-12 20:29:06 +01:00
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(2)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// GetAudioDeviceOutputVolume(buffer<bytes, 5> name) -> f32 volume
|
|
|
|
|
public ResultCode GetAudioDeviceOutputVolume(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
long position = context.Request.SendBuff[0].Position;
|
|
|
|
|
long size = context.Request.SendBuff[0].Size;
|
2018-04-17 02:24:42 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, size);
|
|
|
|
|
|
|
|
|
|
ResultCode result = _impl.GetAudioDeviceOutputVolume(deviceName, out float volume);
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(volume);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2018-03-12 20:29:06 +01:00
|
|
|
|
}
|
2018-04-18 03:52:20 +02:00
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(3)]
|
2019-07-12 03:13:43 +02:00
|
|
|
|
// GetActiveAudioDeviceName() -> buffer<bytes, 6>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetActiveAudioDeviceName(ServiceCtx context)
|
2018-04-22 06:21:49 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
string name = _impl.GetActiveAudioDeviceName();
|
2018-04-22 06:21:49 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
long position = context.Request.ReceiveBuff[0].Position;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
long size = context.Request.ReceiveBuff[0].Size;
|
2018-04-22 06:21:49 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(name + "\0");
|
2018-04-22 06:21:49 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if ((ulong)deviceNameBuffer.Length <= (ulong)size)
|
2018-04-24 22:14:26 +02:00
|
|
|
|
{
|
2020-05-04 00:54:50 +02:00
|
|
|
|
context.Memory.Write((ulong)position, deviceNameBuffer);
|
2018-04-24 22:14:26 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
2018-04-24 22:14:26 +02:00
|
|
|
|
}
|
2018-04-22 06:21:49 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-04-22 06:21:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(4)]
|
2019-07-12 03:13:43 +02:00
|
|
|
|
// QueryAudioDeviceSystemEvent() -> handle<copy, event>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode QueryAudioDeviceSystemEvent(ServiceCtx context)
|
2018-04-18 03:52:20 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
KEvent deviceSystemEvent = _impl.QueryAudioDeviceSystemEvent();
|
|
|
|
|
|
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(deviceSystemEvent.ReadableEvent, out int handle) != KernelResult.Success)
|
2018-09-23 20:11:46 +02:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
2018-04-18 03:52:20 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
2018-04-18 03:52:20 +02:00
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAudio);
|
2018-04-18 03:52:20 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-04-18 03:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(5)]
|
2019-07-12 03:13:43 +02:00
|
|
|
|
// GetActiveChannelCount() -> u32
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetActiveChannelCount(ServiceCtx context)
|
2018-04-18 03:52:20 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
context.ResponseData.Write(_impl.GetActiveChannelCount());
|
2018-04-18 03:52:20 +02:00
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAudio);
|
2018-04-18 03:52:20 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-04-18 03:52:20 +02:00
|
|
|
|
}
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(6)] // 3.0.0+
|
2019-07-12 03:13:43 +02:00
|
|
|
|
// ListAudioDeviceNameAuto() -> (u32, buffer<bytes, 0x22>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode ListAudioDeviceNameAuto(ServiceCtx context)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
string[] deviceNames = _impl.ListAudioDeviceName();
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
(long position, long size) = context.Request.GetBufferType0x22();
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
long basePosition = position;
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
int count = 0;
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
foreach (string name in deviceNames)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if ((position - basePosition) + buffer.Length > size)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
|
context.Memory.Write((ulong)position, buffer);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, position + buffer.Length, AudioDeviceNameSize - buffer.Length);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
position += AudioDeviceNameSize;
|
|
|
|
|
count++;
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
context.ResponseData.Write(count);
|
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(7)] // 3.0.0+
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// SetAudioDeviceOutputVolumeAuto(f32 volume, buffer<bytes, 0x21> name)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode SetAudioDeviceOutputVolumeAuto(ServiceCtx context)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
float volume = context.RequestData.ReadSingle();
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
(long position, long size) = context.Request.GetBufferType0x21();
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, size);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
return _impl.SetAudioDeviceOutputVolume(deviceName, volume);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(8)] // 3.0.0+
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// GetAudioDeviceOutputVolumeAuto(buffer<bytes, 0x21> name) -> f32
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetAudioDeviceOutputVolumeAuto(ServiceCtx context)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
(long position, long size) = context.Request.GetBufferType0x21();
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
|
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, size);
|
|
|
|
|
|
|
|
|
|
ResultCode result = _impl.GetAudioDeviceOutputVolume(deviceName, out float volume);
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(volume);
|
|
|
|
|
}
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(10)] // 3.0.0+
|
2019-07-12 03:13:43 +02:00
|
|
|
|
// GetActiveAudioDeviceNameAuto() -> buffer<bytes, 0x22>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetActiveAudioDeviceNameAuto(ServiceCtx context)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
string name = _impl.GetActiveAudioDeviceName();
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
(long position, long size) = context.Request.GetBufferType0x22();
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
byte[] deviceNameBuffer = Encoding.UTF8.GetBytes(name + '\0');
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if ((ulong)deviceNameBuffer.Length <= (ulong)size)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2020-05-04 00:54:50 +02:00
|
|
|
|
context.Memory.Write((ulong)position, deviceNameBuffer);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(11)] // 3.0.0+
|
2019-07-12 03:13:43 +02:00
|
|
|
|
// QueryAudioDeviceInputEvent() -> handle<copy, event>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode QueryAudioDeviceInputEvent(ServiceCtx context)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
KEvent deviceInputEvent = _impl.QueryAudioDeviceInputEvent();
|
|
|
|
|
|
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(deviceInputEvent.ReadableEvent, out int handle) != KernelResult.Success)
|
2018-09-23 20:11:46 +02:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAudio);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(12)] // 3.0.0+
|
2019-07-12 03:13:43 +02:00
|
|
|
|
// QueryAudioDeviceOutputEvent() -> handle<copy, event>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode QueryAudioDeviceOutputEvent(ServiceCtx context)
|
2018-06-03 00:46:09 +02:00
|
|
|
|
{
|
2020-08-18 03:49:37 +02:00
|
|
|
|
KEvent deviceOutputEvent = _impl.QueryAudioDeviceOutputEvent();
|
|
|
|
|
|
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(deviceOutputEvent.ReadableEvent, out int handle) != KernelResult.Success)
|
2018-09-23 20:11:46 +02:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAudio);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-06-03 00:46:09 +02:00
|
|
|
|
}
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(13)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// GetAudioSystemMasterVolumeSetting(buffer<bytes, 5> name) -> f32
|
|
|
|
|
public ResultCode GetAudioSystemMasterVolumeSetting(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
long position = context.Request.SendBuff[0].Position;
|
|
|
|
|
long size = context.Request.SendBuff[0].Size;
|
|
|
|
|
|
|
|
|
|
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, size);
|
|
|
|
|
|
|
|
|
|
ResultCode result = _impl.GetAudioSystemMasterVolumeSetting(deviceName, out float systemMasterVolume);
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(systemMasterVolume);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2018-03-12 20:29:06 +01:00
|
|
|
|
}
|
2020-08-18 03:49:37 +02:00
|
|
|
|
}
|