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"
|
2017-01-18 03:59:03 +03:00
|
|
|
#include "MediaContainerType.h"
|
2017-08-16 08:19:39 +03:00
|
|
|
#include "MediaDecoder.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_media.h"
|
2018-08-06 18:37:46 +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 */
|
2017-01-18 03:59:03 +03:00
|
|
|
bool OggDecoder::IsSupportedType(const MediaContainerType& aContainerType) {
|
2019-06-28 07:09:05 +03:00
|
|
|
if (!StaticPrefs::media_ogg_enabled()) {
|
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()) {
|
2018-06-04 19:34:38 +03:00
|
|
|
// Ogg guarantees that the only codecs it contained are supported.
|
2016-08-04 10:14:28 +03:00
|
|
|
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") || 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;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
nsTArray<UniquePtr<TrackInfo>> OggDecoder::GetTracksInfo(
|
2018-06-07 17:47:41 +03:00
|
|
|
const MediaContainerType& aType) {
|
|
|
|
nsTArray<UniquePtr<TrackInfo>> tracks;
|
|
|
|
if (!IsSupportedType(aType)) {
|
|
|
|
return tracks;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MediaCodecs& codecs = aType.ExtendedType().Codecs();
|
|
|
|
if (codecs.IsEmpty()) {
|
|
|
|
// Codecs must be specified for ogg as it can't be implied.
|
|
|
|
return tracks;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& codec : codecs.Range()) {
|
|
|
|
if (codec.EqualsLiteral("opus") || codec.EqualsLiteral("vorbis") ||
|
|
|
|
codec.EqualsLiteral("flac")) {
|
|
|
|
tracks.AppendElement(
|
|
|
|
CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters(
|
2020-07-01 11:29:29 +03:00
|
|
|
"audio/"_ns + NS_ConvertUTF16toUTF8(codec), aType));
|
2018-06-07 17:47:41 +03:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(codec.EqualsLiteral("theora"));
|
|
|
|
tracks.AppendElement(
|
|
|
|
CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters(
|
2020-07-01 11:29:29 +03:00
|
|
|
"video/"_ns + NS_ConvertUTF16toUTF8(codec), aType));
|
2018-06-07 17:47:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return tracks;
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
} // namespace mozilla
|