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

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

Issue 2005103004: AVDACodecImages keep their backing SurfaceTexture alive (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@neverdetach
Patch Set: Comments and add a DCHECK for glGetError after glDelete 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/avda_shared_state.h ('k') | media/gpu/avda_state_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/avda_shared_state.h" 5 #include "media/gpu/avda_shared_state.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "media/gpu/avda_codec_image.h" 9 #include "media/gpu/avda_codec_image.h"
10 #include "ui/gl/android/surface_texture.h"
10 #include "ui/gl/gl_bindings.h" 11 #include "ui/gl/gl_bindings.h"
11 #include "ui/gl/scoped_make_current.h" 12 #include "ui/gl/scoped_make_current.h"
12 13
13 namespace media { 14 namespace media {
14 15
15 AVDASharedState::AVDASharedState() 16 AVDASharedState::AVDASharedState()
16 : surface_texture_service_id_(0), 17 : surface_texture_service_id_(0), frame_available_event_(false, false) {}
17 frame_available_event_(false, false),
18 surface_texture_is_attached_(false) {}
19 18
20 AVDASharedState::~AVDASharedState() {} 19 AVDASharedState::~AVDASharedState() {
20 if (!surface_texture_service_id_)
21 return;
22
23 ui::ScopedMakeCurrent scoped_make_current(context_.get(), surface_.get());
24 if (scoped_make_current.Succeeded()) {
25 glDeleteTextures(1, &surface_texture_service_id_);
26 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
27 }
28 }
21 29
22 void AVDASharedState::SignalFrameAvailable() { 30 void AVDASharedState::SignalFrameAvailable() {
23 frame_available_event_.Signal(); 31 frame_available_event_.Signal();
24 } 32 }
25 33
26 void AVDASharedState::WaitForFrameAvailable() { 34 void AVDASharedState::WaitForFrameAvailable() {
27 DCHECK(!release_time_.is_null()); 35 DCHECK(!release_time_.is_null());
28 36
29 // 5msec covers >99.9% of cases, so just wait for up to that much before 37 // 5msec covers >99.9% of cases, so just wait for up to that much before
30 // giving up. If an error occurs, we might not ever get a notification. 38 // giving up. If an error occurs, we might not ever get a notification.
(...skipping 15 matching lines...) Expand all
46 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame"); 54 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame");
47 if (!frame_available_event_.TimedWait(remaining)) { 55 if (!frame_available_event_.TimedWait(remaining)) {
48 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " 56 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: "
49 << elapsed.InMillisecondsF() 57 << elapsed.InMillisecondsF()
50 << "ms, additionally waited: " << remaining.InMillisecondsF() 58 << "ms, additionally waited: " << remaining.InMillisecondsF()
51 << "ms, total: " << (elapsed + remaining).InMillisecondsF() 59 << "ms, total: " << (elapsed + remaining).InMillisecondsF()
52 << "ms"; 60 << "ms";
53 } 61 }
54 } 62 }
55 63
56 void AVDASharedState::DidAttachSurfaceTexture() { 64 void AVDASharedState::SetSurfaceTexture(
65 scoped_refptr<gl::SurfaceTexture> surface_texture,
66 GLuint attached_service_id) {
67 surface_texture_ = surface_texture;
68 surface_texture_service_id_ = attached_service_id;
57 context_ = gl::GLContext::GetCurrent(); 69 context_ = gl::GLContext::GetCurrent();
58 surface_ = gl::GLSurface::GetCurrent(); 70 surface_ = gl::GLSurface::GetCurrent();
59 DCHECK(context_); 71 DCHECK(context_);
60 DCHECK(surface_); 72 DCHECK(surface_);
61
62 surface_texture_is_attached_ = true;
63 } 73 }
64 74
65 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) { 75 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) {
66 for (auto& image_kv : codec_images_) 76 for (auto& image_kv : codec_images_)
67 image_kv.second->CodecChanged(codec); 77 image_kv.second->CodecChanged(codec);
68 release_time_ = base::TimeTicks(); 78 release_time_ = base::TimeTicks();
69 } 79 }
70 80
71 void AVDASharedState::SetImageForPicture(int picture_buffer_id, 81 void AVDASharedState::SetImageForPicture(int picture_buffer_id,
72 AVDACodecImage* image) { 82 AVDACodecImage* image) {
(...skipping 16 matching lines...) Expand all
89 void AVDASharedState::RenderCodecBufferToSurfaceTexture( 99 void AVDASharedState::RenderCodecBufferToSurfaceTexture(
90 media::MediaCodecBridge* codec, 100 media::MediaCodecBridge* codec,
91 int codec_buffer_index) { 101 int codec_buffer_index) {
92 if (!release_time_.is_null()) 102 if (!release_time_.is_null())
93 WaitForFrameAvailable(); 103 WaitForFrameAvailable();
94 codec->ReleaseOutputBuffer(codec_buffer_index, true); 104 codec->ReleaseOutputBuffer(codec_buffer_index, true);
95 release_time_ = base::TimeTicks::Now(); 105 release_time_ = base::TimeTicks::Now();
96 } 106 }
97 107
98 } // namespace media 108 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/avda_shared_state.h ('k') | media/gpu/avda_state_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698