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 "MediaPrefs.h"
8 : #include "MediaContainerType.h"
9 : #include "MediaDecoderStateMachine.h"
10 : #include "MediaFormatReader.h"
11 : #include "OggDemuxer.h"
12 : #include "OggDecoder.h"
13 :
14 : namespace mozilla {
15 :
16 0 : MediaDecoderStateMachine* OggDecoder::CreateStateMachine()
17 : {
18 0 : RefPtr<OggDemuxer> demuxer = new OggDemuxer(mResource);
19 0 : MediaDecoderReaderInit init(this);
20 0 : init.mVideoFrameContainer = GetVideoFrameContainer();
21 0 : mReader = new MediaFormatReader(init, demuxer);
22 0 : demuxer->SetChainingEvents(&mReader->TimedMetadataProducer(),
23 0 : &mReader->MediaNotSeekableProducer());
24 0 : return new MediaDecoderStateMachine(this, mReader);
25 : }
26 :
27 : /* static */
28 : bool
29 0 : OggDecoder::IsSupportedType(const MediaContainerType& aContainerType)
30 : {
31 0 : if (!MediaPrefs::OggEnabled()) {
32 0 : return false;
33 : }
34 :
35 0 : if (aContainerType.Type() != MEDIAMIMETYPE("audio/ogg") &&
36 0 : aContainerType.Type() != MEDIAMIMETYPE("video/ogg") &&
37 0 : aContainerType.Type() != MEDIAMIMETYPE("application/ogg")) {
38 0 : return false;
39 : }
40 :
41 0 : const bool isOggVideo = (aContainerType.Type() != MEDIAMIMETYPE("audio/ogg"));
42 :
43 0 : const MediaCodecs& codecs = aContainerType.ExtendedType().Codecs();
44 0 : if (codecs.IsEmpty()) {
45 : // WebM guarantees that the only codecs it contained are vp8, vp9, opus or vorbis.
46 0 : return true;
47 : }
48 : // Verify that all the codecs specified are ones that we expect that
49 : // we can play.
50 0 : for (const auto& codec : codecs.Range()) {
51 0 : if ((IsOpusEnabled() && codec.EqualsLiteral("opus")) ||
52 0 : codec.EqualsLiteral("vorbis") ||
53 0 : (MediaPrefs::FlacInOgg() && codec.EqualsLiteral("flac"))) {
54 0 : continue;
55 : }
56 : // Note: Only accept Theora in a video container type, not in an audio
57 : // container type.
58 0 : if (isOggVideo && codec.EqualsLiteral("theora")) {
59 0 : continue;
60 : }
61 : // Some unsupported codec.
62 0 : return false;
63 : }
64 0 : return true;
65 : }
66 :
67 : } // namespace mozilla
|