| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_demuxer_stream_adapter.h" | 5 #include "media/mojo/services/mojo_demuxer_stream_adapter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 if (status == mojom::DemuxerStream::Status::ABORTED) { | 106 if (status == mojom::DemuxerStream::Status::ABORTED) { |
| 107 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr); | 107 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr); |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 | 110 |
| 111 DCHECK_EQ(status, mojom::DemuxerStream::Status::OK); | 111 DCHECK_EQ(status, mojom::DemuxerStream::Status::OK); |
| 112 scoped_refptr<DecoderBuffer> media_buffer( | 112 scoped_refptr<DecoderBuffer> media_buffer( |
| 113 buffer.To<scoped_refptr<DecoderBuffer>>()); | 113 buffer.To<scoped_refptr<DecoderBuffer>>()); |
| 114 | 114 |
| 115 if (!media_buffer->end_of_stream()) { | 115 if (media_buffer->end_of_stream()) { |
| 116 DCHECK_GT(media_buffer->data_size(), 0u); | 116 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, media_buffer); |
| 117 return; |
| 118 } |
| 117 | 119 |
| 118 // Wait for the data to become available in the DataPipe. | 120 DCHECK_GT(media_buffer->data_size(), 0u); |
| 119 MojoHandleSignalsState state; | |
| 120 CHECK_EQ(MOJO_RESULT_OK, | |
| 121 MojoWait(stream_pipe_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | |
| 122 MOJO_DEADLINE_INDEFINITE, &state)); | |
| 123 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals); | |
| 124 | 121 |
| 125 // Read the inner data for the DecoderBuffer from our DataPipe. | 122 // Wait for the data to become available in the DataPipe. |
| 126 uint32_t bytes_to_read = | 123 MojoHandleSignalsState state; |
| 127 base::checked_cast<uint32_t>(media_buffer->data_size()); | 124 MojoResult result = |
| 128 uint32_t bytes_read = bytes_to_read; | 125 MojoWait(stream_pipe_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 129 CHECK_EQ(ReadDataRaw(stream_pipe_.get(), media_buffer->writable_data(), | 126 MOJO_DEADLINE_INDEFINITE, &state); |
| 130 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 127 if (result != MOJO_RESULT_OK) { |
| 131 MOJO_RESULT_OK); | 128 DVLOG(1) << __FUNCTION__ << ": Peer closed the data pipe"; |
| 132 CHECK_EQ(bytes_to_read, bytes_read); | 129 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr); |
| 130 return; |
| 131 } |
| 132 |
| 133 // Read the inner data for the DecoderBuffer from our DataPipe. |
| 134 uint32_t bytes_to_read = |
| 135 base::checked_cast<uint32_t>(media_buffer->data_size()); |
| 136 uint32_t bytes_read = bytes_to_read; |
| 137 result = ReadDataRaw(stream_pipe_.get(), media_buffer->writable_data(), |
| 138 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
| 139 if (result != MOJO_RESULT_OK || bytes_read != bytes_to_read) { |
| 140 DVLOG(1) << __FUNCTION__ << ": reading from pipe failed"; |
| 141 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr); |
| 142 return; |
| 133 } | 143 } |
| 134 | 144 |
| 135 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, media_buffer); | 145 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, media_buffer); |
| 136 } | 146 } |
| 137 | 147 |
| 138 void MojoDemuxerStreamAdapter::UpdateConfig( | 148 void MojoDemuxerStreamAdapter::UpdateConfig( |
| 139 mojom::AudioDecoderConfigPtr audio_config, | 149 mojom::AudioDecoderConfigPtr audio_config, |
| 140 mojom::VideoDecoderConfigPtr video_config) { | 150 mojom::VideoDecoderConfigPtr video_config) { |
| 141 DCHECK_NE(type_, DemuxerStream::UNKNOWN); | 151 DCHECK_NE(type_, DemuxerStream::UNKNOWN); |
| 142 | 152 |
| 143 switch(type_) { | 153 switch(type_) { |
| 144 case DemuxerStream::AUDIO: | 154 case DemuxerStream::AUDIO: |
| 145 DCHECK(audio_config && !video_config); | 155 DCHECK(audio_config && !video_config); |
| 146 audio_config_ = audio_config.To<AudioDecoderConfig>(); | 156 audio_config_ = audio_config.To<AudioDecoderConfig>(); |
| 147 break; | 157 break; |
| 148 case DemuxerStream::VIDEO: | 158 case DemuxerStream::VIDEO: |
| 149 DCHECK(video_config && !audio_config); | 159 DCHECK(video_config && !audio_config); |
| 150 video_config_ = video_config.To<VideoDecoderConfig>(); | 160 video_config_ = video_config.To<VideoDecoderConfig>(); |
| 151 break; | 161 break; |
| 152 default: | 162 default: |
| 153 NOTREACHED(); | 163 NOTREACHED(); |
| 154 } | 164 } |
| 155 } | 165 } |
| 156 | 166 |
| 157 } // namespace media | 167 } // namespace media |
| OLD | NEW |