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

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: 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 27 matching lines...) Expand all
38 #include "media/base/android/media_player_android.h" 38 #include "media/base/android/media_player_android.h"
39 #include "media/base/bind_to_current_loop.h" 39 #include "media/base/bind_to_current_loop.h"
40 #include "media/base/cdm_context.h" 40 #include "media/base/cdm_context.h"
41 #include "media/base/key_systems.h" 41 #include "media/base/key_systems.h"
42 #include "media/base/media_keys.h" 42 #include "media/base/media_keys.h"
43 #include "media/base/media_log.h" 43 #include "media/base/media_log.h"
44 #include "media/base/media_switches.h" 44 #include "media/base/media_switches.h"
45 #include "media/base/timestamp_constants.h" 45 #include "media/base/timestamp_constants.h"
46 #include "media/base/video_frame.h" 46 #include "media/base/video_frame.h"
47 #include "media/blink/webcontentdecryptionmodule_impl.h" 47 #include "media/blink/webcontentdecryptionmodule_impl.h"
48 #include "media/blink/webmediaplayer_cast_android.h"
48 #include "media/blink/webmediaplayer_delegate.h" 49 #include "media/blink/webmediaplayer_delegate.h"
49 #include "media/blink/webmediaplayer_util.h" 50 #include "media/blink/webmediaplayer_util.h"
50 #include "net/base/mime_util.h" 51 #include "net/base/mime_util.h"
51 #include "third_party/WebKit/public/platform/Platform.h" 52 #include "third_party/WebKit/public/platform/Platform.h"
52 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" 53 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
53 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" 54 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h"
54 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" 55 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h"
55 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" 56 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
56 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h" 57 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h"
57 #include "third_party/WebKit/public/platform/WebString.h" 58 #include "third_party/WebKit/public/platform/WebString.h"
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 // there seems no easy way to listen for the layer resizing (as opposed to 1151 // there seems no easy way to listen for the layer resizing (as opposed to
1151 // OnVideoSizeChanged, which is when the frame sizes of the video file 1152 // OnVideoSizeChanged, which is when the frame sizes of the video file
1152 // change). Perhaps have to poll (on main thread of course)? 1153 // change). Perhaps have to poll (on main thread of course)?
1153 gfx::Size video_size_css_px = video_weblayer_->bounds(); 1154 gfx::Size video_size_css_px = video_weblayer_->bounds();
1154 float device_scale_factor = frame_->view()->deviceScaleFactor(); 1155 float device_scale_factor = frame_->view()->deviceScaleFactor();
1155 // canvas_size will be the size in device pixels when pageScaleFactor == 1 1156 // canvas_size will be the size in device pixels when pageScaleFactor == 1
1156 gfx::Size canvas_size( 1157 gfx::Size canvas_size(
1157 static_cast<int>(video_size_css_px.width() * device_scale_factor), 1158 static_cast<int>(video_size_css_px.width() * device_scale_factor),
1158 static_cast<int>(video_size_css_px.height() * device_scale_factor)); 1159 static_cast<int>(video_size_css_px.height() * device_scale_factor));
1159 1160
1160 SkBitmap bitmap; 1161 scoped_refptr<VideoFrame> new_frame(
1161 bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height()); 1162 media::WebMediaPlayerCast::MakeTextFrameForCast(
1162 1163 remote_playback_message,
1163 // Create the canvas and draw the "Casting to <Chromecast>" text on it. 1164 canvas_size,
1164 SkCanvas canvas(bitmap); 1165 base::Bind(&StreamTextureFactory::ContextGL,
1165 canvas.drawColor(SK_ColorBLACK); 1166 stream_texture_factory_)));
1166
1167 const SkScalar kTextSize(40);
1168 const SkScalar kMinPadding(40);
1169
1170 SkPaint paint;
1171 paint.setAntiAlias(true);
1172 paint.setFilterQuality(kHigh_SkFilterQuality);
1173 paint.setColor(SK_ColorWHITE);
1174 paint.setTypeface(SkTypeface::CreateFromName("sans", SkTypeface::kBold));
1175 paint.setTextSize(kTextSize);
1176
1177 // Calculate the vertical margin from the top
1178 SkPaint::FontMetrics font_metrics;
1179 paint.getFontMetrics(&font_metrics);
1180 SkScalar sk_vertical_margin = kMinPadding - font_metrics.fAscent;
1181
1182 // Measure the width of the entire text to display
1183 size_t display_text_width = paint.measureText(
1184 remote_playback_message.c_str(), remote_playback_message.size());
1185 std::string display_text(remote_playback_message);
1186
1187 if (display_text_width + (kMinPadding * 2) > canvas_size.width()) {
1188 // The text is too long to fit in one line, truncate it and append ellipsis
1189 // to the end.
1190
1191 // First, figure out how much of the canvas the '...' will take up.
1192 const std::string kTruncationEllipsis("\xE2\x80\xA6");
1193 SkScalar sk_ellipse_width = paint.measureText(
1194 kTruncationEllipsis.c_str(), kTruncationEllipsis.size());
1195
1196 // Then calculate how much of the text can be drawn with the '...' appended
1197 // to the end of the string.
1198 SkScalar sk_max_original_text_width(
1199 canvas_size.width() - (kMinPadding * 2) - sk_ellipse_width);
1200 size_t sk_max_original_text_length = paint.breakText(
1201 remote_playback_message.c_str(),
1202 remote_playback_message.size(),
1203 sk_max_original_text_width);
1204
1205 // Remove the part of the string that doesn't fit and append '...'.
1206 display_text.erase(sk_max_original_text_length,
1207 remote_playback_message.size() - sk_max_original_text_length);
1208 display_text.append(kTruncationEllipsis);
1209 display_text_width = paint.measureText(
1210 display_text.c_str(), display_text.size());
1211 }
1212
1213 // Center the text horizontally.
1214 SkScalar sk_horizontal_margin =
1215 (canvas_size.width() - display_text_width) / 2.0;
1216 canvas.drawText(display_text.c_str(),
1217 display_text.size(),
1218 sk_horizontal_margin,
1219 sk_vertical_margin,
1220 paint);
1221
1222 GLES2Interface* gl = stream_texture_factory_->ContextGL();
1223 GLuint remote_playback_texture_id = 0;
1224 gl->GenTextures(1, &remote_playback_texture_id);
1225 GLuint texture_target = GL_TEXTURE_2D;
1226 gl->BindTexture(texture_target, remote_playback_texture_id);
1227 gl->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1228 gl->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1229 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1230 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1231
1232 {
1233 SkAutoLockPixels lock(bitmap);
1234 gl->TexImage2D(texture_target,
1235 0 /* level */,
1236 GL_RGBA /* internalformat */,
1237 bitmap.width(),
1238 bitmap.height(),
1239 0 /* border */,
1240 GL_RGBA /* format */,
1241 GL_UNSIGNED_BYTE /* type */,
1242 bitmap.getPixels());
1243 }
1244
1245 gpu::Mailbox texture_mailbox;
1246 gl->GenMailboxCHROMIUM(texture_mailbox.name);
1247 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox.name);
1248 gl->Flush();
1249 gpu::SyncToken texture_mailbox_sync_token(gl->InsertSyncPointCHROMIUM());
1250
1251 scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture(
1252 media::PIXEL_FORMAT_ARGB,
1253 gpu::MailboxHolder(texture_mailbox, texture_mailbox_sync_token,
1254 texture_target),
1255 media::BindToCurrentLoop(base::Bind(&OnReleaseTexture,
1256 stream_texture_factory_,
1257 remote_playback_texture_id)),
1258 canvas_size /* coded_size */, gfx::Rect(canvas_size) /* visible_rect */,
1259 canvas_size /* natural_size */, base::TimeDelta() /* timestamp */);
1260 SetCurrentFrameInternal(new_frame); 1167 SetCurrentFrameInternal(new_frame);
1261 } 1168 }
1262 1169
1263 void WebMediaPlayerAndroid::ReallocateVideoFrame() { 1170 void WebMediaPlayerAndroid::ReallocateVideoFrame() {
1264 DCHECK(main_thread_checker_.CalledOnValidThread()); 1171 DCHECK(main_thread_checker_.CalledOnValidThread());
1265 if (needs_external_surface_) { 1172 if (needs_external_surface_) {
1266 // VideoFrame::CreateHoleFrame is only defined under VIDEO_HOLE. 1173 // VideoFrame::CreateHoleFrame is only defined under VIDEO_HOLE.
1267 #if defined(VIDEO_HOLE) 1174 #if defined(VIDEO_HOLE)
1268 if (!natural_size_.isEmpty()) { 1175 if (!natural_size_.isEmpty()) {
1269 // Now we finally know that "stream texture" and "video frame" won't 1176 // Now we finally know that "stream texture" and "video frame" won't
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; 1881 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER;
1975 } else if (is_hls_url == is_hls) { 1882 } else if (is_hls_url == is_hls) {
1976 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; 1883 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER;
1977 } 1884 }
1978 UMA_HISTOGRAM_ENUMERATION( 1885 UMA_HISTOGRAM_ENUMERATION(
1979 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", 1886 "Media.Android.IsHttpLiveStreamingMediaPredictionResult",
1980 result, PREDICTION_RESULT_MAX); 1887 result, PREDICTION_RESULT_MAX);
1981 } 1888 }
1982 1889
1983 } // namespace content 1890 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698