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

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

Issue 1505013002: Create CanvasCaptureMediaStreamTrack in a regular MediaStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits. Created 5 years 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 "base/base64.h"
7 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
8 #include "content/public/renderer/media_stream_api.h" 9 #include "base/rand_util.h"
10 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/renderer/render_thread.h" 11 #include "content/public/renderer/render_thread.h"
12 #include "content/renderer/media/media_stream_video_capturer_source.h"
13 #include "content/renderer/media/media_stream_video_source.h"
14 #include "content/renderer/media/media_stream_video_track.h"
10 #include "content/renderer/render_thread_impl.h" 15 #include "content/renderer/render_thread_impl.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
17 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/libyuv/include/libyuv.h" 18 #include "third_party/libyuv/include/libyuv.h"
12 19
13 namespace content { 20 namespace content {
14 21
15 class CanvasCaptureHandler::VideoCapturerSource 22 class CanvasCaptureHandler::VideoCapturerSource
16 : public media::VideoCapturerSource { 23 : public media::VideoCapturerSource {
17 public: 24 public:
18 explicit VideoCapturerSource(base::WeakPtr<CanvasCaptureHandler> 25 explicit VideoCapturerSource(base::WeakPtr<CanvasCaptureHandler>
19 canvas_handler, 26 canvas_handler,
20 double frame_rate) 27 double frame_rate)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 const media::VideoCapturerSource::VideoCaptureDeliverFrameCB 86 const media::VideoCapturerSource::VideoCaptureDeliverFrameCB
80 new_frame_callback_; 87 new_frame_callback_;
81 base::ThreadChecker thread_checker_; 88 base::ThreadChecker thread_checker_;
82 base::WeakPtrFactory<CanvasCaptureHandlerDelegate> weak_ptr_factory_; 89 base::WeakPtrFactory<CanvasCaptureHandlerDelegate> weak_ptr_factory_;
83 90
84 DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandlerDelegate); 91 DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandlerDelegate);
85 }; 92 };
86 93
87 CanvasCaptureHandler::CanvasCaptureHandler(const blink::WebSize& size, 94 CanvasCaptureHandler::CanvasCaptureHandler(const blink::WebSize& size,
88 double frame_rate, 95 double frame_rate,
89 blink::WebMediaStream* stream) 96 blink::WebMediaStreamTrack* track)
90 : ask_for_new_frame_(false), 97 : ask_for_new_frame_(false),
91 size_(size), 98 size_(size),
92 io_task_runner_(content::RenderThread::Get()->GetIOMessageLoopProxy()), 99 io_task_runner_(content::RenderThread::Get()->GetIOMessageLoopProxy()),
93 weak_ptr_factory_(this) { 100 weak_ptr_factory_(this) {
94 scoped_ptr<media::VideoCapturerSource> video_source( 101 scoped_ptr<media::VideoCapturerSource> video_source(
95 new CanvasCaptureHandler::VideoCapturerSource( 102 new CanvasCaptureHandler::VideoCapturerSource(
96 weak_ptr_factory_.GetWeakPtr(), frame_rate)); 103 weak_ptr_factory_.GetWeakPtr(), frame_rate));
97 content::AddVideoTrackToMediaStream(video_source.Pass(), false, true, stream); 104 AddVideoCapturerSourceToVideoTrack(video_source.Pass(), track);
98 } 105 }
99 106
100 CanvasCaptureHandler::~CanvasCaptureHandler() { 107 CanvasCaptureHandler::~CanvasCaptureHandler() {
101 DVLOG(3) << __FUNCTION__; 108 DVLOG(3) << __FUNCTION__;
102 DCHECK(thread_checker_.CalledOnValidThread()); 109 DCHECK(thread_checker_.CalledOnValidThread());
103 io_task_runner_->DeleteSoon(FROM_HERE, delegate_.release()); 110 io_task_runner_->DeleteSoon(FROM_HERE, delegate_.release());
104 } 111 }
105 112
106 void CanvasCaptureHandler::sendNewFrame(const blink::WebSkImage& image) { 113 void CanvasCaptureHandler::sendNewFrame(const blink::WebSkImage& image) {
107 DCHECK(thread_checker_.CalledOnValidThread()); 114 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 size.width(), size.height()); 175 size.width(), size.height());
169 176
170 io_task_runner_->PostTask( 177 io_task_runner_->PostTask(
171 FROM_HERE, 178 FROM_HERE,
172 base::Bind(&CanvasCaptureHandler::CanvasCaptureHandlerDelegate:: 179 base::Bind(&CanvasCaptureHandler::CanvasCaptureHandlerDelegate::
173 SendNewFrameOnIOThread, 180 SendNewFrameOnIOThread,
174 delegate_->GetWeakPtrForIOThread(), video_frame, 181 delegate_->GetWeakPtrForIOThread(), video_frame,
175 base::TimeTicks())); 182 base::TimeTicks()));
176 } 183 }
177 184
185 void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack(
186 scoped_ptr<media::VideoCapturerSource> source,
187 blink::WebMediaStreamTrack* web_track) {
188 std::string str_track_id;
189 base::Base64Encode(base::RandBytesAsString(64), &str_track_id);
190 const blink::WebString track_id = base::UTF8ToUTF16(str_track_id);
191 blink::WebMediaStreamSource webkit_source;
192 scoped_ptr<MediaStreamVideoSource> media_stream_source(
193 new MediaStreamVideoCapturerSource(
194 MediaStreamSource::SourceStoppedCallback(), source.Pass()));
195 webkit_source.initialize(track_id, blink::WebMediaStreamSource::TypeVideo,
196 track_id, false, true);
197 webkit_source.setExtraData(media_stream_source.get());
198
199 web_track->initialize(webkit_source);
200 blink::WebMediaConstraints constraints;
201 constraints.initialize();
202 web_track->setExtraData(new MediaStreamVideoTrack(
203 media_stream_source.release(), constraints,
204 MediaStreamVideoSource::ConstraintsCallback(), true));
205 }
206
178 } // namespace content 207 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698