summaryrefslogtreecommitdiffstats
path: root/webkit/media/key_systems.cc
blob: 7efbb9ef9ff073340b4b6f028d2dd8f521507875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/media/key_systems.h"

#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"

namespace webkit_media {

namespace {

const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";

struct MediaFormatAndKeySystem {
  const char* mime_type;
  const char* codec;
  const char* key_system;
};

static const MediaFormatAndKeySystem
supported_format_key_system_combinations[] = {
  // TODO(ddorwin): Reconsider based on how usage of this class evolves.
  // For now, this class is stateless, so we do not have the opportunity to
  // build a list using ParseCodecString() like
  // net::MimeUtil::InitializeMimeTypeMaps(). Therfore, the following line must
  // be separate entries.
  // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem },
  { "video/webm", "vorbis", kClearKeyKeySystem },
  { "video/webm", "vp8", kClearKeyKeySystem },
  { "video/webm", "vp8.0", kClearKeyKeySystem },
  { "audio/webm", "vorbis", kClearKeyKeySystem },
  { "video/webm", "", kClearKeyKeySystem },
  { "audio/webm", "", kClearKeyKeySystem }
};

bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type,
                                               const std::string& codec,
                                               const std::string& key_system) {
  for (size_t i = 0;
       i < arraysize(supported_format_key_system_combinations);
       ++i) {
    const MediaFormatAndKeySystem& combination =
        supported_format_key_system_combinations[i];
    if (combination.mime_type == mime_type &&
        combination.codec == codec &&
        combination.key_system == key_system)
      return true;
  }

  return false;
}

}  // namespace

bool IsSupportedKeySystem(const WebKit::WebString& key_system) {
  if (key_system == kClearKeyKeySystem)
    return true;
  return false;
}

bool IsSupportedKeySystemWithMediaMimeType(
    const std::string& mime_type,
    const std::vector<std::string>& codecs,
    const std::string& key_system) {
  if (codecs.empty())
    return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system);

  for (size_t i = 0; i < codecs.size(); ++i) {
    if (!IsSupportedKeySystemWithContainerAndCodec(
            mime_type, codecs[i], key_system))
      return false;
  }

  return true;
}

}  // namespace webkit_media