| 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 get_gles2_decoder_cb_(get_gles2_decoder_cb), | 389 get_gles2_decoder_cb_(get_gles2_decoder_cb), |
| 390 state_(NO_ERROR), | 390 state_(NO_ERROR), |
| 391 picturebuffers_requested_(false), | 391 picturebuffers_requested_(false), |
| 392 drain_type_(DRAIN_TYPE_NONE), | 392 drain_type_(DRAIN_TYPE_NONE), |
| 393 media_drm_bridge_cdm_context_(nullptr), | 393 media_drm_bridge_cdm_context_(nullptr), |
| 394 cdm_registration_id_(0), | 394 cdm_registration_id_(0), |
| 395 pending_input_buf_index_(-1), | 395 pending_input_buf_index_(-1), |
| 396 error_sequence_token_(0), | 396 error_sequence_token_(0), |
| 397 defer_errors_(false), | 397 defer_errors_(false), |
| 398 deferred_initialization_pending_(false), | 398 deferred_initialization_pending_(false), |
| 399 codec_needs_reset_(false), |
| 399 weak_this_factory_(this) {} | 400 weak_this_factory_(this) {} |
| 400 | 401 |
| 401 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { | 402 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { |
| 402 DCHECK(thread_checker_.CalledOnValidThread()); | 403 DCHECK(thread_checker_.CalledOnValidThread()); |
| 403 g_avda_timer.Pointer()->StopTimer(this); | 404 g_avda_timer.Pointer()->StopTimer(this); |
| 404 g_avda_timer.Pointer()->StopThread(this); | 405 g_avda_timer.Pointer()->StopThread(this); |
| 405 | 406 |
| 406 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 407 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 407 if (!media_drm_bridge_cdm_context_) | 408 if (!media_drm_bridge_cdm_context_) |
| 408 return; | 409 return; |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 | 911 |
| 911 // Connect the PictureBuffer to the decoded frame, via whatever mechanism the | 912 // Connect the PictureBuffer to the decoded frame, via whatever mechanism the |
| 912 // strategy likes. | 913 // strategy likes. |
| 913 strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second); | 914 strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second); |
| 914 } | 915 } |
| 915 | 916 |
| 916 void AndroidVideoDecodeAccelerator::Decode( | 917 void AndroidVideoDecodeAccelerator::Decode( |
| 917 const media::BitstreamBuffer& bitstream_buffer) { | 918 const media::BitstreamBuffer& bitstream_buffer) { |
| 918 DCHECK(thread_checker_.CalledOnValidThread()); | 919 DCHECK(thread_checker_.CalledOnValidThread()); |
| 919 | 920 |
| 921 // If we previously deferred a codec restart, take care of it now. This can |
| 922 // happen on older devices where configuration changes require a codec reset. |
| 923 if (codec_needs_reset_) { |
| 924 DCHECK_EQ(drain_type_, DRAIN_TYPE_NONE); |
| 925 ResetCodecState(base::Closure()); |
| 926 } |
| 927 |
| 920 if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) { | 928 if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) { |
| 921 DecodeBuffer(bitstream_buffer); | 929 DecodeBuffer(bitstream_buffer); |
| 922 return; | 930 return; |
| 923 } | 931 } |
| 924 | 932 |
| 925 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) | 933 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) |
| 926 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); | 934 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); |
| 927 | 935 |
| 928 if (bitstream_buffer.id() < 0) { | 936 if (bitstream_buffer.id() < 0) { |
| 929 POST_ERROR(INVALID_ARGUMENT, | 937 POST_ERROR(INVALID_ARGUMENT, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 // shm block been deleted. Check that it is safe to flush the coec, i.e. | 1197 // shm block been deleted. Check that it is safe to flush the coec, i.e. |
| 1190 // |pending_bitstream_records_| is empty. | 1198 // |pending_bitstream_records_| is empty. |
| 1191 // TODO(timav): keep shm block for that buffer and remove this restriction. | 1199 // TODO(timav): keep shm block for that buffer and remove this restriction. |
| 1192 DCHECK(pending_bitstream_records_.empty()); | 1200 DCHECK(pending_bitstream_records_.empty()); |
| 1193 pending_input_buf_index_ = -1; | 1201 pending_input_buf_index_ = -1; |
| 1194 } | 1202 } |
| 1195 | 1203 |
| 1196 const bool did_codec_error_happen = state_ == ERROR; | 1204 const bool did_codec_error_happen = state_ == ERROR; |
| 1197 state_ = NO_ERROR; | 1205 state_ = NO_ERROR; |
| 1198 | 1206 |
| 1207 // Don't reset the codec here if there's no error and we're only flushing; |
| 1208 // instead defer until the next decode call; this prevents us from unbacking |
| 1209 // frames that might be out for display at end of stream. |
| 1210 codec_needs_reset_ = false; |
| 1211 if (drain_type_ == DRAIN_FOR_FLUSH && !did_codec_error_happen) { |
| 1212 codec_needs_reset_ = true; |
| 1213 if (!done_cb.is_null()) |
| 1214 done_cb.Run(); |
| 1215 return; |
| 1216 } |
| 1217 |
| 1199 // We might increment error_sequence_token here to cancel any delayed errors, | 1218 // We might increment error_sequence_token here to cancel any delayed errors, |
| 1200 // but right now it's unclear that it's safe to do so. If we are in an error | 1219 // but right now it's unclear that it's safe to do so. If we are in an error |
| 1201 // state because of a codec error, then it would be okay. Otherwise, it's | 1220 // state because of a codec error, then it would be okay. Otherwise, it's |
| 1202 // less obvious that we are exiting the error state. Since deferred errors | 1221 // less obvious that we are exiting the error state. Since deferred errors |
| 1203 // are only intended for fullscreen transitions right now, we take the more | 1222 // are only intended for fullscreen transitions right now, we take the more |
| 1204 // conservative approach and let the errors post. | 1223 // conservative approach and let the errors post. |
| 1205 // TODO(liberato): revisit this once we sort out the error state a bit more. | 1224 // TODO(liberato): revisit this once we sort out the error state a bit more. |
| 1206 | 1225 |
| 1207 // When codec is not in error state we can quickly reset (internally calls | 1226 // When codec is not in error state we can quickly reset (internally calls |
| 1208 // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs | 1227 // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) { | 1631 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) { |
| 1613 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: | 1632 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: |
| 1614 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; | 1633 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; |
| 1615 } | 1634 } |
| 1616 } | 1635 } |
| 1617 | 1636 |
| 1618 return capabilities; | 1637 return capabilities; |
| 1619 } | 1638 } |
| 1620 | 1639 |
| 1621 } // namespace media | 1640 } // namespace media |
| OLD | NEW |