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

Side by Side Diff: content/renderer/media/android/stream_texture_wrapper_impl.cc

Issue 2390783003: Make stream_id internal to StreamTextureHost. (Closed)
Patch Set: Handle failure conditions of route_id. Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/renderer/media/android/stream_texture_wrapper_impl.h" 5 #include "content/renderer/media/android/stream_texture_wrapper_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "cc/layers/video_frame_provider.h" 8 #include "cc/layers/video_frame_provider.h"
9 #include "gpu/GLES2/gl2extchromium.h" 9 #include "gpu/GLES2/gl2extchromium.h"
10 #include "gpu/command_buffer/client/gles2_interface.h" 10 #include "gpu/command_buffer/client/gles2_interface.h"
(...skipping 15 matching lines...) Expand all
26 gl->ShallowFlushCHROMIUM(); 26 gl->ShallowFlushCHROMIUM();
27 } 27 }
28 } 28 }
29 29
30 namespace content { 30 namespace content {
31 31
32 StreamTextureWrapperImpl::StreamTextureWrapperImpl( 32 StreamTextureWrapperImpl::StreamTextureWrapperImpl(
33 scoped_refptr<StreamTextureFactory> factory, 33 scoped_refptr<StreamTextureFactory> factory,
34 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) 34 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
35 : texture_id_(0), 35 : texture_id_(0),
36 stream_id_(0),
37 factory_(factory), 36 factory_(factory),
38 main_task_runner_(main_task_runner), 37 main_task_runner_(main_task_runner),
39 weak_factory_(this) {} 38 weak_factory_(this) {}
40 39
41 StreamTextureWrapperImpl::~StreamTextureWrapperImpl() { 40 StreamTextureWrapperImpl::~StreamTextureWrapperImpl() {
42 DCHECK(main_task_runner_->BelongsToCurrentThread()); 41 DCHECK(main_task_runner_->BelongsToCurrentThread());
43 42
44 if (stream_id_) { 43 if (texture_id_) {
45 GLES2Interface* gl = factory_->ContextGL(); 44 GLES2Interface* gl = factory_->ContextGL();
46 gl->DeleteTextures(1, &texture_id_); 45 gl->DeleteTextures(1, &texture_id_);
47 // Flush to ensure that the stream texture gets deleted in a timely fashion. 46 // Flush to ensure that the stream texture gets deleted in a timely fashion.
48 gl->ShallowFlushCHROMIUM(); 47 gl->ShallowFlushCHROMIUM();
49 } 48 }
50 49
51 SetCurrentFrameInternal(nullptr); 50 SetCurrentFrameInternal(nullptr);
52 } 51 }
53 52
54 media::ScopedStreamTextureWrapper StreamTextureWrapperImpl::Create( 53 media::ScopedStreamTextureWrapper StreamTextureWrapperImpl::Create(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 base::TimeDelta()); 98 base::TimeDelta());
100 99
101 // TODO(tguilbert): Create and pipe the enable_texture_copy_ flag for Webview 100 // TODO(tguilbert): Create and pipe the enable_texture_copy_ flag for Webview
102 // scenarios. See crbug.com/628066. 101 // scenarios. See crbug.com/628066.
103 102
104 SetCurrentFrameInternal(new_frame); 103 SetCurrentFrameInternal(new_frame);
105 } 104 }
106 105
107 void StreamTextureWrapperImpl::ForwardStreamTextureForSurfaceRequest( 106 void StreamTextureWrapperImpl::ForwardStreamTextureForSurfaceRequest(
108 const base::UnguessableToken& request_token) { 107 const base::UnguessableToken& request_token) {
109 return factory_->ForwardStreamTextureForSurfaceRequest(stream_id_, 108 stream_texture_proxy_->ForwardStreamTextureForSurfaceRequest(request_token);
110 request_token);
111 } 109 }
112 110
113 void StreamTextureWrapperImpl::SetCurrentFrameInternal( 111 void StreamTextureWrapperImpl::SetCurrentFrameInternal(
114 const scoped_refptr<media::VideoFrame>& video_frame) { 112 const scoped_refptr<media::VideoFrame>& video_frame) {
115 base::AutoLock auto_lock(current_frame_lock_); 113 base::AutoLock auto_lock(current_frame_lock_);
116 current_frame_ = video_frame; 114 current_frame_ = video_frame;
117 } 115 }
118 116
119 void StreamTextureWrapperImpl::UpdateTextureSize(const gfx::Size& new_size) { 117 void StreamTextureWrapperImpl::UpdateTextureSize(const gfx::Size& new_size) {
120 DVLOG(2) << __FUNCTION__; 118 DVLOG(2) << __FUNCTION__;
121 119
122 if (!main_task_runner_->BelongsToCurrentThread()) { 120 if (!main_task_runner_->BelongsToCurrentThread()) {
123 main_task_runner_->PostTask( 121 main_task_runner_->PostTask(
124 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::UpdateTextureSize, 122 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::UpdateTextureSize,
125 weak_factory_.GetWeakPtr(), new_size)); 123 weak_factory_.GetWeakPtr(), new_size));
126 return; 124 return;
127 } 125 }
128 126
129 if (natural_size_ == new_size) 127 if (natural_size_ == new_size)
130 return; 128 return;
131 129
132 natural_size_ = new_size; 130 natural_size_ = new_size;
133 131
134 ReallocateVideoFrame(new_size); 132 ReallocateVideoFrame(new_size);
135 factory_->SetStreamTextureSize(stream_id_, new_size); 133 stream_texture_proxy_->SetStreamTextureSize(new_size);
136 } 134 }
137 135
138 void StreamTextureWrapperImpl::Initialize( 136 void StreamTextureWrapperImpl::Initialize(
139 const base::Closure& received_frame_cb, 137 const base::Closure& received_frame_cb,
140 const gfx::Size& natural_size, 138 const gfx::Size& natural_size,
141 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, 139 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
142 const base::Closure& init_cb) { 140 const base::Closure& init_cb) {
143 DVLOG(2) << __FUNCTION__; 141 DVLOG(2) << __FUNCTION__;
144 142
145 compositor_task_runner_ = compositor_task_runner; 143 compositor_task_runner_ = compositor_task_runner;
146 natural_size_ = natural_size; 144 natural_size_ = natural_size;
147 145
148 main_task_runner_->PostTask( 146 main_task_runner_->PostTask(
149 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::InitializeOnMainThread, 147 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::InitializeOnMainThread,
150 weak_factory_.GetWeakPtr(), received_frame_cb, 148 weak_factory_.GetWeakPtr(), received_frame_cb,
151 media::BindToCurrentLoop(init_cb))); 149 media::BindToCurrentLoop(init_cb)));
152 } 150 }
153 151
154 void StreamTextureWrapperImpl::InitializeOnMainThread( 152 void StreamTextureWrapperImpl::InitializeOnMainThread(
155 const base::Closure& received_frame_cb, 153 const base::Closure& received_frame_cb,
156 const base::Closure& init_cb) { 154 const base::Closure& init_cb) {
157 DCHECK(main_task_runner_->BelongsToCurrentThread()); 155 DCHECK(main_task_runner_->BelongsToCurrentThread());
158 DVLOG(2) << __FUNCTION__; 156 DVLOG(2) << __FUNCTION__;
159 157
160 stream_texture_proxy_.reset(factory_->CreateProxy()); 158 stream_texture_proxy_.reset(factory_->CreateProxy(
159 kGLTextureExternalOES, &texture_id_, &texture_mailbox_));
160 if (!stream_texture_proxy_)
161 return;
161 162
162 stream_id_ = factory_->CreateStreamTexture(kGLTextureExternalOES,
163 &texture_id_, &texture_mailbox_);
164 ReallocateVideoFrame(natural_size_); 163 ReallocateVideoFrame(natural_size_);
165 164
166 stream_texture_proxy_->BindToTaskRunner(stream_id_, received_frame_cb, 165 stream_texture_proxy_->BindToTaskRunner(received_frame_cb,
167 compositor_task_runner_); 166 compositor_task_runner_);
168 167
169 // TODO(tguilbert): Register the surface properly. See crbug.com/627658. 168 // TODO(tguilbert): Register the surface properly. See crbug.com/627658.
170 169
171 // |init_cb| is bound to the thread that originally called Initialize(). 170 // |init_cb| is bound to the thread that originally called Initialize().
172 init_cb.Run(); 171 init_cb.Run();
173 } 172 }
174 173
175 void StreamTextureWrapperImpl::Destroy() { 174 void StreamTextureWrapperImpl::Destroy() {
176 // Note: StreamTextureProxy stop calling back the provided frame received 175 // Note: StreamTextureProxy stop calling back the provided frame received
177 // callback immediately, and delete itself on the right thread. 176 // callback immediately, and delete itself on the right thread.
178 stream_texture_proxy_.reset(); 177 stream_texture_proxy_.reset();
179 178
180 if (!main_task_runner_->BelongsToCurrentThread()) { 179 if (!main_task_runner_->BelongsToCurrentThread()) {
181 // base::Unretained is safe here because this function is the only one that 180 // base::Unretained is safe here because this function is the only one that
182 // can can call delete. 181 // can can call delete.
183 main_task_runner_->PostTask( 182 main_task_runner_->PostTask(
184 FROM_HERE, 183 FROM_HERE,
185 base::Bind(&StreamTextureWrapperImpl::Destroy, base::Unretained(this))); 184 base::Bind(&StreamTextureWrapperImpl::Destroy, base::Unretained(this)));
186 return; 185 return;
187 } 186 }
188 187
189 delete this; 188 delete this;
190 } 189 }
191 190
192 } // namespace content 191 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/stream_texture_wrapper_impl.h ('k') | content/renderer/media/android/webmediaplayer_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698