michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "MP4Decoder.h" michael@0: #include "MP4Reader.h" michael@0: #include "MediaDecoderStateMachine.h" michael@0: #include "mozilla/Preferences.h" michael@0: michael@0: #ifdef XP_WIN michael@0: #include "mozilla/WindowsVersion.h" michael@0: #endif michael@0: #ifdef MOZ_FFMPEG michael@0: #include "FFmpegDecoderModule.h" michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: michael@0: MediaDecoderStateMachine* MP4Decoder::CreateStateMachine() michael@0: { michael@0: return new MediaDecoderStateMachine(this, new MP4Reader(this)); michael@0: } michael@0: michael@0: bool michael@0: MP4Decoder::GetSupportedCodecs(const nsACString& aType, michael@0: char const *const ** aCodecList) michael@0: { michael@0: if (!IsEnabled()) { michael@0: return false; michael@0: } michael@0: michael@0: // AAC in M4A. michael@0: static char const *const aacAudioCodecs[] = { michael@0: "mp4a.40.2", // AAC-LC michael@0: // TODO: AAC-HE ? michael@0: nullptr michael@0: }; michael@0: if (aType.EqualsASCII("audio/mp4") || michael@0: aType.EqualsASCII("audio/x-m4a")) { michael@0: if (aCodecList) { michael@0: *aCodecList = aacAudioCodecs; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: // H.264 + AAC in MP4. michael@0: static char const *const h264Codecs[] = { michael@0: "avc1.42E01E", // H.264 Constrained Baseline Profile Level 3.0 michael@0: "avc1.42001E", // H.264 Baseline Profile Level 3.0 michael@0: "avc1.58A01E", // H.264 Extended Profile Level 3.0 michael@0: "avc1.4D401E", // H.264 Main Profile Level 3.0 michael@0: "avc1.64001E", // H.264 High Profile Level 3.0 michael@0: "avc1.64001F", // H.264 High Profile Level 3.1 michael@0: "mp4a.40.2", // AAC-LC michael@0: // TODO: There must be more profiles here? michael@0: nullptr michael@0: }; michael@0: if (aType.EqualsASCII("video/mp4")) { michael@0: if (aCodecList) { michael@0: *aCodecList = h264Codecs; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: return false; michael@0: } michael@0: michael@0: static bool michael@0: IsFFmpegAvailable() michael@0: { michael@0: #ifndef MOZ_FFMPEG michael@0: return false; michael@0: #else michael@0: if (!Preferences::GetBool("media.fragmented-mp4.ffmpeg.enabled", false)) { michael@0: return false; michael@0: } michael@0: michael@0: // If we can link to FFmpeg, then we can almost certainly play H264 and AAC michael@0: // with it. michael@0: return FFmpegDecoderModule::Link(); michael@0: #endif michael@0: } michael@0: michael@0: static bool michael@0: HavePlatformMPEGDecoders() michael@0: { michael@0: return Preferences::GetBool("media.fragmented-mp4.use-blank-decoder") || michael@0: #ifdef XP_WIN michael@0: // We have H.264/AAC platform decoders on Windows Vista and up. michael@0: IsVistaOrLater() || michael@0: #endif michael@0: IsFFmpegAvailable() || michael@0: // TODO: Other platforms... michael@0: false; michael@0: } michael@0: michael@0: /* static */ michael@0: bool michael@0: MP4Decoder::IsEnabled() michael@0: { michael@0: return HavePlatformMPEGDecoders() && michael@0: Preferences::GetBool("media.fragmented-mp4.enabled"); michael@0: } michael@0: michael@0: } // namespace mozilla michael@0: