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" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 new MojoDecoderBufferReader(std::move(receive_pipe))); | 76 new MojoDecoderBufferReader(std::move(receive_pipe))); |
77 } | 77 } |
78 | 78 |
79 void MojoAudioDecoderService::Decode(mojom::DecoderBufferPtr buffer, | 79 void MojoAudioDecoderService::Decode(mojom::DecoderBufferPtr buffer, |
80 const DecodeCallback& callback) { | 80 const DecodeCallback& callback) { |
81 DVLOG(3) << __FUNCTION__; | 81 DVLOG(3) << __FUNCTION__; |
82 | 82 |
83 scoped_refptr<DecoderBuffer> media_buffer = | 83 scoped_refptr<DecoderBuffer> media_buffer = |
84 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer); | 84 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer); |
85 if (!media_buffer) { | 85 if (!media_buffer) { |
86 callback.Run(mojom::DecodeStatus::DECODE_ERROR); | 86 callback.Run(DecodeStatus::DECODE_ERROR); |
87 return; | 87 return; |
88 } | 88 } |
89 | 89 |
90 decoder_->Decode(media_buffer, | 90 decoder_->Decode(media_buffer, |
91 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, | 91 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, |
92 weak_this_, callback)); | 92 weak_this_, callback)); |
93 } | 93 } |
94 | 94 |
95 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { | 95 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { |
96 DVLOG(1) << __FUNCTION__; | 96 DVLOG(1) << __FUNCTION__; |
97 decoder_->Reset( | 97 decoder_->Reset( |
98 base::Bind(&MojoAudioDecoderService::OnResetDone, weak_this_, callback)); | 98 base::Bind(&MojoAudioDecoderService::OnResetDone, weak_this_, callback)); |
99 } | 99 } |
100 | 100 |
101 void MojoAudioDecoderService::OnInitialized(const InitializeCallback& callback, | 101 void MojoAudioDecoderService::OnInitialized(const InitializeCallback& callback, |
102 scoped_refptr<MediaKeys> cdm, | 102 scoped_refptr<MediaKeys> cdm, |
103 bool success) { | 103 bool success) { |
104 DVLOG(1) << __FUNCTION__ << " success:" << success; | 104 DVLOG(1) << __FUNCTION__ << " success:" << success; |
105 | 105 |
106 if (success) { | 106 if (success) { |
107 cdm_ = cdm; | 107 cdm_ = cdm; |
108 callback.Run(success, decoder_->NeedsBitstreamConversion()); | 108 callback.Run(success, decoder_->NeedsBitstreamConversion()); |
109 } else { | 109 } else { |
110 // Do not call decoder_->NeedsBitstreamConversion() if init failed. | 110 // Do not call decoder_->NeedsBitstreamConversion() if init failed. |
111 callback.Run(false, false); | 111 callback.Run(false, false); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
| 115 // These two methods are needed so that we can bind them with a weak pointer to |
| 116 // avoid running the |callback| after connection error happens and |this| is |
| 117 // deleted. It's not safe to run the |callback| after a connection error. |
| 118 |
115 void MojoAudioDecoderService::OnDecodeStatus(const DecodeCallback& callback, | 119 void MojoAudioDecoderService::OnDecodeStatus(const DecodeCallback& callback, |
116 media::DecodeStatus status) { | 120 media::DecodeStatus status) { |
117 DVLOG(3) << __FUNCTION__ << " status:" << status; | 121 DVLOG(3) << __FUNCTION__ << " status:" << status; |
118 callback.Run(static_cast<mojom::DecodeStatus>(status)); | 122 callback.Run(status); |
119 } | 123 } |
120 | 124 |
121 void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) { | 125 void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) { |
122 DVLOG(1) << __FUNCTION__; | 126 DVLOG(1) << __FUNCTION__; |
123 callback.Run(); | 127 callback.Run(); |
124 } | 128 } |
125 | 129 |
126 void MojoAudioDecoderService::OnAudioBufferReady( | 130 void MojoAudioDecoderService::OnAudioBufferReady( |
127 const scoped_refptr<AudioBuffer>& audio_buffer) { | 131 const scoped_refptr<AudioBuffer>& audio_buffer) { |
128 DVLOG(1) << __FUNCTION__; | 132 DVLOG(1) << __FUNCTION__; |
129 | 133 |
130 // TODO(timav): Use DataPipe. | 134 // TODO(timav): Use DataPipe. |
131 client_->OnBufferDecoded(mojom::AudioBuffer::From(audio_buffer)); | 135 client_->OnBufferDecoded(mojom::AudioBuffer::From(audio_buffer)); |
132 } | 136 } |
133 | 137 |
134 } // namespace media | 138 } // namespace media |
OLD | NEW |