2021-07-06 13:49:51 -04:00
|
|
|
using Ryujinx.Common;
|
2019-09-18 20:45:11 -04:00
|
|
|
using Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager;
|
2021-07-06 13:49:51 -04:00
|
|
|
using Ryujinx.HLE.HOS.Services.Audio.Types;
|
2019-09-18 20:45:11 -04:00
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Audio
|
2018-11-16 22:36:49 -05:00
|
|
|
{
|
2019-07-10 11:59:54 -04:00
|
|
|
[Service("hwopus")]
|
2018-11-16 22:36:49 -05:00
|
|
|
class IHardwareOpusDecoderManager : IpcService
|
|
|
|
{
|
2019-07-11 21:13:43 -04:00
|
|
|
public IHardwareOpusDecoderManager(ServiceCtx context) { }
|
2018-11-16 22:36:49 -05:00
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(0)]
|
2019-07-11 21:13:43 -04:00
|
|
|
// Initialize(bytes<8, 4>, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode Initialize(ServiceCtx context)
|
2018-11-16 22:36:49 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
int sampleRate = context.RequestData.ReadInt32();
|
|
|
|
int channelsCount = context.RequestData.ReadInt32();
|
2018-11-16 22:36:49 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
MakeObject(context, new IHardwareOpusDecoder(sampleRate, channelsCount));
|
2018-11-16 22:36:49 -05:00
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
// Close transfer memory immediately as we don't use it.
|
|
|
|
context.Device.System.KernelContext.Syscall.CloseHandle(context.Request.HandleDesc.ToCopy[0]);
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-11-16 22:36:49 -05:00
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(1)]
|
2019-07-11 21:13:43 -04:00
|
|
|
// GetWorkBufferSize(bytes<8, 4>) -> u32
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetWorkBufferSize(ServiceCtx context)
|
2018-11-16 22:36:49 -05:00
|
|
|
{
|
2021-07-06 13:49:51 -04:00
|
|
|
// NOTE: The sample rate is ignored because it is fixed to 48KHz.
|
2018-12-06 06:16:24 -05:00
|
|
|
int sampleRate = context.RequestData.ReadInt32();
|
|
|
|
int channelsCount = context.RequestData.ReadInt32();
|
2018-11-16 22:36:49 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
context.ResponseData.Write(GetOpusDecoderSize(channelsCount));
|
2018-11-16 22:36:49 -05:00
|
|
|
|
2021-07-06 13:49:51 -04:00
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(4)] // 12.0.0+
|
|
|
|
// InitializeEx(OpusParametersEx, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
|
|
|
public ResultCode InitializeEx(ServiceCtx context)
|
|
|
|
{
|
|
|
|
OpusParametersEx parameters = context.RequestData.ReadStruct<OpusParametersEx>();
|
|
|
|
|
|
|
|
// UseLargeFrameSize can be ignored due to not relying on fixed size buffers for storing the decoded result.
|
|
|
|
MakeObject(context, new IHardwareOpusDecoder(parameters.SampleRate, parameters.ChannelCount));
|
|
|
|
|
|
|
|
// Close transfer memory immediately as we don't use it.
|
|
|
|
context.Device.System.KernelContext.Syscall.CloseHandle(context.Request.HandleDesc.ToCopy[0]);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(5)] // 12.0.0+
|
|
|
|
// GetWorkBufferSizeEx(OpusParametersEx) -> u32
|
|
|
|
public ResultCode GetWorkBufferSizeEx(ServiceCtx context)
|
|
|
|
{
|
|
|
|
OpusParametersEx parameters = context.RequestData.ReadStruct<OpusParametersEx>();
|
|
|
|
|
|
|
|
// NOTE: The sample rate is ignored because it is fixed to 48KHz.
|
|
|
|
context.ResponseData.Write(GetOpusDecoderSize(parameters.ChannelCount));
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-11-16 22:36:49 -05:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
private static int GetOpusDecoderSize(int channelsCount)
|
2018-11-16 22:36:49 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
const int silkDecoderSize = 0x2198;
|
2018-11-16 22:36:49 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (channelsCount < 1 || channelsCount > 2)
|
2018-11-16 22:36:49 -05:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
int celtDecoderSize = GetCeltDecoderSize(channelsCount);
|
2018-11-16 22:36:49 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
int opusDecoderSize = (channelsCount * 0x800 + 0x4807) & -0x800 | 0x50;
|
2018-11-16 22:36:49 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
return opusDecoderSize + silkDecoderSize + celtDecoderSize;
|
2018-11-16 22:36:49 -05:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
private static int GetCeltDecoderSize(int channelsCount)
|
2018-11-16 22:36:49 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
const int decodeBufferSize = 0x2030;
|
|
|
|
const int celtDecoderSize = 0x58;
|
|
|
|
const int celtSigSize = 0x4;
|
|
|
|
const int overlap = 120;
|
|
|
|
const int eBandsCount = 21;
|
|
|
|
|
|
|
|
return (decodeBufferSize + overlap * 4) * channelsCount +
|
|
|
|
eBandsCount * 16 +
|
|
|
|
celtDecoderSize +
|
|
|
|
celtSigSize;
|
2018-11-16 22:36:49 -05:00
|
|
|
}
|
|
|
|
}
|
2019-07-11 21:13:43 -04:00
|
|
|
}
|