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" | |
|
perkj_chrome
2014/01/14 08:29:10
media_stream_source_extra_data.h is not needed her
Ronghua Wu (Left Chromium)
2014/01/14 19:42:10
Done.
| |
| 10 #include "content/renderer/render_thread_impl.h" | |
| 11 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | |
|
perkj_chrome
2014/01/14 08:29:10
unused?
Ronghua Wu (Left Chromium)
2014/01/14 19:42:10
Done.
| |
| 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 webrtc::VideoSourceInterface* adapter) | |
| 20 : factory_(factory), | |
| 21 adapter_(adapter), | |
| 22 width_(0), | |
| 23 height_(0), | |
| 24 first_frame_timestamp_(media::kNoTimestamp()) { | |
| 25 if (!factory_) { | |
|
perkj_chrome
2014/01/14 08:29:10
I would prefer to always incject the factory for n
Ronghua Wu (Left Chromium)
2014/01/14 19:42:10
Done.
| |
| 26 factory_ = RenderThreadImpl::current()->GetMediaStreamDependencyFactory(); | |
| 27 DCHECK(factory_ != NULL); | |
| 28 } | |
| 29 if (!adapter_) { | |
| 30 adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(), | |
| 31 NULL); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 bool MediaStreamVideoSource::AddTrack( | |
|
perkj_chrome
2014/01/14 08:29:10
why bool ?
Ronghua Wu (Left Chromium)
2014/01/14 19:42:10
Done.
| |
| 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 factory_->CreateNativeMediaStreamTrack(track); |
| 16 // deliver frames to it according to |constraints|. | 39 return true; |
| 17 } | 40 } |
| 18 | 41 |
| 19 void MediaStreamVideoSource::RemoveTrack( | 42 bool MediaStreamVideoSource::RemoveTrack( |
| 20 const blink::WebMediaStreamTrack& track) { | 43 const blink::WebMediaStreamTrack& track) { |
| 21 // TODO(ronghuawu): Remove |track| from the list, i.e. will stop delivering | 44 // TODO(ronghuawu): What can be done here? Do we need RemoveTrack or how? |
| 22 // frame to |track|. | 45 return true; |
| 23 } | 46 } |
| 24 | 47 |
| 25 void MediaStreamVideoSource::SetReadyState( | 48 void MediaStreamVideoSource::SetReadyState( |
| 26 blink::WebMediaStreamSource::ReadyState state) { | 49 blink::WebMediaStreamSource::ReadyState state) { |
| 27 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the | 50 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the |
| 28 // ready state to all registered tracks. | 51 // ready state to all registered tracks. |
| 29 } | 52 } |
| 30 | 53 |
| 31 void MediaStreamVideoSource::DeliverVideoFrame( | 54 void MediaStreamVideoSource::DeliverVideoFrame( |
| 32 const scoped_refptr<media::VideoFrame>& frame) { | 55 const scoped_refptr<media::VideoFrame>& frame) { |
| 33 // TODO(ronghuawu): Deliver |frame| to all the registered tracks. | 56 if (first_frame_timestamp_ == media::kNoTimestamp()) { |
| 57 first_frame_timestamp_ = frame->GetTimestamp(); | |
| 58 } | |
| 59 | |
| 60 cricket::VideoRenderer* input = adapter_->FrameInput(); | |
| 61 if (width_ != frame->coded_size().width() || | |
| 62 height_ != frame->coded_size().height()) { | |
| 63 width_ = frame->coded_size().width(); | |
| 64 height_ = frame->coded_size().height(); | |
| 65 const int reserved = 0; | |
| 66 input->SetSize(width_, height_, reserved); | |
| 67 } | |
| 68 | |
| 69 cricket::WebRtcVideoFrame cricket_frame; | |
| 70 // TODO(ronghuawu): we assume contiguous layout of image planes and | |
| 71 // FOURCC_I420. | |
| 72 int64 elapsed_time = | |
| 73 (frame->GetTimestamp() - first_frame_timestamp_).InMicroseconds() * | |
| 74 base::Time::kNanosecondsPerMicrosecond; | |
| 75 int64 time_stamp = frame->GetTimestamp().InMicroseconds() * | |
| 76 base::Time::kNanosecondsPerMicrosecond; | |
| 77 size_t size = | |
| 78 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size()); | |
| 79 cricket_frame.Alias(frame->data(0), size, width_, height_, | |
| 80 1, 1, elapsed_time, time_stamp, 0); | |
|
perkj_chrome
2014/01/14 08:29:10
nit, fits on line above.
Ronghua Wu (Left Chromium)
2014/01/14 19:42:10
It doesn't actually.
| |
| 81 input->RenderFrame(&cricket_frame); | |
| 34 } | 82 } |
| 35 | 83 |
| 36 MediaStreamVideoSource::~MediaStreamVideoSource() { | 84 MediaStreamVideoSource::~MediaStreamVideoSource() { |
| 37 } | 85 } |
| 38 | 86 |
| 39 } // namespace content | 87 } // namespace content |
| OLD | NEW |