/// <summary> /// Initialize the <see cref="MemoryPoolState"/> for system use. /// </summary> /// <param name="memoryPool">The <see cref="MemoryPoolState"/> for system use.</param> /// <param name="cpuAddress">The <see cref="CpuAddress"/> to assign.</param> /// <param name="size">The size to assign.</param> /// <returns>Returns true if mapping on the <see cref="Dsp.AudioProcessor"/> succeeded.</returns> public bool InitializeSystemPool(ref MemoryPoolState memoryPool, CpuAddress cpuAddress, ulong size) { if (memoryPool.Location != MemoryPoolState.LocationType.Dsp) { return(false); } return(InitializePool(ref memoryPool, cpuAddress, size)); }
/// <summary> /// Update a <see cref="MemoryPoolState"/> using user parameters. /// </summary> /// <param name="memoryPool">The <see cref="MemoryPoolState"/> to update.</param> /// <param name="inParameter">Input user parameter.</param> /// <param name="outStatus">Output user parameter.</param> /// <returns>Returns the <see cref="UpdateResult"/> of the operations performed.</returns> public UpdateResult Update(ref MemoryPoolState memoryPool, ref MemoryPoolInParameter inParameter, ref MemoryPoolOutStatus outStatus) { MemoryPoolUserState inputState = inParameter.State; MemoryPoolUserState outputState; const uint pageSize = 0x1000; if (inputState != MemoryPoolUserState.RequestAttach && inputState != MemoryPoolUserState.RequestDetach) { return(UpdateResult.Success); } if (inParameter.CpuAddress == 0 || (inParameter.CpuAddress & (pageSize - 1)) != 0) { return(UpdateResult.InvalidParameter); } if (inParameter.Size == 0 || (inParameter.Size & (pageSize - 1)) != 0) { return(UpdateResult.InvalidParameter); } if (inputState == MemoryPoolUserState.RequestAttach) { bool initializeSuccess = InitializePool(ref memoryPool, inParameter.CpuAddress, inParameter.Size); if (!initializeSuccess) { memoryPool.SetCpuAddress(0, 0); Logger.Error?.Print(LogClass.AudioRenderer, $"Map of memory pool (address: 0x{inParameter.CpuAddress:x}, size 0x{inParameter.Size:x}) failed!"); return(UpdateResult.MapError); } outputState = MemoryPoolUserState.Attached; } else { if (memoryPool.CpuAddress != inParameter.CpuAddress || memoryPool.Size != inParameter.Size) { return(UpdateResult.InvalidParameter); } if (!Unmap(ref memoryPool)) { Logger.Error?.Print(LogClass.AudioRenderer, $"Unmap of memory pool (address: 0x{memoryPool.CpuAddress:x}, size 0x{memoryPool.Size:x}) failed!"); return(UpdateResult.UnmapError); } outputState = MemoryPoolUserState.Detached; } outStatus.State = outputState; return(UpdateResult.Success); }
/// <summary> /// Map the <see cref="MemoryPoolState"/> on the <see cref="Dsp.AudioProcessor"/>. /// </summary> /// <param name="memoryPool">The <see cref="MemoryPoolState"/> to map.</param> /// <returns>Returns the DSP address mapped.</returns> public DspAddress Map(ref MemoryPoolState memoryPool) { DspAddress result = AudioProcessorMemoryManager.Map(GetProcessHandle(ref memoryPool), memoryPool.CpuAddress, memoryPool.Size); if (result != 0) { memoryPool.DspAddress = result; } return(result); }
/// <summary> /// Get the process handle associated to the <see cref="MemoryPoolState"/>. /// </summary> /// <param name="memoryPool">The <see cref="MemoryPoolState"/>.</param> /// <returns>Returns the process handle associated to the <see cref="MemoryPoolState"/>.</returns> public uint GetProcessHandle(ref MemoryPoolState memoryPool) { if (memoryPool.Location == MemoryPoolState.LocationType.Cpu) { return(CurrentProcessPseudoHandle); } else if (memoryPool.Location == MemoryPoolState.LocationType.Dsp) { return(_processHandle); } return(0); }
/// <summary> /// Unmap the <see cref="MemoryPoolState"/> from the <see cref="Dsp.AudioProcessor"/>. /// </summary> /// <param name="memoryPool">The <see cref="MemoryPoolState"/> to unmap.</param> /// <returns>Returns true if unmapped.</returns> public bool Unmap(ref MemoryPoolState memoryPool) { if (memoryPool.IsUsed) { return(false); } AudioProcessorMemoryManager.Unmap(GetProcessHandle(ref memoryPool), memoryPool.CpuAddress, memoryPool.Size); memoryPool.SetCpuAddress(0, 0); memoryPool.DspAddress = 0; return(true); }
/// <summary> /// Initialize the <see cref="MemoryPoolState"/>. /// </summary> /// <param name="memoryPool">The <see cref="MemoryPoolState"/>.</param> /// <param name="cpuAddress">The <see cref="CpuAddress"/> to assign.</param> /// <param name="size">The size to assign.</param> /// <returns>Returns true if mapping on the <see cref="Dsp.AudioProcessor"/> succeeded.</returns> public bool InitializePool(ref MemoryPoolState memoryPool, CpuAddress cpuAddress, ulong size) { memoryPool.SetCpuAddress(cpuAddress, size); return(Map(ref memoryPool) != 0); }