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

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

Issue 12084088: Renamed WebMediaStreamComponent and WebMediaStreamDescriptor to WebMediaStreamTrack & WebMediaStream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/media_stream_impl.h" 5 #include "content/renderer/media/media_stream_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "content/renderer/media/media_stream_extra_data.h" 13 #include "content/renderer/media/media_stream_extra_data.h"
14 #include "content/renderer/media/media_stream_source_extra_data.h" 14 #include "content/renderer/media/media_stream_source_extra_data.h"
15 #include "content/renderer/media/media_stream_dependency_factory.h" 15 #include "content/renderer/media/media_stream_dependency_factory.h"
16 #include "content/renderer/media/media_stream_dispatcher.h" 16 #include "content/renderer/media/media_stream_dispatcher.h"
17 #include "content/renderer/media/rtc_video_decoder.h" 17 #include "content/renderer/media/rtc_video_decoder.h"
18 #include "content/renderer/media/rtc_video_renderer.h" 18 #include "content/renderer/media/rtc_video_renderer.h"
19 #include "content/renderer/media/video_capture_impl_manager.h" 19 #include "content/renderer/media/video_capture_impl_manager.h"
20 #include "content/renderer/media/webrtc_audio_capturer.h" 20 #include "content/renderer/media/webrtc_audio_capturer.h"
21 #include "content/renderer/media/webrtc_audio_renderer.h" 21 #include "content/renderer/media/webrtc_audio_renderer.h"
22 #include "content/renderer/media/webrtc_local_audio_renderer.h" 22 #include "content/renderer/media/webrtc_local_audio_renderer.h"
23 #include "content/renderer/media/webrtc_uma_histograms.h" 23 #include "content/renderer/media/webrtc_uma_histograms.h"
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints .h" 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints .h"
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCompo nent.h"
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourc e.h" 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourc e.h"
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack .h"
27 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
32 #include "webkit/media/media_stream_audio_renderer.h" 32 #include "webkit/media/media_stream_audio_renderer.h"
33 33
34 namespace content { 34 namespace content {
35 namespace { 35 namespace {
36 36
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 webkit_sources[i].initialize( 87 webkit_sources[i].initialize(
88 UTF8ToUTF16(source_id), 88 UTF8ToUTF16(source_id),
89 type, 89 type,
90 UTF8ToUTF16(devices[i].device.name)); 90 UTF8ToUTF16(devices[i].device.name));
91 webkit_sources[i].setExtraData( 91 webkit_sources[i].setExtraData(
92 new content::MediaStreamSourceExtraData(devices[i])); 92 new content::MediaStreamSourceExtraData(devices[i]));
93 } 93 }
94 } 94 }
95 95
96 webrtc::MediaStreamInterface* GetNativeMediaStream( 96 webrtc::MediaStreamInterface* GetNativeMediaStream(
97 const WebKit::WebMediaStreamDescriptor& descriptor) { 97 const WebKit::WebMediaStream& descriptor) {
98 content::MediaStreamExtraData* extra_data = 98 content::MediaStreamExtraData* extra_data =
99 static_cast<content::MediaStreamExtraData*>(descriptor.extraData()); 99 static_cast<content::MediaStreamExtraData*>(descriptor.extraData());
100 if (!extra_data) 100 if (!extra_data)
101 return NULL; 101 return NULL;
102 webrtc::MediaStreamInterface* stream = extra_data->local_stream(); 102 webrtc::MediaStreamInterface* stream = extra_data->local_stream();
103 if (!stream) 103 if (!stream)
104 stream = extra_data->remote_stream(); 104 stream = extra_data->remote_stream();
105 return stream; 105 return stream;
106 } 106 }
107 107
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 DCHECK(CalledOnValidThread()); 193 DCHECK(CalledOnValidThread());
194 UserMediaRequestInfo* request = FindUserMediaRequestInfo(user_media_request); 194 UserMediaRequestInfo* request = FindUserMediaRequestInfo(user_media_request);
195 if (request) { 195 if (request) {
196 // We can't abort the stream generation process. 196 // We can't abort the stream generation process.
197 // Instead, erase the request. Once the stream is generated we will stop the 197 // Instead, erase the request. Once the stream is generated we will stop the
198 // stream if the request does not exist. 198 // stream if the request does not exist.
199 DeleteUserMediaRequestInfo(request); 199 DeleteUserMediaRequestInfo(request);
200 } 200 }
201 } 201 }
202 202
203 WebKit::WebMediaStreamDescriptor MediaStreamImpl::GetMediaStream( 203 WebKit::WebMediaStream MediaStreamImpl::GetMediaStream(
204 const GURL& url) { 204 const GURL& url) {
205 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); 205 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url);
206 } 206 }
207 207
208 bool MediaStreamImpl::IsMediaStream(const GURL& url) { 208 bool MediaStreamImpl::IsMediaStream(const GURL& url) {
209 return CheckMediaStream(url); 209 return CheckMediaStream(url);
210 } 210 }
211 211
212 // static 212 // static
213 bool MediaStreamImpl::CheckMediaStream(const GURL& url) { 213 bool MediaStreamImpl::CheckMediaStream(const GURL& url) {
214 WebKit::WebMediaStreamDescriptor descriptor( 214 WebKit::WebMediaStream descriptor(
215 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url)); 215 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url));
216 216
217 if (descriptor.isNull() || !descriptor.extraData()) 217 if (descriptor.isNull() || !descriptor.extraData())
218 return false; // This is not a valid stream. 218 return false; // This is not a valid stream.
219 219
220 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor); 220 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor);
221 return stream && 221 return stream &&
222 ((stream->video_tracks() && stream->video_tracks()->count() > 0) || 222 ((stream->video_tracks() && stream->video_tracks()->count() > 0) ||
223 (stream->audio_tracks() && stream->audio_tracks()->count() > 0)); 223 (stream->audio_tracks() && stream->audio_tracks()->count() > 0));
224 } 224 }
225 225
226 scoped_refptr<webkit_media::VideoFrameProvider> 226 scoped_refptr<webkit_media::VideoFrameProvider>
227 MediaStreamImpl::GetVideoFrameProvider( 227 MediaStreamImpl::GetVideoFrameProvider(
228 const GURL& url, 228 const GURL& url,
229 const base::Closure& error_cb, 229 const base::Closure& error_cb,
230 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { 230 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) {
231 DCHECK(CalledOnValidThread()); 231 DCHECK(CalledOnValidThread());
232 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); 232 WebKit::WebMediaStream descriptor(GetMediaStream(url));
233 233
234 if (descriptor.isNull() || !descriptor.extraData()) 234 if (descriptor.isNull() || !descriptor.extraData())
235 return NULL; // This is not a valid stream. 235 return NULL; // This is not a valid stream.
236 236
237 DVLOG(1) << "MediaStreamImpl::GetVideoFrameProvider stream:" 237 DVLOG(1) << "MediaStreamImpl::GetVideoFrameProvider stream:"
238 << UTF16ToUTF8(descriptor.label()); 238 << UTF16ToUTF8(descriptor.label());
239 239
240 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor); 240 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor);
241 if (stream) 241 if (stream)
242 return CreateVideoFrameProvider(stream, error_cb, repaint_cb); 242 return CreateVideoFrameProvider(stream, error_cb, repaint_cb);
243 NOTREACHED(); 243 NOTREACHED();
244 return NULL; 244 return NULL;
245 } 245 }
246 246
247 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( 247 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder(
248 const GURL& url, 248 const GURL& url,
249 const scoped_refptr<base::MessageLoopProxy>& message_loop) { 249 const scoped_refptr<base::MessageLoopProxy>& message_loop) {
250 DCHECK(CalledOnValidThread()); 250 DCHECK(CalledOnValidThread());
251 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); 251 WebKit::WebMediaStream descriptor(GetMediaStream(url));
252 252
253 if (descriptor.isNull() || !descriptor.extraData()) 253 if (descriptor.isNull() || !descriptor.extraData())
254 return NULL; // This is not a valid stream. 254 return NULL; // This is not a valid stream.
255 255
256 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:" 256 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:"
257 << UTF16ToUTF8(descriptor.label()); 257 << UTF16ToUTF8(descriptor.label());
258 258
259 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor); 259 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor);
260 if (stream) 260 if (stream)
261 return CreateVideoDecoder(stream, message_loop); 261 return CreateVideoDecoder(stream, message_loop);
262 NOTREACHED(); 262 NOTREACHED();
263 return NULL; 263 return NULL;
264 } 264 }
265 265
266 scoped_refptr<webkit_media::MediaStreamAudioRenderer> 266 scoped_refptr<webkit_media::MediaStreamAudioRenderer>
267 MediaStreamImpl::GetAudioRenderer(const GURL& url) { 267 MediaStreamImpl::GetAudioRenderer(const GURL& url) {
268 DCHECK(CalledOnValidThread()); 268 DCHECK(CalledOnValidThread());
269 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); 269 WebKit::WebMediaStream descriptor(GetMediaStream(url));
270 270
271 if (descriptor.isNull() || !descriptor.extraData()) 271 if (descriptor.isNull() || !descriptor.extraData())
272 return NULL; // This is not a valid stream. 272 return NULL; // This is not a valid stream.
273 273
274 DVLOG(1) << "MediaStreamImpl::GetAudioRenderer stream:" 274 DVLOG(1) << "MediaStreamImpl::GetAudioRenderer stream:"
275 << UTF16ToUTF8(descriptor.label()); 275 << UTF16ToUTF8(descriptor.label());
276 276
277 MediaStreamExtraData* extra_data = 277 MediaStreamExtraData* extra_data =
278 static_cast<MediaStreamExtraData*>(descriptor.extraData()); 278 static_cast<MediaStreamExtraData*>(descriptor.extraData());
279 279
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 WebKit::WebMediaStreamSource::TypeAudio, 327 WebKit::WebMediaStreamSource::TypeAudio,
328 audio_source_vector); 328 audio_source_vector);
329 WebKit::WebVector<WebKit::WebMediaStreamSource> video_source_vector( 329 WebKit::WebVector<WebKit::WebMediaStreamSource> video_source_vector(
330 video_array.size()); 330 video_array.size());
331 CreateWebKitSourceVector(label, video_array, 331 CreateWebKitSourceVector(label, video_array,
332 WebKit::WebMediaStreamSource::TypeVideo, 332 WebKit::WebMediaStreamSource::TypeVideo,
333 video_source_vector); 333 video_source_vector);
334 334
335 WebKit::WebUserMediaRequest* request = &(request_info->request); 335 WebKit::WebUserMediaRequest* request = &(request_info->request);
336 WebKit::WebString webkit_label = UTF8ToUTF16(label); 336 WebKit::WebString webkit_label = UTF8ToUTF16(label);
337 WebKit::WebMediaStreamDescriptor* description = &(request_info->descriptor); 337 WebKit::WebMediaStream* description = &(request_info->descriptor);
338 338
339 description->initialize(webkit_label, audio_source_vector, 339 description->initialize(webkit_label, audio_source_vector,
340 video_source_vector); 340 video_source_vector);
341 341
342 // WebUserMediaRequest don't have an implementation in unit tests. 342 // WebUserMediaRequest don't have an implementation in unit tests.
343 // Therefore we need to check for isNull here. 343 // Therefore we need to check for isNull here.
344 WebKit::WebMediaConstraints audio_constraints = request->isNull() ? 344 WebKit::WebMediaConstraints audio_constraints = request->isNull() ?
345 WebKit::WebMediaConstraints() : request->audioConstraints(); 345 WebKit::WebMediaConstraints() : request->audioConstraints();
346 WebKit::WebMediaConstraints video_constraints = request->isNull() ? 346 WebKit::WebMediaConstraints video_constraints = request->isNull() ?
347 WebKit::WebMediaConstraints() : request->videoConstraints(); 347 WebKit::WebMediaConstraints() : request->videoConstraints();
(...skipping 18 matching lines...) Expand all
366 } 366 }
367 CompleteGetUserMediaRequest(request_info->descriptor, 367 CompleteGetUserMediaRequest(request_info->descriptor,
368 &request_info->request, 368 &request_info->request,
369 false); 369 false);
370 DeleteUserMediaRequestInfo(request_info); 370 DeleteUserMediaRequestInfo(request_info);
371 } 371 }
372 372
373 // Callback from MediaStreamDependencyFactory when the sources in |description| 373 // Callback from MediaStreamDependencyFactory when the sources in |description|
374 // have been generated. 374 // have been generated.
375 void MediaStreamImpl::OnCreateNativeSourcesComplete( 375 void MediaStreamImpl::OnCreateNativeSourcesComplete(
376 WebKit::WebMediaStreamDescriptor* description, 376 WebKit::WebMediaStream* description,
377 bool request_succeeded) { 377 bool request_succeeded) {
378 DVLOG(1) << "MediaStreamImpl::OnCreateNativeSourcesComplete stream:" 378 DVLOG(1) << "MediaStreamImpl::OnCreateNativeSourcesComplete stream:"
379 << UTF16ToUTF8(description->label()); 379 << UTF16ToUTF8(description->label());
380 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(description); 380 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(description);
381 if (!request_info) { 381 if (!request_info) {
382 // This can happen if the request is canceled or the frame reloads while 382 // This can happen if the request is canceled or the frame reloads while
383 // MediaStreamDependencyFactory is creating the sources. 383 // MediaStreamDependencyFactory is creating the sources.
384 DVLOG(1) << "Request ID not found"; 384 DVLOG(1) << "Request ID not found";
385 return; 385 return;
386 } 386 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 NOTIMPLEMENTED(); 421 NOTIMPLEMENTED();
422 } 422 }
423 423
424 void MediaStreamImpl::OnDeviceOpenFailed(int request_id) { 424 void MediaStreamImpl::OnDeviceOpenFailed(int request_id) {
425 DVLOG(1) << "MediaStreamImpl::VideoDeviceOpenFailed(" 425 DVLOG(1) << "MediaStreamImpl::VideoDeviceOpenFailed("
426 << request_id << ")"; 426 << request_id << ")";
427 NOTIMPLEMENTED(); 427 NOTIMPLEMENTED();
428 } 428 }
429 429
430 void MediaStreamImpl::CompleteGetUserMediaRequest( 430 void MediaStreamImpl::CompleteGetUserMediaRequest(
431 const WebKit::WebMediaStreamDescriptor& stream, 431 const WebKit::WebMediaStream& stream,
432 WebKit::WebUserMediaRequest* request_info, 432 WebKit::WebUserMediaRequest* request_info,
433 bool request_succeeded) { 433 bool request_succeeded) {
434 if (request_succeeded) { 434 if (request_succeeded) {
435 request_info->requestSucceeded(stream); 435 request_info->requestSucceeded(stream);
436 } else { 436 } else {
437 request_info->requestFailed(); 437 request_info->requestFailed();
438 } 438 }
439 } 439 }
440 440
441 MediaStreamImpl::UserMediaRequestInfo* 441 MediaStreamImpl::UserMediaRequestInfo*
(...skipping 22 matching lines...) Expand all
464 UserMediaRequests::iterator it = user_media_requests_.begin(); 464 UserMediaRequests::iterator it = user_media_requests_.begin();
465 for (; it != user_media_requests_.end(); ++it) { 465 for (; it != user_media_requests_.end(); ++it) {
466 if ((*it)->generated && (*it)->descriptor.label() == UTF8ToUTF16(label)) 466 if ((*it)->generated && (*it)->descriptor.label() == UTF8ToUTF16(label))
467 return (*it); 467 return (*it);
468 } 468 }
469 return NULL; 469 return NULL;
470 } 470 }
471 471
472 MediaStreamImpl::UserMediaRequestInfo* 472 MediaStreamImpl::UserMediaRequestInfo*
473 MediaStreamImpl::FindUserMediaRequestInfo( 473 MediaStreamImpl::FindUserMediaRequestInfo(
474 WebKit::WebMediaStreamDescriptor* descriptor) { 474 WebKit::WebMediaStream* descriptor) {
475 UserMediaRequests::iterator it = user_media_requests_.begin(); 475 UserMediaRequests::iterator it = user_media_requests_.begin();
476 for (; it != user_media_requests_.end(); ++it) { 476 for (; it != user_media_requests_.end(); ++it) {
477 if (&((*it)->descriptor) == descriptor) 477 if (&((*it)->descriptor) == descriptor)
478 return (*it); 478 return (*it);
479 } 479 }
480 return NULL; 480 return NULL;
481 } 481 }
482 482
483 void MediaStreamImpl::DeleteUserMediaRequestInfo( 483 void MediaStreamImpl::DeleteUserMediaRequestInfo(
484 UserMediaRequestInfo* request) { 484 UserMediaRequestInfo* request) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 const StreamStopCallback& stop_callback) { 611 const StreamStopCallback& stop_callback) {
612 stream_stop_callback_ = stop_callback; 612 stream_stop_callback_ = stop_callback;
613 } 613 }
614 614
615 void MediaStreamExtraData::OnLocalStreamStop() { 615 void MediaStreamExtraData::OnLocalStreamStop() {
616 if (!stream_stop_callback_.is_null()) 616 if (!stream_stop_callback_.is_null())
617 stream_stop_callback_.Run(local_stream_->label()); 617 stream_stop_callback_.Run(local_stream_->label());
618 } 618 }
619 619
620 } // namespace content 620 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_impl.h ('k') | content/renderer/media/media_stream_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698