Commit e840eb7d authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Move audio stream decryptor creation to FuchsiaCdm

Previously audio and video decryptor creation logic was not consistent:
audio stream decryptor was created in FuchsiaClearStreamDecryptor::Create(),
while video stream decryptor is allocated in FuchsiaCdm. This CL removes
Create() from FuchsiaClearStreamDecryptor and adds

FuchsiaCdm: :CreateAudioDecryptor().
Change-Id: I17b4ad0d9e8b0949de9951ec2534c15f678d2e90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531053
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Commit-Queue: David Dorwin <ddorwin@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826168}
parent 54cfcfc3
...@@ -24,6 +24,10 @@ namespace media { ...@@ -24,6 +24,10 @@ namespace media {
namespace { namespace {
// Audio packets are normally smaller than 128kB (more than enough for 2 seconds
// at 320kb/s).
const size_t kAudioStreamBufferSize = 128 * 1024;
std::string GetInitDataTypeName(EmeInitDataType type) { std::string GetInitDataTypeName(EmeInitDataType type) {
switch (type) { switch (type) {
case EmeInitDataType::WEBM: case EmeInitDataType::WEBM:
...@@ -245,7 +249,7 @@ FuchsiaCdm::FuchsiaCdm(fuchsia::media::drm::ContentDecryptionModulePtr cdm, ...@@ -245,7 +249,7 @@ FuchsiaCdm::FuchsiaCdm(fuchsia::media::drm::ContentDecryptionModulePtr cdm,
: cdm_(std::move(cdm)), : cdm_(std::move(cdm)),
ready_cb_(std::move(ready_cb)), ready_cb_(std::move(ready_cb)),
session_callbacks_(std::move(callbacks)), session_callbacks_(std::move(callbacks)),
decryptor_(cdm_.get()) { decryptor_(this) {
DCHECK(cdm_); DCHECK(cdm_);
cdm_.events().OnProvisioned = cdm_.events().OnProvisioned =
fit::bind_member(this, &FuchsiaCdm::OnProvisioned); fit::bind_member(this, &FuchsiaCdm::OnProvisioned);
...@@ -292,6 +296,18 @@ std::unique_ptr<FuchsiaSecureStreamDecryptor> FuchsiaCdm::CreateVideoDecryptor( ...@@ -292,6 +296,18 @@ std::unique_ptr<FuchsiaSecureStreamDecryptor> FuchsiaCdm::CreateVideoDecryptor(
return decryptor; return decryptor;
} }
std::unique_ptr<FuchsiaClearStreamDecryptor>
FuchsiaCdm::CreateAudioDecryptor() {
fuchsia::media::drm::DecryptorParams params;
params.set_require_secure_mode(false);
params.mutable_input_details()->set_format_details_version_ordinal(0);
fuchsia::media::StreamProcessorPtr stream_processor;
cdm_->CreateDecryptor(std::move(params), stream_processor.NewRequest());
return std::make_unique<FuchsiaClearStreamDecryptor>(
std::move(stream_processor), kAudioStreamBufferSize);
}
void FuchsiaCdm::SetServerCertificate( void FuchsiaCdm::SetServerCertificate(
const std::vector<uint8_t>& certificate, const std::vector<uint8_t>& certificate,
std::unique_ptr<SimpleCdmPromise> promise) { std::unique_ptr<SimpleCdmPromise> promise) {
......
...@@ -73,6 +73,7 @@ class FuchsiaCdm : public ContentDecryptionModule, ...@@ -73,6 +73,7 @@ class FuchsiaCdm : public ContentDecryptionModule,
// FuchsiaCdmContext implementation: // FuchsiaCdmContext implementation:
std::unique_ptr<FuchsiaSecureStreamDecryptor> CreateVideoDecryptor( std::unique_ptr<FuchsiaSecureStreamDecryptor> CreateVideoDecryptor(
FuchsiaSecureStreamDecryptor::Client* client) override; FuchsiaSecureStreamDecryptor::Client* client) override;
std::unique_ptr<FuchsiaClearStreamDecryptor> CreateAudioDecryptor() override;
private: private:
class CdmSession; class CdmSession;
......
...@@ -17,6 +17,8 @@ class FuchsiaCdmContext { ...@@ -17,6 +17,8 @@ class FuchsiaCdmContext {
// Creates FuchsiaSecureStreamDecryptor instance for the CDM context. // Creates FuchsiaSecureStreamDecryptor instance for the CDM context.
virtual std::unique_ptr<FuchsiaSecureStreamDecryptor> CreateVideoDecryptor( virtual std::unique_ptr<FuchsiaSecureStreamDecryptor> CreateVideoDecryptor(
FuchsiaSecureStreamDecryptor::Client* client) = 0; FuchsiaSecureStreamDecryptor::Client* client) = 0;
virtual std::unique_ptr<FuchsiaClearStreamDecryptor>
CreateAudioDecryptor() = 0;
protected: protected:
virtual ~FuchsiaCdmContext() = default; virtual ~FuchsiaCdmContext() = default;
......
...@@ -11,18 +11,14 @@ ...@@ -11,18 +11,14 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "media/base/decoder_buffer.h" #include "media/base/decoder_buffer.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "media/fuchsia/cdm/fuchsia_cdm_context.h"
#include "media/fuchsia/cdm/fuchsia_stream_decryptor.h" #include "media/fuchsia/cdm/fuchsia_stream_decryptor.h"
namespace media { namespace media {
// Audio packets are normally smaller than 128kB (more than enough for 2 seconds FuchsiaDecryptor::FuchsiaDecryptor(FuchsiaCdmContext* cdm_context)
// at 320kb/s). : cdm_context_(cdm_context) {
const size_t kAudioStreamBufferSize = 128 * 1024; DCHECK(cdm_context_);
FuchsiaDecryptor::FuchsiaDecryptor(
fuchsia::media::drm::ContentDecryptionModule* cdm)
: cdm_(cdm) {
DCHECK(cdm_);
} }
FuchsiaDecryptor::~FuchsiaDecryptor() { FuchsiaDecryptor::~FuchsiaDecryptor() {
...@@ -42,8 +38,7 @@ void FuchsiaDecryptor::Decrypt(StreamType stream_type, ...@@ -42,8 +38,7 @@ void FuchsiaDecryptor::Decrypt(StreamType stream_type,
if (!audio_decryptor_) { if (!audio_decryptor_) {
audio_decryptor_task_runner_ = base::ThreadTaskRunnerHandle::Get(); audio_decryptor_task_runner_ = base::ThreadTaskRunnerHandle::Get();
audio_decryptor_ = audio_decryptor_ = cdm_context_->CreateAudioDecryptor();
FuchsiaClearStreamDecryptor::Create(cdm_, kAudioStreamBufferSize);
} }
audio_decryptor_->Decrypt(std::move(encrypted), std::move(decrypt_cb)); audio_decryptor_->Decrypt(std::move(encrypted), std::move(decrypt_cb));
......
...@@ -14,22 +14,15 @@ ...@@ -14,22 +14,15 @@
#include "media/base/decryptor.h" #include "media/base/decryptor.h"
#include "media/fuchsia/cdm/fuchsia_stream_decryptor.h" #include "media/fuchsia/cdm/fuchsia_stream_decryptor.h"
namespace fuchsia {
namespace media {
namespace drm {
class ContentDecryptionModule;
} // namespace drm
} // namespace media
} // namespace fuchsia
namespace media { namespace media {
class FuchsiaCdmContext;
class FuchsiaClearStreamDecryptor; class FuchsiaClearStreamDecryptor;
class FuchsiaDecryptor : public Decryptor { class FuchsiaDecryptor : public Decryptor {
public: public:
// Caller should make sure |cdm| lives longer than this class. // Caller should make sure |cdm| lives longer than this class.
explicit FuchsiaDecryptor(fuchsia::media::drm::ContentDecryptionModule* cdm); explicit FuchsiaDecryptor(FuchsiaCdmContext* cdm_context);
~FuchsiaDecryptor() override; ~FuchsiaDecryptor() override;
// media::Decryptor implementation: // media::Decryptor implementation:
...@@ -50,7 +43,7 @@ class FuchsiaDecryptor : public Decryptor { ...@@ -50,7 +43,7 @@ class FuchsiaDecryptor : public Decryptor {
bool CanAlwaysDecrypt() override; bool CanAlwaysDecrypt() override;
private: private:
fuchsia::media::drm::ContentDecryptionModule* const cdm_; FuchsiaCdmContext* const cdm_context_;
std::unique_ptr<FuchsiaClearStreamDecryptor> audio_decryptor_; std::unique_ptr<FuchsiaClearStreamDecryptor> audio_decryptor_;
......
...@@ -216,22 +216,6 @@ void FuchsiaStreamDecryptorBase::ProcessEndOfStream() { ...@@ -216,22 +216,6 @@ void FuchsiaStreamDecryptorBase::ProcessEndOfStream() {
processor_.ProcessEos(); processor_.ProcessEos();
} }
std::unique_ptr<FuchsiaClearStreamDecryptor>
FuchsiaClearStreamDecryptor::Create(
fuchsia::media::drm::ContentDecryptionModule* cdm,
size_t min_buffer_size) {
DCHECK(cdm);
fuchsia::media::drm::DecryptorParams params;
params.set_require_secure_mode(false);
params.mutable_input_details()->set_format_details_version_ordinal(0);
fuchsia::media::StreamProcessorPtr stream_processor;
cdm->CreateDecryptor(std::move(params), stream_processor.NewRequest());
return std::make_unique<FuchsiaClearStreamDecryptor>(
std::move(stream_processor), min_buffer_size);
}
FuchsiaClearStreamDecryptor::FuchsiaClearStreamDecryptor( FuchsiaClearStreamDecryptor::FuchsiaClearStreamDecryptor(
fuchsia::media::StreamProcessorPtr processor, fuchsia::media::StreamProcessorPtr processor,
size_t min_buffer_size) size_t min_buffer_size)
......
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