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 acdb7dfc9012677655a044d41e43688d08d1cde3..c0d9f956fd8e4026c4aa28d36a9cdf1b5642ae25 100644 |
| --- a/content/renderer/media/media_stream_video_source.cc |
| +++ b/content/renderer/media/media_stream_video_source.cc |
| @@ -5,21 +5,58 @@ |
| #include "content/renderer/media/media_stream_video_source.h" |
| #include "base/logging.h" |
| -#include "content/public/renderer/media_stream_video_sink.h" |
| +#include "content/renderer/media/media_stream_dependency_factory.h" |
| +#include "content/renderer/media/media_stream_source_extra_data.h" |
| +#include "content/renderer/render_thread_impl.h" |
| +#include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| +#include "third_party/libjingle/source/talk/app/webrtc/remotevideocapturer.h" |
| +#include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" |
| namespace content { |
| -void MediaStreamVideoSource::AddTrack( |
| +MediaStreamVideoSource::MediaStreamVideoSource( |
| + MediaStreamDependencyFactory* factory) |
| + : factory_(factory), |
| + width_(0), |
| + height_(0) { |
| +} |
| + |
| +bool MediaStreamVideoSource::Init() { |
| + if (!factory_) { |
|
perkj_chrome
2014/01/10 13:07:00
You might want to use dependency injection of the
Ronghua Wu (Left Chromium)
2014/01/11 01:22:58
I do have the injection, see the ctor.
Regarding
|
| + factory_ = RenderThreadImpl::current()->GetMediaStreamDependencyFactory(); |
| + DCHECK(factory_ != NULL); |
| + } |
| + blink::WebMediaConstraints constraints; |
| + adapter_ = factory_->CreateVideoSource( |
| + new webrtc::RemoteVideoCapturer(), constraints); |
| + return true; |
| +} |
| + |
| +bool MediaStreamVideoSource::AddTrack( |
| const blink::WebMediaStreamTrack& track, |
| const blink::WebMediaConstraints& constraints) { |
| - // TODO(ronghuawu): Put |track| in the registered tracks list. Will later |
| - // deliver frames to it according to |constraints|. |
| + // WebMediaStreamTrack init requires WebMediaStreamSource, so assuming it's |
| + // not null at this point. |
| + if (track.isNull() || track.source().isNull()) { |
| + return false; |
| + } |
| + blink::WebMediaStreamSource source = track.source(); |
|
perkj_chrome
2014/01/10 13:07:00
This seem wrong. The source already has extra data
Ronghua Wu (Left Chromium)
2014/01/11 01:22:58
The idea is before a track is add/associated with
|
| + if (source.extraData()) { |
| + // The track has already associated with a native source. |
| + return false; |
| + } |
| + MediaStreamSourceExtraData* source_data = new MediaStreamSourceExtraData(); |
| + source_data->SetVideoSource(adapter_.get()); |
| + source.setExtraData(source_data); |
| + |
| + factory_->CreateNativeMediaStreamTrack(track); |
| + return true; |
| } |
| -void MediaStreamVideoSource::RemoveTrack( |
| +bool MediaStreamVideoSource::RemoveTrack( |
| const blink::WebMediaStreamTrack& track) { |
| - // TODO(ronghuawu): Remove |track| from the list, i.e. will stop delivering |
| - // frame to |track|. |
| + // TODO(ronghuawu): What can be done here? Do we need RemoveTrack or how? |
|
perkj_chrome
2014/01/10 13:07:00
This means that a track is being destroyed by webk
Ronghua Wu (Left Chromium)
2014/01/11 01:22:58
Ack
|
| + return true; |
| } |
| void MediaStreamVideoSource::SetReadyState( |
| @@ -30,7 +67,19 @@ void MediaStreamVideoSource::SetReadyState( |
| void MediaStreamVideoSource::DeliverVideoFrame( |
| const scoped_refptr<media::VideoFrame>& frame) { |
| - // TODO(ronghuawu): Deliver |frame| to all the registered tracks. |
| + cricket::VideoRenderer* input = adapter_->FrameInput(); |
| + |
| + if (width_ != frame->coded_size().width() || |
| + height_ != frame->coded_size().height()) { |
| + width_ = frame->coded_size().width(); |
| + height_ = frame->coded_size().height(); |
| + const int reserved = 0; |
| + input->SetSize(width_, height_, reserved); |
| + } |
| + |
| + cricket::WebRtcVideoFrame cricket_frame; |
| + // TODO(ronghuawu): convert from media::VideoFrame to cricket::VideoFrame. |
|
perkj_chrome
2014/01/10 13:07:00
Take a look at RTCVideoCapture to see how we conve
|
| + input->RenderFrame(&cricket_frame); |
| } |
| MediaStreamVideoSource::~MediaStreamVideoSource() { |