2018-06-22 22:00:14 -07:00
|
|
|
using ChocolArm64.Memory;
|
2018-06-10 17:46:42 -07:00
|
|
|
using Ryujinx.HLE.Logging;
|
|
|
|
using Ryujinx.HLE.OsHle.Handles;
|
|
|
|
using Ryujinx.HLE.OsHle.Ipc;
|
2018-03-19 11:58:46 -07:00
|
|
|
using System;
|
2018-02-09 16:14:55 -08:00
|
|
|
using System.Collections.Generic;
|
2018-06-22 22:00:14 -07:00
|
|
|
using System.Runtime.InteropServices;
|
2018-02-08 08:52:02 -08:00
|
|
|
|
2018-06-10 17:46:42 -07:00
|
|
|
namespace Ryujinx.HLE.OsHle.Services.Aud
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-03-19 11:58:46 -07:00
|
|
|
class IAudioRenderer : IpcService, IDisposable
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-09 16:14:55 -08:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
2018-03-19 11:58:46 -07:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
|
|
|
|
|
|
|
private KEvent UpdateEvent;
|
2018-02-09 16:14:55 -08:00
|
|
|
|
2018-06-22 22:00:14 -07:00
|
|
|
private AudioRendererParameter Params;
|
|
|
|
|
|
|
|
public IAudioRenderer(AudioRendererParameter Params)
|
2018-02-09 16:14:55 -08:00
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
|
|
|
{ 4, RequestUpdateAudioRenderer },
|
|
|
|
{ 5, StartAudioRenderer },
|
|
|
|
{ 6, StopAudioRenderer },
|
|
|
|
{ 7, QuerySystemEvent }
|
|
|
|
};
|
2018-03-19 11:58:46 -07:00
|
|
|
|
|
|
|
UpdateEvent = new KEvent();
|
2018-06-22 22:00:14 -07:00
|
|
|
|
|
|
|
this.Params = Params;
|
2018-02-09 16:14:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public long RequestUpdateAudioRenderer(ServiceCtx Context)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-06-22 22:00:14 -07:00
|
|
|
long OutputPosition = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
|
|
|
long InputPosition = Context.Request.SendBuff[0].Position;
|
|
|
|
|
|
|
|
UpdateDataHeader InputDataHeader = AMemoryHelper.Read<UpdateDataHeader>(Context.Memory, InputPosition);
|
|
|
|
|
|
|
|
int MemoryPoolOffset = Marshal.SizeOf(InputDataHeader) + InputDataHeader.BehaviorSize;
|
|
|
|
|
|
|
|
UpdateDataHeader OutputDataHeader = new UpdateDataHeader();
|
2018-02-08 08:52:02 -08:00
|
|
|
|
2018-06-22 22:00:14 -07:00
|
|
|
OutputDataHeader.Revision = Params.Revision;
|
|
|
|
OutputDataHeader.BehaviorSize = 0xb0;
|
|
|
|
OutputDataHeader.MemoryPoolsSize = (Params.EffectCount + (Params.VoiceCount * 4)) * 0x10;
|
|
|
|
OutputDataHeader.VoicesSize = Params.VoiceCount * 0x10;
|
|
|
|
OutputDataHeader.EffectsSize = Params.EffectCount * 0x10;
|
|
|
|
OutputDataHeader.SinksSize = Params.SinkCount * 0x20;
|
|
|
|
OutputDataHeader.PerformanceManagerSize = 0x10;
|
|
|
|
OutputDataHeader.TotalSize = Marshal.SizeOf(OutputDataHeader) + OutputDataHeader.BehaviorSize + OutputDataHeader.MemoryPoolsSize +
|
|
|
|
OutputDataHeader.VoicesSize + OutputDataHeader.EffectsSize + OutputDataHeader.SinksSize + OutputDataHeader.PerformanceManagerSize;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-06-22 22:00:14 -07:00
|
|
|
AMemoryHelper.Write(Context.Memory, OutputPosition, OutputDataHeader);
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-06-22 22:00:14 -07:00
|
|
|
for (int Offset = 0x40; Offset < 0x40 + OutputDataHeader.MemoryPoolsSize; Offset += 0x10, MemoryPoolOffset += 0x20)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-06-22 22:00:14 -07:00
|
|
|
MemoryPoolStates PoolState = (MemoryPoolStates) Context.Memory.ReadInt32(InputPosition + MemoryPoolOffset + 0x10);
|
|
|
|
|
|
|
|
if (PoolState == MemoryPoolStates.RequestAttach)
|
|
|
|
{
|
|
|
|
Context.Memory.WriteInt32(OutputPosition + Offset, (int)MemoryPoolStates.Attached);
|
|
|
|
}
|
|
|
|
else if (PoolState == MemoryPoolStates.RequestDetach)
|
|
|
|
{
|
|
|
|
Context.Memory.WriteInt32(OutputPosition + Offset, (int)MemoryPoolStates.Detached);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Context.Memory.WriteInt32(OutputPosition + Offset, (int)PoolState);
|
|
|
|
}
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
2018-02-06 07:15:08 -08:00
|
|
|
|
2018-03-19 11:58:46 -07:00
|
|
|
//TODO: We shouldn't be signaling this here.
|
2018-04-18 19:52:23 -07:00
|
|
|
UpdateEvent.WaitEvent.Set();
|
2018-03-19 11:58:46 -07:00
|
|
|
|
2018-02-04 15:08:20 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long StartAudioRenderer(ServiceCtx Context)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-04-24 11:57:39 -07:00
|
|
|
Context.Ns.Log.PrintStub(LogClass.ServiceAudio, "Stubbed.");
|
2018-04-16 17:24:42 -07:00
|
|
|
|
2018-02-04 15:08:20 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long StopAudioRenderer(ServiceCtx Context)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-04-24 11:57:39 -07:00
|
|
|
Context.Ns.Log.PrintStub(LogClass.ServiceAudio, "Stubbed.");
|
2018-04-16 17:24:42 -07:00
|
|
|
|
2018-02-08 08:52:02 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long QuerySystemEvent(ServiceCtx Context)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-03-19 11:58:46 -07:00
|
|
|
int Handle = Context.Process.HandleTable.OpenHandle(UpdateEvent);
|
2018-02-08 08:52:02 -08:00
|
|
|
|
|
|
|
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
|
|
|
|
2018-02-04 15:08:20 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-19 11:58:46 -07:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool Disposing)
|
|
|
|
{
|
|
|
|
if (Disposing)
|
|
|
|
{
|
|
|
|
UpdateEvent.Dispose();
|
|
|
|
}
|
|
|
|
}
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
2018-06-22 22:00:14 -07:00
|
|
|
}
|
|
|
|
|