Browse code

lavr: make sure that the mix function is reset even if no mixing will be done

If the matrix reduction ends up with no mixing matrix needed, we need to still
reset the mix function accordingly and log the info to the user.

Justin Ruggles authored on 2013/01/19 03:27:50
Showing 1 changed files
... ...
@@ -527,28 +527,13 @@ int ff_audio_mix_get_matrix(AudioMix *am, double *matrix, int stride)
527 527
     return 0;
528 528
 }
529 529
 
530
-int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
530
+static void reduce_matrix(AudioMix *am, const double *matrix, int stride)
531 531
 {
532
-    int i, o, i0, o0, ret;
533
-    char in_layout_name[128];
534
-    char out_layout_name[128];
535
-
536
-    if ( am->in_channels <= 0 ||  am->in_channels > AVRESAMPLE_MAX_CHANNELS ||
537
-        am->out_channels <= 0 || am->out_channels > AVRESAMPLE_MAX_CHANNELS) {
538
-        av_log(am->avr, AV_LOG_ERROR, "Invalid channel counts\n");
539
-        return AVERROR(EINVAL);
540
-    }
541
-
542
-    if (am->matrix) {
543
-        av_free(am->matrix[0]);
544
-        am->matrix = NULL;
545
-    }
532
+    int i, o;
546 533
 
547 534
     memset(am->output_zero, 0, sizeof(am->output_zero));
548 535
     memset(am->input_skip,  0, sizeof(am->input_skip));
549
-    memset(am->output_skip, 0, sizeof(am->output_zero));
550
-    am->in_matrix_channels  = am->in_channels;
551
-    am->out_matrix_channels = am->out_channels;
536
+    memset(am->output_skip, 0, sizeof(am->output_skip));
552 537
 
553 538
     /* exclude output channels if they can be zeroed instead of mixed */
554 539
     for (o = 0; o < am->out_channels; o++) {
... ...
@@ -578,7 +563,7 @@ int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
578 578
     }
579 579
     if (am->out_matrix_channels == 0) {
580 580
         am->in_matrix_channels = 0;
581
-        return 0;
581
+        return;
582 582
     }
583 583
 
584 584
     /* skip input channels that contribute fully only to the corresponding
... ...
@@ -615,7 +600,7 @@ int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
615 615
     }
616 616
     if (am->in_matrix_channels == 0) {
617 617
         am->out_matrix_channels = 0;
618
-        return 0;
618
+        return;
619 619
     }
620 620
 
621 621
     /* skip output channels that only get full contribution from the
... ...
@@ -637,8 +622,31 @@ int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
637 637
     }
638 638
     if (am->out_matrix_channels == 0) {
639 639
         am->in_matrix_channels = 0;
640
-        return 0;
640
+        return;
641 641
     }
642
+}
643
+
644
+int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
645
+{
646
+    int i, o, i0, o0, ret;
647
+    char in_layout_name[128];
648
+    char out_layout_name[128];
649
+
650
+    if ( am->in_channels <= 0 ||  am->in_channels > AVRESAMPLE_MAX_CHANNELS ||
651
+        am->out_channels <= 0 || am->out_channels > AVRESAMPLE_MAX_CHANNELS) {
652
+        av_log(am->avr, AV_LOG_ERROR, "Invalid channel counts\n");
653
+        return AVERROR(EINVAL);
654
+    }
655
+
656
+    if (am->matrix) {
657
+        av_free(am->matrix[0]);
658
+        am->matrix = NULL;
659
+    }
660
+
661
+    am->in_matrix_channels  = am->in_channels;
662
+    am->out_matrix_channels = am->out_channels;
663
+
664
+    reduce_matrix(am, matrix, stride);
642 665
 
643 666
 #define CONVERT_MATRIX(type, expr)                                          \
644 667
     am->matrix_## type[0] = av_mallocz(am->out_matrix_channels *            \
... ...
@@ -664,6 +672,7 @@ int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
664 664
     }                                                                       \
665 665
     am->matrix = (void **)am->matrix_## type;
666 666
 
667
+    if (am->in_matrix_channels && am->out_matrix_channels) {
667 668
     switch (am->coeff_type) {
668 669
     case AV_MIX_COEFF_TYPE_Q8:
669 670
         CONVERT_MATRIX(q8, av_clip_int16(lrint(256.0 * v)))
... ...
@@ -678,6 +687,7 @@ int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
678 678
         av_log(am->avr, AV_LOG_ERROR, "Invalid mix coeff type\n");
679 679
         return AVERROR(EINVAL);
680 680
     }
681
+    }
681 682
 
682 683
     ret = mix_function_init(am);
683 684
     if (ret < 0)