| 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 "content/renderer/media/media_stream_dependency_factory.h" | 7 #include "content/renderer/media/media_stream_dependency_factory.h" |
| 8 #include "content/renderer/media/rtc_media_constraints.h" |
| 8 #include "media/base/video_frame.h" | 9 #include "media/base/video_frame.h" |
| 9 #include "third_party/libjingle/source/talk/app/webrtc/remotevideocapturer.h" | 10 #include "third_party/libjingle/source/talk/app/webrtc/remotevideocapturer.h" |
| 10 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" | 11 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 MediaStreamVideoSource::MediaStreamVideoSource( | 15 MediaStreamVideoSource::MediaStreamVideoSource( |
| 15 MediaStreamDependencyFactory* factory) | 16 MediaStreamDependencyFactory* factory) |
| 16 : factory_(factory), | 17 : initializing_(false), |
| 18 factory_(factory), |
| 17 width_(0), | 19 width_(0), |
| 18 height_(0), | 20 height_(0), |
| 19 first_frame_timestamp_(media::kNoTimestamp()) { | 21 first_frame_timestamp_(media::kNoTimestamp()) { |
| 20 DCHECK(factory_); | 22 DCHECK(factory_); |
| 21 } | 23 } |
| 22 | 24 |
| 25 MediaStreamVideoSource::~MediaStreamVideoSource() { |
| 26 if (initializing_) { |
| 27 adapter_->UnregisterObserver(this); |
| 28 } |
| 29 } |
| 30 |
| 23 void MediaStreamVideoSource::AddTrack( | 31 void MediaStreamVideoSource::AddTrack( |
| 24 const blink::WebMediaStreamTrack& track, | 32 const blink::WebMediaStreamTrack& track, |
| 25 const blink::WebMediaConstraints& constraints) { | 33 const blink::WebMediaConstraints& constraints, |
| 34 const ConstraintsCallback& callback) { |
| 35 if (!adapter_) { |
| 36 // Create the webrtc::MediaStreamVideoSourceInterface adapter. |
| 37 Init(constraints); |
| 38 DCHECK(adapter_); |
| 39 |
| 40 current_constraints_ = constraints; |
| 41 initializing_ = true; |
| 42 // Register to the adapter to get notified when it has been started |
| 43 // successfully. |
| 44 adapter_->RegisterObserver(this); |
| 45 } |
| 46 |
| 47 // TODO(perkj): Currently, reconfiguring the source is not supported. For now |
| 48 // we ignore it the constraints do not match the constraints that was used |
| 49 // when the source was started |
| 50 |
| 51 // There might be multiple tracks attaching to the source while it is being |
| 52 // configured. |
| 53 constraints_callbacks_.push_back(callback); |
| 54 CheckIfAdapterIsLive(); |
| 55 |
| 56 // TODO(perkj): Use the MediaStreamDependencyFactory for now to create the |
| 57 // MediaStreamVideoTrack since creation is currently still depending on |
| 58 // libjingle. The webrtc video track implementation will attach to the |
| 59 // webrtc::VideoSourceInterface returned by GetAdapter() to receive video |
| 60 // frames. |
| 26 factory_->CreateNativeMediaStreamTrack(track); | 61 factory_->CreateNativeMediaStreamTrack(track); |
| 27 } | 62 } |
| 28 | 63 |
| 29 void MediaStreamVideoSource::RemoveTrack( | 64 void MediaStreamVideoSource::RemoveTrack( |
| 30 const blink::WebMediaStreamTrack& track) { | 65 const blink::WebMediaStreamTrack& track) { |
| 31 // TODO(ronghuawu): What should be done here? Do we really need RemoveTrack? | 66 // TODO(ronghuawu): What should be done here? Do we really need RemoveTrack? |
| 32 } | 67 } |
| 33 | 68 |
| 34 void MediaStreamVideoSource::Init() { | 69 void MediaStreamVideoSource::Init( |
| 35 if (!adapter_) { | 70 const blink::WebMediaConstraints& constraints) { |
| 36 const webrtc::MediaConstraintsInterface* constraints = NULL; | 71 DCHECK(!adapter_); |
| 37 adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(), | 72 RTCMediaConstraints webrtc_constraints(constraints); |
| 38 constraints); | 73 adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(), |
| 39 } | 74 &webrtc_constraints); |
| 40 } | 75 } |
| 41 | 76 |
| 42 void MediaStreamVideoSource::SetReadyState( | 77 void MediaStreamVideoSource::SetReadyState( |
| 43 blink::WebMediaStreamSource::ReadyState state) { | 78 blink::WebMediaStreamSource::ReadyState state) { |
| 44 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the | 79 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the |
| 45 // ready state to all registered tracks. | 80 // ready state to all registered tracks. |
| 46 } | 81 } |
| 47 | 82 |
| 48 void MediaStreamVideoSource::DeliverVideoFrame( | 83 void MediaStreamVideoSource::DeliverVideoFrame( |
| 49 const scoped_refptr<media::VideoFrame>& frame) { | 84 const scoped_refptr<media::VideoFrame>& frame) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 72 const size_t pixel_height = 1; | 107 const size_t pixel_height = 1; |
| 73 const int rotation = 0; | 108 const int rotation = 0; |
| 74 cricket_frame.Alias(frame->data(0), size, | 109 cricket_frame.Alias(frame->data(0), size, |
| 75 width_, height_, | 110 width_, height_, |
| 76 pixel_width, pixel_height, | 111 pixel_width, pixel_height, |
| 77 elapsed_time_ns, time_stamp_ns, | 112 elapsed_time_ns, time_stamp_ns, |
| 78 rotation); | 113 rotation); |
| 79 input->RenderFrame(&cricket_frame); | 114 input->RenderFrame(&cricket_frame); |
| 80 } | 115 } |
| 81 | 116 |
| 82 MediaStreamVideoSource::~MediaStreamVideoSource() { | 117 void MediaStreamVideoSource::OnChanged() { |
| 118 DCHECK(CalledOnValidThread()); |
| 119 CheckIfAdapterIsLive(); |
| 120 } |
| 121 |
| 122 void MediaStreamVideoSource::CheckIfAdapterIsLive() { |
| 123 if (adapter_->state() == webrtc::MediaSourceInterface::kInitializing) |
| 124 return; |
| 125 |
| 126 bool success = adapter_->state() == webrtc::MediaSourceInterface::kLive |
| 127 ? true : false; |
| 128 |
| 129 if (initializing_) { |
| 130 adapter_->UnregisterObserver(this); |
| 131 initializing_ = false; |
| 132 } |
| 133 |
| 134 std::vector<ConstraintsCallback> callbacks(constraints_callbacks_); |
| 135 constraints_callbacks_.clear(); |
| 136 |
| 137 for (std::vector<ConstraintsCallback>::iterator it = callbacks.begin(); |
| 138 it != callbacks.end(); ++it) { |
| 139 if (!it->is_null()) |
| 140 it->Run(this, success); |
| 141 } |
| 83 } | 142 } |
| 84 | 143 |
| 85 } // namespace content | 144 } // namespace content |
| OLD | NEW |