 Chromium Code Reviews
 Chromium Code Reviews Issue 131763002:
  Adds MediaStreamSource, MediaStreamAudioSource and MediaStreamVideoCaptureDeviceSource  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 131763002:
  Adds MediaStreamSource, MediaStreamAudioSource and MediaStreamVideoCaptureDeviceSource  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 | 
| 13 namespace { | |
| 14 | |
| 15 // Returns true if the mandatory constraints in |c2| match the mandatory | |
| 16 // constraints in |c1|. All mandatory constraints in |c1| do not need to exist | |
| 17 // in |c2|. | |
| 18 bool MandatoryConstraintsMatch(const blink::WebMediaConstraints& c1, | |
| 
Ronghua Wu (Left Chromium)
2014/01/16 23:02:37
c1->original
c2->new
 
perkj_chrome
2014/01/17 13:19:45
Done.
 | |
| 19 const blink::WebMediaConstraints& c2) { | |
| 20 if (c1.isNull() && c2.isNull()) { | |
| 21 // WebMediaConstraints are NULL in unit tests unfortunately. | |
| 
Ronghua Wu (Left Chromium)
2014/01/16 23:02:37
being null makes sense in real case also, right? i
 
perkj_chrome
2014/01/17 13:19:45
Not 100% sure.
Better safe than sorry.
 | |
| 22 return true; | |
| 23 } | |
| 24 blink::WebVector<blink::WebMediaConstraint> m1; | |
| 25 c1.getMandatoryConstraints(m1); | |
| 26 blink::WebVector<blink::WebMediaConstraint> m2; | |
| 27 c2.getMandatoryConstraints(m2); | |
| 28 | |
| 29 if (m1.size() < m2.size()) | |
| 30 return false; | |
| 31 | |
| 32 size_t matched_constraints = 0; | |
| 33 | |
| 34 for (size_t i = 0; i < m1.size(); ++i) { | |
| 35 blink::WebString value; | |
| 36 if (!c2.getMandatoryConstraintValue(m1[i].m_name, value)) | |
| 37 continue; | |
| 38 if (value != m1[i].m_value) | |
| 39 return false; | |
| 40 ++matched_constraints; | |
| 41 } | |
| 42 return m1.size() >= matched_constraints + m2.size(); | |
| 
Ronghua Wu (Left Chromium)
2014/01/16 23:02:37
sorry I don't get this one. Why matched_constraint
 
Jói
2014/01/17 08:57:08
Perhaps the check you want is |matched_constraints
 
perkj_chrome
2014/01/17 13:19:45
Thinking about it more I think we need to skip thi
 | |
| 43 } | |
| 44 | |
| 45 } // anonymous namespace | |
| 46 | |
| 12 namespace content { | 47 namespace content { | 
| 13 | 48 | 
| 14 MediaStreamVideoSource::MediaStreamVideoSource( | 49 MediaStreamVideoSource::MediaStreamVideoSource( | 
| 15 MediaStreamDependencyFactory* factory) | 50 MediaStreamDependencyFactory* factory) | 
| 16 : factory_(factory), | 51 : initializing_(false), | 
| 52 factory_(factory), | |
| 17 width_(0), | 53 width_(0), | 
| 18 height_(0), | 54 height_(0), | 
| 19 first_frame_timestamp_(media::kNoTimestamp()) { | 55 first_frame_timestamp_(media::kNoTimestamp()) { | 
| 20 DCHECK(factory_); | 56 DCHECK(factory_); | 
| 21 } | 57 } | 
| 22 | 58 | 
| 59 MediaStreamVideoSource::~MediaStreamVideoSource() { | |
| 60 if (initializing_) { | |
| 61 GetAdapter()->UnregisterObserver(this); | |
| 62 } | |
| 63 } | |
| 64 | |
| 23 void MediaStreamVideoSource::AddTrack( | 65 void MediaStreamVideoSource::AddTrack( | 
| 24 const blink::WebMediaStreamTrack& track, | 66 const blink::WebMediaStreamTrack& track, | 
| 25 const blink::WebMediaConstraints& constraints) { | 67 const blink::WebMediaConstraints& constraints, | 
| 68 const ConstraintsCallback& callback) { | |
| 69 if (!GetAdapter()) { | |
| 70 Init(constraints); | |
| 71 DCHECK(GetAdapter()); | |
| 
Ronghua Wu (Left Chromium)
2014/01/16 23:02:37
any particular reason why use getter instead of us
 
perkj_chrome
2014/01/17 13:19:45
Done.
 | |
| 72 | |
| 73 current_constraints_ = constraints; | |
| 74 initializing_ = true; | |
| 75 GetAdapter()->RegisterObserver(this); | |
| 
Ronghua Wu (Left Chromium)
2014/01/16 23:02:37
this doesn't seem be right. i.e. when will you Reg
 
perkj_chrome
2014/01/17 13:19:45
The adapter is the webrtc::source and I register t
 | |
| 76 } | |
| 77 | |
| 78 // Currently, reconfiguring the source is not supported. | |
| 79 if (!MandatoryConstraintsMatch(current_constraints_, constraints)) { | |
| 80 callback.Run(this, false); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 // There might be multiple tracks attaching to the source while it is being | |
| 85 // configured. | |
| 86 constraints_callbacks_.push_back(callback); | |
| 87 CheckIfAdapterIsLive(); | |
| 88 | |
| 89 // TODO(perkj): Use the MediaStreamDependencyFactory for now to create the | |
| 90 // MediaStreamVideoTrack since creation is currently still depending on | |
| 91 // libjingle. The webrtc video track implementation will attach to the | |
| 92 // webrtc::VideoSourceInterface returned by GetAdapter() to receive video | |
| 93 // frames. | |
| 26 factory_->CreateNativeMediaStreamTrack(track); | 94 factory_->CreateNativeMediaStreamTrack(track); | 
| 27 } | 95 } | 
| 28 | 96 | 
| 29 void MediaStreamVideoSource::RemoveTrack( | 97 void MediaStreamVideoSource::RemoveTrack( | 
| 30 const blink::WebMediaStreamTrack& track) { | 98 const blink::WebMediaStreamTrack& track) { | 
| 31 // TODO(ronghuawu): What should be done here? Do we really need RemoveTrack? | 99 // TODO(ronghuawu): What should be done here? Do we really need RemoveTrack? | 
| 32 } | 100 } | 
| 33 | 101 | 
| 34 void MediaStreamVideoSource::Init() { | 102 void MediaStreamVideoSource::Init( | 
| 35 if (!adapter_) { | 103 const blink::WebMediaConstraints& constraints) { | 
| 36 const webrtc::MediaConstraintsInterface* constraints = NULL; | 104 DCHECK(!adapter_); | 
| 37 adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(), | 105 RTCMediaConstraints webrtc_constraints(constraints); | 
| 38 constraints); | 106 adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(), | 
| 39 } | 107 &webrtc_constraints); | 
| 40 } | 108 } | 
| 41 | 109 | 
| 42 void MediaStreamVideoSource::SetReadyState( | 110 void MediaStreamVideoSource::SetReadyState( | 
| 43 blink::WebMediaStreamSource::ReadyState state) { | 111 blink::WebMediaStreamSource::ReadyState state) { | 
| 44 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the | 112 // TODO(ronghuawu): Sets WebMediaStreamSource's ready state and notifies the | 
| 45 // ready state to all registered tracks. | 113 // ready state to all registered tracks. | 
| 46 } | 114 } | 
| 47 | 115 | 
| 48 void MediaStreamVideoSource::DeliverVideoFrame( | 116 void MediaStreamVideoSource::DeliverVideoFrame( | 
| 49 const scoped_refptr<media::VideoFrame>& frame) { | 117 const scoped_refptr<media::VideoFrame>& frame) { | 
| (...skipping 22 matching lines...) Expand all Loading... | |
| 72 const size_t pixel_height = 1; | 140 const size_t pixel_height = 1; | 
| 73 const int rotation = 0; | 141 const int rotation = 0; | 
| 74 cricket_frame.Alias(frame->data(0), size, | 142 cricket_frame.Alias(frame->data(0), size, | 
| 75 width_, height_, | 143 width_, height_, | 
| 76 pixel_width, pixel_height, | 144 pixel_width, pixel_height, | 
| 77 elapsed_time_ns, time_stamp_ns, | 145 elapsed_time_ns, time_stamp_ns, | 
| 78 rotation); | 146 rotation); | 
| 79 input->RenderFrame(&cricket_frame); | 147 input->RenderFrame(&cricket_frame); | 
| 80 } | 148 } | 
| 81 | 149 | 
| 82 MediaStreamVideoSource::~MediaStreamVideoSource() { | 150 void MediaStreamVideoSource::OnChanged() { | 
| 151 DCHECK(CalledOnValidThread()); | |
| 152 CheckIfAdapterIsLive(); | |
| 153 } | |
| 154 | |
| 155 void MediaStreamVideoSource::CheckIfAdapterIsLive() { | |
| 156 webrtc::VideoSourceInterface* webrtc_source = GetAdapter(); | |
| 157 | |
| 158 if (webrtc_source->state() == webrtc::MediaSourceInterface::kInitializing) | |
| 159 return; | |
| 160 | |
| 161 bool success = webrtc_source->state() == webrtc::MediaSourceInterface::kLive | |
| 162 ? true : false; | |
| 163 | |
| 164 if (initializing_) { | |
| 165 webrtc_source->UnregisterObserver(this); | |
| 166 initializing_ = false; | |
| 167 } | |
| 168 | |
| 169 std::vector<ConstraintsCallback> callbacks(constraints_callbacks_); | |
| 170 constraints_callbacks_.clear(); | |
| 171 | |
| 172 for (std::vector<ConstraintsCallback>::iterator it = callbacks.begin(); | |
| 173 it != callbacks.end(); ++it) { | |
| 174 if (!it->is_null()) | |
| 175 it->Run(this, success); | |
| 176 } | |
| 83 } | 177 } | 
| 84 | 178 | 
| 85 } // namespace content | 179 } // namespace content | 
| OLD | NEW |