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 27 matching lines...) Expand all Loading... |
38 input_buf_index_(-1), | 38 input_buf_index_(-1), |
39 is_content_encrypted_(false), | 39 is_content_encrypted_(false), |
40 stop_decode_pending_(false), | 40 stop_decode_pending_(false), |
41 destroy_pending_(false), | 41 destroy_pending_(false), |
42 is_requesting_demuxer_data_(false), | 42 is_requesting_demuxer_data_(false), |
43 is_incoming_data_invalid_(false), | 43 is_incoming_data_invalid_(false), |
44 release_resources_pending_(false), | 44 release_resources_pending_(false), |
45 drm_bridge_(NULL), | 45 drm_bridge_(NULL), |
46 drain_decoder_(false) { | 46 drain_decoder_(false) { |
47 InitializeReceivedData(); | 47 InitializeReceivedData(); |
48 eos_unit_.end_of_stream = true; | 48 eos_unit_.is_end_of_stream = true; |
49 } | 49 } |
50 | 50 |
51 MediaDecoderJob::~MediaDecoderJob() { | 51 MediaDecoderJob::~MediaDecoderJob() { |
52 ReleaseMediaCodecBridge(); | 52 ReleaseMediaCodecBridge(); |
53 } | 53 } |
54 | 54 |
55 void MediaDecoderJob::OnDataReceived(const DemuxerData& data) { | 55 void MediaDecoderJob::OnDataReceived(const DemuxerData& data) { |
56 DVLOG(1) << __FUNCTION__ << ": " << data.access_units.size() << " units"; | 56 DVLOG(1) << __FUNCTION__ << ": " << data.access_units.size() << " units"; |
57 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 57 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
58 DCHECK(NoAccessUnitsRemainingInChunk(false)); | 58 DCHECK(NoAccessUnitsRemainingInChunk(false)); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 MediaCodecStatus status = | 239 MediaCodecStatus status = |
240 media_codec_bridge_->DequeueInputBuffer(timeout, &input_buf_index); | 240 media_codec_bridge_->DequeueInputBuffer(timeout, &input_buf_index); |
241 if (status != MEDIA_CODEC_OK) { | 241 if (status != MEDIA_CODEC_OK) { |
242 DVLOG(1) << "DequeueInputBuffer fails: " << status; | 242 DVLOG(1) << "DequeueInputBuffer fails: " << status; |
243 return status; | 243 return status; |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 // TODO(qinmin): skip frames if video is falling far behind. | 247 // TODO(qinmin): skip frames if video is falling far behind. |
248 DCHECK_GE(input_buf_index, 0); | 248 DCHECK_GE(input_buf_index, 0); |
249 if (unit.end_of_stream || unit.data.empty()) { | 249 if (unit.is_end_of_stream || unit.data.empty()) { |
250 media_codec_bridge_->QueueEOS(input_buf_index); | 250 media_codec_bridge_->QueueEOS(input_buf_index); |
251 return MEDIA_CODEC_INPUT_END_OF_STREAM; | 251 return MEDIA_CODEC_INPUT_END_OF_STREAM; |
252 } | 252 } |
253 | 253 |
254 if (unit.key_id.empty() || unit.iv.empty()) { | 254 if (unit.key_id.empty() || unit.iv.empty()) { |
255 DCHECK(unit.iv.empty() || !unit.key_id.empty()); | 255 DCHECK(unit.iv.empty() || !unit.key_id.empty()); |
256 return media_codec_bridge_->QueueInputBuffer( | 256 return media_codec_bridge_->QueueInputBuffer( |
257 input_buf_index, &unit.data[0], unit.data.size(), unit.timestamp); | 257 input_buf_index, &unit.data[0], unit.data.size(), unit.timestamp); |
258 } | 258 } |
259 | 259 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // EOS. | 379 // EOS. |
380 DCHECK(!output_eos_encountered_); | 380 DCHECK(!output_eos_encountered_); |
381 | 381 |
382 // For aborted access unit, just skip it and inform the player. | 382 // For aborted access unit, just skip it and inform the player. |
383 if (unit.status == DemuxerStream::kAborted) { | 383 if (unit.status == DemuxerStream::kAborted) { |
384 callback.Run(MEDIA_CODEC_ABORT, kNoTimestamp(), kNoTimestamp()); | 384 callback.Run(MEDIA_CODEC_ABORT, kNoTimestamp(), kNoTimestamp()); |
385 return; | 385 return; |
386 } | 386 } |
387 | 387 |
388 if (skip_eos_enqueue_) { | 388 if (skip_eos_enqueue_) { |
389 if (unit.end_of_stream || unit.data.empty()) { | 389 if (unit.is_end_of_stream || unit.data.empty()) { |
390 input_eos_encountered_ = true; | 390 input_eos_encountered_ = true; |
391 output_eos_encountered_ = true; | 391 output_eos_encountered_ = true; |
392 callback.Run(MEDIA_CODEC_OUTPUT_END_OF_STREAM, kNoTimestamp(), | 392 callback.Run(MEDIA_CODEC_OUTPUT_END_OF_STREAM, kNoTimestamp(), |
393 kNoTimestamp()); | 393 kNoTimestamp()); |
394 return; | 394 return; |
395 } | 395 } |
396 | 396 |
397 skip_eos_enqueue_ = false; | 397 skip_eos_enqueue_ = false; |
398 } | 398 } |
399 | 399 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 void MediaDecoderJob::RequestCurrentChunkIfEmpty() { | 583 void MediaDecoderJob::RequestCurrentChunkIfEmpty() { |
584 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 584 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
585 DCHECK(HasData()); | 585 DCHECK(HasData()); |
586 if (!NoAccessUnitsRemainingInChunk(true)) | 586 if (!NoAccessUnitsRemainingInChunk(true)) |
587 return; | 587 return; |
588 | 588 |
589 // Requests new data if the the last access unit of the next chunk is not EOS. | 589 // Requests new data if the the last access unit of the next chunk is not EOS. |
590 current_demuxer_data_index_ = inactive_demuxer_data_index(); | 590 current_demuxer_data_index_ = inactive_demuxer_data_index(); |
591 const AccessUnit last_access_unit = | 591 const AccessUnit last_access_unit = |
592 received_data_[current_demuxer_data_index_].access_units.back(); | 592 received_data_[current_demuxer_data_index_].access_units.back(); |
593 if (!last_access_unit.end_of_stream && | 593 if (!last_access_unit.is_end_of_stream && |
594 last_access_unit.status != DemuxerStream::kAborted) { | 594 last_access_unit.status != DemuxerStream::kAborted) { |
595 RequestData(base::Closure()); | 595 RequestData(base::Closure()); |
596 } | 596 } |
597 } | 597 } |
598 | 598 |
599 void MediaDecoderJob::InitializeReceivedData() { | 599 void MediaDecoderJob::InitializeReceivedData() { |
600 for (size_t i = 0; i < 2; ++i) { | 600 for (size_t i = 0; i < 2; ++i) { |
601 received_data_[i] = DemuxerData(); | 601 received_data_[i] = DemuxerData(); |
602 access_unit_index_[i] = 0; | 602 access_unit_index_[i] = 0; |
603 } | 603 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 655 |
656 void MediaDecoderJob::ReleaseMediaCodecBridge() { | 656 void MediaDecoderJob::ReleaseMediaCodecBridge() { |
657 if (!media_codec_bridge_) | 657 if (!media_codec_bridge_) |
658 return; | 658 return; |
659 | 659 |
660 media_codec_bridge_.reset(); | 660 media_codec_bridge_.reset(); |
661 input_buf_index_ = -1; | 661 input_buf_index_ = -1; |
662 } | 662 } |
663 | 663 |
664 } // namespace media | 664 } // namespace media |
OLD | NEW |