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