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