Skip to content

Commit

Permalink
b/328305808
Browse files Browse the repository at this point in the history
Allows playback of encrypted content by wrapping SbDrm in a media::ContentDecryptionModule interface.
  • Loading branch information
sideb0ard committed Nov 13, 2024
1 parent d0a9e4b commit e0c5fec
Show file tree
Hide file tree
Showing 14 changed files with 859 additions and 602 deletions.
4 changes: 4 additions & 0 deletions content/renderer/media/media_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
#include "media/cdm/fuchsia/fuchsia_cdm_factory.h"
#include "media/fuchsia/video/fuchsia_decoder_factory.h"
#include "media/mojo/clients/mojo_fuchsia_cdm_provider.h"
#elif BUILDFLAG(USE_STARBOARD_MEDIA)
#include "media/starboard/starboard_cdm_factory.h"
#elif BUILDFLAG(ENABLE_MOJO_CDM)
#include "media/mojo/clients/mojo_cdm_factory.h" // nogncheck
#else
Expand Down Expand Up @@ -855,6 +857,8 @@ media::CdmFactory* MediaFactory::GetCdmFactory() {
DCHECK(interface_broker_);
cdm_factory_ = std::make_unique<media::FuchsiaCdmFactory>(
std::make_unique<media::MojoFuchsiaCdmProvider>(interface_broker_));
#elif BUILDFLAG(USE_STARBOARD_MEDIA)
cdm_factory_ = std::make_unique<media::StarboardCdmFactory>();
#elif BUILDFLAG(ENABLE_MOJO_CDM)
cdm_factory_ =
std::make_unique<media::MojoCdmFactory>(GetMediaInterfaceFactory());
Expand Down
4 changes: 4 additions & 0 deletions content/renderer/media/media_permission_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ void MediaPermissionDispatcher::OnPermissionStatus(
PermissionStatusCB permission_status_cb = std::move(iter->second);
requests_.erase(iter);

#if BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(permission_status_cb).Run(true);
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(permission_status_cb)
.Run(status == blink::mojom::PermissionStatus::GRANTED);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
}

void MediaPermissionDispatcher::OnConnectionError() {
Expand Down
65 changes: 61 additions & 4 deletions content/shell/renderer/shell_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
#include "third_party/blink/public/web/web_view.h"
#include "v8/include/v8.h"

#if BUILDFLAG(USE_STARBOARD_MEDIA)
#include "starboard/media.h"
#include "components/cdm/renderer/widevine_key_system_info.h"
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

#if BUILDFLAG(ENABLE_PLUGINS)
#include "ppapi/shared_impl/ppapi_switches.h" // nogncheck
#endif
Expand All @@ -49,10 +54,6 @@
#include "media/base/media_switches.h"
#endif

#if BUILDFLAG(USE_STARBOARD_MEDIA)
#include "starboard/media.h"
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

namespace content {

namespace {
Expand Down Expand Up @@ -270,6 +271,60 @@ ShellContentRendererClient::CreateURLLoaderThrottleProvider(
return std::make_unique<ShellContentRendererUrlLoaderThrottleProvider>();
}

#if BUILDFLAG(USE_STARBOARD_MEDIA)
media::SupportedCodecs GetStarboardEmeSupportedCodecs() {
media::SupportedCodecs codecs = ::media::EME_CODEC_AAC |
::media::EME_CODEC_AVC1 |
::media::EME_CODEC_VP9_PROFILE0 |
::media::EME_CODEC_VP9_PROFILE2 |
::media::EME_CODEC_VP8 |
::media::EME_CODEC_OPUS |
::media::EME_CODEC_VORBIS |
::media::EME_CODEC_MPEG_H_AUDIO |
::media::EME_CODEC_FLAC |
::media::EME_CODEC_HEVC_PROFILE_MAIN |
::media::EME_CODEC_HEVC_PROFILE_MAIN10 |
::media::EME_CODEC_AV1 |
::media::EME_CODEC_AC3 |
::media::EME_CODEC_EAC3;
return codecs;
}

void AddStarboardCmaKeySystems(::media::KeySystemInfos* key_system_infos) {
media::SupportedCodecs codecs = GetStarboardEmeSupportedCodecs();

#if BUILDFLAG(IS_ANDROID)
using Robustness = cdm::WidevineKeySystemInfo::Robustness;

const base::flat_set<media::EncryptionScheme> kEncryptionSchemes = {
media::EncryptionScheme::kCenc, media::EncryptionScheme::kCbcs};

const base::flat_set<media::CdmSessionType> kSessionTypes = {
media::CdmSessionType::kTemporary};

key_system_infos->emplace_back(new cdm::WidevineKeySystemInfo(
codecs, // Regular codecs.
kEncryptionSchemes, // Encryption schemes.
kSessionTypes, // Session types.
codecs, // Hardware secure codecs.
kEncryptionSchemes, // Hardware secure encryption schemes.
kSessionTypes, // Hardware secure session types.
Robustness::HW_SECURE_CRYPTO, // Max audio robustness.
Robustness::HW_SECURE_ALL, // Max video robustness.
media::EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state.
media::EmeFeatureSupport::ALWAYS_ENABLED)); // Distinctive identifier.
#endif
}

void ShellContentRendererClient::GetSupportedKeySystems(
media::GetSupportedKeySystemsCB cb) {
media::KeySystemInfos key_systems;
AddStarboardCmaKeySystems(&key_systems);
std::move(cb).Run(std::move(key_systems));
}

#else // BUILDFLAG(USE_STARBOARD_MEDIA)

#if BUILDFLAG(ENABLE_MOJO_CDM)
void ShellContentRendererClient::GetSupportedKeySystems(
media::GetSupportedKeySystemsCB cb) {
Expand All @@ -281,6 +336,8 @@ void ShellContentRendererClient::GetSupportedKeySystems(
}
#endif

#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

#if BUILDFLAG(USE_STARBOARD_MEDIA)
// TODO(b/376542844): Eliminate the usage of hardcoded MIME string once we
// support to query codec capabilities with configs.
Expand Down
7 changes: 7 additions & 0 deletions media/base/cdm_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ MediaCryptoContext* CdmContext::GetMediaCryptoContext() {
}
#endif

#if BUILDFLAG(USE_STARBOARD_MEDIA)
SbDrmSystem CdmContext::GetSbDrmSystem() {
return kSbDrmSystemInvalid;
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)


#if BUILDFLAG(IS_FUCHSIA)
FuchsiaCdmContext* CdmContext::GetFuchsiaCdmContext() {
return nullptr;
Expand Down
7 changes: 7 additions & 0 deletions media/base/cdm_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class ChromeOsCdmContext;
}
#endif

#if BUILDFLAG(USE_STARBOARD_MEDIA)
#include "starboard/drm.h"
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
namespace media {

class CallbackRegistration;
Expand Down Expand Up @@ -112,6 +115,10 @@ class MEDIA_EXPORT CdmContext {
virtual MediaCryptoContext* GetMediaCryptoContext();
#endif

#if BUILDFLAG(USE_STARBOARD_MEDIA)
virtual SbDrmSystem GetSbDrmSystem();
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

#if BUILDFLAG(IS_FUCHSIA)
// Returns FuchsiaCdmContext interface when the context is backed by Fuchsia
// CDM. Otherwise returns nullptr.
Expand Down
6 changes: 6 additions & 0 deletions media/starboard/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ source_set("starboard") {
"decoder_buffer_allocator.cc",
"decoder_buffer_allocator.h",
"decoder_buffer_memory_info.h",
"starboard_cdm.cc",
"starboard_cdm.h",
"starboard_cdm_factory.cc",
"starboard_cdm_factory.h",
"starboard_cdm_session.cc",
"starboard_cdm_session.h",
"starboard_memory_allocator.h",
]
}
Expand Down
Loading

0 comments on commit e0c5fec

Please sign in to comment.