Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2089)

Unified Diff: content/renderer/media/media_stream_video_source.cc

Issue 129923002: Implements MediaStreamVideoSource. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_video_source.cc
diff --git a/content/renderer/media/media_stream_video_source.cc b/content/renderer/media/media_stream_video_source.cc
index acdb7dfc9012677655a044d41e43688d08d1cde3..c0d9f956fd8e4026c4aa28d36a9cdf1b5642ae25 100644
--- a/content/renderer/media/media_stream_video_source.cc
+++ b/content/renderer/media/media_stream_video_source.cc
@@ -5,21 +5,58 @@
#include "content/renderer/media/media_stream_video_source.h"
#include "base/logging.h"
-#include "content/public/renderer/media_stream_video_sink.h"
+#include "content/renderer/media/media_stream_dependency_factory.h"
+#include "content/renderer/media/media_stream_source_extra_data.h"
+#include "content/renderer/render_thread_impl.h"
+#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
+#include "third_party/libjingle/source/talk/app/webrtc/remotevideocapturer.h"
+#include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h"
namespace content {
-void MediaStreamVideoSource::AddTrack(
+MediaStreamVideoSource::MediaStreamVideoSource(
+ MediaStreamDependencyFactory* factory)
+ : factory_(factory),
+ width_(0),
+ height_(0) {
+}
+
+bool MediaStreamVideoSource::Init() {
+ if (!factory_) {
perkj_chrome 2014/01/10 13:07:00 You might want to use dependency injection of the
Ronghua Wu (Left Chromium) 2014/01/11 01:22:58 I do have the injection, see the ctor. Regarding
+ factory_ = RenderThreadImpl::current()->GetMediaStreamDependencyFactory();
+ DCHECK(factory_ != NULL);
+ }
+ blink::WebMediaConstraints constraints;
+ adapter_ = factory_->CreateVideoSource(
+ new webrtc::RemoteVideoCapturer(), constraints);
+ return true;
+}
+
+bool MediaStreamVideoSource::AddTrack(
const blink::WebMediaStreamTrack& track,
const blink::WebMediaConstraints& constraints) {
- // TODO(ronghuawu): Put |track| in the registered tracks list. Will later
- // deliver frames to it according to |constraints|.
+ // WebMediaStreamTrack init requires WebMediaStreamSource, so assuming it's
+ // not null at this point.
+ if (track.isNull() || track.source().isNull()) {
+ return false;
+ }
+ blink::WebMediaStreamSource source = track.source();
perkj_chrome 2014/01/10 13:07:00 This seem wrong. The source already has extra data
Ronghua Wu (Left Chromium) 2014/01/11 01:22:58 The idea is before a track is add/associated with
+ if (source.extraData()) {
+ // The track has already associated with a native source.
+ return false;
+ }
+ MediaStreamSourceExtraData* source_data = new MediaStreamSourceExtraData();
+ source_data->SetVideoSource(adapter_.get());
+ source.setExtraData(source_data);
+
+ factory_->CreateNativeMediaStreamTrack(track);
+ return true;
}
-void MediaStreamVideoSource::RemoveTrack(
+bool MediaStreamVideoSource::RemoveTrack(
const blink::WebMediaStreamTrack& track) {
- // TODO(ronghuawu): Remove |track| from the list, i.e. will stop delivering
- // frame to |track|.
+ // TODO(ronghuawu): What can be done here? Do we need RemoveTrack or how?
perkj_chrome 2014/01/10 13:07:00 This means that a track is being destroyed by webk
Ronghua Wu (Left Chromium) 2014/01/11 01:22:58 Ack
+ return true;
}
void MediaStreamVideoSource::SetReadyState(
@@ -30,7 +67,19 @@ void MediaStreamVideoSource::SetReadyState(
void MediaStreamVideoSource::DeliverVideoFrame(
const scoped_refptr<media::VideoFrame>& frame) {
- // TODO(ronghuawu): Deliver |frame| to all the registered tracks.
+ cricket::VideoRenderer* input = adapter_->FrameInput();
+
+ if (width_ != frame->coded_size().width() ||
+ height_ != frame->coded_size().height()) {
+ width_ = frame->coded_size().width();
+ height_ = frame->coded_size().height();
+ const int reserved = 0;
+ input->SetSize(width_, height_, reserved);
+ }
+
+ cricket::WebRtcVideoFrame cricket_frame;
+ // TODO(ronghuawu): convert from media::VideoFrame to cricket::VideoFrame.
perkj_chrome 2014/01/10 13:07:00 Take a look at RTCVideoCapture to see how we conve
+ input->RenderFrame(&cricket_frame);
}
MediaStreamVideoSource::~MediaStreamVideoSource() {

Powered by Google App Engine
This is Rietveld 408576698