-
Notifications
You must be signed in to change notification settings - Fork 134
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
sideb0ard
wants to merge
1
commit into
youtube:main
Choose a base branch
from
sideb0ard:getMetrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
third_party/blink/renderer/modules/cobalt/encryptedmedia/BUILD.gn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import("//third_party/blink/renderer/modules/modules.gni") | ||
|
||
blink_modules_sources("encryptedmedia") { | ||
sources = [ | ||
"media_keys_get_metrics.cc", | ||
"media_keys_get_metrics.h", | ||
] | ||
deps = | ||
[ "//third_party/blink/renderer/modules/encryptedmedia:encryptedmedia" ] | ||
} |
24 changes: 24 additions & 0 deletions
24
third_party/blink/renderer/modules/cobalt/encryptedmedia/media_keys_extensions.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// https://w3c.github.io/encrypted-media/#mediakeys-interface | ||
|
||
[ | ||
Exposed=Window, | ||
ActiveScriptWrappable, | ||
SecureContext, | ||
ImplementedAs=MediaKeysGetMetrics | ||
] partial interface MediaKeys { | ||
[RaisesException] DOMString getMetrics(); | ||
}; |
31 changes: 31 additions & 0 deletions
31
third_party/blink/renderer/modules/cobalt/encryptedmedia/media_keys_get_metrics.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "third_party/blink/renderer/modules/cobalt/encryptedmedia/media_keys_get_metrics.h" | ||
|
||
#include "third_party/blink/renderer/modules/encryptedmedia/media_keys.h" | ||
|
||
#if !BUILDFLAG(USE_STARBOARD_MEDIA) | ||
#error "This file only works with Starboard media" | ||
#endif // !BUILDFLAG(USE_STARBOARD_MEDIA) | ||
|
||
namespace blink { | ||
|
||
// static | ||
WebString MediaKeysGetMetrics::getMetrics(MediaKeys& media_keys, | ||
ExceptionState& exception_state) { | ||
return media_keys.getMetrics(exception_state); | ||
} | ||
|
||
} // namespace blink |
35 changes: 35 additions & 0 deletions
35
third_party/blink/renderer/modules/cobalt/encryptedmedia/media_keys_get_metrics.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_COBALT_ENCRYPTEDMEDIA_MEDIA_KEYS_GET_METRICS_H_ | ||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_COBALT_ENCRYPTEDMEDIA_MEDIA_KEYS_GET_METRICS_H_ | ||
|
||
#include "build/build_config.h" | ||
#include "third_party/blink/public/platform/web_string.h" | ||
#include "third_party/blink/renderer/platform/bindings/exception_state.h" | ||
|
||
namespace blink { | ||
|
||
class MediaKeys; | ||
|
||
class MediaKeysGetMetrics { | ||
STATIC_ONLY(MediaKeysGetMetrics); | ||
|
||
public: | ||
static WebString getMetrics(MediaKeys&, ExceptionState&); | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_COBALT_ENCRYPTEDMEDIA_MEDIA_KEYS_GET_METRICS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
third_party/blink/renderer/platform/media/web_content_decryption_module_impl_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "third_party/blink/renderer/platform/media/web_content_decryption_module_impl.h" | ||
|
||
#include "base/functional/bind.h" | ||
#include "base/logging.h" | ||
#include "base/run_loop.h" | ||
#include "base/test/task_environment.h" | ||
#include "media/starboard/starboard_cdm_factory.h" | ||
#include "testing/gmock/include/gmock/gmock.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "third_party/blink/renderer/platform/media/cdm_session_adapter.h" | ||
|
||
namespace blink { | ||
|
||
const char* kKeyType = "com.widevine.alpha"; | ||
|
||
class WebContentDecryptionModuleImplTest : public testing::Test { | ||
public: | ||
void SetUp() override {} | ||
|
||
void OnWebCdmCreated(WebContentDecryptionModule* cdm, | ||
const std::string& error_message) { | ||
cdm_ = cdm; | ||
} | ||
|
||
protected: | ||
media::CdmConfig cdm_config_{kKeyType, false, false, false}; | ||
std::unique_ptr<media::StarboardCdmFactory> cdm_factory_; | ||
scoped_refptr<CdmSessionAdapter> adapter_; | ||
WebContentDecryptionModule* cdm_{nullptr}; | ||
|
||
base::WeakPtrFactory<WebContentDecryptionModuleImplTest> weak_factory_{this}; | ||
}; | ||
|
||
TEST_F(WebContentDecryptionModuleImplTest, IsValid) { | ||
EXPECT_NE(cdm_factory_, nullptr); | ||
|
||
base::test::TaskEnvironment task_environment_; | ||
cdm_factory_ = std::make_unique<media::StarboardCdmFactory>(); | ||
adapter_ = new CdmSessionAdapter(); | ||
|
||
adapter_->CreateCdm( | ||
cdm_factory_.get(), cdm_config_, | ||
base::BindOnce(&WebContentDecryptionModuleImplTest::OnWebCdmCreated, | ||
weak_factory_.GetWeakPtr())); | ||
base::RunLoop().RunUntilIdle(); | ||
|
||
EXPECT_NE(cdm_, nullptr); | ||
} | ||
|
||
} // namespace blink |
43 changes: 43 additions & 0 deletions
43
third_party/blink/web_tests/media/encrypted-media/encrypted-media-getmetrics.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>MediaKeys.getMetrics</title> | ||
<script src="encrypted-media-utils.js"></script> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<video></video> | ||
<script> | ||
async_test(function(test) | ||
{ | ||
const opts = [{ | ||
initDataTypes: ['cenc', 'sinf', 'keyids'], | ||
encryptionScheme: 'cbcs-1-9', | ||
videoCapabilities: [{ | ||
contentType: 'video/mp4; codecs="avc1.640028"' | ||
}], | ||
audioCapabilities: [{ | ||
contentType: 'audio/mp4; codecs="mp4a.40.2"' | ||
}], | ||
}]; | ||
|
||
opts[0].videoCapabilities[0].robustness = 'SW_SECURE_DECODE'; | ||
opts[0].audioCapabilities[0].robustness = 'SW_SECURE_CRYPTO'; | ||
|
||
return navigator.requestMediaKeySystemAccess('com.widevine.alpha', opts) | ||
.then(function(keySystemAccess) { | ||
return keySystemAccess.createMediaKeys(); | ||
}) | ||
.then(function (mediaKeys) { | ||
assert_not_equals(mediaKeys, null); | ||
const blob = mediaKeys.getMetrics(); | ||
assert_true(blob.length > 0); | ||
test.done(); | ||
}).catch(function(error) { | ||
forceTestFailureFromPromise(test, error); | ||
}); | ||
}, 'GetMetrics from MediaKeys.'); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
micro-nit: We could use here more GTest style:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the suggestion, I'll amend this unittest in follow-up PR for b/395905524