Backed out 11 changesets (bug 1248861) for gtest test failures
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Fri, 08 Apr 2016 11:14:31 +0200
changeset 330286 615f67ac2823f0428e54a64c42037c645076c39e
parent 330285 a60d4b9232b19fb0d9726bdc2376fe4924dee9fc
child 330287 3819bbd16d8b57685741e0104cdf5cb67b30c249
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1248861
milestone48.0a1
backs outbe02aaa8b2e8099047ac3c9dcb8ee06810cda5ee
48718147d79ea89fa3e047ad57cbb31318e7b2f6
904a19b9cdd00287eb0cc739013335c26929de2e
b326f17035c14bf743b80455d5cef193c82fe748
ddff88a6db07072fc69e256b7b22535647e2b9a5
0565edbead7fa107491b3ea72dca001a369a548e
d71b93bc6cc7d8acfa97a16a2f0e390a9af0db75
6e917e5d29c06b11ece21ce6e18c9d82da2829a7
c17c2fde0e8922acf9ab024f818eb70ae68fcc48
56f769e95df2fb54bab466bcf168969ad486fa9c
cb8a49f92cba589b168aeea3d7dbc076bf3509c6
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out 11 changesets (bug 1248861) for gtest test failures Backed out changeset be02aaa8b2e8 (bug 1248861) Backed out changeset 48718147d79e (bug 1248861) Backed out changeset 904a19b9cdd0 (bug 1248861) Backed out changeset b326f17035c1 (bug 1248861) Backed out changeset ddff88a6db07 (bug 1248861) Backed out changeset 0565edbead7f (bug 1248861) Backed out changeset d71b93bc6cc7 (bug 1248861) Backed out changeset 6e917e5d29c0 (bug 1248861) Backed out changeset c17c2fde0e89 (bug 1248861) Backed out changeset 56f769e95df2 (bug 1248861) Backed out changeset cb8a49f92cba (bug 1248861)
dom/media/AudioCompactor.h
dom/media/AudioConverter.cpp
dom/media/AudioConverter.h
dom/media/MediaData.cpp
dom/media/MediaData.h
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaInfo.cpp
dom/media/MediaInfo.h
dom/media/VideoUtils.cpp
dom/media/moz.build
dom/media/ogg/OggReader.cpp
dom/media/platforms/agnostic/BlankDecoderModule.cpp
dom/media/platforms/agnostic/OpusDecoder.cpp
dom/media/platforms/agnostic/OpusDecoder.h
dom/media/platforms/agnostic/VorbisDecoder.cpp
dom/media/platforms/agnostic/VorbisDecoder.h
dom/media/platforms/agnostic/WAVDecoder.cpp
dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
dom/media/platforms/android/AndroidDecoderModule.cpp
dom/media/platforms/apple/AppleATDecoder.cpp
dom/media/platforms/apple/AppleATDecoder.h
dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
dom/media/platforms/wmf/WMFAudioMFTManager.cpp
dom/media/wave/WaveReader.cpp
--- a/dom/media/AudioCompactor.h
+++ b/dom/media/AudioCompactor.h
@@ -36,20 +36,17 @@ public:
             uint32_t aFrames, uint32_t aChannels, CopyFunc aCopyFunc)
   {
     // If we are losing more than a reasonable amount to padding, try to chunk
     // the data.
     size_t maxSlop = AudioDataSize(aFrames, aChannels) / MAX_SLOP_DIVISOR;
 
     while (aFrames > 0) {
       uint32_t samples = GetChunkSamples(aFrames, aChannels, maxSlop);
-      AlignedAudioBuffer buffer(samples);
-      if (!buffer) {
-        return false;
-      }
+      auto buffer = MakeUnique<AudioDataValue[]>(samples);
 
       // Copy audio data to buffer using caller-provided functor.
       uint32_t framesCopied = aCopyFunc(buffer.get(), samples);
 
       NS_ASSERTION(framesCopied <= aFrames, "functor copied too many frames");
 
       CheckedInt64 duration = FramesToUsecs(framesCopied, aSampleRate);
       if (!duration.isValid()) {
deleted file mode 100644
--- a/dom/media/AudioConverter.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "AudioConverter.h"
-#include <string.h>
-
-/*
- *  Parts derived from MythTV AudioConvert Class
- *  Created by Jean-Yves Avenard.
- *
- *  Copyright (C) Bubblestuff Pty Ltd 2013
- *  Copyright (C) foobum@gmail.com 2010
- */
-
-namespace mozilla {
-
-AudioConverter::AudioConverter(const AudioConfig& aIn, const AudioConfig& aOut)
-  : mIn(aIn)
-  , mOut(aOut)
-{
-  MOZ_DIAGNOSTIC_ASSERT(aIn.Channels() == aOut.Channels() &&
-                        aIn.Rate() == aOut.Rate() &&
-                        aIn.Format() == aOut.Format() &&
-                        aIn.Interleaved() == aOut.Interleaved(),
-                        "Only channel reordering is supported at this stage");
-  MOZ_DIAGNOSTIC_ASSERT(aOut.Interleaved(), "planar audio format not supported");
-  mIn.Layout().MappingTable(mOut.Layout(), mChannelOrderMap);
-}
-
-bool
-AudioConverter::CanWorkInPlace() const
-{
-  return mIn.Channels() * mIn.Rate() * AudioConfig::SampleSize(mIn.Format()) >=
-    mOut.Channels() * mOut.Rate() * AudioConfig::SampleSize(mOut.Format());
-}
-
-size_t
-AudioConverter::Process(void* aOut, const void* aIn, size_t aBytes)
-{
-  if (!CanWorkInPlace()) {
-    return 0;
-  }
-  if (mIn.Layout() != mOut.Layout() &&
-      CanReorderAudio()) {
-    ReOrderInterleavedChannels(aOut, aIn, aBytes);
-  }
-  return aBytes;
-}
-
-// Reorder interleaved channels.
-// Can work in place (e.g aOut == aIn).
-template <class AudioDataType>
-void
-_ReOrderInterleavedChannels(AudioDataType* aOut, const AudioDataType* aIn,
-                            uint32_t aFrames, uint32_t aChannels,
-                            const uint8_t* aChannelOrderMap)
-{
-  MOZ_DIAGNOSTIC_ASSERT(aChannels <= MAX_AUDIO_CHANNELS);
-  AudioDataType val[MAX_AUDIO_CHANNELS];
-  for (uint32_t i = 0; i < aFrames; i++) {
-    for (uint32_t j = 0; j < aChannels; j++) {
-      val[j] = aIn[aChannelOrderMap[j]];
-    }
-    for (uint32_t j = 0; j < aChannels; j++) {
-      aOut[j] = val[j];
-    }
-    aOut += aChannels;
-    aIn += aChannels;
-  }
-}
-
-void
-AudioConverter::ReOrderInterleavedChannels(void* aOut, const void* aIn,
-                                           size_t aDataSize) const
-{
-  MOZ_DIAGNOSTIC_ASSERT(mIn.Channels() == mOut.Channels());
-
-  if (mOut.Layout() == mIn.Layout()) {
-    return;
-  }
-  if (mOut.Channels() == 1) {
-    // If channel count is 1, planar and non-planar formats are the same and
-    // there's nothing to reorder.
-    if (aOut != aIn) {
-      memmove(aOut, aIn, aDataSize);
-    }
-    return;
-  }
-
-  uint32_t bits = AudioConfig::FormatToBits(mOut.Format());
-  switch (bits) {
-    case 8:
-      _ReOrderInterleavedChannels((uint8_t*)aOut, (const uint8_t*)aIn,
-                                  aDataSize/sizeof(uint8_t)/mIn.Channels(),
-                                  mIn.Channels(), mChannelOrderMap);
-      break;
-    case 16:
-      _ReOrderInterleavedChannels((int16_t*)aOut,(const int16_t*)aIn,
-                                  aDataSize/sizeof(int16_t)/mIn.Channels(),
-                                  mIn.Channels(), mChannelOrderMap);
-      break;
-    default:
-      MOZ_DIAGNOSTIC_ASSERT(AudioConfig::SampleSize(mOut.Format()) == 4);
-      _ReOrderInterleavedChannels((int32_t*)aOut,(const int32_t*)aIn,
-                                  aDataSize/sizeof(int32_t)/mIn.Channels(),
-                                  mIn.Channels(), mChannelOrderMap);
-      break;
-  }
-}
-
-} // namespace mozilla
\ No newline at end of file
deleted file mode 100644
--- a/dom/media/AudioConverter.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#if !defined(AudioConverter_h)
-#define AudioConverter_h
-
-#include "MediaInfo.h"
-
-namespace mozilla {
-
-template <AudioConfig::SampleFormat T> struct AudioDataBufferTypeChooser;
-template <> struct AudioDataBufferTypeChooser<AudioConfig::FORMAT_U8>
-{ typedef uint8_t Type; };
-template <> struct AudioDataBufferTypeChooser<AudioConfig::FORMAT_S16>
-{ typedef int16_t Type; };
-template <> struct AudioDataBufferTypeChooser<AudioConfig::FORMAT_S24LSB>
-{ typedef int32_t Type; };
-template <> struct AudioDataBufferTypeChooser<AudioConfig::FORMAT_S24>
-{ typedef int32_t Type; };
-template <> struct AudioDataBufferTypeChooser<AudioConfig::FORMAT_S32>
-{ typedef int32_t Type; };
-template <> struct AudioDataBufferTypeChooser<AudioConfig::FORMAT_FLT>
-{ typedef float Type; };
-
-// 'Value' is the type used externally to deal with stored value.
-// AudioDataBuffer can perform conversion between different SampleFormat content.
-template <AudioConfig::SampleFormat Format, typename Value = typename AudioDataBufferTypeChooser<Format>::Type>
-class AudioDataBuffer
-{
-public:
-  AudioDataBuffer() {}
-  AudioDataBuffer(Value* aBuffer, size_t aLength)
-    : mBuffer(aBuffer, aLength)
-  {}
-  explicit AudioDataBuffer(const AudioDataBuffer& aOther)
-    : mBuffer(aOther.mBuffer)
-  {}
-  AudioDataBuffer(AudioDataBuffer&& aOther)
-    : mBuffer(Move(aOther.mBuffer))
-  {}
-  template <AudioConfig::SampleFormat OtherFormat, typename OtherValue>
-  explicit AudioDataBuffer(const AudioDataBuffer<OtherFormat, OtherValue>& other)
-  {
-    // TODO: Convert from different type, may use asm routines.
-    MOZ_CRASH("Conversion not implemented yet");
-  }
-
-  // A u8, s16 and float aligned buffer can only be treated as
-  // FORMAT_U8, FORMAT_S16 and FORMAT_FLT respectively.
-  // So allow them as copy and move constructors.
-  explicit AudioDataBuffer(const AlignedByteBuffer& aBuffer)
-    : mBuffer(aBuffer)
-  {
-    static_assert(Format == AudioConfig::FORMAT_U8,
-                  "Conversion not implemented yet");
-  }
-  explicit AudioDataBuffer(const AlignedShortBuffer& aBuffer)
-    : mBuffer(aBuffer)
-  {
-    static_assert(Format == AudioConfig::FORMAT_S16,
-                  "Conversion not implemented yet");
-  }
-  explicit AudioDataBuffer(const AlignedFloatBuffer& aBuffer)
-    : mBuffer(aBuffer)
-  {
-    static_assert(Format == AudioConfig::FORMAT_FLT,
-                  "Conversion not implemented yet");
-  }
-  explicit AudioDataBuffer(AlignedByteBuffer&& aBuffer)
-    : mBuffer(Move(aBuffer))
-  {
-    static_assert(Format == AudioConfig::FORMAT_U8,
-                  "Conversion not implemented yet");
-  }
-  explicit AudioDataBuffer(AlignedShortBuffer&& aBuffer)
-    : mBuffer(Move(aBuffer))
-  {
-    static_assert(Format == AudioConfig::FORMAT_S16,
-                  "Conversion not implemented yet");
-  }
-  explicit AudioDataBuffer(const AlignedFloatBuffer&& aBuffer)
-    : mBuffer(Move(aBuffer))
-  {
-    static_assert(Format == AudioConfig::FORMAT_FLT,
-                  "Conversion not implemented yet");
-  }
-
-  Value* Data() const { return mBuffer.Data(); }
-  size_t Length() const { return mBuffer.Length(); }
-  size_t Size() const { return mBuffer.Size(); }
-  AlignedBuffer<Value> Forget()
-  {
-    // Correct type -> Just give values as-is.
-    return Move(mBuffer);
-  }
-private:
-  AlignedBuffer<Value> mBuffer;
-};
-
-typedef AudioDataBuffer<AudioConfig::FORMAT_DEFAULT> AudioSampleBuffer;
-
-class AudioConverter {
-public:
-  AudioConverter(const AudioConfig& aIn, const AudioConfig& aOut);
-
-  // Attempt to convert the AudioDataBuffer in place.
-  // Will return 0 if the conversion wasn't possible.
-  // Process may allocate memory internally should intermediary steps be
-  // required.
-  template <AudioConfig::SampleFormat Type, typename Value>
-  size_t Process(AudioDataBuffer<Type, Value>& aBuffer)
-  {
-    MOZ_DIAGNOSTIC_ASSERT(mIn.Format() == mOut.Format() && mIn.Format() == Type);
-    return Process(aBuffer.Data(), aBuffer.Data(), aBuffer.Size());
-  }
-  bool CanWorkInPlace() const;
-  bool CanReorderAudio() const
-  {
-    return mIn.Layout().MappingTable(mOut.Layout());
-  }
-
-private:
-  const AudioConfig mIn;
-  const AudioConfig mOut;
-  uint8_t mChannelOrderMap[MAX_AUDIO_CHANNELS];
-  /**
-   * Process
-   * Parameters:
-   * aOut  : destination buffer where converted samples will be copied
-   * aIn   : source buffer
-   * aBytes: size in bytes of source buffer
-   *
-   * Return Value: size in bytes of samples converted or 0 if error
-   */
-  size_t Process(void* aOut, const void* aIn, size_t aBytes);
-  void ReOrderInterleavedChannels(void* aOut, const void* aIn, size_t aDataSize) const;
-};
-
-} // namespace mozilla
-
-#endif /* AudioConverter_h */
--- a/dom/media/MediaData.cpp
+++ b/dom/media/MediaData.cpp
@@ -7,16 +7,17 @@
 #include "MediaData.h"
 #include "MediaInfo.h"
 #ifdef MOZ_OMX_DECODER
 #include "GrallocImages.h"
 #include "mozilla/layers/TextureClient.h"
 #endif
 #include "VideoUtils.h"
 #include "ImageContainer.h"
+#include "mozilla/UniquePtrExtensions.h"
 
 #ifdef MOZ_WIDGET_GONK
 #include <cutils/properties.h>
 #endif
 #include <stdint.h>
 
 namespace mozilla {
 
@@ -41,18 +42,17 @@ AudioData::EnsureAudioBuffer()
       data[j*mFrames + i] = mAudioData[i*mChannels + j];
     }
   }
 }
 
 size_t
 AudioData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
-  size_t size =
-    aMallocSizeOf(this) + mAudioData.SizeOfExcludingThis(aMallocSizeOf);
+  size_t size = aMallocSizeOf(this) + aMallocSizeOf(mAudioData.get());
   if (mAudioBuffer) {
     size += mAudioBuffer->SizeOfIncludingThis(aMallocSizeOf);
   }
   return size;
 }
 
 bool
 AudioData::IsAudible() const
@@ -482,99 +482,186 @@ VideoData::Create(const VideoInfo& aInfo
   RefPtr<layers::GrallocImage> image = new layers::GrallocImage();
   image->SetData(aBuffer, aPicture.Size());
   v->mImage = image;
 
   return v.forget();
 }
 #endif  // MOZ_OMX_DECODER
 
+// Alignment value - 1. 0 means that data isn't aligned.
+// For 32-bytes aligned, use 31U.
+#define RAW_DATA_ALIGNMENT 31U
+
 MediaRawData::MediaRawData()
   : MediaData(RAW_DATA, 0)
   , mCrypto(mCryptoInternal)
+  , mData(nullptr)
+  , mSize(0)
+  , mBuffer(nullptr)
+  , mCapacity(0)
 {
 }
 
 MediaRawData::MediaRawData(const uint8_t* aData, size_t aSize)
   : MediaData(RAW_DATA, 0)
   , mCrypto(mCryptoInternal)
-  , mBuffer(aData, aSize)
+  , mData(nullptr)
+  , mSize(0)
+  , mBuffer(nullptr)
+  , mCapacity(0)
 {
+  if (!EnsureCapacity(aSize)) {
+    return;
+  }
+
+  // We ensure sufficient capacity above so this shouldn't fail.
+  memcpy(mData, aData, aSize);
+  mSize = aSize;
 }
 
 already_AddRefed<MediaRawData>
 MediaRawData::Clone() const
 {
   RefPtr<MediaRawData> s = new MediaRawData;
   s->mTimecode = mTimecode;
   s->mTime = mTime;
   s->mDuration = mDuration;
   s->mOffset = mOffset;
   s->mKeyframe = mKeyframe;
   s->mExtraData = mExtraData;
   s->mCryptoInternal = mCryptoInternal;
   s->mTrackInfo = mTrackInfo;
-  if (!s->mBuffer.Append(mBuffer.Data(), mBuffer.Length())) {
-    return nullptr;
+  if (mSize) {
+    if (!s->EnsureCapacity(mSize)) {
+      return nullptr;
+    }
+
+    memcpy(s->mData, mData, mSize);
+    s->mSize = mSize;
   }
   return s.forget();
 }
 
+// EnsureCapacity ensures that the buffer is big enough to hold
+// aSize. It doesn't set the mSize. It's up to the caller to adjust it.
+bool
+MediaRawData::EnsureCapacity(size_t aSize)
+{
+  const size_t sizeNeeded = aSize + RAW_DATA_ALIGNMENT * 2;
+
+  if (mData && mCapacity >= sizeNeeded) {
+    return true;
+  }
+  auto newBuffer = MakeUniqueFallible<uint8_t[]>(sizeNeeded);
+  if (!newBuffer) {
+    return false;
+  }
+
+  // Find alignment address.
+  const uintptr_t alignmask = RAW_DATA_ALIGNMENT;
+  uint8_t* newData = reinterpret_cast<uint8_t*>(
+    (reinterpret_cast<uintptr_t>(newBuffer.get()) + alignmask) & ~alignmask);
+  MOZ_ASSERT(uintptr_t(newData) % (RAW_DATA_ALIGNMENT+1) == 0);
+  memcpy(newData, mData, mSize);
+
+  mBuffer = Move(newBuffer);
+  mCapacity = sizeNeeded;
+  mData = newData;
+
+  return true;
+}
+
 MediaRawData::~MediaRawData()
 {
 }
 
 size_t
 MediaRawData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t size = aMallocSizeOf(this);
-  size += mBuffer.SizeOfExcludingThis(aMallocSizeOf);
+  size += aMallocSizeOf(mBuffer.get());
   return size;
 }
 
 MediaRawDataWriter*
 MediaRawData::CreateWriter()
 {
   return new MediaRawDataWriter(this);
 }
 
 MediaRawDataWriter::MediaRawDataWriter(MediaRawData* aMediaRawData)
   : mCrypto(aMediaRawData->mCryptoInternal)
   , mTarget(aMediaRawData)
 {
 }
 
 bool
+MediaRawDataWriter::EnsureSize(size_t aSize)
+{
+  if (aSize <= mTarget->mSize) {
+    return true;
+  }
+  if (!mTarget->EnsureCapacity(aSize)) {
+    return false;
+  }
+  return true;
+}
+
+bool
 MediaRawDataWriter::SetSize(size_t aSize)
 {
-  return mTarget->mBuffer.SetLength(aSize);
+  if (aSize > mTarget->mSize && !EnsureSize(aSize)) {
+    return false;
+  }
+
+  mTarget->mSize = aSize;
+  return true;
 }
 
 bool
 MediaRawDataWriter::Prepend(const uint8_t* aData, size_t aSize)
 {
-  return mTarget->mBuffer.Prepend(aData, aSize);
+  if (!EnsureSize(aSize + mTarget->mSize)) {
+    return false;
+  }
+
+  // Shift the data to the right by aSize to leave room for the new data.
+  memmove(mTarget->mData + aSize, mTarget->mData, mTarget->mSize);
+  memcpy(mTarget->mData, aData, aSize);
+
+  mTarget->mSize += aSize;
+  return true;
 }
 
 bool
 MediaRawDataWriter::Replace(const uint8_t* aData, size_t aSize)
 {
-  return mTarget->mBuffer.Replace(aData, aSize);
+  // If aSize is smaller than our current size, we leave the buffer as is,
+  // only adjusting the reported size.
+  if (!EnsureSize(aSize)) {
+    return false;
+  }
+
+  memcpy(mTarget->mData, aData, aSize);
+  mTarget->mSize = aSize;
+  return true;
 }
 
 void
 MediaRawDataWriter::Clear()
 {
-  mTarget->mBuffer.Clear();
+  mTarget->mSize = 0;
+  mTarget->mData = nullptr;
 }
 
 uint8_t*
 MediaRawDataWriter::Data()
 {
-  return mTarget->mBuffer.Data();
+  return mTarget->mData;
 }
 
 size_t
 MediaRawDataWriter::Size()
 {
   return mTarget->Size();
 }
 
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -9,256 +9,28 @@
 #include "nsSize.h"
 #include "mozilla/gfx/Rect.h"
 #include "nsRect.h"
 #include "AudioSampleFormat.h"
 #include "nsIMemoryReporter.h"
 #include "SharedBuffer.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtr.h"
-#include "mozilla/UniquePtrExtensions.h"
 #include "nsTArray.h"
-#include "mozilla/CheckedInt.h"
-#include "mozilla/PodOperations.h"
 
 namespace mozilla {
 
 namespace layers {
 class Image;
 class ImageContainer;
 } // namespace layers
 
 class MediaByteBuffer;
 class SharedTrackInfo;
 
-// AlignedBuffer:
-// Memory allocations are fallibles. Methods return a boolean indicating if
-// memory allocations were successful. Return values should always be checked.
-// AlignedBuffer::mData will be nullptr if no memory has been allocated or if
-// an error occurred during construction.
-// Existing data is only ever modified if new memory allocation has succeeded
-// and preserved if not.
-//
-// The memory referenced by mData will always be Alignment bytes aligned and the
-// underlying buffer will always have a size such that Alignment bytes blocks
-// can be used to read the content, regardless of the mSize value. Buffer is
-// zeroed on creation, elements are not individually constructed.
-// An Alignment value of 0 means that the data isn't aligned.
-//
-// Type must be trivially copyable.
-//
-// AlignedBuffer can typically be used in place of UniquePtr<Type[]> however
-// care must be taken as all memory allocations are fallible.
-// Example:
-// auto buffer = MakeUniqueFallible<float[]>(samples)
-// becomes: AlignedFloatBuffer buffer(samples)
-//
-// auto buffer = MakeUnique<float[]>(samples)
-// becomes:
-// AlignedFloatBuffer buffer(samples);
-// if (!buffer) { return NS_ERROR_OUT_OF_MEMORY; }
-
-template <typename Type, int Alignment = 32>
-class AlignedBuffer
-{
-public:
-  AlignedBuffer()
-    : mData(nullptr)
-    , mLength(0)
-    , mBuffer(nullptr)
-    , mCapacity(0)
-  {}
-
-  explicit AlignedBuffer(size_t aLength)
-    : mData(nullptr)
-    , mLength(0)
-    , mBuffer(nullptr)
-    , mCapacity(0)
-  {
-    if (EnsureCapacity(aLength)) {
-      mLength = aLength;
-    }
-  }
-
-  AlignedBuffer(const Type* aData, size_t aLength)
-    : AlignedBuffer(aLength)
-  {
-    if (!mData) {
-      return;
-    }
-    PodCopy(mData, aData, aLength);
-  }
-
-  AlignedBuffer(const AlignedBuffer& aOther)
-    : AlignedBuffer(aOther.Data(), aOther.Length())
-  {}
-
-  AlignedBuffer(AlignedBuffer&& aOther)
-    : mData(aOther.mData)
-    , mLength(aOther.mLength)
-    , mBuffer(Move(aOther.mBuffer))
-    , mCapacity(aOther.mCapacity)
-  {
-    aOther.mData = nullptr;
-    aOther.mLength = 0;
-    aOther.mCapacity = 0;
-  }
-
-  AlignedBuffer& operator=(AlignedBuffer&& aOther)
-  {
-    this->~AlignedBuffer();
-    new (this) AlignedBuffer(Move(aOther));
-    return *this;
-  }
-
-  Type* Data() const { return mData; }
-  size_t Length() const { return mLength; }
-  size_t Size() const { return mLength * sizeof(Type); }
-  Type& operator[](size_t aIndex)
-  {
-    MOZ_ASSERT(aIndex < mLength);
-    return mData[aIndex];
-  }
-  const Type& operator[](size_t aIndex) const
-  {
-    MOZ_ASSERT(aIndex < mLength);
-    return mData[aIndex];
-  }
-  // Set length of buffer, allocating memory as required.
-  // If length is increased, new buffer area is filled with 0.
-  bool SetLength(size_t aLength)
-  {
-    if (aLength > mLength && !EnsureCapacity(aLength)) {
-      return false;
-    }
-    mLength = aLength;
-    return true;
-  }
-  // Add aData at the beginning of buffer.
-  bool Prepend(const Type* aData, size_t aLength)
-  {
-    if (!EnsureCapacity(aLength + mLength)) {
-      return false;
-    }
-
-    // Shift the data to the right by aLength to leave room for the new data.
-    PodMove(mData + aLength, mData, mLength);
-    PodCopy(mData, aData, aLength);
-
-    mLength += aLength;
-    return true;
-  }
-  // Add aData at the end of buffer.
-  bool Append(const Type* aData, size_t aLength)
-  {
-    if (!EnsureCapacity(aLength + mLength)) {
-      return false;
-    }
-
-    PodCopy(mData + mLength, aData, aLength);
-
-    mLength += aLength;
-    return true;
-  }
-  // Replace current content with aData.
-  bool Replace(const Type* aData, size_t aLength)
-  {
-    // If aLength is smaller than our current length, we leave the buffer as is,
-    // only adjusting the reported length.
-    if (!EnsureCapacity(aLength)) {
-      return false;
-    }
-
-    PodCopy(mData, aData, aLength);
-    mLength = aLength;
-    return true;
-  }
-  // Clear the memory buffer. Will set target mData and mLength to 0.
-  void Clear()
-  {
-    mLength = 0;
-    mData = nullptr;
-  }
-
-  // Methods for reporting memory.
-  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
-  {
-    size_t size = aMallocSizeOf(this);
-    size += aMallocSizeOf(mBuffer.get());
-    return size;
-  }
-  // AlignedBuffer is typically allocated on the stack. As such, you likely
-  // want to use SizeOfExcludingThis
-  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
-  {
-    return aMallocSizeOf(mBuffer.get());
-  }
-  size_t ComputedSizeOfExcludingThis() const
-  {
-    return mCapacity;
-  }
-
-  // For backward compatibility with UniquePtr<Type[]>
-  Type* get() const { return mData; }
-  explicit operator bool() const { return mData != nullptr; }
-
-private:
-  size_t AlignmentOffset() const
-  {
-    return Alignment ? Alignment - 1 : 0;
-  }
-
-  // Ensure that the backend buffer can hold aLength data. Will update mData.
-  // Will enforce that the start of allocated data is always Alignment bytes
-  // aligned and that it has sufficient end padding to allow for Alignment bytes
-  // block read as required by some data decoders.
-  // Returns false if memory couldn't be allocated.
-  bool EnsureCapacity(size_t aLength)
-  {
-    const CheckedInt<size_t> sizeNeeded =
-      CheckedInt<size_t>(aLength) * sizeof(Type) + AlignmentOffset() * 2;
-
-    if (!sizeNeeded.isValid()) {
-      // overflow.
-      return false;
-    }
-    if (mData && mCapacity >= sizeNeeded.value()) {
-      return true;
-    }
-    auto newBuffer = MakeUniqueFallible<uint8_t[]>(sizeNeeded.value());
-    if (!newBuffer) {
-      return false;
-    }
-
-    // Find alignment address.
-    const uintptr_t alignmask = AlignmentOffset();
-    Type* newData = reinterpret_cast<Type*>(
-      (reinterpret_cast<uintptr_t>(newBuffer.get()) + alignmask) & ~alignmask);
-    MOZ_ASSERT(uintptr_t(newData) % (AlignmentOffset()+1) == 0);
-
-    PodZero(newData + mLength, aLength - mLength);
-    PodCopy(newData, mData, mLength);
-
-    mBuffer = Move(newBuffer);
-    mCapacity = sizeNeeded.value();
-    mData = newData;
-
-    return true;
-  }
-  Type* mData;
-  size_t mLength;
-  UniquePtr<uint8_t[]> mBuffer;
-  size_t mCapacity;
-};
-
-typedef AlignedBuffer<uint8_t> AlignedByteBuffer;
-typedef AlignedBuffer<float> AlignedFloatBuffer;
-typedef AlignedBuffer<int16_t> AlignedShortBuffer;
-typedef AlignedBuffer<AudioDataValue> AlignedAudioBuffer;
-
 // Container that holds media samples.
 class MediaData {
 public:
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaData)
 
   enum Type {
     AUDIO_DATA = 0,
@@ -347,17 +119,17 @@ protected:
 // Holds chunk a decoded audio frames.
 class AudioData : public MediaData {
 public:
 
   AudioData(int64_t aOffset,
             int64_t aTime,
             int64_t aDuration,
             uint32_t aFrames,
-            AlignedAudioBuffer&& aData,
+            UniquePtr<AudioDataValue[]> aData,
             uint32_t aChannels,
             uint32_t aRate)
     : MediaData(sType, aOffset, aTime, aDuration, aFrames)
     , mChannels(aChannels)
     , mRate(aRate)
     , mAudioData(Move(aData)) {}
 
   static const Type sType = AUDIO_DATA;
@@ -382,17 +154,17 @@ public:
   bool IsAudible() const;
 
   const uint32_t mChannels;
   const uint32_t mRate;
   // At least one of mAudioBuffer/mAudioData must be non-null.
   // mChannels channels, each with mFrames frames
   RefPtr<SharedBuffer> mAudioBuffer;
   // mFrames frames, each with mChannels values
-  AlignedAudioBuffer mAudioData;
+  UniquePtr<AudioDataValue[]> mAudioData;
 
 protected:
   ~AudioData() {}
 };
 
 namespace layers {
 class TextureClient;
 class PlanarYCbCrImage;
@@ -561,21 +333,22 @@ class CryptoSample : public CryptoTrack
 {
 public:
   nsTArray<uint16_t> mPlainSizes;
   nsTArray<uint32_t> mEncryptedSizes;
   nsTArray<uint8_t> mIV;
   nsTArray<nsCString> mSessionIds;
 };
 
+
 // MediaRawData is a MediaData container used to store demuxed, still compressed
 // samples.
 // Use MediaRawData::CreateWriter() to obtain a MediaRawDataWriter object that
 // provides methods to modify and manipulate the data.
-// Memory allocations are fallible. Methods return a boolean indicating if
+// Memory allocations are fallibles. Methods return a boolean indicating if
 // memory allocations were successful. Return values should always be checked.
 // MediaRawData::mData will be nullptr if no memory has been allocated or if
 // an error occurred during construction.
 // Existing data is only ever modified if new memory allocation has succeeded
 // and preserved if not.
 //
 // The memory referenced by mData will always be 32 bytes aligned and the
 // underlying buffer will always have a size such that 32 bytes blocks can be
@@ -618,22 +391,22 @@ private:
 };
 
 class MediaRawData : public MediaData {
 public:
   MediaRawData();
   MediaRawData(const uint8_t* aData, size_t mSize);
 
   // Pointer to data or null if not-yet allocated
-  const uint8_t* Data() const { return mBuffer.Data(); }
+  const uint8_t* Data() const { return mData; }
   // Size of buffer.
-  size_t Size() const { return mBuffer.Length(); }
+  size_t Size() const { return mSize; }
   size_t ComputedSizeOfIncludingThis() const
   {
-    return sizeof(*this) + mBuffer.ComputedSizeOfExcludingThis();
+    return sizeof(*this) + mCapacity;
   }
 
   const CryptoSample& mCrypto;
   RefPtr<MediaByteBuffer> mExtraData;
 
   RefPtr<SharedTrackInfo> mTrackInfo;
 
   // Return a deep copy or nullptr if out of memory.
@@ -643,17 +416,26 @@ public:
   virtual MediaRawDataWriter* CreateWriter();
   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
 
 protected:
   ~MediaRawData();
 
 private:
   friend class MediaRawDataWriter;
-  AlignedByteBuffer mBuffer;
+  // Ensure that the backend buffer can hold aSize data. Will update mData.
+  // Will enforce that the start of allocated data is always 32 bytes
+  // aligned and that it has sufficient end padding to allow for 32 bytes block
+  // read as required by some data decoders.
+  // Returns false if memory couldn't be allocated.
+  bool EnsureCapacity(size_t aSize);
+  uint8_t* mData;
+  size_t mSize;
+  UniquePtr<uint8_t[]> mBuffer;
+  uint32_t mCapacity;
   CryptoSample mCryptoInternal;
   MediaRawData(const MediaRawData&); // Not implemented
 };
 
   // MediaByteBuffer is a ref counted infallible TArray.
 class MediaByteBuffer : public nsTArray<uint8_t> {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaByteBuffer);
   MediaByteBuffer() = default;
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2506,20 +2506,17 @@ MediaDecoderStateMachine::DropAudioUpToS
   if (framesToPrune.value() > audio->mFrames) {
     // We've messed up somehow. Don't try to trim frames, the |frames|
     // variable below will overflow.
     DECODER_WARN("Can't prune more frames that we have!");
     return NS_ERROR_FAILURE;
   }
   uint32_t frames = audio->mFrames - static_cast<uint32_t>(framesToPrune.value());
   uint32_t channels = audio->mChannels;
-  AlignedAudioBuffer audioData(frames * channels);
-  if (!audioData) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  auto audioData = MakeUnique<AudioDataValue[]>(frames * channels);
   memcpy(audioData.get(),
          audio->mAudioData.get() + (framesToPrune.value() * channels),
          frames * channels * sizeof(AudioDataValue));
   CheckedInt64 duration = FramesToUsecs(frames, mInfo.mAudio.mRate);
   if (!duration.isValid()) {
     return NS_ERROR_FAILURE;
   }
   RefPtr<AudioData> data(new AudioData(audio->mOffset,
deleted file mode 100644
--- a/dom/media/MediaInfo.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "MediaInfo.h"
-
-namespace mozilla {
-
-typedef AudioConfig::ChannelLayout ChannelLayout;
-
-/**
- * AudioConfig::ChannelLayout
- */
-
-/*
- SMPTE channel layout (also known as wave order)
- DUAL-MONO      L   R
- DUAL-MONO-LFE  L   R   LFE
- MONO           M
- MONO-LFE       M   LFE
- STEREO         L   R
- STEREO-LFE     L   R   LFE
- 3F             L   R   C
- 3F-LFE         L   R   C    LFE
- 2F1            L   R   S
- 2F1-LFE        L   R   LFE  S
- 3F1            L   R   C    S
- 3F1-LFE        L   R   C    LFE S
- 2F2            L   R   LS   RS
- 2F2-LFE        L   R   LFE  LS   RS
- 3F2            L   R   C    LS   RS
- 3F2-LFE        L   R   C    LFE  LS   RS
- 3F3R-LFE       L   R   C    LFE  BC   LS   RS
- 3F4-LFE        L   R   C    LFE  Rls  Rrs  LS   RS
-*/
-
-void
-AudioConfig::ChannelLayout::UpdateChannelMap()
-{
-  mChannelMap = 0;
-  mValid = mChannels.Length() <= MAX_AUDIO_CHANNELS;
-  for (size_t i = 0; i < mChannels.Length() && i <= MAX_AUDIO_CHANNELS; i++) {
-    uint32_t mask = 1 << mChannels[i];
-    if (mChannels[i] == CHANNEL_INVALID || (mChannelMap & mask)) {
-      mValid = false;
-    }
-    mChannelMap |= mask;
-  }
-}
-
-/* static */ const AudioConfig::Channel*
-AudioConfig::ChannelLayout::SMPTEDefault(uint32_t aChannels) const
-{
-  switch (aChannels) {
-    case 1: // MONO
-    {
-      static const Channel config[] = { CHANNEL_MONO };
-      return config;
-    }
-    case 2: // STEREO
-    {
-      static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT };
-      return config;
-    }
-    case 3: // 3F
-    {
-      static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER };
-      return config;
-    }
-    case 4: // 2F2
-    {
-      static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_LS, CHANNEL_RS };
-      return config;
-    }
-    case 5: // 3F2
-    {
-      static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LS, CHANNEL_RS };
-      return config;
-    }
-    case 6: // 3F2-LFE
-    {
-      static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_LS, CHANNEL_RS };
-      return config;
-    }
-    case 7: // 3F3R-LFE
-    {
-      static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_RCENTER, CHANNEL_LS, CHANNEL_RS };
-      return config;
-    }
-    case 8: // 3F4-LFE
-    {
-      static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_RLS, CHANNEL_RRS, CHANNEL_LS, CHANNEL_RS };
-      return config;
-    }
-    default:
-      return nullptr;
-  }
-}
-
-bool
-AudioConfig::ChannelLayout::MappingTable(const ChannelLayout& aOther,
-                                         uint8_t* aMap) const
-{
-  if (!IsValid() || !aOther.IsValid() ||
-      Map() != aOther.Map()) {
-    return false;
-  }
-  if (!aMap) {
-    return true;
-  }
-  for (uint32_t i = 0; i < Count(); i++) {
-    for (uint32_t j = 0; j < Count(); j++) {
-      if (aOther[j] == mChannels[i]) {
-        aMap[j] = i;
-        break;
-      }
-    }
-  }
-  return true;
-}
-
-/**
- * AudioConfig::ChannelConfig
- */
-
-/* static */ const char*
-AudioConfig::FormatToString(AudioConfig::SampleFormat aFormat)
-{
-  switch (aFormat) {
-    case FORMAT_U8:     return "unsigned 8 bit";
-    case FORMAT_S16:    return "signed 16 bit";
-    case FORMAT_S24:    return "signed 24 bit MSB";
-    case FORMAT_S24LSB: return "signed 24 bit LSB";
-    case FORMAT_S32:    return "signed 32 bit";
-    case FORMAT_FLT:    return "32 bit floating point";
-    case FORMAT_NONE:   return "none";
-    default:            return "unknown";
-  }
-}
-/* static */ uint32_t
-AudioConfig::SampleSize(AudioConfig::SampleFormat aFormat)
-{
-  switch (aFormat) {
-    case FORMAT_U8:     return 1;
-    case FORMAT_S16:    return 2;
-    case FORMAT_S24:    MOZ_FALLTHROUGH;
-    case FORMAT_S24LSB: MOZ_FALLTHROUGH;
-    case FORMAT_S32:    MOZ_FALLTHROUGH;
-    case FORMAT_FLT:    return 4;
-    case FORMAT_NONE:
-    default:            return 0;
-  }
-}
-
-/* static */ uint32_t
-AudioConfig::FormatToBits(AudioConfig::SampleFormat aFormat)
-{
-  switch (aFormat) {
-    case FORMAT_U8:     return 8;
-    case FORMAT_S16:    return 16;
-    case FORMAT_S24LSB: MOZ_FALLTHROUGH;
-    case FORMAT_S24:    return 24;
-    case FORMAT_S32:    MOZ_FALLTHROUGH;
-    case FORMAT_FLT:    return 32;
-    case FORMAT_NONE:   MOZ_FALLTHROUGH;
-    default:            return 0;
-  }
-}
-
-AudioConfig::AudioConfig(const ChannelLayout& aChannelLayout, uint32_t aRate,
-                         AudioConfig::SampleFormat aFormat, bool aInterleaved)
-  : mChannelLayout(aChannelLayout)
-  , mChannels(aChannelLayout.Count())
-  , mRate(aRate)
-  , mFormat(aFormat)
-  , mInterleaved(aInterleaved)
-{}
-
-AudioConfig::AudioConfig(uint32_t aChannels, uint32_t aRate,
-                         AudioConfig::SampleFormat aFormat, bool aInterleaved)
-  : mChannelLayout(aChannels)
-  , mChannels(aChannels)
-  , mRate(aRate)
-  , mFormat(aFormat)
-  , mInterleaved(aInterleaved)
-{}
-
-} // namespace mozilla
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -469,158 +469,11 @@ private:
   UniquePtr<TrackInfo> mInfo;
   // A unique ID, guaranteed to change when changing streams.
   uint32_t mStreamSourceID;
 
 public:
   const nsCString& mMimeType;
 };
 
-// Maximum channel number we can currently handle (7.1)
-#define MAX_AUDIO_CHANNELS 8
-
-class AudioConfig {
-public:
-  enum Channel {
-    CHANNEL_INVALID = -1,
-    CHANNEL_MONO = 0,
-    CHANNEL_LEFT,
-    CHANNEL_RIGHT,
-    CHANNEL_CENTER,
-    CHANNEL_LS,
-    CHANNEL_RS,
-    CHANNEL_RLS,
-    CHANNEL_RCENTER,
-    CHANNEL_RRS,
-    CHANNEL_LFE,
-  };
-
-  class ChannelLayout {
-  public:
-    ChannelLayout()
-      : mChannelMap(0)
-      , mValid(false)
-    {}
-    explicit ChannelLayout(uint32_t aChannels)
-      : ChannelLayout(aChannels, SMPTEDefault(aChannels))
-    {}
-    ChannelLayout(uint32_t aChannels, const Channel* aConfig)
-    {
-      mChannels.AppendElements(aConfig, aChannels);
-      UpdateChannelMap();
-    }
-    bool operator==(const ChannelLayout& aOther) const
-    {
-      return mChannels == aOther.mChannels;
-    }
-    bool operator!=(const ChannelLayout& aOther) const
-    {
-      return mChannels != aOther.mChannels;
-    }
-    const Channel& operator[](uint32_t aIndex) const
-    {
-      return mChannels[aIndex];
-    }
-    uint32_t Count() const
-    {
-      return mChannels.Length();
-    }
-    uint32_t Map() const
-    {
-      return mChannelMap;
-    }
-    // Calculate the mapping table from the current layout to aOther such that
-    // one can easily go from one layout to the other by doing:
-    // out[channel] = in[map[channel]].
-    // Returns true if the reordering is possible or false otherwise.
-    // If true, then aMap, if set, will be updated to contain the mapping table
-    // allowing conversion from the current layout to aOther.
-    // If aMap is nullptr, then MappingTable can be used to simply determine if
-    // the current layout can be easily reordered to aOther.
-    // aMap must be an array of size MAX_AUDIO_CHANNELS.
-    bool MappingTable(const ChannelLayout& aOther, uint8_t* aMap = nullptr) const;
-    bool IsValid() const {
-      return mValid;
-    }
-    bool HasChannel(Channel aChannel) const
-    {
-      return mChannelMap & (1 << aChannel);
-    }
-  private:
-    void UpdateChannelMap();
-    const Channel* SMPTEDefault(uint32_t aChannels) const;
-    AutoTArray<Channel, MAX_AUDIO_CHANNELS> mChannels;
-    uint32_t mChannelMap;
-    bool mValid;
-  };
-
-  enum SampleFormat {
-    FORMAT_NONE = 0,
-    FORMAT_U8,
-    FORMAT_S16,
-    FORMAT_S24LSB,
-    FORMAT_S24,
-    FORMAT_S32,
-    FORMAT_FLT,
-#if defined(MOZ_SAMPLE_TYPE_FLOAT32)
-    FORMAT_DEFAULT = FORMAT_FLT
-#elif defined(MOZ_SAMPLE_TYPE_S16)
-    FORMAT_DEFAULT = FORMAT_S16
-#else
-#error "Not supported audio type"
-#endif
-  };
-
-  AudioConfig(const ChannelLayout& aChannelLayout, uint32_t aRate,
-              AudioConfig::SampleFormat aFormat = FORMAT_DEFAULT,
-              bool aInterleaved = true);
-  // Will create a channel configuration from default SMPTE ordering.
-  AudioConfig(uint32_t aChannels, uint32_t aRate,
-              AudioConfig::SampleFormat aFormat = FORMAT_DEFAULT,
-              bool aInterleaved = true);
-
-  const ChannelLayout& Layout() const
-  {
-    return mChannelLayout;
-  }
-  uint32_t Channels() const
-  {
-    if (!mChannelLayout.IsValid()) {
-      return mChannels;
-    }
-    return mChannelLayout.Count();
-  }
-  uint32_t Rate() const
-  {
-    return mRate;
-  }
-  SampleFormat Format() const
-  {
-    return mFormat;
-  }
-  bool Interleaved() const
-  {
-    return mInterleaved;
-  }
-
-  static const char* FormatToString(SampleFormat aFormat);
-  static uint32_t SampleSize(SampleFormat aFormat);
-  static uint32_t FormatToBits(SampleFormat aFormat);
-
-private:
-  // Channels configuration.
-  ChannelLayout mChannelLayout;
-
-  // Channel count.
-  uint32_t mChannels;
-
-  // Sample rate.
-  uint32_t mRate;
-
-  // Sample format.
-  SampleFormat mFormat;
-
-  bool mInterleaved;
-};
-
 } // namespace mozilla
 
 #endif // MediaInfo_h
--- a/dom/media/VideoUtils.cpp
+++ b/dom/media/VideoUtils.cpp
@@ -143,44 +143,44 @@ media::TimeIntervals GetEstimatedBuffere
 int DownmixAudioToStereo(mozilla::AudioDataValue* buffer,
                          int channels, uint32_t frames)
 {
   int outChannels;
   outChannels = 2;
 #ifdef MOZ_SAMPLE_TYPE_FLOAT32
   // Downmix matrix. Per-row normalization 1 for rows 3,4 and 2 for rows 5-8.
   static const float dmatrix[6][8][2]= {
-      /*3*/{{0.5858f,0},{0,0.5858f},{0.4142f,0.4142f}},
-      /*4*/{{0.4226f,0},{0,0.4226f},{0.366f, 0.2114f},{0.2114f,0.366f}},
-      /*5*/{{0.6510f,0},{0,0.6510f},{0.4600f,0.4600f},{0.5636f,0.3254f},{0.3254f,0.5636f}},
-      /*6*/{{0.5290f,0},{0,0.5290f},{0.3741f,0.3741f},{0.3741f,0.3741f},{0.4582f,0.2645f},{0.2645f,0.4582f}},
-      /*7*/{{0.4553f,0},{0,0.4553f},{0.3220f,0.3220f},{0.3220f,0.3220f},{0.2788f,0.2788f},{0.3943f,0.2277f},{0.2277f,0.3943f}},
-      /*8*/{{0.3886f,0},{0,0.3886f},{0.2748f,0.2748f},{0.2748f,0.2748f},{0.3366f,0.1943f},{0.1943f,0.3366f},{0.3366f,0.1943f},{0.1943f,0.3366f}},
+      /*3*/{{0.5858f,0},{0.4142f,0.4142f},{0,     0.5858f}},
+      /*4*/{{0.4226f,0},{0,      0.4226f},{0.366f,0.2114f},{0.2114f,0.366f}},
+      /*5*/{{0.6510f,0},{0.4600f,0.4600f},{0,     0.6510f},{0.5636f,0.3254f},{0.3254f,0.5636f}},
+      /*6*/{{0.5290f,0},{0.3741f,0.3741f},{0,     0.5290f},{0.4582f,0.2645f},{0.2645f,0.4582f},{0.3741f,0.3741f}},
+      /*7*/{{0.4553f,0},{0.3220f,0.3220f},{0,     0.4553f},{0.3943f,0.2277f},{0.2277f,0.3943f},{0.2788f,0.2788f},{0.3220f,0.3220f}},
+      /*8*/{{0.3886f,0},{0.2748f,0.2748f},{0,     0.3886f},{0.3366f,0.1943f},{0.1943f,0.3366f},{0.3366f,0.1943f},{0.1943f,0.3366f},{0.2748f,0.2748f}},
   };
   // Re-write the buffer with downmixed data
   for (uint32_t i = 0; i < frames; i++) {
     float sampL = 0.0;
     float sampR = 0.0;
     for (int j = 0; j < channels; j++) {
       sampL+=buffer[i*channels+j]*dmatrix[channels-3][j][0];
       sampR+=buffer[i*channels+j]*dmatrix[channels-3][j][1];
     }
     buffer[i*outChannels]=sampL;
     buffer[i*outChannels+1]=sampR;
   }
 #else
   // Downmix matrix. Per-row normalization 1 for rows 3,4 and 2 for rows 5-8.
   // Coefficients in Q14.
   static const int16_t dmatrix[6][8][2]= {
-      /*3*/{{9598, 0},{0,   9598},{6786,6786}},
+      /*3*/{{9598, 0},{6786,6786},{0,   9598}},
       /*4*/{{6925, 0},{0,   6925},{5997,3462},{3462,5997}},
-      /*5*/{{10663,0},{0,  10663},{7540,7540},{9234,5331},{5331,9234}},
-      /*6*/{{8668, 0},{0,   8668},{6129,6129},{6129,6129},{7507,4335},{4335,7507}},
-      /*7*/{{7459, 0},{0,   7459},{5275,5275},{5275,5275},{4568,4568},{6460,3731},{3731,6460}},
-      /*8*/{{6368, 0},{0,   6368},{4502,4502},{4502,4502},{5514,3184},{3184,5514},{5514,3184},{3184,5514}}
+      /*5*/{{10663,0},{7540,7540},{0,  10663},{9234,5331},{5331,9234}},
+      /*6*/{{8668, 0},{6129,6129},{0,   8668},{7507,4335},{4335,7507},{6129,6129}},
+      /*7*/{{7459, 0},{5275,5275},{0,   7459},{6460,3731},{3731,6460},{4568,4568},{5275,5275}},
+      /*8*/{{6368, 0},{4502,4502},{0,   6368},{5514,3184},{3184,5514},{5514,3184},{3184,5514},{4502,4502}}
   };
   // Re-write the buffer with downmixed data
   for (uint32_t i = 0; i < frames; i++) {
     int32_t sampL = 0;
     int32_t sampR = 0;
     for (int j = 0; j < channels; j++) {
       sampL+=buffer[i*channels+j]*dmatrix[channels-3][j][0];
       sampR+=buffer[i*channels+j]*dmatrix[channels-3][j][1];
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -84,17 +84,16 @@ XPIDL_MODULE = 'dom_media'
 
 EXPORTS += [
     'AbstractMediaDecoder.h',
     'ADTSDecoder.h',
     'ADTSDemuxer.h',
     'AudioBufferUtils.h',
     'AudioChannelFormat.h',
     'AudioCompactor.h',
-    'AudioConverter.h',
     'AudioMixer.h',
     'AudioPacketizer.h',
     'AudioSampleFormat.h',
     'AudioSegment.h',
     'AudioStream.h',
     'Benchmark.h',
     'BufferMediaResource.h',
     'CubebUtils.h',
@@ -192,17 +191,16 @@ EXPORTS.mozilla.dom += [
 ]
 
 UNIFIED_SOURCES += [
     'ADTSDecoder.cpp',
     'ADTSDemuxer.cpp',
     'AudioCaptureStream.cpp',
     'AudioChannelFormat.cpp',
     'AudioCompactor.cpp',
-    'AudioConverter.cpp',
     'AudioSegment.cpp',
     'AudioStream.cpp',
     'AudioStreamTrack.cpp',
     'AudioTrack.cpp',
     'AudioTrackList.cpp',
     'Benchmark.cpp',
     'CanvasCaptureMediaStream.cpp',
     'CubebUtils.cpp',
@@ -217,17 +215,16 @@ UNIFIED_SOURCES += [
     'MediaData.cpp',
     'MediaDecoder.cpp',
     'MediaDecoderReader.cpp',
     'MediaDecoderReaderWrapper.cpp',
     'MediaDecoderStateMachine.cpp',
     'MediaDeviceInfo.cpp',
     'MediaDevices.cpp',
     'MediaFormatReader.cpp',
-    'MediaInfo.cpp',
     'MediaManager.cpp',
     'MediaRecorder.cpp',
     'MediaResource.cpp',
     'MediaShutdownManager.cpp',
     'MediaStreamError.cpp',
     'MediaStreamGraph.cpp',
     'MediaStreamTrack.cpp',
     'MediaTimer.cpp',
--- a/dom/media/ogg/OggReader.cpp
+++ b/dom/media/ogg/OggReader.cpp
@@ -523,20 +523,17 @@ nsresult OggReader::DecodeVorbis(ogg_pac
   }
 
   VorbisPCMValue** pcm = 0;
   int32_t frames = 0;
   uint32_t channels = mVorbisState->mInfo.channels;
   ogg_int64_t endFrame = aPacket->granulepos;
   while ((frames = vorbis_synthesis_pcmout(&mVorbisState->mDsp, &pcm)) > 0) {
     mVorbisState->ValidateVorbisPacketSamples(aPacket, frames);
-    AlignedAudioBuffer buffer(frames * channels);
-    if (!buffer) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
+    auto buffer = MakeUnique<AudioDataValue[]>(frames * channels);
     for (uint32_t j = 0; j < channels; ++j) {
       VorbisPCMValue* channel = pcm[j];
       for (uint32_t i = 0; i < uint32_t(frames); ++i) {
         buffer[i*channels + j] = MOZ_CONVERT_VORBIS_SAMPLE(channel[i]);
       }
     }
 
     // No channel mapping for more than 8 channels.
@@ -575,20 +572,17 @@ nsresult OggReader::DecodeOpus(ogg_packe
   int32_t samples = opus_packet_get_samples_per_frame(aPacket->packet,
                                                       (opus_int32) mOpusState->mRate);
   int32_t frames = frames_number*samples;
 
   // A valid Opus packet must be between 2.5 and 120 ms long.
   if (frames < 120 || frames > 5760)
     return NS_ERROR_FAILURE;
   uint32_t channels = mOpusState->mChannels;
-  AlignedAudioBuffer buffer(frames * channels);
-  if (!buffer) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  auto buffer = MakeUnique<AudioDataValue[]>(frames * channels);
 
   // Decode to the appropriate sample type.
 #ifdef MOZ_SAMPLE_TYPE_FLOAT32
   int ret = opus_multistream_decode_float(mOpusState->mDecoder,
                                           aPacket->packet, aPacket->bytes,
                                           buffer.get(), frames, false);
 #else
   int ret = opus_multistream_decode(mOpusState->mDecoder,
@@ -618,20 +612,17 @@ nsresult OggReader::DecodeOpus(ogg_packe
       // discard the whole packet
       mOpusState->mSkip -= frames;
       LOG(LogLevel::Debug, ("Opus decoder skipping %d frames"
                          " (whole packet)", frames));
       return NS_OK;
     }
     int32_t keepFrames = frames - skipFrames;
     int samples = keepFrames * channels;
-    AlignedAudioBuffer trimBuffer(samples);
-    if (!trimBuffer) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
+    auto trimBuffer = MakeUnique<AudioDataValue[]>(samples);
     for (int i = 0; i < samples; i++)
       trimBuffer[i] = buffer[skipFrames*channels + i];
 
     startFrame = endFrame - keepFrames;
     frames = keepFrames;
     buffer = Move(trimBuffer);
 
     mOpusState->mSkip -= skipFrames;
--- a/dom/media/platforms/agnostic/BlankDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/BlankDecoderModule.cpp
@@ -6,16 +6,18 @@
 
 #include "ImageContainer.h"
 #include "MediaDecoderReader.h"
 #include "MediaInfo.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/mozalloc.h" // for operator new, and new (fallible)
 #include "mozilla/RefPtr.h"
 #include "mozilla/TaskQueue.h"
+#include "mozilla/UniquePtr.h"
+#include "mozilla/UniquePtrExtensions.h"
 #include "nsRect.h"
 #include "PlatformDecoderModule.h"
 #include "TimeUnits.h"
 #include "VideoUtils.h"
 
 namespace mozilla {
 
 // Decoder that uses a passed in object's Create function to create blank
@@ -187,17 +189,18 @@ public:
     CheckedInt64 frames =
       UsecsToFrames(aDuration.ToMicroseconds()+1, mSampleRate);
     if (!frames.isValid() ||
         !mChannelCount ||
         !mSampleRate ||
         frames.value() > (UINT32_MAX / mChannelCount)) {
       return nullptr;
     }
-    AlignedAudioBuffer samples(frames.value() * mChannelCount);
+    auto samples =
+      MakeUniqueFallible<AudioDataValue[]>(frames.value() * mChannelCount);
     if (!samples) {
       return nullptr;
     }
     // Fill the sound buffer with an A4 tone.
     static const float pi = 3.14159265f;
     static const float noteHz = 440.0f;
     for (int i = 0; i < frames.value(); i++) {
       float f = sin(2 * pi * noteHz * mFrameSum / mSampleRate);
--- a/dom/media/platforms/agnostic/OpusDecoder.cpp
+++ b/dom/media/platforms/agnostic/OpusDecoder.cpp
@@ -2,19 +2,17 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "OpusDecoder.h"
 #include "TimeUnits.h"
 #include "VorbisUtils.h"
-#include "VorbisDecoder.h" // For VorbisLayout
 #include "mozilla/Endian.h"
-#include "mozilla/PodOperations.h"
 
 #include <stdint.h>
 #include <inttypes.h>  // For PRId64
 
 extern mozilla::LogModule* GetPDMLog();
 #define OPUS_DEBUG(arg, ...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, \
     ("OpusDataDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
 
@@ -63,17 +61,17 @@ OpusDataDecoder::Init()
     return InitPromise::CreateAndReject(DecoderFailureReason::INIT_ERROR, __func__);
   }
 
   int r;
   mOpusDecoder = opus_multistream_decoder_create(mOpusParser->mRate,
                                                  mOpusParser->mChannels,
                                                  mOpusParser->mStreams,
                                                  mOpusParser->mCoupledStreams,
-                                                 mMappingTable,
+                                                 mOpusParser->mMappingTable,
                                                  &r);
   mSkip = mOpusParser->mPreSkip;
   mPaddingDiscarded = false;
 
   if (codecDelay != FramesToUsecs(mOpusParser->mPreSkip,
                                   mOpusParser->mRate).value()) {
     NS_WARNING("Invalid Opus header: CodecDelay and pre-skip do not match!");
     return InitPromise::CreateAndReject(DecoderFailureReason::INIT_ERROR, __func__);
@@ -97,40 +95,23 @@ OpusDataDecoder::DecodeHeader(const unsi
   MOZ_ASSERT(!mOpusDecoder);
   MOZ_ASSERT(!mDecodedHeader);
   mDecodedHeader = true;
 
   mOpusParser = new OpusParser;
   if (!mOpusParser->DecodeHeader(const_cast<unsigned char*>(aData), aLength)) {
     return NS_ERROR_FAILURE;
   }
-  int channels = mOpusParser->mChannels;
   // No channel mapping for more than 8 channels.
-  if (channels > 8) {
+  if (mOpusParser->mChannels > 8) {
     OPUS_DEBUG("No channel mapping for more than 8 channels. Source is %d channels",
-               channels);
+               mOpusParser->mChannels);
     return NS_ERROR_FAILURE;
   }
 
-  AudioConfig::ChannelLayout vorbisLayout(
-    channels, VorbisDataDecoder::VorbisLayout(channels));
-  AudioConfig::ChannelLayout smpteLayout(channels);
-  static_assert(sizeof(mOpusParser->mMappingTable) / sizeof(mOpusParser->mMappingTable[0]) >= MAX_AUDIO_CHANNELS,
-                       "Invalid size set");
-  uint8_t map[sizeof(mOpusParser->mMappingTable) / sizeof(mOpusParser->mMappingTable[0])];
-  if (vorbisLayout.MappingTable(smpteLayout, map)) {
-    for (int i = 0; i < channels; i++) {
-      mMappingTable[i] = mOpusParser->mMappingTable[map[i]];
-    }
-  } else {
-    // Should never get here as vorbis layout is always convertible to SMPTE
-    // default layout.
-    PodCopy(mMappingTable, mOpusParser->mMappingTable, MAX_AUDIO_CHANNELS);
-  }
-
   return NS_OK;
 }
 
 nsresult
 OpusDataDecoder::Input(MediaRawData* aSample)
 {
   nsCOMPtr<nsIRunnable> runnable(
     NS_NewRunnableMethodWithArg<RefPtr<MediaRawData>>(
@@ -188,20 +169,17 @@ OpusDataDecoder::DoDecode(MediaRawData* 
 
   // A valid Opus packet must be between 2.5 and 120 ms long (48kHz).
   int32_t frames = frames_number*samples;
   if (frames < 120 || frames > 5760) {
     OPUS_DEBUG("Invalid packet frames: %ld", frames);
     return -1;
   }
 
-  AlignedAudioBuffer buffer(frames * channels);
-  if (!buffer) {
-    return -1;
-  }
+  auto buffer = MakeUnique<AudioDataValue[]>(frames * channels);
 
   // Decode to the appropriate sample type.
 #ifdef MOZ_SAMPLE_TYPE_FLOAT32
   int ret = opus_multistream_decode_float(mOpusDecoder,
                                           aSample->Data(), aSample->Size(),
                                           buffer.get(), frames, false);
 #else
   int ret = opus_multistream_decode(mOpusDecoder,
--- a/dom/media/platforms/agnostic/OpusDecoder.h
+++ b/dom/media/platforms/agnostic/OpusDecoder.h
@@ -54,13 +54,12 @@ private:
   bool mDecodedHeader;
 
   // Opus padding should only be discarded on the final packet.  Once this
   // is set to true, if the reader attempts to decode any further packets it
   // will raise an error so we can indicate that the file is invalid.
   bool mPaddingDiscarded;
   int64_t mFrames;
   Maybe<int64_t> mLastFrameTime;
-  uint8_t mMappingTable[MAX_AUDIO_CHANNELS]; // Channel mapping table.
 };
 
 } // namespace mozilla
 #endif
--- a/dom/media/platforms/agnostic/VorbisDecoder.cpp
+++ b/dom/media/platforms/agnostic/VorbisDecoder.cpp
@@ -179,69 +179,56 @@ VorbisDataDecoder::DoDecode(MediaRawData
   // start time is calculated.  Otherwise we'd end up with a media start
   // time derived from the timecode of the first packet that produced
   // data.
   if (frames == 0 && first_packet) {
     mCallback->Output(new AudioData(aOffset,
                                     aTstampUsecs,
                                     0,
                                     0,
-                                    AlignedAudioBuffer(),
+                                    nullptr,
                                     mVorbisDsp.vi->channels,
                                     mVorbisDsp.vi->rate));
   }
   while (frames > 0) {
     uint32_t channels = mVorbisDsp.vi->channels;
-    uint32_t rate = mVorbisDsp.vi->rate;
-    AlignedAudioBuffer buffer(frames*channels);
-    if (!buffer) {
-      return -1;
-    }
+    auto buffer = MakeUnique<AudioDataValue[]>(frames*channels);
     for (uint32_t j = 0; j < channels; ++j) {
       VorbisPCMValue* channel = pcm[j];
       for (uint32_t i = 0; i < uint32_t(frames); ++i) {
         buffer[i*channels + j] = MOZ_CONVERT_VORBIS_SAMPLE(channel[i]);
       }
     }
 
-    CheckedInt64 duration = FramesToUsecs(frames, rate);
+    CheckedInt64 duration = FramesToUsecs(frames, mVorbisDsp.vi->rate);
     if (!duration.isValid()) {
       NS_WARNING("Int overflow converting WebM audio duration");
       return -1;
     }
-    CheckedInt64 total_duration = FramesToUsecs(mFrames, rate);
+    CheckedInt64 total_duration = FramesToUsecs(mFrames,
+                                                mVorbisDsp.vi->rate);
     if (!total_duration.isValid()) {
       NS_WARNING("Int overflow converting WebM audio total_duration");
       return -1;
     }
 
     CheckedInt64 time = total_duration + aTstampUsecs;
     if (!time.isValid()) {
       NS_WARNING("Int overflow adding total_duration and aTstampUsecs");
       return -1;
     };
 
-    if (!mAudioConverter) {
-      AudioConfig in(AudioConfig::ChannelLayout(channels, VorbisLayout(channels)),
-                     rate);
-      AudioConfig out(channels, rate);
-      mAudioConverter = MakeUnique<AudioConverter>(in, out);
-    }
-    MOZ_ASSERT(mAudioConverter->CanWorkInPlace());
-    AudioSampleBuffer data(Move(buffer));
-    mAudioConverter->Process(data);
-
     aTotalFrames += frames;
     mCallback->Output(new AudioData(aOffset,
                                     time.value(),
                                     duration.value(),
                                     frames,
-                                    data.Forget(),
-                                    channels,
-                                    rate));
+                                    Move(buffer),
+                                    mVorbisDsp.vi->channels,
+                                    mVorbisDsp.vi->rate));
     mFrames += frames;
     if (vorbis_synthesis_read(&mVorbisDsp, frames) != 0) {
       return -1;
     }
 
     frames = vorbis_synthesis_pcmout(&mVorbisDsp, &pcm);
   }
 
@@ -278,63 +265,11 @@ VorbisDataDecoder::Flush()
 /* static */
 bool
 VorbisDataDecoder::IsVorbis(const nsACString& aMimeType)
 {
   return aMimeType.EqualsLiteral("audio/webm; codecs=vorbis") ||
          aMimeType.EqualsLiteral("audio/ogg; codecs=vorbis");
 }
 
-/* static */ const AudioConfig::Channel*
-VorbisDataDecoder::VorbisLayout(uint32_t aChannels)
-{
-  // From https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html
-  // Section 4.3.9.
-  typedef AudioConfig::Channel Channel;
-
-  switch (aChannels) {
-    case 1: // the stream is monophonic
-    {
-      static const Channel config[] = { AudioConfig::CHANNEL_MONO };
-      return config;
-    }
-    case 2: // the stream is stereo. channel order: left, right
-    {
-      static const Channel config[] = { AudioConfig::CHANNEL_LEFT, AudioConfig::CHANNEL_RIGHT };
-      return config;
-    }
-    case 3: // the stream is a 1d-surround encoding. channel order: left, center, right
-    {
-      static const Channel config[] = { AudioConfig::CHANNEL_LEFT, AudioConfig::CHANNEL_CENTER, AudioConfig::CHANNEL_RIGHT };
-      return config;
-    }
-    case 4: // the stream is quadraphonic surround. channel order: front left, front right, rear left, rear right
-    {
-      static const Channel config[] = { AudioConfig::CHANNEL_LEFT, AudioConfig::CHANNEL_RIGHT, AudioConfig::CHANNEL_LS, AudioConfig::CHANNEL_RS };
-      return config;
-    }
-    case 5: // the stream is five-channel surround. channel order: front left, center, front right, rear left, rear right
-    {
-      static const Channel config[] = { AudioConfig::CHANNEL_LEFT, AudioConfig::CHANNEL_CENTER, AudioConfig::CHANNEL_RIGHT, AudioConfig::CHANNEL_LS, AudioConfig::CHANNEL_RS };
-      return config;
-    }
-    case 6: // the stream is 5.1 surround. channel order: front left, center, front right, rear left, rear right, LFE
-    {
-      static const Channel config[] = { AudioConfig::CHANNEL_LEFT, AudioConfig::CHANNEL_CENTER, AudioConfig::CHANNEL_RIGHT, AudioConfig::CHANNEL_LS, AudioConfig::CHANNEL_RS, AudioConfig::CHANNEL_LFE };
-      return config;
-    }
-    case 7: // surround. channel order: front left, center, front right, side left, side right, rear center, LFE
-    {
-      static const Channel config[] = { AudioConfig::CHANNEL_LEFT, AudioConfig::CHANNEL_CENTER, AudioConfig::CHANNEL_RIGHT, AudioConfig::CHANNEL_LS, AudioConfig::CHANNEL_RS, AudioConfig::CHANNEL_RCENTER, AudioConfig::CHANNEL_LFE };
-      return config;
-    }
-    case 8: // the stream is 7.1 surround. channel order: front left, center, front right, side left, side right, rear left, rear right, LFE
-    {
-      static const Channel config[] = { AudioConfig::CHANNEL_LEFT, AudioConfig::CHANNEL_CENTER, AudioConfig::CHANNEL_RIGHT, AudioConfig::CHANNEL_LS, AudioConfig::CHANNEL_RS, AudioConfig::CHANNEL_RLS, AudioConfig::CHANNEL_RRS, AudioConfig::CHANNEL_LFE };
-      return config;
-    }
-    default:
-      return nullptr;
-  }
-}
 
 } // namespace mozilla
 #undef LOG
--- a/dom/media/platforms/agnostic/VorbisDecoder.h
+++ b/dom/media/platforms/agnostic/VorbisDecoder.h
@@ -3,17 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #if !defined(VorbisDecoder_h_)
 #define VorbisDecoder_h_
 
 #include "PlatformDecoderModule.h"
 #include "mozilla/Maybe.h"
-#include "AudioConverter.h"
 
 #ifdef MOZ_TREMOR
 #include "tremor/ivorbiscodec.h"
 #else
 #include "vorbis/codec.h"
 #endif
 
 namespace mozilla {
@@ -33,17 +32,16 @@ public:
   nsresult Shutdown() override;
   const char* GetDescriptionName() const override
   {
     return "vorbis audio decoder";
   }
 
   // Return true if mimetype is Vorbis
   static bool IsVorbis(const nsACString& aMimeType);
-  static const AudioConfig::Channel* VorbisLayout(uint32_t aChannels);
 
 private:
   nsresult DecodeHeader(const unsigned char* aData, size_t aLength);
 
   void Decode (MediaRawData* aSample);
   int DoDecode (MediaRawData* aSample);
   void DoDrain ();
 
@@ -55,13 +53,12 @@ private:
   vorbis_info mVorbisInfo;
   vorbis_comment mVorbisComment;
   vorbis_dsp_state mVorbisDsp;
   vorbis_block mVorbisBlock;
 
   int64_t mPacketCount;
   int64_t mFrames;
   Maybe<int64_t> mLastFrameTime;
-  UniquePtr<AudioConverter> mAudioConverter;
 };
 
 } // namespace mozilla
 #endif
--- a/dom/media/platforms/agnostic/WAVDecoder.cpp
+++ b/dom/media/platforms/agnostic/WAVDecoder.cpp
@@ -94,20 +94,17 @@ WaveDataDecoder::DoDecode(MediaRawData* 
 {
   size_t aLength = aSample->Size();
   ByteReader aReader = ByteReader(aSample->Data(), aLength);
   int64_t aOffset = aSample->mOffset;
   uint64_t aTstampUsecs = aSample->mTime;
 
   int32_t frames = aLength * 8 / mInfo.mBitDepth / mInfo.mChannels;
 
-  AlignedAudioBuffer buffer(frames * mInfo.mChannels);
-  if (!buffer) {
-    return false;
-  }
+  auto buffer = MakeUnique<AudioDataValue[]>(frames * mInfo.mChannels);
   for (int i = 0; i < frames; ++i) {
     for (unsigned int j = 0; j < mInfo.mChannels; ++j) {
       if (mInfo.mProfile == 6) {                              //ALAW Data
         uint8_t v = aReader.ReadU8();
         int16_t decoded = DecodeALawSample(v);
         buffer[i * mInfo.mChannels + j] =
             IntegerToAudioSample<AudioDataValue>(decoded);
       } else if (mInfo.mProfile == 7) {                       //ULAW Data
--- a/dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
@@ -32,21 +32,17 @@ AudioCallbackAdapter::Decoded(const nsTA
   if (aRate == 0 || aChannels == 0) {
     NS_WARNING("Invalid rate or num channels returned on GMP audio samples");
     mCallback->Error();
     return;
   }
 
   size_t numFrames = aPCM.Length() / aChannels;
   MOZ_ASSERT((aPCM.Length() % aChannels) == 0);
-  AlignedAudioBuffer audioData(aPCM.Length());
-  if (!audioData) {
-    mCallback->Error();
-    return;
-  }
+  auto audioData = MakeUnique<AudioDataValue[]>(aPCM.Length());
 
   for (size_t i = 0; i < aPCM.Length(); ++i) {
     audioData[i] = AudioSampleToFloat(aPCM[i]);
   }
 
   if (mMustRecaptureAudioPosition) {
     mAudioFrameSum = 0;
     auto timestamp = UsecsToFrames(aTimeStamp, aRate);
--- a/dom/media/platforms/android/AndroidDecoderModule.cpp
+++ b/dom/media/platforms/android/AndroidDecoderModule.cpp
@@ -213,20 +213,17 @@ public:
 
 #ifdef MOZ_SAMPLE_TYPE_S16
     const int32_t numSamples = size / 2;
 #else
 #error We only support 16-bit integer PCM
 #endif
 
     const int32_t numFrames = numSamples / numChannels;
-    AlignedAudioBuffer audio(numSamples);
-    if (!audio) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
+    auto audio = MakeUnique<AudioDataValue[]>(numSamples);
 
     const uint8_t* bufferStart = static_cast<uint8_t*>(aBuffer) + offset;
     PodCopy(audio.get(), reinterpret_cast<const AudioDataValue*>(bufferStart),
             numSamples);
 
     int64_t presentationTimeUs;
     NS_ENSURE_SUCCESS(rv = aInfo->PresentationTimeUs(&presentationTimeUs), rv);
 
--- a/dom/media/platforms/apple/AppleATDecoder.cpp
+++ b/dom/media/platforms/apple/AppleATDecoder.cpp
@@ -215,20 +215,17 @@ AppleATDecoder::DecodeSample(MediaRawDat
   auto packets = MakeUnique<AudioStreamPacketDescription[]>(MAX_AUDIO_FRAMES);
 
   // This API insists on having packets spoon-fed to it from a callback.
   // This structure exists only to pass our state.
   PassthroughUserData userData =
     { channels, (UInt32)aSample->Size(), aSample->Data() };
 
   // Decompressed audio buffer
-  AlignedAudioBuffer decoded(maxDecodedSamples);
-  if (!decoded) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  auto decoded = MakeUnique<AudioDataValue[]>(maxDecodedSamples);
 
   do {
     AudioBufferList decBuffer;
     decBuffer.mNumberBuffers = 1;
     decBuffer.mBuffers[0].mNumberChannels = channels;
     decBuffer.mBuffers[0].mDataByteSize =
       maxDecodedSamples * sizeof(AudioDataValue);
     decBuffer.mBuffers[0].mData = decoded.get();
@@ -271,35 +268,23 @@ AppleATDecoder::DecodeSample(MediaRawDat
   }
 
 #ifdef LOG_SAMPLE_DECODE
   LOG("pushed audio at time %lfs; duration %lfs\n",
       (double)aSample->mTime / USECS_PER_S,
       duration.ToSeconds());
 #endif
 
-  AudioSampleBuffer data(outputData.Elements(), outputData.Length());
-  if (!data.Data()) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-  if (mChannelLayout && !mAudioConverter) {
-    AudioConfig in(*mChannelLayout.get(), rate);
-    AudioConfig out(channels, rate);
-    mAudioConverter = MakeUnique<AudioConverter>(in, out);
-  }
-  if (mAudioConverter) {
-    MOZ_ASSERT(mAudioConverter->CanWorkInPlace());
-    mAudioConverter->Process(data);
-  }
-
+  auto data = MakeUnique<AudioDataValue[]>(outputData.Length());
+  PodCopy(data.get(), &outputData[0], outputData.Length());
   RefPtr<AudioData> audio = new AudioData(aSample->mOffset,
                                           aSample->mTime,
                                           duration.ToMicroseconds(),
                                           numFrames,
-                                          data.Forget(),
+                                          Move(data),
                                           channels,
                                           rate);
   mCallback->Output(audio);
   return NS_OK;
 }
 
 nsresult
 AppleATDecoder::GetInputAudioDescription(AudioStreamBasicDescription& aDesc,
@@ -369,146 +354,16 @@ AppleATDecoder::GetInputAudioDescription
     return NS_OK;
   }
 
   aDesc = formatList[itemIndex].mASBD;
 
   return NS_OK;
 }
 
-AudioConfig::Channel
-ConvertChannelLabel(AudioChannelLabel id)
-{
-  switch (id) {
-    case kAudioChannelLabel_Mono:
-      return AudioConfig::CHANNEL_MONO;
-    case kAudioChannelLabel_Left:
-      return AudioConfig::CHANNEL_LEFT;
-    case kAudioChannelLabel_Right:
-      return AudioConfig::CHANNEL_RIGHT;
-    case kAudioChannelLabel_Center:
-      return AudioConfig::CHANNEL_CENTER;
-    case kAudioChannelLabel_LFEScreen:
-      return AudioConfig::CHANNEL_LFE;
-    case kAudioChannelLabel_LeftSurround:
-      return AudioConfig::CHANNEL_LS;
-    case kAudioChannelLabel_RightSurround:
-      return AudioConfig::CHANNEL_RS;
-    case kAudioChannelLabel_CenterSurround:
-      return AudioConfig::CHANNEL_RCENTER;
-    case kAudioChannelLabel_RearSurroundLeft:
-      return AudioConfig::CHANNEL_RLS;
-    case kAudioChannelLabel_RearSurroundRight:
-      return AudioConfig::CHANNEL_RRS;
-    default:
-      return AudioConfig::CHANNEL_INVALID;
-  }
-}
-
-// Will set mChannelLayout if a channel layout could properly be identified
-// and is supported.
-nsresult
-AppleATDecoder::SetupChannelLayout()
-{
-  // Determine the channel layout.
-  UInt32 propertySize;
-  UInt32 size;
-  OSStatus status =
-    AudioConverterGetPropertyInfo(mConverter,
-                                  kAudioConverterOutputChannelLayout,
-                                  &propertySize, NULL);
-  if (status || !propertySize) {
-    LOG("Couldn't get channel layout property (%s)", FourCC2Str(status));
-    return NS_ERROR_FAILURE;
-  }
-
-  auto data = MakeUnique<uint8_t[]>(propertySize);
-  size = propertySize;
-  status =
-    AudioConverterGetProperty(mConverter, kAudioConverterInputChannelLayout,
-                              &size, data.get());
-  if (status || size != propertySize) {
-    LOG("Couldn't get channel layout property (%s)",
-        FourCC2Str(status));
-    return NS_ERROR_FAILURE;
-  }
-
-  AudioChannelLayout* layout =
-    reinterpret_cast<AudioChannelLayout*>(data.get());
-  AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
-
-  // if tag is kAudioChannelLayoutTag_UseChannelDescriptions then the structure
-  // directly contains the the channel layout mapping.
-  // If tag is kAudioChannelLayoutTag_UseChannelBitmap then the layout will
-  // be defined via the bitmap and can be retrieved using
-  // kAudioFormatProperty_ChannelLayoutForBitmap property.
-  // Otherwise the tag itself describes the layout.
-  if (tag != kAudioChannelLayoutTag_UseChannelDescriptions) {
-    AudioFormatPropertyID property =
-      tag == kAudioChannelLayoutTag_UseChannelBitmap
-        ? kAudioFormatProperty_ChannelLayoutForBitmap
-        : kAudioFormatProperty_ChannelLayoutForTag;
-
-    if (property == kAudioFormatProperty_ChannelLayoutForBitmap) {
-      status =
-        AudioFormatGetPropertyInfo(property,
-                                   sizeof(UInt32), &layout->mChannelBitmap,
-                                   &propertySize);
-    } else {
-      status =
-        AudioFormatGetPropertyInfo(property,
-                                   sizeof(AudioChannelLayoutTag), &tag,
-                                   &propertySize);
-    }
-    if (status || !propertySize) {
-      LOG("Couldn't get channel layout property info (%s:%s)",
-          FourCC2Str(property), FourCC2Str(status));
-      return NS_ERROR_FAILURE;
-    }
-    data = MakeUnique<uint8_t[]>(propertySize);
-    layout = reinterpret_cast<AudioChannelLayout*>(data.get());
-    size = propertySize;
-
-    if (property == kAudioFormatProperty_ChannelLayoutForBitmap) {
-      status = AudioFormatGetProperty(property,
-                                      sizeof(UInt32), &layout->mChannelBitmap,
-                                      &size, layout);
-    } else {
-      status = AudioFormatGetProperty(property,
-                                      sizeof(AudioChannelLayoutTag), &tag,
-                                      &size, layout);
-    }
-    if (status || size != propertySize) {
-      LOG("Couldn't get channel layout property (%s:%s)",
-          FourCC2Str(property), FourCC2Str(status));
-      return NS_ERROR_FAILURE;
-    }
-    // We have retrieved the channel layout from the tag or bitmap.
-    // We can now directly use the channel descriptions.
-    layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
-  }
-
-  if (layout->mNumberChannelDescriptions > MAX_AUDIO_CHANNELS ||
-      layout->mNumberChannelDescriptions != mOutputFormat.mChannelsPerFrame) {
-    LOG("Nonsensical channel layout or not matching the original channel number");
-    return NS_ERROR_FAILURE;
-  }
-
-  AudioConfig::Channel channels[MAX_AUDIO_CHANNELS];
-  for (uint32_t i = 0; i < layout->mNumberChannelDescriptions; i++) {
-    AudioChannelLabel id = layout->mChannelDescriptions[i].mChannelLabel;
-    AudioConfig::Channel channel = ConvertChannelLabel(id);
-    channels[i] = channel;
-  }
-  mChannelLayout =
-    MakeUnique<AudioConfig::ChannelLayout>(mOutputFormat.mChannelsPerFrame,
-                                           channels);
-  return NS_OK;
-}
-
 nsresult
 AppleATDecoder::SetupDecoder(MediaRawData* aSample)
 {
   if (mFormatID == kAudioFormatMPEG4AAC &&
       mConfig.mExtendedProfile == 2) {
     // Check for implicit SBR signalling if stream is AAC-LC
     // This will provide us with an updated magic cookie for use with
     // GetInputAudioDescription.
@@ -553,21 +408,16 @@ AppleATDecoder::SetupDecoder(MediaRawDat
         = mOutputFormat.mChannelsPerFrame * mOutputFormat.mBitsPerChannel / 8;
 
   OSStatus status = AudioConverterNew(&inputFormat, &mOutputFormat, &mConverter);
   if (status) {
     LOG("Error %d constructing AudioConverter", status);
     mConverter = nullptr;
     return NS_ERROR_FAILURE;
   }
-
-  if (NS_FAILED(SetupChannelLayout())) {
-    NS_WARNING("Couldn't retrieve channel layout, will use default layout");
-  }
-
   return NS_OK;
 }
 
 static void
 _MetadataCallback(void* aAppleATDecoder,
                   AudioFileStreamID aStream,
                   AudioFileStreamPropertyID aProperty,
                   UInt32* aFlags)
--- a/dom/media/platforms/apple/AppleATDecoder.h
+++ b/dom/media/platforms/apple/AppleATDecoder.h
@@ -7,17 +7,16 @@
 #ifndef mozilla_AppleATDecoder_h
 #define mozilla_AppleATDecoder_h
 
 #include <AudioToolbox/AudioToolbox.h>
 #include "PlatformDecoderModule.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "mozilla/Vector.h"
 #include "nsIThread.h"
-#include "AudioConverter.h"
 
 namespace mozilla {
 
 class FlushableTaskQueue;
 class MediaDataDecoderCallback;
 
 class AppleATDecoder : public MediaDataDecoder {
 public:
@@ -49,25 +48,22 @@ public:
 private:
   RefPtr<FlushableTaskQueue> mTaskQueue;
   MediaDataDecoderCallback* mCallback;
   AudioConverterRef mConverter;
   AudioStreamBasicDescription mOutputFormat;
   UInt32 mFormatID;
   AudioFileStreamID mStream;
   nsTArray<RefPtr<MediaRawData>> mQueuedSamples;
-  UniquePtr<AudioConfig::ChannelLayout> mChannelLayout;
-  UniquePtr<AudioConverter> mAudioConverter;
 
   void SubmitSample(MediaRawData* aSample);
   nsresult DecodeSample(MediaRawData* aSample);
   nsresult GetInputAudioDescription(AudioStreamBasicDescription& aDesc,
                                     const nsTArray<uint8_t>& aExtraData);
   // Setup AudioConverter once all information required has been gathered.
   // Will return NS_ERROR_NOT_INITIALIZED if more data is required.
   nsresult SetupDecoder(MediaRawData* aSample);
   nsresult GetImplicitAACMagicCookie(const MediaRawData* aSample);
-  nsresult SetupChannelLayout();
 };
 
 } // namespace mozilla
 
 #endif // mozilla_AppleATDecoder_h
--- a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
@@ -43,25 +43,22 @@ FFmpegAudioDecoder<LIBAV_VER>::InitCodec
   // isn't implemented.
   mCodecContext->thread_count = 1;
   // FFmpeg takes this as a suggestion for what format to use for audio samples.
   // LibAV 0.8 produces rubbish float interleaved samples, request 16 bits audio.
   mCodecContext->request_sample_fmt =
     (mLib->mVersion == 53) ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_FLT;
 }
 
-static AlignedAudioBuffer
+static UniquePtr<AudioDataValue[]>
 CopyAndPackAudio(AVFrame* aFrame, uint32_t aNumChannels, uint32_t aNumAFrames)
 {
   MOZ_ASSERT(aNumChannels <= MAX_CHANNELS);
 
-  AlignedAudioBuffer audio(aNumChannels * aNumAFrames);
-  if (!audio) {
-    return audio;
-  }
+  auto audio = MakeUnique<AudioDataValue[]>(aNumChannels * aNumAFrames);
 
   if (aFrame->format == AV_SAMPLE_FMT_FLT) {
     // Audio data already packed. No need to do anything other than copy it
     // into a buffer we own.
     memcpy(audio.get(), aFrame->data[0],
            aNumChannels * aNumAFrames * sizeof(AudioDataValue));
   } else if (aFrame->format == AV_SAMPLE_FMT_FLTP) {
     // Planar audio data. Pack it into something we can understand.
@@ -125,22 +122,22 @@ FFmpegAudioDecoder<LIBAV_VER>::DecodePac
       mCallback->Error();
       return;
     }
 
     if (decoded) {
       uint32_t numChannels = mCodecContext->channels;
       uint32_t samplingRate = mCodecContext->sample_rate;
 
-      AlignedAudioBuffer audio =
+      UniquePtr<AudioDataValue[]> audio =
         CopyAndPackAudio(mFrame, numChannels, mFrame->nb_samples);
 
       media::TimeUnit duration =
         FramesToTimeUnit(mFrame->nb_samples, samplingRate);
-      if (!audio || !duration.IsValid()) {
+      if (!duration.IsValid()) {
         NS_WARNING("Invalid count of accumulated audio samples");
         mCallback->Error();
         return;
       }
 
       RefPtr<AudioData> data = new AudioData(samplePosition,
                                              pts.ToMicroseconds(),
                                              duration.ToMicroseconds(),
--- a/dom/media/platforms/wmf/WMFAudioMFTManager.cpp
+++ b/dom/media/platforms/wmf/WMFAudioMFTManager.cpp
@@ -285,20 +285,17 @@ WMFAudioMFTManager::Output(int64_t aStre
   MOZ_ASSERT(numFrames >= 0);
   MOZ_ASSERT(numSamples >= 0);
   if (numFrames == 0) {
     // All data from this chunk stripped, loop back and try to output the next
     // frame, if possible.
     return S_OK;
   }
 
-  AlignedAudioBuffer audioData(numSamples);
-  if (!audioData) {
-    return E_OUTOFMEMORY;
-  }
+  auto audioData = MakeUnique<AudioDataValue[]>(numSamples);
 
   int16_t* pcm = (int16_t*)data;
   for (int32_t i = 0; i < numSamples; ++i) {
     audioData[i] = AudioSampleToFloat(pcm[i]);
   }
 
   buffer->Unlock();
 
--- a/dom/media/wave/WaveReader.cpp
+++ b/dom/media/wave/WaveReader.cpp
@@ -213,20 +213,17 @@ bool WaveReader::DecodeAudioData()
 
   MOZ_ASSERT(BLOCK_SIZE % 3 == 0);
   MOZ_ASSERT(BLOCK_SIZE % 2 == 0);
 
   static_assert(uint64_t(BLOCK_SIZE) < UINT_MAX /
                 sizeof(AudioDataValue) / MAX_CHANNELS,
                 "bufferSize calculation could overflow.");
   const size_t bufferSize = static_cast<size_t>(frames * mChannels);
-  AlignedAudioBuffer sampleBuffer(bufferSize);
-  if (!sampleBuffer) {
-    return false;
-  }
+  auto sampleBuffer = MakeUnique<AudioDataValue[]>(bufferSize);
 
   static_assert(uint64_t(BLOCK_SIZE) < UINT_MAX / sizeof(char),
                 "BLOCK_SIZE too large for enumerator.");
   auto dataBuffer = MakeUnique<char[]>(static_cast<size_t>(readSize));
 
   if (!ReadAll(dataBuffer.get(), readSize)) {
     return false;
   }