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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/gpu/android_video_decode_accelerator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/gpu/android_video_decode_accelerator.cc
diff --git a/media/gpu/android_video_decode_accelerator.cc b/media/gpu/android_video_decode_accelerator.cc
index 50fe2ebca4ece288bff98a1135b8baa2d94a0966..c1a4cc76922e054b0ddae912a39e12bbe5f167f4 100644
--- a/media/gpu/android_video_decode_accelerator.cc
+++ b/media/gpu/android_video_decode_accelerator.cc
@@ -1217,19 +1217,7 @@ void AndroidVideoDecodeAccelerator::Reset() {
DCHECK(thread_checker_.CalledOnValidThread());
TRACE_EVENT0("media", "AVDA::Reset");
- while (!pending_bitstream_buffers_.empty()) {
- int32_t bitstream_buffer_id = pending_bitstream_buffers_.front().id();
- pending_bitstream_buffers_.pop();
-
- if (bitstream_buffer_id != -1) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer,
- weak_this_factory_.GetWeakPtr(), bitstream_buffer_id));
- }
- }
- TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", 0);
- bitstreams_notified_in_advance_.clear();
+ ClearPendingBitstreamBuffers(NOTIFY_CLIENT);
// Any error that is waiting to post can be ignored.
error_sequence_token_++;
@@ -1295,6 +1283,10 @@ void AndroidVideoDecodeAccelerator::ActualDestroy() {
// if we have no surface and/or weren't the owner or a waiter.
g_avda_timer.Pointer()->DeallocateSurface(config_.surface_id, this);
+ // Clear any bitstream buffers to prevent leaked file descriptors for the
+ // shared memory, if any.
+ ClearPendingBitstreamBuffers(DONT_NOTIFY_CLIENT);
+
// Note that async codec construction might still be in progress. In that
// case, the codec will be deleted when it completes once we invalidate all
// our weak refs.
@@ -1519,6 +1511,31 @@ void AndroidVideoDecodeAccelerator::ManageTimer(bool did_work) {
g_avda_timer.Pointer()->StopTimer(this);
}
+void AndroidVideoDecodeAccelerator::ClearPendingBitstreamBuffers(
+ BitstreamBufferNotificationType notify) {
+ while (!pending_bitstream_buffers_.empty()) {
+ media::BitstreamBuffer bitstream_buffer =
+ pending_bitstream_buffers_.front();
+ int32_t bitstream_buffer_id = bitstream_buffer.id();
+ pending_bitstream_buffers_.pop();
+
+ if (bitstream_buffer_id != -1) {
+ std::unique_ptr<SharedMemoryRegion> shm(
+ 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
+
+ if (notify == NOTIFY_CLIENT) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer,
+ weak_this_factory_.GetWeakPtr(), bitstream_buffer_id));
+ }
+ }
+ }
+ TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", 0);
+ bitstreams_notified_in_advance_.clear();
+}
+
// static
bool AndroidVideoDecodeAccelerator::UseDeferredRenderingStrategy(
const gpu::GpuPreferences& gpu_preferences) {
« 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