| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_codec_video_decoder.h" | 5 #include "media/base/android/media_codec_video_decoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "media/base/android/media_codec_bridge.h" | 9 #include "media/base/android/media_codec_bridge.h" |
| 10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
| 11 #include "media/base/demuxer_stream.h" | 11 #include "media/base/demuxer_stream.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 const int kDelayForStandAloneEOS = 2; // milliseconds | 16 const int kDelayForStandAloneEOS = 2; // milliseconds |
| 17 } | 17 } |
| 18 | 18 |
| 19 MediaCodecVideoDecoder::MediaCodecVideoDecoder( | 19 MediaCodecVideoDecoder::MediaCodecVideoDecoder( |
| 20 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, | 20 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 21 const base::Closure& request_data_cb, | 21 const base::Closure& request_data_cb, |
| 22 const base::Closure& starvation_cb, | 22 const base::Closure& starvation_cb, |
| 23 const base::Closure& preroll_done_cb, |
| 23 const base::Closure& stop_done_cb, | 24 const base::Closure& stop_done_cb, |
| 24 const base::Closure& error_cb, | 25 const base::Closure& error_cb, |
| 25 const SetTimeCallback& update_current_time_cb, | 26 const SetTimeCallback& update_current_time_cb, |
| 26 const VideoSizeChangedCallback& video_size_changed_cb, | 27 const VideoSizeChangedCallback& video_size_changed_cb, |
| 27 const base::Closure& codec_created_cb) | 28 const base::Closure& codec_created_cb) |
| 28 : MediaCodecDecoder(media_task_runner, | 29 : MediaCodecDecoder(media_task_runner, |
| 29 request_data_cb, | 30 request_data_cb, |
| 30 starvation_cb, | 31 starvation_cb, |
| 32 preroll_done_cb, |
| 31 stop_done_cb, | 33 stop_done_cb, |
| 32 error_cb, | 34 error_cb, |
| 33 "VideoDecoder"), | 35 "VideoDecoder"), |
| 34 update_current_time_cb_(update_current_time_cb), | 36 update_current_time_cb_(update_current_time_cb), |
| 35 video_size_changed_cb_(video_size_changed_cb), | 37 video_size_changed_cb_(video_size_changed_cb), |
| 36 codec_created_cb_(codec_created_cb) { | 38 codec_created_cb_(codec_created_cb) { |
| 37 } | 39 } |
| 38 | 40 |
| 39 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { | 41 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { |
| 40 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; | 42 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return CONFIG_FAILURE; | 154 return CONFIG_FAILURE; |
| 153 } | 155 } |
| 154 | 156 |
| 155 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " succeeded"; | 157 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " succeeded"; |
| 156 | 158 |
| 157 media_task_runner_->PostTask(FROM_HERE, codec_created_cb_); | 159 media_task_runner_->PostTask(FROM_HERE, codec_created_cb_); |
| 158 | 160 |
| 159 return CONFIG_OK; | 161 return CONFIG_OK; |
| 160 } | 162 } |
| 161 | 163 |
| 162 void MediaCodecVideoDecoder::SynchronizePTSWithTime( | 164 void MediaCodecVideoDecoder::AssociateCurrentTimeWithPTS(base::TimeDelta pts) { |
| 163 base::TimeDelta current_time) { | |
| 164 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 165 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 165 | 166 |
| 166 start_time_ticks_ = base::TimeTicks::Now(); | 167 start_time_ticks_ = base::TimeTicks::Now(); |
| 167 start_pts_ = current_time; | 168 start_pts_ = pts; |
| 168 last_seen_pts_ = current_time; | 169 last_seen_pts_ = pts; |
| 170 } |
| 171 |
| 172 void MediaCodecVideoDecoder::DissociatePTSFromTime() { |
| 173 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 174 |
| 175 start_pts_ = last_seen_pts_ = kNoTimestamp(); |
| 169 } | 176 } |
| 170 | 177 |
| 171 void MediaCodecVideoDecoder::OnOutputFormatChanged() { | 178 void MediaCodecVideoDecoder::OnOutputFormatChanged() { |
| 172 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 179 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 173 | 180 |
| 174 gfx::Size prev_size = video_size_; | 181 gfx::Size prev_size = video_size_; |
| 175 | 182 |
| 176 // See b/18224769. The values reported from MediaCodecBridge::GetOutputFormat | 183 // See b/18224769. The values reported from MediaCodecBridge::GetOutputFormat |
| 177 // correspond to the actual video frame size, but this is not necessarily the | 184 // correspond to the actual video frame size, but this is not necessarily the |
| 178 // size that should be output. | 185 // size that should be output. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 199 if (!size && eos_encountered) { | 206 if (!size && eos_encountered) { |
| 200 // Stand-alone EOS | 207 // Stand-alone EOS |
| 201 // Discard the PTS that comes with it and ensure it is released last. | 208 // Discard the PTS that comes with it and ensure it is released last. |
| 202 pts = last_seen_pts_ + | 209 pts = last_seen_pts_ + |
| 203 base::TimeDelta::FromMilliseconds(kDelayForStandAloneEOS); | 210 base::TimeDelta::FromMilliseconds(kDelayForStandAloneEOS); |
| 204 } else { | 211 } else { |
| 205 // Keep track of last seen PTS | 212 // Keep track of last seen PTS |
| 206 last_seen_pts_ = pts; | 213 last_seen_pts_ = pts; |
| 207 } | 214 } |
| 208 | 215 |
| 209 if (!render_output) { | 216 if (!render_output || start_pts_ == kNoTimestamp()) { |
| 210 ReleaseOutputBuffer(buffer_index, pts, size, false, eos_encountered); | 217 ReleaseOutputBuffer(buffer_index, pts, size, false, eos_encountered); |
| 211 return; | 218 return; |
| 212 } | 219 } |
| 213 | 220 |
| 214 base::TimeDelta time_to_render = | 221 base::TimeDelta time_to_render = |
| 215 pts - (base::TimeTicks::Now() - start_time_ticks_ + start_pts_); | 222 pts - (base::TimeTicks::Now() - start_time_ticks_ + start_pts_); |
| 216 | 223 |
| 217 if (time_to_render < base::TimeDelta()) { | 224 if (time_to_render < base::TimeDelta()) { |
| 218 // Skip late frames | 225 // Skip late frames |
| 219 ReleaseOutputBuffer(buffer_index, pts, size, false, eos_encountered); | 226 ReleaseOutputBuffer(buffer_index, pts, size, false, eos_encountered); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 281 |
| 275 // |update_current_time_cb_| might be null if there is audio stream. | 282 // |update_current_time_cb_| might be null if there is audio stream. |
| 276 // Do not update current time for stand-alone EOS frames. | 283 // Do not update current time for stand-alone EOS frames. |
| 277 if (!update_current_time_cb_.is_null() && !(eos_encountered && !size)) { | 284 if (!update_current_time_cb_.is_null() && !(eos_encountered && !size)) { |
| 278 media_task_runner_->PostTask(FROM_HERE, | 285 media_task_runner_->PostTask(FROM_HERE, |
| 279 base::Bind(update_current_time_cb_, pts, pts)); | 286 base::Bind(update_current_time_cb_, pts, pts)); |
| 280 } | 287 } |
| 281 } | 288 } |
| 282 | 289 |
| 283 } // namespace media | 290 } // namespace media |
| OLD | NEW |