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

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

Issue 2136103010: Add StreamTextureWrapper/StreamTextureWrapperImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/media/android/surface_texture_frame_provider_impl.h"
6
7 #include "base/callback.h"
8 #include "cc/layers/video_frame_provider.h"
9 #include "gpu/GLES2/gl2extchromium.h"
10 #include "gpu/command_buffer/client/gles2_interface.h"
11 #include "media/base/bind_to_current_loop.h"
12
13 using gpu::gles2::GLES2Interface;
14
15 static const uint32_t kGLTextureExternalOES = 0x8D65;
16
17 namespace {
18 // File-static function is to allow it to run even after this class is deleted.
19 void OnReleaseTexture(
liberato (no reviews please) 2016/07/13 16:42:50 static void
tguilbert 2016/07/14 02:47:02 Done.
20 const scoped_refptr<content::StreamTextureFactory>& factories,
21 uint32_t texture_id,
22 const gpu::SyncToken& sync_token) {
23 GLES2Interface* gl = factories->ContextGL();
24 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
25 gl->DeleteTextures(1, &texture_id);
26 // Flush to ensure that the stream texture gets deleted in a timely fashion.
27 gl->ShallowFlushCHROMIUM();
28 }
29 }
30
31 namespace content {
32
33 SurfaceTextureFrameProviderImpl::SurfaceTextureFrameProviderImpl(
34 scoped_refptr<StreamTextureFactory> factory)
35 : texture_id_(0), stream_id_(0), client_(nullptr), factory_(factory) {}
36
37 SurfaceTextureFrameProviderImpl::~SurfaceTextureFrameProviderImpl() {
38 if (stream_id_) {
39 GLES2Interface* gl = factory_->ContextGL();
liberato (no reviews please) 2016/07/13 16:42:50 can call OnReleaseTexture() to avoid duplication.
tguilbert 2016/07/14 02:47:02 In order to call OnReleaseTexture(), I need a sync
liberato (no reviews please) 2016/07/14 16:41:30 i think that SyncToken() creates a token that retu
40 gl->DeleteTextures(1, &texture_id_);
41 // Flush to ensure that the stream texture gets deleted in a timely fashion.
42 gl->ShallowFlushCHROMIUM();
43 texture_id_ = 0;
44 texture_mailbox_ = gpu::Mailbox();
45 stream_id_ = 0;
46 }
47
48 {
liberato (no reviews please) 2016/07/13 16:42:50 nit: don't need {} here. actually, can just SetCu
tguilbert 2016/07/14 02:47:02 Done.
49 base::AutoLock auto_lock(current_frame_lock_);
50 current_frame_ = NULL;
51 }
52 }
53
54 void SurfaceTextureFrameProviderImpl::SetVideoFrameProviderClient(
55 cc::VideoFrameProvider::Client* client) {
56 DVLOG(3) << __FUNCTION__;
57
58 // Set the callback target when a frame is produced. Need to do this before
59 // StopUsingProvider to ensure we really stop using the client.
60 if (stream_texture_proxy_) {
61 stream_texture_proxy_->BindToLoop(stream_id_, client,
62 compositor_task_runner_);
63 }
64
65 if (client_ && client_ != client)
66 client_->StopUsingProvider();
67
68 client_ = client;
69 }
70
71 bool SurfaceTextureFrameProviderImpl::UpdateCurrentFrame(
72 base::TimeTicks deadline_min,
73 base::TimeTicks deadline_max) {
74 NOTIMPLEMENTED();
75 return false;
76 }
77
78 bool SurfaceTextureFrameProviderImpl::HasCurrentFrame() {
79 base::AutoLock auto_lock(current_frame_lock_);
80 return static_cast<bool>(current_frame_);
81 }
82
83 scoped_refptr<media::VideoFrame>
84 SurfaceTextureFrameProviderImpl::GetCurrentFrame() {
85 scoped_refptr<media::VideoFrame> frame;
86 {
liberato (no reviews please) 2016/07/13 16:42:50 nit: don't need {}
tguilbert 2016/07/14 02:47:02 Done.
87 base::AutoLock auto_lock(current_frame_lock_);
88 frame = current_frame_;
89 }
90
91 return frame;
92 }
93
94 void SurfaceTextureFrameProviderImpl::PutCurrentFrame() {}
95
96 void SurfaceTextureFrameProviderImpl::ReallocateVideoFrame(
97 const gfx::Size& natural_size) {
98 GLES2Interface* gl = factory_->ContextGL();
99 GLuint texture_target = kGLTextureExternalOES;
100 GLuint texture_id_ref = gl->CreateAndConsumeTextureCHROMIUM(
101 texture_target, texture_mailbox_.name);
102 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM();
103 gl->Flush();
104
105 gpu::SyncToken texture_mailbox_sync_token;
106 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync,
107 texture_mailbox_sync_token.GetData());
108 if (texture_mailbox_sync_token.namespace_id() ==
109 gpu::CommandBufferNamespace::IN_PROCESS) {
110 // TODO(boliu): Remove this once Android WebView switches to IPC-based
111 // command buffer for video.
112 GLbyte* sync_tokens[] = {texture_mailbox_sync_token.GetData()};
113 gl->VerifySyncTokensCHROMIUM(sync_tokens, arraysize(sync_tokens));
114 }
115
116 gpu::MailboxHolder holders[media::VideoFrame::kMaxPlanes] = {
117 gpu::MailboxHolder(texture_mailbox_, texture_mailbox_sync_token,
118 texture_target)};
119
120 scoped_refptr<media::VideoFrame> new_frame =
121 media::VideoFrame::WrapNativeTextures(
122 media::PIXEL_FORMAT_ARGB, holders,
123 media::BindToCurrentLoop(
124 base::Bind(&OnReleaseTexture, factory_, texture_id_ref)),
125 natural_size, gfx::Rect(natural_size), natural_size,
126 base::TimeDelta());
127
128 // TODO(tguilbert): For reviewers -- what was the purpose of
129 // |enable_texture_copy_| in WMPA? Should it be added here? WPMA had the
liberato (no reviews please) 2016/07/13 16:42:50 it's needed for webview. COPY_REQUIRED tells the
tguilbert 2016/07/14 02:47:02 Ok! Thanks for the background. Opened 628066.
130 // following code:
131 //
132 // if (new_frame.get()) {
133 // new_frame->metadata()->SetBoolean(
134 // media::VideoFrameMetadata::COPY_REQUIRED, enable_texture_copy_);
135 // }
136
137 SetCurrentFrameInternal(new_frame);
138 }
139
140 void SurfaceTextureFrameProviderImpl::SetCurrentFrameInternal(
141 scoped_refptr<media::VideoFrame>& video_frame) {
142 base::AutoLock auto_lock(current_frame_lock_);
143 current_frame_ = video_frame;
144 }
145
146 void SurfaceTextureFrameProviderImpl::UpdateTextureSize(
147 const gfx::Size& new_size) {
148 if (natural_size_ == new_size)
149 return;
150
151 natural_size_ = new_size;
152
153 ReallocateVideoFrame(new_size);
154 factory_->SetStreamTextureSize(stream_id_, new_size);
155 }
156
157 void SurfaceTextureFrameProviderImpl::Initialize(
158 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
159 const gfx::Size& natural_size) {
160 DVLOG(2) << __FUNCTION__;
161
162 compositor_task_runner_ = task_runner;
163 natural_size_ = natural_size;
164
165 stream_texture_proxy_.reset(factory_->CreateProxy());
166
167 stream_id_ = factory_->CreateStreamTexture(kGLTextureExternalOES,
168 &texture_id_, &texture_mailbox_);
169 ReallocateVideoFrame(natural_size_);
170
171 if (client_) {
172 stream_texture_proxy_->BindToLoop(stream_id_, client_,
173 compositor_task_runner_);
174 }
175 }
176
177 int SurfaceTextureFrameProviderImpl::GetSurfaceTextureIdentifier() {
178 // TODO(tguilbert): Return meaningful value and send it to the
179 // MediaPlayerRenderer living in the Browser process.
180 return 0;
181 }
182
183 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698