| 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/video_media_codec_decoder.h" | 5 #include "media/base/android/video_media_codec_decoder.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // correspond to the actual video frame size, but this is not necessarily the | 214 // correspond to the actual video frame size, but this is not necessarily the |
| 215 // size that should be output. | 215 // size that should be output. |
| 216 video_size_ = configs_.video_size; | 216 video_size_ = configs_.video_size; |
| 217 if (video_size_ != prev_size) { | 217 if (video_size_ != prev_size) { |
| 218 media_task_runner_->PostTask( | 218 media_task_runner_->PostTask( |
| 219 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); | 219 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); |
| 220 } | 220 } |
| 221 return true; | 221 return true; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void VideoMediaCodecDecoder::Render(int buffer_index, | 224 bool VideoMediaCodecDecoder::Render(int buffer_index, |
| 225 size_t offset, | 225 size_t offset, |
| 226 size_t size, | 226 size_t size, |
| 227 RenderMode render_mode, | 227 RenderMode render_mode, |
| 228 base::TimeDelta pts, | 228 base::TimeDelta pts, |
| 229 bool eos_encountered) { | 229 bool eos_encountered) { |
| 230 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 230 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 231 | 231 |
| 232 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts | 232 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts |
| 233 << (eos_encountered ? " EOS " : " ") << AsString(render_mode); | 233 << (eos_encountered ? " EOS " : " ") << AsString(render_mode); |
| 234 | 234 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 246 | 246 |
| 247 // Do not update time for stand-alone EOS. | 247 // Do not update time for stand-alone EOS. |
| 248 const bool update_time = !(eos_encountered && size == 0u); | 248 const bool update_time = !(eos_encountered && size == 0u); |
| 249 | 249 |
| 250 // For video we simplify the preroll operation and render the first frame | 250 // For video we simplify the preroll operation and render the first frame |
| 251 // after preroll during the preroll phase, i.e. without waiting for audio | 251 // after preroll during the preroll phase, i.e. without waiting for audio |
| 252 // stream to finish prerolling. | 252 // stream to finish prerolling. |
| 253 switch (render_mode) { | 253 switch (render_mode) { |
| 254 case kRenderSkip: | 254 case kRenderSkip: |
| 255 ReleaseOutputBuffer(buffer_index, pts, false, false, eos_encountered); | 255 ReleaseOutputBuffer(buffer_index, pts, false, false, eos_encountered); |
| 256 return; | 256 return true; |
| 257 case kRenderAfterPreroll: | 257 case kRenderAfterPreroll: |
| 258 // We get here in the preroll phase. Render now as explained above. | 258 // We get here in the preroll phase. Render now as explained above. |
| 259 // |start_pts_| is not set yet, thus we cannot calculate |time_to_render|. | 259 // |start_pts_| is not set yet, thus we cannot calculate |time_to_render|. |
| 260 ReleaseOutputBuffer(buffer_index, pts, (size > 0), update_time, | 260 ReleaseOutputBuffer(buffer_index, pts, (size > 0), update_time, |
| 261 eos_encountered); | 261 eos_encountered); |
| 262 return; | 262 return true; |
| 263 case kRenderNow: | 263 case kRenderNow: |
| 264 break; | 264 break; |
| 265 } | 265 } |
| 266 | 266 |
| 267 DCHECK_EQ(kRenderNow, render_mode); | 267 DCHECK_EQ(kRenderNow, render_mode); |
| 268 DCHECK_NE(kNoTimestamp(), start_pts_); // start_pts_ must be set | 268 DCHECK_NE(kNoTimestamp(), start_pts_); // start_pts_ must be set |
| 269 | 269 |
| 270 base::TimeDelta time_to_render = | 270 base::TimeDelta time_to_render = |
| 271 pts - (base::TimeTicks::Now() - start_time_ticks_ + start_pts_); | 271 pts - (base::TimeTicks::Now() - start_time_ticks_ + start_pts_); |
| 272 | 272 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 283 if (render) { | 283 if (render) { |
| 284 DVLOG(2) << class_name() << "::" << __FUNCTION__ | 284 DVLOG(2) << class_name() << "::" << __FUNCTION__ |
| 285 << " LATE FRAME delay:" << (-1) * time_to_render; | 285 << " LATE FRAME delay:" << (-1) * time_to_render; |
| 286 | 286 |
| 287 frame_statistics_->IncrementLateFrameCount(); | 287 frame_statistics_->IncrementLateFrameCount(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 // Render late frames immediately. | 290 // Render late frames immediately. |
| 291 ReleaseOutputBuffer(buffer_index, pts, render, update_time, | 291 ReleaseOutputBuffer(buffer_index, pts, render, update_time, |
| 292 eos_encountered); | 292 eos_encountered); |
| 293 return; | 293 return true; |
| 294 } | 294 } |
| 295 | 295 |
| 296 delayed_buffers_.insert(buffer_index); | 296 delayed_buffers_.insert(buffer_index); |
| 297 | 297 |
| 298 decoder_thread_.task_runner()->PostDelayedTask( | 298 decoder_thread_.task_runner()->PostDelayedTask( |
| 299 FROM_HERE, base::Bind(&VideoMediaCodecDecoder::ReleaseOutputBuffer, | 299 FROM_HERE, base::Bind(&VideoMediaCodecDecoder::ReleaseOutputBuffer, |
| 300 base::Unretained(this), buffer_index, pts, render, | 300 base::Unretained(this), buffer_index, pts, render, |
| 301 update_time, eos_encountered), | 301 update_time, eos_encountered), |
| 302 time_to_render); | 302 time_to_render); |
| 303 |
| 304 return true; |
| 303 } | 305 } |
| 304 | 306 |
| 305 int VideoMediaCodecDecoder::NumDelayedRenderTasks() const { | 307 int VideoMediaCodecDecoder::NumDelayedRenderTasks() const { |
| 306 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 308 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 307 | 309 |
| 308 return delayed_buffers_.size(); | 310 return delayed_buffers_.size(); |
| 309 } | 311 } |
| 310 | 312 |
| 311 void VideoMediaCodecDecoder::ReleaseDelayedBuffers() { | 313 void VideoMediaCodecDecoder::ReleaseDelayedBuffers() { |
| 312 // Media thread | 314 // Media thread |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 350 |
| 349 // |update_current_time_cb_| might be null if there is audio stream. | 351 // |update_current_time_cb_| might be null if there is audio stream. |
| 350 // Do not update current time for stand-alone EOS frames. | 352 // Do not update current time for stand-alone EOS frames. |
| 351 if (!update_current_time_cb_.is_null() && update_time) { | 353 if (!update_current_time_cb_.is_null() && update_time) { |
| 352 media_task_runner_->PostTask( | 354 media_task_runner_->PostTask( |
| 353 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, false)); | 355 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, false)); |
| 354 } | 356 } |
| 355 } | 357 } |
| 356 | 358 |
| 357 } // namespace media | 359 } // namespace media |
| OLD | NEW |