Skip to content

Commit c5c26ec

Browse files
committed
upipe_audio_merge: merge loops over subpipes
1 parent aa49eaf commit c5c26ec

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

lib/upipe-modules/upipe_audio_merge.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ static void upipe_audio_merge_produce_output(struct upipe *upipe, struct upump *
394394
return;
395395

396396
/* interate through input subpipes, checking if they all have a uref available
397-
and counting the number of channels */
397+
and counting the number of samples */
398+
uint64_t output_num_samples = 0;
398399
ulist_foreach (&upipe_audio_merge->inputs, uchain) {
399400
struct upipe_audio_merge_sub *upipe_audio_merge_sub =
400401
upipe_audio_merge_sub_from_uchain(uchain);
@@ -403,16 +404,10 @@ static void upipe_audio_merge_produce_output(struct upipe *upipe, struct upump *
403404
we're not ready to output */
404405
if (upipe_audio_merge_sub->uref == NULL || upipe_audio_merge_sub->flow_def == NULL)
405406
return;
406-
}
407407

408-
/* TODO: merge this loop with the above? */
409-
uint64_t output_num_samples = 0;
410-
ulist_foreach (&upipe_audio_merge->inputs, uchain) {
411-
struct upipe_audio_merge_sub *upipe_audio_merge_sub =
412-
upipe_audio_merge_sub_from_uchain(uchain);
413-
/* if we haven't got one already, copy the uref to form the basis of our output uref */
408+
/* if we haven't got one already, get a uref to form the basis of our output uref */
414409
if (output_uref == NULL)
415-
output_uref = uref_dup(upipe_audio_merge_sub->uref);
410+
output_uref = upipe_audio_merge_sub->uref;
416411

417412
size_t samples = 0;
418413
if (ubase_check(uref_sound_size(upipe_audio_merge_sub->uref, &samples, NULL))
@@ -421,9 +416,12 @@ static void upipe_audio_merge_produce_output(struct upipe *upipe, struct upump *
421416
}
422417
upipe_audio_merge->output_num_samples = output_num_samples;
423418

424-
if (unlikely(!output_uref))
419+
/* Duplicate uref for output. */
420+
output_uref = uref_dup(output_uref);
421+
if (unlikely(!output_uref)) {
422+
upipe_throw_error(upipe, UBASE_ERR_ALLOC);
425423
return;
426-
424+
}
427425

428426
uint8_t output_sample_size = 0;
429427
UBASE_ERROR(upipe, uref_sound_flow_get_sample_size(upipe_audio_merge->flow_def, &output_sample_size));

0 commit comments

Comments
 (0)