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