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

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

Issue 2889603005: Position overlays in AVDACodecImage (Closed)
Patch Set: rebased Created 3 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 unified diff | Download patch
« no previous file with comments | « media/gpu/avda_shared_state.h ('k') | media/gpu/avda_surface_bundle.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/android/surface_texture.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 // Protects changes to listener_. 55 // Protects changes to listener_.
56 base::Lock lock_; 56 base::Lock lock_;
57 57
58 // The AVDASharedState that wants the OnFrameAvailable callback. 58 // The AVDASharedState that wants the OnFrameAvailable callback.
59 AVDASharedState* listener_; 59 AVDASharedState* listener_;
60 60
61 DISALLOW_COPY_AND_ASSIGN(OnFrameAvailableHandler); 61 DISALLOW_COPY_AND_ASSIGN(OnFrameAvailableHandler);
62 }; 62 };
63 63
64 AVDASharedState::AVDASharedState() 64 AVDASharedState::AVDASharedState(
65 scoped_refptr<AVDASurfaceBundle> surface_bundle)
65 : frame_available_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 66 : frame_available_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
66 base::WaitableEvent::InitialState::NOT_SIGNALED), 67 base::WaitableEvent::InitialState::NOT_SIGNALED),
67 68
68 gl_matrix_{ 69 gl_matrix_{
69 1, 0, 0, 0, // Default to a sane guess just in case we can't get the 70 1, 0, 0, 0, // Default to a sane guess just in case we can't get the
70 0, 1, 0, 0, // matrix on the first call. Will be Y-flipped later. 71 0, 1, 0, 0, // matrix on the first call. Will be Y-flipped later.
71 0, 0, 1, 0, // 72 0, 0, 1, 0, //
72 0, 0, 0, 1, // Comment preserves 4x4 formatting. 73 0, 0, 0, 1, // Comment preserves 4x4 formatting.
73 } {} 74 },
75 surface_bundle_(surface_bundle),
76 weak_this_factory_(this) {
77 // If the surface bundle has a surface texture, then register to receive
78 // OnFrameAvailable notifications.
79 if (surface_texture()) {
80 on_frame_available_handler_ =
81 new OnFrameAvailableHandler(this, surface_texture());
82 }
83
84 // If we're holding a reference to an overlay, then register to drop it if the
85 // overlay's surface is destroyed.
86 if (overlay()) {
87 overlay()->AddSurfaceDestroyedCallback(base::Bind(
88 &AVDASharedState::OnSurfaceDestroyed, weak_this_factory_.GetWeakPtr()));
89 }
90 }
74 91
75 AVDASharedState::~AVDASharedState() { 92 AVDASharedState::~AVDASharedState() {
76 if (!surface_texture_) 93 if (on_frame_available_handler_)
77 return; 94 on_frame_available_handler_->ClearListener();
78
79 on_frame_available_handler_->ClearListener();
80 } 95 }
81 96
82 void AVDASharedState::SignalFrameAvailable() { 97 void AVDASharedState::SignalFrameAvailable() {
83 frame_available_event_.Signal(); 98 frame_available_event_.Signal();
84 } 99 }
85 100
86 void AVDASharedState::WaitForFrameAvailable() { 101 void AVDASharedState::WaitForFrameAvailable() {
87 DCHECK(!release_time_.is_null()); 102 DCHECK(!release_time_.is_null());
88 103
89 // 5msec covers >99.9% of cases, so just wait for up to that much before 104 // 5msec covers >99.9% of cases, so just wait for up to that much before
(...skipping 16 matching lines...) Expand all
106 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame"); 121 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame");
107 if (!frame_available_event_.TimedWait(remaining)) { 122 if (!frame_available_event_.TimedWait(remaining)) {
108 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " 123 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: "
109 << elapsed.InMillisecondsF() 124 << elapsed.InMillisecondsF()
110 << "ms, additionally waited: " << remaining.InMillisecondsF() 125 << "ms, additionally waited: " << remaining.InMillisecondsF()
111 << "ms, total: " << (elapsed + remaining).InMillisecondsF() 126 << "ms, total: " << (elapsed + remaining).InMillisecondsF()
112 << "ms"; 127 << "ms";
113 } 128 }
114 } 129 }
115 130
116 void AVDASharedState::SetSurfaceTexture(
117 scoped_refptr<SurfaceTextureGLOwner> surface_texture) {
118 DCHECK(surface_texture);
119 surface_texture_ = surface_texture;
120 on_frame_available_handler_ =
121 new OnFrameAvailableHandler(this, surface_texture_.get());
122 }
123
124 void AVDASharedState::RenderCodecBufferToSurfaceTexture( 131 void AVDASharedState::RenderCodecBufferToSurfaceTexture(
125 MediaCodecBridge* codec, 132 MediaCodecBridge* codec,
126 int codec_buffer_index) { 133 int codec_buffer_index) {
127 if (!release_time_.is_null()) 134 if (!release_time_.is_null())
128 WaitForFrameAvailable(); 135 WaitForFrameAvailable();
129 codec->ReleaseOutputBuffer(codec_buffer_index, true); 136 codec->ReleaseOutputBuffer(codec_buffer_index, true);
130 release_time_ = base::TimeTicks::Now(); 137 release_time_ = base::TimeTicks::Now();
131 } 138 }
132 139
133 void AVDASharedState::UpdateTexImage() { 140 void AVDASharedState::UpdateTexImage() {
134 surface_texture_->UpdateTexImage(); 141 surface_texture()->UpdateTexImage();
135 // Helpfully, this is already column major. 142 // Helpfully, this is already column major.
136 surface_texture_->GetTransformMatrix(gl_matrix_); 143 surface_texture()->GetTransformMatrix(gl_matrix_);
137 } 144 }
138 145
139 void AVDASharedState::GetTransformMatrix(float matrix[16]) const { 146 void AVDASharedState::GetTransformMatrix(float matrix[16]) const {
140 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); 147 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_));
141 } 148 }
142 149
150 void AVDASharedState::OnSurfaceDestroyed(AndroidOverlay* overlay_raw) {
151 if (surface_bundle_ && overlay() == overlay_raw)
152 surface_bundle_ = nullptr;
153 }
154
143 } // namespace media 155 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/avda_shared_state.h ('k') | media/gpu/avda_surface_bundle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698