feat(podcasts): prepare seekable MP4 replays and overlay controls
Remux completed broadcasts with FFmpeg, retain source segments and account for both formats. Serve authenticated byte ranges and add native Android/Desktop replay controls with auto-hide. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
ed75f06fb2
commit
1dcbfe159a
31 changed files with 1386 additions and 36 deletions
|
|
@ -58,7 +58,7 @@ public sealed class PodcastController(ILiveProcessor processor) : ControllerBase
|
|||
return Ok(await processor.AppendAsync(id, ownerId, sequence, duration, Request.Body, ct));
|
||||
}
|
||||
|
||||
/// <summary>Ends the broadcast and publishes its retained HLS replay.</summary>
|
||||
/// <summary>Ends the broadcast and schedules preparation of its MP4 replay.</summary>
|
||||
[HttpPost("{id:guid}/complete")]
|
||||
[ProducesResponseType<PodcastResponse>(StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<PodcastResponse>> Complete(Guid id, CancellationToken ct)
|
||||
|
|
@ -68,6 +68,30 @@ public sealed class PodcastController(ILiveProcessor processor) : ControllerBase
|
|||
return Ok(await processor.CompleteAsync(id, ownerId, ct));
|
||||
}
|
||||
|
||||
/// <summary>Serves a completed MP4 replay with authenticated byte-range support.</summary>
|
||||
[HttpGet("{id:guid}/replay.mp4")]
|
||||
[HttpHead("{id:guid}/replay.mp4")]
|
||||
[Produces("video/mp4")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status206PartialContent)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
||||
public async Task<IActionResult> Replay(Guid id, CancellationToken ct)
|
||||
{
|
||||
Response.Headers.CacheControl = "private, no-store";
|
||||
return File(await processor.OpenReplayAsync(id, ct), "video/mp4", enableRangeProcessing: true);
|
||||
}
|
||||
|
||||
/// <summary>Retries failed MP4 preparation. Only the broadcast owner can retry.</summary>
|
||||
[HttpPost("{id:guid}/replay/retry")]
|
||||
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||
public async Task<IActionResult> RetryReplay(Guid id, CancellationToken ct)
|
||||
{
|
||||
var ownerId = User.GetUserId();
|
||||
if (string.IsNullOrWhiteSpace(ownerId)) return Unauthorized();
|
||||
await processor.RetryReplayAsync(id, ownerId, ct);
|
||||
return AcceptedAtAction(nameof(Get), new { id }, value: null);
|
||||
}
|
||||
|
||||
/// <summary>Serves the authenticated event playlist, terminated for completed or interrupted replays.</summary>
|
||||
[HttpGet("{id:guid}/index.m3u8")]
|
||||
[Produces("application/vnd.apple.mpegurl")]
|
||||
|
|
|
|||
|
|
@ -36,6 +36,19 @@ Authorization: Bearer {{token}}
|
|||
POST {{baseUrl}}/api/v1/podcasts/{{id}}/complete
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### Ready MP4: authenticated seek range (206; 409 until replay.state is Ready)
|
||||
GET {{baseUrl}}/api/v1/podcasts/{{id}}/replay.mp4
|
||||
Authorization: Bearer {{token}}
|
||||
Range: bytes=0-65535
|
||||
|
||||
### MP4 size and range support without downloading the body
|
||||
HEAD {{baseUrl}}/api/v1/podcasts/{{id}}/replay.mp4
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### Retry failed MP4 preparation (owner only; 202)
|
||||
POST {{baseUrl}}/api/v1/podcasts/{{id}}/replay/retry
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### Delete an ended podcast (owner only)
|
||||
DELETE {{baseUrl}}/api/v1/podcasts/{{id}}
|
||||
Authorization: Bearer {{token}}
|
||||
|
|
|
|||
25
src/Yavsc.Api/Services/PodcastReplayWorker.cs
Normal file
25
src/Yavsc.Api/Services/PodcastReplayWorker.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using Yavsc.Services;
|
||||
|
||||
namespace Yavsc.Api.Services;
|
||||
|
||||
public sealed class PodcastReplayWorker(
|
||||
ILiveProcessor processor, IPodcastReplayRemuxer remuxer, ILogger<PodcastReplayWorker> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await processor.PrepareNextReplayAsync(remuxer, stoppingToken)) continue;
|
||||
}
|
||||
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested) { break; }
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Podcast MP4 worker failed; retrying the scan");
|
||||
}
|
||||
try { await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken); }
|
||||
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ public static class PodcastServiceCollectionExtensions
|
|||
{
|
||||
services.Configure<PodcastOptions>(configuration.GetSection("Podcast"));
|
||||
services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
||||
services.AddSingleton<IPodcastReplayRemuxer, FfmpegPodcastReplayRemuxer>();
|
||||
services.AddHostedService<PodcastReplayWorker>();
|
||||
services.AddOpenApi("podcasts", options => options.ShouldInclude = description => description.GroupName == "podcasts");
|
||||
return services;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue