content/media/fmp4/MP4Decoder.cpp

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "MP4Decoder.h"
michael@0 8 #include "MP4Reader.h"
michael@0 9 #include "MediaDecoderStateMachine.h"
michael@0 10 #include "mozilla/Preferences.h"
michael@0 11
michael@0 12 #ifdef XP_WIN
michael@0 13 #include "mozilla/WindowsVersion.h"
michael@0 14 #endif
michael@0 15 #ifdef MOZ_FFMPEG
michael@0 16 #include "FFmpegDecoderModule.h"
michael@0 17 #endif
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20
michael@0 21 MediaDecoderStateMachine* MP4Decoder::CreateStateMachine()
michael@0 22 {
michael@0 23 return new MediaDecoderStateMachine(this, new MP4Reader(this));
michael@0 24 }
michael@0 25
michael@0 26 bool
michael@0 27 MP4Decoder::GetSupportedCodecs(const nsACString& aType,
michael@0 28 char const *const ** aCodecList)
michael@0 29 {
michael@0 30 if (!IsEnabled()) {
michael@0 31 return false;
michael@0 32 }
michael@0 33
michael@0 34 // AAC in M4A.
michael@0 35 static char const *const aacAudioCodecs[] = {
michael@0 36 "mp4a.40.2", // AAC-LC
michael@0 37 // TODO: AAC-HE ?
michael@0 38 nullptr
michael@0 39 };
michael@0 40 if (aType.EqualsASCII("audio/mp4") ||
michael@0 41 aType.EqualsASCII("audio/x-m4a")) {
michael@0 42 if (aCodecList) {
michael@0 43 *aCodecList = aacAudioCodecs;
michael@0 44 }
michael@0 45 return true;
michael@0 46 }
michael@0 47
michael@0 48 // H.264 + AAC in MP4.
michael@0 49 static char const *const h264Codecs[] = {
michael@0 50 "avc1.42E01E", // H.264 Constrained Baseline Profile Level 3.0
michael@0 51 "avc1.42001E", // H.264 Baseline Profile Level 3.0
michael@0 52 "avc1.58A01E", // H.264 Extended Profile Level 3.0
michael@0 53 "avc1.4D401E", // H.264 Main Profile Level 3.0
michael@0 54 "avc1.64001E", // H.264 High Profile Level 3.0
michael@0 55 "avc1.64001F", // H.264 High Profile Level 3.1
michael@0 56 "mp4a.40.2", // AAC-LC
michael@0 57 // TODO: There must be more profiles here?
michael@0 58 nullptr
michael@0 59 };
michael@0 60 if (aType.EqualsASCII("video/mp4")) {
michael@0 61 if (aCodecList) {
michael@0 62 *aCodecList = h264Codecs;
michael@0 63 }
michael@0 64 return true;
michael@0 65 }
michael@0 66
michael@0 67 return false;
michael@0 68 }
michael@0 69
michael@0 70 static bool
michael@0 71 IsFFmpegAvailable()
michael@0 72 {
michael@0 73 #ifndef MOZ_FFMPEG
michael@0 74 return false;
michael@0 75 #else
michael@0 76 if (!Preferences::GetBool("media.fragmented-mp4.ffmpeg.enabled", false)) {
michael@0 77 return false;
michael@0 78 }
michael@0 79
michael@0 80 // If we can link to FFmpeg, then we can almost certainly play H264 and AAC
michael@0 81 // with it.
michael@0 82 return FFmpegDecoderModule::Link();
michael@0 83 #endif
michael@0 84 }
michael@0 85
michael@0 86 static bool
michael@0 87 HavePlatformMPEGDecoders()
michael@0 88 {
michael@0 89 return Preferences::GetBool("media.fragmented-mp4.use-blank-decoder") ||
michael@0 90 #ifdef XP_WIN
michael@0 91 // We have H.264/AAC platform decoders on Windows Vista and up.
michael@0 92 IsVistaOrLater() ||
michael@0 93 #endif
michael@0 94 IsFFmpegAvailable() ||
michael@0 95 // TODO: Other platforms...
michael@0 96 false;
michael@0 97 }
michael@0 98
michael@0 99 /* static */
michael@0 100 bool
michael@0 101 MP4Decoder::IsEnabled()
michael@0 102 {
michael@0 103 return HavePlatformMPEGDecoders() &&
michael@0 104 Preferences::GetBool("media.fragmented-mp4.enabled");
michael@0 105 }
michael@0 106
michael@0 107 } // namespace mozilla
michael@0 108

mercurial