Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 "mozilla/Preferences.h"
8 : #ifdef MOZ_AV1
9 : #include "AOMDecoder.h"
10 : #endif
11 : #include "MediaContainerType.h"
12 : #include "MediaDecoderStateMachine.h"
13 : #include "WebMDemuxer.h"
14 : #include "WebMDecoder.h"
15 : #include "VideoUtils.h"
16 :
17 : namespace mozilla {
18 :
19 0 : MediaDecoderStateMachine* WebMDecoder::CreateStateMachine()
20 : {
21 0 : MediaDecoderReaderInit init(this);
22 0 : init.mVideoFrameContainer = GetVideoFrameContainer();
23 0 : mReader = new MediaFormatReader(init, new WebMDemuxer(mResource));
24 0 : return new MediaDecoderStateMachine(this, mReader);
25 : }
26 :
27 : /* static */
28 : bool
29 0 : WebMDecoder::IsSupportedType(const MediaContainerType& aContainerType)
30 : {
31 0 : if (!Preferences::GetBool("media.webm.enabled")) {
32 0 : return false;
33 : }
34 :
35 0 : bool isVideo = aContainerType.Type() == MEDIAMIMETYPE("video/webm");
36 0 : if (aContainerType.Type() != MEDIAMIMETYPE("audio/webm") && !isVideo) {
37 0 : return false;
38 : }
39 :
40 0 : const MediaCodecs& codecs = aContainerType.ExtendedType().Codecs();
41 0 : if (codecs.IsEmpty()) {
42 : // WebM guarantees that the only codecs it contained are vp8, vp9, opus or vorbis.
43 0 : return true;
44 : }
45 : // Verify that all the codecs specified are ones that we expect that
46 : // we can play.
47 0 : for (const auto& codec : codecs.Range()) {
48 0 : if (codec.EqualsLiteral("opus") || codec.EqualsLiteral("vorbis")) {
49 0 : continue;
50 : }
51 : // Note: Only accept VP8/VP9 in a video container type, not in an audio
52 : // container type.
53 0 : if (isVideo &&
54 0 : (codec.EqualsLiteral("vp8") || codec.EqualsLiteral("vp8.0") ||
55 0 : codec.EqualsLiteral("vp9") || codec.EqualsLiteral("vp9.0"))) {
56 0 : continue;
57 : }
58 : #ifdef MOZ_AV1
59 0 : if (isVideo && AOMDecoder::IsSupportedCodec(codec)) {
60 0 : continue;
61 : }
62 : #endif
63 : // Some unsupported codec.
64 0 : return false;
65 : }
66 0 : return true;
67 : }
68 :
69 : void
70 0 : WebMDecoder::GetMozDebugReaderData(nsACString& aString)
71 : {
72 : // This is definitely a MediaFormatReader. See CreateStateMachine() above.
73 0 : auto reader = static_cast<MediaFormatReader*>(mReader.get());
74 0 : if (reader) {
75 0 : reader->GetMozDebugReaderData(aString);
76 : }
77 0 : }
78 :
79 : } // namespace mozilla
80 :
|