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

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

Issue 2339193002: Wip - cl for implemening VideoTrackSource::ApplyConstraints(constraints, VideoTrack) and adopt safe…
Patch Set: Created 4 years, 3 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/canvas_capture_handler.h" 5 #include "content/renderer/media/canvas_capture_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 const media::VideoCapturerSource::VideoCaptureDeliverFrameCB 114 const media::VideoCapturerSource::VideoCaptureDeliverFrameCB
115 new_frame_callback_; 115 new_frame_callback_;
116 // Bound to IO thread. 116 // Bound to IO thread.
117 base::ThreadChecker io_thread_checker_; 117 base::ThreadChecker io_thread_checker_;
118 base::WeakPtrFactory<CanvasCaptureHandlerDelegate> weak_ptr_factory_; 118 base::WeakPtrFactory<CanvasCaptureHandlerDelegate> weak_ptr_factory_;
119 119
120 DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandlerDelegate); 120 DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandlerDelegate);
121 }; 121 };
122 122
123 CanvasCaptureHandler::CanvasCaptureHandler( 123 CanvasCaptureHandler::CanvasCaptureHandler(
124 const blink::WebSize& size, 124 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
125 double frame_rate,
126 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
127 blink::WebMediaStreamTrack* track)
128 : ask_for_new_frame_(false), 125 : ask_for_new_frame_(false),
129 size_(size),
130 io_task_runner_(io_task_runner), 126 io_task_runner_(io_task_runner),
131 weak_ptr_factory_(this) { 127 weak_ptr_factory_(this) {
132 std::unique_ptr<media::VideoCapturerSource> video_source(
133 new VideoCapturerSource(weak_ptr_factory_.GetWeakPtr(), frame_rate));
134 AddVideoCapturerSourceToVideoTrack(std::move(video_source), track);
135 } 128 }
136 129
137 CanvasCaptureHandler::~CanvasCaptureHandler() { 130 CanvasCaptureHandler::~CanvasCaptureHandler() {
138 DVLOG(3) << __func__; 131 DVLOG(3) << __func__;
139 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 132 DCHECK(main_render_thread_checker_.CalledOnValidThread());
140 io_task_runner_->DeleteSoon(FROM_HERE, delegate_.release()); 133 io_task_runner_->DeleteSoon(FROM_HERE, delegate_.release());
141 } 134 }
142 135
143 // static 136 // static
144 CanvasCaptureHandler* CanvasCaptureHandler::CreateCanvasCaptureHandler( 137 CanvasCaptureHandler* CanvasCaptureHandler::CreateCanvasCaptureHandler(
145 const blink::WebSize& size, 138 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) {
146 double frame_rate,
147 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
148 blink::WebMediaStreamTrack* track) {
149 // Save histogram data so we can see how much CanvasCapture is used. 139 // Save histogram data so we can see how much CanvasCapture is used.
150 // The histogram counts the number of calls to the JS API. 140 // The histogram counts the number of calls to the JS API.
151 UpdateWebRTCMethodCount(WEBKIT_CANVAS_CAPTURE_STREAM); 141 UpdateWebRTCMethodCount(WEBKIT_CANVAS_CAPTURE_STREAM);
152 142
153 return new CanvasCaptureHandler(size, frame_rate, io_task_runner, track); 143 return new CanvasCaptureHandler(io_task_runner);
144 }
145
146 blink::WebMediaStreamTrack CanvasCaptureHandler::createTrack(
147 const blink::WebSize& size, double frame_rate) {
148 DCHECK(main_render_thread_checker_.CalledOnValidThread());
149 size_ = size;
150 std::unique_ptr<media::VideoCapturerSource> video_source(
151 new VideoCapturerSource(weak_ptr_factory_.GetWeakPtr(), frame_rate));
152 std::string str_track_id;
153 base::Base64Encode(base::RandBytesAsString(64), &str_track_id);
154 const blink::WebString track_id = base::UTF8ToUTF16(str_track_id);
155 blink::WebMediaStreamSource webkit_source;
156 std::unique_ptr<MediaStreamVideoSource> media_stream_source(
157 new MediaStreamVideoCapturerSource(
158 MediaStreamSource::SourceStoppedCallback(), std::move(video_source)));
159 webkit_source.initialize(track_id, blink::WebMediaStreamSource::TypeVideo,
160 track_id, false);
161 webkit_source.setExtraData(media_stream_source.get());
162 return MediaStreamVideoTrack::CreateVideoTrack(media_stream_source.release());
154 } 163 }
155 164
156 void CanvasCaptureHandler::sendNewFrame(const SkImage* image) { 165 void CanvasCaptureHandler::sendNewFrame(const SkImage* image) {
157 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 166 DCHECK(main_render_thread_checker_.CalledOnValidThread());
158 CreateNewFrame(image); 167 CreateNewFrame(image);
159 } 168 }
160 169
161 bool CanvasCaptureHandler::needsNewFrame() const { 170 bool CanvasCaptureHandler::needsNewFrame() const {
162 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 171 DCHECK(main_render_thread_checker_.CalledOnValidThread());
163 return ask_for_new_frame_; 172 return ask_for_new_frame_;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 size.width(), size.height()); 253 size.width(), size.height());
245 } 254 }
246 255
247 last_frame_ = video_frame; 256 last_frame_ = video_frame;
248 io_task_runner_->PostTask( 257 io_task_runner_->PostTask(
249 FROM_HERE, 258 FROM_HERE,
250 base::Bind(&CanvasCaptureHandler::CanvasCaptureHandlerDelegate:: 259 base::Bind(&CanvasCaptureHandler::CanvasCaptureHandlerDelegate::
251 SendNewFrameOnIOThread, 260 SendNewFrameOnIOThread,
252 delegate_->GetWeakPtrForIOThread(), video_frame, timestamp)); 261 delegate_->GetWeakPtrForIOThread(), video_frame, timestamp));
253 } 262 }
254
255 void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack(
256 std::unique_ptr<media::VideoCapturerSource> source,
257 blink::WebMediaStreamTrack* web_track) {
258 std::string str_track_id;
259 base::Base64Encode(base::RandBytesAsString(64), &str_track_id);
260 const blink::WebString track_id = base::UTF8ToUTF16(str_track_id);
261 blink::WebMediaStreamSource webkit_source;
262 std::unique_ptr<MediaStreamVideoSource> media_stream_source(
263 new MediaStreamVideoCapturerSource(
264 MediaStreamSource::SourceStoppedCallback(), std::move(source)));
265 webkit_source.initialize(track_id, blink::WebMediaStreamSource::TypeVideo,
266 track_id, false);
267 webkit_source.setExtraData(media_stream_source.get());
268
269 web_track->initialize(webkit_source);
270 blink::WebMediaConstraints constraints;
271 constraints.initialize();
272 web_track->setTrackData(new MediaStreamVideoTrack(
273 media_stream_source.release(), constraints,
274 MediaStreamVideoSource::ConstraintsCallback(), true));
275 }
276
277 } // namespace content 263 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/canvas_capture_handler.h ('k') | content/renderer/media/media_stream_audio_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698