@@ -391,7 +391,8 @@ static void upipe_audio_merge_produce_output(struct upipe *upipe, struct upump *
391391 return ;
392392
393393 /* iterate through input subpipes, checking if they all have a uref available
394- and counting the number of channels */
394+ and counting the number of samples */
395+ uint64_t output_num_samples = 0 ;
395396 ulist_foreach (& upipe_audio_merge -> inputs , uchain ) {
396397 struct upipe_audio_merge_sub * upipe_audio_merge_sub =
397398 upipe_audio_merge_sub_from_uchain (uchain );
@@ -400,16 +401,10 @@ static void upipe_audio_merge_produce_output(struct upipe *upipe, struct upump *
400401 we're not ready to output */
401402 if (upipe_audio_merge_sub -> uref == NULL || upipe_audio_merge_sub -> flow_def == NULL )
402403 return ;
403- }
404404
405- /* TODO: merge this loop with the above? */
406- uint64_t output_num_samples = 0 ;
407- ulist_foreach (& upipe_audio_merge -> inputs , uchain ) {
408- struct upipe_audio_merge_sub * upipe_audio_merge_sub =
409- upipe_audio_merge_sub_from_uchain (uchain );
410- /* if we haven't got one already, copy the uref to form the basis of our output uref */
405+ /* if we haven't got one already, get a uref to form the basis of our output uref */
411406 if (output_uref == NULL )
412- output_uref = uref_dup ( upipe_audio_merge_sub -> uref ) ;
407+ output_uref = upipe_audio_merge_sub -> uref ;
413408
414409 size_t samples = 0 ;
415410 if (ubase_check (uref_sound_size (upipe_audio_merge_sub -> uref , & samples , NULL ))
@@ -418,9 +413,12 @@ static void upipe_audio_merge_produce_output(struct upipe *upipe, struct upump *
418413 }
419414 upipe_audio_merge -> output_num_samples = output_num_samples ;
420415
421- if (unlikely (!output_uref ))
416+ /* Duplicate uref for output. */
417+ output_uref = uref_dup (output_uref );
418+ if (unlikely (!output_uref )) {
419+ upipe_throw_error (upipe , UBASE_ERR_ALLOC );
422420 return ;
423-
421+ }
424422
425423 uint8_t output_sample_size = 0 ;
426424 UBASE_ERROR (upipe , uref_sound_flow_get_sample_size (upipe_audio_merge -> flow_def , & output_sample_size ));
0 commit comments