From 099d7da53f588cfd40c400a7a9f424e4472ffc42 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 2 Apr 2026 07:43:23 +0200 Subject: [PATCH] feat: implement streaming handler with FFmpeg-based HLS transcoding and GPU acceleration support --- bin/api/streaming_handler.dart | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/api/streaming_handler.dart b/bin/api/streaming_handler.dart index 98b3b06..67a24a8 100644 --- a/bin/api/streaming_handler.dart +++ b/bin/api/streaming_handler.dart @@ -564,13 +564,29 @@ Handler createRecordingStreamHandler( router.get('//playlist.m3u8', (Request request, String streamId) async { final recording = db.getRecordingById(streamId); - if (recording == null || recording.filePath == null) { - return Response.internalServerError(body: 'DEBUG_ERROR: Recording $streamId or file not found in DB'); + if (recording == null) { + return Response.notFound('Recording not found'); + } + + // Check recording status - only allow streaming if completed or recording + if (recording.status == 'scheduled') { + return Response(202, body: 'Recording not yet started'); + } + if (recording.status == 'failed') { + return Response(422, body: 'Recording failed: ${recording.errorReason ?? 'unknown error'}'); + } + if (recording.status != 'completed' && recording.status != 'recording') { + return Response.internalServerError(body: 'Invalid recording status: ${recording.status}'); + } + + // Check file path and existence + if (recording.filePath == null) { + return Response.internalServerError(body: 'Recording file path not set'); } final targetUrl = recording.filePath!; if (!File(targetUrl).existsSync()) { - return Response.internalServerError(body: 'DEBUG_ERROR: Physical recording file $targetUrl DOES NOT EXIST on disk.'); + return Response.internalServerError(body: 'Physical recording file not found: $targetUrl'); } final streamDir = Directory('${_hlsTempDir.path}/rec_$streamId');