1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "FlacDecoder.h" 8 #include "FlacDemuxer.h" 9 #include "MediaDecoderStateMachine.h" 10 #include "MediaFormatReader.h" 11 #include "MediaPrefs.h" 12 #include "PDMFactory.h" 13 14 namespace mozilla { 15 16 MediaDecoder* Clone(MediaDecoderOwner * aOwner)17FlacDecoder::Clone(MediaDecoderOwner* aOwner) 18 { 19 if (!IsEnabled()) 20 return nullptr; 21 22 return new FlacDecoder(aOwner); 23 } 24 25 MediaDecoderStateMachine* CreateStateMachine()26FlacDecoder::CreateStateMachine() 27 { 28 RefPtr<MediaDecoderReader> reader = 29 new MediaFormatReader(this, new FlacDemuxer(GetResource())); 30 return new MediaDecoderStateMachine(this, reader); 31 } 32 33 /* static */ bool IsEnabled()34FlacDecoder::IsEnabled() 35 { 36 #ifdef MOZ_FFVPX 37 return MediaPrefs::FlacEnabled(); 38 #elif defined(MOZ_FFMPEG) 39 RefPtr<PDMFactory> platform = new PDMFactory(); 40 return MediaPrefs::FlacEnabled() && platform->SupportsMimeType(NS_LITERAL_CSTRING("audio/flac"), 41 /* DecoderDoctorDiagnostics* */ nullptr); 42 #else 43 // Until bug 1295886 is fixed. 44 return false; 45 #endif 46 } 47 48 /* static */ bool CanHandleMediaType(const nsACString & aType,const nsAString & aCodecs)49FlacDecoder::CanHandleMediaType(const nsACString& aType, 50 const nsAString& aCodecs) 51 { 52 return IsEnabled() && 53 (aType.EqualsASCII("audio/flac") || aType.EqualsASCII("audio/x-flac") || 54 aType.EqualsASCII("application/x-flac")); 55 } 56 57 } // namespace mozilla 58