| 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. As this interval affects the |
| 18 static const int kStatsCallbackIntervalMs = 100; | 18 // time offset of the render and playout times, we want it in the same ball park |
| 19 // as the frame rate. |
| 20 static const int kStatsCallbackIntervalMs = 33; |
| 19 | 21 |
| 20 RtpSender::RtpSender( | 22 RtpSender::RtpSender( |
| 21 base::TickClock* clock, | 23 base::TickClock* clock, |
| 22 const CastTransportConfig& config, | 24 const CastTransportConfig& config, |
| 23 bool is_audio, | 25 bool is_audio, |
| 24 const scoped_refptr<base::TaskRunner>& transport_task_runner, | 26 const scoped_refptr<base::TaskRunner>& transport_task_runner, |
| 25 PacedSender* const transport) | 27 PacedSender* const transport) |
| 26 : clock_(clock), | 28 : config_(), |
| 27 config_(), | |
| 28 transport_(transport), | 29 transport_(transport), |
| 29 stats_callback_(), | 30 stats_callback_(), |
| 30 transport_task_runner_(transport_task_runner) { | 31 transport_task_runner_(transport_task_runner) { |
| 31 // Store generic cast config and create packetizer config. | 32 // Store generic cast config and create packetizer config. |
| 32 if (is_audio) { | 33 if (is_audio) { |
| 33 storage_.reset( | 34 storage_.reset( |
| 34 new PacketStorage(clock, config.audio_rtp_config.history_ms)); | 35 new PacketStorage(clock, config.audio_rtp_config.history_ms)); |
| 35 config_.audio = true; | 36 config_.audio = true; |
| 36 config_.ssrc = config.audio_ssrc; | 37 config_.ssrc = config.audio_ssrc; |
| 37 config_.payload_type = config.audio_rtp_config.payload_type; | 38 config_.payload_type = config.audio_rtp_config.payload_type; |
| 38 config_.frequency = config.audio_frequency; | 39 config_.frequency = config.audio_frequency; |
| 39 config_.audio_codec = config.audio_codec; | 40 config_.audio_codec = config.audio_codec; |
| 40 } else { | 41 } else { |
| 41 storage_.reset( | 42 storage_.reset( |
| 42 new PacketStorage(clock, config.audio_rtp_config.history_ms)); | 43 new PacketStorage(clock, config.audio_rtp_config.history_ms)); |
| 43 config_.audio = false; | 44 config_.audio = false; |
| 44 config_.ssrc = config.video_ssrc; | 45 config_.ssrc = config.video_ssrc; |
| 45 config_.payload_type = config.video_rtp_config.payload_type; | 46 config_.payload_type = config.video_rtp_config.payload_type; |
| 46 config_.frequency = kVideoFrequency; | 47 config_.frequency = kVideoFrequency; |
| 47 config_.video_codec = config.video_codec; | 48 config_.video_codec = config.video_codec; |
| 48 } | 49 } |
| 49 // Randomly set start values. | 50 // Randomly set start values. |
| 50 config_.sequence_number = base::RandInt(0, 65535); | 51 config_.sequence_number = base::RandInt(0, 65535); |
| 51 packetizer_.reset(new RtpPacketizer(transport, storage_.get(), config_)); | 52 packetizer_.reset( |
| 53 new RtpPacketizer(transport, storage_.get(), config_)); |
| 52 } | 54 } |
| 53 | 55 |
| 54 RtpSender::~RtpSender() {} | 56 RtpSender::~RtpSender() {} |
| 55 | 57 |
| 56 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, | 58 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, |
| 57 const base::TimeTicks& capture_time) { | 59 const base::TimeTicks& capture_time) { |
| 58 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); | 60 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void RtpSender::IncomingEncodedAudioFrame( | 63 void RtpSender::IncomingEncodedAudioFrame( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 133 |
| 132 void RtpSender::ScheduleNextStatsReport() { | 134 void RtpSender::ScheduleNextStatsReport() { |
| 133 transport_task_runner_->PostDelayedTask( | 135 transport_task_runner_->PostDelayedTask( |
| 134 FROM_HERE, | 136 FROM_HERE, |
| 135 base::Bind(&RtpSender::RtpStatistics, base::Unretained(this)), | 137 base::Bind(&RtpSender::RtpStatistics, base::Unretained(this)), |
| 136 base::TimeDelta::FromMilliseconds(kStatsCallbackIntervalMs)); | 138 base::TimeDelta::FromMilliseconds(kStatsCallbackIntervalMs)); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void RtpSender::RtpStatistics() { | 141 void RtpSender::RtpStatistics() { |
| 140 RtcpSenderInfo sender_info; | 142 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; | 143 base::TimeTicks time_sent; |
| 148 uint32 rtp_timestamp = 0; | 144 uint32 rtp_timestamp = 0; |
| 149 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); | 145 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); |
| 150 sender_info.send_packet_count = packetizer_->send_packets_count(); | 146 sender_info.send_packet_count = packetizer_->send_packets_count(); |
| 151 sender_info.send_octet_count = packetizer_->send_octet_count(); | 147 sender_info.send_octet_count = packetizer_->send_octet_count(); |
| 152 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); | 148 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); |
| 153 ScheduleNextStatsReport(); | 149 ScheduleNextStatsReport(); |
| 154 } | 150 } |
| 155 | 151 |
| 156 } // namespace transport | 152 } // namespace transport |
| 157 } // namespace cast | 153 } // namespace cast |
| 158 } // namespace media | 154 } // namespace media |
| OLD | NEW |