2018-03-01 20:06:05 -08:00
|
|
|
using ChocolArm64.Memory;
|
2018-03-15 17:06:24 -07:00
|
|
|
using Ryujinx.Audio;
|
2018-06-10 17:46:42 -07:00
|
|
|
using Ryujinx.HLE.Logging;
|
|
|
|
using Ryujinx.HLE.OsHle.Handles;
|
|
|
|
using Ryujinx.HLE.OsHle.Ipc;
|
2018-02-08 09:20:07 -08:00
|
|
|
using System;
|
2018-02-08 08:52:02 -08:00
|
|
|
using System.Collections.Generic;
|
2018-02-08 09:20:07 -08:00
|
|
|
|
2018-06-10 17:46:42 -07:00
|
|
|
namespace Ryujinx.HLE.OsHle.Services.Aud
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-19 11:58:46 -07:00
|
|
|
class IAudioOut : IpcService, IDisposable
|
2018-02-08 08:52:02 -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;
|
2018-02-09 16:14:55 -08:00
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
private IAalOutput AudioOut;
|
|
|
|
|
2018-03-19 11:58:46 -07:00
|
|
|
private KEvent ReleaseEvent;
|
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
private int Track;
|
|
|
|
|
2018-03-19 11:58:46 -07:00
|
|
|
public IAudioOut(IAalOutput AudioOut, KEvent ReleaseEvent, int Track)
|
2018-02-09 16:14:55 -08:00
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
{ 0, GetAudioOutState },
|
|
|
|
{ 1, StartAudioOut },
|
|
|
|
{ 2, StopAudioOut },
|
|
|
|
{ 3, AppendAudioOutBuffer },
|
|
|
|
{ 4, RegisterBufferEvent },
|
|
|
|
{ 5, GetReleasedAudioOutBuffer },
|
|
|
|
{ 6, ContainsAudioOutBuffer },
|
|
|
|
{ 7, AppendAudioOutBufferEx },
|
|
|
|
{ 8, GetReleasedAudioOutBufferEx }
|
2018-02-09 16:14:55 -08:00
|
|
|
};
|
2018-02-08 08:52:02 -08:00
|
|
|
|
2018-03-19 11:58:46 -07:00
|
|
|
this.AudioOut = AudioOut;
|
|
|
|
this.ReleaseEvent = ReleaseEvent;
|
|
|
|
this.Track = Track;
|
2018-03-15 17:06:24 -07:00
|
|
|
}
|
2018-02-08 08:52:02 -08:00
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long GetAudioOutState(ServiceCtx Context)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
Context.ResponseData.Write((int)AudioOut.GetState(Track));
|
2018-02-08 08:52:02 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long StartAudioOut(ServiceCtx Context)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
AudioOut.Start(Track);
|
2018-02-08 08:52:02 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long StopAudioOut(ServiceCtx Context)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
AudioOut.Stop(Track);
|
2018-02-08 08:52:02 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long AppendAudioOutBuffer(ServiceCtx Context)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
long Tag = Context.RequestData.ReadInt64();
|
2018-02-08 08:52:02 -08:00
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
AudioOutData Data = AMemoryHelper.Read<AudioOutData>(
|
|
|
|
Context.Memory,
|
|
|
|
Context.Request.SendBuff[0].Position);
|
2018-04-24 11:57:39 -07:00
|
|
|
|
2018-06-08 17:15:02 -07:00
|
|
|
byte[] Buffer = Context.Memory.ReadBytes(
|
2018-03-15 17:06:24 -07:00
|
|
|
Data.SampleBufferPtr,
|
|
|
|
Data.SampleBufferSize);
|
2018-03-01 20:06:05 -08:00
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
AudioOut.AppendBuffer(Track, Tag, Buffer);
|
2018-02-08 08:52:02 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long RegisterBufferEvent(ServiceCtx Context)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-19 11:58:46 -07:00
|
|
|
int Handle = Context.Process.HandleTable.OpenHandle(ReleaseEvent);
|
2018-02-08 08:52:02 -08:00
|
|
|
|
|
|
|
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long GetReleasedAudioOutBuffer(ServiceCtx Context)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
long Position = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
long Size = Context.Request.ReceiveBuff[0].Size;
|
|
|
|
|
|
|
|
uint Count = (uint)((ulong)Size >> 3);
|
2018-02-08 08:52:02 -08:00
|
|
|
|
2018-03-15 20:42:44 -07:00
|
|
|
long[] ReleasedBuffers = AudioOut.GetReleasedBuffers(Track, (int)Count);
|
2018-03-15 17:06:24 -07:00
|
|
|
|
|
|
|
for (uint Index = 0; Index < Count; Index++)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
long Tag = 0;
|
2018-03-01 20:06:05 -08:00
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
if (Index < ReleasedBuffers.Length)
|
|
|
|
{
|
|
|
|
Tag = ReleasedBuffers[Index];
|
|
|
|
}
|
2018-02-08 08:52:02 -08:00
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
Context.Memory.WriteInt64(Position + Index * 8, Tag);
|
2018-02-08 08:52:02 -08:00
|
|
|
}
|
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
Context.ResponseData.Write(ReleasedBuffers.Length);
|
2018-03-01 20:06:05 -08:00
|
|
|
|
2018-02-08 08:52:02 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:14:55 -08:00
|
|
|
public long ContainsAudioOutBuffer(ServiceCtx Context)
|
2018-02-08 08:52:02 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
long Tag = Context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
Context.ResponseData.Write(AudioOut.ContainsBuffer(Track, Tag) ? 1 : 0);
|
2018-02-08 08:52:02 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
public long AppendAudioOutBufferEx(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-03-15 17:06:24 -07:00
|
|
|
|
2018-02-08 08:52:02 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-03 20:41:35 -08:00
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
public long GetReleasedAudioOutBufferEx(ServiceCtx Context)
|
2018-03-03 20:41:35 -08:00
|
|
|
{
|
2018-04-24 11:57:39 -07:00
|
|
|
Context.Ns.Log.PrintStub(LogClass.ServiceAudio, "Stubbed.");
|
2018-03-03 20:41:35 -08:00
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
return 0;
|
2018-03-03 20:41:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:06:24 -07:00
|
|
|
protected virtual void Dispose(bool Disposing)
|
2018-03-03 20:41:35 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
if (Disposing)
|
2018-03-03 20:41:35 -08:00
|
|
|
{
|
2018-03-15 17:06:24 -07:00
|
|
|
AudioOut.CloseTrack(Track);
|
2018-03-19 11:58:46 -07:00
|
|
|
|
|
|
|
ReleaseEvent.Dispose();
|
2018-03-03 20:41:35 -08:00
|
|
|
}
|
|
|
|
}
|
2018-02-08 08:52:02 -08:00
|
|
|
}
|
|
|
|
}
|