2019-10-11 15:22:24 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Audio.Types;
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
2018-11-17 03:36:49 +00:00
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
|
2018-11-17 03:36:49 +00:00
|
|
|
{
|
|
|
|
class IHardwareOpusDecoder : IpcService
|
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
private readonly IDecoder _decoder;
|
|
|
|
private readonly OpusDecoderFlags _flags;
|
2018-11-17 03:36:49 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
public IHardwareOpusDecoder(int sampleRate, int channelsCount, OpusDecoderFlags flags)
|
2018-11-17 03:36:49 +00:00
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
_decoder = new Decoder(sampleRate, channelsCount);
|
|
|
|
_flags = flags;
|
2018-11-17 03:36:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
public IHardwareOpusDecoder(int sampleRate, int channelsCount, int streams, int coupledStreams, OpusDecoderFlags flags, byte[] mapping)
|
2018-11-17 03:36:49 +00:00
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
_decoder = new MultiSampleDecoder(sampleRate, channelsCount, streams, coupledStreams, mapping);
|
|
|
|
_flags = flags;
|
2019-10-11 15:22:24 +00:00
|
|
|
}
|
2018-11-17 03:36:49 +00:00
|
|
|
|
2023-04-14 23:00:34 +00:00
|
|
|
[CommandCmif(0)]
|
2022-04-15 21:16:28 +00:00
|
|
|
// DecodeInterleavedOld(buffer<unknown, 5>) -> (u32, u32, buffer<unknown, 6>)
|
|
|
|
public ResultCode DecodeInterleavedOld(ServiceCtx context)
|
2019-10-11 15:22:24 +00:00
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset: false, withPerf: false);
|
2019-10-11 15:22:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 23:00:34 +00:00
|
|
|
[CommandCmif(2)]
|
2022-04-15 21:16:28 +00:00
|
|
|
// DecodeInterleavedForMultiStreamOld(buffer<unknown, 5>) -> (u32, u32, buffer<unknown, 6>)
|
|
|
|
public ResultCode DecodeInterleavedForMultiStreamOld(ServiceCtx context)
|
2019-10-11 15:22:24 +00:00
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset: false, withPerf: false);
|
2019-10-11 15:22:24 +00:00
|
|
|
}
|
2018-11-17 03:36:49 +00:00
|
|
|
|
2023-04-14 23:00:34 +00:00
|
|
|
[CommandCmif(4)] // 6.0.0+
|
2019-10-11 15:22:24 +00:00
|
|
|
// DecodeInterleavedWithPerfOld(buffer<unknown, 5>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
|
|
|
public ResultCode DecodeInterleavedWithPerfOld(ServiceCtx context)
|
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset: false, withPerf: true);
|
|
|
|
}
|
2019-10-11 15:22:24 +00:00
|
|
|
|
2023-04-14 23:00:34 +00:00
|
|
|
[CommandCmif(5)] // 6.0.0+
|
2022-04-15 21:16:28 +00:00
|
|
|
// DecodeInterleavedForMultiStreamWithPerfOld(buffer<unknown, 5>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
|
|
|
public ResultCode DecodeInterleavedForMultiStreamWithPerfOld(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset: false, withPerf: true);
|
2018-11-17 03:36:49 +00:00
|
|
|
}
|
2019-07-12 01:13:43 +00:00
|
|
|
|
2023-04-14 23:00:34 +00:00
|
|
|
[CommandCmif(6)] // 6.0.0+
|
2022-04-15 21:16:28 +00:00
|
|
|
// DecodeInterleavedWithPerfAndResetOld(bool reset, buffer<unknown, 5>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
|
|
|
public ResultCode DecodeInterleavedWithPerfAndResetOld(ServiceCtx context)
|
2019-07-12 01:13:43 +00:00
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
bool reset = context.RequestData.ReadBoolean();
|
2019-10-11 15:22:24 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset, withPerf: true);
|
|
|
|
}
|
2019-07-12 01:13:43 +00:00
|
|
|
|
2023-04-14 23:00:34 +00:00
|
|
|
[CommandCmif(7)] // 6.0.0+
|
2022-04-15 21:16:28 +00:00
|
|
|
// DecodeInterleavedForMultiStreamWithPerfAndResetOld(bool reset, buffer<unknown, 5>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
|
|
|
public ResultCode DecodeInterleavedForMultiStreamWithPerfAndResetOld(ServiceCtx context)
|
|
|
|
{
|
|
|
|
bool reset = context.RequestData.ReadBoolean();
|
2019-10-11 15:22:24 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset, withPerf: true);
|
2019-10-11 15:22:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 23:00:34 +00:00
|
|
|
[CommandCmif(8)] // 7.0.0+
|
2019-10-11 15:22:24 +00:00
|
|
|
// DecodeInterleaved(bool reset, buffer<unknown, 0x45>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
|
|
|
public ResultCode DecodeInterleaved(ServiceCtx context)
|
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
bool reset = context.RequestData.ReadBoolean();
|
2019-10-11 15:22:24 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
return DecodeInterleavedInternal(context, _flags, reset, withPerf: true);
|
|
|
|
}
|
2019-10-11 15:22:24 +00:00
|
|
|
|
2023-04-14 23:00:34 +00:00
|
|
|
[CommandCmif(9)] // 7.0.0+
|
2022-04-15 21:16:28 +00:00
|
|
|
// DecodeInterleavedForMultiStream(bool reset, buffer<unknown, 0x45>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
|
|
|
public ResultCode DecodeInterleavedForMultiStream(ServiceCtx context)
|
|
|
|
{
|
|
|
|
bool reset = context.RequestData.ReadBoolean();
|
|
|
|
|
|
|
|
return DecodeInterleavedInternal(context, _flags, reset, withPerf: true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode DecodeInterleavedInternal(ServiceCtx context, OpusDecoderFlags flags, bool reset, bool withPerf)
|
|
|
|
{
|
2021-04-24 10:16:01 +00:00
|
|
|
ulong inPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong inSize = context.Request.SendBuff[0].Size;
|
|
|
|
ulong outputPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong outputSize = context.Request.ReceiveBuff[0].Size;
|
2019-10-11 15:22:24 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
ReadOnlySpan<byte> input = context.Memory.GetSpan(inPosition, (int)inSize);
|
2020-05-03 22:54:50 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
ResultCode result = _decoder.DecodeInterleaved(reset, input, out short[] outPcmData, outputSize, out uint outConsumed, out int outSamples);
|
2020-05-03 22:54:50 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
if (result == ResultCode.Success)
|
2019-10-11 15:22:24 +00:00
|
|
|
{
|
2022-04-15 21:16:28 +00:00
|
|
|
context.Memory.Write(outputPosition, MemoryMarshal.Cast<short, byte>(outPcmData.AsSpan()));
|
2019-10-11 15:22:24 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
context.ResponseData.Write(outConsumed);
|
|
|
|
context.ResponseData.Write(outSamples);
|
2019-10-11 15:22:24 +00:00
|
|
|
|
2022-04-15 21:16:28 +00:00
|
|
|
if (withPerf)
|
|
|
|
{
|
2019-10-11 15:22:24 +00:00
|
|
|
// This is the time the DSP took to process the request, TODO: fill this.
|
2022-04-15 21:16:28 +00:00
|
|
|
context.ResponseData.Write(0UL);
|
2019-10-11 15:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-12 01:13:43 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2018-11-17 03:36:49 +00:00
|
|
|
}
|
2019-07-12 01:13:43 +00:00
|
|
|
}
|