2018-02-25 04:34:16 +00:00
|
|
|
using ChocolArm64.Memory;
|
2018-03-16 00:06:24 +00:00
|
|
|
using Ryujinx.Audio;
|
2018-06-11 01:46:42 +01:00
|
|
|
using Ryujinx.HLE.Logging;
|
|
|
|
using Ryujinx.HLE.OsHle.Handles;
|
|
|
|
using Ryujinx.HLE.OsHle.Ipc;
|
2018-02-25 04:34:16 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
|
2018-06-11 01:46:42 +01:00
|
|
|
namespace Ryujinx.HLE.OsHle.Services.Aud
|
2018-02-25 04:34:16 +00:00
|
|
|
{
|
2018-03-21 23:30:10 +00:00
|
|
|
class IAudioOutManager : IpcService
|
2018-02-25 04:34:16 +00:00
|
|
|
{
|
2018-04-24 21:14:26 +01:00
|
|
|
private const string DefaultAudioOutput = "DeviceOut";
|
|
|
|
|
2018-02-25 04:34:16 +00:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-25 04:34:16 +00:00
|
|
|
|
2018-03-21 23:30:10 +00:00
|
|
|
public IAudioOutManager()
|
2018-02-25 04:34:16 +00:00
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
|
|
|
{ 0, ListAudioOuts },
|
2018-03-16 00:06:24 +00:00
|
|
|
{ 1, OpenAudioOut }
|
2018-02-25 04:34:16 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public long ListAudioOuts(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
long Position = Context.Request.ReceiveBuff[0].Position;
|
2018-04-24 21:14:26 +01:00
|
|
|
long Size = Context.Request.ReceiveBuff[0].Size;
|
|
|
|
|
|
|
|
int NameCount = 0;
|
2018-02-25 04:34:16 +00:00
|
|
|
|
2018-04-26 15:34:40 +01:00
|
|
|
byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DefaultAudioOutput + "\0");
|
2018-02-25 04:34:16 +00:00
|
|
|
|
2018-04-24 21:14:26 +01:00
|
|
|
if ((ulong)DeviceNameBuffer.Length <= (ulong)Size)
|
|
|
|
{
|
2018-06-09 17:05:41 +01:00
|
|
|
Context.Memory.WriteBytes(Position, DeviceNameBuffer);
|
2018-04-24 21:14:26 +01:00
|
|
|
|
|
|
|
NameCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Context.Ns.Log.PrintError(LogClass.ServiceAudio, $"Output buffer size {Size} too small!");
|
|
|
|
}
|
|
|
|
|
|
|
|
Context.ResponseData.Write(NameCount);
|
2018-02-25 04:34:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long OpenAudioOut(ServiceCtx Context)
|
|
|
|
{
|
2018-03-16 00:06:24 +00:00
|
|
|
IAalOutput AudioOut = Context.Ns.AudioOut;
|
|
|
|
|
|
|
|
string DeviceName = AMemoryHelper.ReadAsciiString(
|
|
|
|
Context.Memory,
|
|
|
|
Context.Request.SendBuff[0].Position,
|
|
|
|
Context.Request.SendBuff[0].Size);
|
|
|
|
|
|
|
|
if (DeviceName == string.Empty)
|
|
|
|
{
|
2018-04-24 21:14:26 +01:00
|
|
|
DeviceName = DefaultAudioOutput;
|
2018-03-16 00:06:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 21:14:26 +01:00
|
|
|
long Position = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
long Size = Context.Request.ReceiveBuff[0].Size;
|
2018-03-16 00:06:24 +00:00
|
|
|
|
2018-04-26 15:34:40 +01:00
|
|
|
byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName + "\0");
|
2018-03-16 00:06:24 +00:00
|
|
|
|
2018-04-24 21:14:26 +01:00
|
|
|
if ((ulong)DeviceNameBuffer.Length <= (ulong)Size)
|
|
|
|
{
|
2018-06-09 17:05:41 +01:00
|
|
|
Context.Memory.WriteBytes(Position, DeviceNameBuffer);
|
2018-04-24 21:14:26 +01:00
|
|
|
}
|
|
|
|
else
|
2018-03-16 00:06:24 +00:00
|
|
|
{
|
2018-04-24 21:14:26 +01:00
|
|
|
Context.Ns.Log.PrintError(LogClass.ServiceAudio, $"Output buffer size {Size} too small!");
|
2018-03-16 00:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SampleRate = Context.RequestData.ReadInt32();
|
|
|
|
int Channels = Context.RequestData.ReadInt32();
|
|
|
|
|
|
|
|
Channels = (ushort)(Channels >> 16);
|
|
|
|
|
|
|
|
if (SampleRate == 0)
|
|
|
|
{
|
|
|
|
SampleRate = 48000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Channels < 1 || Channels > 2)
|
|
|
|
{
|
|
|
|
Channels = 2;
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
KEvent ReleaseEvent = new KEvent();
|
|
|
|
|
|
|
|
ReleaseCallback Callback = () =>
|
|
|
|
{
|
2018-04-19 03:52:23 +01:00
|
|
|
ReleaseEvent.WaitEvent.Set();
|
2018-03-19 18:58:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback, out AudioFormat Format);
|
2018-03-16 00:06:24 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track));
|
2018-03-16 00:06:24 +00:00
|
|
|
|
|
|
|
Context.ResponseData.Write(SampleRate);
|
|
|
|
Context.ResponseData.Write(Channels);
|
|
|
|
Context.ResponseData.Write((int)Format);
|
|
|
|
Context.ResponseData.Write((int)PlaybackState.Stopped);
|
2018-02-25 04:34:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|