Adds seekable normalized audio track delivery

This commit is contained in:
BinaryAlley committed 2026-10-18 14:55:56 +03:00
1 parent 4e13b23f16
commit 45f9aa3bd5
57 files changed
+3452 -344

No files matched your search

@@ -11,25 +11,29 @@ namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.P
/// 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="UserId">The Id of the user whose request starts the production. It is used for the per-user admission limit, and never for the cache identity.</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="SourceContainer">The container of the stored audio file, as captured by the probe, used to pin the ffmpeg demuxer.</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="Bitrate">The stored audio bitrate of the track, in kbps, used to estimate a remux of a lossy codec.</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>
/// <param name="SourceLength">The length the source file had when the delivery was declared, in bytes. The production is rejected when the file no longer matches.</param>
/// <param name="SourceLastModifiedUtc">The last modification time the source file had when the delivery was declared. The production is rejected when the file no longer matches.</param>
[DebuggerDisplay("TrackId: {TrackId} Mode: {Mode} Container: {Container} Codec: {Codec}")]
public sealed record NormalizedTrackRequestDto(
Guid TrackId,
Guid UserId,
string SourcePath,
IReadOnlyList<string> AllowedRoots,
string? SourceContainer,
@@ -42,5 +46,7 @@ public sealed record NormalizedTrackRequestDto(
int SampleRate,
int Channels,
int? BitDepth,
PlaybackStreamingQuality Quality
PlaybackStreamingQuality Quality,
long SourceLength,
DateTime SourceLastModifiedUtc
);
@@ -0,0 +1,29 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using System.IO;
#endregion
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
/// <summary>
/// Data transfer object for a single produced segment of the normalized audio of a track, ready to be written to the response.
/// </summary>
/// <remarks>
/// The segment owns a live stream over a leased cache entry, so it is an internal delivery object of the API rather than a serializable
/// contract. The caller must dispose the stream once the response is written, which releases the cache reader lease.
/// </remarks>
/// <param name="Content">The read stream over the segment, which the caller owns and must release once the response is written.</param>
/// <param name="Length">The length of the segment, in bytes, taken from the index of the normalized audio.</param>
/// <param name="StartSeconds">The exact start of the segment on the track timeline, in seconds, taken from the index of the normalized audio.</param>
/// <param name="Container">The container of the delivered audio, used to resolve the media type of the segment.</param>
/// <param name="SegmentCount">The number of segments the production holds, so the caller can tell the end of the audio from a missing segment.</param>
/// <param name="DurationInSeconds">The duration of the produced normalized audio, in seconds, which can differ from the probed duration.</param>
[DebuggerDisplay("Length: {Length} StartSeconds: {StartSeconds} Container: {Container} SegmentCount: {SegmentCount}")]
public sealed record NormalizedTrackSegmentDataDto(
Stream Content,
long Length,
decimal StartSeconds,
string Container,
int SegmentCount,
int DurationInSeconds
);
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
/// <summary>
/// Data transfer object for the delivery a playback manifest issued to a user. It composes the exact normalization request the delivery declares,
/// so a new production input is added in one place and can never drift between the cache identity and the handle.
/// </summary>
/// <param name="Request">The complete normalization request the delivery declares, including its user, track, decision, quality and source identity.</param>
/// <param name="Shape">The shape the delivered audio is addressed by, which must be time addressed segments for a segment route.</param>
/// <param name="LibraryId">The Id of the library the track belongs to, so the segment route can scope the delivery without querying it again.</param>
/// <param name="AlbumId">The Id of the album the track belongs to, so the segment route can scope the delivery without querying it again.</param>
/// <param name="ArtistId">The Id of the artist that owns the album, so the segment route can scope the delivery without querying it again.</param>
[DebuggerDisplay("TrackId: {Request.TrackId} Mode: {Request.Mode} Container: {Request.Container} Codec: {Request.Codec}")]
public sealed record PlaybackDeliveryHandleDto(
NormalizedTrackRequestDto Request,
PlaybackDeliveryShape Shape,
Guid LibraryId,
Guid AlbumId,
Guid ArtistId
);
@@ -7,56 +7,30 @@ namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.T
/// <summary>
/// Data transfer object for the stored probe result of a track, containing only the fields a playback manifest is built from.
/// </summary>
/// <param name="Path">The file system path of the stored audio file of the track, used to bind a normalized delivery to the file version it was declared for.</param>
/// <param name="Container">The container of the audio file of the track, for example MP3, FLAC, OGG, AAC, MP4 or WAV, if applicable.</param>
/// <param name="AudioCodec">The audio codec used by the audio file of the track, if applicable.</param>
/// <param name="DurationInSeconds">The duration of the audio of the track in seconds.</param>
/// <param name="SampleRate">The sample rate of the audio of the track in Hz.</param>
/// <param name="Channels">The number of audio channels of the track.</param>
/// <param name="BitDepth">The bit depth of the audio of the track, if applicable.</param>
/// <param name="Bitrate">The bitrate of the audio of the track, in kbps, if applicable.</param>
/// <param name="ReplayGainTrackGain">The ReplayGain track gain of the track, in decibels, if applicable.</param>
/// <param name="ReplayGainTrackPeak">The ReplayGain track peak of the track, if applicable.</param>
/// <param name="ReplayGainAlbumGain">The ReplayGain album gain of the track, in decibels, if applicable.</param>
/// <param name="ReplayGainAlbumPeak">The ReplayGain album peak of the track, if applicable.</param>
[DebuggerDisplay("Container: {Container} Codec: {AudioCodec}")]
public sealed record TrackPlaybackManifestDto
{
/// <summary>
/// Gets the container of the audio file of the track, for example MP3, FLAC, OGG, AAC, MP4 or WAV, if applicable.
/// </summary>
public string? Container { get; init; }
/// <summary>
/// Gets the audio codec used by the audio file of the track, if applicable.
/// </summary>
public string? AudioCodec { get; init; }
/// <summary>
/// Gets the duration of the audio of the track in seconds.
/// </summary>
public int DurationInSeconds { get; init; }
/// <summary>
/// Gets the sample rate of the audio of the track in Hz.
/// </summary>
public int SampleRate { get; init; }
/// <summary>
/// Gets the number of audio channels of the track.
/// </summary>
public int Channels { get; init; }
/// <summary>
/// Gets the bit depth of the audio of the track, if applicable.
/// </summary>
public int? BitDepth { get; init; }
/// <summary>
/// Gets the ReplayGain track gain of the track, in decibels, if applicable.
/// </summary>
public decimal? ReplayGainTrackGain { get; init; }
/// <summary>
/// Gets the ReplayGain track peak of the track, if applicable.
/// </summary>
public decimal? ReplayGainTrackPeak { get; init; }
/// <summary>
/// Gets the ReplayGain album gain of the track, in decibels, if applicable.
/// </summary>
public decimal? ReplayGainAlbumGain { get; init; }
/// <summary>
/// Gets the ReplayGain album peak of the track, if applicable.
/// </summary>
public decimal? ReplayGainAlbumPeak { get; init; }
}
public sealed record TrackPlaybackManifestDto(
string Path,
string? Container,
string? AudioCodec,
int DurationInSeconds,
int SampleRate,
int Channels,
int? BitDepth,
int? Bitrate,
decimal? ReplayGainTrackGain,
decimal? ReplayGainTrackPeak,
decimal? ReplayGainAlbumGain,
decimal? ReplayGainAlbumPeak
);
@@ -7,55 +7,27 @@ namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.T
/// <summary>
/// Data transfer object for a track, containing the data needed to stream, or to describe the streaming of, its audio file.
/// </summary>
public sealed record TrackStreamDto
{
/// <summary>
/// Gets the file system path of the track.
/// </summary>
public required string Path { get; init; }
/// <summary>
/// Gets the Id of the media library the track belongs to.
/// </summary>
public required Guid LibraryId { get; init; }
/// <summary>
/// Gets the Id of the album the track belongs to.
/// </summary>
public required Guid AlbumId { get; init; }
/// <summary>
/// Gets the Id of the artist that owns the album the track belongs to.
/// </summary>
public required Guid ArtistId { get; init; }
/// <summary>
/// Gets the audio codec used by the audio file of the track, if applicable.
/// </summary>
public string? AudioCodec { get; init; }
/// <summary>
/// Gets the duration of the audio of the track in seconds.
/// </summary>
public int DurationInSeconds { get; init; }
/// <summary>
/// Gets the sample rate of the audio of the track in Hz.
/// </summary>
public int SampleRate { get; init; }
/// <summary>
/// Gets the number of audio channels of the track.
/// </summary>
public int Channels { get; init; }
/// <summary>
/// Gets the bit depth of the audio of the track, if applicable.
/// </summary>
public int? BitDepth { get; init; }
/// <summary>
/// Gets the bitrate of the audio of the track in kbps, if applicable.
/// </summary>
public int? Bitrate { get; init; }
}
/// <param name="Path">The file system path of the track.</param>
/// <param name="LibraryId">The Id of the media library the track belongs to.</param>
/// <param name="AlbumId">The Id of the album the track belongs to.</param>
/// <param name="ArtistId">The Id of the artist that owns the album the track belongs to.</param>
/// <param name="Container">The container of the audio file of the track, for example MP3, FLAC, OGG, AAC, MP4 or WAV, if applicable.</param>
/// <param name="AudioCodec">The audio codec used by the audio file of the track, if applicable.</param>
/// <param name="DurationInSeconds">The duration of the audio of the track in seconds.</param>
/// <param name="SampleRate">The sample rate of the audio of the track in Hz.</param>
/// <param name="Channels">The number of audio channels of the track.</param>
/// <param name="BitDepth">The bit depth of the audio of the track, if applicable.</param>
/// <param name="Bitrate">The bitrate of the audio of the track, in kbps, if applicable.</param>
public sealed record TrackStreamDto(
string Path,
Guid LibraryId,
Guid AlbumId,
Guid ArtistId,
string? Container,
string? AudioCodec,
int DurationInSeconds,
int SampleRate,
int Channels,
int? BitDepth,
int? Bitrate
);