1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/fmp4/MP4Decoder.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "MP4Decoder.h" 1.11 +#include "MP4Reader.h" 1.12 +#include "MediaDecoderStateMachine.h" 1.13 +#include "mozilla/Preferences.h" 1.14 + 1.15 +#ifdef XP_WIN 1.16 +#include "mozilla/WindowsVersion.h" 1.17 +#endif 1.18 +#ifdef MOZ_FFMPEG 1.19 +#include "FFmpegDecoderModule.h" 1.20 +#endif 1.21 + 1.22 +namespace mozilla { 1.23 + 1.24 +MediaDecoderStateMachine* MP4Decoder::CreateStateMachine() 1.25 +{ 1.26 + return new MediaDecoderStateMachine(this, new MP4Reader(this)); 1.27 +} 1.28 + 1.29 +bool 1.30 +MP4Decoder::GetSupportedCodecs(const nsACString& aType, 1.31 + char const *const ** aCodecList) 1.32 +{ 1.33 + if (!IsEnabled()) { 1.34 + return false; 1.35 + } 1.36 + 1.37 + // AAC in M4A. 1.38 + static char const *const aacAudioCodecs[] = { 1.39 + "mp4a.40.2", // AAC-LC 1.40 + // TODO: AAC-HE ? 1.41 + nullptr 1.42 + }; 1.43 + if (aType.EqualsASCII("audio/mp4") || 1.44 + aType.EqualsASCII("audio/x-m4a")) { 1.45 + if (aCodecList) { 1.46 + *aCodecList = aacAudioCodecs; 1.47 + } 1.48 + return true; 1.49 + } 1.50 + 1.51 + // H.264 + AAC in MP4. 1.52 + static char const *const h264Codecs[] = { 1.53 + "avc1.42E01E", // H.264 Constrained Baseline Profile Level 3.0 1.54 + "avc1.42001E", // H.264 Baseline Profile Level 3.0 1.55 + "avc1.58A01E", // H.264 Extended Profile Level 3.0 1.56 + "avc1.4D401E", // H.264 Main Profile Level 3.0 1.57 + "avc1.64001E", // H.264 High Profile Level 3.0 1.58 + "avc1.64001F", // H.264 High Profile Level 3.1 1.59 + "mp4a.40.2", // AAC-LC 1.60 + // TODO: There must be more profiles here? 1.61 + nullptr 1.62 + }; 1.63 + if (aType.EqualsASCII("video/mp4")) { 1.64 + if (aCodecList) { 1.65 + *aCodecList = h264Codecs; 1.66 + } 1.67 + return true; 1.68 + } 1.69 + 1.70 + return false; 1.71 +} 1.72 + 1.73 +static bool 1.74 +IsFFmpegAvailable() 1.75 +{ 1.76 +#ifndef MOZ_FFMPEG 1.77 + return false; 1.78 +#else 1.79 + if (!Preferences::GetBool("media.fragmented-mp4.ffmpeg.enabled", false)) { 1.80 + return false; 1.81 + } 1.82 + 1.83 + // If we can link to FFmpeg, then we can almost certainly play H264 and AAC 1.84 + // with it. 1.85 + return FFmpegDecoderModule::Link(); 1.86 +#endif 1.87 +} 1.88 + 1.89 +static bool 1.90 +HavePlatformMPEGDecoders() 1.91 +{ 1.92 + return Preferences::GetBool("media.fragmented-mp4.use-blank-decoder") || 1.93 +#ifdef XP_WIN 1.94 + // We have H.264/AAC platform decoders on Windows Vista and up. 1.95 + IsVistaOrLater() || 1.96 +#endif 1.97 + IsFFmpegAvailable() || 1.98 + // TODO: Other platforms... 1.99 + false; 1.100 +} 1.101 + 1.102 +/* static */ 1.103 +bool 1.104 +MP4Decoder::IsEnabled() 1.105 +{ 1.106 + return HavePlatformMPEGDecoders() && 1.107 + Preferences::GetBool("media.fragmented-mp4.enabled"); 1.108 +} 1.109 + 1.110 +} // namespace mozilla 1.111 +