Backed out 15 changesets (bug 1195723) for various media test failures/unexpected-passes a=backout
authorWes Kocher <wkocher@mozilla.com>
Mon, 22 Aug 2016 10:07:25 -0700
changeset 310708 ecd29e0a263208d596a88e2fafa88d30ca558ca3
parent 310707 d15eeb67d8bff77fdbce4714f9a04f8dec63e576
child 310709 e6b665f320576b68febf5e054e9c5622a997f5e6
push id80949
push userryanvm@gmail.com
push dateTue, 23 Aug 2016 14:07:01 +0000
treeherdermozilla-inbound@12c339c60630 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1195723
milestone51.0a1
backs out2a3b10281c9c7fd450fa27bdfa11d60bc0e0133c
c3775a6225d853d4fea8818c90203a75fba10cea
ba0aeb71c6721973ccdd30e6ac434ce8705acbe8
894061e6037e11918514659f546bdb572604b113
4637f8be98bb89a1c46dc5890f56843e5336116f
c2664064fa550c3271ebeb5c78f2ca41e850cd4a
39908ea4c390bd0d231cd5e42740f9e52455bfc3
3fcb5682049ab166db4d7b7b9930e0b8aa365ba5
867d6507a3818869e867ad0a74e6e45585c95d38
c938ad9dd11cf2b6e46df21f63734299f59f47fa
7bdb9540b60f4b2ede18cfb56b078e73719e0434
a4f7a73c04faad80e517aadcf872c2529b91c72c
7f86beff4263beb66777dfe5f3927e749779d2d6
efb6bcf743e709692051043610c48832323bd4c3
04eceefa54c7229f8c3ccfa1206ecaebcd9cacf5
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 15 changesets (bug 1195723) for various media test failures/unexpected-passes a=backout Backed out changeset 2a3b10281c9c (bug 1195723) Backed out changeset c3775a6225d8 (bug 1195723) Backed out changeset ba0aeb71c672 (bug 1195723) Backed out changeset 894061e6037e (bug 1195723) Backed out changeset 4637f8be98bb (bug 1195723) Backed out changeset c2664064fa55 (bug 1195723) Backed out changeset 39908ea4c390 (bug 1195723) Backed out changeset 3fcb5682049a (bug 1195723) Backed out changeset 867d6507a381 (bug 1195723) Backed out changeset c938ad9dd11c (bug 1195723) Backed out changeset 7bdb9540b60f (bug 1195723) Backed out changeset a4f7a73c04fa (bug 1195723) Backed out changeset 7f86beff4263 (bug 1195723) Backed out changeset efb6bcf743e7 (bug 1195723) Backed out changeset 04eceefa54c7 (bug 1195723)
dom/media/ADTSDecoder.cpp
dom/media/ADTSDecoder.h
dom/media/DecoderTraits.cpp
dom/media/MediaPrefs.h
dom/media/flac/FlacDecoder.cpp
dom/media/flac/FlacDecoder.h
dom/media/flac/FlacDemuxer.cpp
dom/media/flac/FlacDemuxer.h
dom/media/flac/FlacFrameParser.cpp
dom/media/flac/FlacFrameParser.h
dom/media/flac/moz.build
dom/media/moz.build
dom/media/ogg/OggCodecState.cpp
dom/media/ogg/OggCodecState.h
dom/media/ogg/OggDecoder.cpp
dom/media/ogg/OggDecoder.h
dom/media/ogg/OggDemuxer.cpp
dom/media/ogg/OggDemuxer.h
dom/media/test/A4.ogv
dom/media/test/A4.ogv^headers^
dom/media/test/flac-noheader-s16.flac
dom/media/test/flac-noheader-s16.flac^headers^
dom/media/test/flac-s24.flac
dom/media/test/flac-s24.flac^headers^
dom/media/test/manifest.js
dom/media/test/mochitest.ini
media/libstagefright/binding/BitReader.cpp
media/libstagefright/binding/H264.cpp
media/libstagefright/binding/include/mp4_demuxer/BitReader.h
media/libstagefright/binding/include/mp4_demuxer/ByteReader.h
media/libstagefright/moz.build
modules/libpref/init/all.js
netwerk/mime/nsMimeTypes.h
toolkit/components/mediasniffer/nsMediaSniffer.cpp
--- a/dom/media/ADTSDecoder.cpp
+++ b/dom/media/ADTSDecoder.cpp
@@ -36,17 +36,16 @@ ADTSDecoder::IsEnabled()
   return platform->SupportsMimeType(NS_LITERAL_CSTRING("audio/mp4a-latm"),
                                     /* DecoderDoctorDiagnostics* */ nullptr);
 }
 
 /* static */ bool
 ADTSDecoder::CanHandleMediaType(const nsACString& aType,
                                 const nsAString& aCodecs)
 {
-  if (aType.EqualsASCII("audio/aac") || aType.EqualsASCII("audio/aacp") ||
-      aType.EqualsASCII("audio/x-aac")) {
+  if (aType.EqualsASCII("audio/aac") || aType.EqualsASCII("audio/aacp")) {
     return IsEnabled() && (aCodecs.IsEmpty() || aCodecs.EqualsASCII("aac"));
   }
 
   return false;
 }
 
 } // namespace mozilla
--- a/dom/media/ADTSDecoder.h
+++ b/dom/media/ADTSDecoder.h
@@ -13,17 +13,17 @@ namespace mozilla {
 
 class ADTSDecoder : public MediaDecoder {
 public:
   // MediaDecoder interface.
   explicit ADTSDecoder(MediaDecoderOwner* aOwner) : MediaDecoder(aOwner) {}
   MediaDecoder* Clone(MediaDecoderOwner* aOwner) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
-  // Returns true if the ADTS backend is pref'ed on, and we're running on a
+  // Returns true if the MP3 backend is pref'ed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsEnabled();
   static bool CanHandleMediaType(const nsACString& aType,
                                  const nsAString& aCodecs);
 };
 
 } // namespace mozilla
 
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -48,21 +48,17 @@
 
 #include "WaveDecoder.h"
 #include "WaveDemuxer.h"
 #include "WaveReader.h"
 
 #include "ADTSDecoder.h"
 #include "ADTSDemuxer.h"
 
-#include "FlacDecoder.h"
-#include "FlacDemuxer.h"
-
 #include "nsPluginHost.h"
-#include "MediaPrefs.h"
 
 namespace mozilla
 {
 
 template <class String>
 static bool
 CodecListContains(char const *const * aCodecs, const String& aCodec)
 {
@@ -90,27 +86,46 @@ IsRawType(const nsACString& aType)
   if (!MediaDecoder::IsRawEnabled()) {
     return false;
   }
 
   return CodecListContains(gRawTypes, aType);
 }
 #endif
 
-static bool
-IsOggSupportedType(const nsACString& aType,
-                    const nsAString& aCodecs = EmptyString())
-{
-  return OggDecoder::CanHandleMediaType(aType, aCodecs);
-}
+// See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
+// of Ogg media types and codec types
+static const char* const gOggTypes[4] = {
+  "video/ogg",
+  "audio/ogg",
+  "application/ogg",
+  nullptr
+};
+
+static char const *const gOggCodecs[3] = {
+  "vorbis",
+  "theora",
+  nullptr
+};
+
+static char const *const gOggCodecsWithOpus[4] = {
+  "vorbis",
+  "opus",
+  "theora",
+  nullptr
+};
 
 static bool
-IsOggTypeAndEnabled(const nsACString& aType)
+IsOggType(const nsACString& aType)
 {
-  return IsOggSupportedType(aType);
+  if (!MediaDecoder::IsOggEnabled()) {
+    return false;
+  }
+
+  return CodecListContains(gOggTypes, aType);
 }
 
 // See http://www.rfc-editor.org/rfc/rfc2361.txt for the definitions
 // of WAVE media types and codec types. However, the audio/vnd.wave
 // MIME type described there is not used.
 static const char* const gWaveTypes[5] = {
   "audio/x-wav",
   "audio/wav",
@@ -318,23 +333,16 @@ IsAACSupportedType(const nsACString& aTy
 
 static bool
 IsWAVSupportedType(const nsACString& aType,
                    const nsAString& aCodecs = EmptyString())
 {
   return WaveDecoder::CanHandleMediaType(aType, aCodecs);
 }
 
-static bool
-IsFlacSupportedType(const nsACString& aType,
-                   const nsAString& aCodecs = EmptyString())
-{
-  return FlacDecoder::CanHandleMediaType(aType, aCodecs);
-}
-
 /* static */
 bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType,
                                           DecoderDoctorDiagnostics* aDiagnostics)
 {
   if (IsWaveType(nsDependentCString(aMIMEType))) {
     // We should not return true for Wave types, since there are some
     // Wave codecs actually in use in the wild that we don't support, and
     // we should allow those to be handled by plugins or helper apps.
@@ -365,24 +373,18 @@ DecoderTraits::CanHandleCodecsType(const
                                    DecoderDoctorDiagnostics* aDiagnostics)
 {
   char const* const* codecList = nullptr;
 #ifdef MOZ_RAW
   if (IsRawType(nsDependentCString(aMIMEType))) {
     codecList = gRawCodecs;
   }
 #endif
-  if (IsOggTypeAndEnabled(nsDependentCString(aMIMEType))) {
-    if (IsOggSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
-      return CANPLAY_YES;
-    } else {
-      // We can only reach this position if a particular codec was requested,
-      // ogg is supported and working: the codec must be invalid.
-      return CANPLAY_NO;
-    }
+  if (IsOggType(nsDependentCString(aMIMEType))) {
+    codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs;
   }
   if (IsWaveType(nsDependentCString(aMIMEType))) {
     codecList = gWaveCodecs;
   }
 #if !defined(MOZ_OMX_WEBM_DECODER)
   if (IsWebMTypeAndEnabled(nsDependentCString(aMIMEType))) {
     if (IsWebMSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
       return CANPLAY_YES;
@@ -405,19 +407,16 @@ DecoderTraits::CanHandleCodecsType(const
   }
 #endif
   if (IsMP3SupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
     return CANPLAY_YES;
   }
   if (IsAACSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
     return CANPLAY_YES;
   }
-  if (IsFlacSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
-    return CANPLAY_YES;
-  }
 #ifdef MOZ_OMX_DECODER
   if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
     if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) {
       codecList = gMpegAudioCodecs;
 #ifdef MOZ_OMX_WEBM_DECODER
     } else if (nsDependentCString(aMIMEType).EqualsASCII("audio/webm") ||
                nsDependentCString(aMIMEType).EqualsASCII("video/webm")) {
       codecList = gOMXWebMCodecs;
@@ -481,17 +480,17 @@ DecoderTraits::CanHandleMediaType(const 
       return result;
     }
   }
 #ifdef MOZ_RAW
   if (IsRawType(nsDependentCString(aMIMEType))) {
     return CANPLAY_MAYBE;
   }
 #endif
-  if (IsOggTypeAndEnabled(nsDependentCString(aMIMEType))) {
+  if (IsOggType(nsDependentCString(aMIMEType))) {
     return CANPLAY_MAYBE;
   }
   if (IsWaveType(nsDependentCString(aMIMEType))) {
     return CANPLAY_MAYBE;
   }
   if (IsMP4TypeAndEnabled(nsDependentCString(aMIMEType), aDiagnostics)) {
     return CANPLAY_MAYBE;
   }
@@ -501,19 +500,16 @@ DecoderTraits::CanHandleMediaType(const 
   }
 #endif
   if (IsMP3SupportedType(nsDependentCString(aMIMEType))) {
     return CANPLAY_MAYBE;
   }
   if (IsAACSupportedType(nsDependentCString(aMIMEType))) {
     return CANPLAY_MAYBE;
   }
-  if (IsFlacSupportedType(nsDependentCString(aMIMEType))) {
-    return CANPLAY_MAYBE;
-  }
 #ifdef MOZ_OMX_DECODER
   if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
     return CANPLAY_MAYBE;
   }
 #endif
 #ifdef MOZ_DIRECTSHOW
   if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), nullptr)) {
     return CANPLAY_MAYBE;
@@ -553,28 +549,24 @@ InstantiateDecoder(const nsACString& aTy
     return decoder.forget();
   }
 #ifdef MOZ_RAW
   if (IsRawType(aType)) {
     decoder = new RawDecoder(aOwner);
     return decoder.forget();
   }
 #endif
-  if (IsOggSupportedType(aType)) {
+  if (IsOggType(aType)) {
     decoder = new OggDecoder(aOwner);
     return decoder.forget();
   }
   if (IsWaveType(aType)) {
     decoder = new WaveDecoder(aOwner);
     return decoder.forget();
   }
-  if (IsFlacSupportedType(aType)) {
-    decoder = new FlacDecoder(aOwner);
-    return decoder.forget();
-  }
 #ifdef MOZ_OMX_DECODER
   if (IsOmxSupportedType(aType)) {
     // we are discouraging Web and App developers from using those formats in
     // gB2GOnlyTypes, thus we only allow them to be played on WebApps.
     if (IsB2GSupportOnlyType(aType)) {
       dom::HTMLMediaElement* element = aOwner->GetMediaElement();
       if (!element) {
         return nullptr;
@@ -649,26 +641,23 @@ MediaDecoderReader* DecoderTraits::Creat
     decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource()));
   } else
   if (IsAACSupportedType(aType)) {
     decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource()));
   } else
   if (IsWAVSupportedType(aType)) {
     decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
   } else
-  if (IsFlacSupportedType(aType)) {
-    decoderReader = new MediaFormatReader(aDecoder, new FlacDemuxer(aDecoder->GetResource()));
-  } else
 #ifdef MOZ_RAW
   if (IsRawType(aType)) {
     decoderReader = new RawReader(aDecoder);
   } else
 #endif
-  if (IsOggSupportedType(aType)) {
-    decoderReader = MediaPrefs::OggFormatReader() ?
+  if (IsOggType(aType)) {
+    decoderReader = Preferences::GetBool("media.format-reader.ogg", true) ?
       static_cast<MediaDecoderReader*>(new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()))) :
       new OggReader(aDecoder);
   } else
   if (IsWaveType(aType)) {
     decoderReader = new WaveReader(aDecoder);
   } else
 #ifdef MOZ_OMX_DECODER
   if (IsOmxSupportedType(aType)) {
@@ -702,33 +691,32 @@ bool DecoderTraits::IsSupportedInVideoDo
   // not to, using either the legacy WMF specific pref, or the newer
   // catch-all pref.
   if (!Preferences::GetBool("media.windows-media-foundation.play-stand-alone", true) ||
       !Preferences::GetBool("media.play-stand-alone", true)) {
     return false;
   }
 
   return
-    IsOggSupportedType(aType) ||
+    IsOggType(aType) ||
 #ifdef MOZ_OMX_DECODER
     // We support the formats in gB2GOnlyTypes only inside WebApps on firefoxOS
     // but not in general web content. Ensure we dont create a VideoDocument
     // when accessing those format URLs directly.
     (IsOmxSupportedType(aType) &&
      !IsB2GSupportOnlyType(aType)) ||
 #endif
     IsWebMSupportedType(aType) ||
 #ifdef MOZ_ANDROID_OMX
     (MediaDecoder::IsAndroidMediaPluginEnabled() && IsAndroidMediaType(aType)) ||
 #endif
 #ifdef MOZ_FMP4
     IsMP4SupportedType(aType, /* DecoderDoctorDiagnostics* */ nullptr) ||
 #endif
     IsMP3SupportedType(aType) ||
     IsAACSupportedType(aType) ||
-    IsFlacSupportedType(aType) ||
 #ifdef MOZ_DIRECTSHOW
     IsDirectShowSupportedType(aType) ||
 #endif
     false;
 }
 
 } // namespace mozilla
--- a/dom/media/MediaPrefs.h
+++ b/dom/media/MediaPrefs.h
@@ -142,23 +142,16 @@ private:
   DECL_MEDIA_PREF("media.webspeech.test.fake_fsm_events",     WebSpeechFakeFSMEvents, bool, false);
   DECL_MEDIA_PREF(TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE,   WebSpeechFakeRecognitionService, bool, false);
   DECL_MEDIA_PREF("media.webspeech.recognition.enable",       WebSpeechRecognitionEnabled, bool, false);
   DECL_MEDIA_PREF("media.webspeech.recognition.force_enable", WebSpeechRecognitionForceEnabled, bool, false);
 
   DECL_MEDIA_PREF("media.num-decode-threads",                 MediaThreadPoolDefaultCount, uint32_t, 4);
   DECL_MEDIA_PREF("media.decoder.limit",                      MediaDecoderLimit, int32_t, MediaDecoderLimitDefault());
 
-  // Ogg
-  DECL_MEDIA_PREF("media.ogg.enabled",                        OggEnabled, bool, true);
-  DECL_MEDIA_PREF("media.format-reader.ogg",                  OggFormatReader, bool, true);
-  // Flac
-  DECL_MEDIA_PREF("media.ogg.flac.enabled",                   FlacInOgg, bool, false);
-  DECL_MEDIA_PREF("media.flac.enabled",                       FlacEnabled, bool, true);
-
 public:
   // Manage the singleton:
   static MediaPrefs& GetSingleton();
   static bool SingletonExists();
 
 private:
   template<class T> friend class StaticAutoPtr;
   static StaticAutoPtr<MediaPrefs> sInstance;
deleted file mode 100644
--- a/dom/media/flac/FlacDecoder.cpp
+++ /dev/null
@@ -1,52 +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 "FlacDecoder.h"
-#include "FlacDemuxer.h"
-#include "MediaDecoderStateMachine.h"
-#include "MediaFormatReader.h"
-#include "MediaPrefs.h"
-
-namespace mozilla {
-
-MediaDecoder*
-FlacDecoder::Clone(MediaDecoderOwner* aOwner)
-{
-  if (!IsEnabled())
-    return nullptr;
-
-  return new FlacDecoder(aOwner);
-}
-
-MediaDecoderStateMachine*
-FlacDecoder::CreateStateMachine()
-{
-  RefPtr<MediaDecoderReader> reader =
-      new MediaFormatReader(this, new FlacDemuxer(GetResource()));
-  return new MediaDecoderStateMachine(this, reader);
-}
-
-/* static */ bool
-FlacDecoder::IsEnabled()
-{
-#ifdef MOZ_FFVPX
-  return MediaPrefs::FlacEnabled();
-#else
-  // Until bug 1295886 is fixed.
-  return false;
-#endif
-}
-
-/* static */ bool
-FlacDecoder::CanHandleMediaType(const nsACString& aType,
-                                const nsAString& aCodecs)
-{
-  return IsEnabled() &&
-    (aType.EqualsASCII("audio/flac") || aType.EqualsASCII("audio/x-flac") ||
-     aType.EqualsASCII("application/x-flac"));
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/dom/media/flac/FlacDecoder.h
+++ /dev/null
@@ -1,30 +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/. */
-
-#ifndef FLAC_DECODER_H_
-#define FLAC_DECODER_H_
-
-#include "MediaDecoder.h"
-
-namespace mozilla {
-
-class FlacDecoder : public MediaDecoder {
-public:
-  // MediaDecoder interface.
-  explicit FlacDecoder(MediaDecoderOwner* aOwner) : MediaDecoder(aOwner) {}
-  MediaDecoder* Clone(MediaDecoderOwner* aOwner) override;
-  MediaDecoderStateMachine* CreateStateMachine() override;
-
-  // Returns true if the Flac backend is pref'ed on, and we're running on a
-  // platform that is likely to have decoders for the format.
-  static bool IsEnabled();
-  static bool CanHandleMediaType(const nsACString& aType,
-                                 const nsAString& aCodecs);
-};
-
-} // namespace mozilla
-
-#endif // !FLAC_DECODER_H_
deleted file mode 100644
--- a/dom/media/flac/FlacDemuxer.cpp
+++ /dev/null
@@ -1,1074 +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 "FlacDemuxer.h"
-
-#include "mozilla/Maybe.h"
-#include "mp4_demuxer/BitReader.h"
-#include "nsAutoPtr.h"
-#include "prenv.h"
-#include "FlacFrameParser.h"
-#include "VideoUtils.h"
-#include "TimeUnits.h"
-
-#ifdef PR_LOGGING
-extern mozilla::LazyLogModule gMediaDemuxerLog;
-#define LOG(msg, ...) \
-  MOZ_LOG(gMediaDemuxerLog, LogLevel::Debug, ("FlacDemuxer " msg, ##__VA_ARGS__))
-#define LOGV(msg, ...) \
-  MOZ_LOG(gMediaDemuxerLog, LogLevel::Verbose, ("FlacDemuxer " msg, ##__VA_ARGS__))
-#else
-#define LOG(msg, ...)  do {} while (false)
-#define LOGV(msg, ...) do {} while (false)
-#endif
-
-using namespace mozilla::media;
-
-namespace mozilla {
-namespace flac {
-
-// flac::FrameHeader - Holds the flac frame header and its parsing
-// state.
-
-#define FLAC_MAX_CHANNELS           8
-#define FLAC_MIN_BLOCKSIZE         16
-#define FLAC_MAX_BLOCKSIZE      65535
-#define FLAC_MIN_FRAME_SIZE        11
-#define FLAC_MAX_FRAME_HEADER_SIZE 16
-#define FLAC_MAX_FRAME_SIZE (FLAC_MAX_FRAME_HEADER_SIZE \
-                             +FLAC_MAX_BLOCKSIZE*FLAC_MAX_CHANNELS*3)
-
-class FrameHeader {
-public:
-  const AudioInfo& Info() const { return mInfo; }
-
-  uint32_t Size() const { return mSize; }
-
-  bool IsValid() const { return mValid; }
-
-  // Return the index (in samples) from the beginning of the track.
-  int64_t Index() const { return mIndex; }
-
-  // Parse the current packet and check that it made a valid flac frame header.
-  // From https://xiph.org/flac/format.html#frame_header
-  // A valid header is one that can be decoded without error and that has a
-  // valid CRC.
-  // aPacket must points to a buffer that is at least FLAC_MAX_FRAME_HEADER_SIZE
-  // bytes.
-  bool Parse(const uint8_t* aPacket)
-  {
-    mp4_demuxer::BitReader br(aPacket, FLAC_MAX_FRAME_HEADER_SIZE);
-
-    // Frame sync code.
-    if ((br.ReadBits(15) & 0x7fff) != 0x7ffc) {
-      return false;
-    }
-
-    // Variable block size stream code.
-    mVariableBlockSize = br.ReadBit();
-
-    // Block size and sample rate codes.
-    int bs_code = br.ReadBits(4);
-    int sr_code = br.ReadBits(4);
-
-    // Channels and decorrelation.
-    int ch_mode = br.ReadBits(4);
-    if (ch_mode < FLAC_MAX_CHANNELS) {
-      mInfo.mChannels = ch_mode + 1;
-    } else if (ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {
-      // This is a special flac channels, we can't handle those yet. Treat it
-      // as stereo.
-      mInfo.mChannels = 2;
-    } else {
-      // invalid channel mode
-      return false;
-    }
-
-    // Bits per sample.
-    int bps_code = br.ReadBits(3);
-    if (bps_code == 3 || bps_code == 7) {
-      // Invalid sample size code.
-      return false;
-    }
-    mInfo.mBitDepth = FlacSampleSizeTable[bps_code];
-
-    // Reserved bit, most be 1.
-    if (br.ReadBit()) {
-      // Broken stream, invalid padding.
-      return false;
-    }
-
-    // Sample or frame count.
-    int64_t frame_or_sample_num = br.ReadUTF8();
-    if (frame_or_sample_num < 0) {
-      // Sample/frame number invalid.
-      return false;
-    }
-
-    // Blocksize
-    if (bs_code == 0) {
-      // reserved blocksize code
-      return false;
-    } else if (bs_code == 6) {
-      mBlocksize = br.ReadBits(8) + 1;
-    } else if (bs_code == 7) {
-      mBlocksize = br.ReadBits(16) + 1;
-    } else {
-      mBlocksize = FlacBlocksizeTable[bs_code];
-    }
-
-    // The sample index is either:
-    // 1- coded sample number if blocksize is variable or
-    // 2- coded frame number if blocksize is known.
-    // A frame is made of Blocksize sample.
-    mIndex = mVariableBlockSize
-      ? frame_or_sample_num
-      : frame_or_sample_num * mBlocksize;
-
-    // Sample rate.
-    if (sr_code < 12) {
-      mInfo.mRate = FlacSampleRateTable[sr_code];
-    } else if (sr_code == 12) {
-      mInfo.mRate = br.ReadBits(8) * 1000;
-    } else if (sr_code == 13) {
-      mInfo.mRate = br.ReadBits(16);
-    } else if (sr_code == 14) {
-      mInfo.mRate = br.ReadBits(16) * 10;
-    } else {
-      // Illegal sample rate code.
-      return false;
-    }
-
-    // Header CRC-8 check.
-    uint8_t crc = 0;
-    for (uint32_t i = 0; i < br.BitCount() / 8; i++) {
-      crc = CRC8Table[crc ^ aPacket[i]];
-    }
-    mValid = crc == br.ReadBits(8);
-    mSize = br.BitCount() / 8;
-
-    if (mValid) {
-      // Set the mimetype to make it a valid AudioInfo.
-      mInfo.mMimeType = "audio/flac";
-    }
-
-    return mValid;
-  }
-
-private:
-  friend class Frame;
-  enum {
-    FLAC_CHMODE_INDEPENDENT = 0,
-    FLAC_CHMODE_LEFT_SIDE,
-    FLAC_CHMODE_RIGHT_SIDE,
-    FLAC_CHMODE_MID_SIDE,
-  };
-  AudioInfo mInfo;
-  // Index in samples from start;
-  int64_t mIndex = 0;
-  bool mVariableBlockSize = false;
-  uint32_t mBlocksize = 0;;
-  uint32_t mSize = 0;
-  bool mValid = false;
-
-  static const int FlacSampleRateTable[16];
-  static const int32_t FlacBlocksizeTable[16];
-  static const uint8_t FlacSampleSizeTable[8];
-  static const uint8_t CRC8Table[256];
-};
-
-const int FrameHeader::FlacSampleRateTable[16] =
-{ 0,
-  88200, 176400, 192000,
-  8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000,
-  0, 0, 0, 0
-};
-
-const int32_t FrameHeader::FlacBlocksizeTable[16] =
-{
-  0     , 192   , 576<<0, 576<<1, 576<<2, 576<<3,      0,      0,
-  256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7
-};
-
-const uint8_t FrameHeader::FlacSampleSizeTable[8] = { 0, 8, 12, 0, 16, 20, 24, 0 };
-
-const uint8_t FrameHeader::CRC8Table[256] =
-{
-  0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
-  0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
-  0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
-  0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
-  0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
-  0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
-  0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
-  0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
-  0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
-  0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
-  0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
-  0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
-  0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
-  0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
-  0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
-  0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
-  0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
-  0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
-  0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
-  0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
-  0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
-  0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
-  0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
-  0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
-  0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
-  0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
-  0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
-  0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
-  0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
-  0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
-  0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
-  0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
-};
-
-// flac::Frame - Frame meta container used to parse and hold a frame
-// header and side info.
-class Frame {
-public:
-
-  // The FLAC signature is made of 14 bits set to 1; however the 15th bit is
-  // mandatorily set to 0, so we need to find either of 0xfffc or 0xfffd 2-bytes
-  // signature. We first use a bitmask to see if 0xfc or 0xfd is present. And if
-  // so we check for the whole signature.
-  // aData must be pointing to a buffer at least
-  // aLength + FLAC_MAX_FRAME_HEADER_SIZE bytes.
-  int64_t FindNext(const uint8_t* aData, const uint32_t aLength)
-  {
-    uint32_t modOffset = aLength % 4;
-    uint32_t i, j;
-
-    for (i = 0; i < modOffset; i++) {
-      if ((BigEndian::readUint16(aData + i) & 0xfffe) == 0xfff8) {
-        if (mHeader.Parse(aData + i)) {
-          return i;
-        }
-      }
-    }
-
-    for (; i < aLength; i += 4) {
-      uint32_t x = BigEndian::readUint32(aData + i);
-      if (((x & ~(x + 0x01010101)) & 0x80808080)) {
-        for (j = 0; j < 4; j++) {
-          if ((BigEndian::readUint16(aData + i + j) & 0xfffe) == 0xfff8) {
-            if (mHeader.Parse(aData + i + j)) {
-              return i + j;
-            }
-          }
-        }
-      }
-    }
-    return -1;
-  }
-
-  // Find the next frame start in the current resource.
-  // On exit return true, offset is set and resource points to the frame found.
-  bool FindNext(MediaResourceIndex& aResource)
-  {
-    static const int BUFFER_SIZE = 4096;
-
-    Reset();
-
-    nsTArray<char> buffer;
-    int64_t originalOffset = aResource.Tell();
-    int64_t offset = originalOffset;
-    uint32_t innerOffset = 0;
-
-    do {
-      uint32_t read = 0;
-      buffer.SetLength(BUFFER_SIZE + innerOffset);
-      nsresult rv =
-        aResource.Read(buffer.Elements() + innerOffset, BUFFER_SIZE, &read);
-      if (NS_FAILED(rv)) {
-        return false;
-      }
-
-      if (read < FLAC_MAX_FRAME_HEADER_SIZE) {
-        // Assume that we can't have a valid frame in such small content, we
-        // must have reached EOS.
-        // So we're done.
-        mEOS = true;
-        return false;
-      }
-
-      const size_t bufSize = read + innerOffset - FLAC_MAX_FRAME_HEADER_SIZE;
-      int64_t foundOffset =
-        FindNext(reinterpret_cast<uint8_t*>(buffer.Elements()), bufSize);
-
-      if (foundOffset >= 0) {
-        SetOffset(aResource, foundOffset + offset);
-        return true;
-      }
-
-      // Scan the next block;
-      offset += bufSize;
-      buffer.RemoveElementsAt(0, bufSize);
-      innerOffset = buffer.Length();
-    } while (offset - originalOffset < FLAC_MAX_FRAME_SIZE);
-
-    return false;
-  }
-
-  int64_t Offset() const { return mOffset; }
-
-  const AudioInfo& Info() const { return Header().Info(); }
-
-  void SetEndOffset(int64_t aOffset) { mSize = aOffset - mOffset; }
-
-  void SetEndTime(int64_t aIndex)
-  {
-    if (aIndex > Header().mIndex) {
-      mDuration = aIndex - Header().mIndex;
-    }
-  }
-
-  uint32_t Size() const { return mSize; }
-
-  TimeUnit Time() const
-  {
-    if (!IsValid()) {
-      return TimeUnit::Invalid();
-    }
-    MOZ_ASSERT(Header().Info().mRate, "Invalid Frame. Need Header");
-    return FramesToTimeUnit(Header().mIndex, Header().Info().mRate);
-  }
-
-  TimeUnit Duration() const
-  {
-    if (!IsValid()) {
-      return TimeUnit();
-    }
-    MOZ_ASSERT(Header().Info().mRate, "Invalid Frame. Need Header");
-    return FramesToTimeUnit(mDuration, Header().Info().mRate);
-  }
-
-  // Returns the parsed frame header.
-  const FrameHeader& Header() const { return mHeader; }
-
-  bool IsValid() const { return mHeader.IsValid(); }
-
-  bool EOS() const { return mEOS; }
-
-  void SetRate(uint32_t aRate) { mHeader.mInfo.mRate = aRate; };
-
-  void SetBitDepth(uint32_t aBitDepth) { mHeader.mInfo.mBitDepth = aBitDepth; }
-
-  void SetInvalid() { mHeader.mValid = false; }
-
-  // Resets the frame header and data.
-  void Reset() { *this = Frame(); }
-
-private:
-  void SetOffset(MediaResourceIndex& aResource, int64_t aOffset)
-  {
-    mOffset = aOffset;
-    aResource.Seek(SEEK_SET, mOffset);
-  }
-
-  // The offset to the start of the header.
-  int64_t mOffset = 0;
-  uint32_t mSize = 0;
-  uint32_t mDuration = 0;
-  bool mEOS = false;
-
-  // The currently parsed frame header.
-  FrameHeader mHeader;
-
-};
-
-class FrameParser {
-public:
-
-  // Returns the currently parsed frame. Reset via EndFrameSession.
-  const Frame& CurrentFrame() const { return mFrame; }
-
-  // Returns the first parsed frame.
-  const Frame& FirstFrame() const { return mFirstFrame; }
-
-  // Clear the last parsed frame to allow for next frame parsing
-  void EndFrameSession()
-  {
-    mNextFrame.Reset();
-    mFrame.Reset();
-  }
-
-  // Attempt to find the next frame.
-  bool FindNextFrame(MediaResourceIndex& aResource)
-  {
-    mFrame = mNextFrame;
-    if (GetNextFrame(aResource)) {
-      if (!mFrame.IsValid()) {
-        mFrame = mNextFrame;
-        // We need two frames to be able to start playing (or have reached EOS).
-        GetNextFrame(aResource);
-      }
-    }
-
-    if (mFrame.IsValid()) {
-      if (mNextFrame.EOS()) {
-        mFrame.SetEndOffset(aResource.Tell());
-      } else if (mNextFrame.IsValid()) {
-        mFrame.SetEndOffset(mNextFrame.Offset());
-        mFrame.SetEndTime(mNextFrame.Header().Index());
-      }
-    }
-
-    if (!mFirstFrame.IsValid()) {
-      mFirstFrame = mFrame;
-    }
-    return mFrame.IsValid();
-  }
-
-  // Convenience methods to external FlacFrameParser ones.
-  bool IsHeaderBlock(const uint8_t* aPacket, size_t aLength) const
-  {
-    return mParser.IsHeaderBlock(aPacket, aLength);
-  }
-
-  uint32_t HeaderBlockLength(const uint8_t* aPacket) const
-  {
-    return mParser.HeaderBlockLength(aPacket);
-  }
-
-  bool DecodeHeaderBlock(const uint8_t* aPacket, size_t aLength)
-  {
-    return mParser.DecodeHeaderBlock(aPacket, aLength);
-  }
-
-  bool HasFullMetadata() const { return mParser.HasFullMetadata(); }
-
-  AudioInfo Info() const { return mParser.mInfo; }
-
-  // Return a hash table with tag metadata.
-  MetadataTags* GetTags() const { return mParser.GetTags(); }
-
-private:
-  bool GetNextFrame(MediaResourceIndex& aResource)
-  {
-    while (mNextFrame.FindNext(aResource)) {
-      // Move our offset slightly, so that we don't find the same frame at the
-      // next FindNext call.
-      aResource.Seek(SEEK_CUR, mNextFrame.Header().Size());
-      if (mFrame.IsValid()
-          && mNextFrame.Offset() - mFrame.Offset() < FLAC_MAX_FRAME_SIZE
-          && !CheckCRC16AtOffset(mFrame.Offset(),
-                                 mNextFrame.Offset(),
-                                 aResource)) {
-        // The frame doesn't match its CRC or would be too far, skip it..
-        continue;
-      }
-      CheckFrameData();
-      break;
-    }
-    return mNextFrame.IsValid();
-  }
-
-  bool CheckFrameData()
-  {
-    if (mNextFrame.Header().Info().mRate == 0
-        || mNextFrame.Header().Info().mBitDepth == 0) {
-      if (!Info().IsValid()) {
-        // We can only use the STREAMINFO data if we have one.
-        mNextFrame.SetInvalid();
-      } else {
-        if (mNextFrame.Header().Info().mRate == 0) {
-          mNextFrame.SetRate(Info().mRate);
-        }
-        if (mNextFrame.Header().Info().mBitDepth == 0) {
-          mNextFrame.SetBitDepth(Info().mBitDepth);
-        }
-      }
-    }
-    return mNextFrame.IsValid();
-  }
-
-  bool CheckCRC16AtOffset(int64_t aStart, int64_t aEnd,
-                          MediaResourceIndex& aResource) const
-  {
-    int64_t size = aEnd - aStart;
-    if (size <= 0) {
-      return false;
-    }
-    UniquePtr<char[]> buffer(new char[size]);
-    uint32_t read = 0;
-    if (NS_FAILED(aResource.ReadAt(aStart, buffer.get(),
-                                   size, &read))
-        || read != size) {
-      NS_WARNING("Couldn't read frame content");
-      return false;
-    }
-
-    uint16_t crc = 0;
-    uint8_t* buf = reinterpret_cast<uint8_t*>(buffer.get());
-    const uint8_t *end = buf + size;
-    while (buf < end) {
-      crc = CRC16Table[((uint8_t)crc) ^ *buf++] ^ (crc >> 8);
-    }
-    return !crc;
-  }
-
-  const uint16_t CRC16Table[256] =
-  {
-    0x0000, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180,
-    0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200,
-    0x6380, 0x6600, 0x6C00, 0x6980, 0x7800, 0x7D80, 0x7780, 0x7200,
-    0x5000, 0x5580, 0x5F80, 0x5A00, 0x4B80, 0x4E00, 0x4400, 0x4180,
-    0xC380, 0xC600, 0xCC00, 0xC980, 0xD800, 0xDD80, 0xD780, 0xD200,
-    0xF000, 0xF580, 0xFF80, 0xFA00, 0xEB80, 0xEE00, 0xE400, 0xE180,
-    0xA000, 0xA580, 0xAF80, 0xAA00, 0xBB80, 0xBE00, 0xB400, 0xB180,
-    0x9380, 0x9600, 0x9C00, 0x9980, 0x8800, 0x8D80, 0x8780, 0x8200,
-    0x8381, 0x8601, 0x8C01, 0x8981, 0x9801, 0x9D81, 0x9781, 0x9201,
-    0xB001, 0xB581, 0xBF81, 0xBA01, 0xAB81, 0xAE01, 0xA401, 0xA181,
-    0xE001, 0xE581, 0xEF81, 0xEA01, 0xFB81, 0xFE01, 0xF401, 0xF181,
-    0xD381, 0xD601, 0xDC01, 0xD981, 0xC801, 0xCD81, 0xC781, 0xC201,
-    0x4001, 0x4581, 0x4F81, 0x4A01, 0x5B81, 0x5E01, 0x5401, 0x5181,
-    0x7381, 0x7601, 0x7C01, 0x7981, 0x6801, 0x6D81, 0x6781, 0x6201,
-    0x2381, 0x2601, 0x2C01, 0x2981, 0x3801, 0x3D81, 0x3781, 0x3201,
-    0x1001, 0x1581, 0x1F81, 0x1A01, 0x0B81, 0x0E01, 0x0401, 0x0181,
-    0x0383, 0x0603, 0x0C03, 0x0983, 0x1803, 0x1D83, 0x1783, 0x1203,
-    0x3003, 0x3583, 0x3F83, 0x3A03, 0x2B83, 0x2E03, 0x2403, 0x2183,
-    0x6003, 0x6583, 0x6F83, 0x6A03, 0x7B83, 0x7E03, 0x7403, 0x7183,
-    0x5383, 0x5603, 0x5C03, 0x5983, 0x4803, 0x4D83, 0x4783, 0x4203,
-    0xC003, 0xC583, 0xCF83, 0xCA03, 0xDB83, 0xDE03, 0xD403, 0xD183,
-    0xF383, 0xF603, 0xFC03, 0xF983, 0xE803, 0xED83, 0xE783, 0xE203,
-    0xA383, 0xA603, 0xAC03, 0xA983, 0xB803, 0xBD83, 0xB783, 0xB203,
-    0x9003, 0x9583, 0x9F83, 0x9A03, 0x8B83, 0x8E03, 0x8403, 0x8183,
-    0x8002, 0x8582, 0x8F82, 0x8A02, 0x9B82, 0x9E02, 0x9402, 0x9182,
-    0xB382, 0xB602, 0xBC02, 0xB982, 0xA802, 0xAD82, 0xA782, 0xA202,
-    0xE382, 0xE602, 0xEC02, 0xE982, 0xF802, 0xFD82, 0xF782, 0xF202,
-    0xD002, 0xD582, 0xDF82, 0xDA02, 0xCB82, 0xCE02, 0xC402, 0xC182,
-    0x4382, 0x4602, 0x4C02, 0x4982, 0x5802, 0x5D82, 0x5782, 0x5202,
-    0x7002, 0x7582, 0x7F82, 0x7A02, 0x6B82, 0x6E02, 0x6402, 0x6182,
-    0x2002, 0x2582, 0x2F82, 0x2A02, 0x3B82, 0x3E02, 0x3402, 0x3182,
-    0x1382, 0x1602, 0x1C02, 0x1982, 0x0802, 0x0D82, 0x0782, 0x0202,
-  };
-
-  FlacFrameParser mParser;
-  // We keep the first parsed frame around for static info access
-  // and the currently parsed frame.
-  Frame mFirstFrame;
-  Frame mNextFrame;
-  Frame mFrame;
-};
-
-} // namespace flac
-
-// FlacDemuxer
-
-FlacDemuxer::FlacDemuxer(MediaResource* aSource)
-  : mSource(aSource)
-{}
-
-bool
-FlacDemuxer::InitInternal()
-{
-  if (!mTrackDemuxer) {
-    mTrackDemuxer = new FlacTrackDemuxer(mSource);
-  }
-  return mTrackDemuxer->Init();
-}
-
-RefPtr<FlacDemuxer::InitPromise>
-FlacDemuxer::Init()
-{
-  if (!InitInternal()) {
-    LOG("Init() failure: waiting for data");
-
-    return InitPromise::CreateAndReject(
-      DemuxerFailureReason::DEMUXER_ERROR, __func__);
-  }
-
-  LOG("Init() successful");
-  return InitPromise::CreateAndResolve(NS_OK, __func__);
-}
-
-bool
-FlacDemuxer::HasTrackType(TrackInfo::TrackType aType) const
-{
-  return aType == TrackInfo::kAudioTrack;
-}
-
-uint32_t
-FlacDemuxer::GetNumberTracks(TrackInfo::TrackType aType) const
-{
-  return (aType == TrackInfo::kAudioTrack) ? 1 : 0;
-}
-
-already_AddRefed<MediaTrackDemuxer>
-FlacDemuxer::GetTrackDemuxer(TrackInfo::TrackType aType, uint32_t aTrackNumber)
-{
-  if (!mTrackDemuxer) {
-    return nullptr;
-  }
-
-  return RefPtr<FlacTrackDemuxer>(mTrackDemuxer).forget();
-}
-
-bool
-FlacDemuxer::IsSeekable() const
-{
-  return mTrackDemuxer && mTrackDemuxer->IsSeekable();
-}
-
-// FlacTrackDemuxer
-FlacTrackDemuxer::FlacTrackDemuxer(MediaResource* aSource)
-  : mSource(aSource)
-  , mParser(new flac::FrameParser())
-  , mTotalFrameLen(0)
-{
-  Reset();
-}
-
-FlacTrackDemuxer::~FlacTrackDemuxer()
-{
-}
-
-bool
-FlacTrackDemuxer::Init()
-{
-  static const int BUFFER_SIZE = 4096;
-
-  // First check if we have a valid Flac start.
-  char buffer[BUFFER_SIZE];
-  const uint8_t* ubuffer = reinterpret_cast<uint8_t*>(buffer); // only needed due to type constraints of ReadAt.
-  int64_t offset = 0;
-
-  do {
-    uint32_t read = 0;
-    nsresult ret = mSource.ReadAt(offset, buffer, BUFFER_SIZE, &read);
-    if (NS_FAILED(ret) || read < BUFFER_SIZE) {
-      // Assume that if we can't read that many bytes while parsing the header,
-      // that something is wrong.
-      return false;
-    }
-    if (!mParser->IsHeaderBlock(ubuffer, BUFFER_SIZE)) {
-      // Not a header and we haven't reached the end of the metadata blocks.
-      // Will fall back to using the frames header instead.
-      break;
-    }
-    uint32_t sizeHeader = mParser->HeaderBlockLength(ubuffer);
-    RefPtr<MediaByteBuffer> block =
-      mSource.MediaReadAt(offset, sizeHeader);
-    if (!block || block->Length() != sizeHeader) {
-      break;
-    }
-    if (!mParser->DecodeHeaderBlock(block->Elements(), sizeHeader)) {
-      break;
-    }
-    offset += sizeHeader;
-  } while (!mParser->HasFullMetadata());
-
-  // First flac frame is found after the metadata.
-  // Can seek there immediately to avoid reparsing it all.
-  mSource.Seek(SEEK_SET, offset);
-
-  // Find the first frame to fully initialise our parser.
-  if (mParser->FindNextFrame(mSource)) {
-    // Ensure that the next frame returned will be the first.
-    mSource.Seek(SEEK_SET, mParser->FirstFrame().Offset());
-    mParser->EndFrameSession();
-  } else if (!mParser->Info().IsValid()) {
-    // We must find at least a frame to determine the metadata.
-    // We can't play this stream.
-    return false;
-  }
-
-  if (!mParser->Info().IsValid() || !mParser->Info().mDuration) {
-    // Check if we can look at the last frame for the end time to determine the
-    // duration when we don't have any.
-    TimeAtEnd();
-  }
-
-  return true;
-}
-
-UniquePtr<TrackInfo>
-FlacTrackDemuxer::GetInfo() const
-{
-  if (mParser->Info().IsValid()) {
-    // We have a proper metadata header.
-    UniquePtr<TrackInfo> info = mParser->Info().Clone();
-    nsAutoPtr<MetadataTags> tags(mParser->GetTags());
-    if (tags) {
-      for (auto iter = tags->Iter(); !iter.Done(); iter.Next()) {
-        info->mTags.AppendElement(MetadataTag(iter.Key(), iter.Data()));
-      }
-    }
-    return info;
-  } else if (mParser->FirstFrame().Info().IsValid()) {
-    // Use the first frame header.
-    UniquePtr<TrackInfo> info = mParser->FirstFrame().Info().Clone();
-    info->mDuration = Duration().ToMicroseconds();
-    return info;
-  }
-  return nullptr;
-}
-
-bool
-FlacTrackDemuxer::IsSeekable() const
-{
-  // For now we only allow seeking if a STREAMINFO block was found and with
-  // a known number of samples (duration is set).
-  return mParser->Info().IsValid() && mParser->Info().mDuration;
-}
-
-RefPtr<FlacTrackDemuxer::SeekPromise>
-FlacTrackDemuxer::Seek(TimeUnit aTime)
-{
-  // Efficiently seek to the position.
-  FastSeek(aTime);
-  // Correct seek position by scanning the next frames.
-  const TimeUnit seekTime = ScanUntil(aTime);
-
-  return SeekPromise::CreateAndResolve(seekTime, __func__);
-}
-
-TimeUnit
-FlacTrackDemuxer::FastSeek(const TimeUnit& aTime)
-{
-  LOG("FastSeek(%f) avgFrameLen=%f mParsedFramesDuration=%f offset=%lld",
-      aTime.ToSeconds(), AverageFrameLength(),
-      mParsedFramesDuration.ToSeconds(), GetResourceOffset());
-
-  // Invalidate current frames in the parser.
-  mParser->EndFrameSession();
-
-  if (!mParser->FirstFrame().IsValid()) {
-    // Something wrong, and there's nothing to seek to anyway, so we can
-    // do whatever here.
-    mSource.Seek(SEEK_SET, 0);
-    return TimeUnit();
-  }
-
-  if (aTime <= mParser->FirstFrame().Time()) {
-    // We're attempting to seek prior the first frame, return the first frame.
-    mSource.Seek(SEEK_SET, mParser->FirstFrame().Offset());
-    return mParser->FirstFrame().Time();
-  }
-
-  // We look for the seek position using a bisection search, starting where the
-  // estimated position might be using the average frame length.
-  // Typically, with flac such approximation is typically useless.
-
-  // Estimate where the position might be.
-  int64_t pivot =
-    aTime.ToSeconds() * AverageFrameLength() + mParser->FirstFrame().Offset();
-
-  // Time in seconds where we can stop seeking and will continue using ScanUntil.
-  static const int GAP_THRESHOLD = 5;
-  int64_t first = mParser->FirstFrame().Offset();
-  int64_t last = mSource.GetLength();
-  Maybe<int64_t> lastFoundOffset;
-  uint32_t iterations = 0;
-  TimeUnit timeSeekedTo;
-
-  do {
-    iterations++;
-    mSource.Seek(SEEK_SET, pivot);
-    flac::Frame frame;
-    if (!frame.FindNext(mSource)) {
-      NS_WARNING("We should have found a point");
-      break;
-    }
-    timeSeekedTo = frame.Time();
-
-    LOGV("FastSeek: interation:%u found:%f @ %lld",
-         iterations, timeSeekedTo.ToSeconds(), frame.Offset());
-
-    if (lastFoundOffset && lastFoundOffset.ref() == frame.Offset()) {
-      // Same frame found twice. We're done.
-      break;
-    }
-    lastFoundOffset = Some(frame.Offset());
-
-    if (frame.Time() == aTime) {
-      break;
-    }
-    if (aTime > frame.Time()
-        && aTime - frame.Time() <= TimeUnit::FromSeconds(GAP_THRESHOLD)) {
-      // We're close enough to the target, experimentation shows that bisection
-      // search doesn't help much after that.
-      break;
-    }
-    if (frame.Time() > aTime) {
-      last = pivot;
-      pivot -= (pivot - first) / 2;
-    } else {
-      first = pivot;
-      pivot += (last - pivot) / 2;
-    }
-  } while (true);
-
-  if (lastFoundOffset) {
-    mSource.Seek(SEEK_SET, lastFoundOffset.ref());
-  }
-
-  return timeSeekedTo;
-}
-
-TimeUnit
-FlacTrackDemuxer::ScanUntil(const TimeUnit& aTime)
-{
-  LOG("ScanUntil(%f avgFrameLen=%f mParsedFramesDuration=%f offset=%lld",
-      aTime.ToSeconds(), AverageFrameLength(),
-      mParsedFramesDuration.ToSeconds(), mParser->CurrentFrame().Offset());
-
-   if (!mParser->FirstFrame().IsValid()
-       || aTime <= mParser->FirstFrame().Time()) {
-     return FastSeek(aTime);
-   }
-
-  int64_t previousOffset = 0;
-  TimeUnit previousTime;
-  while (FindNextFrame().IsValid() && mParser->CurrentFrame().Time() < aTime) {
-    previousOffset = mParser->CurrentFrame().Offset();
-    previousTime = mParser->CurrentFrame().Time();
-  }
-
-  if (!mParser->CurrentFrame().IsValid()) {
-    // We reached EOS.
-    return Duration();
-  }
-
-  // Seek back to the last frame found prior the target.
-  mParser->EndFrameSession();
-  mSource.Seek(SEEK_SET, previousOffset);
-  return previousTime;
-}
-
-RefPtr<FlacTrackDemuxer::SamplesPromise>
-FlacTrackDemuxer::GetSamples(int32_t aNumSamples)
-{
-  LOGV("GetSamples(%d) Begin offset=%lld mParsedFramesDuration=%f"
-       " mTotalFrameLen=%llu",
-       aNumSamples, GetResourceOffset(), mParsedFramesDuration.ToSeconds(),
-       mTotalFrameLen);
-
-  if (!aNumSamples) {
-    return SamplesPromise::CreateAndReject(
-      DemuxerFailureReason::DEMUXER_ERROR, __func__);
-  }
-
-  RefPtr<SamplesHolder> frames = new SamplesHolder();
-
-  while (aNumSamples--) {
-    RefPtr<MediaRawData> frame(GetNextFrame(FindNextFrame()));
-    if (!frame)
-      break;
-
-    frames->mSamples.AppendElement(frame);
-  }
-
-  LOGV("GetSamples() End mSamples.Length=%u aNumSamples=%d offset=%lld"
-       " mParsedFramesDuration=%f mTotalFrameLen=%llu",
-       frames->mSamples.Length(), aNumSamples, GetResourceOffset(),
-       mParsedFramesDuration.ToSeconds(), mTotalFrameLen);
-
-  if (frames->mSamples.IsEmpty()) {
-    return SamplesPromise::CreateAndReject(
-      DemuxerFailureReason::END_OF_STREAM, __func__);
-  }
-
-  return SamplesPromise::CreateAndResolve(frames, __func__);
-}
-
-void
-FlacTrackDemuxer::Reset()
-{
-  LOG("Reset()");
-  MOZ_ASSERT(mParser);
-  if (mParser->FirstFrame().IsValid()) {
-    mSource.Seek(SEEK_SET, mParser->FirstFrame().Offset());
-  } else {
-    mSource.Seek(SEEK_SET, 0);
-  }
-  mParser->EndFrameSession();
-}
-
-RefPtr<FlacTrackDemuxer::SkipAccessPointPromise>
-FlacTrackDemuxer::SkipToNextRandomAccessPoint(TimeUnit aTimeThreshold)
-{
-  // Will not be called for audio-only resources.
-  return SkipAccessPointPromise::CreateAndReject(
-    SkipFailureHolder(DemuxerFailureReason::DEMUXER_ERROR, 0), __func__);
-}
-
-int64_t
-FlacTrackDemuxer::GetResourceOffset() const
-{
-  return mSource.Tell();
-}
-
-TimeIntervals
-FlacTrackDemuxer::GetBuffered()
-{
-  TimeUnit duration = Duration();
-
-  if (duration <= TimeUnit()) {
-    return TimeIntervals();
-  }
-
-  // We could simply parse the cached data instead and read the timestamps.
-  // However, for now this will do.
-  AutoPinned<MediaResource> stream(mSource.GetResource());
-  return GetEstimatedBufferedTimeRanges(stream, duration.ToMicroseconds());
-}
-
-const flac::Frame&
-FlacTrackDemuxer::FindNextFrame()
-{
-  LOGV("FindNext() Begin offset=%lld mParsedFramesDuration=%f"
-       " mTotalFrameLen=%llu",
-       GetResourceOffset(), mParsedFramesDuration.ToSeconds(), mTotalFrameLen);
-
-  if (mParser->FindNextFrame(mSource)) {
-    // Update our current progress stats.
-    mParsedFramesDuration =
-      std::max(mParsedFramesDuration,
-               mParser->CurrentFrame().Time() - mParser->FirstFrame().Time()
-               + mParser->CurrentFrame().Duration());
-    mTotalFrameLen =
-      std::max<uint64_t>(mTotalFrameLen,
-                         mParser->CurrentFrame().Offset()
-                         - mParser->FirstFrame().Offset()
-                         + mParser->CurrentFrame().Size());
-
-    LOGV("FindNext() End time=%f offset=%lld mParsedFramesDuration=%f"
-         " mTotalFrameLen=%llu",
-         mParser->CurrentFrame().Time().ToSeconds(), GetResourceOffset(),
-         mParsedFramesDuration.ToSeconds(), mTotalFrameLen);
-  }
-
-  return mParser->CurrentFrame();
-}
-
-already_AddRefed<MediaRawData>
-FlacTrackDemuxer::GetNextFrame(const flac::Frame& aFrame)
-{
-  if (!aFrame.IsValid()) {
-    LOG("GetNextFrame() EOS");
-    return nullptr;
-  }
-
-  LOG("GetNextFrame() Begin(time=%f offset=%lld size=%u)",
-      aFrame.Time().ToSeconds(), aFrame.Offset(), aFrame.Size());
-
-  const int64_t offset = aFrame.Offset();
-  const uint32_t size = aFrame.Size();
-
-  RefPtr<MediaRawData> frame = new MediaRawData();
-  frame->mOffset = offset;
-
-  nsAutoPtr<MediaRawDataWriter> frameWriter(frame->CreateWriter());
-  if (!frameWriter->SetSize(size)) {
-    LOG("GetNext() Exit failed to allocated media buffer");
-    return nullptr;
-  }
-
-  const uint32_t read = Read(frameWriter->Data(), offset, size);
-  if (read != size) {
-    LOG("GetNextFrame() Exit read=%u frame->Size=%u", read, frame->Size());
-    return nullptr;
-  }
-
-  frame->mTime = aFrame.Time().ToMicroseconds();
-  frame->mDuration = aFrame.Duration().ToMicroseconds();
-  frame->mTimecode = frame->mTime;
-  frame->mOffset = aFrame.Offset();
-  frame->mKeyframe = true;
-
-  MOZ_ASSERT(frame->mTime >= 0);
-  MOZ_ASSERT(frame->mDuration >= 0);
-
-  return frame.forget();
-}
-
-int32_t
-FlacTrackDemuxer::Read(uint8_t* aBuffer, int64_t aOffset, int32_t aSize)
-{
-  uint32_t read = 0;
-  const nsresult rv = mSource.ReadAt(aOffset, reinterpret_cast<char*>(aBuffer),
-                                     static_cast<uint32_t>(aSize), &read);
-  NS_ENSURE_SUCCESS(rv, 0);
-  return static_cast<int32_t>(read);
-}
-
-double
-FlacTrackDemuxer::AverageFrameLength() const
-{
-  if (mParsedFramesDuration.ToMicroseconds()) {
-    return mTotalFrameLen / mParsedFramesDuration.ToSeconds();
-  }
-
-  return 0.0;
-}
-
-TimeUnit
-FlacTrackDemuxer::Duration() const
-{
-  return std::max(mParsedFramesDuration,
-                  TimeUnit::FromMicroseconds(mParser->Info().mDuration));
-}
-
-TimeUnit
-FlacTrackDemuxer::TimeAtEnd()
-{
-  // Scan the last 128kB if available to determine the last frame.
-  static const int OFFSET_FROM_END = 128 * 1024;
-
-  // Seek to the end of the file and attempt to find the last frame.
-  MediaResourceIndex source(mSource.GetResource());
-  TimeUnit previousDuration;
-  TimeUnit previousTime;
-
-  const int64_t streamLen = mSource.GetLength();
-  if (streamLen < 0) {
-    return TimeUnit::FromInfinity();
-  }
-
-  flac::FrameParser parser;
-
-  source.Seek(SEEK_SET, std::max<int64_t>(0LL, streamLen - OFFSET_FROM_END));
-  while (parser.FindNextFrame(source)) {
-    // FFmpeg flac muxer can generate a last frame with earlier than the others.
-    previousTime = std::max(previousTime, parser.CurrentFrame().Time());
-    if (parser.CurrentFrame().Duration() > TimeUnit()) {
-      // The last frame doesn't have a duration, so only update our duration
-      // if we do have one.
-      previousDuration = parser.CurrentFrame().Duration();
-    }
-    if (source.Tell() >= streamLen) {
-      // Limit the read, in case the length change half-way.
-      break;
-    }
-  }
-
-  // Update our current progress stats.
-  mParsedFramesDuration =
-    previousTime + previousDuration - mParser->FirstFrame().Time();
-  mTotalFrameLen = streamLen - mParser->FirstFrame().Offset();
-
-  return mParsedFramesDuration;
-}
-
-/* static */ bool
-FlacDemuxer::FlacSniffer(const uint8_t* aData, const uint32_t aLength)
-{
-  if (aLength < FLAC_MAX_FRAME_HEADER_SIZE) {
-    return false;
-  }
-
-  flac::Frame frame;
-  return frame.FindNext(aData, aLength - FLAC_MAX_FRAME_HEADER_SIZE) >= 0;
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/dom/media/flac/FlacDemuxer.h
+++ /dev/null
@@ -1,108 +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/. */
-
-#ifndef FLAC_DEMUXER_H_
-#define FLAC_DEMUXER_H_
-
-#include "mozilla/Attributes.h"
-#include "MediaDataDemuxer.h"
-#include "MediaResource.h"
-namespace mozilla {
-
-namespace flac {
-class Frame;
-class FrameParser;
-}
-class FlacTrackDemuxer;
-
-
-class FlacDemuxer : public MediaDataDemuxer {
-public:
-  // MediaDataDemuxer interface.
-  explicit FlacDemuxer(MediaResource* aSource);
-  RefPtr<InitPromise> Init() override;
-  bool HasTrackType(TrackInfo::TrackType aType) const override;
-  uint32_t GetNumberTracks(TrackInfo::TrackType aType) const override;
-  already_AddRefed<MediaTrackDemuxer> GetTrackDemuxer(
-    TrackInfo::TrackType aType, uint32_t aTrackNumber) override;
-  bool IsSeekable() const override;
-
-  // Return true if a valid flac frame header could be found.
-  static bool FlacSniffer(const uint8_t* aData, const uint32_t aLength);
-
-private:
-  bool InitInternal();
-
-  RefPtr<MediaResource> mSource;
-  RefPtr<FlacTrackDemuxer> mTrackDemuxer;
-};
-
-class FlacTrackDemuxer : public MediaTrackDemuxer {
-public:
-  explicit FlacTrackDemuxer(MediaResource* aSource);
-
-  // Initializes the track demuxer by reading the first frame for meta data.
-  // Returns initialization success state.
-  bool Init();
-
-  // MediaTrackDemuxer interface.
-  UniquePtr<TrackInfo> GetInfo() const override;
-  RefPtr<SeekPromise> Seek(media::TimeUnit aTime) override;
-  RefPtr<SamplesPromise> GetSamples(int32_t aNumSamples = 1) override;
-  void Reset() override;
-  int64_t GetResourceOffset() const override;
-  media::TimeIntervals GetBuffered() override;
-  RefPtr<SkipAccessPointPromise> SkipToNextRandomAccessPoint(
-    media::TimeUnit aTimeThreshold) override;
-
-  bool IsSeekable() const;
-
-private:
-  // Destructor.
-  ~FlacTrackDemuxer();
-
-  // Returns the estimated stream duration, or a 0-duration if unknown.
-  media::TimeUnit Duration() const;
-  media::TimeUnit TimeAtEnd();
-
-  // Fast approximate seeking to given time.
-  media::TimeUnit FastSeek(const media::TimeUnit& aTime);
-
-  // Seeks by scanning the stream up to the given time for more accurate results.
-  media::TimeUnit ScanUntil(const media::TimeUnit& aTime);
-
-  // Finds the next valid frame and return it.
-  const flac::Frame& FindNextFrame();
-
-  // Returns the next ADTS frame, if available.
-  already_AddRefed<MediaRawData> GetNextFrame(const flac::Frame& aFrame);
-
-  // Reads aSize bytes into aBuffer from the source starting at aOffset.
-  // Returns the actual size read.
-  int32_t Read(uint8_t* aBuffer, int64_t aOffset, int32_t aSize);
-
-  // Returns the average frame length derived from the previously parsed frames.
-  double AverageFrameLength() const;
-
-  // The (hopefully) Flac resource.
-  MediaResourceIndex mSource;
-
-  // Flac frame parser used to detect frames and extract side info.
-  nsAutoPtr<flac::FrameParser> mParser;
-
-  // Total duration of parsed frames.
-  media::TimeUnit mParsedFramesDuration;
-
-  // Sum of parsed frames' lengths in bytes.
-  uint64_t mTotalFrameLen;
-
-  // Audio track config info.
-  UniquePtr<AudioInfo> mInfo;
-};
-
-} // mozilla
-
-#endif // !FLAC_DEMUXER_H_
deleted file mode 100644
--- a/dom/media/flac/FlacFrameParser.cpp
+++ /dev/null
@@ -1,258 +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 "FlacFrameParser.h"
-#include "mp4_demuxer/ByteReader.h"
-#include "nsTArray.h"
-#include "OggCodecState.h"
-#include "VideoUtils.h"
-
-namespace mozilla
-{
-
-class AutoByteReader : public mp4_demuxer::ByteReader
-{
-public:
-  AutoByteReader(const uint8_t* aData, size_t aSize)
-    : mp4_demuxer::ByteReader(aData, aSize)
-  {
-
-  }
-  virtual ~AutoByteReader()
-  {
-    DiscardRemaining();
-  }
-};
-
-#define OGG_FLAC_METADATA_TYPE_STREAMINFO 0x7F
-#define FLAC_STREAMINFO_SIZE   34
-
-#define BITMASK(x) ((1ULL << x)-1)
-
-enum
-{
-  FLAC_METADATA_TYPE_STREAMINFO = 0,
-  FLAC_METADATA_TYPE_PADDING,
-  FLAC_METADATA_TYPE_APPLICATION,
-  FLAC_METADATA_TYPE_SEEKTABLE,
-  FLAC_METADATA_TYPE_VORBIS_COMMENT,
-  FLAC_METADATA_TYPE_CUESHEET,
-  FLAC_METADATA_TYPE_PICTURE,
-  FLAC_METADATA_TYPE_INVALID = 127
-};
-
-FlacFrameParser::FlacFrameParser()
-  : mMinBlockSize(0)
-  , mMaxBlockSize(0)
-  , mMinFrameSize(0)
-  , mMaxFrameSize(0)
-  , mNumFrames(0)
-  , mFullMetadata(false)
-  , mPacketCount(0)
-{
-}
-
-uint32_t
-FlacFrameParser::HeaderBlockLength(const uint8_t* aPacket) const
-{
-  uint32_t extra = 4;
-  if (aPacket[0] == 'f') {
-    // This must be the first block read, which contains the fLaC signature.
-    aPacket += 4;
-    extra += 4;
-  }
-  return (BigEndian::readUint32(aPacket) & BITMASK(24)) + extra;
-}
-
-bool
-FlacFrameParser::DecodeHeaderBlock(const uint8_t* aPacket, size_t aLength)
-{
-  if (aLength < 4 || aPacket[0] == 0xff) {
-    // Not a header block.
-    return false;
-  }
-  AutoByteReader br(aPacket, aLength);
-
-  mPacketCount++;
-
-  if (aPacket[0] == 'f') {
-    if (mPacketCount != 1 || memcmp(br.Read(4), "fLaC", 4) ||
-        br.Remaining() != FLAC_STREAMINFO_SIZE + 4) {
-      return false;
-    }
-    aPacket += 4;
-    aLength -= 4;
-  }
-  uint8_t blockHeader = br.ReadU8();
-  // blockType is a misnomer as it could indicate here either a packet type
-  // should it points to the start of a Flac in Ogg metadata, or an actual
-  // block type as per the flac specification.
-  uint32_t blockType = blockHeader & 0x7f;
-  bool lastBlock = blockHeader & 0x80;
-
-  if (blockType == OGG_FLAC_METADATA_TYPE_STREAMINFO) {
-    if (mPacketCount != 1 || memcmp(br.Read(4), "FLAC", 4) ||
-        br.Remaining() != FLAC_STREAMINFO_SIZE + 12) {
-      return false;
-    }
-    uint32_t major = br.ReadU8();
-    if (major != 1) {
-      // unsupported version;
-      return false;
-    }
-    br.ReadU8(); // minor version
-    mNumHeaders = Some(uint32_t(br.ReadU16()));
-    br.Read(4); // fLaC
-    blockType = br.ReadU8() & BITMASK(7);
-    // First METADATA_BLOCK_STREAMINFO
-    if (blockType != FLAC_METADATA_TYPE_STREAMINFO) {
-      // First block must be a stream info.
-      return false;
-    }
-  }
-
-  uint32_t blockDataSize = br.ReadU24();
-  const uint8_t* blockDataStart = br.Peek(blockDataSize);
-  if (!blockDataStart) {
-    // Incomplete block.
-    return false;
-  }
-
-  switch (blockType) {
-    case FLAC_METADATA_TYPE_STREAMINFO:
-    {
-      if (mPacketCount != 1 || blockDataSize != FLAC_STREAMINFO_SIZE) {
-        // STREAMINFO must be the first metadata block found, and its size
-        // is constant.
-        return false;
-      }
-
-      mMinBlockSize = br.ReadU16();
-      mMaxBlockSize = br.ReadU16();
-      mMinFrameSize = br.ReadU24();
-      mMaxFrameSize = br.ReadU24();
-
-      uint64_t blob = br.ReadU64();
-      uint32_t sampleRate = (blob >> 44) & BITMASK(20);
-      if (!sampleRate) {
-        return false;
-      }
-      uint32_t numChannels = ((blob >> 41) & BITMASK(3)) + 1;
-      if (numChannels > FLAC_MAX_CHANNELS) {
-        return false;
-      }
-      uint32_t bps = ((blob >> 38) & BITMASK(5)) + 1;
-      if (bps > 24) {
-        return false;
-      }
-      mNumFrames = blob & BITMASK(36);
-
-      mInfo.mMimeType = "audio/flac";
-      mInfo.mRate = sampleRate;
-      mInfo.mChannels = numChannels;
-      mInfo.mBitDepth = bps;
-      mInfo.mCodecSpecificConfig->AppendElements(blockDataStart, blockDataSize);
-      CheckedInt64 duration =
-        SaferMultDiv(mNumFrames, USECS_PER_S, sampleRate);
-      mInfo.mDuration = duration.isValid() ? duration.value() : 0;
-      mParser = new OpusParser;
-      break;
-    }
-    case FLAC_METADATA_TYPE_VORBIS_COMMENT:
-    {
-      if (!mParser) {
-        // We must have seen a valid streaminfo first.
-        return false;
-      }
-      nsTArray<uint8_t> comments(blockDataSize + 8);
-      comments.AppendElements("OpusTags", 8);
-      comments.AppendElements(blockDataStart, blockDataSize);
-      if (!mParser->DecodeTags(comments.Elements(), comments.Length())) {
-        return false;
-      }
-      break;
-    }
-    default:
-      break;
-  }
-
-  if (mNumHeaders && mPacketCount > mNumHeaders.ref() + 1) {
-    // Received too many header block. assuming invalid.
-    return false;
-  }
-
-  if (lastBlock || (mNumHeaders && mNumHeaders.ref() + 1 == mPacketCount)) {
-    mFullMetadata = true;
-  }
-
-  return true;
-}
-
-int64_t
-FlacFrameParser::BlockDuration(const uint8_t* aPacket, size_t aLength) const
-{
-  if (!mInfo.IsValid()) {
-    return -1;
-  }
-  if (mMinBlockSize == mMaxBlockSize) {
-    // block size is fixed, use this instead of looking at the frame header.
-    return mMinBlockSize;
-  }
-  // TODO
-  return 0;
-}
-
-bool
-FlacFrameParser::IsHeaderBlock(const uint8_t* aPacket, size_t aLength) const
-{
-  // Ogg Flac header
-  // The one-byte packet type 0x7F
-  // The four-byte ASCII signature "FLAC", i.e. 0x46, 0x4C, 0x41, 0x43
-
-  // Flac header:
-  // "fLaC", the FLAC stream marker in ASCII, meaning byte 0 of the stream is 0x66, followed by 0x4C 0x61 0x43
-
-  // If we detect either a ogg or plain flac header, then it must be valid.
-  if (aLength < 4 || aPacket[0] == 0xff) {
-    // A header is at least 4 bytes.
-    return false;
-  }
-  if (aPacket[0] == 0x7f) {
-    // Ogg packet
-    AutoByteReader br(aPacket + 1, aLength - 1);
-    const uint8_t* signature = br.Read(4);
-    return signature && !memcmp(signature, "FLAC", 4);
-  }
-  AutoByteReader br(aPacket, aLength - 1);
-  const uint8_t* signature = br.Read(4);
-  if (signature && !memcmp(signature, "fLaC", 4)) {
-    // Flac start header, must have STREAMINFO as first metadata block;
-    if (!br.CanRead8()) {
-      return false;
-    }
-    uint32_t blockType = br.ReadU8() & 0x7f;
-    return blockType == FLAC_METADATA_TYPE_STREAMINFO;
-  }
-  char type = aPacket[0] & 0x7f;
-  return type >= 1 && type <= 6;
-}
-
-MetadataTags*
-FlacFrameParser::GetTags() const
-{
-  MetadataTags* tags;
-
-  tags = new MetadataTags;
-  for (uint32_t i = 0; i < mParser->mTags.Length(); i++) {
-    OggCodecState::AddVorbisComment(tags,
-                                    mParser->mTags[i].Data(),
-                                    mParser->mTags[i].Length());
-  }
-
-  return tags;
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/dom/media/flac/FlacFrameParser.h
+++ /dev/null
@@ -1,64 +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/. */
-
-#ifndef FLAC_FRAME_PARSER_H_
-#define FLAC_FRAME_PARSER_H_
-
-#include "mozilla/Maybe.h"
-#include "nsAutoPtr.h"
-#include "MediaDecoder.h" // For MetadataTags
-#include "MediaInfo.h"
-#include "MediaResource.h"
-
-namespace mozilla
-{
-
-class OpusParser;
-
-// Decode a Flac Metadata block contained in either a ogg packet
-// (https://xiph.org/flac/ogg_mapping.html) or in flac container
-// (https://xiph.org/flac/format.html#frame_header)
-
-class FlacFrameParser
-{
-public:
-  FlacFrameParser();
-
-  bool IsHeaderBlock(const uint8_t* aPacket, size_t aLength) const;
-  // Return the length of the block header (METADATA_BLOCK_HEADER+
-  // METADATA_BLOCK_DATA), aPacket must point to at least 4
-  // bytes and to a valid block header start (as determined by IsHeaderBlock).
-  uint32_t HeaderBlockLength(const uint8_t* aPacket) const;
-  bool DecodeHeaderBlock(const uint8_t* aPacket, size_t aLength);
-  bool HasFullMetadata() const { return mFullMetadata; }
-  // Return the duration in frames found in the block. -1 if error
-  // such as invalid packet.
-  int64_t BlockDuration(const uint8_t* aPacket, size_t aLength) const;
-
-  // Return a hash table with tag metadata.
-  MetadataTags* GetTags() const;
-
-  AudioInfo mInfo;
-
-private:
-  bool ReconstructFlacGranulepos(void);
-  Maybe<uint32_t> mNumHeaders;
-  uint32_t mMinBlockSize;
-  uint32_t mMaxBlockSize;
-  uint32_t mMinFrameSize;
-  uint32_t mMaxFrameSize;
-  uint64_t mNumFrames;
-  bool mFullMetadata;
-  uint32_t mPacketCount;
-
-  // Used to decode the vorbis comment metadata.
-  nsAutoPtr<OpusParser> mParser;
-
-};
-
-}
-
-#endif // FLAC_FRAME_PARSER_H_
deleted file mode 100644
--- a/dom/media/flac/moz.build
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# 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/.
-
-EXPORTS += [
-    'FlacDecoder.h',
-    'FlacDemuxer.h',
-    'FlacFrameParser.h',
-]
-
-UNIFIED_SOURCES += [
-    'FlacDecoder.cpp',
-    'FlacDemuxer.cpp',
-    'FlacFrameParser.cpp',
-]
-
-CXXFLAGS += CONFIG['MOZ_LIBVPX_CFLAGS']
-
-FINAL_LIBRARY = 'xul'
-
-if CONFIG['GNU_CXX']:
-    CXXFLAGS += ['-Wno-error=shadow']
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -16,17 +16,16 @@ with Files('RTC*'):
     BUG_COMPONENT = component_signaling
 
 component_av = ('Core', 'WebRTC: Audio/Video')
 with Files('GetUserMedia*'):
     BUG_COMPONENT = component_av
 
 DIRS += [
     'encoder',
-    'flac',
     'gmp',
     'gmp-plugin',
     'gmp-plugin-openh264',
     'imagecapture',
     'mediasink',
     'mediasource',
     'ogg',
     'platforms',
--- a/dom/media/ogg/OggCodecState.cpp
+++ b/dom/media/ogg/OggCodecState.cpp
@@ -44,22 +44,20 @@ OggCodecState::Create(ogg_page* aPage)
   if (aPage->body_len > 6 && memcmp(aPage->body+1, "theora", 6) == 0) {
     codecState = new TheoraState(aPage);
   } else if (aPage->body_len > 6 && memcmp(aPage->body+1, "vorbis", 6) == 0) {
     codecState = new VorbisState(aPage);
   } else if (aPage->body_len > 8 && memcmp(aPage->body, "OpusHead", 8) == 0) {
     codecState = new OpusState(aPage);
   } else if (aPage->body_len > 8 && memcmp(aPage->body, "fishead\0", 8) == 0) {
     codecState = new SkeletonState(aPage);
-  } else if (aPage->body_len > 5 && memcmp(aPage->body, "\177FLAC", 5) == 0) {
-    codecState = new FlacState(aPage);
   } else {
     codecState = new OggCodecState(aPage, false);
   }
-  return codecState->OggCodecState::InternalInit() ? codecState.forget() : nullptr;
+  return codecState->OggCodecState::Init() ? codecState.forget() : nullptr;
 }
 
 OggCodecState::OggCodecState(ogg_page* aBosPage, bool aActive)
   : mPacketCount(0)
   , mSerial(ogg_page_serialno(aBosPage))
   , mActive(aActive)
   , mDoneReadingHeaders(!aActive)
 {
@@ -94,17 +92,17 @@ OggCodecState::ClearUnstamped()
 {
   for (uint32_t i = 0; i < mUnstamped.Length(); ++i) {
     OggCodecState::ReleasePacket(mUnstamped[i]);
   }
   mUnstamped.Clear();
 }
 
 bool
-OggCodecState::InternalInit()
+OggCodecState::Init()
 {
   int ret = ogg_stream_init(&mState, mSerial);
   return ret == 0;
 }
 
 bool
 OggCodecState::IsValidVorbisTagName(nsCString& aName)
 {
@@ -827,17 +825,17 @@ VorbisState::ReconstructVorbisGranulepos
   // (for example if the stream was truncated).
   //
   // We validate our prediction of the number of samples decoded when
   // VALIDATE_VORBIS_SAMPLE_CALCULATION is defined by recording the predicted
   // number of samples, and verifing we extract that many when decoding
   // each packet.
 
   NS_ASSERTION(mUnstamped.Length() > 0, "Length must be > 0");
-  ogg_packet* last = mUnstamped.LastElement();
+  ogg_packet* last = mUnstamped[mUnstamped.Length()-1];
   NS_ASSERTION(last->e_o_s || last->granulepos >= 0,
     "Must know last granulepos!");
   if (mUnstamped.Length() == 1) {
     ogg_packet* packet = mUnstamped[0];
     long blockSize = vorbis_packet_blocksize(&mInfo, packet);
     if (blockSize < 0) {
       // On failure vorbis_packet_blocksize returns < 0. If we've got
       // a bad packet, we just assume that decode will have to skip this
@@ -1141,17 +1139,17 @@ OpusState::PacketDuration(ogg_packet* aP
   CheckedInt64 t = SaferMultDiv(GetOpusDeltaGP(aPacket), USECS_PER_S, 48000);
   return t.isValid() ? t.value() : -1;
 }
 
 bool
 OpusState::ReconstructOpusGranulepos(void)
 {
   NS_ASSERTION(mUnstamped.Length() > 0, "Must have unstamped packets");
-  ogg_packet* last = mUnstamped.LastElement();
+  ogg_packet* last = mUnstamped[mUnstamped.Length()-1];
   NS_ASSERTION(last->e_o_s || last->granulepos > 0,
       "Must know last granulepos!");
   int64_t gp;
   // If this is the last page, and we've seen at least one previous page (or
   // this is the first page)...
   if (last->e_o_s) {
     if (mPrevPageGranulepos != -1) {
       // If this file only has one page and the final granule position is
@@ -1227,144 +1225,16 @@ OpusState::ReconstructOpusGranulepos(voi
   // We MUST reject such streams.
   if (!mDoneReadingHeaders && GetOpusDeltaGP(mUnstamped[0]) > gp) {
     return false;
   }
   mPrevPageGranulepos = last->granulepos;
   return true;
 }
 
-FlacState::FlacState(ogg_page* aBosPage)
-  : OggCodecState(aBosPage, true)
-{
-}
-
-bool
-FlacState::DecodeHeader(ogg_packet* aPacket)
-{
-  nsAutoRef<ogg_packet> autoRelease(aPacket);
-
-  if (!mParser.DecodeHeaderBlock(aPacket->packet, aPacket->bytes)) {
-    return false;
-  }
-  if (mParser.HasFullMetadata()) {
-    mDoneReadingHeaders = true;
-  }
-  return true;
-}
-
-int64_t
-FlacState::Time(int64_t granulepos)
-{
-  if (!mParser.mInfo.IsValid()) {
-    return -1;
-  }
-  CheckedInt64 t =
-      SaferMultDiv(granulepos, USECS_PER_S, mParser.mInfo.mRate);
-  if (!t.isValid()) {
-    return -1;
-  }
-  return t.value();
-}
-
-int64_t
-FlacState::PacketDuration(ogg_packet* aPacket)
-{
-  return mParser.BlockDuration(aPacket->packet, aPacket->bytes);
-}
-
-bool
-FlacState::IsHeader(ogg_packet* aPacket)
-{
-  return mParser.IsHeaderBlock(aPacket->packet, aPacket->bytes);
-}
-
-nsresult
-FlacState::PageIn(ogg_page* aPage)
-{
-  if (!mActive) {
-    return NS_OK;
-  }
-  NS_ASSERTION(static_cast<uint32_t>(ogg_page_serialno(aPage)) == mSerial,
-               "Page must be for this stream!");
-  if (ogg_stream_pagein(&mState, aPage) == -1)
-    return NS_ERROR_FAILURE;
-  bool foundGp;
-  nsresult res = PacketOutUntilGranulepos(foundGp);
-  if (NS_FAILED(res)) {
-    return res;
-  }
-  if (foundGp && mDoneReadingHeaders) {
-    // We've found a packet with a granulepos, and we've loaded our metadata
-    // and initialized our decoder. Determine granulepos of buffered packets.
-    ReconstructFlacGranulepos();
-    for (uint32_t i = 0; i < mUnstamped.Length(); ++i) {
-      ogg_packet* packet = mUnstamped[i];
-      NS_ASSERTION(!IsHeader(packet), "Don't try to recover header packet gp");
-      NS_ASSERTION(packet->granulepos != -1, "Packet must have gp by now");
-      mPackets.Append(packet);
-    }
-    mUnstamped.Clear();
-  }
-  return NS_OK;
-}
-
-// Return a hash table with tag metadata.
-MetadataTags*
-FlacState::GetTags()
-{
-  return mParser.GetTags();
-}
-
-const AudioInfo&
-FlacState::Info()
-{
-  return mParser.mInfo;
-}
-
-bool
-FlacState::ReconstructFlacGranulepos(void)
-{
-  NS_ASSERTION(mUnstamped.Length() > 0, "Must have unstamped packets");
-  ogg_packet* last = mUnstamped.LastElement();
-  NS_ASSERTION(last->e_o_s || last->granulepos > 0,
-      "Must know last granulepos!");
-  int64_t gp;
-
-  gp = last->granulepos;
-  // Loop through the packets backwards, subtracting the next
-  // packet's duration from its granulepos to get the value
-  // for the current packet.
-  for (uint32_t i = mUnstamped.Length() - 1; i > 0; i--) {
-    int offset =
-        mParser.BlockDuration(mUnstamped[i]->packet, mUnstamped[i]->bytes);
-    // Check for error (negative offset) and overflow.
-    if (offset >= 0) {
-      if (offset <= gp) {
-        gp -= offset;
-      } else {
-        // If the granule position of the first data page is smaller than the
-        // number of decodable audio samples on that page, then we MUST reject
-        // the stream.
-        if (!mDoneReadingHeaders) {
-          return false;
-        }
-        // It's too late to reject the stream.
-        // If we get here, this almost certainly means the file has screwed-up
-        // timestamps somewhere after the first page.
-        NS_WARNING("Clamping negative granulepos to zero.");
-        gp = 0;
-      }
-    }
-    mUnstamped[i - 1]->granulepos = gp;
-  }
-
-  return true;
-}
-
 SkeletonState::SkeletonState(ogg_page* aBosPage)
   : OggCodecState(aBosPage, true)
   , mVersion(0)
   , mPresentationTime(0)
   , mLength(0)
 {
   MOZ_COUNT_CTOR(SkeletonState);
 }
@@ -1791,10 +1661,11 @@ SkeletonState::DecodeHeader(ogg_packet* 
     return DecodeFisbone(aPacket);
   } else if (aPacket->e_o_s) {
     mDoneReadingHeaders = true;
     return true;
   }
   return true;
 }
 
+
 } // namespace mozilla
 
--- a/dom/media/ogg/OggCodecState.h
+++ b/dom/media/ogg/OggCodecState.h
@@ -20,17 +20,16 @@
 #include "MediaDecoderStateMachine.h"
 #include "MediaDecoderReader.h"
 #include <nsAutoPtr.h>
 #include <nsAutoRef.h>
 #include <nsDeque.h>
 #include <nsTArray.h>
 #include <nsClassHashtable.h>
 #include "VideoUtils.h"
-#include "FlacFrameParser.h"
 
 #include <stdint.h>
 
 // Uncomment the following to validate that we're predicting the number
 // of Vorbis samples in each packet correctly.
 #define VALIDATE_VORBIS_SAMPLE_CALCULATION
 #ifdef  VALIDATE_VORBIS_SAMPLE_CALCULATION
 #include <map>
@@ -81,21 +80,20 @@ public:
 class OggCodecState
 {
 public:
   typedef mozilla::MetadataTags MetadataTags;
   // Ogg types we know about
   enum CodecType
   {
     TYPE_VORBIS=0,
-    TYPE_THEORA,
-    TYPE_OPUS,
-    TYPE_SKELETON,
-    TYPE_FLAC,
-    TYPE_UNKNOWN
+    TYPE_THEORA=1,
+    TYPE_OPUS=2,
+    TYPE_SKELETON=3,
+    TYPE_UNKNOWN=4
   };
 
   virtual ~OggCodecState();
   
   // Factory for creating nsCodecStates. Use instead of constructor.
   // aPage should be a beginning-of-stream page.
   static OggCodecState* Create(ogg_page* aPage);
   
@@ -138,17 +136,17 @@ public:
       // Audio preskip may eat a whole packet or more.
       return 0;
     } else {
       return endTime - duration;
     }
   }
 
   // Initializes the codec state.
-  virtual bool Init() { return true; }
+  virtual bool Init();
 
   // Returns true when this bitstream has finished reading all its
   // header packets.
   bool DoneReadingHeaders() { return mDoneReadingHeaders; }
 
   // Deactivates the bitstream. Only the primary video and audio bitstreams
   // should be active.
   void Deactivate()
@@ -223,26 +221,16 @@ public:
   OggPacketQueue mPackets;
 
   // Is the bitstream active; whether we're decoding and playing this bitstream.
   bool mActive;
   
   // True when all headers packets have been read.
   bool mDoneReadingHeaders;
 
-  // Validation utility for vorbis-style tag names.
-  static bool IsValidVorbisTagName(nsCString& aName);
-
-  // Utility method to parse and add a vorbis-style comment
-  // to a metadata hash table. Most Ogg-encapsulated codecs
-  // use the vorbis comment format for metadata.
-  static bool AddVorbisComment(MetadataTags* aTags,
-                        const char* aComment,
-                        uint32_t aLength);
-
 protected:
   // Constructs a new OggCodecState. aActive denotes whether the stream is
   // active. For streams of unsupported or unknown types, aActive should be
   // false.
   OggCodecState(ogg_page* aBosPage, bool aActive);
 
   // Deallocates all packets stored in mUnstamped, and clears the array.
   void ClearUnstamped();
@@ -255,18 +243,25 @@ protected:
   // can be pushed over to mPackets. Used by PageIn() implementations in
   // subclasses.
   nsresult PacketOutUntilGranulepos(bool& aFoundGranulepos);
 
   // Temporary buffer in which to store packets while we're reading packets
   // in order to capture granulepos.
   nsTArray<ogg_packet*> mUnstamped;
 
-private:
-  bool InternalInit();
+  // Validation utility for vorbis-style tag names.
+  static bool IsValidVorbisTagName(nsCString& aName);
+
+  // Utility method to parse and add a vorbis-style comment
+  // to a metadata hash table. Most Ogg-encapsulated codecs
+  // use the vorbis comment format for metadata.
+  static bool AddVorbisComment(MetadataTags* aTags,
+                        const char* aComment,
+                        uint32_t aLength);
 };
 
 class VorbisState : public OggCodecState
 {
 public:
   explicit VorbisState(ogg_page* aBosPage);
   virtual ~VorbisState();
 
@@ -470,16 +465,17 @@ public:
   explicit SkeletonState(ogg_page* aBosPage);
   ~SkeletonState();
 
   nsClassHashtable<nsUint32HashKey, MessageField> mMsgFieldStore;
 
   CodecType GetType() override { return TYPE_SKELETON; }
   bool DecodeHeader(ogg_packet* aPacket) override;
   int64_t Time(int64_t granulepos) override { return -1; }
+  bool Init() override { return true; }
   bool IsHeader(ogg_packet* aPacket) override { return true; }
 
   // Return true if the given time (in milliseconds) is within
   // the presentation time defined in the skeleton track.
   bool IsPresentable(int64_t aTime) { return aTime >= mPresentationTime; }
 
   // Stores the offset of the page on which a keyframe starts,
   // and its presentation time.
@@ -602,39 +598,16 @@ private:
   private:
     nsTArray<nsKeyPoint> mKeyPoints;
   };
 
   // Maps Ogg serialnos to the index-keypoint list.
   nsClassHashtable<nsUint32HashKey, nsKeyFrameIndex> mIndex;
 };
 
-class FlacState : public OggCodecState
-{
-public:
-  explicit FlacState(ogg_page* aBosPage);
-
-  CodecType GetType() override { return TYPE_FLAC; }
-  bool DecodeHeader(ogg_packet* aPacket) override;
-  int64_t Time(int64_t granulepos) override;
-  int64_t PacketDuration(ogg_packet* aPacket) override;
-  bool IsHeader(ogg_packet* aPacket) override;
-  nsresult PageIn(ogg_page* aPage) override;
-
-  // Return a hash table with tag metadata.
-  MetadataTags* GetTags() override;
-
-  const AudioInfo& Info();
-
-private:
-  bool ReconstructFlacGranulepos(void);
-
-  FlacFrameParser mParser;
-};
-
 } // namespace mozilla
 
 // This allows the use of nsAutoRefs for an ogg_packet that properly free the
 // contents of the packet.
 template <>
 class nsAutoRefTraits<ogg_packet> : public nsPointerRefTraits<ogg_packet>
 {
 public:
--- a/dom/media/ogg/OggDecoder.cpp
+++ b/dom/media/ogg/OggDecoder.cpp
@@ -1,85 +1,32 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "MediaPrefs.h"
+#include "mozilla/Preferences.h"
 #include "MediaDecoderStateMachine.h"
 #include "MediaFormatReader.h"
 #include "OggDemuxer.h"
 #include "OggReader.h"
 #include "OggDecoder.h"
-#include "nsContentTypeParser.h"
 
 namespace mozilla {
 
 MediaDecoderStateMachine* OggDecoder::CreateStateMachine()
 {
-  bool useFormatDecoder = MediaPrefs::OggFormatReader();
+  bool useFormatDecoder =
+    Preferences::GetBool("media.format-reader.ogg", true);
   RefPtr<OggDemuxer> demuxer =
     useFormatDecoder ? new OggDemuxer(GetResource()) : nullptr;
   RefPtr<MediaDecoderReader> reader = useFormatDecoder
     ? static_cast<MediaDecoderReader*>(new MediaFormatReader(this, demuxer, GetVideoFrameContainer()))
     : new OggReader(this);
   if (useFormatDecoder) {
     demuxer->SetChainingEvents(&reader->TimedMetadataProducer(),
                                &reader->MediaNotSeekableProducer());
   }
   return new MediaDecoderStateMachine(this, reader);
 }
 
-/* static */
-bool
-OggDecoder::IsEnabled()
-{
-  return MediaPrefs::OggEnabled();
-}
-
-/* static */
-bool
-OggDecoder::CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
-                               const nsAString& aCodecs)
-{
-  if (!IsEnabled()) {
-    return false;
-  }
-
-  const bool isOggAudio = aMIMETypeExcludingCodecs.EqualsASCII("audio/ogg");
-  const bool isOggVideo =
-    aMIMETypeExcludingCodecs.EqualsASCII("video/ogg") ||
-    aMIMETypeExcludingCodecs.EqualsASCII("application/ogg");
-
-  if (!isOggAudio && !isOggVideo) {
-    return false;
-  }
-
-  nsTArray<nsCString> codecMimes;
-  if (aCodecs.IsEmpty()) {
-    // WebM guarantees that the only codecs it contained are vp8, vp9, opus or vorbis.
-    return true;
-  }
-  // Verify that all the codecs specified are ones that we expect that
-  // we can play.
-  nsTArray<nsString> codecs;
-  if (!ParseCodecsString(aCodecs, codecs)) {
-    return false;
-  }
-  for (const nsString& codec : codecs) {
-    if ((IsOpusEnabled() && codec.EqualsLiteral("opus")) ||
-        codec.EqualsLiteral("vorbis") ||
-        (MediaPrefs::FlacInOgg() && codec.EqualsLiteral("flac"))) {
-      continue;
-    }
-    // Note: Only accept Theora in a video content type, not in an audio
-    // content type.
-    if (isOggVideo && codec.EqualsLiteral("theora")) {
-      continue;
-    }
-    // Some unsupported codec.
-    return false;
-  }
-  return true;
-}
-
 } // namespace mozilla
--- a/dom/media/ogg/OggDecoder.h
+++ b/dom/media/ogg/OggDecoder.h
@@ -32,24 +32,16 @@ public:
   // protect the general state with a lock, so we make a special copy and a
   // special-purpose lock. This method may be called on any thread.
   bool IsOggDecoderShutdown() override
   {
     MonitorAutoLock lock(mShutdownBitMonitor);
     return mShutdownBit;
   }
 
-  // Returns true if aMIMEType is a type that we think we can render with the
-  // a platform decoder backend. If aCodecs is non emtpy, it is filled
-  // with a comma-delimited list of codecs to check support for.
-  static bool CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
-                                 const nsAString& aCodecs);
-
-  static bool IsEnabled();
-
 protected:
   void ShutdownBitChanged() override
   {
     MonitorAutoLock lock(mShutdownBitMonitor);
     mShutdownBit = mStateMachineIsShutdown;
   }
 
   Monitor mShutdownBitMonitor;
--- a/dom/media/ogg/OggDemuxer.cpp
+++ b/dom/media/ogg/OggDemuxer.cpp
@@ -5,23 +5,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsError.h"
 #include "MediaDecoderStateMachine.h"
 #include "AbstractMediaDecoder.h"
 #include "OggDemuxer.h"
 #include "OggCodecState.h"
 #include "mozilla/PodOperations.h"
+#include "mozilla/Preferences.h"
 #include "mozilla/SharedThreadPool.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 #include "MediaDataDemuxer.h"
 #include "nsAutoRef.h"
 #include "XiphExtradata.h"
-#include "MediaPrefs.h"
 
 #include <algorithm>
 
 extern mozilla::LazyLogModule gMediaDemuxerLog;
 #define OGG_DEBUG(arg, ...) MOZ_LOG(gMediaDemuxerLog, mozilla::LogLevel::Debug, ("OggDemuxer(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
 
 // Un-comment to enable logging of seek bisections.
 //#define SEEK_LOGGING
@@ -122,25 +122,23 @@ OggDemuxer::InitTrack(MessageField* aMsg
               sLanguage? NS_ConvertUTF8toUTF16(*sLanguage):EmptyString(),
               aEnable);
 }
 
 OggDemuxer::OggDemuxer(MediaResource* aResource)
   : mTheoraState(nullptr)
   , mVorbisState(nullptr)
   , mOpusState(nullptr)
-  , mFlacState(nullptr)
   , mOpusEnabled(MediaDecoder::IsOpusEnabled())
   , mSkeletonState(nullptr)
   , mAudioOggState(aResource)
   , mVideoOggState(aResource)
   , mVorbisSerial(0)
   , mOpusSerial(0)
   , mTheoraSerial(0)
-  , mFlacSerial(0)
   , mOpusPreSkip(0)
   , mIsChained(false)
   , mTimedMetadataEvent(nullptr)
   , mOnSeekableEvent(nullptr)
 {
   MOZ_COUNT_CTOR(OggDemuxer);
   PodZero(&mTheoraInfo);
 }
@@ -170,17 +168,17 @@ OggDemuxer::SetChainingEvents(TimedMetad
   mOnSeekableEvent = aOnSeekableEvent;
 }
 
 
 bool
 OggDemuxer::HasAudio()
 const
 {
-  return mVorbisState || mOpusState || mFlacState;
+  return mVorbisState || mOpusState;
 }
 
 bool
 OggDemuxer::HasVideo()
 const
 {
   return mTheoraState;
 }
@@ -246,37 +244,34 @@ OggDemuxer::HasTrackType(TrackInfo::Trac
 
 OggCodecState*
 OggDemuxer::GetTrackCodecState(TrackInfo::TrackType aType) const
 {
   switch(aType) {
     case TrackInfo::kAudioTrack:
       if (mVorbisState) {
         return mVorbisState;
-      } else if (mOpusState) {
+      } else {
         return mOpusState;
-      } else {
-        return mFlacState;
       }
     case TrackInfo::kVideoTrack:
       return mTheoraState;
     default:
       return 0;
   }
 }
 
 TrackInfo::TrackType
 OggDemuxer::GetCodecStateType(OggCodecState* aState) const
 {
   switch (aState->GetType()) {
     case OggCodecState::TYPE_THEORA:
       return TrackInfo::kVideoTrack;
     case OggCodecState::TYPE_OPUS:
     case OggCodecState::TYPE_VORBIS:
-    case OggCodecState::TYPE_FLAC:
       return TrackInfo::kAudioTrack;
     default:
       return TrackInfo::kUndefinedTrack;
   }
 }
 
 uint32_t
 OggDemuxer::GetNumberTracks(TrackInfo::TrackType aType) const
@@ -462,28 +457,16 @@ OggDemuxer::SetupTargetOpus(OpusState* a
                                                     aHeaders.mHeaderLens[0]);
 
   mOpusState = aOpusState;
   mOpusSerial = aOpusState->mSerial;
   mOpusPreSkip = aOpusState->mPreSkip;
 }
 
 void
-OggDemuxer::SetupTargetFlac(FlacState* aFlacState, OggHeaders& aHeaders)
-{
-  if (mFlacState) {
-    mFlacState->Reset();
-  }
-
-  mInfo.mAudio = aFlacState->Info();
-  mFlacState = aFlacState;
-  mFlacSerial = aFlacState->mSerial;
-}
-
-void
 OggDemuxer::SetupTargetSkeleton()
 {
   // Setup skeleton related information after mVorbisState & mTheroState
   // being set (if they exist).
   if (mSkeletonState) {
     OggHeaders headers;
     if (!HasAudio() && !HasVideo()) {
       // We have a skeleton track, but no audio or video, may as well disable
@@ -569,28 +552,16 @@ OggDemuxer::SetupMediaTracksInfo(const n
 
       if (msgInfo) {
         InitTrack(msgInfo, &mInfo.mAudio, mOpusState == opusState);
       }
 
       mInfo.mAudio.mRate = opusState->mRate;
       mInfo.mAudio.mChannels = opusState->mChannels;
       FillTags(&mInfo.mAudio, opusState->GetTags());
-    } else if (codecState->GetType() == OggCodecState::TYPE_FLAC) {
-      FlacState* flacState = static_cast<FlacState*>(codecState);
-      if (!(mFlacState && mFlacState->mSerial == flacState->mSerial)) {
-        continue;
-      }
-
-      if (msgInfo) {
-        InitTrack(msgInfo, &mInfo.mAudio, mFlacState == flacState);
-      }
-
-      mInfo.mAudio = flacState->Info();
-      FillTags(&mInfo.mAudio, flacState->GetTags());
     }
   }
 }
 
 void
 OggDemuxer::FillTags(TrackInfo* aInfo, MetadataTags* aTags)
 {
   if (!aTags) {
@@ -686,25 +657,16 @@ OggDemuxer::ReadMetadata()
             SetupTargetOpus(opusState, headers);
           } else {
             s->Deactivate();
           }
         } else {
           NS_WARNING("Opus decoding disabled."
                      " See media.opus.enabled in about:config");
         }
-      } else if (MediaPrefs::FlacInOgg() &&
-                 s->GetType() == OggCodecState::TYPE_FLAC &&
-                 ReadHeaders(TrackInfo::kAudioTrack, s, headers)) {
-        if (!mFlacState) {
-          FlacState* flacState = static_cast<FlacState*>(s);
-          SetupTargetFlac(flacState, headers);
-        } else {
-          s->Deactivate();
-        }
       } else if (s->GetType() == OggCodecState::TYPE_SKELETON && !mSkeletonState) {
         mSkeletonState = static_cast<SkeletonState*>(s);
       } else {
         // Deactivate any non-primary bitstreams.
         s->Deactivate();
       }
     }
   }
@@ -768,17 +730,16 @@ OggDemuxer::SetChained() {
 }
 
 bool
 OggDemuxer::ReadOggChain(const media::TimeUnit& aLastEndTime)
 {
   bool chained = false;
   OpusState* newOpusState = nullptr;
   VorbisState* newVorbisState = nullptr;
-  FlacState* newFlacState = nullptr;
   nsAutoPtr<MetadataTags> tags;
 
   if (HasVideo() || HasSkeleton() || !HasAudio()) {
     return false;
   }
 
   ogg_page page;
   if (!ReadOggPage(TrackInfo::kAudioTrack, &page) || !ogg_page_bos(&page)) {
@@ -796,18 +757,16 @@ OggDemuxer::ReadOggChain(const media::Ti
   if (!codecState) {
     return false;
   }
 
   if (mVorbisState && (codecState->GetType() == OggCodecState::TYPE_VORBIS)) {
     newVorbisState = static_cast<VorbisState*>(codecState.get());
   } else if (mOpusState && (codecState->GetType() == OggCodecState::TYPE_OPUS)) {
     newOpusState = static_cast<OpusState*>(codecState.get());
-  } else if (mFlacState && (codecState->GetType() == OggCodecState::TYPE_FLAC)) {
-    newFlacState = static_cast<FlacState*>(codecState.get());
   } else {
     return false;
   }
 
   OggCodecState* state;
 
   mCodecStore.Add(serial, codecState.forget());
   state = mCodecStore.Get(serial);
@@ -857,34 +816,16 @@ OggDemuxer::ReadOggChain(const media::Ti
     mInfo.mAudio.mMimeType = NS_LITERAL_CSTRING("audio/ogg; codec=opus");
     mInfo.mAudio.mRate = newOpusState->mRate;
     mInfo.mAudio.mChannels = newOpusState->mChannels;
 
     chained = true;
     tags = newOpusState->GetTags();
   }
 
-  OggHeaders flacHeaders;
-  if ((newFlacState &&
-       ReadHeaders(TrackInfo::kAudioTrack, newFlacState, flacHeaders)) &&
-      (mFlacState->Info().mRate == newFlacState->Info().mRate) &&
-      (mFlacState->Info().mChannels == newFlacState->Info().mChannels)) {
-
-    SetupTargetFlac(newFlacState, flacHeaders);
-    LOG(LogLevel::Debug, ("New flac ogg link, serial=%d\n", mFlacSerial));
-
-    if (msgInfo) {
-      InitTrack(msgInfo, &mInfo.mAudio, true);
-    }
-
-    mInfo.mAudio = newFlacState->Info();
-    chained = true;
-    tags = newFlacState->GetTags();
-  }
-
   if (chained) {
     SetChained();
     mInfo.mMediaSeekable = false;
     mDecodedAudioDuration += aLastEndTime;
     if (mTimedMetadataEvent) {
       mTimedMetadataEvent->Notify(
         TimedMetadata(mDecodedAudioDuration,
                       Move(tags),
@@ -1111,20 +1052,16 @@ OggDemuxer::GetBuffered(TrackInfo::Track
       if (aType == TrackInfo::kAudioTrack && mVorbisState &&
           serial == mVorbisSerial) {
         startTime = VorbisState::Time(&mVorbisInfo, granulepos);
         NS_ASSERTION(startTime > 0, "Must have positive start time");
       } else if (aType == TrackInfo::kAudioTrack && mOpusState &&
                  serial == mOpusSerial) {
         startTime = OpusState::Time(mOpusPreSkip, granulepos);
         NS_ASSERTION(startTime > 0, "Must have positive start time");
-      } else if (aType == TrackInfo::kAudioTrack && mFlacState &&
-                 serial == mFlacSerial) {
-        startTime = mFlacState->Time(granulepos);
-        NS_ASSERTION(startTime > 0, "Must have positive start time");
       } else if (aType == TrackInfo::kVideoTrack && mTheoraState &&
                  serial == mTheoraSerial) {
         startTime = TheoraState::Time(&mTheoraInfo, granulepos);
         NS_ASSERTION(startTime > 0, "Must have positive start time");
       } else if (mCodecStore.Contains(serial)) {
         // Stream is not the theora or vorbis stream we're playing,
         // but is one that we have header data for.
         startOffset += page.header_len + page.body_len;
@@ -2070,18 +2007,16 @@ OggDemuxer::SeekBisection(TrackInfo::Tra
           ogg_int64_t granulepos = ogg_page_granulepos(&page);
 
           if (aType == TrackInfo::kAudioTrack &&
               granulepos > 0 && audioTime == -1) {
             if (mVorbisState && serial == mVorbisState->mSerial) {
               audioTime = mVorbisState->Time(granulepos);
             } else if (mOpusState && serial == mOpusState->mSerial) {
               audioTime = mOpusState->Time(granulepos);
-            } else if (mFlacState && serial == mFlacState->mSerial) {
-              audioTime = mFlacState->Time(granulepos);
             }
           }
 
           if (aType == TrackInfo::kVideoTrack &&
               granulepos > 0 && serial == mTheoraState->mSerial &&
               videoTime == -1) {
             videoTime = mTheoraState->Time(granulepos);
           }
--- a/dom/media/ogg/OggDemuxer.h
+++ b/dom/media/ogg/OggDemuxer.h
@@ -215,17 +215,16 @@ private:
   // Fills aTracks with the serial numbers of each active stream, for use by
   // various SkeletonState functions.
   void BuildSerialList(nsTArray<uint32_t>& aTracks);
 
   // Setup target bitstreams for decoding.
   void SetupTargetTheora(TheoraState* aTheoraState, OggHeaders& aHeaders);
   void SetupTargetVorbis(VorbisState* aVorbisState, OggHeaders& aHeaders);
   void SetupTargetOpus(OpusState* aOpusState, OggHeaders& aHeaders);
-  void SetupTargetFlac(FlacState* aFlacState, OggHeaders& aHeaders);
   void SetupTargetSkeleton();
   void SetupMediaTracksInfo(const nsTArray<uint32_t>& aSerials);
   void FillTags(TrackInfo* aInfo, MetadataTags* aTags);
 
   // Compute an ogg page's checksum
   ogg_uint32_t GetPageChecksum(ogg_page* aPage);
 
   // Get the end time of aEndOffset. This is the playback position we'd reach
@@ -260,19 +259,16 @@ private:
 
   // Decode state of the Vorbis bitstream we're decoding, if we have audio.
   VorbisState* mVorbisState;
 
   // Decode state of the Opus bitstream we're decoding, if we have one.
   OpusState* mOpusState;
 
   // Get the bitstream decode state for the given track type
-  // Decode state of the Flac bitstream we're decoding, if we have one.
-  FlacState* mFlacState;
-
   OggCodecState* GetTrackCodecState(TrackInfo::TrackType aType) const;
   TrackInfo::TrackType GetCodecStateType(OggCodecState* aState) const;
 
   // Represents the user pref media.opus.enabled at the time our
   // contructor was called. We can't check it dynamically because
   // we're not on the main thread;
   bool mOpusEnabled;
 
@@ -301,18 +297,16 @@ private:
   // decoder thread and read on the main thread. All reading on the main
   // thread must be done after metadataloaded. We can't use the existing
   // data in the codec states due to threading issues. You must check the
   // associated mTheoraState or mVorbisState pointer is non-null before
   // using this codec data.
   uint32_t mVorbisSerial;
   uint32_t mOpusSerial;
   uint32_t mTheoraSerial;
-  uint32_t mFlacSerial;
-
   vorbis_info mVorbisInfo;
   int mOpusPreSkip;
   th_info mTheoraInfo;
 
   Maybe<int64_t> mStartTime;
 
   // Booleans to indicate if we have audio and/or video data
   bool HasVideo() const;
deleted file mode 100644
index de99616ecebe6107c33156c1c5513ef007b4e63d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
--- a/dom/media/test/A4.ogv^headers^
+++ /dev/null
@@ -1,1 +0,0 @@
-Cache-Control: no-store
deleted file mode 100755
index 01152142a9dee57668871abb7e7ec617f12967ca..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
--- a/dom/media/test/flac-noheader-s16.flac^headers^
+++ /dev/null
@@ -1,1 +0,0 @@
-Cache-Control: no-store
deleted file mode 100644
index 1ba5e27a154eef9d90208e611630ceb9d70c7c57..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
--- a/dom/media/test/flac-s24.flac^headers^
+++ /dev/null
@@ -1,1 +0,0 @@
-Cache-Control: no-store
--- a/dom/media/test/manifest.js
+++ b/dom/media/test/manifest.js
@@ -31,17 +31,16 @@ var gSmallTests = [
   { name:"small-shot-mp3.mp4", type:"audio/mp4; codecs=mp3", duration:0.34 },
   { name:"small-shot.flac", type:"audio/flac", duration:0.197 },
   { name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 },
   { name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.266 },
   { name:"seek.webm", type:"video/webm", width:320, height:240, duration:3.966 },
   { name:"vp9.webm", type:"video/webm", width:320, height:240, duration:4 },
   { name:"detodos.opus", type:"audio/ogg; codecs=opus", duration:2.9135 },
   { name:"gizmo.mp4", type:"video/mp4", width:560, height:320, duration:5.56 },
-  { name:"flac-s24.flac", type:"audio/flac", duration:4.04 },
   { name:"bogus.duh", type:"bogus/duh" }
 ];
 
 if (SpecialPowers.Services.appinfo.name != "B2G") {
   // We only run mochitests on b2g desktop and b2g emulator. The 3gp codecs
   // aren't present on desktop, and the emulator codecs (which are different
   // from the real device codecs) don't pass all of our tests, so we need
   // to disable them.
@@ -82,17 +81,17 @@ var gPlayedTests = [
   { name:"big.wav", type:"audio/x-wav", duration:9.0 },
   { name:"seek.ogv", type:"video/ogg", duration:3.966 },
   { name:"seek.webm", type:"video/webm", duration:3.966 },
   { name:"gizmo.mp4", type:"video/mp4", duration:5.56 },
   { name:"owl.mp3", type:"audio/mpeg", duration:3.343 },
   // Disable vbr.mp3 to see if it reduces the error of AUDCLNT_E_CPUUSAGE_EXCEEDED.
   // See bug 1110922 comment 26.
   //{ name:"vbr.mp3", type:"audio/mpeg", duration:10.0 },
-  { name:"bug495794.ogg", type:"audio/ogg", duration:0.3 },
+  { name:"bug495794.ogg", type:"audio/ogg", duration:0.3 }
 ];
 
 // Used by test_mozLoadFrom.  Need one test file per decoder backend, plus
 // anything for testing clone-specific bugs.
 var cloneKey = Math.floor(Math.random()*100000000);
 var gCloneTests = gSmallTests.concat([
   { name:"bug520908.ogv", type:"video/ogg", duration:0.2 },
   // short-video is more like 1s, so if you load this twice you'll get an unexpected duration
@@ -115,17 +114,16 @@ var gPausedAfterEndedTests = gSmallTests
 
 // Test the mozHasAudio property, and APIs that detect different kinds of
 // tracks
 var gTrackTests = [
   { name:"big.wav", type:"audio/x-wav", duration:9.278982, size:102444, hasAudio:true, hasVideo:false },
   { name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.266, size:28942, hasAudio:false, hasVideo:true },
   { name:"short-video.ogv", type:"video/ogg", duration:1.081, hasAudio:true, hasVideo:true },
   { name:"seek.webm", type:"video/webm", duration:3.966, size:215529, hasAudio:false, hasVideo:true },
-  { name:"flac-s24.flac", type:"audio/flac", duration:4.04, hasAudio:true, hasVideo:false },
   { name:"bogus.duh", type:"bogus/duh" }
 ];
 
 var gClosingConnectionsTest = [
   { name:"seek.ogv", type:"video/ogg", duration:3.966 }
 ];
 
 // Used by any media recorder test. Need one test file per decoder backend
@@ -269,23 +267,16 @@ var gPlayTests = [
   // in that offset. This test case makes sure that ID3 exclusion holds.
   { name:"huge-id3.mp3", type:"audio/mpeg", duration:1.00 },
   // A truncated VBR MP3 with just enough frames to keep most decoders happy.
   // The Xing header reports the length of the file to be around 10 seconds, but
   // there is really only one second worth of data. We want MP3FrameParser to
   // trust the header, so this should be reported as 10 seconds.
   { name:"vbr-head.mp3", type:"audio/mpeg", duration:10.00 },
 
-  // A flac file where the STREAMINFO block was removed.
-  // It is necessary to parse the file to find an audio frame instead.
-  { name:"flac-noheader-s16.flac", type:"audio/flac", duration:4.0 },
-  { name:"flac-s24.flac", type:"audio/flac", duration:4.04 },
-  // Ogg with theora video and flac audio.
-  { name:"A4.ogv", type:"video/ogg", width:320, height:240, duration:3.13 },
-
   // Invalid file
   { name:"bogus.duh", type:"bogus/duh", duration:Number.NaN },
 ];
 
 var gSeekToNextFrameTests = [
   // Test playback of a WebM file with vp9 video
   { name:"vp9.webm", type:"video/webm", duration:4 },
   { name:"vp9cake.webm", type:"video/webm", duration:7.966 },
@@ -764,25 +755,16 @@ var gMetadataTests = [
   },
   { name:"wave_metadata_bad_utf8.wav", tags: {
       name:"歌曲名稱",
       comments:"註解",
     }
   },
   { name:"wavedata_u8.wav", tags: { }
   },
-  { name:"flac-s24.flac", tags: {
-      ALBUM:"Seascapes",
-      TITLE:"(La Mer) - II. Jeux de vagues. Allegro",
-      COMPOSER:"Debussy, Claude",
-      TRACKNUMBER:"2/9",
-      DISCNUMBER:"1/1",
-      encoder:"Lavf57.41.100",
-    }
-  },
 ];
 
 // Test files for Encrypted Media Extensions
 var gEMETests = [
   {
     name:"video-only with 2 keys",
     tracks: [
       {
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -26,18 +26,16 @@ subsuite = media
 skip-if = buildapp == 'mulet' || android_version == '18'
 support-files =
   16bit_wave_extrametadata.wav
   16bit_wave_extrametadata.wav^headers^
   320x240.ogv
   320x240.ogv^headers^
   448636.ogv
   448636.ogv^headers^
-  A4.ogv
-  A4.ogv^headers^
   VID_0001.ogg
   VID_0001.ogg^headers^
   allowed.sjs
   audio-gaps.ogg
   audio-gaps.ogg^headers^
   audio-overhang.ogg
   audio-overhang.ogg^headers^
   audio.wav
@@ -408,20 +406,16 @@ support-files =
   detodos.webm
   detodos.webm^headers^
   dirac.ogg
   dirac.ogg^headers^
   dynamic_redirect.sjs
   dynamic_resource.sjs
   eme.js
   file_access_controls.html
-  flac-s24.flac
-  flac-s24.flac^headers^
-  flac-noheader-s16.flac
-  flac-noheader-s16.flac^headers^
   fragment_noplay.js
   fragment_play.js
   gizmo.mp4
   gizmo.mp4^headers^
   huge-id3.mp3
   huge-id3.mp3^headers^
   id3tags.mp3
   id3tags.mp3^headers^
deleted file mode 100644
--- a/media/libstagefright/binding/BitReader.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/* 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 "mp4_demuxer/BitReader.h"
-#include <media/stagefright/foundation/ABitReader.h>
-
-using namespace mozilla;
-using namespace stagefright;
-
-namespace mp4_demuxer
-{
-
-BitReader::BitReader(const mozilla::MediaByteBuffer* aBuffer)
-  : mBitReader(new ABitReader(aBuffer->Elements(), aBuffer->Length()))
-  , mSize(aBuffer->Length()) {}
-
-BitReader::BitReader(const uint8_t* aBuffer, size_t aLength)
-  : mBitReader(new ABitReader(aBuffer, aLength))
-  , mSize(aLength) {}
-
-BitReader::~BitReader() {}
-
-uint32_t
-BitReader::ReadBits(size_t aNum)
-{
-  MOZ_ASSERT(aNum <= 32);
-  if (mBitReader->numBitsLeft() < aNum) {
-    return 0;
-  }
-  return mBitReader->getBits(aNum);
-}
-
-// Read unsigned integer Exp-Golomb-coded.
-uint32_t
-BitReader::ReadUE()
-{
-  uint32_t i = 0;
-
-  while (ReadBit() == 0 && i < 32) {
-    i++;
-  }
-  if (i == 32) {
-    // This can happen if the data is invalid, or if it's
-    // short, since ReadBit() will return 0 when it runs
-    // off the end of the buffer.
-    NS_WARNING("Invalid H.264 data");
-    return 0;
-  }
-  uint32_t r = ReadBits(i);
-  r += (1 << i) - 1;
-  return r;
-}
-
-// Read signed integer Exp-Golomb-coded.
-int32_t
-BitReader::ReadSE()
-{
-  int32_t r = ReadUE();
-  if (r & 1) {
-    return (r+1) / 2;
-  } else {
-    return -r / 2;
-  }
-}
-
-uint64_t
-BitReader::ReadU64()
-{
-  uint64_t hi = ReadU32();
-  uint32_t lo = ReadU32();
-  return (hi << 32) | lo;
-}
-
-uint64_t
-BitReader::ReadUTF8()
-{
-  int64_t val = ReadBits(8);
-  uint32_t top = (val & 0x80) >> 1;
-
-  if ((val & 0xc0) == 0x80 || val >= 0xFE) {
-    // error.
-    return -1;
-  }
-  while (val & top) {
-    int tmp = ReadBits(8) - 128;
-    if (tmp >> 6) {
-      // error.
-      return -1;
-    }
-    val = (val << 6) + tmp;
-    top <<= 5;
-  }
-  val &= (top << 1) - 1;
-  return val;
-}
-
-size_t
-BitReader::BitCount() const
-{
-  return mSize * 8 - mBitReader->numBitsLeft();
-}
-
-} // namespace mp4_demuxer
--- a/media/libstagefright/binding/H264.cpp
+++ b/media/libstagefright/binding/H264.cpp
@@ -1,27 +1,83 @@
 /* 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 "mozilla/ArrayUtils.h"
 #include "mozilla/PodOperations.h"
 #include "mp4_demuxer/AnnexB.h"
-#include "mp4_demuxer/BitReader.h"
 #include "mp4_demuxer/ByteReader.h"
 #include "mp4_demuxer/ByteWriter.h"
 #include "mp4_demuxer/H264.h"
 #include <media/stagefright/foundation/ABitReader.h>
 #include <limits>
 
 using namespace mozilla;
 
 namespace mp4_demuxer
 {
 
+class BitReader
+{
+public:
+  explicit BitReader(const mozilla::MediaByteBuffer* aBuffer)
+    : mBitReader(aBuffer->Elements(), aBuffer->Length())
+  {
+  }
+
+  uint32_t ReadBits(size_t aNum)
+  {
+    MOZ_ASSERT(aNum <= 32);
+    if (mBitReader.numBitsLeft() < aNum) {
+      return 0;
+    }
+    return mBitReader.getBits(aNum);
+  }
+
+  uint32_t ReadBit()
+  {
+    return ReadBits(1);
+  }
+
+  // Read unsigned integer Exp-Golomb-coded.
+  uint32_t ReadUE()
+  {
+    uint32_t i = 0;
+
+    while (ReadBit() == 0 && i < 32) {
+      i++;
+    }
+    if (i == 32) {
+      // This can happen if the data is invalid, or if it's
+      // short, since ReadBit() will return 0 when it runs
+      // off the end of the buffer.
+      NS_WARNING("Invalid H.264 data");
+      return 0;
+    }
+    uint32_t r = ReadBits(i);
+    r += (1 << i) - 1;
+    return r;
+  }
+
+  // Read signed integer Exp-Golomb-coded.
+  int32_t ReadSE()
+  {
+    int32_t r = ReadUE();
+    if (r & 1) {
+      return (r+1) / 2;
+    } else {
+      return -r / 2;
+    }
+  }
+
+private:
+  stagefright::ABitReader mBitReader;
+};
+
 SPSData::SPSData()
 {
   PodZero(this);
   // Default values when they aren't defined as per ITU-T H.264 (2014/02).
   chroma_format_idc = 1;
   video_format = 5;
   colour_primaries = 2;
   transfer_characteristics = 2;
deleted file mode 100644
--- a/media/libstagefright/binding/include/mp4_demuxer/BitReader.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* 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/. */
-
-#ifndef BIT_READER_H_
-#define BIT_READER_H_
-
-#include "nsAutoPtr.h"
-#include "MediaData.h"
-
-namespace stagefright { class ABitReader; }
-
-namespace mp4_demuxer
-{
-
-class BitReader
-{
-public:
-  explicit BitReader(const mozilla::MediaByteBuffer* aBuffer);
-  BitReader(const uint8_t* aBuffer, size_t aLength);
-  ~BitReader();
-  uint32_t ReadBits(size_t aNum);
-  uint32_t ReadBit() { return ReadBits(1); }
-  uint32_t ReadU32() { return ReadBits(32); }
-  uint64_t ReadU64();
-
-  // Read the UTF-8 sequence and convert it to its 64-bit UCS-4 encoded form.
-  // Return 0xfffffffffffffff if sequence was invalid.
-  uint64_t ReadUTF8();
-  // Read unsigned integer Exp-Golomb-coded.
-  uint32_t ReadUE();
-  // Read signed integer Exp-Golomb-coded.
-  int32_t ReadSE();
-
-  // Return the number of bits parsed so far;
-  size_t BitCount() const;
-
-private:
-  nsAutoPtr<stagefright::ABitReader> mBitReader;
-  const size_t mSize;
-};
-
-} // namespace mp4_demuxer
-
-#endif // BIT_READER_H_
\ No newline at end of file
--- a/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h
@@ -267,16 +267,17 @@ public:
       return 0;
     }
     return mozilla::BigEndian::readInt64(ptr);
   }
 
   const uint8_t* Peek(size_t aCount)
   {
     if (aCount > mRemaining) {
+      MOZ_ASSERT(false);
       return nullptr;
     }
     return mPtr;
   }
 
   const uint8_t* Seek(size_t aOffset)
   {
     if (aOffset >= mLength) {
--- a/media/libstagefright/moz.build
+++ b/media/libstagefright/moz.build
@@ -47,17 +47,16 @@ if CONFIG['OS_TARGET'] != 'Android':
         'system/core/liblog/logprint.c',
     ]
 
 EXPORTS.mp4_demuxer += [
     'binding/include/mp4_demuxer/Adts.h',
     'binding/include/mp4_demuxer/AnnexB.h',
     'binding/include/mp4_demuxer/Atom.h',
     'binding/include/mp4_demuxer/AtomType.h',
-    'binding/include/mp4_demuxer/BitReader.h',
     'binding/include/mp4_demuxer/BufferStream.h',
     'binding/include/mp4_demuxer/ByteReader.h',
     'binding/include/mp4_demuxer/ByteWriter.h',
     'binding/include/mp4_demuxer/DecoderData.h',
     'binding/include/mp4_demuxer/H264.h',
     'binding/include/mp4_demuxer/Index.h',
     'binding/include/mp4_demuxer/Interval.h',
     'binding/include/mp4_demuxer/MoofParser.h',
@@ -83,17 +82,16 @@ SOURCES += [
 if CONFIG['MOZ_RUST']:
     EXPORTS += [
         'binding/include/mp4parse.h',
     ]
 
 UNIFIED_SOURCES += [
     'binding/Adts.cpp',
     'binding/AnnexB.cpp',
-    'binding/BitReader.cpp',
     'binding/Box.cpp',
     'binding/BufferStream.cpp',
     'binding/DecoderData.cpp',
     'binding/H264.cpp',
     'binding/Index.cpp',
     'binding/MoofParser.cpp',
     'binding/MP4Metadata.cpp',
     'binding/ResourceStream.cpp',
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -547,18 +547,16 @@ pref("media.mediasource.mp4.enabled", tr
 pref("media.mediasource.webm.enabled", false);
 #else
 pref("media.mediasource.webm.enabled", true);
 #endif
 pref("media.mediasource.webm.audio.enabled", true);
 
 // Use new MediaFormatReader architecture for plain ogg.
 pref("media.format-reader.ogg", true);
-pref("media.flac.enabled", true);
-pref("media.ogg.flac.enabled", true);
 
 pref("media.benchmark.vp9.threshold", 150);
 pref("media.benchmark.frames", 300);
 pref("media.benchmark.timeout", 1000);
 
 #ifdef MOZ_WEBSPEECH
 pref("media.webspeech.recognition.enable", false);
 pref("media.webspeech.synth.enabled", false);
--- a/netwerk/mime/nsMimeTypes.h
+++ b/netwerk/mime/nsMimeTypes.h
@@ -82,17 +82,16 @@
 #define AUDIO_MP3                           "audio/mpeg"
 #define AUDIO_MP4                           "audio/mp4"
 #define AUDIO_AMR                           "audio/amr"
 #define AUDIO_FLAC                          "audio/flac"
 #define AUDIO_3GPP                          "audio/3gpp"
 #define AUDIO_3GPP2                         "audio/3gpp2"
 #define AUDIO_MIDI                          "audio/x-midi"
 #define AUDIO_MATROSKA                      "audio/x-matroska"
-#define AUDIO_FLAC                          "audio/flac"
 
 #define BINARY_OCTET_STREAM                 "binary/octet-stream"
 
 #define IMAGE_GIF                           "image/gif"
 #define IMAGE_JPEG                          "image/jpeg"
 #define IMAGE_JPG                           "image/jpg"
 #define IMAGE_PJPEG                         "image/pjpeg"
 #define IMAGE_PNG                           "image/png"
--- a/toolkit/components/mediasniffer/nsMediaSniffer.cpp
+++ b/toolkit/components/mediasniffer/nsMediaSniffer.cpp
@@ -7,17 +7,16 @@
 #include "nsMediaSniffer.h"
 #include "nsIHttpChannel.h"
 #include "nsString.h"
 #include "nsMimeTypes.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/ModuleUtils.h"
 #include "mp3sniff.h"
 #include "nestegg/nestegg.h"
-#include "FlacDemuxer.h"
 
 #include "nsIClassInfoImpl.h"
 #include <algorithm>
 
 // The minimum number of bytes that are needed to attempt to sniff an mp4 file.
 static const unsigned MP4_MIN_BYTES_COUNT = 12;
 // The maximum number of bytes to consider when attempting to sniff a file.
 static const uint32_t MAX_BYTES_SNIFFED = 512;
@@ -29,19 +28,17 @@ static const uint32_t MAX_BYTES_SNIFFED_
 NS_IMPL_ISUPPORTS(nsMediaSniffer, nsIContentSniffer)
 
 nsMediaSnifferEntry nsMediaSniffer::sSnifferEntries[] = {
   // The string OggS, followed by the null byte.
   PATTERN_ENTRY("\xFF\xFF\xFF\xFF\xFF", "OggS", APPLICATION_OGG),
   // The string RIFF, followed by four bytes, followed by the string WAVE
   PATTERN_ENTRY("\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF", "RIFF\x00\x00\x00\x00WAVE", AUDIO_WAV),
   // mp3 with ID3 tags, the string "ID3".
-  PATTERN_ENTRY("\xFF\xFF\xFF", "ID3", AUDIO_MP3),
-  // FLAC with standard header
-  PATTERN_ENTRY("\xFF\xFF\xFF\xFF", "fLaC", AUDIO_FLAC)
+  PATTERN_ENTRY("\xFF\xFF\xFF", "ID3", AUDIO_MP3)
 };
 
 // For a complete list of file types, see http://www.ftyps.com/index.html
 nsMediaSnifferEntry sFtypEntries[] = {
   PATTERN_ENTRY("\xFF\xFF\xFF", "mp4", VIDEO_MP4), // Could be mp41 or mp42.
   PATTERN_ENTRY("\xFF\xFF\xFF", "avc", VIDEO_MP4), // Could be avc1, avc2, ...
   PATTERN_ENTRY("\xFF\xFF\xFF", "3gp", VIDEO_3GPP), // Could be 3gp4, 3gp5, ...
   PATTERN_ENTRY("\xFF\xFF\xFF\xFF", "M4A ", AUDIO_MP4),
@@ -116,21 +113,16 @@ static bool MatchesWebM(const uint8_t* a
 
 // This function implements mp3 sniffing based on parsing
 // packet headers and looking for expected boundaries.
 static bool MatchesMP3(const uint8_t* aData, const uint32_t aLength)
 {
   return mp3_sniff(aData, (long)aLength);
 }
 
-static bool MatchesFLAC(const uint8_t* aData, const uint32_t aLength)
-{
-  return mozilla::FlacDemuxer::FlacSniffer(aData, aLength);
-}
-
 NS_IMETHODIMP
 nsMediaSniffer::GetMIMETypeFromContent(nsIRequest* aRequest,
                                        const uint8_t* aData,
                                        const uint32_t aLength,
                                        nsACString& aSniffedType)
 {
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
   if (channel) {
@@ -180,21 +172,13 @@ nsMediaSniffer::GetMIMETypeFromContent(n
   }
 
   // Bug 950023: 512 bytes are often not enough to sniff for mp3.
   if (MatchesMP3(aData, std::min(aLength, MAX_BYTES_SNIFFED_MP3))) {
     aSniffedType.AssignLiteral(AUDIO_MP3);
     return NS_OK;
   }
 
-  // Flac frames are generally big, often in excess of 24kB.
-  // Using a size of MAX_BYTES_SNIFFED effectively means that we will only
-  // recognize flac content if it starts with a frame.
-  if (MatchesFLAC(aData, clampedLength)) {
-    aSniffedType.AssignLiteral(AUDIO_FLAC);
-    return NS_OK;
-  }
-
   // Could not sniff the media type, we are required to set it to
   // application/octet-stream.
   aSniffedType.AssignLiteral(APPLICATION_OCTET_STREAM);
   return NS_ERROR_NOT_AVAILABLE;
 }