Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: media/mojo/services/mojo_audio_decoder_service.cc

Issue 1824763002: Get CdmContext in MojoAudioDecoderService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@spitzer-audio-serialize
Patch Set: Hold MediaKey in a member variable to control its lifetime Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/mojo/services/mojo_audio_decoder_service.h" 5 #include "media/mojo/services/mojo_audio_decoder_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/base/cdm_context.h" 10 #include "media/base/cdm_context.h"
11 #include "media/base/media_keys.h"
11 #include "media/mojo/common/media_type_converters.h" 12 #include "media/mojo/common/media_type_converters.h"
13 #include "media/mojo/services/mojo_cdm_service_context.h"
12 14
13 namespace media { 15 namespace media {
14 16
15 MojoAudioDecoderService::MojoAudioDecoderService( 17 MojoAudioDecoderService::MojoAudioDecoderService(
18 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context,
16 scoped_ptr<media::AudioDecoder> decoder, 19 scoped_ptr<media::AudioDecoder> decoder,
17 mojo::InterfaceRequest<interfaces::AudioDecoder> request) 20 mojo::InterfaceRequest<interfaces::AudioDecoder> request)
18 : binding_(this, std::move(request)), 21 : binding_(this, std::move(request)),
22 mojo_cdm_service_context_(mojo_cdm_service_context),
19 decoder_(std::move(decoder)), 23 decoder_(std::move(decoder)),
20 weak_factory_(this) { 24 weak_factory_(this) {
21 weak_this_ = weak_factory_.GetWeakPtr(); 25 weak_this_ = weak_factory_.GetWeakPtr();
22 } 26 }
23 27
24 MojoAudioDecoderService::~MojoAudioDecoderService() {} 28 MojoAudioDecoderService::~MojoAudioDecoderService() {}
25 29
26 void MojoAudioDecoderService::Initialize( 30 void MojoAudioDecoderService::Initialize(
27 interfaces::AudioDecoderClientPtr client, 31 interfaces::AudioDecoderClientPtr client,
28 interfaces::AudioDecoderConfigPtr config, 32 interfaces::AudioDecoderConfigPtr config,
29 int32_t cdm_id, 33 int32_t cdm_id,
30 const InitializeCallback& callback) { 34 const InitializeCallback& callback) {
31 DVLOG(1) << __FUNCTION__ << " " 35 DVLOG(1) << __FUNCTION__ << " "
32 << config.To<media::AudioDecoderConfig>().AsHumanReadableString(); 36 << config.To<media::AudioDecoderConfig>().AsHumanReadableString();
33 37
34 // Encrypted streams are not supported for now. 38 // Get CdmContext from cdm_id if the stream is encrypted.
35 if (config.To<media::AudioDecoderConfig>().is_encrypted() && 39 CdmContext* cdm_context = nullptr;
36 cdm_id == CdmContext::kInvalidCdmId) { 40 if (config.To<media::AudioDecoderConfig>().is_encrypted()) {
37 // The client should prevent this situation. 41 if (!mojo_cdm_service_context_) {
38 NOTREACHED() << "Encrypted streams are not supported"; 42 DVLOG(1) << "CDM service context not available.";
39 callback.Run(false, false); 43 callback.Run(false, false);
40 return; 44 return;
45 }
46
47 scoped_refptr<MediaKeys> cdm = mojo_cdm_service_context_->GetCdm(cdm_id);
48 if (!cdm) {
49 DVLOG(1) << "CDM not found for CDM id: " << cdm_id;
50 callback.Run(false, false);
51 return;
52 }
53
54 cdm_context = cdm->GetCdmContext();
55 if (!cdm_context) {
56 DVLOG(1) << "CDM context not available for CDM id: " << cdm_id;
57 callback.Run(false, false);
58 return;
59 }
60
61 cdm_ = cdm;
Tima Vaisburd 2016/03/21 21:53:01 I can bind |cdm| to OnInitialized() instead, but d
xhwang 2016/03/21 22:31:23 Either way is fine. When you bind |cdm| into the c
Tima Vaisburd 2016/03/21 23:07:05 That you, I missed the fact that Bind() will hold
xhwang 2016/03/21 23:13:03 Yes, this often results in more elegant code. But
41 } 62 }
42 63
43 client_ = std::move(client); 64 client_ = std::move(client);
44 65
45 // TODO(timav): Get CdmContext from cdm_id.
46 decoder_->Initialize( 66 decoder_->Initialize(
47 config.To<media::AudioDecoderConfig>(), 67 config.To<media::AudioDecoderConfig>(), cdm_context,
48 nullptr, // no CdmContext
49 base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback), 68 base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback),
50 base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, weak_this_)); 69 base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, weak_this_));
51 } 70 }
52 71
53 void MojoAudioDecoderService::SetDataSource( 72 void MojoAudioDecoderService::SetDataSource(
54 mojo::ScopedDataPipeConsumerHandle receive_pipe) { 73 mojo::ScopedDataPipeConsumerHandle receive_pipe) {
55 DVLOG(1) << __FUNCTION__; 74 DVLOG(1) << __FUNCTION__;
56 consumer_handle_ = std::move(receive_pipe); 75 consumer_handle_ = std::move(receive_pipe);
57 } 76 }
58 77
59 void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer, 78 void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer,
60 const DecodeCallback& callback) { 79 const DecodeCallback& callback) {
61 DVLOG(3) << __FUNCTION__; 80 DVLOG(3) << __FUNCTION__;
62 decoder_->Decode(ReadDecoderBuffer(std::move(buffer)), 81 decoder_->Decode(ReadDecoderBuffer(std::move(buffer)),
63 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, 82 base::Bind(&MojoAudioDecoderService::OnDecodeStatus,
64 weak_this_, callback)); 83 weak_this_, callback));
65 } 84 }
66 85
67 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { 86 void MojoAudioDecoderService::Reset(const ResetCallback& callback) {
68 DVLOG(1) << __FUNCTION__; 87 DVLOG(1) << __FUNCTION__;
69 decoder_->Reset( 88 decoder_->Reset(
70 base::Bind(&MojoAudioDecoderService::OnResetDone, weak_this_, callback)); 89 base::Bind(&MojoAudioDecoderService::OnResetDone, weak_this_, callback));
71 } 90 }
72 91
73 void MojoAudioDecoderService::OnInitialized(const InitializeCallback& callback, 92 void MojoAudioDecoderService::OnInitialized(const InitializeCallback& callback,
74 bool success) { 93 bool success) {
75 DVLOG(1) << __FUNCTION__ << " success:" << success; 94 DVLOG(1) << __FUNCTION__ << " success:" << success;
95
96 if (!success)
97 cdm_ = nullptr;
98
76 callback.Run(success, decoder_->NeedsBitstreamConversion()); 99 callback.Run(success, decoder_->NeedsBitstreamConversion());
77 } 100 }
78 101
79 static interfaces::AudioDecoder::DecodeStatus ConvertDecodeStatus( 102 static interfaces::AudioDecoder::DecodeStatus ConvertDecodeStatus(
80 media::AudioDecoder::Status status) { 103 media::AudioDecoder::Status status) {
81 switch (status) { 104 switch (status) {
82 case media::AudioDecoder::kOk: 105 case media::AudioDecoder::kOk:
83 return interfaces::AudioDecoder::DecodeStatus::OK; 106 return interfaces::AudioDecoder::DecodeStatus::OK;
84 case media::AudioDecoder::kAborted: 107 case media::AudioDecoder::kAborted:
85 return interfaces::AudioDecoder::DecodeStatus::ABORTED; 108 return interfaces::AudioDecoder::DecodeStatus::ABORTED;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 uint32_t bytes_read = bytes_to_read; 154 uint32_t bytes_read = bytes_to_read;
132 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), 155 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(),
133 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), 156 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE),
134 MOJO_RESULT_OK); 157 MOJO_RESULT_OK);
135 CHECK_EQ(bytes_to_read, bytes_read); 158 CHECK_EQ(bytes_to_read, bytes_read);
136 159
137 return media_buffer; 160 return media_buffer;
138 } 161 }
139 162
140 } // namespace media 163 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/mojo_audio_decoder_service.h ('k') | media/mojo/services/service_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698