 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 | 
| 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(), | 
| 
no longer working on chromium
2014/01/17 14:51:51
can we change the CreateVideoSource to use blink::
 
perkj_chrome
2014/01/19 15:52:39
I guess we can but Ronghua seemed to prefer to kee
 | |
| 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() { | |
| 
no longer working on chromium
2014/01/17 14:51:51
in which thread this method is called?
 
perkj_chrome
2014/01/19 15:52:39
This is an internal method so see where it is call
 | |
| 123 webrtc::VideoSourceInterface* webrtc_source = GetAdapter(); | |
| 124 | |
| 125 if (webrtc_source->state() == webrtc::MediaSourceInterface::kInitializing) | |
| 126 return; | |
| 127 | |
| 128 bool success = webrtc_source->state() == webrtc::MediaSourceInterface::kLive | |
| 129 ? true : false; | |
| 130 | |
| 131 if (initializing_) { | |
| 132 webrtc_source->UnregisterObserver(this); | |
| 133 initializing_ = false; | |
| 
no longer working on chromium
2014/01/17 14:51:51
don't you need to call adapter_->UnregisterObserve
 
perkj_chrome
2014/01/19 15:52:39
ptal. I had forgot to change GetAdapter to adapter
 | |
| 134 } | |
| 135 | |
| 136 std::vector<ConstraintsCallback> callbacks(constraints_callbacks_); | |
| 137 constraints_callbacks_.clear(); | |
| 138 | |
| 139 for (std::vector<ConstraintsCallback>::iterator it = callbacks.begin(); | |
| 140 it != callbacks.end(); ++it) { | |
| 141 if (!it->is_null()) | |
| 
no longer working on chromium
2014/01/17 14:51:51
can the callback be null?
 
perkj_chrome
2014/01/19 15:52:39
I have never really understood when / if is_null c
 | |
| 142 it->Run(this, success); | |
| 143 } | |
| 83 } | 144 } | 
| 84 | 145 | 
| 85 } // namespace content | 146 } // namespace content | 
| OLD | NEW |