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

Unified Diff: media/cast/test/utility/in_process_receiver.cc

Issue 184813009: Cast Streaming API end-to-end browser_test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed hubbe's comments, and fixed threading/shutdown issues. Created 6 years, 9 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: media/cast/test/utility/in_process_receiver.cc
diff --git a/media/cast/test/utility/in_process_receiver.cc b/media/cast/test/utility/in_process_receiver.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c7a72ae1f08b8ea11252708ce0375ac5b418941f
--- /dev/null
+++ b/media/cast/test/utility/in_process_receiver.cc
@@ -0,0 +1,128 @@
+// Copyright 2014 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 "media/cast/test/utility/in_process_receiver.h"
+
+#include "base/bind_helpers.h"
+#include "base/time/time.h"
+#include "media/base/video_frame.h"
+#include "media/cast/cast_config.h"
+#include "media/cast/cast_environment.h"
+#include "media/cast/cast_receiver.h"
+#include "media/cast/transport/cast_transport_config.h"
+#include "media/cast/transport/transport/udp_transport.h"
+
+using media::cast::transport::CastTransportStatus;
+using media::cast::transport::UdpTransport;
+
+namespace media {
+namespace cast {
+
+InProcessReceiver::InProcessReceiver(
+ const scoped_refptr<CastEnvironment>& cast_environment,
+ const net::IPEndPoint& local_end_point,
+ const net::IPEndPoint& remote_end_point,
+ const AudioReceiverConfig& audio_config,
+ const VideoReceiverConfig& video_config)
+ : cast_environment_(cast_environment),
+ local_end_point_(local_end_point),
+ remote_end_point_(remote_end_point),
+ audio_config_(audio_config),
+ video_config_(video_config) {}
+
+InProcessReceiver::~InProcessReceiver() {}
+
+void InProcessReceiver::Start() {
+ cast_environment_->PostTask(
+ CastEnvironment::MAIN,
+ FROM_HERE,
+ base::Bind(&InProcessReceiver::StartOnMainThread, this));
+}
+
+void InProcessReceiver::StopSoon() {
+ cast_environment_->PostTask(
+ CastEnvironment::MAIN,
+ FROM_HERE,
+ base::Bind(&InProcessReceiver::StopOnMainThread, this));
+}
+
+void InProcessReceiver::UpdateCastTransportStatus(CastTransportStatus status) {
+ LOG_IF(ERROR, status == media::cast::transport::TRANSPORT_SOCKET_ERROR)
+ << "Transport socket error occurred. InProcessReceiver is likely dead.";
+ VLOG(1) << "CastTransportStatus is now " << status;
+}
+
+void InProcessReceiver::StartOnMainThread() {
+ DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
+
+ DCHECK(!transport_ && !cast_receiver_);
+
+ transport_.reset(
+ new UdpTransport(NULL,
+ cast_environment_->GetTaskRunner(CastEnvironment::MAIN),
+ local_end_point_,
+ remote_end_point_,
+ base::Bind(&InProcessReceiver::UpdateCastTransportStatus,
+ base::Unretained(this))));
+ cast_receiver_.reset(CastReceiver::CreateCastReceiver(
+ cast_environment_, audio_config_, video_config_, transport_.get()));
+
+ // TODO(hubbe): Make the cast receiver do this automatically.
+ transport_->StartReceiving(cast_receiver_->packet_receiver());
+
+ PullNextAudioFrame();
+ PullNextVideoFrame();
+}
+
+void InProcessReceiver::StopOnMainThread() {
+ DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
+
+ cast_receiver_.reset();
+ transport_.reset();
+}
+
+void InProcessReceiver::GotAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame,
+ const base::TimeTicks& playout_time) {
+ DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
+ OnAudioFrame(audio_frame.Pass(), playout_time);
+ // TODO(miu): Put this back here: PullNextAudioFrame();
+}
+
+void InProcessReceiver::GotVideoFrame(
+ const scoped_refptr<VideoFrame>& video_frame,
+ const base::TimeTicks& render_time) {
+ DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
+ OnVideoFrame(video_frame, render_time);
+ PullNextVideoFrame();
+}
+
+void InProcessReceiver::PullNextAudioFrame() {
+ DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
+ if (!cast_receiver_)
+ return;
+ cast_receiver_->frame_receiver()->GetRawAudioFrame(
+ 1 /* 10 ms of samples */,
+ audio_config_.frequency,
+ base::Bind(&InProcessReceiver::GotAudioFrame, this));
+ // TODO(miu): Fix audio decoder so that it never drops a request for the next
+ // frame of audio. Once fixed, remove this, and add PullNextAudioFrame() to
+ // the end of GotAudioFrame(), so that it behaves just like GotVideoFrame().
+ // http://crbug.com/347361
+ cast_environment_->PostDelayedTask(
+ CastEnvironment::MAIN,
+ FROM_HERE,
+ base::Bind(&InProcessReceiver::PullNextAudioFrame, this),
+ base::TimeDelta::FromMilliseconds(10));
+}
+
+void InProcessReceiver::PullNextVideoFrame() {
+ DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
+ if (!cast_receiver_)
+ return;
+ cast_receiver_->frame_receiver()->GetRawVideoFrame(
+ base::Bind(&InProcessReceiver::GotVideoFrame, this));
+}
+
+} // namespace cast
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698