Bug 1195723: [flac] P8. Add flac MediaDecoder. r?kamidphish draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 17 Aug 2016 15:42:18 +1000
changeset 404117 37be6439a7e6c09fe4af78abd4e7b60d4cde978f
parent 404116 e3e376b18febf0122096393d81a7e02f02e1bfe9
child 404118 fd0311a345c4c3517b48a367c8d224e3fb840da8
push id27118
push userbmo:jyavenard@mozilla.com
push dateMon, 22 Aug 2016 22:58:57 +0000
reviewerskamidphish
bugs1195723
milestone51.0a1
Bug 1195723: [flac] P8. Add flac MediaDecoder. r?kamidphish MozReview-Commit-ID: BQ9fERFEFcg
dom/media/MediaPrefs.h
dom/media/flac/FlacDecoder.cpp
dom/media/flac/FlacDecoder.h
dom/media/flac/moz.build
--- a/dom/media/MediaPrefs.h
+++ b/dom/media/MediaPrefs.h
@@ -142,17 +142,19 @@ private:
   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;
new file mode 100644
--- /dev/null
+++ b/dom/media/flac/FlacDecoder.cpp
@@ -0,0 +1,52 @@
+/* -*- 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
new file mode 100644
--- /dev/null
+++ b/dom/media/flac/FlacDecoder.h
@@ -0,0 +1,30 @@
+/* -*- 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_
--- a/dom/media/flac/moz.build
+++ b/dom/media/flac/moz.build
@@ -1,20 +1,22 @@
 # -*- 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'