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