Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/base/android/media_decoder_job.h" | 5 #include "media/base/android/media_decoder_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 : ui_task_runner_(base::MessageLoopProxy::current()), | 26 : ui_task_runner_(base::MessageLoopProxy::current()), |
| 27 decoder_task_runner_(decoder_task_runner), | 27 decoder_task_runner_(decoder_task_runner), |
| 28 media_codec_bridge_(media_codec_bridge), | 28 media_codec_bridge_(media_codec_bridge), |
| 29 needs_flush_(false), | 29 needs_flush_(false), |
| 30 input_eos_encountered_(false), | 30 input_eos_encountered_(false), |
| 31 output_eos_encountered_(false), | 31 output_eos_encountered_(false), |
| 32 skip_eos_enqueue_(true), | 32 skip_eos_enqueue_(true), |
| 33 prerolling_(true), | 33 prerolling_(true), |
| 34 weak_this_(this), | 34 weak_this_(this), |
| 35 request_data_cb_(request_data_cb), | 35 request_data_cb_(request_data_cb), |
| 36 access_unit_index_(0), | 36 current_demuxer_data_index_(0), |
| 37 input_buf_index_(-1), | 37 input_buf_index_(-1), |
| 38 stop_decode_pending_(false), | 38 stop_decode_pending_(false), |
| 39 destroy_pending_(false) { | 39 destroy_pending_(false), |
| 40 is_requesting_demuxer_data_(false), | |
| 41 is_incoming_data_invalid_(false) { | |
| 42 InitializeReceivedData(); | |
| 40 } | 43 } |
| 41 | 44 |
| 42 MediaDecoderJob::~MediaDecoderJob() {} | 45 MediaDecoderJob::~MediaDecoderJob() {} |
| 43 | 46 |
| 44 void MediaDecoderJob::OnDataReceived(const DemuxerData& data) { | 47 void MediaDecoderJob::OnDataReceived(const DemuxerData& data) { |
| 45 DVLOG(1) << __FUNCTION__ << ": " << data.access_units.size() << " units"; | 48 DVLOG(1) << __FUNCTION__ << ": " << data.access_units.size() << " units"; |
| 46 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 49 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 47 DCHECK(!on_data_received_cb_.is_null()); | 50 DCHECK(NoAccessUnitsRemainingInChunk(false)); |
| 48 | 51 |
| 49 TRACE_EVENT_ASYNC_END2( | 52 TRACE_EVENT_ASYNC_END2( |
| 50 "media", "MediaDecoderJob::RequestData", this, | 53 "media", "MediaDecoderJob::RequestData", this, |
| 51 "Data type", data.type == media::DemuxerStream::AUDIO ? "AUDIO" : "VIDEO", | 54 "Data type", data.type == media::DemuxerStream::AUDIO ? "AUDIO" : "VIDEO", |
| 52 "Units read", data.access_units.size()); | 55 "Units read", data.access_units.size()); |
| 53 | 56 |
| 57 if (is_incoming_data_invalid_) { | |
| 58 is_incoming_data_invalid_ = false; | |
| 59 | |
| 60 // If there is a pending callback, need to request the data again to get | |
| 61 // valid data. | |
| 62 if (!on_data_received_cb_.is_null()) | |
| 63 request_data_cb_.Run(); | |
| 64 else | |
| 65 is_requesting_demuxer_data_ = false; | |
| 66 return; | |
| 67 } | |
| 68 | |
| 69 size_t next_demuxer_data_index = inactive_demuxer_data_index(); | |
| 70 received_data_[next_demuxer_data_index] = data; | |
| 71 access_unit_index_[next_demuxer_data_index] = 0; | |
| 72 is_requesting_demuxer_data_ = false; | |
| 73 | |
| 54 base::Closure done_cb = base::ResetAndReturn(&on_data_received_cb_); | 74 base::Closure done_cb = base::ResetAndReturn(&on_data_received_cb_); |
| 55 | |
| 56 if (stop_decode_pending_) { | 75 if (stop_decode_pending_) { |
| 57 OnDecodeCompleted(MEDIA_CODEC_STOPPED, kNoTimestamp(), 0); | 76 OnDecodeCompleted(MEDIA_CODEC_STOPPED, kNoTimestamp(), 0); |
| 58 return; | 77 return; |
| 59 } | 78 } |
| 60 | 79 |
| 61 access_unit_index_ = 0; | 80 if (!done_cb.is_null()) |
| 62 received_data_ = data; | 81 done_cb.Run(); |
| 63 done_cb.Run(); | |
| 64 } | 82 } |
| 65 | 83 |
| 66 void MediaDecoderJob::Prefetch(const base::Closure& prefetch_cb) { | 84 void MediaDecoderJob::Prefetch(const base::Closure& prefetch_cb) { |
| 67 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 85 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 68 DCHECK(on_data_received_cb_.is_null()); | 86 DCHECK(on_data_received_cb_.is_null()); |
| 69 DCHECK(decode_cb_.is_null()); | 87 DCHECK(decode_cb_.is_null()); |
| 70 | 88 |
| 71 if (HasData()) { | 89 if (HasData()) { |
| 72 DVLOG(1) << __FUNCTION__ << " : using previously received data"; | 90 DVLOG(1) << __FUNCTION__ << " : using previously received data"; |
| 73 ui_task_runner_->PostTask(FROM_HERE, prefetch_cb); | 91 ui_task_runner_->PostTask(FROM_HERE, prefetch_cb); |
| 74 return; | 92 return; |
| 75 } | 93 } |
| 76 | 94 |
| 77 DVLOG(1) << __FUNCTION__ << " : requesting data"; | 95 DVLOG(1) << __FUNCTION__ << " : requesting data"; |
| 78 RequestData(prefetch_cb); | 96 RequestData(prefetch_cb); |
| 79 } | 97 } |
| 80 | 98 |
| 81 bool MediaDecoderJob::Decode( | 99 bool MediaDecoderJob::Decode( |
| 82 const base::TimeTicks& start_time_ticks, | 100 base::TimeTicks start_time_ticks, |
| 83 const base::TimeDelta& start_presentation_timestamp, | 101 base::TimeDelta start_presentation_timestamp, |
| 84 const DecoderCallback& callback) { | 102 const DecoderCallback& callback) { |
| 85 DCHECK(decode_cb_.is_null()); | 103 DCHECK(decode_cb_.is_null()); |
| 86 DCHECK(on_data_received_cb_.is_null()); | 104 DCHECK(on_data_received_cb_.is_null()); |
| 87 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 105 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 88 | 106 |
| 89 decode_cb_ = callback; | 107 decode_cb_ = callback; |
| 90 | 108 |
| 91 if (!HasData()) { | 109 if (!HasData()) { |
| 92 RequestData(base::Bind(&MediaDecoderJob::DecodeNextAccessUnit, | 110 RequestData(base::Bind(&MediaDecoderJob::DecodeCurrentAccessUnit, |
| 93 base::Unretained(this), | 111 base::Unretained(this), |
| 94 start_time_ticks, | 112 start_time_ticks, |
| 95 start_presentation_timestamp)); | 113 start_presentation_timestamp)); |
| 96 return true; | 114 return true; |
| 97 } | 115 } |
| 98 | 116 |
| 99 if (DemuxerStream::kConfigChanged == | 117 if (DemuxerStream::kConfigChanged == CurrentAccessUnit().status) { |
| 100 received_data_.access_units[access_unit_index_].status) { | |
| 101 // Clear received data because we need to handle a config change. | 118 // Clear received data because we need to handle a config change. |
| 102 decode_cb_.Reset(); | 119 decode_cb_.Reset(); |
| 103 received_data_ = DemuxerData(); | 120 ClearData(); |
| 104 access_unit_index_ = 0; | |
| 105 return false; | 121 return false; |
| 106 } | 122 } |
| 107 | 123 |
| 108 DecodeNextAccessUnit(start_time_ticks, start_presentation_timestamp); | 124 DecodeCurrentAccessUnit(start_time_ticks, start_presentation_timestamp); |
| 109 return true; | 125 return true; |
| 110 } | 126 } |
| 111 | 127 |
| 112 void MediaDecoderJob::StopDecode() { | 128 void MediaDecoderJob::StopDecode() { |
| 113 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 129 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 114 DCHECK(is_decoding()); | 130 DCHECK(is_decoding()); |
| 115 stop_decode_pending_ = true; | 131 stop_decode_pending_ = true; |
| 116 } | 132 } |
| 117 | 133 |
| 118 void MediaDecoderJob::Flush() { | 134 void MediaDecoderJob::Flush() { |
| 119 DCHECK(decode_cb_.is_null()); | 135 DCHECK(decode_cb_.is_null()); |
| 120 | 136 |
| 121 // Do nothing, flush when the next Decode() happens. | 137 // Do nothing, flush when the next Decode() happens. |
| 122 needs_flush_ = true; | 138 needs_flush_ = true; |
| 123 received_data_ = DemuxerData(); | 139 ClearData(); |
| 124 input_eos_encountered_ = false; | |
| 125 access_unit_index_ = 0; | |
| 126 on_data_received_cb_.Reset(); | |
| 127 } | 140 } |
| 128 | 141 |
| 129 void MediaDecoderJob::BeginPrerolling( | 142 void MediaDecoderJob::BeginPrerolling(base::TimeDelta preroll_timestamp) { |
| 130 const base::TimeDelta& preroll_timestamp) { | |
| 131 DVLOG(1) << __FUNCTION__ << "(" << preroll_timestamp.InSecondsF() << ")"; | 143 DVLOG(1) << __FUNCTION__ << "(" << preroll_timestamp.InSecondsF() << ")"; |
| 132 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 144 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 133 DCHECK(!is_decoding()); | 145 DCHECK(!is_decoding()); |
| 134 | 146 |
| 135 preroll_timestamp_ = preroll_timestamp; | 147 preroll_timestamp_ = preroll_timestamp; |
| 136 prerolling_ = true; | 148 prerolling_ = true; |
| 137 } | 149 } |
| 138 | 150 |
| 139 void MediaDecoderJob::Release() { | 151 void MediaDecoderJob::Release() { |
| 140 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 152 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 // In case of MEDIA_CODEC_NO_KEY, we must reuse the |input_buf_index_|. | 213 // In case of MEDIA_CODEC_NO_KEY, we must reuse the |input_buf_index_|. |
| 202 // Otherwise MediaDrm will report errors. | 214 // Otherwise MediaDrm will report errors. |
| 203 if (status == MEDIA_CODEC_NO_KEY) | 215 if (status == MEDIA_CODEC_NO_KEY) |
| 204 input_buf_index_ = input_buf_index; | 216 input_buf_index_ = input_buf_index; |
| 205 | 217 |
| 206 return status; | 218 return status; |
| 207 } | 219 } |
| 208 | 220 |
| 209 bool MediaDecoderJob::HasData() const { | 221 bool MediaDecoderJob::HasData() const { |
| 210 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 222 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 211 // When |input_eos_encountered_| is set, |access_units| must not be empty and | 223 // When |input_eos_encountered_| is set, |access_unit_index_| and |
| 212 // |access_unit_index_| must be pointing to an EOS unit. We'll reuse this | 224 // |current_demuxer_data_index_| must be pointing to an EOS unit. |
| 213 // unit to flush the decoder until we hit output EOS. | 225 // We'll reuse this unit to flush the decoder until we hit output EOS. |
| 214 DCHECK(!input_eos_encountered_ || | 226 DCHECK(!input_eos_encountered_ || !NoAccessUnitsRemainingInChunk(true)); |
| 215 (received_data_.access_units.size() > 0 && | 227 return !NoAccessUnitsRemainingInChunk(true) || |
| 216 access_unit_index_ < received_data_.access_units.size())) | 228 !NoAccessUnitsRemainingInChunk(false); |
| 217 << " (access_units.size(): " << received_data_.access_units.size() | |
| 218 << ", access_unit_index_: " << access_unit_index_ << ")"; | |
| 219 return access_unit_index_ < received_data_.access_units.size() || | |
| 220 input_eos_encountered_; | |
| 221 } | 229 } |
| 222 | 230 |
| 223 void MediaDecoderJob::RequestData(const base::Closure& done_cb) { | 231 void MediaDecoderJob::RequestData(const base::Closure& done_cb) { |
| 224 DVLOG(1) << __FUNCTION__; | 232 DVLOG(1) << __FUNCTION__; |
| 225 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 233 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 226 DCHECK(on_data_received_cb_.is_null()); | 234 DCHECK(on_data_received_cb_.is_null()); |
| 227 DCHECK(!input_eos_encountered_); | 235 DCHECK(!input_eos_encountered_); |
| 236 DCHECK(NoAccessUnitsRemainingInChunk(false)); | |
| 228 | 237 |
| 229 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaDecoderJob::RequestData", this); | 238 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaDecoderJob::RequestData", this); |
| 230 | 239 |
| 231 received_data_ = DemuxerData(); | |
| 232 access_unit_index_ = 0; | |
| 233 on_data_received_cb_ = done_cb; | 240 on_data_received_cb_ = done_cb; |
| 234 | 241 |
| 242 // If we are already expecting new data, just set the callback and do | |
| 243 // nothing. | |
| 244 if (is_requesting_demuxer_data_) | |
| 245 return; | |
| 246 | |
| 247 // The new incoming data will be stored as the next demuxer data chunk, since | |
| 248 // the decoder might still be decoding the current one. | |
| 249 size_t next_demuxer_data_index = inactive_demuxer_data_index(); | |
| 250 received_data_[next_demuxer_data_index] = DemuxerData(); | |
| 251 access_unit_index_[next_demuxer_data_index] = 0; | |
| 252 is_requesting_demuxer_data_ = true; | |
| 253 | |
| 235 request_data_cb_.Run(); | 254 request_data_cb_.Run(); |
| 236 } | 255 } |
| 237 | 256 |
| 238 void MediaDecoderJob::DecodeNextAccessUnit( | 257 void MediaDecoderJob::DecodeCurrentAccessUnit( |
| 239 const base::TimeTicks& start_time_ticks, | 258 base::TimeTicks start_time_ticks, |
| 240 const base::TimeDelta& start_presentation_timestamp) { | 259 base::TimeDelta start_presentation_timestamp) { |
| 241 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 260 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 242 DCHECK(!decode_cb_.is_null()); | 261 DCHECK(!decode_cb_.is_null()); |
| 243 | 262 |
| 263 RequestCurrentChunkIfEmpty(); | |
| 264 const AccessUnit& access_unit = CurrentAccessUnit(); | |
| 244 // If the first access unit is a config change, request the player to dequeue | 265 // If the first access unit is a config change, request the player to dequeue |
| 245 // the input buffer again so that it can request config data. | 266 // the input buffer again so that it can request config data. |
| 246 if (received_data_.access_units[access_unit_index_].status == | 267 if (access_unit.status == DemuxerStream::kConfigChanged) { |
| 247 DemuxerStream::kConfigChanged) { | |
| 248 ui_task_runner_->PostTask(FROM_HERE, | 268 ui_task_runner_->PostTask(FROM_HERE, |
| 249 base::Bind(&MediaDecoderJob::OnDecodeCompleted, | 269 base::Bind(&MediaDecoderJob::OnDecodeCompleted, |
| 250 base::Unretained(this), | 270 base::Unretained(this), |
| 251 MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER, | 271 MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER, |
| 252 kNoTimestamp(), | 272 kNoTimestamp(), |
| 253 0)); | 273 0)); |
| 254 return; | 274 return; |
| 255 } | 275 } |
| 256 | 276 |
| 257 decoder_task_runner_->PostTask(FROM_HERE, base::Bind( | 277 decoder_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 258 &MediaDecoderJob::DecodeInternal, base::Unretained(this), | 278 &MediaDecoderJob::DecodeInternal, base::Unretained(this), |
| 259 received_data_.access_units[access_unit_index_], | 279 access_unit, |
| 260 start_time_ticks, start_presentation_timestamp, needs_flush_, | 280 start_time_ticks, start_presentation_timestamp, needs_flush_, |
| 261 media::BindToCurrentLoop(base::Bind( | 281 media::BindToCurrentLoop(base::Bind( |
| 262 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this))))); | 282 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this))))); |
| 263 needs_flush_ = false; | 283 needs_flush_ = false; |
| 264 } | 284 } |
| 265 | 285 |
| 266 void MediaDecoderJob::DecodeInternal( | 286 void MediaDecoderJob::DecodeInternal( |
| 267 const AccessUnit& unit, | 287 const AccessUnit& unit, |
| 268 const base::TimeTicks& start_time_ticks, | 288 base::TimeTicks start_time_ticks, |
| 269 const base::TimeDelta& start_presentation_timestamp, | 289 base::TimeDelta start_presentation_timestamp, |
| 270 bool needs_flush, | 290 bool needs_flush, |
| 271 const MediaDecoderJob::DecoderCallback& callback) { | 291 const MediaDecoderJob::DecoderCallback& callback) { |
| 272 DVLOG(1) << __FUNCTION__; | 292 DVLOG(1) << __FUNCTION__; |
| 273 DCHECK(decoder_task_runner_->BelongsToCurrentThread()); | 293 DCHECK(decoder_task_runner_->BelongsToCurrentThread()); |
| 274 TRACE_EVENT0("media", __FUNCTION__); | 294 TRACE_EVENT0("media", __FUNCTION__); |
| 275 | 295 |
| 276 if (needs_flush) { | 296 if (needs_flush) { |
| 277 DVLOG(1) << "DecodeInternal needs flush."; | 297 DVLOG(1) << "DecodeInternal needs flush."; |
| 278 input_eos_encountered_ = false; | 298 input_eos_encountered_ = false; |
| 279 output_eos_encountered_ = false; | 299 output_eos_encountered_ = false; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 presentation_timestamp, start_presentation_timestamp); | 401 presentation_timestamp, start_presentation_timestamp); |
| 382 } else { | 402 } else { |
| 383 presentation_timestamp = kNoTimestamp(); | 403 presentation_timestamp = kNoTimestamp(); |
| 384 } | 404 } |
| 385 ReleaseOutputCompletionCallback completion_callback = base::Bind( | 405 ReleaseOutputCompletionCallback completion_callback = base::Bind( |
| 386 callback, status, presentation_timestamp); | 406 callback, status, presentation_timestamp); |
| 387 ReleaseOutputBuffer(buffer_index, size, render_output, completion_callback); | 407 ReleaseOutputBuffer(buffer_index, size, render_output, completion_callback); |
| 388 } | 408 } |
| 389 | 409 |
| 390 void MediaDecoderJob::OnDecodeCompleted( | 410 void MediaDecoderJob::OnDecodeCompleted( |
| 391 MediaCodecStatus status, const base::TimeDelta& presentation_timestamp, | 411 MediaCodecStatus status, base::TimeDelta presentation_timestamp, |
| 392 size_t audio_output_bytes) { | 412 size_t audio_output_bytes) { |
| 393 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 413 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 394 | 414 |
| 395 if (destroy_pending_) { | 415 if (destroy_pending_) { |
| 396 DVLOG(1) << __FUNCTION__ << " : completing pending deletion"; | 416 DVLOG(1) << __FUNCTION__ << " : completing pending deletion"; |
| 397 delete this; | 417 delete this; |
| 398 return; | 418 return; |
| 399 } | 419 } |
| 400 | 420 |
| 401 DCHECK(!decode_cb_.is_null()); | 421 DCHECK(!decode_cb_.is_null()); |
| 402 | 422 |
| 403 // If output was queued for rendering, then we have completed prerolling. | 423 // If output was queued for rendering, then we have completed prerolling. |
| 404 if (presentation_timestamp != kNoTimestamp()) | 424 if (presentation_timestamp != kNoTimestamp()) |
| 405 prerolling_ = false; | 425 prerolling_ = false; |
| 406 | 426 |
| 407 switch (status) { | 427 switch (status) { |
| 408 case MEDIA_CODEC_OK: | 428 case MEDIA_CODEC_OK: |
| 409 case MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: | 429 case MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: |
| 410 case MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED: | 430 case MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED: |
| 411 case MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: | 431 case MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: |
| 412 case MEDIA_CODEC_OUTPUT_END_OF_STREAM: | 432 case MEDIA_CODEC_OUTPUT_END_OF_STREAM: |
| 413 if (!input_eos_encountered_) | 433 if (!input_eos_encountered_) |
| 414 access_unit_index_++; | 434 access_unit_index_[current_demuxer_data_index_]++; |
| 415 break; | 435 break; |
| 416 | 436 |
| 417 case MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER: | 437 case MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER: |
| 418 case MEDIA_CODEC_INPUT_END_OF_STREAM: | 438 case MEDIA_CODEC_INPUT_END_OF_STREAM: |
| 419 case MEDIA_CODEC_NO_KEY: | 439 case MEDIA_CODEC_NO_KEY: |
| 420 case MEDIA_CODEC_STOPPED: | 440 case MEDIA_CODEC_STOPPED: |
| 421 case MEDIA_CODEC_ERROR: | 441 case MEDIA_CODEC_ERROR: |
| 422 // Do nothing. | 442 // Do nothing. |
| 423 break; | 443 break; |
| 424 }; | 444 }; |
| 425 | 445 |
| 426 stop_decode_pending_ = false; | 446 stop_decode_pending_ = false; |
| 427 base::ResetAndReturn(&decode_cb_).Run(status, presentation_timestamp, | 447 base::ResetAndReturn(&decode_cb_).Run(status, presentation_timestamp, |
| 428 audio_output_bytes); | 448 audio_output_bytes); |
| 429 } | 449 } |
| 430 | 450 |
| 451 const AccessUnit& MediaDecoderJob::CurrentAccessUnit() const { | |
| 452 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 453 DCHECK(HasData()); | |
| 454 int index = NoAccessUnitsRemainingInChunk(true) ? | |
| 455 inactive_demuxer_data_index() : current_demuxer_data_index_; | |
| 456 return received_data_[index].access_units[access_unit_index_[index]]; | |
| 457 } | |
| 458 | |
| 459 bool MediaDecoderJob::NoAccessUnitsRemainingInChunk(bool current_chunk) const { | |
|
wolenetz
2014/03/19 17:26:05
nit: s/current_chunk/is_active_chunk/ to match dec
qinmin
2014/03/19 19:24:55
Done.
| |
| 460 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 461 size_t index = current_chunk ? current_demuxer_data_index_ : | |
|
wolenetz
2014/03/19 17:26:05
nit: ditto
qinmin
2014/03/19 19:24:55
Done.
| |
| 462 inactive_demuxer_data_index(); | |
| 463 return received_data_[index].access_units.size() <= access_unit_index_[index]; | |
| 464 } | |
| 465 | |
| 466 void MediaDecoderJob::ClearData() { | |
| 467 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 468 current_demuxer_data_index_ = 0; | |
| 469 InitializeReceivedData(); | |
| 470 on_data_received_cb_.Reset(); | |
| 471 if (is_requesting_demuxer_data_) | |
| 472 is_incoming_data_invalid_ = true; | |
| 473 input_eos_encountered_ = false; | |
| 474 } | |
| 475 | |
| 476 void MediaDecoderJob::RequestCurrentChunkIfEmpty() { | |
| 477 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 478 DCHECK(HasData()); | |
| 479 if (!NoAccessUnitsRemainingInChunk(true)) | |
| 480 return; | |
| 481 | |
| 482 // Requests new data if the the last access unit of the next chunk is not EOS. | |
| 483 current_demuxer_data_index_ = inactive_demuxer_data_index(); | |
| 484 const AccessUnit last_access_unit = | |
| 485 received_data_[current_demuxer_data_index_].access_units.back(); | |
| 486 if (!last_access_unit.end_of_stream && | |
| 487 last_access_unit.status != DemuxerStream::kConfigChanged && | |
| 488 last_access_unit.status != DemuxerStream::kAborted) { | |
| 489 RequestData(base::Closure()); | |
| 490 } | |
| 491 } | |
| 492 | |
| 493 void MediaDecoderJob::InitializeReceivedData() { | |
| 494 for (size_t i = 0; i < 2; ++i) { | |
| 495 received_data_[i] = DemuxerData(); | |
| 496 access_unit_index_[i] = 0; | |
| 497 } | |
| 498 } | |
| 499 | |
| 431 } // namespace media | 500 } // namespace media |
| OLD | NEW |