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/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "cc/layers/video_layer.h" | 15 #include "cc/layers/video_layer.h" |
16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
17 #include "content/renderer/media/android/proxy_media_keys.h" | 17 #include "content/renderer/media/android/proxy_media_keys.h" |
18 #include "content/renderer/media/android/renderer_demuxer_android.h" | 18 #include "content/renderer/media/android/renderer_demuxer_android.h" |
19 #include "content/renderer/media/android/renderer_media_player_manager.h" | 19 #include "content/renderer/media/android/renderer_media_player_manager.h" |
20 #include "content/renderer/media/crypto/key_systems.h" | 20 #include "content/renderer/media/crypto/key_systems.h" |
21 #include "content/renderer/media/webmediaplayer_delegate.h" | 21 #include "content/renderer/media/webmediaplayer_delegate.h" |
22 #include "content/renderer/media/webmediaplayer_util.h" | 22 #include "content/renderer/media/webmediaplayer_util.h" |
23 #include "content/renderer/render_thread_impl.h" | 23 #include "content/renderer/render_thread_impl.h" |
24 #include "gpu/GLES2/gl2extchromium.h" | 24 #include "gpu/GLES2/gl2extchromium.h" |
| 25 #include "gpu/command_buffer/client/gles2_interface.h" |
25 #include "grit/content_resources.h" | 26 #include "grit/content_resources.h" |
26 #include "media/base/android/media_player_android.h" | 27 #include "media/base/android/media_player_android.h" |
27 #include "media/base/bind_to_current_loop.h" | 28 #include "media/base/bind_to_current_loop.h" |
28 #include "media/base/media_switches.h" | 29 #include "media/base/media_switches.h" |
29 #include "media/base/video_frame.h" | 30 #include "media/base/video_frame.h" |
30 #include "net/base/mime_util.h" | 31 #include "net/base/mime_util.h" |
31 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 32 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
32 #include "third_party/WebKit/public/platform/WebString.h" | 33 #include "third_party/WebKit/public/platform/WebString.h" |
33 #include "third_party/WebKit/public/web/WebDocument.h" | 34 #include "third_party/WebKit/public/web/WebDocument.h" |
34 #include "third_party/WebKit/public/web/WebFrame.h" | 35 #include "third_party/WebKit/public/web/WebFrame.h" |
(...skipping 10 matching lines...) Expand all Loading... |
45 #include "content/renderer/media/media_stream_client.h" | 46 #include "content/renderer/media/media_stream_client.h" |
46 #endif | 47 #endif |
47 | 48 |
48 static const uint32 kGLTextureExternalOES = 0x8D65; | 49 static const uint32 kGLTextureExternalOES = 0x8D65; |
49 | 50 |
50 using blink::WebMediaPlayer; | 51 using blink::WebMediaPlayer; |
51 using blink::WebSize; | 52 using blink::WebSize; |
52 using blink::WebString; | 53 using blink::WebString; |
53 using blink::WebTimeRanges; | 54 using blink::WebTimeRanges; |
54 using blink::WebURL; | 55 using blink::WebURL; |
| 56 using gpu::gles2::GLES2Interface; |
55 using media::MediaPlayerAndroid; | 57 using media::MediaPlayerAndroid; |
56 using media::VideoFrame; | 58 using media::VideoFrame; |
57 | 59 |
58 namespace { | 60 namespace { |
59 // Prefix for histograms related to Encrypted Media Extensions. | 61 // Prefix for histograms related to Encrypted Media Extensions. |
60 const char* kMediaEme = "Media.EME."; | 62 const char* kMediaEme = "Media.EME."; |
61 } // namespace | 63 } // namespace |
62 | 64 |
63 namespace content { | 65 namespace content { |
64 | 66 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 176 |
175 if (manager_) { | 177 if (manager_) { |
176 manager_->DestroyPlayer(player_id_); | 178 manager_->DestroyPlayer(player_id_); |
177 manager_->UnregisterMediaPlayer(player_id_); | 179 manager_->UnregisterMediaPlayer(player_id_); |
178 } | 180 } |
179 | 181 |
180 if (stream_id_) | 182 if (stream_id_) |
181 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 183 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
182 | 184 |
183 if (remote_playback_texture_id_) { | 185 if (remote_playback_texture_id_) { |
184 blink::WebGraphicsContext3D* context = | 186 stream_texture_factory_->ContextGL()-> |
185 stream_texture_factory_->Context3d(); | 187 DeleteTextures(1, &remote_playback_texture_id_); |
186 if (context->makeContextCurrent()) | |
187 context->deleteTexture(remote_playback_texture_id_); | |
188 } | 188 } |
189 | 189 |
190 if (base::MessageLoop::current()) | 190 if (base::MessageLoop::current()) |
191 base::MessageLoop::current()->RemoveDestructionObserver(this); | 191 base::MessageLoop::current()->RemoveDestructionObserver(this); |
192 | 192 |
193 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) | 193 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) |
194 delegate_->PlayerGone(this); | 194 delegate_->PlayerGone(this); |
195 | 195 |
196 #if defined(GOOGLE_TV) | 196 #if defined(GOOGLE_TV) |
197 if (audio_renderer_) { | 197 if (audio_renderer_) { |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 audio_renderer_->Pause(); | 922 audio_renderer_->Pause(); |
923 #endif | 923 #endif |
924 manager_->Pause(player_id_, is_media_related_action); | 924 manager_->Pause(player_id_, is_media_related_action); |
925 UpdatePlayingState(false); | 925 UpdatePlayingState(false); |
926 } | 926 } |
927 | 927 |
928 void WebMediaPlayerAndroid::DrawRemotePlaybackIcon() { | 928 void WebMediaPlayerAndroid::DrawRemotePlaybackIcon() { |
929 DCHECK(main_thread_checker_.CalledOnValidThread()); | 929 DCHECK(main_thread_checker_.CalledOnValidThread()); |
930 if (!video_weblayer_) | 930 if (!video_weblayer_) |
931 return; | 931 return; |
932 blink::WebGraphicsContext3D* context = stream_texture_factory_->Context3d(); | |
933 if (!context->makeContextCurrent()) | |
934 return; | |
935 | 932 |
936 // TODO(johnme): Should redraw this frame if the layer bounds change; but | 933 // TODO(johnme): Should redraw this frame if the layer bounds change; but |
937 // there seems no easy way to listen for the layer resizing (as opposed to | 934 // there seems no easy way to listen for the layer resizing (as opposed to |
938 // OnVideoSizeChanged, which is when the frame sizes of the video file | 935 // OnVideoSizeChanged, which is when the frame sizes of the video file |
939 // change). Perhaps have to poll (on main thread of course)? | 936 // change). Perhaps have to poll (on main thread of course)? |
940 gfx::Size video_size_css_px = video_weblayer_->bounds(); | 937 gfx::Size video_size_css_px = video_weblayer_->bounds(); |
941 float device_scale_factor = frame_->view()->deviceScaleFactor(); | 938 float device_scale_factor = frame_->view()->deviceScaleFactor(); |
942 // canvas_size will be the size in device pixels when pageScaleFactor == 1 | 939 // canvas_size will be the size in device pixels when pageScaleFactor == 1 |
943 gfx::Size canvas_size( | 940 gfx::Size canvas_size( |
944 static_cast<int>(video_size_css_px.width() * device_scale_factor), | 941 static_cast<int>(video_size_css_px.width() * device_scale_factor), |
(...skipping 26 matching lines...) Expand all Loading... |
971 icon_bitmap->height() * 3 / 5); | 968 icon_bitmap->height() * 3 / 5); |
972 int icon_height = icon_width * icon_bitmap->height() / icon_bitmap->width(); | 969 int icon_height = icon_width * icon_bitmap->height() / icon_bitmap->width(); |
973 // Center the icon within the frame | 970 // Center the icon within the frame |
974 SkRect icon_rect = SkRect::MakeXYWH((canvas_size.width() - icon_width) / 2, | 971 SkRect icon_rect = SkRect::MakeXYWH((canvas_size.width() - icon_width) / 2, |
975 (canvas_size.height() - icon_height) / 2, | 972 (canvas_size.height() - icon_height) / 2, |
976 icon_width, | 973 icon_width, |
977 icon_height); | 974 icon_height); |
978 canvas.drawBitmapRectToRect( | 975 canvas.drawBitmapRectToRect( |
979 *icon_bitmap, NULL /* src */, icon_rect /* dest */, &paint); | 976 *icon_bitmap, NULL /* src */, icon_rect /* dest */, &paint); |
980 | 977 |
| 978 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
| 979 |
981 if (!remote_playback_texture_id_) | 980 if (!remote_playback_texture_id_) |
982 remote_playback_texture_id_ = context->createTexture(); | 981 gl->GenTextures(1, &remote_playback_texture_id_); |
983 unsigned texture_target = GL_TEXTURE_2D; | 982 GLuint texture_target = GL_TEXTURE_2D; |
984 context->bindTexture(texture_target, remote_playback_texture_id_); | 983 gl->BindTexture(texture_target, remote_playback_texture_id_); |
985 context->texParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 984 gl->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
986 context->texParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 985 gl->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
987 context->texParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 986 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
988 context->texParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 987 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
989 | 988 |
990 { | 989 { |
991 SkAutoLockPixels lock(bitmap); | 990 SkAutoLockPixels lock(bitmap); |
992 context->texImage2D(texture_target, | 991 gl->TexImage2D(texture_target, |
993 0 /* level */, | 992 0 /* level */, |
994 GL_RGBA /* internalformat */, | 993 GL_RGBA /* internalformat */, |
995 bitmap.width(), | 994 bitmap.width(), |
996 bitmap.height(), | 995 bitmap.height(), |
997 0 /* border */, | 996 0 /* border */, |
998 GL_RGBA /* format */, | 997 GL_RGBA /* format */, |
999 GL_UNSIGNED_BYTE /* type */, | 998 GL_UNSIGNED_BYTE /* type */, |
1000 bitmap.getPixels()); | 999 bitmap.getPixels()); |
1001 } | 1000 } |
1002 | 1001 |
1003 gpu::Mailbox texture_mailbox; | 1002 gpu::Mailbox texture_mailbox; |
1004 context->genMailboxCHROMIUM(texture_mailbox.name); | 1003 gl->GenMailboxCHROMIUM(texture_mailbox.name); |
1005 context->produceTextureCHROMIUM(texture_target, texture_mailbox.name); | 1004 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox.name); |
1006 context->flush(); | 1005 gl->Flush(); |
1007 unsigned texture_mailbox_sync_point = context->insertSyncPoint(); | 1006 GLuint texture_mailbox_sync_point = gl->InsertSyncPointCHROMIUM(); |
1008 | 1007 |
1009 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( | 1008 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( |
1010 make_scoped_ptr(new VideoFrame::MailboxHolder( | 1009 make_scoped_ptr(new VideoFrame::MailboxHolder( |
1011 texture_mailbox, | 1010 texture_mailbox, |
1012 texture_mailbox_sync_point, | 1011 texture_mailbox_sync_point, |
1013 base::Bind(&WebMediaPlayerAndroid::OnReleaseRemotePlaybackTexture, | 1012 base::Bind(&WebMediaPlayerAndroid::OnReleaseRemotePlaybackTexture, |
1014 main_loop_, | 1013 main_loop_, |
1015 weak_factory_.GetWeakPtr()))), | 1014 weak_factory_.GetWeakPtr()))), |
1016 texture_target, | 1015 texture_target, |
1017 canvas_size /* coded_size */, | 1016 canvas_size /* coded_size */, |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 demuxer_ = demuxer; | 1436 demuxer_ = demuxer; |
1438 destroy_demuxer_cb_ = destroy_demuxer_cb; | 1437 destroy_demuxer_cb_ = destroy_demuxer_cb; |
1439 return true; | 1438 return true; |
1440 } | 1439 } |
1441 #endif | 1440 #endif |
1442 | 1441 |
1443 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture(uint32 sync_point) { | 1442 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture(uint32 sync_point) { |
1444 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1443 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1445 DCHECK(remote_playback_texture_id_); | 1444 DCHECK(remote_playback_texture_id_); |
1446 | 1445 |
1447 blink::WebGraphicsContext3D* context = | 1446 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
1448 stream_texture_factory_->Context3d(); | |
1449 | 1447 |
1450 if (sync_point) | 1448 if (sync_point) |
1451 context->waitSyncPoint(sync_point); | 1449 gl->WaitSyncPointCHROMIUM(sync_point); |
1452 context->deleteTexture(remote_playback_texture_id_); | 1450 gl->DeleteTextures(1, &remote_playback_texture_id_); |
1453 remote_playback_texture_id_ = 0; | 1451 remote_playback_texture_id_ = 0; |
1454 } | 1452 } |
1455 | 1453 |
1456 void WebMediaPlayerAndroid::enterFullscreen() { | 1454 void WebMediaPlayerAndroid::enterFullscreen() { |
1457 if (manager_->CanEnterFullscreen(frame_)) { | 1455 if (manager_->CanEnterFullscreen(frame_)) { |
1458 manager_->EnterFullscreen(player_id_); | 1456 manager_->EnterFullscreen(player_id_); |
1459 SetNeedsEstablishPeer(false); | 1457 SetNeedsEstablishPeer(false); |
1460 } | 1458 } |
1461 } | 1459 } |
1462 | 1460 |
1463 void WebMediaPlayerAndroid::exitFullscreen() { | 1461 void WebMediaPlayerAndroid::exitFullscreen() { |
1464 manager_->ExitFullscreen(player_id_); | 1462 manager_->ExitFullscreen(player_id_); |
1465 } | 1463 } |
1466 | 1464 |
1467 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1465 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
1468 return manager_->CanEnterFullscreen(frame_); | 1466 return manager_->CanEnterFullscreen(frame_); |
1469 } | 1467 } |
1470 | 1468 |
1471 } // namespace content | 1469 } // namespace content |
OLD | NEW |