mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-11 17:30:00 +02:00
feat: Implement API handlers for live and VOD streaming and create database module.
This commit is contained in:
1 parent
72e28a398a
commit
ce82b9e824
3 files changed
+47
-11
No files matched your search
@@ -116,7 +116,8 @@ PlaylistConfig? _getCurrentPlaylist(Request request) {
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
Handler createLiveStreamHandler(
|
Handler createLiveStreamHandler(
|
||||||
Future<PlaylistConfig?> Function(Request) getPlaylist) {
|
Future<PlaylistConfig?> Function(Request) getPlaylist,
|
||||||
|
{bool Function()? isGpuEnabled}) {
|
||||||
final router = Router();
|
final router = Router();
|
||||||
|
|
||||||
// Route: /api/live/{streamId} (Catch all pattern to debug)
|
// Route: /api/live/{streamId} (Catch all pattern to debug)
|
||||||
@@ -144,11 +145,13 @@ Handler createLiveStreamHandler(
|
|||||||
'${playlist.dns}/live/${playlist.username}/${playlist.password}/$streamId.ts';
|
'${playlist.dns}/live/${playlist.username}/${playlist.password}/$streamId.ts';
|
||||||
print('[Live] Streaming via FFmpeg: $targetUrl');
|
print('[Live] Streaming via FFmpeg: $targetUrl');
|
||||||
|
|
||||||
// Log GPU status once
|
// Check if NVIDIA GPU is enabled (from database setting or env var fallback)
|
||||||
_logGpuStatus();
|
final useNvidiaGpu = isGpuEnabled?.call() ?? _isNvidiaGpuEnabled();
|
||||||
|
|
||||||
// Check if NVIDIA GPU is enabled
|
// Log GPU status
|
||||||
final useNvidiaGpu = _isNvidiaGpuEnabled();
|
if (useNvidiaGpu) {
|
||||||
|
print('[Live] Using NVIDIA GPU acceleration (NVDEC)');
|
||||||
|
}
|
||||||
|
|
||||||
// Build FFmpeg arguments
|
// Build FFmpeg arguments
|
||||||
final ffmpegArgs = <String>[
|
final ffmpegArgs = <String>[
|
||||||
@@ -268,7 +271,8 @@ Handler createLiveStreamHandler(
|
|||||||
final _lastLogTime = <String, int>{};
|
final _lastLogTime = <String, int>{};
|
||||||
|
|
||||||
Handler createVodStreamHandler(
|
Handler createVodStreamHandler(
|
||||||
Future<PlaylistConfig?> Function(Request) getPlaylist) {
|
Future<PlaylistConfig?> Function(Request) getPlaylist,
|
||||||
|
{bool Function()? isGpuEnabled}) {
|
||||||
final router = Router();
|
final router = Router();
|
||||||
|
|
||||||
// Route: /api/vod/{streamId}/playlist.m3u8
|
// Route: /api/vod/{streamId}/playlist.m3u8
|
||||||
@@ -345,9 +349,12 @@ Handler createVodStreamHandler(
|
|||||||
'${playlist.dns}/$basePath/${playlist.username}/${playlist.password}/$streamId.mkv';
|
'${playlist.dns}/$basePath/${playlist.username}/${playlist.password}/$streamId.mkv';
|
||||||
print('[VOD] Starting Transcode ($contentType): $targetUrl');
|
print('[VOD] Starting Transcode ($contentType): $targetUrl');
|
||||||
|
|
||||||
// Log GPU status and check if enabled
|
// Check if NVIDIA GPU is enabled (from database setting or env var fallback)
|
||||||
_logGpuStatus();
|
final useNvidiaGpu = isGpuEnabled?.call() ?? _isNvidiaGpuEnabled();
|
||||||
final useNvidiaGpu = _isNvidiaGpuEnabled();
|
|
||||||
|
if (useNvidiaGpu) {
|
||||||
|
print('[VOD] Using NVIDIA GPU acceleration (NVENC)');
|
||||||
|
}
|
||||||
|
|
||||||
// Build FFmpeg arguments
|
// Build FFmpeg arguments
|
||||||
final ffmpegArgs = <String>[
|
final ffmpegArgs = <String>[
|
||||||
|
|||||||
@@ -373,6 +373,29 @@ class AppDatabase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if NVIDIA GPU is enabled in any user's settings
|
||||||
|
/// This is a server-wide setting that applies to all streaming
|
||||||
|
bool isNvidiaGpuEnabled() {
|
||||||
|
try {
|
||||||
|
// Check all user settings for enable_nvidia_gpu
|
||||||
|
final result = _db.select(
|
||||||
|
'SELECT settings_json FROM user_settings ORDER BY updated_at DESC LIMIT 1',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.isEmpty) return false;
|
||||||
|
|
||||||
|
final settingsJson = result.first['settings_json'] as String;
|
||||||
|
// Parse JSON to check the setting
|
||||||
|
// Settings key: enable_nvidia_gpu
|
||||||
|
if (settingsJson.contains('"enable_nvidia_gpu":true')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print('[Database] Error checking GPU setting: $e');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Close database connection
|
/// Close database connection
|
||||||
void close() {
|
void close() {
|
||||||
_db.dispose();
|
_db.dispose();
|
||||||
|
|||||||
+8
-2
@@ -172,8 +172,14 @@ void main(List<String> args) async {
|
|||||||
|
|
||||||
// Create Streaming Router (Mount handlers on correct paths)
|
// Create Streaming Router (Mount handlers on correct paths)
|
||||||
final streamingRouter = Router()
|
final streamingRouter = Router()
|
||||||
..mount('/api/live', createLiveStreamHandler(getPlaylist))
|
..mount(
|
||||||
..mount('/api/vod', createVodStreamHandler(getPlaylist));
|
'/api/live',
|
||||||
|
createLiveStreamHandler(getPlaylist,
|
||||||
|
isGpuEnabled: db.isNvidiaGpuEnabled))
|
||||||
|
..mount(
|
||||||
|
'/api/vod',
|
||||||
|
createVodStreamHandler(getPlaylist,
|
||||||
|
isGpuEnabled: db.isNvidiaGpuEnabled));
|
||||||
|
|
||||||
// Main handler with API proxy and NEW Streaming Handlers
|
// Main handler with API proxy and NEW Streaming Handlers
|
||||||
final handler = Cascade()
|
final handler = Cascade()
|
||||||
|
|||||||
Reference in new issue
Block a user