Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/cast/test/utility/in_process_receiver.h" | |
| 6 | |
| 7 #include "base/bind_helpers.h" | |
| 8 #include "base/time/time.h" | |
| 9 #include "media/base/video_frame.h" | |
| 10 #include "media/cast/cast_config.h" | |
| 11 #include "media/cast/cast_environment.h" | |
| 12 #include "media/cast/cast_receiver.h" | |
| 13 #include "media/cast/transport/cast_transport_config.h" | |
| 14 #include "media/cast/transport/transport/udp_transport.h" | |
| 15 | |
| 16 using media::cast::transport::CastTransportStatus; | |
| 17 using media::cast::transport::UdpTransport; | |
| 18 | |
| 19 namespace media { | |
| 20 namespace cast { | |
| 21 | |
| 22 InProcessReceiver::InProcessReceiver( | |
| 23 const scoped_refptr<CastEnvironment>& cast_environment, | |
| 24 const net::IPEndPoint& local_end_point, | |
| 25 const net::IPEndPoint& remote_end_point, | |
| 26 const AudioReceiverConfig& audio_config, | |
| 27 const VideoReceiverConfig& video_config) | |
| 28 : cast_environment_(cast_environment), | |
| 29 audio_sampling_frequency_(audio_config.frequency), | |
| 30 weak_factory_(this) { | |
| 31 cast_environment_->PostTask( | |
| 32 CastEnvironment::MAIN, | |
| 33 FROM_HERE, | |
| 34 base::Bind(&InProcessReceiver::InitializeOnMainThread, | |
| 35 weak_factory_.GetWeakPtr(), | |
| 36 local_end_point, | |
| 37 remote_end_point, | |
| 38 audio_config, | |
| 39 video_config)); | |
| 40 } | |
| 41 | |
| 42 void InProcessReceiver::InitializeOnMainThread( | |
| 43 const net::IPEndPoint& local_end_point, | |
| 44 const net::IPEndPoint& remote_end_point, | |
| 45 const AudioReceiverConfig& audio_config, | |
| 46 const VideoReceiverConfig& video_config) { | |
| 47 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | |
| 48 | |
| 49 transport_.reset(new UdpTransport( | |
| 50 NULL, | |
| 51 cast_environment_->GetMessageSingleThreadTaskRunnerForThread( | |
| 52 CastEnvironment::MAIN), | |
| 53 local_end_point, | |
| 54 remote_end_point, | |
| 55 base::Bind(&InProcessReceiver::UpdateCastTransportStatus, | |
| 56 base::Unretained(this)))); | |
| 57 | |
| 58 cast_receiver_.reset(CastReceiver::CreateCastReceiver( | |
| 59 cast_environment_, audio_config, video_config, transport_.get())); | |
| 60 } | |
| 61 | |
| 62 InProcessReceiver::~InProcessReceiver() {} | |
| 63 | |
| 64 void InProcessReceiver::Start() { | |
| 65 cast_environment_->PostTask(CastEnvironment::MAIN, | |
| 66 FROM_HERE, | |
| 67 base::Bind(&InProcessReceiver::StartOnMainThread, | |
| 68 weak_factory_.GetWeakPtr())); | |
| 69 } | |
| 70 | |
| 71 // static | |
| 72 AudioReceiverConfig InProcessReceiver::GetDefaultAudioConfig() { | |
| 73 AudioReceiverConfig config; | |
| 74 config.feedback_ssrc = 1; | |
| 75 config.incoming_ssrc = 2; | |
| 76 config.rtp_payload_type = 127; | |
| 77 config.rtcp_c_name = "audio_receiver@a.b.c.d"; | |
| 78 config.use_external_decoder = false; | |
| 79 config.frequency = 48000; | |
| 80 config.channels = 2; | |
| 81 config.codec = media::cast::transport::kOpus; | |
| 82 return config; | |
| 83 } | |
| 84 | |
| 85 // static | |
| 86 VideoReceiverConfig InProcessReceiver::GetDefaultVideoConfig() { | |
| 87 VideoReceiverConfig config; | |
| 88 config.feedback_ssrc = 12; | |
| 89 config.incoming_ssrc = 11; | |
| 90 config.rtp_payload_type = 96; | |
| 91 config.rtcp_c_name = "video_receiver@a.b.c.d"; | |
| 92 config.use_external_decoder = false; | |
| 93 config.codec = media::cast::transport::kVp8; | |
| 94 return config; | |
| 95 } | |
| 96 | |
| 97 void InProcessReceiver::UpdateCastTransportStatus(CastTransportStatus status) { | |
| 98 LOG_IF(ERROR, status == media::cast::transport::TRANSPORT_SOCKET_ERROR) | |
| 99 << "Transport socket error occurred. InProcessReceiver is likely dead."; | |
| 100 VLOG(1) << "CastTransportStatus is now " << status; | |
| 101 } | |
| 102 | |
| 103 void InProcessReceiver::StartOnMainThread() { | |
| 104 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | |
| 105 | |
| 106 DCHECK(transport_); | |
| 107 // TODO(hubbe): Make the cast receiver do this automatically. | |
| 108 transport_->StartReceiving(cast_receiver_->packet_receiver()); | |
| 109 | |
| 110 DCHECK(cast_receiver_); | |
| 111 PullNextAudioFrame(); | |
| 112 PullNextVideoFrame(); | |
| 113 } | |
| 114 | |
| 115 void InProcessReceiver::GotAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame, | |
| 116 const base::TimeTicks& playout_time) { | |
| 117 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | |
| 118 OnAudioFrame(audio_frame.Pass(), playout_time); | |
| 119 // TODO(miu): Put this back here: PullNextAudioFrame(); | |
| 120 } | |
| 121 | |
| 122 void InProcessReceiver::GotVideoFrame( | |
| 123 const scoped_refptr<VideoFrame>& video_frame, | |
| 124 const base::TimeTicks& render_time) { | |
| 125 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | |
| 126 OnVideoFrame(video_frame, render_time); | |
| 127 PullNextVideoFrame(); | |
| 128 } | |
| 129 | |
| 130 void InProcessReceiver::PullNextAudioFrame() { | |
| 131 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | |
| 132 cast_receiver_->frame_receiver()->GetRawAudioFrame( | |
| 133 1 /* 10 ms of samples */, | |
| 134 audio_sampling_frequency_, | |
| 135 base::Bind(&InProcessReceiver::GotAudioFrame, | |
| 136 weak_factory_.GetWeakPtr())); | |
| 137 // 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.
| |
| 138 // frame of audio. Once fixed, remove this, and add PullNextAudioFrame() to | |
| 139 // the end of GotAudioFrame(), so that it behaves just like GotVideoFrame(). | |
| 140 cast_environment_->PostDelayedTask( | |
| 141 CastEnvironment::MAIN, | |
| 142 FROM_HERE, | |
| 143 base::Bind(&InProcessReceiver::PullNextAudioFrame, | |
| 144 weak_factory_.GetWeakPtr()), | |
| 145 base::TimeDelta::FromMilliseconds(10)); | |
| 146 } | |
| 147 | |
| 148 void InProcessReceiver::PullNextVideoFrame() { | |
| 149 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | |
| 150 cast_receiver_->frame_receiver()->GetRawVideoFrame(base::Bind( | |
| 151 &InProcessReceiver::GotVideoFrame, weak_factory_.GetWeakPtr())); | |
| 152 } | |
| 153 | |
| 154 } // namespace cast | |
| 155 } // namespace media | |
| OLD | NEW |