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

Unified Diff: chrome/renderer/media/cast_receiver_session_delegate.cc

Issue 883293005: Cast: Basic cast_receiver API for chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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: chrome/renderer/media/cast_receiver_session_delegate.cc
diff --git a/chrome/renderer/media/cast_receiver_session_delegate.cc b/chrome/renderer/media/cast_receiver_session_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a984c6bfa6abc5cb929c2ceab430c6669403accf
--- /dev/null
+++ b/chrome/renderer/media/cast_receiver_session_delegate.cc
@@ -0,0 +1,103 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/media/cast_receiver_session_delegate.h"
+
+#include "base/synchronization/waitable_event.h"
+#include "base/values.h"
+
+CastReceiverSessionDelegate::CastReceiverSessionDelegate()
+ : weak_factory_(this) {
+}
+CastReceiverSessionDelegate::~CastReceiverSessionDelegate() {}
+
+void CastReceiverSessionDelegate::LogRawEvents(
+ const std::vector<media::cast::PacketEvent>& packet_events,
+ const std::vector<media::cast::FrameEvent>& frame_events) {
+ NOTREACHED();
+}
+
+void CastReceiverSessionDelegate::Start(
+ const media::cast::FrameReceiverConfig& audio_config,
+ const media::cast::FrameReceiverConfig& video_config,
+ const net::IPEndPoint& local_endpoint,
+ const net::IPEndPoint& remote_endpoint,
+ scoped_ptr<base::DictionaryValue> options,
+ const media::VideoCaptureFormat& format) {
+ format_ = format;
+ DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
+ CastSessionDelegateBase::StartUDP(local_endpoint,
+ remote_endpoint,
+ options.Pass());
+ cast_receiver_ = media::cast::CastReceiver::Create(cast_environment_,
+ audio_config,
+ video_config,
+ cast_transport_.get());
+ on_audio_decoded_cb_ = base::Bind(
+ &CastReceiverSessionDelegate::OnDecodedAudioFrame,
+ weak_factory_.GetWeakPtr());
+ on_video_decoded_cb_ = base::Bind(
+ &CastReceiverSessionDelegate::OnDecodedVideoFrame,
+ weak_factory_.GetWeakPtr());
+}
+
+void CastReceiverSessionDelegate::StartAudio(AudioCB audio_callback) {
+ DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
+ audio_callback_ = audio_callback;
+ cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_);
+}
+
+void CastReceiverSessionDelegate::StopAudio(base::WaitableEvent* event) {
+ audio_callback_ = AudioCB();
+ cast_environment_->PostTask(media::cast::CastEnvironment::AUDIO,
+ FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal,
+ base::Unretained(event)));
+}
+
+void CastReceiverSessionDelegate::OnDecodedAudioFrame(
+ scoped_ptr<media::AudioBus> audio_bus,
+ const base::TimeTicks& playout_time,
+ bool is_continous) {
+ if (audio_callback_.is_null())
+ return;
+
+ // We're on the IO thread, which doesn't allow blocking
+ // operations. Since we don't know what the Capture callback
+ // will do exactly, we need to jump to a different thread.
+ // Let's re-use the audio decoder thread.
+ base::TimeTicks now = cast_environment_->Clock()->NowTicks();
+ cast_environment_->PostTask(
+ media::cast::CastEnvironment::AUDIO,
+ FROM_HERE,
+ base::Bind(audio_callback_,
+ base::Owned(audio_bus.release()),
+ (playout_time - now).InMilliseconds(),
+ 1.0,
+ false));
+ cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_);
+}
+
+void CastReceiverSessionDelegate::StartVideo(
+ content::VideoCaptureDeliverFrameCB video_callback) {
Alpha Left Google 2015/02/04 03:07:52 This callback passed from CastVideoCapturerSource
hubbe 2015/02/05 20:23:00 Done.
+ DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
+ frame_callback_ = video_callback;
+ cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_);
+}
+
Alpha Left Google 2015/02/04 03:07:52 nit: empty line.
hubbe 2015/02/05 20:23:00 Done.
+
+void CastReceiverSessionDelegate::StopVideo(base::WaitableEvent* event) {
+ frame_callback_ = content::VideoCaptureDeliverFrameCB();
+ event->Signal();
+}
+
+void CastReceiverSessionDelegate::OnDecodedVideoFrame(
+ const scoped_refptr<media::VideoFrame>& video_frame,
+ const base::TimeTicks& playout_time,
+ bool is_continous) {
+ if (frame_callback_.is_null())
+ return;
+ frame_callback_.Run(video_frame, format_, playout_time);
+ cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_);
+}

Powered by Google App Engine
This is Rietveld 408576698