Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MediaKeys.getMetrics() #4837

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sideb0ard
Copy link
Contributor

@sideb0ard sideb0ard commented Feb 4, 2025

b/381298846

Extend MediaKeys API with getMetrics.

This fixes the YTS EME getMetrics test failure, which is one of the golden ATV tests, required for fishfood.

@sideb0ard sideb0ard requested a review from a team as a code owner February 4, 2025 21:56
@sideb0ard sideb0ard requested a review from y4vor February 4, 2025 21:56
@sideb0ard sideb0ard force-pushed the getMetrics branch 2 times, most recently from 3968bb9 to 7298bc4 Compare February 5, 2025 05:03
static_idl_files_in_modules += get_path_info(
[ "//third_party/blink/renderer/modules/mediasource/source_buffer_write_head.idl" ],
"abspath")

# MediaKeys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You could combine these two into a single addition to static_idl_files_in_modules but leave the comments.

@osagie98
Copy link
Contributor

osagie98 commented Feb 5, 2025

LGTM, though you may need to move the idl/implementation somewhere else depending on what Holden/Andrew think

"media_keys_get_metrics.cc",
"media_keys_get_metrics.h",
]
deps += [ "//starboard($starboard_toolchain)" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use //starboard:starboard_group

Copy link
Contributor

@yell0wd0g yell0wd0g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments, looking good.

auto* cdm_context = cdm_context_ref->GetCdmContext();
DCHECK(cdm_context);

auto sbdrm = cdm_context->GetSbDrmSystem();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/sbdrm/sb_drm/ ?


int metrics_size = -1;
const void* metrics = SbDrmGetMetrics(sbdrm, &metrics_size);
DCHECK(metrics_size > 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: DCHECK_GT(metrics_size, 0);

SecureContext,
ImplementedAs=MediaKeysGetMetrics
] partial interface MediaKeys {
[RaisesException] Uint8Array getMetrics();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a DOMString ? It would simplify the conversion.

int metrics_size = -1;
const void* metrics = SbDrmGetMetrics(sbdrm, &metrics_size);
DCHECK(metrics_size > 0);
metrics_results.assign(static_cast<const char*>(metrics), metrics_size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this function signature std::string ...::GetMetrics() { and then here just do return std::string(static_cast<const char*>(metrics), metrics_size); ?

ActiveScriptWrappable,
SecureContext,
ImplementedAs=MediaKeysGetMetrics
] partial interface MediaKeys {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -54,6 +54,10 @@ class PLATFORM_EXPORT WebContentDecryptionModuleImpl
void GetStatusForPolicy(const WebString& min_hdcp_version_string,
WebContentDecryptionModuleResult result) override;

#if BUILDFLAG(USE_STARBOARD_MEDIA)
void GetMetrics(std::string &metrics_results) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a unit test for this? Not sure the mocking capabilities of SbDrmGetMetrics but the CdmAdapter might be a pickle, and perhaps is not injectable.

class MediaKeysGetMetrics {
STATIC_ONLY(MediaKeysGetMetrics);

public:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there's an extra leading space here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this to a cobalt-specific dir as is being done in #4851

namespace blink {

// static
NotShared<DOMUint8Array> MediaKeysGetMetrics::getMetrics(MediaKeys& media_keys, ExceptionState& exception_state) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wrap at 80 characters.

@@ -53,6 +53,10 @@ class BLINK_PLATFORM_EXPORT WebContentDecryptionModule {

virtual void GetStatusForPolicy(const WebString& min_hdcp_version,
WebContentDecryptionModuleResult) = 0;

#if BUILDFLAG(USE_STARBOARD_MEDIA)
virtual void GetMetrics(std::string &metrics_results) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider turning this into pure virtual function if it doesn't break the build.

Also move the '&' to the left of the space, to be consistent to other functions. The same to other instances.

const unsigned char* unsigned_buffer =
reinterpret_cast<const unsigned char*>(metrics.c_str());

return NotShared<DOMUint8Array>(DOMUint8Array::Create(unsigned_buffer, metrics.size()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to make GetMetrics() return a boolean value, and raise an exception when metrics isn't ready. See https://github.com/youtube/cobalt/blob/25.lts.1%2B/cobalt/dom/eme/media_keys.cc#L120 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants