From 1419f55ef6a57251b82703e7fc19c25795afdd9d Mon Sep 17 00:00:00 2001 From: Saelmala Date: Wed, 13 Nov 2024 11:31:26 +0100 Subject: [PATCH] fix: handle sources with same id from diff ingests --- .../ateliereLive/pipelines/streams/streams.ts | 4 ++- src/api/manager/productions.ts | 35 ++++++++++++++----- src/api/manager/workflow.ts | 9 +++-- .../[ingest_source_name]/route.ts | 8 +++-- src/app/production/[id]/page.tsx | 21 +++++++---- src/interfaces/pipeline.ts | 1 + 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/api/ateliereLive/pipelines/streams/streams.ts b/src/api/ateliereLive/pipelines/streams/streams.ts index bdc10bb6..eeae1d68 100644 --- a/src/api/ateliereLive/pipelines/streams/streams.ts +++ b/src/api/ateliereLive/pipelines/streams/streams.ts @@ -108,7 +108,9 @@ export async function createStream( ); const pipelineSource = pipeline.sources?.find( - (source) => source.source_id === sourceId + (s) => + s.source_id === sourceId && + s.settings.ingest_name === source.ingest_name ); const stream: PipelineStreamSettings = { diff --git a/src/api/manager/productions.ts b/src/api/manager/productions.ts index 716cd340..327a42b9 100644 --- a/src/api/manager/productions.ts +++ b/src/api/manager/productions.ts @@ -104,7 +104,8 @@ function deleteMonitoring(db: Db, productionId: string) { export async function getProductionPipelineSourceAlignment( productionId: string, pipelineId: string, - sourceId: number + sourceId: number, + sourceIngestName: string ) { const production = await getProduction(productionId); @@ -118,7 +119,9 @@ export async function getProductionPipelineSourceAlignment( ); const source = pipeline?.sources?.find( - (source) => String(source.source_id) === String(sourceId) + (source) => + String(source.source_id) === String(sourceId) && + source.settings.ingest_name === sourceIngestName ); const alignment = @@ -133,6 +136,7 @@ export async function setProductionPipelineSourceAlignment( productionId: string, pipelineId: string, sourceId: number, + sourceIngestName: string, alignment_ms: number ) { const db = await getDatabase(); @@ -142,7 +146,9 @@ export async function setProductionPipelineSourceAlignment( { _id: new ObjectId(productionId), 'production_settings.pipelines.pipeline_id': pipelineId, - 'production_settings.pipelines.sources.source_id': sourceId + 'production_settings.pipelines.sources.source_id': sourceId, + 'production_settings.pipelines.sources.settings.ingest_name': + sourceIngestName }, { $set: { @@ -153,7 +159,10 @@ export async function setProductionPipelineSourceAlignment( { arrayFilters: [ { 'p.pipeline_id': pipelineId }, - { 's.source_id': sourceId } + { + 's.source_id': sourceId, + 's.settings.ingest_name': sourceIngestName + } ] } ); @@ -173,7 +182,8 @@ export async function setProductionPipelineSourceAlignment( export async function getProductionSourceLatency( productionId: string, pipelineId: string, - sourceId: number + sourceId: number, + sourceIngestName: string ) { const production = await getProduction(productionId); @@ -187,7 +197,9 @@ export async function getProductionSourceLatency( ); const source = pipeline?.sources?.find( - (source) => String(source.source_id) === String(sourceId) + (source) => + String(source.source_id) === String(sourceId) && + source.settings.ingest_name === sourceIngestName ); const latency = @@ -197,11 +209,11 @@ export async function getProductionSourceLatency( return latency; } - export async function setProductionPipelineSourceLatency( productionId: string, pipelineId: string, sourceId: number, + sourceIngestName: string, max_network_latency_ms: number ) { const db = await getDatabase(); @@ -211,7 +223,9 @@ export async function setProductionPipelineSourceLatency( { _id: new ObjectId(productionId), 'production_settings.pipelines.pipeline_id': pipelineId, - 'production_settings.pipelines.sources.source_id': sourceId + 'production_settings.pipelines.sources.source_id': sourceId, + 'production_settings.pipelines.sources.settings.ingest_name': + sourceIngestName }, { $set: { @@ -222,7 +236,10 @@ export async function setProductionPipelineSourceLatency( { arrayFilters: [ { 'p.pipeline_id': pipelineId }, - { 's.source_id': sourceId } + { + 's.source_id': sourceId, + 's.settings.ingest_name': sourceIngestName + } ] } ); diff --git a/src/api/manager/workflow.ts b/src/api/manager/workflow.ts index 9cc24355..bddecf3e 100644 --- a/src/api/manager/workflow.ts +++ b/src/api/manager/workflow.ts @@ -127,7 +127,9 @@ async function connectIngestSources( ); const pipelineSource = pipeline.sources?.find( - (source) => source.source_id === sourceId + (s) => + s.source_id === sourceId && + s.settings.ingest_name === source.ingest_name ); const stream: PipelineStreamSettings = { @@ -874,12 +876,15 @@ export async function startProduction( ); const currentSettings = pipeline.sources?.find( - (s) => s.source_id === sourceId + (s) => + s.source_id === sourceId && + s.settings.ingest_name === source.ingest_name )?.settings; return { source_id: sourceId || 0, settings: { + ingest_name: source.ingest_name, alignment_ms: currentSettings?.alignment_ms ?? pipeline.alignment_ms, max_network_latency_ms: diff --git a/src/app/api/manager/productions/[id]/[pipeline_id]/[ingest_name]/[ingest_source_name]/route.ts b/src/app/api/manager/productions/[id]/[pipeline_id]/[ingest_name]/[ingest_source_name]/route.ts index becb68d5..fda8a291 100644 --- a/src/app/api/manager/productions/[id]/[pipeline_id]/[ingest_name]/[ingest_source_name]/route.ts +++ b/src/app/api/manager/productions/[id]/[pipeline_id]/[ingest_name]/[ingest_source_name]/route.ts @@ -40,7 +40,8 @@ export async function GET( ? await getProductionPipelineSourceAlignment( params.id, params.pipeline_id, - sourceId + sourceId, + params.ingest_name ) : 0; @@ -49,7 +50,8 @@ export async function GET( ? await getProductionSourceLatency( params.id, params.pipeline_id, - sourceId + sourceId, + params.ingest_name ) : 0; @@ -93,12 +95,14 @@ export async function PUT( params.id, params.pipeline_id, sourceId, + params.ingest_name, alignment ); const latencyResult = await setProductionPipelineSourceLatency( params.id, params.pipeline_id, sourceId, + params.ingest_name, latency ); diff --git a/src/app/production/[id]/page.tsx b/src/app/production/[id]/page.tsx index a8acbe3d..ada43e70 100644 --- a/src/app/production/[id]/page.tsx +++ b/src/app/production/[id]/page.tsx @@ -388,10 +388,13 @@ export default function ProductionConfiguration({ params }: PageProps) { pipelines: productionSetup.production_settings.pipelines.map( (pipeline) => { if (pipeline.pipeline_id === pipeline_uuid) { - pipeline.sources?.map((source) => { - if (source.source_id === sourceId) { - source.settings.alignment_ms = alignment; - source.settings.max_network_latency_ms = latency; + pipeline.sources?.map((s) => { + if ( + s.source_id === sourceId && + s.settings.ingest_name === source.ingest_name + ) { + s.settings.alignment_ms = alignment; + s.settings.max_network_latency_ms = latency; } }); } @@ -598,14 +601,17 @@ export default function ProductionConfiguration({ params }: PageProps) { source.ingest_source_name ), settings: { + ingest_name: source.ingest_name, alignment_ms: pipeline.alignment_ms, max_network_latency_ms: pipeline.max_network_latency_ms } }; - const exists = pipeline.sources?.some( - (s) => s.source_id === newSource.source_id - ); + const exists = + pipeline.sources?.some((s) => s.source_id === newSource.source_id) && + pipeline.sources?.some( + (s) => s.settings.ingest_name === newSource.settings.ingest_name + ); const updatedSources = exists ? pipeline.sources @@ -730,6 +736,7 @@ export default function ProductionConfiguration({ params }: PageProps) { selectedSource.ingest_source_name ), settings: { + ingest_name: selectedSource.ingest_name, alignment_ms: pipeline.alignment_ms, max_network_latency_ms: pipeline.max_network_latency_ms } diff --git a/src/interfaces/pipeline.ts b/src/interfaces/pipeline.ts index bf0c7241..25f85bb4 100644 --- a/src/interfaces/pipeline.ts +++ b/src/interfaces/pipeline.ts @@ -12,6 +12,7 @@ export interface SrtOutput { export interface PipelineSource { source_id: number; settings: { + ingest_name: string; alignment_ms?: number; max_network_latency_ms?: number; };