| 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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 needs_flush_(false), | 27 needs_flush_(false), |
| 28 input_eos_encountered_(false), | 28 input_eos_encountered_(false), |
| 29 weak_this_(this), | 29 weak_this_(this), |
| 30 request_data_cb_(request_data_cb), | 30 request_data_cb_(request_data_cb), |
| 31 access_unit_index_(0), | 31 access_unit_index_(0), |
| 32 stop_decode_pending_(false) { | 32 stop_decode_pending_(false) { |
| 33 } | 33 } |
| 34 | 34 |
| 35 MediaDecoderJob::~MediaDecoderJob() {} | 35 MediaDecoderJob::~MediaDecoderJob() {} |
| 36 | 36 |
| 37 void MediaDecoderJob::OnDataReceived( | 37 void MediaDecoderJob::OnDataReceived(const DemuxerData& data) { |
| 38 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params& params) { | |
| 39 DCHECK(ui_loop_->BelongsToCurrentThread()); | 38 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| 40 DCHECK(!on_data_received_cb_.is_null()); | 39 DCHECK(!on_data_received_cb_.is_null()); |
| 41 | 40 |
| 42 base::Closure done_cb = base::ResetAndReturn(&on_data_received_cb_); | 41 base::Closure done_cb = base::ResetAndReturn(&on_data_received_cb_); |
| 43 | 42 |
| 44 if (stop_decode_pending_) { | 43 if (stop_decode_pending_) { |
| 45 OnDecodeCompleted(DECODE_STOPPED, kNoTimestamp(), 0); | 44 OnDecodeCompleted(DECODE_STOPPED, kNoTimestamp(), 0); |
| 46 return; | 45 return; |
| 47 } | 46 } |
| 48 | 47 |
| 49 access_unit_index_ = 0; | 48 access_unit_index_ = 0; |
| 50 received_data_ = params; | 49 received_data_ = data; |
| 51 done_cb.Run(); | 50 done_cb.Run(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 bool MediaDecoderJob::HasData() const { | 53 bool MediaDecoderJob::HasData() const { |
| 55 DCHECK(ui_loop_->BelongsToCurrentThread()); | 54 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| 56 return access_unit_index_ < received_data_.access_units.size(); | 55 return access_unit_index_ < received_data_.access_units.size(); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void MediaDecoderJob::Prefetch(const base::Closure& prefetch_cb) { | 58 void MediaDecoderJob::Prefetch(const base::Closure& prefetch_cb) { |
| 60 DCHECK(ui_loop_->BelongsToCurrentThread()); | 59 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 84 base::Unretained(this), | 83 base::Unretained(this), |
| 85 start_time_ticks, | 84 start_time_ticks, |
| 86 start_presentation_timestamp)); | 85 start_presentation_timestamp)); |
| 87 return true; | 86 return true; |
| 88 } | 87 } |
| 89 | 88 |
| 90 if (DemuxerStream::kConfigChanged == | 89 if (DemuxerStream::kConfigChanged == |
| 91 received_data_.access_units[access_unit_index_].status) { | 90 received_data_.access_units[access_unit_index_].status) { |
| 92 // Clear received data because we need to handle a config change. | 91 // Clear received data because we need to handle a config change. |
| 93 decode_cb_.Reset(); | 92 decode_cb_.Reset(); |
| 94 received_data_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 93 received_data_ = DemuxerData(); |
| 95 access_unit_index_ = 0; | 94 access_unit_index_ = 0; |
| 96 return false; | 95 return false; |
| 97 } | 96 } |
| 98 | 97 |
| 99 DecodeNextAccessUnit(start_time_ticks, start_presentation_timestamp); | 98 DecodeNextAccessUnit(start_time_ticks, start_presentation_timestamp); |
| 100 return true; | 99 return true; |
| 101 } | 100 } |
| 102 | 101 |
| 103 void MediaDecoderJob::StopDecode() { | 102 void MediaDecoderJob::StopDecode() { |
| 104 DCHECK(ui_loop_->BelongsToCurrentThread()); | 103 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| 105 DCHECK(is_decoding()); | 104 DCHECK(is_decoding()); |
| 106 stop_decode_pending_ = true; | 105 stop_decode_pending_ = true; |
| 107 } | 106 } |
| 108 | 107 |
| 109 void MediaDecoderJob::Flush() { | 108 void MediaDecoderJob::Flush() { |
| 110 DCHECK(decode_cb_.is_null()); | 109 DCHECK(decode_cb_.is_null()); |
| 111 | 110 |
| 112 // Do nothing, flush when the next Decode() happens. | 111 // Do nothing, flush when the next Decode() happens. |
| 113 needs_flush_ = true; | 112 needs_flush_ = true; |
| 114 | 113 |
| 115 received_data_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 114 received_data_ = DemuxerData(); |
| 116 access_unit_index_ = 0; | 115 access_unit_index_ = 0; |
| 117 on_data_received_cb_.Reset(); | 116 on_data_received_cb_.Reset(); |
| 118 } | 117 } |
| 119 | 118 |
| 120 void MediaDecoderJob::Release() { | 119 void MediaDecoderJob::Release() { |
| 121 // If is_decoding() returns false, there is nothing running on the decoder | 120 // If is_decoding() returns false, there is nothing running on the decoder |
| 122 // thread. So it is safe to delete the MediaDecoderJob on the UI thread. | 121 // thread. So it is safe to delete the MediaDecoderJob on the UI thread. |
| 123 // However, if we post a task to the decoder thread to delete object, then we | 122 // However, if we post a task to the decoder thread to delete object, then we |
| 124 // cannot immediately pass the surface to a new MediaDecoderJob instance | 123 // cannot immediately pass the surface to a new MediaDecoderJob instance |
| 125 // because the java surface is still owned by the old object. New decoder | 124 // because the java surface is still owned by the old object. New decoder |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 &unit.subsamples[0], unit.subsamples.size(), unit.timestamp); | 170 &unit.subsamples[0], unit.subsamples.size(), unit.timestamp); |
| 172 } | 171 } |
| 173 | 172 |
| 174 return DECODE_SUCCEEDED; | 173 return DECODE_SUCCEEDED; |
| 175 } | 174 } |
| 176 | 175 |
| 177 void MediaDecoderJob::RequestData(const base::Closure& done_cb) { | 176 void MediaDecoderJob::RequestData(const base::Closure& done_cb) { |
| 178 DCHECK(ui_loop_->BelongsToCurrentThread()); | 177 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| 179 DCHECK(on_data_received_cb_.is_null()); | 178 DCHECK(on_data_received_cb_.is_null()); |
| 180 | 179 |
| 181 received_data_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 180 received_data_ = DemuxerData(); |
| 182 access_unit_index_ = 0; | 181 access_unit_index_ = 0; |
| 183 on_data_received_cb_ = done_cb; | 182 on_data_received_cb_ = done_cb; |
| 184 | 183 |
| 185 request_data_cb_.Run(); | 184 request_data_cb_.Run(); |
| 186 } | 185 } |
| 187 | 186 |
| 188 void MediaDecoderJob::DecodeNextAccessUnit( | 187 void MediaDecoderJob::DecodeNextAccessUnit( |
| 189 const base::TimeTicks& start_time_ticks, | 188 const base::TimeTicks& start_time_ticks, |
| 190 const base::TimeDelta& start_presentation_timestamp) { | 189 const base::TimeDelta& start_presentation_timestamp) { |
| 191 DCHECK(ui_loop_->BelongsToCurrentThread()); | 190 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 status != MediaDecoderJob::DECODE_INPUT_END_OF_STREAM) { | 296 status != MediaDecoderJob::DECODE_INPUT_END_OF_STREAM) { |
| 298 access_unit_index_++; | 297 access_unit_index_++; |
| 299 } | 298 } |
| 300 | 299 |
| 301 stop_decode_pending_ = false; | 300 stop_decode_pending_ = false; |
| 302 base::ResetAndReturn(&decode_cb_).Run(status, presentation_timestamp, | 301 base::ResetAndReturn(&decode_cb_).Run(status, presentation_timestamp, |
| 303 audio_output_bytes); | 302 audio_output_bytes); |
| 304 } | 303 } |
| 305 | 304 |
| 306 } // namespace media | 305 } // namespace media |
| OLD | NEW |