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

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

Powered by Google App Engine
This is Rietveld 408576698