| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_video_source.h" | 5 #include "content/renderer/media/media_stream_video_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "content/renderer/media/media_stream_dependency_factory.h" | 13 #include "content/renderer/media/media_stream_dependency_factory.h" |
| 14 #include "content/renderer/media/media_stream_video_track.h" | 14 #include "content/renderer/media/media_stream_video_track.h" |
| 15 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" | 15 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 // Constraint keys. Specified by draft-alvestrand-constraints-resolution-00b | 19 // Constraint keys. Specified by draft-alvestrand-constraints-resolution-00b |
| 20 const char MediaStreamVideoSource::kMinAspectRatio[] = "minAspectRatio"; | 20 const char MediaStreamVideoSource::kMinAspectRatio[] = "minAspectRatio"; |
| 21 const char MediaStreamVideoSource::kMaxAspectRatio[] = "maxAspectRatio"; | 21 const char MediaStreamVideoSource::kMaxAspectRatio[] = "maxAspectRatio"; |
| 22 const char MediaStreamVideoSource::kMaxWidth[] = "maxWidth"; | 22 const char MediaStreamVideoSource::kMaxWidth[] = "maxWidth"; |
| 23 const char MediaStreamVideoSource::kMinWidth[] = "minWidth"; | 23 const char MediaStreamVideoSource::kMinWidth[] = "minWidth"; |
| 24 const char MediaStreamVideoSource::kMaxHeight[] = "maxHeight"; | 24 const char MediaStreamVideoSource::kMaxHeight[] = "maxHeight"; |
| 25 const char MediaStreamVideoSource::kMinHeight[] = "minHeight"; | 25 const char MediaStreamVideoSource::kMinHeight[] = "minHeight"; |
| 26 const char MediaStreamVideoSource::kMaxFrameRate[] = "maxFrameRate"; | 26 const char MediaStreamVideoSource::kMaxFrameRate[] = "maxFrameRate"; |
| 27 const char MediaStreamVideoSource::kMinFrameRate[] = "minFrameRate"; | 27 const char MediaStreamVideoSource::kMinFrameRate[] = "minFrameRate"; |
| 28 | 28 |
| 29 const char* kSupportedConstraints[] = { | 29 const char* kSupportedConstraints[] = { |
| 30 MediaStreamVideoSource::kMaxAspectRatio, | 30 MediaStreamVideoSource::kMaxAspectRatio, |
| 31 MediaStreamVideoSource::kMinAspectRatio, | 31 MediaStreamVideoSource::kMinAspectRatio, |
| 32 MediaStreamVideoSource::kMaxWidth, | 32 MediaStreamVideoSource::kMaxWidth, |
| 33 MediaStreamVideoSource::kMinWidth, | 33 MediaStreamVideoSource::kMinWidth, |
| 34 MediaStreamVideoSource::kMaxHeight, | 34 MediaStreamVideoSource::kMaxHeight, |
| 35 MediaStreamVideoSource::kMinHeight, | 35 MediaStreamVideoSource::kMinHeight, |
| 36 MediaStreamVideoSource::kMaxFrameRate, | 36 MediaStreamVideoSource::kMaxFrameRate, |
| 37 MediaStreamVideoSource::kMinFrameRate, | 37 MediaStreamVideoSource::kMinFrameRate, |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 const int MediaStreamVideoSource::kDefaultWidth = 640; | 40 const int MediaStreamVideoSource::kDefaultWidth = 640; |
| 41 const int MediaStreamVideoSource::kDefaultHeight = 480; | 41 const int MediaStreamVideoSource::kDefaultHeight = 480; |
| 42 const int MediaStreamVideoSource::kDefaultFrameRate = 30; | 42 const int MediaStreamVideoSource::kDefaultFrameRate = 30; |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 // Constraints keys for http://dev.w3.org/2011/webrtc/editor/getusermedia.html | 45 // Constraints keys for http://dev.w3.org/2011/webrtc/editor/getusermedia.html |
| 46 const char kSourceId[] = "sourceId"; | 46 const char kSourceId[] = "sourceId"; |
| 47 | 47 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 346 } |
| 347 case ENDED: | 347 case ENDED: |
| 348 case STARTED: { | 348 case STARTED: { |
| 349 // Currently, reconfiguring the source is not supported. | 349 // Currently, reconfiguring the source is not supported. |
| 350 FinalizeAddTrack(); | 350 FinalizeAddTrack(); |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 void MediaStreamVideoSource::RemoveTrack(MediaStreamVideoTrack* video_track) { | 355 void MediaStreamVideoSource::RemoveTrack(MediaStreamVideoTrack* video_track) { |
| 356 DCHECK(CalledOnValidThread()); |
| 356 std::vector<MediaStreamVideoTrack*>::iterator it = | 357 std::vector<MediaStreamVideoTrack*>::iterator it = |
| 357 std::find(tracks_.begin(), tracks_.end(), video_track); | 358 std::find(tracks_.begin(), tracks_.end(), video_track); |
| 358 DCHECK(it != tracks_.end()); | 359 DCHECK(it != tracks_.end()); |
| 359 tracks_.erase(it); | 360 tracks_.erase(it); |
| 361 if (tracks_.empty()) |
| 362 StopSource(); |
| 360 } | 363 } |
| 361 | 364 |
| 362 void MediaStreamVideoSource::InitAdapter() { | 365 void MediaStreamVideoSource::InitAdapter() { |
| 363 if (adapter_) | 366 if (adapter_) |
| 364 return; | 367 return; |
| 365 // Create the webrtc::MediaStreamVideoSourceInterface adapter. | 368 // Create the webrtc::MediaStreamVideoSourceInterface adapter. |
| 366 // It needs the constraints so that constraints used by a PeerConnection | 369 // It needs the constraints so that constraints used by a PeerConnection |
| 367 // will be available such as constraints for CPU adaptation and a tab | 370 // will be available such as constraints for CPU adaptation and a tab |
| 368 // capture. | 371 // capture. |
| 369 bool is_screencast = | 372 bool is_screencast = |
| 370 device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE || | 373 device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE || |
| 371 device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE; | 374 device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE; |
| 372 capture_adapter_ = factory_->CreateVideoCapturer(is_screencast); | 375 capture_adapter_ = factory_->CreateVideoCapturer(is_screencast); |
| 373 adapter_ = factory_->CreateVideoSource(capture_adapter_, | 376 adapter_ = factory_->CreateVideoSource(capture_adapter_, |
| 374 current_constraints_); | 377 current_constraints_); |
| 375 } | 378 } |
| 376 | 379 |
| 377 webrtc::VideoSourceInterface* MediaStreamVideoSource::GetAdapter() { | 380 webrtc::VideoSourceInterface* MediaStreamVideoSource::GetAdapter() { |
| 378 if (!adapter_) { | 381 if (!adapter_) { |
| 379 InitAdapter(); | 382 InitAdapter(); |
| 380 } | 383 } |
| 381 return adapter_; | 384 return adapter_; |
| 382 } | 385 } |
| 383 | 386 |
| 384 void MediaStreamVideoSource::DoStopSource() { | 387 void MediaStreamVideoSource::DoStopSource() { |
| 388 DCHECK(CalledOnValidThread()); |
| 385 DVLOG(3) << "DoStopSource()"; | 389 DVLOG(3) << "DoStopSource()"; |
| 386 StopSourceImpl(); | 390 StopSourceImpl(); |
| 387 state_ = ENDED; | 391 state_ = ENDED; |
| 388 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 392 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
| 389 } | 393 } |
| 390 | 394 |
| 391 void MediaStreamVideoSource::DeliverVideoFrame( | 395 void MediaStreamVideoSource::DeliverVideoFrame( |
| 392 const scoped_refptr<media::VideoFrame>& frame) { | 396 const scoped_refptr<media::VideoFrame>& frame) { |
| 393 DCHECK(CalledOnValidThread()); | 397 DCHECK(CalledOnValidThread()); |
| 394 scoped_refptr<media::VideoFrame> video_frame(frame); | 398 scoped_refptr<media::VideoFrame> video_frame(frame); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 MediaStreamVideoSource::RequestedConstraints::RequestedConstraints( | 533 MediaStreamVideoSource::RequestedConstraints::RequestedConstraints( |
| 530 const blink::WebMediaConstraints& constraints, | 534 const blink::WebMediaConstraints& constraints, |
| 531 const ConstraintsCallback& callback) | 535 const ConstraintsCallback& callback) |
| 532 : constraints(constraints), callback(callback) { | 536 : constraints(constraints), callback(callback) { |
| 533 } | 537 } |
| 534 | 538 |
| 535 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { | 539 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { |
| 536 } | 540 } |
| 537 | 541 |
| 538 } // namespace content | 542 } // namespace content |
| OLD | NEW |