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 a9912cdeca0073441ec573488ccc36c864e687e2..14572c2e0595bdee732ce6e573f095c830ffdcf3 100644 |
| --- a/content/renderer/media/media_stream_video_source.cc |
| +++ b/content/renderer/media/media_stream_video_source.cc |
| @@ -5,6 +5,7 @@ |
| #include "content/renderer/media/media_stream_video_source.h" |
| #include "content/renderer/media/media_stream_dependency_factory.h" |
| +#include "content/renderer/media/rtc_media_constraints.h" |
| #include "media/base/video_frame.h" |
| #include "third_party/libjingle/source/talk/app/webrtc/remotevideocapturer.h" |
| #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" |
| @@ -13,16 +14,50 @@ namespace content { |
| MediaStreamVideoSource::MediaStreamVideoSource( |
| MediaStreamDependencyFactory* factory) |
| - : factory_(factory), |
| + : initializing_(false), |
| + factory_(factory), |
| width_(0), |
| height_(0), |
| first_frame_timestamp_(media::kNoTimestamp()) { |
| DCHECK(factory_); |
| } |
| +MediaStreamVideoSource::~MediaStreamVideoSource() { |
| + if (initializing_) { |
| + adapter_->UnregisterObserver(this); |
| + } |
| +} |
| + |
| void MediaStreamVideoSource::AddTrack( |
| const blink::WebMediaStreamTrack& track, |
| - const blink::WebMediaConstraints& constraints) { |
| + const blink::WebMediaConstraints& constraints, |
| + const ConstraintsCallback& callback) { |
| + if (!adapter_) { |
| + // Create the webrtc::MediaStreamVideoSourceInterface adapter. |
| + Init(constraints); |
| + DCHECK(adapter_); |
| + |
| + current_constraints_ = constraints; |
| + initializing_ = true; |
| + // Register to the adapter to get notified when it has been started |
| + // successfully. |
| + adapter_->RegisterObserver(this); |
| + } |
| + |
| + // TODO(perkj): Currently, reconfiguring the source is not supported. For now |
| + // we ignore it the constraints do not match the constraints that was used |
| + // when the source was started |
| + |
| + // There might be multiple tracks attaching to the source while it is being |
| + // configured. |
| + constraints_callbacks_.push_back(callback); |
| + CheckIfAdapterIsLive(); |
| + |
| + // TODO(perkj): Use the MediaStreamDependencyFactory for now to create the |
| + // MediaStreamVideoTrack since creation is currently still depending on |
| + // libjingle. The webrtc video track implementation will attach to the |
| + // webrtc::VideoSourceInterface returned by GetAdapter() to receive video |
| + // frames. |
| factory_->CreateNativeMediaStreamTrack(track); |
| } |
| @@ -31,12 +66,12 @@ void MediaStreamVideoSource::RemoveTrack( |
| // TODO(ronghuawu): What should be done here? Do we really need RemoveTrack? |
| } |
| -void MediaStreamVideoSource::Init() { |
| - if (!adapter_) { |
| - const webrtc::MediaConstraintsInterface* constraints = NULL; |
| - adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(), |
| - constraints); |
| - } |
| +void MediaStreamVideoSource::Init( |
|
Ronghua Wu (Left Chromium)
2014/01/22 01:44:04
Call this InitAdapter maybe?
perkj_chrome
2014/01/22 16:56:37
Done.
|
| + const blink::WebMediaConstraints& constraints) { |
| + DCHECK(!adapter_); |
| + RTCMediaConstraints webrtc_constraints(constraints); |
| + adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(), |
| + &webrtc_constraints); |
| } |
| void MediaStreamVideoSource::SetReadyState( |
| @@ -79,7 +114,30 @@ void MediaStreamVideoSource::DeliverVideoFrame( |
| input->RenderFrame(&cricket_frame); |
| } |
| -MediaStreamVideoSource::~MediaStreamVideoSource() { |
| +void MediaStreamVideoSource::OnChanged() { |
| + DCHECK(CalledOnValidThread()); |
| + CheckIfAdapterIsLive(); |
| +} |
| + |
| +void MediaStreamVideoSource::CheckIfAdapterIsLive() { |
| + if (adapter_->state() == webrtc::MediaSourceInterface::kInitializing) |
| + return; |
| + |
| + bool success = (adapter_->state() == webrtc::MediaSourceInterface::kLive); |
|
no longer working on chromium
2014/01/21 09:25:30
nit, move this line closer to where it is used, li
perkj_chrome
2014/01/22 16:56:37
Done.
|
| + |
| + if (initializing_) { |
| + adapter_->UnregisterObserver(this); |
| + initializing_ = false; |
| + } |
|
Ronghua Wu (Left Chromium)
2014/01/22 01:44:04
It's confusing to put these 3 lines here. Suggest
perkj_chrome
2014/01/22 16:56:37
I can't really. OnChanged is only triggered if the
|
| + |
| + std::vector<ConstraintsCallback> callbacks; |
| + callbacks.swap(constraints_callbacks_); |
| + |
| + for (std::vector<ConstraintsCallback>::iterator it = callbacks.begin(); |
| + it != callbacks.end(); ++it) { |
| + if (!it->is_null()) |
| + it->Run(this, success); |
| + } |
| } |
| } // namespace content |