Chromium Code Reviews| Index: content/renderer/media/media_stream_video_source.cc |
| diff --git a/content/renderer/media/media_stream_video_source.cc b/content/renderer/media/media_stream_video_source.cc |
| index 118d66e3cddc59faa72ed1fd4c7448c0bc0c377e..3fa5d6b399e06a22cd42a470c5536ead378e4d04 100644 |
| --- a/content/renderer/media/media_stream_video_source.cc |
| +++ b/content/renderer/media/media_stream_video_source.cc |
| @@ -214,6 +214,12 @@ const media::VideoCaptureFormat& GetBestCaptureFormat( |
| } // anonymous namespace |
| +// static |
| +MediaStreamVideoSource* MediaStreamVideoSource::GetVideoSource( |
| + const blink::WebMediaStreamSource& source) { |
| + return static_cast<MediaStreamVideoSource*>(source.extraData()); |
| +} |
| + |
| MediaStreamVideoSource::MediaStreamVideoSource( |
| MediaStreamDependencyFactory* factory) |
| : state_(NEW), |
| @@ -223,6 +229,7 @@ MediaStreamVideoSource::MediaStreamVideoSource( |
| } |
| MediaStreamVideoSource::~MediaStreamVideoSource() { |
| + DVLOG(3) << "~MediaStreamVideoSource()"; |
| } |
| void MediaStreamVideoSource::AddTrack( |
| @@ -230,8 +237,15 @@ void MediaStreamVideoSource::AddTrack( |
| const blink::WebMediaConstraints& constraints, |
| const ConstraintsCallback& callback) { |
| DCHECK(CalledOnValidThread()); |
| - requested_constraints_.push_back(RequestedConstraints(constraints, |
| - callback)); |
| + MediaStreamVideoTrack* video_track = |
| + MediaStreamVideoTrack::GetVideoTrack(track); |
| + DCHECK(std::find(tracks_.begin(), tracks_.end(), |
| + video_track) == tracks_.end()); |
| + tracks_.push_back(video_track); |
| + |
| + requested_constraints_.push_back( |
| + RequestedConstraints(constraints, callback)); |
| + |
| switch (state_) { |
| case NEW: { |
| // Tab capture and Screen capture needs the maximum requested height |
| @@ -254,8 +268,8 @@ void MediaStreamVideoSource::AddTrack( |
| } |
| case STARTING: |
| case RETRIEVING_CAPABILITIES: { |
| - // The |callback| will be triggered once the delegate has started or |
| - // the capabilitites has been retrieved. |
| + // The |callback| will be triggered once the source has started or |
| + // the capabilities has been retrieved. |
| break; |
| } |
| case ENDED: |
| @@ -266,9 +280,11 @@ void MediaStreamVideoSource::AddTrack( |
| } |
| } |
| -void MediaStreamVideoSource::RemoveTrack( |
| - const blink::WebMediaStreamTrack& track) { |
| - // TODO(ronghuawu): What should be done here? Do we really need RemoveTrack? |
| +void MediaStreamVideoSource::RemoveTrack(MediaStreamVideoTrack* video_track) { |
| + std::vector<MediaStreamVideoTrack*>::iterator it = |
| + std::find(tracks_.begin(), tracks_.end(), video_track); |
| + DCHECK(it != tracks_.end()); |
| + tracks_.erase(it); |
| } |
| void MediaStreamVideoSource::InitAdapter() { |
| @@ -298,12 +314,18 @@ void MediaStreamVideoSource::DoStopSource() { |
| DVLOG(3) << "DoStopSource()"; |
| StopSourceImpl(); |
| state_ = ENDED; |
| + SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
| } |
| void MediaStreamVideoSource::DeliverVideoFrame( |
| const scoped_refptr<media::VideoFrame>& frame) { |
| if (capture_adapter_) |
| capture_adapter_->OnFrameCaptured(frame); |
| + |
| + for (std::vector<MediaStreamVideoTrack*>::iterator it = tracks_.begin(); |
|
Ronghua Wu (Left Chromium)
2014/03/01 01:26:04
should we do this if capture_adapter_ is not null?
perkj_chrome
2014/03/02 09:20:44
No- capture_adapter_ provides frames to the webrtc
Ronghua Wu (Left Chromium)
2014/03/04 01:04:11
Assume you meant webrtc::VideoSource. So you are s
perkj_chrome
2014/03/04 10:44:51
Currently they work in parallell. ie video frames
|
| + it != tracks_.end(); ++it) { |
| + (*it)->OnVideoFrame(frame); |
| + } |
| } |
| void MediaStreamVideoSource::OnSupportedFormats( |
| @@ -377,8 +399,9 @@ void MediaStreamVideoSource::FinalizeAddTrack() { |
| callbacks.swap(requested_constraints_); |
| for (std::vector<RequestedConstraints>::iterator it = callbacks.begin(); |
| it != callbacks.end(); ++it) { |
| + |
| bool success = state_ == STARTED && |
| - !FilterFormats(it->constraints, formats).empty(); |
| + !FilterFormats(it->constraints, formats).empty(); |
| DVLOG(3) << "FinalizeAddTrack() success " << success; |
| if (!it->callback.is_null()) |
| it->callback.Run(this, success); |
| @@ -390,7 +413,10 @@ void MediaStreamVideoSource::SetReadyState( |
| if (!owner().isNull()) { |
| owner().setReadyState(state); |
| } |
| - // TODO(perkj): Notify all registered tracks. |
| + for (std::vector<MediaStreamVideoTrack*>::iterator it = tracks_.begin(); |
| + it != tracks_.end(); ++it) { |
| + (*it)->OnReadyStateChanged(state); |
| + } |
| } |
| MediaStreamVideoSource::RequestedConstraints::RequestedConstraints( |