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/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 using media::VideoFrame; | 80 using media::VideoFrame; |
81 | 81 |
82 namespace { | 82 namespace { |
83 // Prefix for histograms related to Encrypted Media Extensions. | 83 // Prefix for histograms related to Encrypted Media Extensions. |
84 const char* kMediaEme = "Media.EME."; | 84 const char* kMediaEme = "Media.EME."; |
85 | 85 |
86 // File-static function is to allow it to run even after WMPA is deleted. | 86 // File-static function is to allow it to run even after WMPA is deleted. |
87 void OnReleaseTexture( | 87 void OnReleaseTexture( |
88 const scoped_refptr<content::StreamTextureFactory>& factories, | 88 const scoped_refptr<content::StreamTextureFactory>& factories, |
89 uint32 texture_id, | 89 uint32 texture_id, |
90 uint32 release_sync_point) { | 90 const gpu::SyncToken& sync_token) { |
91 GLES2Interface* gl = factories->ContextGL(); | 91 GLES2Interface* gl = factories->ContextGL(); |
92 gl->WaitSyncPointCHROMIUM(release_sync_point); | 92 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
93 gl->DeleteTextures(1, &texture_id); | 93 gl->DeleteTextures(1, &texture_id); |
94 // Flush to ensure that the stream texture gets deleted in a timely fashion. | 94 // Flush to ensure that the stream texture gets deleted in a timely fashion. |
95 gl->ShallowFlushCHROMIUM(); | 95 gl->ShallowFlushCHROMIUM(); |
96 } | 96 } |
97 | 97 |
98 bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap, | 98 bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap, |
99 const gfx::Size& size) { | 99 const gfx::Size& size) { |
100 return bitmap->getTexture() && bitmap->width() == size.width() && | 100 return bitmap->getTexture() && bitmap->width() == size.width() && |
101 bitmap->height() == size.height(); | 101 bitmap->height() == size.height(); |
102 } | 102 } |
(...skipping 20 matching lines...) Expand all Loading... |
123 | 123 |
124 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight); | 124 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight); |
125 SkGrPixelRef* pixel_ref = new SkGrPixelRef(info, texture.get()); | 125 SkGrPixelRef* pixel_ref = new SkGrPixelRef(info, texture.get()); |
126 if (!pixel_ref) | 126 if (!pixel_ref) |
127 return false; | 127 return false; |
128 bitmap->setInfo(info); | 128 bitmap->setInfo(info); |
129 bitmap->setPixelRef(pixel_ref)->unref(); | 129 bitmap->setPixelRef(pixel_ref)->unref(); |
130 return true; | 130 return true; |
131 } | 131 } |
132 | 132 |
133 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | 133 class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient { |
134 public: | 134 public: |
135 explicit SyncPointClientImpl( | 135 explicit SyncTokenClientImpl( |
136 blink::WebGraphicsContext3D* web_graphics_context) | 136 blink::WebGraphicsContext3D* web_graphics_context) |
137 : web_graphics_context_(web_graphics_context) {} | 137 : web_graphics_context_(web_graphics_context) {} |
138 ~SyncPointClientImpl() override {} | 138 ~SyncTokenClientImpl() override {} |
139 uint32 InsertSyncPoint() override { | 139 uint32 InsertSyncPoint() override { |
140 return web_graphics_context_->insertSyncPoint(); | 140 return web_graphics_context_->insertSyncPoint(); |
141 } | 141 } |
142 void WaitSyncPoint(uint32 sync_point) override { | 142 void WaitSyncToken(const gpu::SyncToken& sync_token) override { |
143 web_graphics_context_->waitSyncPoint(sync_point); | 143 web_graphics_context_->waitSyncToken(sync_token.GetConstData()); |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 blink::WebGraphicsContext3D* web_graphics_context_; | 147 blink::WebGraphicsContext3D* web_graphics_context_; |
148 }; | 148 }; |
149 | 149 |
150 } // namespace | 150 } // namespace |
151 | 151 |
152 namespace content { | 152 namespace content { |
153 | 153 |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 } | 673 } |
674 | 674 |
675 if (!video_frame.get() || !video_frame->HasTextures()) | 675 if (!video_frame.get() || !video_frame->HasTextures()) |
676 return false; | 676 return false; |
677 DCHECK_EQ(1u, media::VideoFrame::NumPlanes(video_frame->format())); | 677 DCHECK_EQ(1u, media::VideoFrame::NumPlanes(video_frame->format())); |
678 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 678 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
679 DCHECK((!is_remote_ && | 679 DCHECK((!is_remote_ && |
680 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) || | 680 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) || |
681 (is_remote_ && mailbox_holder.texture_target == GL_TEXTURE_2D)); | 681 (is_remote_ && mailbox_holder.texture_target == GL_TEXTURE_2D)); |
682 | 682 |
683 web_graphics_context->waitSyncPoint(mailbox_holder.sync_point); | 683 web_graphics_context->waitSyncToken(mailbox_holder.sync_token); |
684 | 684 |
685 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 685 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
686 // an invalid texture target may be used for copy texture. | 686 // an invalid texture target may be used for copy texture. |
687 uint32 src_texture = | 687 uint32 src_texture = |
688 web_graphics_context->createAndConsumeTextureCHROMIUM( | 688 web_graphics_context->createAndConsumeTextureCHROMIUM( |
689 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 689 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
690 | 690 |
691 // Application itself needs to take care of setting the right flip_y | 691 // Application itself needs to take care of setting the right flip_y |
692 // value down to get the expected result. | 692 // value down to get the expected result. |
693 // flip_y==true means to reverse the video orientation while | 693 // flip_y==true means to reverse the video orientation while |
694 // flip_y==false means to keep the intrinsic orientation. | 694 // flip_y==false means to keep the intrinsic orientation. |
695 web_graphics_context->copyTextureCHROMIUM( | 695 web_graphics_context->copyTextureCHROMIUM( |
696 GL_TEXTURE_2D, src_texture, texture, internal_format, type, | 696 GL_TEXTURE_2D, src_texture, texture, internal_format, type, |
697 flip_y, premultiply_alpha, false); | 697 flip_y, premultiply_alpha, false); |
698 | 698 |
699 web_graphics_context->deleteTexture(src_texture); | 699 web_graphics_context->deleteTexture(src_texture); |
700 web_graphics_context->flush(); | 700 web_graphics_context->flush(); |
701 | 701 |
702 SyncPointClientImpl client(web_graphics_context); | 702 SyncTokenClientImpl client(web_graphics_context); |
703 video_frame->UpdateReleaseSyncPoint(&client); | 703 video_frame->UpdateReleaseSyncToken(&client); |
704 return true; | 704 return true; |
705 } | 705 } |
706 | 706 |
707 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 707 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
708 DCHECK(main_thread_checker_.CalledOnValidThread()); | 708 DCHECK(main_thread_checker_.CalledOnValidThread()); |
709 if (player_type_ != MEDIA_PLAYER_TYPE_URL) | 709 if (player_type_ != MEDIA_PLAYER_TYPE_URL) |
710 return true; | 710 return true; |
711 | 711 |
712 if (!info_loader_ || !info_loader_->HasSingleOrigin()) | 712 if (!info_loader_ || !info_loader_->HasSingleOrigin()) |
713 return false; | 713 return false; |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 0 /* border */, | 1217 0 /* border */, |
1218 GL_RGBA /* format */, | 1218 GL_RGBA /* format */, |
1219 GL_UNSIGNED_BYTE /* type */, | 1219 GL_UNSIGNED_BYTE /* type */, |
1220 bitmap.getPixels()); | 1220 bitmap.getPixels()); |
1221 } | 1221 } |
1222 | 1222 |
1223 gpu::Mailbox texture_mailbox; | 1223 gpu::Mailbox texture_mailbox; |
1224 gl->GenMailboxCHROMIUM(texture_mailbox.name); | 1224 gl->GenMailboxCHROMIUM(texture_mailbox.name); |
1225 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox.name); | 1225 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox.name); |
1226 gl->Flush(); | 1226 gl->Flush(); |
1227 GLuint texture_mailbox_sync_point = gl->InsertSyncPointCHROMIUM(); | 1227 gpu::SyncToken texture_mailbox_sync_token(gl->InsertSyncPointCHROMIUM()); |
1228 | 1228 |
1229 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( | 1229 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( |
1230 media::PIXEL_FORMAT_ARGB, | 1230 media::PIXEL_FORMAT_ARGB, |
1231 gpu::MailboxHolder(texture_mailbox, texture_target, | 1231 gpu::MailboxHolder(texture_mailbox, texture_mailbox_sync_token, |
1232 texture_mailbox_sync_point), | 1232 texture_target), |
1233 media::BindToCurrentLoop(base::Bind(&OnReleaseTexture, | 1233 media::BindToCurrentLoop(base::Bind(&OnReleaseTexture, |
1234 stream_texture_factory_, | 1234 stream_texture_factory_, |
1235 remote_playback_texture_id)), | 1235 remote_playback_texture_id)), |
1236 canvas_size /* coded_size */, gfx::Rect(canvas_size) /* visible_rect */, | 1236 canvas_size /* coded_size */, gfx::Rect(canvas_size) /* visible_rect */, |
1237 canvas_size /* natural_size */, base::TimeDelta() /* timestamp */); | 1237 canvas_size /* natural_size */, base::TimeDelta() /* timestamp */); |
1238 SetCurrentFrameInternal(new_frame); | 1238 SetCurrentFrameInternal(new_frame); |
1239 } | 1239 } |
1240 | 1240 |
1241 void WebMediaPlayerAndroid::ReallocateVideoFrame() { | 1241 void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
1242 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1242 DCHECK(main_thread_checker_.CalledOnValidThread()); |
(...skipping 12 matching lines...) Expand all Loading... |
1255 } | 1255 } |
1256 #else | 1256 #else |
1257 NOTIMPLEMENTED() << "Hole punching not supported without VIDEO_HOLE flag"; | 1257 NOTIMPLEMENTED() << "Hole punching not supported without VIDEO_HOLE flag"; |
1258 #endif // defined(VIDEO_HOLE) | 1258 #endif // defined(VIDEO_HOLE) |
1259 } else if (!is_remote_ && texture_id_) { | 1259 } else if (!is_remote_ && texture_id_) { |
1260 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | 1260 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
1261 GLuint texture_target = kGLTextureExternalOES; | 1261 GLuint texture_target = kGLTextureExternalOES; |
1262 GLuint texture_id_ref = gl->CreateAndConsumeTextureCHROMIUM( | 1262 GLuint texture_id_ref = gl->CreateAndConsumeTextureCHROMIUM( |
1263 texture_target, texture_mailbox_.name); | 1263 texture_target, texture_mailbox_.name); |
1264 gl->Flush(); | 1264 gl->Flush(); |
1265 GLuint texture_mailbox_sync_point = gl->InsertSyncPointCHROMIUM(); | 1265 gpu::SyncToken texture_mailbox_sync_token(gl->InsertSyncPointCHROMIUM()); |
1266 | 1266 |
1267 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( | 1267 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( |
1268 media::PIXEL_FORMAT_ARGB, | 1268 media::PIXEL_FORMAT_ARGB, |
1269 gpu::MailboxHolder(texture_mailbox_, texture_target, | 1269 gpu::MailboxHolder(texture_mailbox_, texture_mailbox_sync_token, |
1270 texture_mailbox_sync_point), | 1270 texture_target), |
1271 media::BindToCurrentLoop(base::Bind( | 1271 media::BindToCurrentLoop(base::Bind( |
1272 &OnReleaseTexture, stream_texture_factory_, texture_id_ref)), | 1272 &OnReleaseTexture, stream_texture_factory_, texture_id_ref)), |
1273 natural_size_, gfx::Rect(natural_size_), natural_size_, | 1273 natural_size_, gfx::Rect(natural_size_), natural_size_, |
1274 base::TimeDelta()); | 1274 base::TimeDelta()); |
1275 SetCurrentFrameInternal(new_frame); | 1275 SetCurrentFrameInternal(new_frame); |
1276 } | 1276 } |
1277 } | 1277 } |
1278 | 1278 |
1279 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( | 1279 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
1280 cc::VideoFrameProvider::Client* client) { | 1280 cc::VideoFrameProvider::Client* client) { |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 | 1915 |
1916 bool is_hls = IsHLSStream(); | 1916 bool is_hls = IsHLSStream(); |
1917 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); | 1917 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); |
1918 if (is_hls) { | 1918 if (is_hls) { |
1919 media::RecordOriginOfHLSPlayback( | 1919 media::RecordOriginOfHLSPlayback( |
1920 GURL(frame_->document().securityOrigin().toString())); | 1920 GURL(frame_->document().securityOrigin().toString())); |
1921 } | 1921 } |
1922 } | 1922 } |
1923 | 1923 |
1924 } // namespace content | 1924 } // namespace content |
OLD | NEW |