| 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 gpu::SyncToken sync_token; |
| 141 if (!web_graphics_context_->insertSyncPoint(sync_token.GetData())) |
| 142 return 0; |
| 143 return static_cast<uint32>(sync_token.release_count()); |
| 141 } | 144 } |
| 142 void WaitSyncPoint(uint32 sync_point) override { | 145 void WaitSyncToken(const gpu::SyncToken& sync_token) override { |
| 143 web_graphics_context_->waitSyncPoint(sync_point); | 146 web_graphics_context_->waitSyncToken(sync_token.GetConstData()); |
| 144 } | 147 } |
| 145 | 148 |
| 146 private: | 149 private: |
| 147 blink::WebGraphicsContext3D* web_graphics_context_; | 150 blink::WebGraphicsContext3D* web_graphics_context_; |
| 148 }; | 151 }; |
| 149 | 152 |
| 150 } // namespace | 153 } // namespace |
| 151 | 154 |
| 152 namespace content { | 155 namespace content { |
| 153 | 156 |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 } | 680 } |
| 678 | 681 |
| 679 if (!video_frame.get() || !video_frame->HasTextures()) | 682 if (!video_frame.get() || !video_frame->HasTextures()) |
| 680 return false; | 683 return false; |
| 681 DCHECK_EQ(1u, media::VideoFrame::NumPlanes(video_frame->format())); | 684 DCHECK_EQ(1u, media::VideoFrame::NumPlanes(video_frame->format())); |
| 682 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 685 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
| 683 DCHECK((!is_remote_ && | 686 DCHECK((!is_remote_ && |
| 684 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) || | 687 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) || |
| 685 (is_remote_ && mailbox_holder.texture_target == GL_TEXTURE_2D)); | 688 (is_remote_ && mailbox_holder.texture_target == GL_TEXTURE_2D)); |
| 686 | 689 |
| 687 web_graphics_context->waitSyncPoint(mailbox_holder.sync_point); | 690 web_graphics_context->waitSyncToken(mailbox_holder.sync_token.GetConstData()); |
| 688 | 691 |
| 689 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 692 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
| 690 // an invalid texture target may be used for copy texture. | 693 // an invalid texture target may be used for copy texture. |
| 691 uint32 src_texture = | 694 uint32 src_texture = |
| 692 web_graphics_context->createAndConsumeTextureCHROMIUM( | 695 web_graphics_context->createAndConsumeTextureCHROMIUM( |
| 693 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 696 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
| 694 | 697 |
| 695 // Application itself needs to take care of setting the right flip_y | 698 // Application itself needs to take care of setting the right flip_y |
| 696 // value down to get the expected result. | 699 // value down to get the expected result. |
| 697 // flip_y==true means to reverse the video orientation while | 700 // flip_y==true means to reverse the video orientation while |
| 698 // flip_y==false means to keep the intrinsic orientation. | 701 // flip_y==false means to keep the intrinsic orientation. |
| 699 web_graphics_context->copyTextureCHROMIUM( | 702 web_graphics_context->copyTextureCHROMIUM( |
| 700 GL_TEXTURE_2D, src_texture, texture, internal_format, type, | 703 GL_TEXTURE_2D, src_texture, texture, internal_format, type, |
| 701 flip_y, premultiply_alpha, false); | 704 flip_y, premultiply_alpha, false); |
| 702 | 705 |
| 703 web_graphics_context->deleteTexture(src_texture); | 706 web_graphics_context->deleteTexture(src_texture); |
| 704 web_graphics_context->flush(); | 707 web_graphics_context->flush(); |
| 705 | 708 |
| 706 SyncPointClientImpl client(web_graphics_context); | 709 SyncTokenClientImpl client(web_graphics_context); |
| 707 video_frame->UpdateReleaseSyncPoint(&client); | 710 video_frame->UpdateReleaseSyncToken(&client); |
| 708 return true; | 711 return true; |
| 709 } | 712 } |
| 710 | 713 |
| 711 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 714 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
| 712 DCHECK(main_thread_checker_.CalledOnValidThread()); | 715 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 713 if (player_type_ != MEDIA_PLAYER_TYPE_URL) | 716 if (player_type_ != MEDIA_PLAYER_TYPE_URL) |
| 714 return true; | 717 return true; |
| 715 | 718 |
| 716 if (!info_loader_ || !info_loader_->HasSingleOrigin()) | 719 if (!info_loader_ || !info_loader_->HasSingleOrigin()) |
| 717 return false; | 720 return false; |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 0 /* border */, | 1224 0 /* border */, |
| 1222 GL_RGBA /* format */, | 1225 GL_RGBA /* format */, |
| 1223 GL_UNSIGNED_BYTE /* type */, | 1226 GL_UNSIGNED_BYTE /* type */, |
| 1224 bitmap.getPixels()); | 1227 bitmap.getPixels()); |
| 1225 } | 1228 } |
| 1226 | 1229 |
| 1227 gpu::Mailbox texture_mailbox; | 1230 gpu::Mailbox texture_mailbox; |
| 1228 gl->GenMailboxCHROMIUM(texture_mailbox.name); | 1231 gl->GenMailboxCHROMIUM(texture_mailbox.name); |
| 1229 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox.name); | 1232 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox.name); |
| 1230 gl->Flush(); | 1233 gl->Flush(); |
| 1231 GLuint texture_mailbox_sync_point = gl->InsertSyncPointCHROMIUM(); | 1234 gpu::SyncToken texture_mailbox_sync_token(gl->InsertSyncPointCHROMIUM()); |
| 1232 | 1235 |
| 1233 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( | 1236 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( |
| 1234 media::PIXEL_FORMAT_ARGB, | 1237 media::PIXEL_FORMAT_ARGB, |
| 1235 gpu::MailboxHolder(texture_mailbox, texture_target, | 1238 gpu::MailboxHolder(texture_mailbox, texture_mailbox_sync_token, |
| 1236 texture_mailbox_sync_point), | 1239 texture_target), |
| 1237 media::BindToCurrentLoop(base::Bind(&OnReleaseTexture, | 1240 media::BindToCurrentLoop(base::Bind(&OnReleaseTexture, |
| 1238 stream_texture_factory_, | 1241 stream_texture_factory_, |
| 1239 remote_playback_texture_id)), | 1242 remote_playback_texture_id)), |
| 1240 canvas_size /* coded_size */, gfx::Rect(canvas_size) /* visible_rect */, | 1243 canvas_size /* coded_size */, gfx::Rect(canvas_size) /* visible_rect */, |
| 1241 canvas_size /* natural_size */, base::TimeDelta() /* timestamp */); | 1244 canvas_size /* natural_size */, base::TimeDelta() /* timestamp */); |
| 1242 SetCurrentFrameInternal(new_frame); | 1245 SetCurrentFrameInternal(new_frame); |
| 1243 } | 1246 } |
| 1244 | 1247 |
| 1245 void WebMediaPlayerAndroid::ReallocateVideoFrame() { | 1248 void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
| 1246 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1249 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1259 } | 1262 } |
| 1260 #else | 1263 #else |
| 1261 NOTIMPLEMENTED() << "Hole punching not supported without VIDEO_HOLE flag"; | 1264 NOTIMPLEMENTED() << "Hole punching not supported without VIDEO_HOLE flag"; |
| 1262 #endif // defined(VIDEO_HOLE) | 1265 #endif // defined(VIDEO_HOLE) |
| 1263 } else if (!is_remote_ && texture_id_) { | 1266 } else if (!is_remote_ && texture_id_) { |
| 1264 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | 1267 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
| 1265 GLuint texture_target = kGLTextureExternalOES; | 1268 GLuint texture_target = kGLTextureExternalOES; |
| 1266 GLuint texture_id_ref = gl->CreateAndConsumeTextureCHROMIUM( | 1269 GLuint texture_id_ref = gl->CreateAndConsumeTextureCHROMIUM( |
| 1267 texture_target, texture_mailbox_.name); | 1270 texture_target, texture_mailbox_.name); |
| 1268 gl->Flush(); | 1271 gl->Flush(); |
| 1269 GLuint texture_mailbox_sync_point = gl->InsertSyncPointCHROMIUM(); | 1272 gpu::SyncToken texture_mailbox_sync_token(gl->InsertSyncPointCHROMIUM()); |
| 1270 | 1273 |
| 1271 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( | 1274 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( |
| 1272 media::PIXEL_FORMAT_ARGB, | 1275 media::PIXEL_FORMAT_ARGB, |
| 1273 gpu::MailboxHolder(texture_mailbox_, texture_target, | 1276 gpu::MailboxHolder(texture_mailbox_, texture_mailbox_sync_token, |
| 1274 texture_mailbox_sync_point), | 1277 texture_target), |
| 1275 media::BindToCurrentLoop(base::Bind( | 1278 media::BindToCurrentLoop(base::Bind( |
| 1276 &OnReleaseTexture, stream_texture_factory_, texture_id_ref)), | 1279 &OnReleaseTexture, stream_texture_factory_, texture_id_ref)), |
| 1277 natural_size_, gfx::Rect(natural_size_), natural_size_, | 1280 natural_size_, gfx::Rect(natural_size_), natural_size_, |
| 1278 base::TimeDelta()); | 1281 base::TimeDelta()); |
| 1279 SetCurrentFrameInternal(new_frame); | 1282 SetCurrentFrameInternal(new_frame); |
| 1280 } | 1283 } |
| 1281 } | 1284 } |
| 1282 | 1285 |
| 1283 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( | 1286 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
| 1284 cc::VideoFrameProvider::Client* client) { | 1287 cc::VideoFrameProvider::Client* client) { |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1919 | 1922 |
| 1920 bool is_hls = IsHLSStream(); | 1923 bool is_hls = IsHLSStream(); |
| 1921 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); | 1924 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); |
| 1922 if (is_hls) { | 1925 if (is_hls) { |
| 1923 media::RecordOriginOfHLSPlayback( | 1926 media::RecordOriginOfHLSPlayback( |
| 1924 GURL(frame_->document().securityOrigin().toString())); | 1927 GURL(frame_->document().securityOrigin().toString())); |
| 1925 } | 1928 } |
| 1926 } | 1929 } |
| 1927 | 1930 |
| 1928 } // namespace content | 1931 } // namespace content |
| OLD | NEW |