OLD | NEW |
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 scoped_refptr<MediaKeys> cdm; |
37 // The client should prevent this situation. | 41 if (config.To<media::AudioDecoderConfig>().is_encrypted()) { |
38 NOTREACHED() << "Encrypted streams are not supported"; | 42 if (!mojo_cdm_service_context_) { |
39 callback.Run(false, false); | 43 DVLOG(1) << "CDM service context not available."; |
40 return; | 44 callback.Run(false, false); |
| 45 return; |
| 46 } |
| 47 |
| 48 cdm = mojo_cdm_service_context_->GetCdm(cdm_id); |
| 49 if (!cdm) { |
| 50 DVLOG(1) << "CDM not found for CDM id: " << cdm_id; |
| 51 callback.Run(false, false); |
| 52 return; |
| 53 } |
| 54 |
| 55 cdm_context = cdm->GetCdmContext(); |
| 56 if (!cdm_context) { |
| 57 DVLOG(1) << "CDM context not available for CDM id: " << cdm_id; |
| 58 callback.Run(false, false); |
| 59 return; |
| 60 } |
41 } | 61 } |
42 | 62 |
43 client_ = std::move(client); | 63 client_ = std::move(client); |
44 | 64 |
45 // TODO(timav): Get CdmContext from cdm_id. | |
46 decoder_->Initialize( | 65 decoder_->Initialize( |
47 config.To<media::AudioDecoderConfig>(), | 66 config.To<media::AudioDecoderConfig>(), cdm_context, |
48 nullptr, // no CdmContext | 67 base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback, |
49 base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback), | 68 cdm), |
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, |
| 93 scoped_refptr<MediaKeys> cdm, |
74 bool success) { | 94 bool success) { |
75 DVLOG(1) << __FUNCTION__ << " success:" << success; | 95 DVLOG(1) << __FUNCTION__ << " success:" << success; |
76 callback.Run(success, decoder_->NeedsBitstreamConversion()); | 96 |
| 97 if (success) { |
| 98 cdm_ = cdm; |
| 99 callback.Run(success, decoder_->NeedsBitstreamConversion()); |
| 100 } else { |
| 101 // Do not call decoder_->NeedsBitstreamConversion() if init failed. |
| 102 callback.Run(false, false); |
| 103 } |
77 } | 104 } |
78 | 105 |
79 static interfaces::AudioDecoder::DecodeStatus ConvertDecodeStatus( | 106 static interfaces::AudioDecoder::DecodeStatus ConvertDecodeStatus( |
80 media::AudioDecoder::Status status) { | 107 media::AudioDecoder::Status status) { |
81 switch (status) { | 108 switch (status) { |
82 case media::AudioDecoder::kOk: | 109 case media::AudioDecoder::kOk: |
83 return interfaces::AudioDecoder::DecodeStatus::OK; | 110 return interfaces::AudioDecoder::DecodeStatus::OK; |
84 case media::AudioDecoder::kAborted: | 111 case media::AudioDecoder::kAborted: |
85 return interfaces::AudioDecoder::DecodeStatus::ABORTED; | 112 return interfaces::AudioDecoder::DecodeStatus::ABORTED; |
86 case media::AudioDecoder::kDecodeError: | 113 case media::AudioDecoder::kDecodeError: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 uint32_t bytes_read = bytes_to_read; | 159 uint32_t bytes_read = bytes_to_read; |
133 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), | 160 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), |
134 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 161 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
135 MOJO_RESULT_OK); | 162 MOJO_RESULT_OK); |
136 CHECK_EQ(bytes_to_read, bytes_read); | 163 CHECK_EQ(bytes_to_read, bytes_read); |
137 | 164 |
138 return media_buffer; | 165 return media_buffer; |
139 } | 166 } |
140 | 167 |
141 } // namespace media | 168 } // namespace media |
OLD | NEW |