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/rtp_sender/rtp_sender.h" | 5 #include "media/cast/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/cast_defines.h" | 9 #include "media/cast/cast_defines.h" |
10 #include "media/cast/pacing/paced_sender.h" | 10 #include "media/cast/pacing/paced_sender.h" |
11 #include "media/cast/rtcp/rtcp_defines.h" | 11 #include "media/cast/rtcp/rtcp_defines.h" |
12 #include "net/base/big_endian.h" | |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 namespace cast { | 15 namespace cast { |
15 | 16 |
16 RtpSender::RtpSender(base::TickClock* clock, | 17 RtpSender::RtpSender(scoped_refptr<CastEnvironment> cast_environment, |
17 const AudioSenderConfig* audio_config, | 18 const AudioSenderConfig* audio_config, |
18 const VideoSenderConfig* video_config, | 19 const VideoSenderConfig* video_config, |
19 PacedPacketSender* transport) | 20 PacedPacketSender* transport) |
20 : config_(), | 21 : clock_(cast_environment->Clock()), |
Alpha Left Google
2013/11/14 00:29:24
This is not used anywhere in this file. Please rem
mikhal
2013/11/14 17:42:31
Done.
| |
21 transport_(transport), | 22 cast_environment_(cast_environment), |
22 clock_(clock) { | 23 config_(), |
24 transport_(transport) { | |
23 // Store generic cast config and create packetizer config. | 25 // Store generic cast config and create packetizer config. |
24 DCHECK(audio_config || video_config) << "Invalid argument"; | 26 DCHECK(audio_config || video_config) << "Invalid argument"; |
25 if (audio_config) { | 27 if (audio_config) { |
26 storage_.reset(new PacketStorage(clock, audio_config->rtp_history_ms)); | 28 storage_.reset(new PacketStorage(cast_environment->Clock(), |
29 audio_config->rtp_history_ms)); | |
27 config_.audio = true; | 30 config_.audio = true; |
28 config_.ssrc = audio_config->sender_ssrc; | 31 config_.ssrc = audio_config->sender_ssrc; |
29 config_.payload_type = audio_config->rtp_payload_type; | 32 config_.payload_type = audio_config->rtp_payload_type; |
30 config_.frequency = audio_config->frequency; | 33 config_.frequency = audio_config->frequency; |
31 config_.audio_codec = audio_config->codec; | 34 config_.audio_codec = audio_config->codec; |
32 } else { | 35 } else { |
33 storage_.reset(new PacketStorage(clock, video_config->rtp_history_ms)); | 36 storage_.reset(new PacketStorage(cast_environment->Clock(), |
37 video_config->rtp_history_ms)); | |
34 config_.audio = false; | 38 config_.audio = false; |
35 config_.ssrc = video_config->sender_ssrc; | 39 config_.ssrc = video_config->sender_ssrc; |
36 config_.payload_type = video_config->rtp_payload_type; | 40 config_.payload_type = video_config->rtp_payload_type; |
37 config_.frequency = kVideoFrequency; | 41 config_.frequency = kVideoFrequency; |
38 config_.video_codec = video_config->codec; | 42 config_.video_codec = video_config->codec; |
39 } | 43 } |
40 // Randomly set start values. | 44 // Randomly set start values. |
41 config_.sequence_number = base::RandInt(0, 65535); | 45 config_.sequence_number = base::RandInt(0, 65535); |
42 config_.rtp_timestamp = base::RandInt(0, 65535); | 46 config_.rtp_timestamp = base::RandInt(0, 65535); |
43 config_.rtp_timestamp += base::RandInt(0, 65535) << 16; | 47 config_.rtp_timestamp += base::RandInt(0, 65535) << 16; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 // Get packet from storage. | 79 // Get packet from storage. |
76 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); | 80 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); |
77 | 81 |
78 // Resend packet to the network. | 82 // Resend packet to the network. |
79 if (success) { | 83 if (success) { |
80 VLOG(1) << "Resend " << static_cast<int>(frame_id) | 84 VLOG(1) << "Resend " << static_cast<int>(frame_id) |
81 << ":" << packet_id; | 85 << ":" << packet_id; |
82 // Set a unique incremental sequence number for every packet. | 86 // Set a unique incremental sequence number for every packet. |
83 Packet& packet = packets_to_resend.back(); | 87 Packet& packet = packets_to_resend.back(); |
84 UpdateSequenceNumber(&packet); | 88 UpdateSequenceNumber(&packet); |
89 // Log retransmission (first extract rtp_timestamp). | |
90 uint32 rtp_timestamp; | |
91 net::BigEndianReader big_endian_reader(packet.data() + 4, 4); | |
92 big_endian_reader.ReadU32(&rtp_timestamp); | |
93 // TODO(mikhal): Consider placing the max value instead of -1. | |
94 cast_environment_->Logging()->InsertPacketEvent(kPacketRetransmited, | |
95 rtp_timestamp, frame_id, packet_id, -1, packet.size()); | |
85 // Set the size as correspond to each frame. | 96 // Set the size as correspond to each frame. |
86 ++packet_id; | 97 ++packet_id; |
87 } | 98 } |
88 } while (success); | 99 } while (success); |
89 } else { | 100 } else { |
90 // Iterate over all of the packets in the frame. | 101 // Iterate over all of the packets in the frame. |
91 for (PacketIdSet::const_iterator set_it = packets_set.begin(); | 102 for (PacketIdSet::const_iterator set_it = packets_set.begin(); |
92 set_it != packets_set.end(); ++set_it) { | 103 set_it != packets_set.end(); ++set_it) { |
93 uint16 packet_id = *set_it; | 104 uint16 packet_id = *set_it; |
94 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); | 105 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 time_since_last_send.InMilliseconds() * (config_.frequency / 1000); | 144 time_since_last_send.InMilliseconds() * (config_.frequency / 1000); |
134 } else { | 145 } else { |
135 sender_info->rtp_timestamp = 0; | 146 sender_info->rtp_timestamp = 0; |
136 } | 147 } |
137 sender_info->send_packet_count = packetizer_->send_packets_count(); | 148 sender_info->send_packet_count = packetizer_->send_packets_count(); |
138 sender_info->send_octet_count = packetizer_->send_octet_count(); | 149 sender_info->send_octet_count = packetizer_->send_octet_count(); |
139 } | 150 } |
140 | 151 |
141 } // namespace cast | 152 } // namespace cast |
142 } // namespace media | 153 } // namespace media |
OLD | NEW |