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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 client_ = std::move(client); | 43 client_ = std::move(client); |
44 | 44 |
45 // TODO(timav): Get CdmContext from cdm_id. | 45 // TODO(timav): Get CdmContext from cdm_id. |
46 decoder_->Initialize( | 46 decoder_->Initialize( |
47 config.To<media::AudioDecoderConfig>(), | 47 config.To<media::AudioDecoderConfig>(), |
48 nullptr, // no CdmContext | 48 nullptr, // no CdmContext |
49 base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback), | 49 base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback), |
50 base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, weak_this_)); | 50 base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, weak_this_)); |
51 } | 51 } |
52 | 52 |
53 void MojoAudioDecoderService::SetDataSource( | |
54 mojo::ScopedDataPipeConsumerHandle receive_pipe) { | |
55 DVLOG(1) << __FUNCTION__; | |
56 consumer_handle_ = std::move(receive_pipe); | |
57 } | |
58 | |
53 void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer, | 59 void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer, |
54 const DecodeCallback& callback) { | 60 const DecodeCallback& callback) { |
55 DVLOG(3) << __FUNCTION__; | 61 DVLOG(3) << __FUNCTION__; |
56 decoder_->Decode(ReadDecoderBuffer(std::move(buffer)), | 62 decoder_->Decode(ReadDecoderBuffer(std::move(buffer)), |
57 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, | 63 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, |
58 weak_this_, callback)); | 64 weak_this_, callback)); |
59 } | 65 } |
60 | 66 |
61 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { | 67 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { |
62 DVLOG(1) << __FUNCTION__; | 68 DVLOG(1) << __FUNCTION__; |
(...skipping 29 matching lines...) Expand all Loading... | |
92 } | 98 } |
93 | 99 |
94 void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) { | 100 void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) { |
95 DVLOG(1) << __FUNCTION__; | 101 DVLOG(1) << __FUNCTION__; |
96 callback.Run(); | 102 callback.Run(); |
97 } | 103 } |
98 | 104 |
99 void MojoAudioDecoderService::OnAudioBufferReady( | 105 void MojoAudioDecoderService::OnAudioBufferReady( |
100 const scoped_refptr<AudioBuffer>& audio_buffer) { | 106 const scoped_refptr<AudioBuffer>& audio_buffer) { |
101 DVLOG(1) << __FUNCTION__; | 107 DVLOG(1) << __FUNCTION__; |
102 NOTIMPLEMENTED(); | 108 NOTIMPLEMENTED(); |
xhwang
2016/03/19 04:57:25
I think you can finish this implementation here in
Tima Vaisburd
2016/03/21 19:08:26
Done.
| |
103 } | 109 } |
104 | 110 |
105 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( | 111 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( |
106 interfaces::DecoderBufferPtr buffer) { | 112 interfaces::DecoderBufferPtr buffer) { |
107 scoped_refptr<DecoderBuffer> media_buffer( | 113 scoped_refptr<DecoderBuffer> media_buffer( |
108 buffer.To<scoped_refptr<DecoderBuffer>>()); | 114 buffer.To<scoped_refptr<DecoderBuffer>>()); |
109 | 115 |
110 NOTIMPLEMENTED(); | 116 if (media_buffer->end_of_stream()) |
117 return media_buffer; | |
118 | |
119 // Wait for the data to become available in the DataPipe. | |
120 MojoHandleSignalsState state; | |
121 CHECK_EQ(MOJO_RESULT_OK, | |
122 MojoWait(consumer_handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | |
123 MOJO_DEADLINE_INDEFINITE, &state)); | |
124 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals); | |
125 | |
126 // Read the inner data for the DecoderBuffer from our DataPipe. | |
127 uint32_t bytes_to_read = | |
128 base::checked_cast<uint32_t>(media_buffer->data_size()); | |
129 DCHECK_GT(bytes_to_read, 0u); | |
130 uint32_t bytes_read = bytes_to_read; | |
131 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), | |
132 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | |
133 MOJO_RESULT_OK); | |
134 CHECK_EQ(bytes_to_read, bytes_read); | |
135 | |
111 return media_buffer; | 136 return media_buffer; |
112 } | 137 } |
113 | 138 |
114 } // namespace media | 139 } // namespace media |
OLD | NEW |