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

Side by Side Diff: content/renderer/media/webmediaplayer_ms_compositor.cc

Issue 1815033003: Add srcObject attribute of type MediaStream to HTMLMediaElement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: philipj's comments Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/webmediaplayer_ms_compositor.h" 5 #include "content/renderer/media/webmediaplayer_ms_compositor.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/hash.h" 11 #include "base/hash.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "cc/blink/context_provider_web_context.h" 14 #include "cc/blink/context_provider_web_context.h"
14 #include "content/renderer/media/webmediaplayer_ms.h" 15 #include "content/renderer/media/webmediaplayer_ms.h"
15 #include "content/renderer/render_thread_impl.h" 16 #include "content/renderer/render_thread_impl.h"
16 #include "media/base/media_switches.h" 17 #include "media/base/media_switches.h"
17 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
18 #include "media/base/video_util.h" 19 #include "media/base/video_util.h"
19 #include "media/filters/video_renderer_algorithm.h" 20 #include "media/filters/video_renderer_algorithm.h"
20 #include "media/renderers/skcanvas_video_renderer.h" 21 #include "media/renderers/skcanvas_video_renderer.h"
21 #include "skia/ext/platform_canvas.h" 22 #include "skia/ext/platform_canvas.h"
22 #include "third_party/WebKit/public/platform/WebMediaStream.h" 23 #include "third_party/WebKit/public/platform/WebMediaStream.h"
23 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 24 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 25 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
25 #include "third_party/WebKit/public/platform/WebURL.h"
26 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h"
27 #include "third_party/libyuv/include/libyuv/convert.h" 26 #include "third_party/libyuv/include/libyuv/convert.h"
28 #include "third_party/libyuv/include/libyuv/video_common.h" 27 #include "third_party/libyuv/include/libyuv/video_common.h"
29 28
30 namespace content { 29 namespace content {
31 30
32 namespace { 31 namespace {
33 32
34 // This function copies |frame| to a new I420 or YV12A media::VideoFrame. 33 // This function copies |frame| to a new I420 or YV12A media::VideoFrame.
35 scoped_refptr<media::VideoFrame> CopyFrame( 34 scoped_refptr<media::VideoFrame> CopyFrame(
36 const scoped_refptr<media::VideoFrame>& frame, 35 const scoped_refptr<media::VideoFrame>& frame,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 base::DictionaryValue original_metadata; 108 base::DictionaryValue original_metadata;
110 frame->metadata()->MergeInternalValuesInto(&original_metadata); 109 frame->metadata()->MergeInternalValuesInto(&original_metadata);
111 new_frame->metadata()->MergeInternalValuesFrom(original_metadata); 110 new_frame->metadata()->MergeInternalValuesFrom(original_metadata);
112 return new_frame; 111 return new_frame;
113 } 112 }
114 113
115 } // anonymous namespace 114 } // anonymous namespace
116 115
117 WebMediaPlayerMSCompositor::WebMediaPlayerMSCompositor( 116 WebMediaPlayerMSCompositor::WebMediaPlayerMSCompositor(
118 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, 117 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner,
119 const blink::WebURL& url, 118 const blink::WebMediaStream& web_stream,
120 const base::WeakPtr<WebMediaPlayerMS>& player) 119 const base::WeakPtr<WebMediaPlayerMS>& player)
121 : compositor_task_runner_(compositor_task_runner), 120 : compositor_task_runner_(compositor_task_runner),
122 player_(player), 121 player_(player),
123 video_frame_provider_client_(nullptr), 122 video_frame_provider_client_(nullptr),
124 current_frame_used_by_compositor_(false), 123 current_frame_used_by_compositor_(false),
125 last_render_length_(base::TimeDelta::FromSecondsD(1.0 / 60.0)), 124 last_render_length_(base::TimeDelta::FromSecondsD(1.0 / 60.0)),
126 total_frame_count_(0), 125 total_frame_count_(0),
127 dropped_frame_count_(0), 126 dropped_frame_count_(0),
128 stopped_(true), 127 stopped_(true),
129 weak_ptr_factory_(this) { 128 weak_ptr_factory_(this) {
130 main_message_loop_ = base::MessageLoop::current(); 129 main_message_loop_ = base::MessageLoop::current();
131 130
132 const blink::WebMediaStream web_stream(
133 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url));
134 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; 131 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
135 if (!web_stream.isNull()) 132 if (!web_stream.isNull())
136 web_stream.videoTracks(video_tracks); 133 web_stream.videoTracks(video_tracks);
137 134
138 const bool remote_video = 135 const bool remote_video =
139 video_tracks.size() && video_tracks[0].source().remote(); 136 video_tracks.size() && video_tracks[0].source().remote();
140 137
141 if (remote_video && 138 if (remote_video &&
142 !base::CommandLine::ForCurrentProcess()->HasSwitch( 139 !base::CommandLine::ForCurrentProcess()->HasSwitch(
143 switches::kDisableRTCSmoothnessAlgorithm)) { 140 switches::kDisableRTCSmoothnessAlgorithm)) {
144 base::AutoLock auto_lock(current_frame_lock_); 141 base::AutoLock auto_lock(current_frame_lock_);
145 rendering_frame_buffer_.reset(new media::VideoRendererAlgorithm( 142 rendering_frame_buffer_.reset(new media::VideoRendererAlgorithm(
146 base::Bind(&WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks, 143 base::Bind(&WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks,
147 base::Unretained(this)))); 144 base::Unretained(this))));
148 } 145 }
149 146
150 // Just for logging purpose. 147 // Just for logging purpose.
151 const uint32_t hash_value = base::Hash(url.string().utf8()); 148 std::string stream_id =
149 web_stream.isNull() ? std::string() : web_stream.id().utf8();
150 const uint32_t hash_value = base::Hash(stream_id);
152 serial_ = (hash_value << 1) | (remote_video ? 1 : 0); 151 serial_ = (hash_value << 1) | (remote_video ? 1 : 0);
153 } 152 }
154 153
155 WebMediaPlayerMSCompositor::~WebMediaPlayerMSCompositor() { 154 WebMediaPlayerMSCompositor::~WebMediaPlayerMSCompositor() {
156 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 155 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
157 if (video_frame_provider_client_) 156 if (video_frame_provider_client_)
158 video_frame_provider_client_->StopUsingProvider(); 157 video_frame_provider_client_->StopUsingProvider();
159 } 158 }
160 159
161 gfx::Size WebMediaPlayerMSCompositor::GetCurrentSize() { 160 gfx::Size WebMediaPlayerMSCompositor::GetCurrentSize() {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 413 }
415 414
416 if (!rendering_frame_buffer_) { 415 if (!rendering_frame_buffer_) {
417 rendering_frame_buffer_.reset(new media::VideoRendererAlgorithm( 416 rendering_frame_buffer_.reset(new media::VideoRendererAlgorithm(
418 base::Bind(&WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks, 417 base::Bind(&WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks,
419 base::Unretained(this)))); 418 base::Unretained(this))));
420 } 419 }
421 } 420 }
422 421
423 } // namespace content 422 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698