Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1470)

Side by Side Diff: media/gpu/android_video_decode_accelerator.cc

Issue 2011653002: Close bitstream buffer shared memory handles on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/gpu/android_video_decode_accelerator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 1210
1211 if (!done_cb.is_null()) 1211 if (!done_cb.is_null())
1212 done_cb.Run(); 1212 done_cb.Run();
1213 } 1213 }
1214 1214
1215 void AndroidVideoDecodeAccelerator::Reset() { 1215 void AndroidVideoDecodeAccelerator::Reset() {
1216 DVLOG(1) << __FUNCTION__; 1216 DVLOG(1) << __FUNCTION__;
1217 DCHECK(thread_checker_.CalledOnValidThread()); 1217 DCHECK(thread_checker_.CalledOnValidThread());
1218 TRACE_EVENT0("media", "AVDA::Reset"); 1218 TRACE_EVENT0("media", "AVDA::Reset");
1219 1219
1220 while (!pending_bitstream_buffers_.empty()) { 1220 ClearPendingBitstreamBuffers(NOTIFY_CLIENT);
1221 int32_t bitstream_buffer_id = pending_bitstream_buffers_.front().id();
1222 pending_bitstream_buffers_.pop();
1223
1224 if (bitstream_buffer_id != -1) {
1225 base::MessageLoop::current()->PostTask(
1226 FROM_HERE,
1227 base::Bind(&AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer,
1228 weak_this_factory_.GetWeakPtr(), bitstream_buffer_id));
1229 }
1230 }
1231 TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", 0);
1232 bitstreams_notified_in_advance_.clear();
1233 1221
1234 // Any error that is waiting to post can be ignored. 1222 // Any error that is waiting to post can be ignored.
1235 error_sequence_token_++; 1223 error_sequence_token_++;
1236 1224
1237 DCHECK(strategy_); 1225 DCHECK(strategy_);
1238 strategy_->ReleaseCodecBuffers(output_picture_buffers_); 1226 strategy_->ReleaseCodecBuffers(output_picture_buffers_);
1239 1227
1240 // Some VP8 files require complete MediaCodec drain before we can call 1228 // Some VP8 files require complete MediaCodec drain before we can call
1241 // MediaCodec.flush() or MediaCodec.reset(). http://crbug.com/598963. 1229 // MediaCodec.flush() or MediaCodec.reset(). http://crbug.com/598963.
1242 if (media_codec_ && codec_config_->codec_ == media::kCodecVP8) { 1230 if (media_codec_ && codec_config_->codec_ == media::kCodecVP8) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 1276
1289 if (!on_destroying_surface_cb_.is_null()) { 1277 if (!on_destroying_surface_cb_.is_null()) {
1290 AVDASurfaceTracker::GetInstance()->UnregisterOnDestroyingSurfaceCallback( 1278 AVDASurfaceTracker::GetInstance()->UnregisterOnDestroyingSurfaceCallback(
1291 on_destroying_surface_cb_); 1279 on_destroying_surface_cb_);
1292 } 1280 }
1293 1281
1294 // We no longer care about |surface_id|, in case we did before. It's okay 1282 // We no longer care about |surface_id|, in case we did before. It's okay
1295 // if we have no surface and/or weren't the owner or a waiter. 1283 // if we have no surface and/or weren't the owner or a waiter.
1296 g_avda_timer.Pointer()->DeallocateSurface(config_.surface_id, this); 1284 g_avda_timer.Pointer()->DeallocateSurface(config_.surface_id, this);
1297 1285
1286 // Clear any bitstream buffers to prevent leaked file descriptors for the
1287 // shared memory, if any.
1288 ClearPendingBitstreamBuffers(DONT_NOTIFY_CLIENT);
1289
1298 // Note that async codec construction might still be in progress. In that 1290 // Note that async codec construction might still be in progress. In that
1299 // case, the codec will be deleted when it completes once we invalidate all 1291 // case, the codec will be deleted when it completes once we invalidate all
1300 // our weak refs. 1292 // our weak refs.
1301 weak_this_factory_.InvalidateWeakPtrs(); 1293 weak_this_factory_.InvalidateWeakPtrs();
1302 if (media_codec_) { 1294 if (media_codec_) {
1303 g_avda_timer.Pointer()->StopTimer(this); 1295 g_avda_timer.Pointer()->StopTimer(this);
1304 media_codec_.reset(); 1296 media_codec_.reset();
1305 } 1297 }
1306 delete this; 1298 delete this;
1307 } 1299 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 } else { 1504 } else {
1513 most_recent_work_ = now; 1505 most_recent_work_ = now;
1514 } 1506 }
1515 1507
1516 if (should_be_running) 1508 if (should_be_running)
1517 g_avda_timer.Pointer()->StartTimer(this); 1509 g_avda_timer.Pointer()->StartTimer(this);
1518 else 1510 else
1519 g_avda_timer.Pointer()->StopTimer(this); 1511 g_avda_timer.Pointer()->StopTimer(this);
1520 } 1512 }
1521 1513
1514 void AndroidVideoDecodeAccelerator::ClearPendingBitstreamBuffers(
1515 BitstreamBufferNotificationType notify) {
1516 while (!pending_bitstream_buffers_.empty()) {
1517 media::BitstreamBuffer bitstream_buffer =
1518 pending_bitstream_buffers_.front();
1519 int32_t bitstream_buffer_id = bitstream_buffer.id();
1520 pending_bitstream_buffers_.pop();
1521
1522 if (bitstream_buffer_id != -1) {
1523 std::unique_ptr<SharedMemoryRegion> shm(
1524 new SharedMemoryRegion(bitstream_buffer, true));
watk 2016/05/24 22:16:07 We were thinking it might be safer to wrap the han
liberato (no reviews please) 2016/05/24 23:19:25 SMR is non-copyable, so i hadn't considered it. b
1525
1526 if (notify == NOTIFY_CLIENT) {
1527 base::MessageLoop::current()->PostTask(
1528 FROM_HERE,
1529 base::Bind(
1530 &AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer,
1531 weak_this_factory_.GetWeakPtr(), bitstream_buffer_id));
1532 }
1533 }
1534 }
1535 TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", 0);
1536 bitstreams_notified_in_advance_.clear();
1537 }
1538
1522 // static 1539 // static
1523 bool AndroidVideoDecodeAccelerator::UseDeferredRenderingStrategy( 1540 bool AndroidVideoDecodeAccelerator::UseDeferredRenderingStrategy(
1524 const gpu::GpuPreferences& gpu_preferences) { 1541 const gpu::GpuPreferences& gpu_preferences) {
1525 // TODO(liberato, watk): Figure out what we want to do about zero copy for 1542 // TODO(liberato, watk): Figure out what we want to do about zero copy for
1526 // fullscreen external SurfaceView in WebView. http://crbug.com/582170. 1543 // fullscreen external SurfaceView in WebView. http://crbug.com/582170.
1527 return !gpu_preferences.enable_threaded_texture_mailboxes; 1544 return !gpu_preferences.enable_threaded_texture_mailboxes;
1528 } 1545 }
1529 1546
1530 // static 1547 // static
1531 media::VideoDecodeAccelerator::Capabilities 1548 media::VideoDecodeAccelerator::Capabilities
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « media/gpu/android_video_decode_accelerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698