Verified Commit ea595122 authored by John Lin's avatar John Lin Committed by ma1
Browse files

Bug 2021955 - drop extra channels when out of downmixer's capability. a=RyanVM

parent 65f632f6
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include <cmath>

#include "mozilla/CheckedInt.h"
#include "nsFmtString.h"

/*
 *  Parts derived from MythTV AudioConvert Class
@@ -189,7 +190,12 @@ size_t AudioConverter::DownmixAudio(void* aOut, const void* aIn,
    return aFrames;
  }

  if (!mIn.Layout().IsValid() || !mOut.Layout().IsValid()) {
  // The downmix matrix below only handles 3 to 8 input channels. For more
  // than 8 channels (or invalid layouts) fall back to dropping extra channels.
  if (!mIn.Layout().IsValid() || !mOut.Layout().IsValid() || inChannels > 8) {
    NS_WARNING(nsFmtCString("Dumb remixing: {} channels in, {} channels out",
                            inChannels, outChannels)
                   .get());
    // Dumb copy dropping extra channels.
    if (mIn.Format() == AudioConfig::FORMAT_FLT) {
      dumbUpDownMix(static_cast<float*>(aOut), outChannels,
@@ -245,6 +251,7 @@ size_t AudioConverter::DownmixAudio(void* aOut, const void* aIn,
           {0.3366f, 0.1943f},
           {0.1943f, 0.3366f}},
      };
      MOZ_DIAGNOSTIC_ASSERT(inChannels < std::size(dmatrix) + 3);
      // Re-write the buffer with downmixed data
      const float* in = static_cast<const float*>(aIn);
      float* out = static_cast<float*>(aOut);
@@ -294,6 +301,7 @@ size_t AudioConverter::DownmixAudio(void* aOut, const void* aIn,
           {3184, 5514},
           {5514, 3184},
           {3184, 5514}}};
      MOZ_DIAGNOSTIC_ASSERT(inChannels < std::size(dmatrix) + 3);
      // Re-write the buffer with downmixed data
      const int16_t* in = static_cast<const int16_t*>(aIn);
      int16_t* out = static_cast<int16_t*>(aOut);