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 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1178 if (pending_input_buf_index_ != -1) { | 1178 if (pending_input_buf_index_ != -1) { |
| 1179 // The data for that index exists in the input buffer, but corresponding | 1179 // The data for that index exists in the input buffer, but corresponding |
| 1180 // 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. |
| 1181 // |pending_bitstream_buffers_| is empty. | 1181 // |pending_bitstream_buffers_| is empty. |
| 1182 // 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. |
| 1183 DCHECK(pending_bitstream_buffers_.empty()); | 1183 DCHECK(pending_bitstream_buffers_.empty()); |
| 1184 pending_input_buf_index_ = -1; | 1184 pending_input_buf_index_ = -1; |
| 1185 } | 1185 } |
| 1186 | 1186 |
| 1187 const bool did_codec_error_happen = state_ == ERROR; | 1187 const bool did_codec_error_happen = state_ == ERROR; |
| 1188 state_ = NO_ERROR; | 1188 if (!did_codec_error_happen) |
| 1189 state_ = NO_ERROR; | |
| 1189 | 1190 |
| 1190 // Don't reset the codec here if there's no error and we're only flushing; | 1191 // Don't reset the codec here if there's no error and we're only flushing or |
| 1191 // instead defer until the next decode call; this prevents us from unbacking | 1192 // we have to destruct the codec to reset; instead defer until the next decode |
| 1192 // frames that might be out for display at end of stream. | 1193 // call; this prevents us from unbacking frames that might be out for display |
| 1193 codec_needs_reset_ = false; | 1194 // at end of stream or reconstructing a codec which is never used. |
| 1194 if (drain_type_ == DRAIN_FOR_FLUSH && !did_codec_error_happen) { | 1195 const bool codec_requires_destruction = |
| 1196 base::android::BuildInfo::GetInstance()->sdk_int() <= 18; | |
| 1197 if (!codec_needs_reset_ && !did_codec_error_happen && | |
| 1198 (codec_requires_destruction || drain_type_ == DRAIN_FOR_FLUSH)) { | |
| 1195 codec_needs_reset_ = true; | 1199 codec_needs_reset_ = true; |
| 1196 if (!done_cb.is_null()) | 1200 if (!done_cb.is_null()) |
| 1197 done_cb.Run(); | 1201 done_cb.Run(); |
| 1198 return; | 1202 return; |
| 1199 } | 1203 } |
| 1204 codec_needs_reset_ = false; | |
|
liberato (no reviews please)
2016/06/02 22:10:44
the idea here is to make the first call defer, and
| |
| 1200 | 1205 |
| 1201 // We might increment error_sequence_token here to cancel any delayed errors, | 1206 // We might increment error_sequence_token here to cancel any delayed errors, |
| 1202 // but right now it's unclear that it's safe to do so. If we are in an error | 1207 // but right now it's unclear that it's safe to do so. If we are in an error |
| 1203 // state because of a codec error, then it would be okay. Otherwise, it's | 1208 // state because of a codec error, then it would be okay. Otherwise, it's |
| 1204 // less obvious that we are exiting the error state. Since deferred errors | 1209 // less obvious that we are exiting the error state. Since deferred errors |
| 1205 // are only intended for fullscreen transitions right now, we take the more | 1210 // are only intended for fullscreen transitions right now, we take the more |
| 1206 // conservative approach and let the errors post. | 1211 // conservative approach and let the errors post. |
| 1207 // TODO(liberato): revisit this once we sort out the error state a bit more. | 1212 // TODO(liberato): revisit this once we sort out the error state a bit more. |
|
watk
2016/05/26 20:53:28
Could probably delete this whole comment since it'
| |
| 1208 | 1213 |
| 1209 // When codec is not in error state we can quickly reset (internally calls | 1214 // When codec is not in error state we can quickly reset (internally calls |
| 1210 // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs | 1215 // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs |
| 1211 // (b/8125974, b/8347958) so we must delete the MediaCodec and create a new | 1216 // (b/8125974, b/8347958) so we must delete the MediaCodec and create a new |
| 1212 // one. The full reconfigure is much slower and may cause visible freezing if | 1217 // one. The full reconfigure is much slower and may cause visible freezing if |
| 1213 // done mid-stream. | 1218 // done mid-stream. |
|
watk
2016/05/26 20:53:28
Do you think this comment belongs on codec_require
| |
| 1214 if (!did_codec_error_happen && | 1219 if (!codec_requires_destruction && !did_codec_error_happen) { |
| 1215 base::android::BuildInfo::GetInstance()->sdk_int() >= 18) { | |
| 1216 DVLOG(3) << __FUNCTION__ << " Doing fast MediaCodec reset (flush)."; | 1220 DVLOG(3) << __FUNCTION__ << " Doing fast MediaCodec reset (flush)."; |
| 1217 media_codec_->Reset(); | 1221 media_codec_->Reset(); |
| 1218 // Since we just flushed all the output buffers, make sure that nothing is | 1222 // Since we just flushed all the output buffers, make sure that nothing is |
| 1219 // using them. | 1223 // using them. |
| 1220 strategy_->CodecChanged(media_codec_.get()); | 1224 strategy_->CodecChanged(media_codec_.get()); |
| 1221 } else { | 1225 } else { |
| 1222 DVLOG(3) << __FUNCTION__ | 1226 DVLOG(3) << __FUNCTION__ |
| 1223 << " Deleting the MediaCodec and creating a new one."; | 1227 << " Deleting the MediaCodec and creating a new one."; |
| 1224 g_avda_timer.Pointer()->StopTimer(this); | 1228 g_avda_timer.Pointer()->StopTimer(this); |
|
watk
2016/05/26 20:53:28
unrelated, but it's a bit weird that the other bra
liberato (no reviews please)
2016/06/02 22:10:44
i don't think that it should. the next decode wil
| |
| 1225 // Changing the codec will also notify the strategy to forget about any | 1229 |
| 1226 // output buffers it has currently. | 1230 // Only recreate the codec if we're not in the error state. |
| 1227 ConfigureMediaCodecAsynchronously(); | 1231 media_codec_.reset(); |
| 1232 strategy_->CodecChanged(nullptr); | |
| 1233 if (!did_codec_error_happen) | |
| 1234 ConfigureMediaCodecAsynchronously(); | |
| 1228 } | 1235 } |
| 1229 | 1236 |
| 1230 if (!done_cb.is_null()) | 1237 if (!done_cb.is_null()) |
| 1231 done_cb.Run(); | 1238 done_cb.Run(); |
| 1232 } | 1239 } |
| 1233 | 1240 |
| 1234 void AndroidVideoDecodeAccelerator::Reset() { | 1241 void AndroidVideoDecodeAccelerator::Reset() { |
| 1235 DVLOG(1) << __FUNCTION__; | 1242 DVLOG(1) << __FUNCTION__; |
| 1236 DCHECK(thread_checker_.CalledOnValidThread()); | 1243 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1237 TRACE_EVENT0("media", "AVDA::Reset"); | 1244 TRACE_EVENT0("media", "AVDA::Reset"); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1613 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) { | 1620 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) { |
| 1614 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: | 1621 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: |
| 1615 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; | 1622 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; |
| 1616 } | 1623 } |
| 1617 } | 1624 } |
| 1618 | 1625 |
| 1619 return capabilities; | 1626 return capabilities; |
| 1620 } | 1627 } |
| 1621 | 1628 |
| 1622 } // namespace media | 1629 } // namespace media |
| OLD | NEW |