Commit 01d05867 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Use UNENCRYPTED scheme for unencrypted content.

Previously fuchsia.media.cdm didn't support unencrypted blocks in secure
media streams. See fxb/38253 . To workaround that issue
FuchsiaSecureStreamDecryptor had to wait for a valid key_id. This issue
is fixed now: CDM API now supports ENCRYPTION_SCHEME_UNENCRYPTED, so the
workaround is no longer needed. Updated FuchsiaSecureStreamDecryptor to
use the new encryption scheme and removed the workaround.

Bug: 1012525
Change-Id: I079948a63c53d7fecdbd877452d1aaa1ec7477e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020537Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Commit-Queue: Yuchen Liu <yucliu@chromium.org>
Commit-Queue: David Dorwin <ddorwin@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735170}
parent 0d76dcaf
...@@ -117,7 +117,7 @@ class FuchsiaCdm::CdmSession { ...@@ -117,7 +117,7 @@ class FuchsiaCdm::CdmSession {
base::OnceCallback<void(base::Optional<CdmPromise::Exception>)>; base::OnceCallback<void(base::Optional<CdmPromise::Exception>)>;
CdmSession(const FuchsiaCdm::SessionCallbacks* callbacks, CdmSession(const FuchsiaCdm::SessionCallbacks* callbacks,
FuchsiaSecureStreamDecryptor::NewKeyCB on_new_key) base::RepeatingClosure on_new_key)
: session_callbacks_(callbacks), on_new_key_(on_new_key) { : session_callbacks_(callbacks), on_new_key_(on_new_key) {
// License session events, e.g. license request message, key status change. // License session events, e.g. license request message, key status change.
// Fuchsia CDM service guarantees callback of functions (e.g. // Fuchsia CDM service guarantees callback of functions (e.g.
...@@ -187,7 +187,6 @@ class FuchsiaCdm::CdmSession { ...@@ -187,7 +187,6 @@ class FuchsiaCdm::CdmSession {
void OnKeyStatesChanged( void OnKeyStatesChanged(
std::vector<fuchsia::media::drm::KeyState> key_states) { std::vector<fuchsia::media::drm::KeyState> key_states) {
std::string new_key_id;
bool has_additional_usable_key = false; bool has_additional_usable_key = false;
CdmKeysInfo keys_info; CdmKeysInfo keys_info;
for (const auto& key_state : key_states) { for (const auto& key_state : key_states) {
...@@ -196,13 +195,6 @@ class FuchsiaCdm::CdmSession { ...@@ -196,13 +195,6 @@ class FuchsiaCdm::CdmSession {
} }
CdmKeyInformation::KeyStatus status = ToCdmKeyStatus(key_state.status()); CdmKeyInformation::KeyStatus status = ToCdmKeyStatus(key_state.status());
has_additional_usable_key |= (status == CdmKeyInformation::USABLE); has_additional_usable_key |= (status == CdmKeyInformation::USABLE);
if (status == CdmKeyInformation::USABLE && new_key_id.empty()) {
// The |key_id| is passed to |on_new_key_| to workaround fxb/38253 in
// FuchsiaSecureStreamDecryptor. It needs just one valid |key_id|, so it
// doesn't matter if |key_info| contains more than one key.
// TODO(crbug.com/1012525): Remove the hack once fxb/38253 is resolved.
new_key_id.assign(key_state.key_id().begin(), key_state.key_id().end());
}
keys_info.emplace_back( keys_info.emplace_back(
new CdmKeyInformation(key_state.key_id(), status, 0)); new CdmKeyInformation(key_state.key_id(), status, 0));
} }
...@@ -211,7 +203,7 @@ class FuchsiaCdm::CdmSession { ...@@ -211,7 +203,7 @@ class FuchsiaCdm::CdmSession {
session_id_, has_additional_usable_key, std::move(keys_info)); session_id_, has_additional_usable_key, std::move(keys_info));
if (has_additional_usable_key) if (has_additional_usable_key)
on_new_key_.Run(new_key_id); on_new_key_.Run();
} }
void OnSessionError(zx_status_t status) { void OnSessionError(zx_status_t status) {
...@@ -230,7 +222,7 @@ class FuchsiaCdm::CdmSession { ...@@ -230,7 +222,7 @@ class FuchsiaCdm::CdmSession {
} }
const SessionCallbacks* const session_callbacks_; const SessionCallbacks* const session_callbacks_;
FuchsiaSecureStreamDecryptor::NewKeyCB on_new_key_; base::RepeatingClosure on_new_key_;
fuchsia::media::drm::LicenseSessionPtr session_; fuchsia::media::drm::LicenseSessionPtr session_;
std::string session_id_; std::string session_id_;
...@@ -472,12 +464,12 @@ FuchsiaCdmContext* FuchsiaCdm::GetFuchsiaCdmContext() { ...@@ -472,12 +464,12 @@ FuchsiaCdmContext* FuchsiaCdm::GetFuchsiaCdmContext() {
return this; return this;
} }
void FuchsiaCdm::OnNewKey(const std::string& key_id) { void FuchsiaCdm::OnNewKey() {
decryptor_.OnNewKey(); decryptor_.OnNewKey();
{ {
base::AutoLock auto_lock(new_key_cb_for_video_lock_); base::AutoLock auto_lock(new_key_cb_for_video_lock_);
if (new_key_cb_for_video_) if (new_key_cb_for_video_)
new_key_cb_for_video_.Run(key_id); new_key_cb_for_video_.Run();
} }
} }
......
...@@ -87,8 +87,7 @@ class FuchsiaCdm : public ContentDecryptionModule, ...@@ -87,8 +87,7 @@ class FuchsiaCdm : public ContentDecryptionModule,
uint32_t promise_id, uint32_t promise_id,
base::Optional<CdmPromise::Exception> exception); base::Optional<CdmPromise::Exception> exception);
// TODO(crbug.com/1012525): Remove |key_id| once fxb/38253 is resolved. void OnNewKey();
void OnNewKey(const std::string& key_id);
CdmPromiseAdapter promises_; CdmPromiseAdapter promises_;
base::flat_map<std::string, std::unique_ptr<CdmSession>> session_map_; base::flat_map<std::string, std::unique_ptr<CdmSession>> session_map_;
...@@ -99,7 +98,7 @@ class FuchsiaCdm : public ContentDecryptionModule, ...@@ -99,7 +98,7 @@ class FuchsiaCdm : public ContentDecryptionModule,
FuchsiaDecryptor decryptor_; FuchsiaDecryptor decryptor_;
base::Lock new_key_cb_for_video_lock_; base::Lock new_key_cb_for_video_lock_;
FuchsiaSecureStreamDecryptor::NewKeyCB new_key_cb_for_video_ base::RepeatingClosure new_key_cb_for_video_
GUARDED_BY(new_key_cb_for_video_lock_); GUARDED_BY(new_key_cb_for_video_lock_);
DISALLOW_COPY_AND_ASSIGN(FuchsiaCdm); DISALLOW_COPY_AND_ASSIGN(FuchsiaCdm);
......
...@@ -58,25 +58,9 @@ fuchsia::media::EncryptionPattern GetEncryptionPattern( ...@@ -58,25 +58,9 @@ fuchsia::media::EncryptionPattern GetEncryptionPattern(
return fuchsia_pattern; return fuchsia_pattern;
} }
// We shouldn't need to set Key ID for clear frames, but it's currently fuchsia::media::FormatDetails GetClearFormatDetails() {
// required by the CDM API, see fxb/38253 . This function takes
// |placeholder_key_id| to workaround that issue. The |placeholder_key_id| may
// be empty in this scenario.
// TODO(crbug.com/1012525): Remove |placeholder_key_id| once fxb/38253 is
// resolved.
fuchsia::media::FormatDetails GetClearFormatDetails(
size_t packet_size,
const std::string& placeholder_key_id) {
fuchsia::media::EncryptedFormat encrypted_format; fuchsia::media::EncryptedFormat encrypted_format;
encrypted_format.set_scheme(fuchsia::media::ENCRYPTION_SCHEME_CENC) encrypted_format.set_scheme(fuchsia::media::ENCRYPTION_SCHEME_UNENCRYPTED);
.set_key_id(std::vector<uint8_t>(placeholder_key_id.begin(),
placeholder_key_id.end()))
.set_init_vector(std::vector<uint8_t>(DecryptConfig::kDecryptionKeySize));
std::vector<fuchsia::media::SubsampleEntry> subsamples(1);
subsamples[0].clear_bytes = packet_size;
subsamples[0].encrypted_bytes = 0;
encrypted_format.set_subsamples(subsamples);
fuchsia::media::FormatDetails format; fuchsia::media::FormatDetails format;
format.set_format_details_version_ordinal(0); format.set_format_details_version_ordinal(0);
...@@ -216,7 +200,7 @@ void FuchsiaStreamDecryptorBase::SendInputPacket( ...@@ -216,7 +200,7 @@ void FuchsiaStreamDecryptorBase::SendInputPacket(
fuchsia::media::FormatDetails format = fuchsia::media::FormatDetails format =
(buffer->decrypt_config()) (buffer->decrypt_config())
? GetEncryptedFormatDetails(buffer->decrypt_config()) ? GetEncryptedFormatDetails(buffer->decrypt_config())
: GetClearFormatDetails(packet.size(), last_new_key_id_); : GetClearFormatDetails();
packet.set_format(std::move(format)); packet.set_format(std::move(format));
processor_.Process(std::move(packet)); processor_.Process(std::move(packet));
...@@ -483,8 +467,7 @@ void FuchsiaSecureStreamDecryptor::OnOutputPacket( ...@@ -483,8 +467,7 @@ void FuchsiaSecureStreamDecryptor::OnOutputPacket(
client_->OnDecryptorOutputPacket(std::move(packet)); client_->OnDecryptorOutputPacket(std::move(packet));
} }
FuchsiaSecureStreamDecryptor::NewKeyCB base::RepeatingClosure FuchsiaSecureStreamDecryptor::GetOnNewKeyClosure() {
FuchsiaSecureStreamDecryptor::GetOnNewKeyClosure() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return BindToCurrentLoop(base::BindRepeating( return BindToCurrentLoop(base::BindRepeating(
...@@ -520,17 +503,9 @@ void FuchsiaSecureStreamDecryptor::OnNoKey() { ...@@ -520,17 +503,9 @@ void FuchsiaSecureStreamDecryptor::OnNoKey() {
client_->OnDecryptorNoKey(); client_->OnDecryptorNoKey();
} }
void FuchsiaSecureStreamDecryptor::OnNewKey(const std::string& key_id) { void FuchsiaSecureStreamDecryptor::OnNewKey() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Currently Widevine CDM requires a valid key_id for frames that are not
// encrypted, but we don't have a key_id in the beginning of the stream. To
// workaround this issue we save the |key_id| here and then use it for clear
// frames in SendInputPacket().
// TODO(crbug.com/1012525): Remove this hack once fxb/38253 is resolved: CDM
// shouldn't need |key_id| to handle clear frames.
last_new_key_id_ = key_id;
if (!waiting_for_key_) { if (!waiting_for_key_) {
retry_on_no_key_ = true; retry_on_no_key_ = true;
return; return;
......
...@@ -118,8 +118,6 @@ class FuchsiaSecureStreamDecryptor : public FuchsiaStreamDecryptorBase { ...@@ -118,8 +118,6 @@ class FuchsiaSecureStreamDecryptor : public FuchsiaStreamDecryptorBase {
virtual ~Client() = default; virtual ~Client() = default;
}; };
using NewKeyCB = base::RepeatingCallback<void(const std::string& key_id)>;
FuchsiaSecureStreamDecryptor(fuchsia::media::StreamProcessorPtr processor, FuchsiaSecureStreamDecryptor(fuchsia::media::StreamProcessorPtr processor,
Client* client); Client* client);
~FuchsiaSecureStreamDecryptor() override; ~FuchsiaSecureStreamDecryptor() override;
...@@ -141,7 +139,7 @@ class FuchsiaSecureStreamDecryptor : public FuchsiaStreamDecryptorBase { ...@@ -141,7 +139,7 @@ class FuchsiaSecureStreamDecryptor : public FuchsiaStreamDecryptorBase {
// FuchsiaClearStreamDecryptor and media::Decryptor: they report NO_KEY error // FuchsiaClearStreamDecryptor and media::Decryptor: they report NO_KEY error
// to the caller and expect the caller to resubmit same buffers again after // to the caller and expect the caller to resubmit same buffers again after
// the key is updated. // the key is updated.
NewKeyCB GetOnNewKeyClosure(); base::RepeatingClosure GetOnNewKeyClosure();
// Drops all pending decryption requests. // Drops all pending decryption requests.
void Reset(); void Reset();
...@@ -157,7 +155,7 @@ class FuchsiaSecureStreamDecryptor : public FuchsiaStreamDecryptorBase { ...@@ -157,7 +155,7 @@ class FuchsiaSecureStreamDecryptor : public FuchsiaStreamDecryptorBase {
// Callback returned by GetOnNewKeyClosure(). When waiting for a key this // Callback returned by GetOnNewKeyClosure(). When waiting for a key this
// method unpauses the stream to decrypt any pending buffers. // method unpauses the stream to decrypt any pending buffers.
void OnNewKey(const std::string& key_id); void OnNewKey();
Client* const client_; Client* const client_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment