mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07:11:10 +00:00
Adds normalized audio playback pipeline
This commit is contained in:
1 parent
6991640710
commit
4e13b23f16
35 files changed
+3817
-41
No files matched your search
+34
@@ -0,0 +1,34 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the normalized audio of a track, produced and cached as a sequence of fixed duration segments.
|
||||
/// </summary>
|
||||
/// <param name="TrackId">The Id of the track whose audio the cached entry holds, so the caller can verify that the entry is the one it authorized.</param>
|
||||
/// <param name="CacheId">The opaque identifier of the cached entry that holds the normalized audio.</param>
|
||||
/// <param name="Mode">The way the audio is delivered, which is a remux or a transcode.</param>
|
||||
/// <param name="Container">The container of the delivered audio.</param>
|
||||
/// <param name="Codec">The codec of the delivered audio.</param>
|
||||
/// <param name="SegmentDurationSeconds">The duration of each segment of the delivered audio, in seconds.</param>
|
||||
/// <param name="DurationInSeconds">
|
||||
/// The duration of the produced and cached audio, in seconds, rounded up to the next second. It is the produced end rather than the probed duration, so
|
||||
/// it always covers every produced segment.
|
||||
/// </param>
|
||||
/// <param name="Segments">The segments that make up the delivered audio, in playback order.</param>
|
||||
[DebuggerDisplay("TrackId: {TrackId} CacheId: {CacheId} Container: {Container} Codec: {Codec}")]
|
||||
public sealed record NormalizedTrackDto(
|
||||
Guid TrackId,
|
||||
string CacheId,
|
||||
PlaybackDeliveryMode Mode,
|
||||
string Container,
|
||||
string Codec,
|
||||
int SegmentDurationSeconds,
|
||||
int DurationInSeconds,
|
||||
IReadOnlyList<NormalizedTrackSegmentDto> Segments
|
||||
);
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the request to produce the normalized audio of a track, as the delivery decision of a playback manifest describes it.
|
||||
/// </summary>
|
||||
/// <param name="TrackId">The Id of the track whose audio is normalized. It binds the produced cache entry to the track the caller authorized.</param>
|
||||
/// <param name="SourcePath">The file system path of the stored audio file of the track.</param>
|
||||
/// <param name="AllowedRoots">
|
||||
/// The content locations the source path is allowed to be inside. The service validates the path against them and re-checks it after opening, so a
|
||||
/// caller that forgets to enforce containment cannot hand an arbitrary path to the transcoder.
|
||||
/// </param>
|
||||
/// <param name="SourceContainer">The container of the stored audio file, as captured by the probe, used to pin the ffmpeg demuxer. Optional.</param>
|
||||
/// <param name="Mode">The way the audio is delivered, which is a remux or a transcode.</param>
|
||||
/// <param name="Container">The container of the delivered audio, as chosen by the delivery decision.</param>
|
||||
/// <param name="Codec">The codec of the delivered audio, as chosen by the delivery decision.</param>
|
||||
/// <param name="SegmentDurationSeconds">The duration of each segment of the delivered audio, in seconds.</param>
|
||||
/// <param name="DurationInSeconds">The duration of the audio of the track, in seconds.</param>
|
||||
/// <param name="Bitrate">The stored audio bitrate of the track, in kbps, used to estimate a remux of a lossy codec. Optional.</param>
|
||||
/// <param name="SampleRate">The sample rate of the stored audio of the track, in Hz, used to estimate the size of a lossless delivery.</param>
|
||||
/// <param name="Channels">The number of audio channels of the track, used to estimate the size of a lossless delivery.</param>
|
||||
/// <param name="BitDepth">The bit depth of the stored audio of the track, if applicable, used to estimate the size of a lossless delivery.</param>
|
||||
/// <param name="Quality">The quality cap applied to the delivered audio when it has to be re-encoded.</param>
|
||||
[DebuggerDisplay("TrackId: {TrackId} Mode: {Mode} Container: {Container} Codec: {Codec}")]
|
||||
public sealed record NormalizedTrackRequestDto(
|
||||
Guid TrackId,
|
||||
string SourcePath,
|
||||
IReadOnlyList<string> AllowedRoots,
|
||||
string? SourceContainer,
|
||||
PlaybackDeliveryMode Mode,
|
||||
string Container,
|
||||
string Codec,
|
||||
int SegmentDurationSeconds,
|
||||
int DurationInSeconds,
|
||||
int? Bitrate,
|
||||
int SampleRate,
|
||||
int Channels,
|
||||
int? BitDepth,
|
||||
PlaybackStreamingQuality Quality
|
||||
);
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a single fixed duration segment of the normalized audio of a track.
|
||||
/// </summary>
|
||||
/// <param name="Index">The zero based position of the segment in the delivered audio.</param>
|
||||
/// <param name="StartSeconds">The time, in seconds from the start of the track, at which the segment starts.</param>
|
||||
/// <param name="DurationSeconds">The duration of the segment, in seconds.</param>
|
||||
/// <param name="Length">The length of the segment, in bytes.</param>
|
||||
[DebuggerDisplay("Index: {Index} StartSeconds: {StartSeconds} DurationSeconds: {DurationSeconds}")]
|
||||
public sealed record NormalizedTrackSegmentDto(
|
||||
int Index,
|
||||
decimal StartSeconds,
|
||||
decimal DurationSeconds,
|
||||
long Length
|
||||
);
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the service that produces, caches and serves the normalized audio of a track, when the player cannot play the stored audio directly.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The caller is responsible for authorizing the request. The service re-validates the source path against the allowed roots carried by the request and
|
||||
/// re-checks it after opening, as defense in depth, so a caller that forgets containment cannot hand an arbitrary path to the transcoder. The service
|
||||
/// itself only handles the media pipeline: it never reads or writes a database row, and it never emits a domain event. Every entry is bound to the track
|
||||
/// it was produced for, so a cache handle can never be used to read the audio of another track.
|
||||
/// A production is atomic: the cache entry is published only after ffmpeg has finished the whole track, so the first request waits for a complete
|
||||
/// production. Streaming in this contract means serving the produced segments from the cache without buffering them into memory, not publishing a partial
|
||||
/// track. Incremental publication of segment 0 while the rest is produced would be a different contract. Admission is bounded: when every normalization job
|
||||
/// slot is in use, a request for an entry that is not cached yet is reported as unavailable instead of being queued behind the running jobs. A production
|
||||
/// that was admitted outlives the request that started it, so repeated aborts converge to a cached entry. A production that needs a toolchain the startup
|
||||
/// probe found unusable reports <see cref="Domain.Common.Errors.Errors.Playback.NormalizationUnavailable"/> as well, while an entry that is already
|
||||
/// cached is still served. The playback stream surface that exposes the produced segments is the intended consumer of this contract; no API request path
|
||||
/// calls it yet.
|
||||
/// </remarks>
|
||||
public interface ITrackNormalizationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the normalized audio of a track from the cache, or produces it and caches it when it is not cached yet.
|
||||
/// </summary>
|
||||
/// <param name="request">The track, the delivery decision, the source file and the quality cap the normalized audio is produced with.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the cached normalized audio of the track, or an error message.
|
||||
/// </returns>
|
||||
/// <exception cref="OperationCanceledException">
|
||||
/// Thrown when <paramref name="cancellationToken"/> is canceled while the caller is waiting. The production continues in the background, so this is a
|
||||
/// disconnect signal and must not be treated as a production failure.
|
||||
/// </exception>
|
||||
Task<Result<NormalizedTrackDto>> GetOrCreateNormalizedTrackAsync(NormalizedTrackRequestDto request, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Opens a read stream over a single segment of a cached normalized track, after verifying that the entry belongs to the provided track.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A missing or evicted cache entry, a segment that is no longer present, an entry that cannot be read, or a value that is not a well formed handle is
|
||||
/// reported with <see cref="Domain.Common.Errors.Errors.Playback.NormalizedTrackCacheEntryNotFound"/>. That is the caller's signal to request the
|
||||
/// playback manifest again, or to trigger a new production, instead of treating the result as a broken transcode. A genuine production failure keeps
|
||||
/// its own error. A service that has already been disposed reports
|
||||
/// <see cref="Domain.Common.Errors.Errors.Playback.NormalizationUnavailable"/>.
|
||||
/// </remarks>
|
||||
/// <param name="cacheId">The opaque identifier of the cached entry that holds the normalized audio.</param>
|
||||
/// <param name="trackId">The Id of the track the caller authorized and whose segment is opened.</param>
|
||||
/// <param name="segmentIndex">The zero based position of the segment in the delivered audio.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a read stream over the segment, or an error message. The caller owns the returned stream.
|
||||
/// </returns>
|
||||
Result<Stream> OpenNormalizedSegment(string cacheId, Guid trackId, int segmentIndex);
|
||||
}
|
||||
Reference in new issue
Block a user