2020-07-26 15:25:04 -07:00
using Ryujinx.Cpu ;
2020-12-01 15:23:43 -08:00
using Ryujinx.Memory ;
2020-07-26 15:25:04 -07:00
using System ;
using System.Text ;
namespace Ryujinx.HLE.HOS.Services.Audio
2019-09-18 17:45:11 -07:00
{
[Service("audin:u")]
class IAudioInManager : IpcService
{
2020-07-26 15:25:04 -07:00
private const string DefaultAudioInsName = "BuiltInHeadset" ;
2019-09-18 17:45:11 -07:00
public IAudioInManager ( ServiceCtx context ) { }
2020-07-26 15:25:04 -07:00
[Command(0)]
// ListAudioIns() -> (u32 count, buffer<bytes, 6> names)
public ResultCode ListAudioIns ( ServiceCtx context )
{
long bufferPosition = context . Request . ReceiveBuff [ 0 ] . Position ;
long bufferSize = context . Request . ReceiveBuff [ 0 ] . Size ;
// NOTE: The service check if AudioInManager thread is started, if not it starts it.
uint count = ListAudioInsImpl ( context . Memory , bufferPosition , bufferSize , false ) ;
context . ResponseData . Write ( count ) ;
return ResultCode . Success ;
}
2020-11-21 12:43:36 -08:00
[Command(2)] // 3.0.0+
2020-07-26 15:25:04 -07:00
// ListAudioInsAuto() -> (u32 count, buffer<bytes, 0x22> names)
public ResultCode ListAudioInsAuto ( ServiceCtx context )
{
( long bufferPosition , long bufferSize ) = context . Request . GetBufferType0x22 ( ) ;
// NOTE: The service check if AudioInManager thread is started, if not it starts it.
uint count = ListAudioInsImpl ( context . Memory , bufferPosition , bufferSize , false ) ;
context . ResponseData . Write ( count ) ;
return ResultCode . Success ;
}
[Command(4)] // 3.0.0+
// ListAudioInsAutoFiltered() -> (u32 count, buffer<bytes, 0x22> names)
public ResultCode ListAudioInsAutoFiltered ( ServiceCtx context )
{
( long bufferPosition , long bufferSize ) = context . Request . GetBufferType0x22 ( ) ;
// NOTE: The service check if AudioInManager thread is started, if not it starts it.
uint count = ListAudioInsImpl ( context . Memory , bufferPosition , bufferSize , true ) ;
context . ResponseData . Write ( count ) ;
return ResultCode . Success ;
}
2020-12-01 15:23:43 -08:00
private uint ListAudioInsImpl ( IVirtualMemoryManager memory , long bufferPosition , long bufferSize , bool filtered = false )
2020-07-26 15:25:04 -07:00
{
uint count = 0 ;
MemoryHelper . FillWithZeros ( memory , bufferPosition , ( int ) bufferSize ) ;
if ( bufferSize > 0 )
{
// NOTE: The service also check that the input target is enabled when in filtering mode, as audctl and most of the audin logic isn't supported, we don't support it.
if ( ! filtered )
{
byte [ ] deviceNameBuffer = Encoding . ASCII . GetBytes ( DefaultAudioInsName + "\0" ) ;
memory . Write ( ( ulong ) bufferPosition , deviceNameBuffer ) ;
count + + ;
}
// NOTE: The service adds other input devices names available in the buffer,
// every name is aligned to 0x100 bytes.
// Since we don't support it for now, it's fine to do nothing here.
}
return count ;
}
2019-09-18 17:45:11 -07:00
}
}