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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 if (HasData()) { | 95 if (HasData()) { |
96 DVLOG(1) << __FUNCTION__ << " : using previously received data"; | 96 DVLOG(1) << __FUNCTION__ << " : using previously received data"; |
97 ui_task_runner_->PostTask(FROM_HERE, prefetch_cb); | 97 ui_task_runner_->PostTask(FROM_HERE, prefetch_cb); |
98 return; | 98 return; |
99 } | 99 } |
100 | 100 |
101 DVLOG(1) << __FUNCTION__ << " : requesting data"; | 101 DVLOG(1) << __FUNCTION__ << " : requesting data"; |
102 RequestData(prefetch_cb); | 102 RequestData(prefetch_cb); |
103 } | 103 } |
104 | 104 |
105 bool MediaDecoderJob::Decode( | 105 DemuxerConfigs* MediaDecoderJob::Decode( |
106 base::TimeTicks start_time_ticks, | 106 base::TimeTicks start_time_ticks, |
107 base::TimeDelta start_presentation_timestamp, | 107 base::TimeDelta start_presentation_timestamp, |
108 const DecoderCallback& callback) { | 108 const DecoderCallback& callback) { |
109 DCHECK(decode_cb_.is_null()); | 109 DCHECK(decode_cb_.is_null()); |
110 DCHECK(on_data_received_cb_.is_null()); | 110 DCHECK(on_data_received_cb_.is_null()); |
111 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 111 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
112 | 112 |
113 decode_cb_ = callback; | 113 decode_cb_ = callback; |
114 | 114 |
115 if (!HasData()) { | 115 if (!HasData()) { |
116 RequestData(base::Bind(&MediaDecoderJob::DecodeCurrentAccessUnit, | 116 RequestData(base::Bind(&MediaDecoderJob::DecodeCurrentAccessUnit, |
117 base::Unretained(this), | 117 base::Unretained(this), |
118 start_time_ticks, | 118 start_time_ticks, |
119 start_presentation_timestamp)); | 119 start_presentation_timestamp)); |
120 return true; | 120 return NULL; |
121 } | 121 } |
122 | 122 |
123 if (DemuxerStream::kConfigChanged == CurrentAccessUnit().status) { | 123 if (DemuxerStream::kConfigChanged == CurrentAccessUnit().status) { |
124 // Clear received data because we need to handle a config change. | 124 // Clear received data because we need to handle a config change. |
125 decode_cb_.Reset(); | 125 decode_cb_.Reset(); |
126 ClearData(); | 126 size_t index = CurrentReceivedDataChunkIndex(); |
127 return false; | 127 return &(received_data_[index].demuxer_configs[0]); |
wolenetz
2014/05/05 22:06:55
Before returning, please protect against [0] which
qinmin
2014/05/06 18:05:26
Changed this function to return a new pointer and
| |
128 } | 128 } |
129 | 129 |
130 DecodeCurrentAccessUnit(start_time_ticks, start_presentation_timestamp); | 130 DecodeCurrentAccessUnit(start_time_ticks, start_presentation_timestamp); |
131 return true; | 131 return NULL; |
132 } | 132 } |
133 | 133 |
134 void MediaDecoderJob::StopDecode() { | 134 void MediaDecoderJob::StopDecode() { |
135 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 135 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
136 DCHECK(is_decoding()); | 136 DCHECK(is_decoding()); |
137 stop_decode_pending_ = true; | 137 stop_decode_pending_ = true; |
138 } | 138 } |
139 | 139 |
140 void MediaDecoderJob::Flush() { | 140 void MediaDecoderJob::Flush() { |
141 DCHECK(decode_cb_.is_null()); | 141 DCHECK(decode_cb_.is_null()); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 }; | 455 }; |
456 | 456 |
457 stop_decode_pending_ = false; | 457 stop_decode_pending_ = false; |
458 base::ResetAndReturn(&decode_cb_).Run( | 458 base::ResetAndReturn(&decode_cb_).Run( |
459 status, current_presentation_timestamp, max_presentation_timestamp); | 459 status, current_presentation_timestamp, max_presentation_timestamp); |
460 } | 460 } |
461 | 461 |
462 const AccessUnit& MediaDecoderJob::CurrentAccessUnit() const { | 462 const AccessUnit& MediaDecoderJob::CurrentAccessUnit() const { |
463 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 463 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
464 DCHECK(HasData()); | 464 DCHECK(HasData()); |
465 int index = NoAccessUnitsRemainingInChunk(true) ? | 465 size_t index = CurrentReceivedDataChunkIndex(); |
466 return received_data_[index].access_units[access_unit_index_[index]]; | |
467 } | |
468 | |
469 size_t MediaDecoderJob::CurrentReceivedDataChunkIndex() const { | |
470 return NoAccessUnitsRemainingInChunk(true) ? | |
466 inactive_demuxer_data_index() : current_demuxer_data_index_; | 471 inactive_demuxer_data_index() : current_demuxer_data_index_; |
467 return received_data_[index].access_units[access_unit_index_[index]]; | |
468 } | 472 } |
469 | 473 |
470 bool MediaDecoderJob::NoAccessUnitsRemainingInChunk( | 474 bool MediaDecoderJob::NoAccessUnitsRemainingInChunk( |
471 bool is_active_chunk) const { | 475 bool is_active_chunk) const { |
472 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 476 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
473 size_t index = is_active_chunk ? current_demuxer_data_index_ : | 477 size_t index = is_active_chunk ? current_demuxer_data_index_ : |
474 inactive_demuxer_data_index(); | 478 inactive_demuxer_data_index(); |
475 return received_data_[index].access_units.size() <= access_unit_index_[index]; | 479 return received_data_[index].access_units.size() <= access_unit_index_[index]; |
476 } | 480 } |
477 | 481 |
(...skipping 25 matching lines...) Expand all Loading... | |
503 } | 507 } |
504 | 508 |
505 void MediaDecoderJob::InitializeReceivedData() { | 509 void MediaDecoderJob::InitializeReceivedData() { |
506 for (size_t i = 0; i < 2; ++i) { | 510 for (size_t i = 0; i < 2; ++i) { |
507 received_data_[i] = DemuxerData(); | 511 received_data_[i] = DemuxerData(); |
508 access_unit_index_[i] = 0; | 512 access_unit_index_[i] = 0; |
509 } | 513 } |
510 } | 514 } |
511 | 515 |
512 } // namespace media | 516 } // namespace media |
OLD | NEW |