Chromium Code Reviews| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/public/renderer/media_stream_video_sink.h" | 8 #include "content/renderer/media/media_stream_dependency_factory.h" |
| 9 #include "content/renderer/media/media_stream_source_extra_data.h" | |
| 10 #include "content/renderer/render_thread_impl.h" | |
| 11 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | |
| 12 #include "third_party/libjingle/source/talk/app/webrtc/remotevideocapturer.h" | |
| 13 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" | |
| 9 | 14 |
| 10 namespace content { | 15 namespace content { |
| 11 | 16 |
| 12 void MediaStreamVideoSource::AddTrack( | 17 MediaStreamVideoSource::MediaStreamVideoSource( |
| 18 MediaStreamDependencyFactory* factory) | |
| 19 : factory_(factory), | |
| 20 width_(0), | |
| 21 height_(0) { | |
| 22 } | |
| 23 | |
| 24 bool MediaStreamVideoSource::Init() { | |
| 25 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
| |
| 26 factory_ = RenderThreadImpl::current()->GetMediaStreamDependencyFactory(); | |
| 27 DCHECK(factory_ != NULL); | |
| 28 } | |
| 29 blink::WebMediaConstraints constraints; | |
| 30 adapter_ = factory_->CreateVideoSource( | |
| 31 new webrtc::RemoteVideoCapturer(), constraints); | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 bool MediaStreamVideoSource::AddTrack( | |
| 13 const blink::WebMediaStreamTrack& track, | 36 const blink::WebMediaStreamTrack& track, |
| 14 const blink::WebMediaConstraints& constraints) { | 37 const blink::WebMediaConstraints& constraints) { |
| 15 // TODO(ronghuawu): Put |track| in the registered tracks list. Will later | 38 // WebMediaStreamTrack init requires WebMediaStreamSource, so assuming it's |
| 16 // deliver frames to it according to |constraints|. | 39 // not null at this point. |
| 40 if (track.isNull() || track.source().isNull()) { | |
| 41 return false; | |
| 42 } | |
| 43 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
| |
| 44 if (source.extraData()) { | |
| 45 // The track has already associated with a native source. | |
| 46 return false; | |
| 47 } | |
| 48 MediaStreamSourceExtraData* source_data = new MediaStreamSourceExtraData(); | |
| 49 source_data->SetVideoSource(adapter_.get()); | |
| 50 source.setExtraData(source_data); | |
| 51 | |
| 52 factory_->CreateNativeMediaStreamTrack(track); | |
| 53 return true; | |
| 17 } | 54 } |
| 18 | 55 |
| 19 void MediaStreamVideoSource::RemoveTrack( | 56 bool MediaStreamVideoSource::RemoveTrack( |
| 20 const blink::WebMediaStreamTrack& track) { | 57 const blink::WebMediaStreamTrack& track) { |
| 21 // TODO(ronghuawu): Remove |track| from the list, i.e. will stop delivering | 58 // 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
| |
| 22 // frame to |track|. | 59 return true; |
| 23 } | 60 } |
| 24 | 61 |
| 25 void MediaStreamVideoSource::SetReadyState( | 62 void MediaStreamVideoSource::SetReadyState( |
| 26 blink::WebMediaStreamSource::ReadyState state) { | 63 blink::WebMediaStreamSource::ReadyState state) { |
| 27 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the | 64 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the |
| 28 // ready state to all registered tracks. | 65 // ready state to all registered tracks. |
| 29 } | 66 } |
| 30 | 67 |
| 31 void MediaStreamVideoSource::DeliverVideoFrame( | 68 void MediaStreamVideoSource::DeliverVideoFrame( |
| 32 const scoped_refptr<media::VideoFrame>& frame) { | 69 const scoped_refptr<media::VideoFrame>& frame) { |
| 33 // TODO(ronghuawu): Deliver |frame| to all the registered tracks. | 70 cricket::VideoRenderer* input = adapter_->FrameInput(); |
| 71 | |
| 72 if (width_ != frame->coded_size().width() || | |
| 73 height_ != frame->coded_size().height()) { | |
| 74 width_ = frame->coded_size().width(); | |
| 75 height_ = frame->coded_size().height(); | |
| 76 const int reserved = 0; | |
| 77 input->SetSize(width_, height_, reserved); | |
| 78 } | |
| 79 | |
| 80 cricket::WebRtcVideoFrame cricket_frame; | |
| 81 // 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
| |
| 82 input->RenderFrame(&cricket_frame); | |
| 34 } | 83 } |
| 35 | 84 |
| 36 MediaStreamVideoSource::~MediaStreamVideoSource() { | 85 MediaStreamVideoSource::~MediaStreamVideoSource() { |
| 37 } | 86 } |
| 38 | 87 |
| 39 } // namespace content | 88 } // namespace content |
| OLD | NEW |