Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/ogg/OggDecoder.cpp
Line
Count
Source (jump to first uncovered line)
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 "OggDecoder.h"
8
#include "MediaContainerType.h"
9
#include "MediaDecoder.h"
10
#include "mozilla/StaticPrefs.h"
11
#include "nsMimeTypes.h"
12
13
namespace mozilla {
14
15
/* static */
16
bool
17
OggDecoder::IsSupportedType(const MediaContainerType& aContainerType)
18
0
{
19
0
  if (!StaticPrefs::MediaOggEnabled()) {
20
0
    return false;
21
0
  }
22
0
23
0
  if (aContainerType.Type() != MEDIAMIMETYPE(AUDIO_OGG) &&
24
0
      aContainerType.Type() != MEDIAMIMETYPE(VIDEO_OGG) &&
25
0
      aContainerType.Type() != MEDIAMIMETYPE("application/ogg")) {
26
0
    return false;
27
0
  }
28
0
29
0
  const bool isOggVideo = (aContainerType.Type() != MEDIAMIMETYPE(AUDIO_OGG));
30
0
31
0
  const MediaCodecs& codecs = aContainerType.ExtendedType().Codecs();
32
0
  if (codecs.IsEmpty()) {
33
0
    // Ogg guarantees that the only codecs it contained are supported.
34
0
    return true;
35
0
  }
36
0
  // Verify that all the codecs specified are ones that we expect that
37
0
  // we can play.
38
0
  for (const auto& codec : codecs.Range()) {
39
0
    if ((MediaDecoder::IsOpusEnabled() && codec.EqualsLiteral("opus")) ||
40
0
        codec.EqualsLiteral("vorbis") ||
41
0
        codec.EqualsLiteral("flac")) {
42
0
      continue;
43
0
    }
44
0
    // Note: Only accept Theora in a video container type, not in an audio
45
0
    // container type.
46
0
    if (isOggVideo && codec.EqualsLiteral("theora")) {
47
0
      continue;
48
0
    }
49
0
    // Some unsupported codec.
50
0
    return false;
51
0
  }
52
0
  return true;
53
0
}
54
55
/* static */ nsTArray<UniquePtr<TrackInfo>>
56
OggDecoder::GetTracksInfo(const MediaContainerType& aType)
57
0
{
58
0
  nsTArray<UniquePtr<TrackInfo>> tracks;
59
0
  if (!IsSupportedType(aType)) {
60
0
    return tracks;
61
0
  }
62
0
63
0
  const MediaCodecs& codecs = aType.ExtendedType().Codecs();
64
0
  if (codecs.IsEmpty()) {
65
0
    // Codecs must be specified for ogg as it can't be implied.
66
0
    return tracks;
67
0
  }
68
0
69
0
  for (const auto& codec : codecs.Range()) {
70
0
    if (codec.EqualsLiteral("opus") || codec.EqualsLiteral("vorbis") ||
71
0
        codec.EqualsLiteral("flac")) {
72
0
      tracks.AppendElement(
73
0
        CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters(
74
0
          NS_LITERAL_CSTRING("audio/") + NS_ConvertUTF16toUTF8(codec), aType));
75
0
    } else {
76
0
      MOZ_ASSERT(codec.EqualsLiteral("theora"));
77
0
      tracks.AppendElement(
78
0
        CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters(
79
0
          NS_LITERAL_CSTRING("video/") + NS_ConvertUTF16toUTF8(codec), aType));
80
0
    }
81
0
  }
82
0
  return tracks;
83
0
}
84
85
} // namespace mozilla