| 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_loop.h" | 28 #include "media/base/bind_to_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 if (GLES2Interface* gl = stream_texture_factory_->ContextGL()) |
| 185 stream_texture_factory_->Context3d(); | 187 gl->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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 audio_renderer_->Pause(); | 912 audio_renderer_->Pause(); |
| 913 #endif | 913 #endif |
| 914 manager_->Pause(player_id_, is_media_related_action); | 914 manager_->Pause(player_id_, is_media_related_action); |
| 915 UpdatePlayingState(false); | 915 UpdatePlayingState(false); |
| 916 } | 916 } |
| 917 | 917 |
| 918 void WebMediaPlayerAndroid::DrawRemotePlaybackIcon() { | 918 void WebMediaPlayerAndroid::DrawRemotePlaybackIcon() { |
| 919 DCHECK(main_thread_checker_.CalledOnValidThread()); | 919 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 920 if (!video_weblayer_) | 920 if (!video_weblayer_) |
| 921 return; | 921 return; |
| 922 blink::WebGraphicsContext3D* context = stream_texture_factory_->Context3d(); | 922 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
| 923 if (!context->makeContextCurrent()) | 923 if (!gl) |
| 924 return; | 924 return; |
| 925 | 925 |
| 926 // TODO(johnme): Should redraw this frame if the layer bounds change; but | 926 // TODO(johnme): Should redraw this frame if the layer bounds change; but |
| 927 // there seems no easy way to listen for the layer resizing (as opposed to | 927 // there seems no easy way to listen for the layer resizing (as opposed to |
| 928 // OnVideoSizeChanged, which is when the frame sizes of the video file | 928 // OnVideoSizeChanged, which is when the frame sizes of the video file |
| 929 // change). Perhaps have to poll (on main thread of course)? | 929 // change). Perhaps have to poll (on main thread of course)? |
| 930 gfx::Size video_size_css_px = video_weblayer_->bounds(); | 930 gfx::Size video_size_css_px = video_weblayer_->bounds(); |
| 931 float device_scale_factor = frame_->view()->deviceScaleFactor(); | 931 float device_scale_factor = frame_->view()->deviceScaleFactor(); |
| 932 // canvas_size will be the size in device pixels when pageScaleFactor == 1 | 932 // canvas_size will be the size in device pixels when pageScaleFactor == 1 |
| 933 gfx::Size canvas_size( | 933 gfx::Size canvas_size( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 962 int icon_height = icon_width * icon_bitmap->height() / icon_bitmap->width(); | 962 int icon_height = icon_width * icon_bitmap->height() / icon_bitmap->width(); |
| 963 // Center the icon within the frame | 963 // Center the icon within the frame |
| 964 SkRect icon_rect = SkRect::MakeXYWH((canvas_size.width() - icon_width) / 2, | 964 SkRect icon_rect = SkRect::MakeXYWH((canvas_size.width() - icon_width) / 2, |
| 965 (canvas_size.height() - icon_height) / 2, | 965 (canvas_size.height() - icon_height) / 2, |
| 966 icon_width, | 966 icon_width, |
| 967 icon_height); | 967 icon_height); |
| 968 canvas.drawBitmapRectToRect( | 968 canvas.drawBitmapRectToRect( |
| 969 *icon_bitmap, NULL /* src */, icon_rect /* dest */, &paint); | 969 *icon_bitmap, NULL /* src */, icon_rect /* dest */, &paint); |
| 970 | 970 |
| 971 if (!remote_playback_texture_id_) | 971 if (!remote_playback_texture_id_) |
| 972 remote_playback_texture_id_ = context->createTexture(); | 972 gl->GenTextures(1, &remote_playback_texture_id_); |
| 973 unsigned texture_target = GL_TEXTURE_2D; | 973 GLuint texture_target = GL_TEXTURE_2D; |
| 974 context->bindTexture(texture_target, remote_playback_texture_id_); | 974 gl->BindTexture(texture_target, remote_playback_texture_id_); |
| 975 context->texParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 975 gl->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 976 context->texParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 976 gl->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 977 context->texParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 977 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 978 context->texParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 978 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 979 | 979 |
| 980 { | 980 { |
| 981 SkAutoLockPixels lock(bitmap); | 981 SkAutoLockPixels lock(bitmap); |
| 982 context->texImage2D(texture_target, | 982 gl->TexImage2D(texture_target, |
| 983 0 /* level */, | 983 0 /* level */, |
| 984 GL_RGBA /* internalformat */, | 984 GL_RGBA /* internalformat */, |
| 985 bitmap.width(), | 985 bitmap.width(), |
| 986 bitmap.height(), | 986 bitmap.height(), |
| 987 0 /* border */, | 987 0 /* border */, |
| 988 GL_RGBA /* format */, | 988 GL_RGBA /* format */, |
| 989 GL_UNSIGNED_BYTE /* type */, | 989 GL_UNSIGNED_BYTE /* type */, |
| 990 bitmap.getPixels()); | 990 bitmap.getPixels()); |
| 991 } | 991 } |
| 992 | 992 |
| 993 gpu::Mailbox texture_mailbox; | 993 gpu::Mailbox texture_mailbox; |
| 994 context->genMailboxCHROMIUM(texture_mailbox.name); | 994 gl->GenMailboxCHROMIUM(texture_mailbox.name); |
| 995 context->produceTextureCHROMIUM(texture_target, texture_mailbox.name); | 995 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox.name); |
| 996 context->flush(); | 996 gl->Flush(); |
| 997 unsigned texture_mailbox_sync_point = context->insertSyncPoint(); | 997 GLuint texture_mailbox_sync_point = gl->InsertSyncPointCHROMIUM(); |
| 998 | 998 |
| 999 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( | 999 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( |
| 1000 make_scoped_ptr(new VideoFrame::MailboxHolder( | 1000 make_scoped_ptr(new VideoFrame::MailboxHolder( |
| 1001 texture_mailbox, | 1001 texture_mailbox, |
| 1002 texture_mailbox_sync_point, | 1002 texture_mailbox_sync_point, |
| 1003 base::Bind(&WebMediaPlayerAndroid::OnReleaseRemotePlaybackTexture, | 1003 base::Bind(&WebMediaPlayerAndroid::OnReleaseRemotePlaybackTexture, |
| 1004 main_loop_, | 1004 main_loop_, |
| 1005 weak_factory_.GetWeakPtr()))), | 1005 weak_factory_.GetWeakPtr()))), |
| 1006 texture_target, | 1006 texture_target, |
| 1007 canvas_size /* coded_size */, | 1007 canvas_size /* coded_size */, |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 demuxer_ = demuxer; | 1427 demuxer_ = demuxer; |
| 1428 destroy_demuxer_cb_ = destroy_demuxer_cb; | 1428 destroy_demuxer_cb_ = destroy_demuxer_cb; |
| 1429 return true; | 1429 return true; |
| 1430 } | 1430 } |
| 1431 #endif | 1431 #endif |
| 1432 | 1432 |
| 1433 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture(uint32 sync_point) { | 1433 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture(uint32 sync_point) { |
| 1434 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1434 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1435 DCHECK(remote_playback_texture_id_); | 1435 DCHECK(remote_playback_texture_id_); |
| 1436 | 1436 |
| 1437 blink::WebGraphicsContext3D* context = | 1437 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
| 1438 stream_texture_factory_->Context3d(); | |
| 1439 | 1438 |
| 1440 if (sync_point) | 1439 if (sync_point) |
| 1441 context->waitSyncPoint(sync_point); | 1440 gl->WaitSyncPointCHROMIUM(sync_point); |
| 1442 context->deleteTexture(remote_playback_texture_id_); | 1441 gl->DeleteTextures(1, &remote_playback_texture_id_); |
| 1443 remote_playback_texture_id_ = 0; | 1442 remote_playback_texture_id_ = 0; |
| 1444 } | 1443 } |
| 1445 | 1444 |
| 1446 void WebMediaPlayerAndroid::enterFullscreen() { | 1445 void WebMediaPlayerAndroid::enterFullscreen() { |
| 1447 if (manager_->CanEnterFullscreen(frame_)) { | 1446 if (manager_->CanEnterFullscreen(frame_)) { |
| 1448 manager_->EnterFullscreen(player_id_); | 1447 manager_->EnterFullscreen(player_id_); |
| 1449 SetNeedsEstablishPeer(false); | 1448 SetNeedsEstablishPeer(false); |
| 1450 } | 1449 } |
| 1451 } | 1450 } |
| 1452 | 1451 |
| 1453 void WebMediaPlayerAndroid::exitFullscreen() { | 1452 void WebMediaPlayerAndroid::exitFullscreen() { |
| 1454 manager_->ExitFullscreen(player_id_); | 1453 manager_->ExitFullscreen(player_id_); |
| 1455 } | 1454 } |
| 1456 | 1455 |
| 1457 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1456 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
| 1458 return manager_->CanEnterFullscreen(frame_); | 1457 return manager_->CanEnterFullscreen(frame_); |
| 1459 } | 1458 } |
| 1460 | 1459 |
| 1461 } // namespace content | 1460 } // namespace content |
| OLD | NEW |