2010-04-27 12:53:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-27 12:53:44 +04:00
|
|
|
|
2016-08-04 10:14:28 +03:00
|
|
|
#include "MediaPrefs.h"
|
2017-01-18 03:59:03 +03:00
|
|
|
#include "MediaContainerType.h"
|
2012-11-14 23:46:40 +04:00
|
|
|
#include "MediaDecoderStateMachine.h"
|
2016-07-21 04:34:42 +03:00
|
|
|
#include "MediaFormatReader.h"
|
|
|
|
#include "OggDemuxer.h"
|
2012-11-14 23:46:40 +04:00
|
|
|
#include "OggDecoder.h"
|
2010-04-27 12:53:44 +04:00
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoderStateMachine* OggDecoder::CreateStateMachine()
|
2010-04-27 12:53:44 +04:00
|
|
|
{
|
2016-11-09 03:54:41 +03:00
|
|
|
RefPtr<OggDemuxer> demuxer = new OggDemuxer(GetResource());
|
|
|
|
RefPtr<MediaFormatReader> reader =
|
|
|
|
new MediaFormatReader(this, demuxer, GetVideoFrameContainer());
|
|
|
|
demuxer->SetChainingEvents(&reader->TimedMetadataProducer(),
|
|
|
|
&reader->MediaNotSeekableProducer());
|
2016-07-21 04:34:42 +03:00
|
|
|
return new MediaDecoderStateMachine(this, reader);
|
2010-04-27 12:53:44 +04:00
|
|
|
}
|
2012-11-14 23:45:33 +04:00
|
|
|
|
2016-08-04 10:14:28 +03:00
|
|
|
/* static */
|
|
|
|
bool
|
2017-01-18 03:59:03 +03:00
|
|
|
OggDecoder::IsSupportedType(const MediaContainerType& aContainerType)
|
2016-08-04 10:14:28 +03:00
|
|
|
{
|
2017-01-01 04:08:36 +03:00
|
|
|
if (!MediaPrefs::OggEnabled()) {
|
2016-08-04 10:14:28 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
if (aContainerType.Type() != MEDIAMIMETYPE("audio/ogg") &&
|
|
|
|
aContainerType.Type() != MEDIAMIMETYPE("video/ogg") &&
|
|
|
|
aContainerType.Type() != MEDIAMIMETYPE("application/ogg")) {
|
2016-08-04 10:14:28 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
const bool isOggVideo = (aContainerType.Type() != MEDIAMIMETYPE("audio/ogg"));
|
2017-01-01 04:08:36 +03:00
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
const MediaCodecs& codecs = aContainerType.ExtendedType().Codecs();
|
2017-01-01 04:08:36 +03:00
|
|
|
if (codecs.IsEmpty()) {
|
2016-08-04 10:14:28 +03:00
|
|
|
// WebM guarantees that the only codecs it contained are vp8, vp9, opus or vorbis.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Verify that all the codecs specified are ones that we expect that
|
|
|
|
// we can play.
|
2017-01-01 04:08:36 +03:00
|
|
|
for (const auto& codec : codecs.Range()) {
|
2016-08-04 10:14:28 +03:00
|
|
|
if ((IsOpusEnabled() && codec.EqualsLiteral("opus")) ||
|
2016-08-04 10:21:53 +03:00
|
|
|
codec.EqualsLiteral("vorbis") ||
|
|
|
|
(MediaPrefs::FlacInOgg() && codec.EqualsLiteral("flac"))) {
|
2016-08-04 10:14:28 +03:00
|
|
|
continue;
|
|
|
|
}
|
2017-01-18 03:59:03 +03:00
|
|
|
// Note: Only accept Theora in a video container type, not in an audio
|
|
|
|
// container type.
|
2016-08-04 10:14:28 +03:00
|
|
|
if (isOggVideo && codec.EqualsLiteral("theora")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Some unsupported codec.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
} // namespace mozilla
|