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
|
|
|
|
2017-08-16 08:19:39 +03:00
|
|
|
#include "OggDecoder.h"
|
2016-08-04 10:14:28 +03:00
|
|
|
#include "MediaPrefs.h"
|
2017-01-18 03:59:03 +03:00
|
|
|
#include "MediaContainerType.h"
|
2017-08-16 08:19:39 +03:00
|
|
|
#include "MediaDecoder.h"
|
2018-03-06 19:43:57 +03:00
|
|
|
#include "nsMimeTypes.h"
|
2010-04-27 12:53:44 +04:00
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-03-06 19:43:57 +03:00
|
|
|
if (aContainerType.Type() != MEDIAMIMETYPE(AUDIO_OGG) &&
|
|
|
|
aContainerType.Type() != MEDIAMIMETYPE(VIDEO_OGG) &&
|
2017-01-18 03:59:03 +03:00
|
|
|
aContainerType.Type() != MEDIAMIMETYPE("application/ogg")) {
|
2016-08-04 10:14:28 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-06 19:43:57 +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()) {
|
2017-08-15 08:52:17 +03:00
|
|
|
if ((MediaDecoder::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
|