Chromium Code Reviews| 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..88685e3b76c85823741aae376e7954b620e2902a |
| --- /dev/null |
| +++ b/media/cast/test/utility/in_process_receiver.cc |
| @@ -0,0 +1,155 @@ |
| +// 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), |
| + audio_sampling_frequency_(audio_config.frequency), |
| + weak_factory_(this) { |
| + cast_environment_->PostTask( |
| + CastEnvironment::MAIN, |
| + FROM_HERE, |
| + base::Bind(&InProcessReceiver::InitializeOnMainThread, |
| + weak_factory_.GetWeakPtr(), |
| + local_end_point, |
| + remote_end_point, |
| + audio_config, |
| + video_config)); |
| +} |
| + |
| +void InProcessReceiver::InitializeOnMainThread( |
| + const net::IPEndPoint& local_end_point, |
| + const net::IPEndPoint& remote_end_point, |
| + const AudioReceiverConfig& audio_config, |
| + const VideoReceiverConfig& video_config) { |
| + DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| + |
| + transport_.reset(new UdpTransport( |
| + NULL, |
| + cast_environment_->GetMessageSingleThreadTaskRunnerForThread( |
| + 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())); |
| +} |
| + |
| +InProcessReceiver::~InProcessReceiver() {} |
| + |
| +void InProcessReceiver::Start() { |
| + cast_environment_->PostTask(CastEnvironment::MAIN, |
| + FROM_HERE, |
| + base::Bind(&InProcessReceiver::StartOnMainThread, |
| + weak_factory_.GetWeakPtr())); |
| +} |
| + |
| +// static |
| +AudioReceiverConfig InProcessReceiver::GetDefaultAudioConfig() { |
| + AudioReceiverConfig config; |
| + config.feedback_ssrc = 1; |
| + config.incoming_ssrc = 2; |
| + config.rtp_payload_type = 127; |
| + config.rtcp_c_name = "audio_receiver@a.b.c.d"; |
| + config.use_external_decoder = false; |
| + config.frequency = 48000; |
| + config.channels = 2; |
| + config.codec = media::cast::transport::kOpus; |
| + return config; |
| +} |
| + |
| +// static |
| +VideoReceiverConfig InProcessReceiver::GetDefaultVideoConfig() { |
| + VideoReceiverConfig config; |
| + config.feedback_ssrc = 12; |
| + config.incoming_ssrc = 11; |
| + config.rtp_payload_type = 96; |
| + config.rtcp_c_name = "video_receiver@a.b.c.d"; |
| + config.use_external_decoder = false; |
| + config.codec = media::cast::transport::kVp8; |
| + return config; |
| +} |
| + |
| +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_); |
| + // TODO(hubbe): Make the cast receiver do this automatically. |
| + transport_->StartReceiving(cast_receiver_->packet_receiver()); |
| + |
| + DCHECK(cast_receiver_); |
| + PullNextAudioFrame(); |
| + PullNextVideoFrame(); |
| +} |
| + |
| +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)); |
| + cast_receiver_->frame_receiver()->GetRawAudioFrame( |
| + 1 /* 10 ms of samples */, |
| + audio_sampling_frequency_, |
| + base::Bind(&InProcessReceiver::GotAudioFrame, |
| + weak_factory_.GetWeakPtr())); |
| + // TODO(miu): Fix audio decoder so that it never drops a request for the next |
|
hubbe
2014/03/04 22:42:26
File a bug for this.
miu
2014/03/06 06:09:15
Already is one open. Added link.
|
| + // frame of audio. Once fixed, remove this, and add PullNextAudioFrame() to |
| + // the end of GotAudioFrame(), so that it behaves just like GotVideoFrame(). |
| + cast_environment_->PostDelayedTask( |
| + CastEnvironment::MAIN, |
| + FROM_HERE, |
| + base::Bind(&InProcessReceiver::PullNextAudioFrame, |
| + weak_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromMilliseconds(10)); |
| +} |
| + |
| +void InProcessReceiver::PullNextVideoFrame() { |
| + DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| + cast_receiver_->frame_receiver()->GetRawVideoFrame(base::Bind( |
| + &InProcessReceiver::GotVideoFrame, weak_factory_.GetWeakPtr())); |
| +} |
| + |
| +} // namespace cast |
| +} // namespace media |