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 "content/browser/frame_host/render_frame_host_impl.h" | 11 #include "content/browser/frame_host/render_frame_host_impl.h" |
11 #include "content/browser/media/android/browser_demuxer_android.h" | 12 #include "content/browser/media/android/browser_demuxer_android.h" |
12 #include "content/browser/media/android/media_resource_getter_impl.h" | 13 #include "content/browser/media/android/media_resource_getter_impl.h" |
13 #include "content/browser/media/android/media_throttler.h" | 14 #include "content/browser/media/android/media_throttler.h" |
14 #include "content/browser/media/android/media_web_contents_observer_android.h" | 15 #include "content/browser/media/android/media_web_contents_observer_android.h" |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/common/media/media_player_messages_android.h" | 18 #include "content/common/media/media_player_messages_android.h" |
18 #include "content/public/browser/android/external_video_surface_container.h" | 19 #include "content/public/browser/android/external_video_surface_container.h" |
19 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
22 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
23 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
28 #include "content/public/common/content_client.h" | 29 #include "content/public/common/content_client.h" |
29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 31 #include "gpu/ipc/common/android/surface_texture_peer.h" |
30 #include "media/base/android/media_codec_player.h" | 32 #include "media/base/android/media_codec_player.h" |
31 #include "media/base/android/media_player_bridge.h" | 33 #include "media/base/android/media_player_bridge.h" |
32 #include "media/base/android/media_source_player.h" | 34 #include "media/base/android/media_source_player.h" |
33 #include "media/base/android/media_task_runner.h" | 35 #include "media/base/android/media_task_runner.h" |
34 #include "media/base/android/media_url_interceptor.h" | 36 #include "media/base/android/media_url_interceptor.h" |
35 | 37 |
36 #if !defined(USE_AURA) | 38 #if !defined(USE_AURA) |
37 #include "content/browser/android/content_view_core_impl.h" | 39 #include "content/browser/android/content_view_core_impl.h" |
38 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 40 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
39 #endif | 41 #endif |
40 | 42 |
41 using media::MediaCodecPlayer; | 43 using media::MediaCodecPlayer; |
42 using media::MediaPlayerAndroid; | 44 using media::MediaPlayerAndroid; |
43 using media::MediaPlayerBridge; | 45 using media::MediaPlayerBridge; |
44 using media::MediaPlayerManager; | 46 using media::MediaPlayerManager; |
45 using media::MediaSourcePlayer; | 47 using media::MediaSourcePlayer; |
46 | 48 |
47 namespace content { | 49 namespace content { |
48 | 50 |
| 51 namespace { |
| 52 |
| 53 class BrowserSurfaceTexturePeer : public gpu::SurfaceTexturePeer { |
| 54 public: |
| 55 static BrowserSurfaceTexturePeer* GetInstance(); |
| 56 |
| 57 private: |
| 58 friend struct base::DefaultSingletonTraits<BrowserSurfaceTexturePeer>; |
| 59 |
| 60 BrowserSurfaceTexturePeer(); |
| 61 ~BrowserSurfaceTexturePeer() override; |
| 62 |
| 63 void EstablishSurfaceTexturePeer( |
| 64 base::ProcessHandle render_process_handle, |
| 65 scoped_refptr<gfx::SurfaceTexture> surface_texture, |
| 66 int render_frame_id, |
| 67 int player_id) override; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(BrowserSurfaceTexturePeer); |
| 70 }; |
| 71 |
| 72 // static |
| 73 BrowserSurfaceTexturePeer* BrowserSurfaceTexturePeer::GetInstance() { |
| 74 return base::Singleton< |
| 75 BrowserSurfaceTexturePeer, |
| 76 base::LeakySingletonTraits<BrowserSurfaceTexturePeer>>::get(); |
| 77 } |
| 78 |
| 79 BrowserSurfaceTexturePeer::BrowserSurfaceTexturePeer() { |
| 80 gpu::SurfaceTexturePeer::InitInstance(this); |
| 81 } |
| 82 |
| 83 BrowserSurfaceTexturePeer::~BrowserSurfaceTexturePeer() { |
| 84 gpu::SurfaceTexturePeer::InitInstance(nullptr); |
| 85 } |
| 86 |
| 87 void BrowserSurfaceTexturePeer::EstablishSurfaceTexturePeer( |
| 88 base::ProcessHandle render_process_handle, |
| 89 scoped_refptr<gfx::SurfaceTexture> surface_texture, |
| 90 int render_frame_id, |
| 91 int player_id) { |
| 92 if (!surface_texture.get()) |
| 93 return; |
| 94 BrowserThread::PostTask( |
| 95 BrowserThread::UI, FROM_HERE, |
| 96 base::Bind(&BrowserMediaPlayerManager::SetSurfacePeer, surface_texture, |
| 97 render_process_handle, render_frame_id, player_id)); |
| 98 } |
| 99 |
| 100 } // namespace |
| 101 |
49 // Threshold on the number of media players per renderer before we start | 102 // Threshold on the number of media players per renderer before we start |
50 // attempting to release inactive media players. | 103 // attempting to release inactive media players. |
51 const int kMediaPlayerThreshold = 1; | 104 const int kMediaPlayerThreshold = 1; |
52 const int kInvalidMediaPlayerId = -1; | 105 const int kInvalidMediaPlayerId = -1; |
53 | 106 |
54 static BrowserMediaPlayerManager::Factory g_factory = NULL; | 107 static BrowserMediaPlayerManager::Factory g_factory = NULL; |
55 static media::MediaUrlInterceptor* media_url_interceptor_ = NULL; | 108 static media::MediaUrlInterceptor* media_url_interceptor_ = NULL; |
56 | 109 |
57 // static | 110 // static |
58 void BrowserMediaPlayerManager::RegisterFactory(Factory factory) { | 111 void BrowserMediaPlayerManager::RegisterFactory(Factory factory) { |
59 // TODO(aberent) nullptr test is a temporary fix to simplify upstreaming Cast. | 112 // TODO(aberent) nullptr test is a temporary fix to simplify upstreaming Cast. |
60 // Until Cast is fully upstreamed we want the downstream factory to take | 113 // Until Cast is fully upstreamed we want the downstream factory to take |
61 // priority over the upstream factory. The downstream call happens first, | 114 // priority over the upstream factory. The downstream call happens first, |
62 // so this will ensure that it does. | 115 // so this will ensure that it does. |
63 if (g_factory == nullptr) | 116 if (g_factory == nullptr) |
64 g_factory = factory; | 117 g_factory = factory; |
65 } | 118 } |
66 | 119 |
67 // static | 120 // static |
68 void BrowserMediaPlayerManager::RegisterMediaUrlInterceptor( | 121 void BrowserMediaPlayerManager::RegisterMediaUrlInterceptor( |
69 media::MediaUrlInterceptor* media_url_interceptor) { | 122 media::MediaUrlInterceptor* media_url_interceptor) { |
70 media_url_interceptor_ = media_url_interceptor; | 123 media_url_interceptor_ = media_url_interceptor; |
71 } | 124 } |
72 | 125 |
73 // static | 126 // static |
| 127 void BrowserMediaPlayerManager::InitSurfaceTexturePeer() { |
| 128 BrowserSurfaceTexturePeer::GetInstance(); |
| 129 } |
| 130 |
| 131 // static |
74 void BrowserMediaPlayerManager::SetSurfacePeer( | 132 void BrowserMediaPlayerManager::SetSurfacePeer( |
75 scoped_refptr<gfx::SurfaceTexture> surface_texture, | 133 scoped_refptr<gfx::SurfaceTexture> surface_texture, |
76 base::ProcessHandle render_process_handle, | 134 base::ProcessHandle render_process_handle, |
77 int render_frame_id, | 135 int render_frame_id, |
78 int player_id) { | 136 int player_id) { |
79 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
80 int render_process_id = 0; | 138 int render_process_id = 0; |
81 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | 139 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
82 while (!it.IsAtEnd()) { | 140 while (!it.IsAtEnd()) { |
83 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { | 141 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 if (!player) | 798 if (!player) |
741 return; | 799 return; |
742 player->Start(); | 800 player->Start(); |
743 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) { | 801 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) { |
744 video_view_->OpenVideo(); | 802 video_view_->OpenVideo(); |
745 fullscreen_player_is_released_ = false; | 803 fullscreen_player_is_released_ = false; |
746 } | 804 } |
747 } | 805 } |
748 | 806 |
749 } // namespace content | 807 } // namespace content |
OLD | NEW |