| 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 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 MediaStreamVideoSource::MediaStreamVideoSource() | 307 MediaStreamVideoSource::MediaStreamVideoSource() |
| 308 : state_(NEW), | 308 : state_(NEW), |
| 309 track_adapter_( | 309 track_adapter_( |
| 310 new VideoTrackAdapter(ChildProcess::current()->io_task_runner())), | 310 new VideoTrackAdapter(ChildProcess::current()->io_task_runner())), |
| 311 weak_factory_(this) {} | 311 weak_factory_(this) {} |
| 312 | 312 |
| 313 MediaStreamVideoSource::~MediaStreamVideoSource() { | 313 MediaStreamVideoSource::~MediaStreamVideoSource() { |
| 314 DCHECK(CalledOnValidThread()); | 314 DCHECK(CalledOnValidThread()); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void MediaStreamVideoSource::AddTrack( | 317 bool MediaStreamVideoSource::ConnectToTrack( |
| 318 MediaStreamVideoTrack* track, | 318 const blink::WebMediaStreamTrack& blink_track) { |
| 319 const VideoCaptureDeliverFrameCB& frame_callback, | 319 DCHECK(CalledOnValidThread()); |
| 320 DCHECK(!blink_track.isNull()); |
| 321 |
| 322 // Sanity-check that there is not already a MediaStreamVideoTrack instance |
| 323 // associated with |blink_track|. |
| 324 if (MediaStreamVideoTrack::GetVideoTrack(blink_track)) { // rename ::From ? |
| 325 LOG(DFATAL) |
| 326 << "Attempting to connect another source to a WebMediaStreamTrack."; |
| 327 return false; |
| 328 } |
| 329 |
| 330 // Unless the source has already been permanently stopped, ensure it is |
| 331 // started. If the source cannot start, the new MediaStreamVideoTrack will be |
| 332 // initialized to the stopped/ended state. |
| 333 //if (!is_stopped_) { |
| 334 // if (!EnsureSourceIsStarted()) |
| 335 // StopSource(); |
| 336 // } |
| 337 |
| 338 // Create and initialize a new MediaStreamVideoTrack and pass ownership of it |
| 339 // to the WebMediaStreamTrack. |
| 340 blink::WebMediaStreamTrack mutable_blink_track = blink_track; |
| 341 mutable_blink_track.setTrackData( |
| 342 new MediaStreamVideoTrack(weak_factory_.GetWeakPtr(), |
| 343 blink_track.isEnabled())); |
| 344 MediaStreamVideoTrack* track = |
| 345 MediaStreamVideoTrack::GetVideoTrack(blink_track); |
| 346 |
| 347 |
| 348 /* |
| 349 // If the source is stopped, do not add the track. |
| 350 if (state_ == ENDED) |
| 351 return false; |
| 352 |
| 353 track->Start(base::Bind(&MediaStreamVideoSource::RemoveTrack, |
| 354 weak_factory_.GetWeakPtr(), track)); |
| 355 DVLOG(1) << "Adding MediaStreamVideoTrack@" << track |
| 356 << " as a consumer of MediaStreamVideoSource@" << this << '.'; |
| 357 */ |
| 358 |
| 359 tracks_.push_back(track); |
| 360 secure_tracker_.Add(track, true); |
| 361 return true; |
| 362 } |
| 363 |
| 364 void MediaStreamVideoSource::ApplyConstraints( |
| 365 const blink::WebMediaStreamTrack& blink_track, |
| 320 const blink::WebMediaConstraints& constraints, | 366 const blink::WebMediaConstraints& constraints, |
| 321 const ConstraintsCallback& callback) { | 367 const ConstraintsCallback& callback) { |
| 322 DCHECK(CalledOnValidThread()); | 368 DCHECK(CalledOnValidThread()); |
| 323 DCHECK(!constraints.isNull()); | 369 DCHECK(!constraints.isNull()); |
| 324 DCHECK(std::find(tracks_.begin(), tracks_.end(), track) == tracks_.end()); | 370 |
| 325 tracks_.push_back(track); | 371 MediaStreamVideoTrack* track = MediaStreamVideoTrack::GetVideoTrack(blink_trac
k); |
| 326 secure_tracker_.Add(track, true); | 372 DCHECK(std::find(tracks_.begin(), tracks_.end(), track) != tracks_.end()); |
| 373 // tracks_.push_back(track); |
| 374 // secure_tracker_.Add(track, true); |
| 327 | 375 |
| 328 track_descriptors_.push_back( | 376 track_descriptors_.push_back( |
| 329 TrackDescriptor(track, frame_callback, constraints, callback)); | 377 TrackDescriptor(track, track->frame_input(), constraints, callback)); |
| 330 | 378 |
| 331 switch (state_) { | 379 switch (state_) { |
| 332 case NEW: { | 380 case NEW: { |
| 333 // Tab capture and Screen capture needs the maximum requested height | 381 // Tab capture and Screen capture needs the maximum requested height |
| 334 // and width to decide on the resolution. | 382 // and width to decide on the resolution. |
| 335 // NOTE: Optional constraints are deliberately ignored. | 383 // NOTE: Optional constraints are deliberately ignored. |
| 336 int max_requested_width = 0; | 384 int max_requested_width = 0; |
| 337 if (constraints.basic().width.hasMax()) | 385 if (constraints.basic().width.hasMax()) |
| 338 max_requested_width = constraints.basic().width.max(); | 386 max_requested_width = constraints.basic().width.max(); |
| 339 | 387 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 callback(callback) { | 638 callback(callback) { |
| 591 } | 639 } |
| 592 | 640 |
| 593 MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( | 641 MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( |
| 594 const TrackDescriptor& other) = default; | 642 const TrackDescriptor& other) = default; |
| 595 | 643 |
| 596 MediaStreamVideoSource::TrackDescriptor::~TrackDescriptor() { | 644 MediaStreamVideoSource::TrackDescriptor::~TrackDescriptor() { |
| 597 } | 645 } |
| 598 | 646 |
| 599 } // namespace content | 647 } // namespace content |
| OLD | NEW |