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

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..b0fe08d6e22261fb9def87c7fce98511b1d9145c 100644
--- a/content/renderer/media/media_stream_video_source.cc
+++ b/content/renderer/media/media_stream_video_source.cc
@@ -5,21 +5,44 @@
#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"
perkj_chrome 2014/01/14 08:29:10 media_stream_source_extra_data.h is not needed her
Ronghua Wu (Left Chromium) 2014/01/14 19:42:10 Done.
+#include "content/renderer/render_thread_impl.h"
+#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
perkj_chrome 2014/01/14 08:29:10 unused?
Ronghua Wu (Left Chromium) 2014/01/14 19:42:10 Done.
+#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,
+ webrtc::VideoSourceInterface* adapter)
+ : factory_(factory),
+ adapter_(adapter),
+ width_(0),
+ height_(0),
+ first_frame_timestamp_(media::kNoTimestamp()) {
+ if (!factory_) {
perkj_chrome 2014/01/14 08:29:10 I would prefer to always incject the factory for n
Ronghua Wu (Left Chromium) 2014/01/14 19:42:10 Done.
+ factory_ = RenderThreadImpl::current()->GetMediaStreamDependencyFactory();
+ DCHECK(factory_ != NULL);
+ }
+ if (!adapter_) {
+ adapter_ = factory_->CreateVideoSource(new webrtc::RemoteVideoCapturer(),
+ NULL);
+ }
+}
+
+bool MediaStreamVideoSource::AddTrack(
perkj_chrome 2014/01/14 08:29:10 why bool ?
Ronghua Wu (Left Chromium) 2014/01/14 19:42:10 Done.
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|.
+ 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?
+ return true;
}
void MediaStreamVideoSource::SetReadyState(
@@ -30,7 +53,32 @@ void MediaStreamVideoSource::SetReadyState(
void MediaStreamVideoSource::DeliverVideoFrame(
const scoped_refptr<media::VideoFrame>& frame) {
- // TODO(ronghuawu): Deliver |frame| to all the registered tracks.
+ if (first_frame_timestamp_ == media::kNoTimestamp()) {
+ first_frame_timestamp_ = frame->GetTimestamp();
+ }
+
+ 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): we assume contiguous layout of image planes and
+ // FOURCC_I420.
+ int64 elapsed_time =
+ (frame->GetTimestamp() - first_frame_timestamp_).InMicroseconds() *
+ base::Time::kNanosecondsPerMicrosecond;
+ int64 time_stamp = frame->GetTimestamp().InMicroseconds() *
+ base::Time::kNanosecondsPerMicrosecond;
+ size_t size =
+ media::VideoFrame::AllocationSize(frame->format(), frame->coded_size());
+ cricket_frame.Alias(frame->data(0), size, width_, height_,
+ 1, 1, elapsed_time, time_stamp, 0);
perkj_chrome 2014/01/14 08:29:10 nit, fits on line above.
Ronghua Wu (Left Chromium) 2014/01/14 19:42:10 It doesn't actually.
+ input->RenderFrame(&cricket_frame);
}
MediaStreamVideoSource::~MediaStreamVideoSource() {

Powered by Google App Engine
This is Rietveld 408576698