Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cast/transport/rtp_sender/rtp_sender.h" | 5 #include "media/cast/transport/rtp_sender/rtp_sender.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "media/cast/transport/cast_transport_defines.h" | 9 #include "media/cast/transport/cast_transport_defines.h" |
| 10 #include "media/cast/transport/pacing/paced_sender.h" | 10 #include "media/cast/transport/pacing/paced_sender.h" |
| 11 #include "net/base/big_endian.h" | 11 #include "net/base/big_endian.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 namespace cast { | 14 namespace cast { |
| 15 namespace transport { | 15 namespace transport { |
| 16 | 16 |
| 17 // Schedule the RTP statistics callback every 100mS. | 17 // Schedule the RTP statistics callback every 33mS. |
|
pwestin
2014/02/12 21:16:43
explain why 33
mikhal1
2014/02/12 23:21:05
Done.
| |
| 18 static const int kStatsCallbackIntervalMs = 100; | 18 static const int kStatsCallbackIntervalMs = 33; |
| 19 | 19 |
| 20 RtpSender::RtpSender( | 20 RtpSender::RtpSender( |
| 21 base::TickClock* clock, | 21 base::TickClock* clock, |
| 22 const CastTransportConfig& config, | 22 const CastTransportConfig& config, |
| 23 bool is_audio, | 23 bool is_audio, |
| 24 const scoped_refptr<base::TaskRunner>& transport_task_runner, | 24 const scoped_refptr<base::TaskRunner>& transport_task_runner, |
| 25 PacedSender* const transport) | 25 PacedSender* const transport) |
| 26 : clock_(clock), | 26 : config_(), |
| 27 config_(), | |
| 28 transport_(transport), | 27 transport_(transport), |
| 29 stats_callback_(), | 28 stats_callback_(), |
| 30 transport_task_runner_(transport_task_runner) { | 29 transport_task_runner_(transport_task_runner) { |
| 31 // Store generic cast config and create packetizer config. | 30 // Store generic cast config and create packetizer config. |
| 32 if (is_audio) { | 31 if (is_audio) { |
| 33 storage_.reset( | 32 storage_.reset( |
| 34 new PacketStorage(clock, config.audio_rtp_config.history_ms)); | 33 new PacketStorage(clock, config.audio_rtp_config.history_ms)); |
| 35 config_.audio = true; | 34 config_.audio = true; |
| 36 config_.ssrc = config.audio_ssrc; | 35 config_.ssrc = config.audio_ssrc; |
| 37 config_.payload_type = config.audio_rtp_config.payload_type; | 36 config_.payload_type = config.audio_rtp_config.payload_type; |
| 38 config_.frequency = config.audio_frequency; | 37 config_.frequency = config.audio_frequency; |
| 39 config_.audio_codec = config.audio_codec; | 38 config_.audio_codec = config.audio_codec; |
| 40 } else { | 39 } else { |
| 41 storage_.reset( | 40 storage_.reset( |
| 42 new PacketStorage(clock, config.audio_rtp_config.history_ms)); | 41 new PacketStorage(clock, config.audio_rtp_config.history_ms)); |
| 43 config_.audio = false; | 42 config_.audio = false; |
| 44 config_.ssrc = config.video_ssrc; | 43 config_.ssrc = config.video_ssrc; |
| 45 config_.payload_type = config.video_rtp_config.payload_type; | 44 config_.payload_type = config.video_rtp_config.payload_type; |
| 46 config_.frequency = kVideoFrequency; | 45 config_.frequency = kVideoFrequency; |
| 47 config_.video_codec = config.video_codec; | 46 config_.video_codec = config.video_codec; |
| 48 } | 47 } |
| 49 // Randomly set start values. | 48 // Randomly set start values. |
| 50 config_.sequence_number = base::RandInt(0, 65535); | 49 config_.sequence_number = base::RandInt(0, 65535); |
| 51 packetizer_.reset(new RtpPacketizer(transport, storage_.get(), config_)); | 50 packetizer_.reset( |
| 51 new RtpPacketizer(transport, storage_.get(), config_)); | |
| 52 } | 52 } |
| 53 | 53 |
| 54 RtpSender::~RtpSender() {} | 54 RtpSender::~RtpSender() {} |
| 55 | 55 |
| 56 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, | 56 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, |
| 57 const base::TimeTicks& capture_time) { | 57 const base::TimeTicks& capture_time) { |
| 58 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); | 58 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void RtpSender::IncomingEncodedAudioFrame( | 61 void RtpSender::IncomingEncodedAudioFrame( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 131 |
| 132 void RtpSender::ScheduleNextStatsReport() { | 132 void RtpSender::ScheduleNextStatsReport() { |
| 133 transport_task_runner_->PostDelayedTask( | 133 transport_task_runner_->PostDelayedTask( |
| 134 FROM_HERE, | 134 FROM_HERE, |
| 135 base::Bind(&RtpSender::RtpStatistics, base::Unretained(this)), | 135 base::Bind(&RtpSender::RtpStatistics, base::Unretained(this)), |
| 136 base::TimeDelta::FromMilliseconds(kStatsCallbackIntervalMs)); | 136 base::TimeDelta::FromMilliseconds(kStatsCallbackIntervalMs)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void RtpSender::RtpStatistics() { | 139 void RtpSender::RtpStatistics() { |
| 140 RtcpSenderInfo sender_info; | 140 RtcpSenderInfo sender_info; |
| 141 uint32 ntp_seconds = 0; | |
| 142 uint32 ntp_fraction = 0; | |
| 143 ConvertTimeTicksToNtp(clock_->NowTicks(), &ntp_seconds, &ntp_fraction); | |
| 144 sender_info.ntp_seconds = ntp_seconds; | |
| 145 sender_info.ntp_fraction = ntp_fraction; | |
| 146 | |
| 147 base::TimeTicks time_sent; | 141 base::TimeTicks time_sent; |
| 148 uint32 rtp_timestamp = 0; | 142 uint32 rtp_timestamp = 0; |
| 149 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); | 143 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); |
| 150 sender_info.send_packet_count = packetizer_->send_packets_count(); | 144 sender_info.send_packet_count = packetizer_->send_packets_count(); |
| 151 sender_info.send_octet_count = packetizer_->send_octet_count(); | 145 sender_info.send_octet_count = packetizer_->send_octet_count(); |
| 152 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); | 146 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); |
| 153 ScheduleNextStatsReport(); | 147 ScheduleNextStatsReport(); |
| 154 } | 148 } |
| 155 | 149 |
| 156 } // namespace transport | 150 } // namespace transport |
| 157 } // namespace cast | 151 } // namespace cast |
| 158 } // namespace media | 152 } // namespace media |
| OLD | NEW |