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

Side by Side Diff: content/browser/media/android/browser_media_player_manager.cc

Issue 2420083004: Delete SurfaceTexturePeer (Closed)
Patch Set: Fix missed references Created 3 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/media/android/browser_media_player_manager.h" 5 #include "content/browser/media/android/browser_media_player_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "content/browser/frame_host/render_frame_host_impl.h" 11 #include "content/browser/frame_host/render_frame_host_impl.h"
12 #include "content/browser/media/android/media_resource_getter_impl.h" 12 #include "content/browser/media/android/media_resource_getter_impl.h"
13 #include "content/browser/media/android/media_throttler.h" 13 #include "content/browser/media/android/media_throttler.h"
14 #include "content/browser/media/android/media_web_contents_observer_android.h" 14 #include "content/browser/media/android/media_web_contents_observer_android.h"
15 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/browser/web_contents/web_contents_impl.h" 16 #include "content/browser/web_contents/web_contents_impl.h"
17 #include "content/common/media/media_player_messages_android.h" 17 #include "content/common/media/media_player_messages_android.h"
18 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/content_browser_client.h" 20 #include "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
22 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/storage_partition.h" 24 #include "content/public/browser/storage_partition.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_delegate.h" 26 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/common/content_client.h" 27 #include "content/public/common/content_client.h"
28 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
29 #include "gpu/ipc/common/android/surface_texture_peer.h"
30 #include "media/base/android/media_player_bridge.h" 29 #include "media/base/android/media_player_bridge.h"
31 #include "media/base/android/media_url_interceptor.h" 30 #include "media/base/android/media_url_interceptor.h"
32 #include "media/base/media_content_type.h" 31 #include "media/base/media_content_type.h"
33 32
34 #if !defined(USE_AURA) 33 #if !defined(USE_AURA)
35 #include "content/browser/android/content_view_core_impl.h" 34 #include "content/browser/android/content_view_core_impl.h"
36 #include "content/browser/renderer_host/render_widget_host_view_android.h" 35 #include "content/browser/renderer_host/render_widget_host_view_android.h"
37 #endif 36 #endif
38 37
39 using media::MediaPlayerAndroid; 38 using media::MediaPlayerAndroid;
40 using media::MediaPlayerBridge; 39 using media::MediaPlayerBridge;
41 using media::MediaPlayerManager; 40 using media::MediaPlayerManager;
42 41
43 namespace content { 42 namespace content {
44 43
45 namespace {
46
47 class BrowserSurfaceTexturePeer : public gpu::SurfaceTexturePeer {
48 public:
49 static BrowserSurfaceTexturePeer* GetInstance();
50
51 private:
52 friend struct base::DefaultSingletonTraits<BrowserSurfaceTexturePeer>;
53
54 BrowserSurfaceTexturePeer();
55 ~BrowserSurfaceTexturePeer() override;
56
57 void EstablishSurfaceTexturePeer(
58 base::ProcessHandle render_process_handle,
59 scoped_refptr<gl::SurfaceTexture> surface_texture,
60 int render_frame_id,
61 int player_id) override;
62
63 DISALLOW_COPY_AND_ASSIGN(BrowserSurfaceTexturePeer);
64 };
65
66 // static
67 BrowserSurfaceTexturePeer* BrowserSurfaceTexturePeer::GetInstance() {
68 return base::Singleton<
69 BrowserSurfaceTexturePeer,
70 base::LeakySingletonTraits<BrowserSurfaceTexturePeer>>::get();
71 }
72
73 BrowserSurfaceTexturePeer::BrowserSurfaceTexturePeer() {
74 gpu::SurfaceTexturePeer::InitInstance(this);
75 }
76
77 BrowserSurfaceTexturePeer::~BrowserSurfaceTexturePeer() {
78 gpu::SurfaceTexturePeer::InitInstance(nullptr);
79 }
80
81 void BrowserSurfaceTexturePeer::EstablishSurfaceTexturePeer(
82 base::ProcessHandle render_process_handle,
83 scoped_refptr<gl::SurfaceTexture> surface_texture,
84 int render_frame_id,
85 int player_id) {
86 if (!surface_texture.get())
87 return;
88 BrowserThread::PostTask(
89 BrowserThread::UI, FROM_HERE,
90 base::Bind(&BrowserMediaPlayerManager::SetSurfacePeer, surface_texture,
91 render_process_handle, render_frame_id, player_id));
92 }
93
94 } // namespace
95
96 // Threshold on the number of media players per renderer before we start 44 // Threshold on the number of media players per renderer before we start
97 // attempting to release inactive media players. 45 // attempting to release inactive media players.
98 const int kMediaPlayerThreshold = 1; 46 const int kMediaPlayerThreshold = 1;
99 const int kInvalidMediaPlayerId = -1; 47 const int kInvalidMediaPlayerId = -1;
100 48
101 static BrowserMediaPlayerManager::Factory g_factory = NULL; 49 static BrowserMediaPlayerManager::Factory g_factory = NULL;
102 static media::MediaUrlInterceptor* media_url_interceptor_ = NULL; 50 static media::MediaUrlInterceptor* media_url_interceptor_ = NULL;
103 51
104 // static 52 // static
105 void BrowserMediaPlayerManager::RegisterFactory(Factory factory) { 53 void BrowserMediaPlayerManager::RegisterFactory(Factory factory) {
106 // TODO(aberent) nullptr test is a temporary fix to simplify upstreaming Cast. 54 // TODO(aberent) nullptr test is a temporary fix to simplify upstreaming Cast.
107 // Until Cast is fully upstreamed we want the downstream factory to take 55 // Until Cast is fully upstreamed we want the downstream factory to take
108 // priority over the upstream factory. The downstream call happens first, 56 // priority over the upstream factory. The downstream call happens first,
109 // so this will ensure that it does. 57 // so this will ensure that it does.
110 if (g_factory == nullptr) 58 if (g_factory == nullptr)
111 g_factory = factory; 59 g_factory = factory;
112 } 60 }
113 61
114 // static 62 // static
115 void BrowserMediaPlayerManager::RegisterMediaUrlInterceptor( 63 void BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
116 media::MediaUrlInterceptor* media_url_interceptor) { 64 media::MediaUrlInterceptor* media_url_interceptor) {
117 media_url_interceptor_ = media_url_interceptor; 65 media_url_interceptor_ = media_url_interceptor;
118 } 66 }
119 67
120 // static 68 // static
121 void BrowserMediaPlayerManager::InitSurfaceTexturePeer() {
122 BrowserSurfaceTexturePeer::GetInstance();
123 }
124
125 // static
126 void BrowserMediaPlayerManager::SetSurfacePeer(
127 scoped_refptr<gl::SurfaceTexture> surface_texture,
128 base::ProcessHandle render_process_handle,
129 int render_frame_id,
130 int player_id) {
131 DCHECK_CURRENTLY_ON(BrowserThread::UI);
132 int render_process_id = 0;
133 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
134 while (!it.IsAtEnd()) {
135 if (it.GetCurrentValue()->GetHandle() == render_process_handle) {
136 render_process_id = it.GetCurrentValue()->GetID();
137 break;
138 }
139 it.Advance();
140 }
141 if (!render_process_id) {
142 DVLOG(1) << "Cannot find render process for render_process_handle "
143 << render_process_handle;
144 return;
145 }
146
147 RenderFrameHostImpl* frame =
148 RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
149 if (!frame) {
150 DVLOG(1) << "Cannot find frame for render_frame_id " << render_frame_id;
151 return;
152 }
153
154 BrowserMediaPlayerManager* player_manager =
155 MediaWebContentsObserverAndroid::FromWebContents(
156 WebContents::FromRenderFrameHost(frame))
157 ->GetMediaPlayerManager(frame);
158 if (!player_manager) {
159 DVLOG(1) << "Cannot find the media player manager for frame " << frame;
160 return;
161 }
162
163 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id);
164 if (!player) {
165 DVLOG(1) << "Cannot find media player for player_id " << player_id;
166 return;
167 }
168
169 if (player != player_manager->GetFullscreenPlayer()) {
170 gl::ScopedJavaSurface scoped_surface(surface_texture.get());
171 player->SetVideoSurface(std::move(scoped_surface));
172 }
173 }
174
175 // static
176 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( 69 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create(
177 RenderFrameHost* rfh) { 70 RenderFrameHost* rfh) {
178 if (g_factory) 71 if (g_factory)
179 return g_factory(rfh); 72 return g_factory(rfh);
180 return new BrowserMediaPlayerManager(rfh); 73 return new BrowserMediaPlayerManager(rfh);
181 } 74 }
182 75
183 #if !defined(USE_AURA) 76 #if !defined(USE_AURA)
184 ContentViewCore* BrowserMediaPlayerManager::GetContentViewCore() const { 77 ContentViewCore* BrowserMediaPlayerManager::GetContentViewCore() const {
185 return ContentViewCoreImpl::FromWebContents(web_contents()); 78 return ContentViewCoreImpl::FromWebContents(web_contents());
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 if (!player) 559 if (!player)
667 return; 560 return;
668 player->Start(); 561 player->Start();
669 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) { 562 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) {
670 video_view_->OpenVideo(); 563 video_view_->OpenVideo();
671 fullscreen_player_is_released_ = false; 564 fullscreen_player_is_released_ = false;
672 } 565 }
673 } 566 }
674 567
675 } // namespace content 568 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698