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