| 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 "content/renderer/media/media_stream_dependency_factory.h" |
| 8 #include "content/public/renderer/media_stream_video_sink.h" | 8 #include "media/base/video_frame.h" |
| 9 #include "third_party/libjingle/source/talk/app/webrtc/remotevideocapturer.h" |
| 10 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" |
| 9 | 11 |
| 10 namespace content { | 12 namespace content { |
| 11 | 13 |
| 14 MediaStreamVideoSource::MediaStreamVideoSource( |
| 15 MediaStreamDependencyFactory* factory) |
| 16 : factory_(factory), |
| 17 width_(0), |
| 18 height_(0), |
| 19 first_frame_timestamp_(media::kNoTimestamp()) { |
| 20 DCHECK(factory_); |
| 21 } |
| 22 |
| 12 void MediaStreamVideoSource::AddTrack( | 23 void MediaStreamVideoSource::AddTrack( |
| 13 const blink::WebMediaStreamTrack& track, | 24 const blink::WebMediaStreamTrack& track, |
| 14 const blink::WebMediaConstraints& constraints) { | 25 const blink::WebMediaConstraints& constraints) { |
| 15 // TODO(ronghuawu): Put |track| in the registered tracks list. Will later | 26 factory_->CreateNativeMediaStreamTrack(track); |
| 16 // deliver frames to it according to |constraints|. | |
| 17 } | 27 } |
| 18 | 28 |
| 19 void MediaStreamVideoSource::RemoveTrack( | 29 void MediaStreamVideoSource::RemoveTrack( |
| 20 const blink::WebMediaStreamTrack& track) { | 30 const blink::WebMediaStreamTrack& track) { |
| 21 // TODO(ronghuawu): Remove |track| from the list, i.e. will stop delivering | 31 // TODO(ronghuawu): What should be done here? Do we really need RemoveTrack? |
| 22 // frame to |track|. | 32 } |
| 33 |
| 34 void MediaStreamVideoSource::Init() { |
| 35 if (!adapter_) { |
| 36 const webrtc::MediaConstraintsInterface* constraints = NULL; |
| 37 adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(), |
| 38 constraints); |
| 39 } |
| 23 } | 40 } |
| 24 | 41 |
| 25 void MediaStreamVideoSource::SetReadyState( | 42 void MediaStreamVideoSource::SetReadyState( |
| 26 blink::WebMediaStreamSource::ReadyState state) { | 43 blink::WebMediaStreamSource::ReadyState state) { |
| 27 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the | 44 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the |
| 28 // ready state to all registered tracks. | 45 // ready state to all registered tracks. |
| 29 } | 46 } |
| 30 | 47 |
| 31 void MediaStreamVideoSource::DeliverVideoFrame( | 48 void MediaStreamVideoSource::DeliverVideoFrame( |
| 32 const scoped_refptr<media::VideoFrame>& frame) { | 49 const scoped_refptr<media::VideoFrame>& frame) { |
| 33 // TODO(ronghuawu): Deliver |frame| to all the registered tracks. | 50 if (first_frame_timestamp_ == media::kNoTimestamp()) { |
| 51 first_frame_timestamp_ = frame->GetTimestamp(); |
| 52 } |
| 53 |
| 54 cricket::VideoRenderer* input = adapter_->FrameInput(); |
| 55 if (width_ != frame->coded_size().width() || |
| 56 height_ != frame->coded_size().height()) { |
| 57 width_ = frame->coded_size().width(); |
| 58 height_ = frame->coded_size().height(); |
| 59 const int reserved = 0; |
| 60 input->SetSize(width_, height_, reserved); |
| 61 } |
| 62 |
| 63 cricket::WebRtcVideoFrame cricket_frame; |
| 64 const int64 elapsed_time_ns = |
| 65 (frame->GetTimestamp() - first_frame_timestamp_).InMicroseconds() * |
| 66 base::Time::kNanosecondsPerMicrosecond; |
| 67 const int64 time_stamp_ns = frame->GetTimestamp().InMicroseconds() * |
| 68 base::Time::kNanosecondsPerMicrosecond; |
| 69 const size_t size = |
| 70 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size()); |
| 71 const size_t pixel_width = 1; |
| 72 const size_t pixel_height = 1; |
| 73 const int rotation = 0; |
| 74 cricket_frame.Alias(frame->data(0), size, |
| 75 width_, height_, |
| 76 pixel_width, pixel_height, |
| 77 elapsed_time_ns, time_stamp_ns, |
| 78 rotation); |
| 79 input->RenderFrame(&cricket_frame); |
| 34 } | 80 } |
| 35 | 81 |
| 36 MediaStreamVideoSource::~MediaStreamVideoSource() { | 82 MediaStreamVideoSource::~MediaStreamVideoSource() { |
| 37 } | 83 } |
| 38 | 84 |
| 39 } // namespace content | 85 } // namespace content |
| OLD | NEW |