diff --git a/dom/media/MediaPrefs.h b/dom/media/MediaPrefs.h index b3b9fc903361..012d56b5c6cf 100644 --- a/dom/media/MediaPrefs.h +++ b/dom/media/MediaPrefs.h @@ -150,7 +150,9 @@ private: // 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: diff --git a/dom/media/flac/FlacDecoder.cpp b/dom/media/flac/FlacDecoder.cpp new file mode 100644 index 000000000000..3109713dbecd --- /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 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 diff --git a/dom/media/flac/FlacDecoder.h b/dom/media/flac/FlacDecoder.h new file mode 100644 index 000000000000..304ee62f8b49 --- /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_ diff --git a/dom/media/flac/moz.build b/dom/media/flac/moz.build index 240979fd4b05..6933ded1f958 100644 --- a/dom/media/flac/moz.build +++ b/dom/media/flac/moz.build @@ -5,11 +5,13 @@ # 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', ]