| 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 |
| 905 // happen on older devices where configuration changes require a codec reset. |
| 906 if (codec_needs_reset_) { |
| 907 DCHECK_EQ(drain_type_, DRAIN_TYPE_NONE); |
| 908 ResetCodecState(base::Closure()); |
| 909 } |
| 910 |
| 903 if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) { | 911 if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) { |
| 904 DecodeBuffer(bitstream_buffer); | 912 DecodeBuffer(bitstream_buffer); |
| 905 return; | 913 return; |
| 906 } | 914 } |
| 907 | 915 |
| 908 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) | 916 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) |
| 909 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); | 917 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); |
| 910 | 918 |
| 911 if (bitstream_buffer.id() < 0) { | 919 if (bitstream_buffer.id() < 0) { |
| 912 POST_ERROR(INVALID_ARGUMENT, | 920 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. | 1180 // shm block been deleted. Check that it is safe to flush the coec, i.e. |
| 1173 // |pending_bitstream_buffers_| is empty. | 1181 // |pending_bitstream_buffers_| is empty. |
| 1174 // TODO(timav): keep shm block for that buffer and remove this restriction. | 1182 // TODO(timav): keep shm block for that buffer and remove this restriction. |
| 1175 DCHECK(pending_bitstream_buffers_.empty()); | 1183 DCHECK(pending_bitstream_buffers_.empty()); |
| 1176 pending_input_buf_index_ = -1; | 1184 pending_input_buf_index_ = -1; |
| 1177 } | 1185 } |
| 1178 | 1186 |
| 1179 const bool did_codec_error_happen = state_ == ERROR; | 1187 const bool did_codec_error_happen = state_ == ERROR; |
| 1180 state_ = NO_ERROR; | 1188 state_ = NO_ERROR; |
| 1181 | 1189 |
| 1190 // Don't reset the codec here if there's no error and we're only flushing; |
| 1191 // instead defer until the next decode call; this prevents us from unbacking |
| 1192 // frames that might be out for display at end of stream. |
| 1193 codec_needs_reset_ = false; |
| 1194 if (drain_type_ == DRAIN_FOR_FLUSH && !did_codec_error_happen) { |
| 1195 codec_needs_reset_ = true; |
| 1196 if (!done_cb.is_null()) |
| 1197 done_cb.Run(); |
| 1198 return; |
| 1199 } |
| 1200 |
| 1182 // We might increment error_sequence_token here to cancel any delayed errors, | 1201 // 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 | 1202 // 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 | 1203 // 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 | 1204 // 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 | 1205 // are only intended for fullscreen transitions right now, we take the more |
| 1187 // conservative approach and let the errors post. | 1206 // conservative approach and let the errors post. |
| 1188 // TODO(liberato): revisit this once we sort out the error state a bit more. | 1207 // TODO(liberato): revisit this once we sort out the error state a bit more. |
| 1189 | 1208 |
| 1190 // When codec is not in error state we can quickly reset (internally calls | 1209 // 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 | 1210 // 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()) { | 1613 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) { |
| 1595 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: | 1614 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: |
| 1596 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; | 1615 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; |
| 1597 } | 1616 } |
| 1598 } | 1617 } |
| 1599 | 1618 |
| 1600 return capabilities; | 1619 return capabilities; |
| 1601 } | 1620 } |
| 1602 | 1621 |
| 1603 } // namespace media | 1622 } // namespace media |
| OLD | NEW |