chrome_key_systems.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// found in the LICENSE file.
4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/renderer/media/chrome_key_systems.h"
6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include <string>
8d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
9d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "base/logging.h"
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/strings/string16.h"
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/strings/string_split.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/common/render_messages.h"
14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "content/public/renderer/render_thread.h"
15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// The following must be after widevine_cdm_version.h.
19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include <gnu/libc-version.h>
22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "base/version.h"
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(OS_ANDROID)
26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/common/encrypted_media_messages_android.h"
27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
29d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)using content::KeySystemInfo;
30d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
3168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kAudioWebM[] = "audio/webm";
3268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kVideoWebM[] = "video/webm";
3368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kVorbis[] = "vorbis";
3468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kVorbisVP8[] = "vorbis,vp8,vp8.0";
35d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
3668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#if defined(USE_PROPRIETARY_CODECS)
3768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kAudioMp4[] = "audio/mp4";
3868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kVideoMp4[] = "video/mp4";
3968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kMp4a[] = "mp4a";
408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#if defined(WIDEVINE_CDM_AVAILABLE)
418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const char kAvc1Avc3[] = "avc1,avc3";
428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif  // WIDEVINE_CDM_AVAILABLE
438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const char kMp4aAvc1Avc3[] = "mp4a,avc1,avc3";
4468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#endif  // defined(USE_PROPRIETARY_CODECS)
45d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(ENABLE_PEPPER_CDMS)
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)static bool IsPepperCdmRegistered(
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const std::string& pepper_type,
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    std::vector<base::string16>* additional_param_names,
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    std::vector<base::string16>* additional_param_values) {
51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  bool is_registered = false;
52d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  content::RenderThread::Get()->Send(
53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      new ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType(
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          pepper_type,
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          &is_registered,
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          additional_param_names,
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          additional_param_values));
58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return is_registered;
60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
61d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
62d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// External Clear Key (used for testing).
63d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)static void AddExternalClearKey(
64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    std::vector<KeySystemInfo>* concrete_key_systems) {
65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static const char kExternalClearKeyKeySystem[] =
66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      "org.chromium.externalclearkey";
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static const char kExternalClearKeyPepperType[] =
68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      "application/x-ppapi-clearkey-cdm";
69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::vector<base::string16> additional_param_names;
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::vector<base::string16> additional_param_values;
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (!IsPepperCdmRegistered(kExternalClearKeyPepperType,
731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             &additional_param_names,
741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             &additional_param_values)) {
75d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return;
761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  KeySystemInfo info(kExternalClearKeyKeySystem);
79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(USE_PROPRIETARY_CODECS)
83d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1Avc3));
85d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(USE_PROPRIETARY_CODECS)
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  info.pepper_type = kExternalClearKeyPepperType;
87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  concrete_key_systems->push_back(info);
894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // A key system that Chrome thinks is supported by ClearKeyCdm, but actually
914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // will be refused by ClearKeyCdm. This is to test the CDM initialization
924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // failure case.
934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  info.key_system += ".initializefail";
944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  concrete_key_systems->push_back(info);
95d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
96d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(ENABLE_PEPPER_CDMS)
97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
98d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
99d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(WIDEVINE_CDM_AVAILABLE)
100d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)enum WidevineCdmType {
101d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  WIDEVINE,
102d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  WIDEVINE_HR,
10368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#if defined(OS_ANDROID)
10468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  WIDEVINE_HR_NON_COMPOSITING,
10568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#endif
106d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)};
107d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
108d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Defines bitmask values used to specify supported codecs.
109d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Each value represents a codec within a specific container.
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The mask values are stored in a SupportedCodecs.
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)typedef uint32 SupportedCodecs;
1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)enum SupportedCodecMasks {
1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  NO_CODECS = 0,
114d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  WEBM_VP8_AND_VORBIS = 1 << 0,
115d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(USE_PROPRIETARY_CODECS)
116d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  MP4_AAC = 1 << 1,
117d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  MP4_AVC1 = 1 << 2,
118d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(USE_PROPRIETARY_CODECS)
119d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)};
120d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
121d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(OS_ANDROID)
122d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#define COMPILE_ASSERT_MATCHING_ENUM(name) \
123d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  COMPILE_ASSERT(static_cast<int>(name) == \
124d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                 static_cast<int>(android::name), \
125d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                 mismatching_enums)
126d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)COMPILE_ASSERT_MATCHING_ENUM(WEBM_VP8_AND_VORBIS);
127d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)COMPILE_ASSERT_MATCHING_ENUM(MP4_AAC);
128d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)COMPILE_ASSERT_MATCHING_ENUM(MP4_AVC1);
129d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#undef COMPILE_ASSERT_MATCHING_ENUM
130d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)static const uint8 kWidevineUuid[16] = {
132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
133d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED };
134d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#else
135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)static bool IsWidevineHrSupported() {
136d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // TODO(jrummell): Need to call CheckPlatformState() but it is
137d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // asynchronous, and needs to be done in the browser.
138d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return false;
139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
140d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif
141d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
142d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Return |name|'s parent key system.
143d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)static std::string GetDirectParentName(std::string name) {
144d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  int last_period = name.find_last_of('.');
145d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DCHECK_GT(last_period, 0);
146d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return name.substr(0, last_period);
147d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
148d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
149d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)static void AddWidevineWithCodecs(
150d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    WidevineCdmType widevine_cdm_type,
151d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    SupportedCodecs supported_codecs,
152d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    std::vector<KeySystemInfo>* concrete_key_systems) {
153d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
154d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  KeySystemInfo info(kWidevineKeySystem);
155d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
156d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  switch (widevine_cdm_type) {
157d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    case WIDEVINE:
158d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      // For standard Widevine, add parent name.
159d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      info.parent_key_system = GetDirectParentName(kWidevineKeySystem);
160d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      break;
161d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    case WIDEVINE_HR:
162d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      info.key_system.append(".hr");
163d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      break;
16468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#if defined(OS_ANDROID)
16568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    case WIDEVINE_HR_NON_COMPOSITING:
16668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      info.key_system.append(".hrnoncompositing");
167d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      break;
16868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#endif
169d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    default:
170d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      NOTREACHED();
171d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
172d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
173d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (supported_codecs & WEBM_VP8_AND_VORBIS) {
174d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
175d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
176d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
177d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
178d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(USE_PROPRIETARY_CODECS)
179d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (supported_codecs & MP4_AAC)
180d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
181d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
182d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (supported_codecs & MP4_AVC1) {
1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const char* video_codecs =
1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        (supported_codecs & MP4_AAC) ? kMp4aAvc1Avc3 : kAvc1Avc3;
185d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs));
186d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
187d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(USE_PROPRIETARY_CODECS)
188d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
189d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(ENABLE_PEPPER_CDMS)
190d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  info.pepper_type = kWidevineCdmPluginMimeType;
191d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#elif defined(OS_ANDROID)
192d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid));
193d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(ENABLE_PEPPER_CDMS)
194d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
195d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  concrete_key_systems->push_back(info);
196d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
197d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
198d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(ENABLE_PEPPER_CDMS)
1991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// When the adapter is registered, a name-value pair is inserted in
2001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// additional_param_* that lists the supported codecs. The name is "codecs" and
2011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// the value is a comma-delimited list of codecs.
2021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// This function finds "codecs" and parses the value into the vector |codecs|.
2031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Converts the codec strings to UTF-8 since we only expect ASCII strings and
2041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// this simplifies the rest of the code in this file.
2051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void GetSupportedCodecs(
2061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const std::vector<base::string16>& additional_param_names,
2071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const std::vector<base::string16>& additional_param_values,
2081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    std::vector<std::string>* codecs) {
2091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(codecs->empty());
2101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK_EQ(additional_param_names.size(), additional_param_values.size());
2111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  for (size_t i = 0; i < additional_param_names.size(); ++i) {
2121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (additional_param_names[i] ==
2131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) {
2141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const base::string16& codecs_string16 = additional_param_values[i];
2151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      std::string codecs_string;
2161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (!base::UTF16ToUTF8(codecs_string16.c_str(),
2171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             codecs_string16.length(),
2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             &codecs_string)) {
2191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        DLOG(WARNING) << "Non-UTF-8 codecs string.";
2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        // Continue using the best effort conversion.
2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      }
2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::SplitString(codecs_string,
2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                        kCdmSupportedCodecsValueDelimiter,
2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                        codecs);
2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      break;
2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
230d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)static void AddPepperBasedWidevine(
231d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    std::vector<KeySystemInfo>* concrete_key_systems) {
232d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
233d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  Version glibc_version(gnu_get_libc_version());
234d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DCHECK(glibc_version.IsValid());
235d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION))
236d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return;
237d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
238d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::vector<base::string16> additional_param_names;
2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::vector<base::string16> additional_param_values;
2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType,
2421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             &additional_param_names,
2431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             &additional_param_values)) {
244d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    DVLOG(1) << "Widevine CDM is not currently available.";
245d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return;
246d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
247d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
2481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::vector<std::string> codecs;
2491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  GetSupportedCodecs(additional_param_names, additional_param_values, &codecs);
250d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
2511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  SupportedCodecs supported_codecs = NO_CODECS;
2521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  for (size_t i = 0; i < codecs.size(); ++i) {
2531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // TODO(ddorwin): Break up VP8 and Vorbis. For now, "vp8" implies both.
2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (codecs[i] == kCdmSupportedCodecVp8)
2551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      supported_codecs |= WEBM_VP8_AND_VORBIS;
256d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(USE_PROPRIETARY_CODECS)
2571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (codecs[i] == kCdmSupportedCodecAac)
2581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      supported_codecs |= MP4_AAC;
2591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (codecs[i] == kCdmSupportedCodecAvc1)
2601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      supported_codecs |= MP4_AVC1;
261d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(USE_PROPRIETARY_CODECS)
2621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
263d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
264d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems);
265d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
266d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (IsWidevineHrSupported())
267d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems);
268d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
269d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#elif defined(OS_ANDROID)
270d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)static void AddAndroidWidevine(
271d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    std::vector<KeySystemInfo>* concrete_key_systems) {
27268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  SupportedKeySystemRequest request;
27368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  SupportedKeySystemResponse response;
274d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
275d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  request.uuid.insert(request.uuid.begin(), kWidevineUuid,
276d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                      kWidevineUuid + arraysize(kWidevineUuid));
277d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(USE_PROPRIETARY_CODECS)
278d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  request.codecs = static_cast<android::SupportedCodecs>(
279d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      android::MP4_AAC | android::MP4_AVC1);
280d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(USE_PROPRIETARY_CODECS)
281d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  content::RenderThread::Get()->Send(
282d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      new ChromeViewHostMsg_GetSupportedKeySystems(request, &response));
283d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DCHECK_EQ(response.compositing_codecs >> 3, 0) << "unrecognized codec";
284d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DCHECK_EQ(response.non_compositing_codecs >> 3, 0) << "unrecognized codec";
28568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  if (response.compositing_codecs != android::NO_SUPPORTED_CODECS) {
286d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    AddWidevineWithCodecs(
287d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        WIDEVINE,
288d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        static_cast<SupportedCodecs>(response.compositing_codecs),
289d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        concrete_key_systems);
290d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
291d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
29268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  if (response.non_compositing_codecs != android::NO_SUPPORTED_CODECS) {
293d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    AddWidevineWithCodecs(
29468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)        WIDEVINE_HR_NON_COMPOSITING,
295d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        static_cast<SupportedCodecs>(response.non_compositing_codecs),
296d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        concrete_key_systems);
297d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
298d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
299d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(ENABLE_PEPPER_CDMS)
300d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // defined(WIDEVINE_CDM_AVAILABLE)
301d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
302d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) {
303d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(ENABLE_PEPPER_CDMS)
304d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  AddExternalClearKey(key_systems_info);
305d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif
306d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
307d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(WIDEVINE_CDM_AVAILABLE)
308d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(ENABLE_PEPPER_CDMS)
309d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  AddPepperBasedWidevine(key_systems_info);
310d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#elif defined(OS_ANDROID)
3111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  AddAndroidWidevine(key_systems_info);
312d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif
313d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif
314d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
315