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