OLD | NEW |
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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 static BrowserSurfaceTexturePeer* GetInstance(); | 55 static BrowserSurfaceTexturePeer* GetInstance(); |
56 | 56 |
57 private: | 57 private: |
58 friend struct base::DefaultSingletonTraits<BrowserSurfaceTexturePeer>; | 58 friend struct base::DefaultSingletonTraits<BrowserSurfaceTexturePeer>; |
59 | 59 |
60 BrowserSurfaceTexturePeer(); | 60 BrowserSurfaceTexturePeer(); |
61 ~BrowserSurfaceTexturePeer() override; | 61 ~BrowserSurfaceTexturePeer() override; |
62 | 62 |
63 void EstablishSurfaceTexturePeer( | 63 void EstablishSurfaceTexturePeer( |
64 base::ProcessHandle render_process_handle, | 64 base::ProcessHandle render_process_handle, |
65 scoped_refptr<gfx::SurfaceTexture> surface_texture, | 65 scoped_refptr<gl::SurfaceTexture> surface_texture, |
66 int render_frame_id, | 66 int render_frame_id, |
67 int player_id) override; | 67 int player_id) override; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(BrowserSurfaceTexturePeer); | 69 DISALLOW_COPY_AND_ASSIGN(BrowserSurfaceTexturePeer); |
70 }; | 70 }; |
71 | 71 |
72 // static | 72 // static |
73 BrowserSurfaceTexturePeer* BrowserSurfaceTexturePeer::GetInstance() { | 73 BrowserSurfaceTexturePeer* BrowserSurfaceTexturePeer::GetInstance() { |
74 return base::Singleton< | 74 return base::Singleton< |
75 BrowserSurfaceTexturePeer, | 75 BrowserSurfaceTexturePeer, |
76 base::LeakySingletonTraits<BrowserSurfaceTexturePeer>>::get(); | 76 base::LeakySingletonTraits<BrowserSurfaceTexturePeer>>::get(); |
77 } | 77 } |
78 | 78 |
79 BrowserSurfaceTexturePeer::BrowserSurfaceTexturePeer() { | 79 BrowserSurfaceTexturePeer::BrowserSurfaceTexturePeer() { |
80 gpu::SurfaceTexturePeer::InitInstance(this); | 80 gpu::SurfaceTexturePeer::InitInstance(this); |
81 } | 81 } |
82 | 82 |
83 BrowserSurfaceTexturePeer::~BrowserSurfaceTexturePeer() { | 83 BrowserSurfaceTexturePeer::~BrowserSurfaceTexturePeer() { |
84 gpu::SurfaceTexturePeer::InitInstance(nullptr); | 84 gpu::SurfaceTexturePeer::InitInstance(nullptr); |
85 } | 85 } |
86 | 86 |
87 void BrowserSurfaceTexturePeer::EstablishSurfaceTexturePeer( | 87 void BrowserSurfaceTexturePeer::EstablishSurfaceTexturePeer( |
88 base::ProcessHandle render_process_handle, | 88 base::ProcessHandle render_process_handle, |
89 scoped_refptr<gfx::SurfaceTexture> surface_texture, | 89 scoped_refptr<gl::SurfaceTexture> surface_texture, |
90 int render_frame_id, | 90 int render_frame_id, |
91 int player_id) { | 91 int player_id) { |
92 if (!surface_texture.get()) | 92 if (!surface_texture.get()) |
93 return; | 93 return; |
94 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
95 BrowserThread::UI, FROM_HERE, | 95 BrowserThread::UI, FROM_HERE, |
96 base::Bind(&BrowserMediaPlayerManager::SetSurfacePeer, surface_texture, | 96 base::Bind(&BrowserMediaPlayerManager::SetSurfacePeer, surface_texture, |
97 render_process_handle, render_frame_id, player_id)); | 97 render_process_handle, render_frame_id, player_id)); |
98 } | 98 } |
99 | 99 |
(...skipping 23 matching lines...) Expand all Loading... |
123 media_url_interceptor_ = media_url_interceptor; | 123 media_url_interceptor_ = media_url_interceptor; |
124 } | 124 } |
125 | 125 |
126 // static | 126 // static |
127 void BrowserMediaPlayerManager::InitSurfaceTexturePeer() { | 127 void BrowserMediaPlayerManager::InitSurfaceTexturePeer() { |
128 BrowserSurfaceTexturePeer::GetInstance(); | 128 BrowserSurfaceTexturePeer::GetInstance(); |
129 } | 129 } |
130 | 130 |
131 // static | 131 // static |
132 void BrowserMediaPlayerManager::SetSurfacePeer( | 132 void BrowserMediaPlayerManager::SetSurfacePeer( |
133 scoped_refptr<gfx::SurfaceTexture> surface_texture, | 133 scoped_refptr<gl::SurfaceTexture> surface_texture, |
134 base::ProcessHandle render_process_handle, | 134 base::ProcessHandle render_process_handle, |
135 int render_frame_id, | 135 int render_frame_id, |
136 int player_id) { | 136 int player_id) { |
137 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
138 int render_process_id = 0; | 138 int render_process_id = 0; |
139 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | 139 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
140 while (!it.IsAtEnd()) { | 140 while (!it.IsAtEnd()) { |
141 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { | 141 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { |
142 render_process_id = it.GetCurrentValue()->GetID(); | 142 render_process_id = it.GetCurrentValue()->GetID(); |
143 break; | 143 break; |
(...skipping 22 matching lines...) Expand all Loading... |
166 return; | 166 return; |
167 } | 167 } |
168 | 168 |
169 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id); | 169 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id); |
170 if (!player) { | 170 if (!player) { |
171 DVLOG(1) << "Cannot find media player for player_id " << player_id; | 171 DVLOG(1) << "Cannot find media player for player_id " << player_id; |
172 return; | 172 return; |
173 } | 173 } |
174 | 174 |
175 if (player != player_manager->GetFullscreenPlayer()) { | 175 if (player != player_manager->GetFullscreenPlayer()) { |
176 gfx::ScopedJavaSurface scoped_surface(surface_texture.get()); | 176 gl::ScopedJavaSurface scoped_surface(surface_texture.get()); |
177 player->SetVideoSurface(std::move(scoped_surface)); | 177 player->SetVideoSurface(std::move(scoped_surface)); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 // static | 181 // static |
182 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( | 182 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( |
183 RenderFrameHost* rfh) { | 183 RenderFrameHost* rfh) { |
184 if (g_factory) | 184 if (g_factory) |
185 return g_factory(rfh); | 185 return g_factory(rfh); |
186 return new BrowserMediaPlayerManager(rfh); | 186 return new BrowserMediaPlayerManager(rfh); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return; | 309 return; |
310 | 310 |
311 #if defined(VIDEO_HOLE) | 311 #if defined(VIDEO_HOLE) |
312 if (external_video_surface_container_) | 312 if (external_video_surface_container_) |
313 external_video_surface_container_->OnFrameInfoUpdated(); | 313 external_video_surface_container_->OnFrameInfoUpdated(); |
314 #endif // defined(VIDEO_HOLE) | 314 #endif // defined(VIDEO_HOLE) |
315 | 315 |
316 if (release_media_player) | 316 if (release_media_player) |
317 ReleaseFullscreenPlayer(player); | 317 ReleaseFullscreenPlayer(player); |
318 else | 318 else |
319 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 319 player->SetVideoSurface(gl::ScopedJavaSurface()); |
320 #endif // defined(USE_AURA) | 320 #endif // defined(USE_AURA) |
321 } | 321 } |
322 | 322 |
323 void BrowserMediaPlayerManager::OnTimeUpdate( | 323 void BrowserMediaPlayerManager::OnTimeUpdate( |
324 int player_id, | 324 int player_id, |
325 base::TimeDelta current_timestamp, | 325 base::TimeDelta current_timestamp, |
326 base::TimeTicks current_time_ticks) { | 326 base::TimeTicks current_time_ticks) { |
327 Send(new MediaPlayerMsg_MediaTimeUpdate( | 327 Send(new MediaPlayerMsg_MediaTimeUpdate( |
328 RoutingID(), player_id, current_timestamp, current_time_ticks)); | 328 RoutingID(), player_id, current_timestamp, current_time_ticks)); |
329 } | 329 } |
330 | 330 |
331 void BrowserMediaPlayerManager::SetVideoSurface( | 331 void BrowserMediaPlayerManager::SetVideoSurface(gl::ScopedJavaSurface surface) { |
332 gfx::ScopedJavaSurface surface) { | |
333 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 332 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
334 if (!player) | 333 if (!player) |
335 return; | 334 return; |
336 | 335 |
337 bool empty_surface = surface.IsEmpty(); | 336 bool empty_surface = surface.IsEmpty(); |
338 player->SetVideoSurface(std::move(surface)); | 337 player->SetVideoSurface(std::move(surface)); |
339 if (empty_surface) | 338 if (empty_surface) |
340 return; | 339 return; |
341 | 340 |
342 // If we already know the size, set it now. Otherwise it will be set when the | 341 // If we already know the size, set it now. Otherwise it will be set when the |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 player_id_to_delegate_id_map_[player_id], has_audio, | 458 player_id_to_delegate_id_map_[player_id], has_audio, |
460 IsPlayingRemotely(player_id), duration); | 459 IsPlayingRemotely(player_id), duration); |
461 } | 460 } |
462 | 461 |
463 #if defined(VIDEO_HOLE) | 462 #if defined(VIDEO_HOLE) |
464 void BrowserMediaPlayerManager::AttachExternalVideoSurface(int player_id, | 463 void BrowserMediaPlayerManager::AttachExternalVideoSurface(int player_id, |
465 jobject surface) { | 464 jobject surface) { |
466 MediaPlayerAndroid* player = GetPlayer(player_id); | 465 MediaPlayerAndroid* player = GetPlayer(player_id); |
467 if (player) { | 466 if (player) { |
468 player->SetVideoSurface( | 467 player->SetVideoSurface( |
469 gfx::ScopedJavaSurface::AcquireExternalSurface(surface)); | 468 gl::ScopedJavaSurface::AcquireExternalSurface(surface)); |
470 } | 469 } |
471 } | 470 } |
472 | 471 |
473 void BrowserMediaPlayerManager::DetachExternalVideoSurface(int player_id) { | 472 void BrowserMediaPlayerManager::DetachExternalVideoSurface(int player_id) { |
474 MediaPlayerAndroid* player = GetPlayer(player_id); | 473 MediaPlayerAndroid* player = GetPlayer(player_id); |
475 if (player) | 474 if (player) |
476 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 475 player->SetVideoSurface(gl::ScopedJavaSurface()); |
477 } | 476 } |
478 | 477 |
479 void BrowserMediaPlayerManager::OnFrameInfoUpdated() { | 478 void BrowserMediaPlayerManager::OnFrameInfoUpdated() { |
480 if (fullscreen_player_id_ != kInvalidMediaPlayerId) | 479 if (fullscreen_player_id_ != kInvalidMediaPlayerId) |
481 return; | 480 return; |
482 | 481 |
483 if (external_video_surface_container_) | 482 if (external_video_surface_container_) |
484 external_video_surface_container_->OnFrameInfoUpdated(); | 483 external_video_surface_container_->OnFrameInfoUpdated(); |
485 } | 484 } |
486 | 485 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 if (!player) | 797 if (!player) |
799 return; | 798 return; |
800 player->Start(); | 799 player->Start(); |
801 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) { | 800 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) { |
802 video_view_->OpenVideo(); | 801 video_view_->OpenVideo(); |
803 fullscreen_player_is_released_ = false; | 802 fullscreen_player_is_released_ = false; |
804 } | 803 } |
805 } | 804 } |
806 | 805 |
807 } // namespace content | 806 } // namespace content |
OLD | NEW |