Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 1567123002: Support CAST+WMPI on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fixes + comments addressed Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 28 matching lines...) Expand all
39 #include "media/base/android/media_player_android.h" 39 #include "media/base/android/media_player_android.h"
40 #include "media/base/bind_to_current_loop.h" 40 #include "media/base/bind_to_current_loop.h"
41 #include "media/base/cdm_context.h" 41 #include "media/base/cdm_context.h"
42 #include "media/base/key_systems.h" 42 #include "media/base/key_systems.h"
43 #include "media/base/media_keys.h" 43 #include "media/base/media_keys.h"
44 #include "media/base/media_log.h" 44 #include "media/base/media_log.h"
45 #include "media/base/media_switches.h" 45 #include "media/base/media_switches.h"
46 #include "media/base/timestamp_constants.h" 46 #include "media/base/timestamp_constants.h"
47 #include "media/base/video_frame.h" 47 #include "media/base/video_frame.h"
48 #include "media/blink/webcontentdecryptionmodule_impl.h" 48 #include "media/blink/webcontentdecryptionmodule_impl.h"
49 #include "media/blink/webmediaplayer_cast_android.h"
49 #include "media/blink/webmediaplayer_delegate.h" 50 #include "media/blink/webmediaplayer_delegate.h"
50 #include "media/blink/webmediaplayer_util.h" 51 #include "media/blink/webmediaplayer_util.h"
51 #include "net/base/mime_util.h" 52 #include "net/base/mime_util.h"
52 #include "third_party/WebKit/public/platform/Platform.h" 53 #include "third_party/WebKit/public/platform/Platform.h"
53 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" 54 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
54 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" 55 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h"
55 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" 56 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h"
56 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" 57 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
57 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h" 58 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h"
58 #include "third_party/WebKit/public/platform/WebString.h" 59 #include "third_party/WebKit/public/platform/WebString.h"
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 // OnVideoSizeChanged, which is when the frame sizes of the video file 1155 // OnVideoSizeChanged, which is when the frame sizes of the video file
1155 // change). Perhaps have to poll (on main thread of course)? 1156 // change). Perhaps have to poll (on main thread of course)?
1156 gfx::Size video_size_css_px = video_weblayer_->bounds(); 1157 gfx::Size video_size_css_px = video_weblayer_->bounds();
1157 RenderView* render_view = RenderView::FromWebView(frame_->view()); 1158 RenderView* render_view = RenderView::FromWebView(frame_->view());
1158 float device_scale_factor = render_view->GetDeviceScaleFactor(); 1159 float device_scale_factor = render_view->GetDeviceScaleFactor();
1159 // canvas_size will be the size in device pixels when pageScaleFactor == 1 1160 // canvas_size will be the size in device pixels when pageScaleFactor == 1
1160 gfx::Size canvas_size( 1161 gfx::Size canvas_size(
1161 static_cast<int>(video_size_css_px.width() * device_scale_factor), 1162 static_cast<int>(video_size_css_px.width() * device_scale_factor),
1162 static_cast<int>(video_size_css_px.height() * device_scale_factor)); 1163 static_cast<int>(video_size_css_px.height() * device_scale_factor));
1163 1164
1164 SkBitmap bitmap; 1165 scoped_refptr<VideoFrame> new_frame(media::MakeTextFrameForCast(
1165 bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height()); 1166 remote_playback_message,
1166 1167 canvas_size,
1167 // Create the canvas and draw the "Casting to <Chromecast>" text on it. 1168 canvas_size,
1168 SkCanvas canvas(bitmap); 1169 base::Bind(&StreamTextureFactory::ContextGL,
1169 canvas.drawColor(SK_ColorBLACK); 1170 stream_texture_factory_)));
1170
1171 const SkScalar kTextSize(40);
1172 const SkScalar kMinPadding(40);
1173
1174 SkPaint paint;
1175 paint.setAntiAlias(true);
1176 paint.setFilterQuality(kHigh_SkFilterQuality);
1177 paint.setColor(SK_ColorWHITE);
1178 paint.setTypeface(SkTypeface::CreateFromName("sans", SkTypeface::kBold));
1179 paint.setTextSize(kTextSize);
1180
1181 // Calculate the vertical margin from the top
1182 SkPaint::FontMetrics font_metrics;
1183 paint.getFontMetrics(&font_metrics);
1184 SkScalar sk_vertical_margin = kMinPadding - font_metrics.fAscent;
1185
1186 // Measure the width of the entire text to display
1187 size_t display_text_width = paint.measureText(
1188 remote_playback_message.c_str(), remote_playback_message.size());
1189 std::string display_text(remote_playback_message);
1190
1191 if (display_text_width + (kMinPadding * 2) > canvas_size.width()) {
1192 // The text is too long to fit in one line, truncate it and append ellipsis
1193 // to the end.
1194
1195 // First, figure out how much of the canvas the '...' will take up.
1196 const std::string kTruncationEllipsis("\xE2\x80\xA6");
1197 SkScalar sk_ellipse_width = paint.measureText(
1198 kTruncationEllipsis.c_str(), kTruncationEllipsis.size());
1199
1200 // Then calculate how much of the text can be drawn with the '...' appended
1201 // to the end of the string.
1202 SkScalar sk_max_original_text_width(
1203 canvas_size.width() - (kMinPadding * 2) - sk_ellipse_width);
1204 size_t sk_max_original_text_length = paint.breakText(
1205 remote_playback_message.c_str(),
1206 remote_playback_message.size(),
1207 sk_max_original_text_width);
1208
1209 // Remove the part of the string that doesn't fit and append '...'.
1210 display_text.erase(sk_max_original_text_length,
1211 remote_playback_message.size() - sk_max_original_text_length);
1212 display_text.append(kTruncationEllipsis);
1213 display_text_width = paint.measureText(
1214 display_text.c_str(), display_text.size());
1215 }
1216
1217 // Center the text horizontally.
1218 SkScalar sk_horizontal_margin =
1219 (canvas_size.width() - display_text_width) / 2.0;
1220 canvas.drawText(display_text.c_str(),
1221 display_text.size(),
1222 sk_horizontal_margin,
1223 sk_vertical_margin,
1224 paint);
1225
1226 GLES2Interface* gl = stream_texture_factory_->ContextGL();
1227 GLuint remote_playback_texture_id = 0;
1228 gl->GenTextures(1, &remote_playback_texture_id);
1229 GLuint texture_target = GL_TEXTURE_2D;
1230 gl->BindTexture(texture_target, remote_playback_texture_id);
1231 gl->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1232 gl->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1233 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1234 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1235
1236 {
1237 SkAutoLockPixels lock(bitmap);
1238 gl->TexImage2D(texture_target,
1239 0 /* level */,
1240 GL_RGBA /* internalformat */,
1241 bitmap.width(),
1242 bitmap.height(),
1243 0 /* border */,
1244 GL_RGBA /* format */,
1245 GL_UNSIGNED_BYTE /* type */,
1246 bitmap.getPixels());
1247 }
1248
1249 gpu::Mailbox texture_mailbox;
1250 gl->GenMailboxCHROMIUM(texture_mailbox.name);
1251 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox.name);
1252 gl->Flush();
1253 gpu::SyncToken texture_mailbox_sync_token(gl->InsertSyncPointCHROMIUM());
1254
1255 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture(
1256 media::PIXEL_FORMAT_ARGB,
1257 gpu::MailboxHolder(texture_mailbox, texture_mailbox_sync_token,
1258 texture_target),
1259 media::BindToCurrentLoop(base::Bind(&OnReleaseTexture,
1260 stream_texture_factory_,
1261 remote_playback_texture_id)),
1262 canvas_size /* coded_size */, gfx::Rect(canvas_size) /* visible_rect */,
1263 canvas_size /* natural_size */, base::TimeDelta() /* timestamp */);
1264 if (!new_frame) 1171 if (!new_frame)
1265 return; 1172 return;
1266 SetCurrentFrameInternal(new_frame); 1173 SetCurrentFrameInternal(new_frame);
1267 } 1174 }
1268 1175
1269 void WebMediaPlayerAndroid::ReallocateVideoFrame() { 1176 void WebMediaPlayerAndroid::ReallocateVideoFrame() {
1270 DCHECK(main_thread_checker_.CalledOnValidThread()); 1177 DCHECK(main_thread_checker_.CalledOnValidThread());
1271 if (needs_external_surface_) { 1178 if (needs_external_surface_) {
1272 // VideoFrame::CreateHoleFrame is only defined under VIDEO_HOLE. 1179 // VideoFrame::CreateHoleFrame is only defined under VIDEO_HOLE.
1273 #if defined(VIDEO_HOLE) 1180 #if defined(VIDEO_HOLE)
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; 1867 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER;
1961 } else if (is_hls_url == is_hls) { 1868 } else if (is_hls_url == is_hls) {
1962 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; 1869 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER;
1963 } 1870 }
1964 UMA_HISTOGRAM_ENUMERATION( 1871 UMA_HISTOGRAM_ENUMERATION(
1965 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", 1872 "Media.Android.IsHttpLiveStreamingMediaPredictionResult",
1966 result, PREDICTION_RESULT_MAX); 1873 result, PREDICTION_RESULT_MAX);
1967 } 1874 }
1968 1875
1969 } // namespace content 1876 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698