Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/gpu/android_video_decode_accelerator.h" | 5 #include "media/gpu/android_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 get_gles2_decoder_cb_(get_gles2_decoder_cb), | 376 get_gles2_decoder_cb_(get_gles2_decoder_cb), |
| 377 state_(NO_ERROR), | 377 state_(NO_ERROR), |
| 378 picturebuffers_requested_(false), | 378 picturebuffers_requested_(false), |
| 379 drain_type_(DRAIN_TYPE_NONE), | 379 drain_type_(DRAIN_TYPE_NONE), |
| 380 media_drm_bridge_cdm_context_(nullptr), | 380 media_drm_bridge_cdm_context_(nullptr), |
| 381 cdm_registration_id_(0), | 381 cdm_registration_id_(0), |
| 382 pending_input_buf_index_(-1), | 382 pending_input_buf_index_(-1), |
| 383 error_sequence_token_(0), | 383 error_sequence_token_(0), |
| 384 defer_errors_(false), | 384 defer_errors_(false), |
| 385 deferred_initialization_pending_(false), | 385 deferred_initialization_pending_(false), |
| 386 codec_needs_reset_(false), | |
| 386 weak_this_factory_(this) {} | 387 weak_this_factory_(this) {} |
| 387 | 388 |
| 388 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { | 389 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { |
| 389 DCHECK(thread_checker_.CalledOnValidThread()); | 390 DCHECK(thread_checker_.CalledOnValidThread()); |
| 390 g_avda_timer.Pointer()->StopTimer(this); | 391 g_avda_timer.Pointer()->StopTimer(this); |
| 391 g_avda_timer.Pointer()->StopThread(this); | 392 g_avda_timer.Pointer()->StopThread(this); |
| 392 | 393 |
| 393 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 394 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 394 if (!media_drm_bridge_cdm_context_) | 395 if (!media_drm_bridge_cdm_context_) |
| 395 return; | 396 return; |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 893 | 894 |
| 894 // Connect the PictureBuffer to the decoded frame, via whatever mechanism the | 895 // Connect the PictureBuffer to the decoded frame, via whatever mechanism the |
| 895 // strategy likes. | 896 // strategy likes. |
| 896 strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second); | 897 strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second); |
| 897 } | 898 } |
| 898 | 899 |
| 899 void AndroidVideoDecodeAccelerator::Decode( | 900 void AndroidVideoDecodeAccelerator::Decode( |
| 900 const media::BitstreamBuffer& bitstream_buffer) { | 901 const media::BitstreamBuffer& bitstream_buffer) { |
| 901 DCHECK(thread_checker_.CalledOnValidThread()); | 902 DCHECK(thread_checker_.CalledOnValidThread()); |
| 902 | 903 |
| 904 // If we previously deferred a codec restart, take care of it now. This can | |
|
Tima Vaisburd
2016/05/24 19:06:26
Do you want to DCHECK that drain_type_ == DRAIN_TY
DaleCurtis
2016/05/24 23:53:14
Done.
| |
| 905 // happen on older devices where configuration changes require a codec reset. | |
| 906 if (codec_needs_reset_) | |
| 907 ResetCodecState(base::Closure()); | |
| 908 | |
| 903 if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) { | 909 if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) { |
| 904 DecodeBuffer(bitstream_buffer); | 910 DecodeBuffer(bitstream_buffer); |
| 905 return; | 911 return; |
| 906 } | 912 } |
| 907 | 913 |
| 908 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) | 914 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) |
| 909 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); | 915 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); |
| 910 | 916 |
| 911 if (bitstream_buffer.id() < 0) { | 917 if (bitstream_buffer.id() < 0) { |
| 912 POST_ERROR(INVALID_ARGUMENT, | 918 POST_ERROR(INVALID_ARGUMENT, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 // shm block been deleted. Check that it is safe to flush the coec, i.e. | 1178 // shm block been deleted. Check that it is safe to flush the coec, i.e. |
| 1173 // |pending_bitstream_buffers_| is empty. | 1179 // |pending_bitstream_buffers_| is empty. |
| 1174 // TODO(timav): keep shm block for that buffer and remove this restriction. | 1180 // TODO(timav): keep shm block for that buffer and remove this restriction. |
| 1175 DCHECK(pending_bitstream_buffers_.empty()); | 1181 DCHECK(pending_bitstream_buffers_.empty()); |
| 1176 pending_input_buf_index_ = -1; | 1182 pending_input_buf_index_ = -1; |
| 1177 } | 1183 } |
| 1178 | 1184 |
| 1179 const bool did_codec_error_happen = state_ == ERROR; | 1185 const bool did_codec_error_happen = state_ == ERROR; |
| 1180 state_ = NO_ERROR; | 1186 state_ = NO_ERROR; |
| 1181 | 1187 |
| 1188 // Don't reset the codec here if there's no error and we're only flushing; | |
| 1189 // instead defer until the next decode call; this prevents us from unbacking | |
| 1190 // frames that might be out for display at end of stream. | |
| 1191 codec_needs_reset_ = false; | |
| 1192 if (drain_type_ == DRAIN_FOR_FLUSH && !did_codec_error_happen) { | |
|
watk
2016/05/24 19:47:26
Can we do this even if there's no drain going on?
DaleCurtis
2016/05/24 23:53:14
We probably can, but doing so exposed a few issues
| |
| 1193 codec_needs_reset_ = true; | |
| 1194 if (!done_cb.is_null()) | |
| 1195 done_cb.Run(); | |
| 1196 return; | |
| 1197 } | |
| 1198 | |
| 1182 // We might increment error_sequence_token here to cancel any delayed errors, | 1199 // We might increment error_sequence_token here to cancel any delayed errors, |
| 1183 // but right now it's unclear that it's safe to do so. If we are in an error | 1200 // but right now it's unclear that it's safe to do so. If we are in an error |
| 1184 // state because of a codec error, then it would be okay. Otherwise, it's | 1201 // state because of a codec error, then it would be okay. Otherwise, it's |
| 1185 // less obvious that we are exiting the error state. Since deferred errors | 1202 // less obvious that we are exiting the error state. Since deferred errors |
| 1186 // are only intended for fullscreen transitions right now, we take the more | 1203 // are only intended for fullscreen transitions right now, we take the more |
| 1187 // conservative approach and let the errors post. | 1204 // conservative approach and let the errors post. |
| 1188 // TODO(liberato): revisit this once we sort out the error state a bit more. | 1205 // TODO(liberato): revisit this once we sort out the error state a bit more. |
| 1189 | 1206 |
| 1190 // When codec is not in error state we can quickly reset (internally calls | 1207 // When codec is not in error state we can quickly reset (internally calls |
| 1191 // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs | 1208 // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1594 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) { | 1611 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) { |
| 1595 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: | 1612 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: |
| 1596 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; | 1613 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; |
| 1597 } | 1614 } |
| 1598 } | 1615 } |
| 1599 | 1616 |
| 1600 return capabilities; | 1617 return capabilities; |
| 1601 } | 1618 } |
| 1602 | 1619 |
| 1603 } // namespace media | 1620 } // namespace media |
| OLD | NEW |