79bbbd4956
Processors now emit a ProcessedAudio plan with a streamed writer instead of a whole-file AudioBinary; vault writes stream via RegisterResourceStreamingAsync. Header parsing is bounded. Wave 2 (waveform/Opus) still re-reads the full file by design.
43 lines
1.8 KiB
C#
43 lines
1.8 KiB
C#
using DeepDrftContent.FileDatabase.Models;
|
|
|
|
namespace DeepDrftContent.Processors;
|
|
|
|
/// <summary>
|
|
/// Dispatches an audio file to the correct format processor by extension. The single seam through
|
|
/// which <see cref="TrackContentService"/> processes uploads, so callers depend on one abstraction
|
|
/// rather than three concrete processors.
|
|
/// </summary>
|
|
public class AudioProcessorRouter
|
|
{
|
|
private readonly AudioProcessor _wavProcessor;
|
|
private readonly Mp3AudioProcessor _mp3Processor;
|
|
private readonly FlacAudioProcessor _flacProcessor;
|
|
|
|
public AudioProcessorRouter(
|
|
AudioProcessor wavProcessor,
|
|
Mp3AudioProcessor mp3Processor,
|
|
FlacAudioProcessor flacProcessor)
|
|
{
|
|
_wavProcessor = wavProcessor;
|
|
_mp3Processor = mp3Processor;
|
|
_flacProcessor = flacProcessor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Processes <paramref name="filePath"/> with the processor matching its extension, returning a
|
|
/// <see cref="ProcessedAudio"/> store plan (extracted metadata plus a streamed writer for the
|
|
/// canonical vault bytes). Throws <see cref="ArgumentException"/> for unsupported extensions.
|
|
/// </summary>
|
|
public async Task<ProcessedAudio?> ProcessAudioFileAsync(string filePath, CancellationToken cancellationToken = default)
|
|
{
|
|
var ext = Path.GetExtension(filePath).ToLowerInvariant();
|
|
return ext switch
|
|
{
|
|
".wav" => await _wavProcessor.ProcessWavFileAsync(filePath, cancellationToken),
|
|
".mp3" => await _mp3Processor.ProcessMp3FileAsync(filePath, cancellationToken),
|
|
".flac" => await _flacProcessor.ProcessFlacFileAsync(filePath, cancellationToken),
|
|
_ => throw new ArgumentException($"Unsupported audio format: {ext}", nameof(filePath)),
|
|
};
|
|
}
|
|
}
|