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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 stats_callback_(), | 29 stats_callback_(), |
30 transport_task_runner_(transport_task_runner), | 30 transport_task_runner_(transport_task_runner), |
31 weak_factory_(this) { | 31 weak_factory_(this) { |
32 // Randomly set sequence number start value. | 32 // Randomly set sequence number start value. |
33 config_.sequence_number = base::RandInt(0, 65535); | 33 config_.sequence_number = base::RandInt(0, 65535); |
34 } | 34 } |
35 | 35 |
36 RtpSender::~RtpSender() {} | 36 RtpSender::~RtpSender() {} |
37 | 37 |
38 void RtpSender::InitializeAudio(const CastTransportAudioConfig& config) { | 38 void RtpSender::InitializeAudio(const CastTransportAudioConfig& config) { |
39 storage_.reset(new PacketStorage(clock_, config.base.rtp_config.history_ms)); | 39 storage_.reset(new PacketStorage(config.rtp.max_outstanding_frames)); |
40 config_.audio = true; | 40 config_.audio = true; |
41 config_.ssrc = config.base.ssrc; | 41 config_.ssrc = config.rtp.config.ssrc; |
42 config_.payload_type = config.base.rtp_config.payload_type; | 42 config_.payload_type = config.rtp.config.payload_type; |
43 config_.frequency = config.frequency; | 43 config_.frequency = config.frequency; |
44 config_.audio_codec = config.codec; | 44 config_.audio_codec = config.codec; |
45 packetizer_.reset( | 45 packetizer_.reset( |
46 new RtpPacketizer(transport_, storage_.get(), config_, clock_, logging_)); | 46 new RtpPacketizer(transport_, storage_.get(), config_, clock_, logging_)); |
47 } | 47 } |
48 | 48 |
49 void RtpSender::InitializeVideo(const CastTransportVideoConfig& config) { | 49 void RtpSender::InitializeVideo(const CastTransportVideoConfig& config) { |
50 storage_.reset(new PacketStorage(clock_, config.base.rtp_config.history_ms)); | 50 storage_.reset(new PacketStorage(config.rtp.max_outstanding_frames)); |
51 config_.audio = false; | 51 config_.audio = false; |
52 config_.ssrc = config.base.ssrc; | 52 config_.ssrc = config.rtp.config.ssrc; |
53 config_.payload_type = config.base.rtp_config.payload_type; | 53 config_.payload_type = config.rtp.config.payload_type; |
54 config_.frequency = kVideoFrequency; | 54 config_.frequency = kVideoFrequency; |
55 config_.video_codec = config.codec; | 55 config_.video_codec = config.codec; |
56 packetizer_.reset( | 56 packetizer_.reset( |
57 new RtpPacketizer(transport_, storage_.get(), config_, clock_, logging_)); | 57 new RtpPacketizer(transport_, storage_.get(), config_, clock_, logging_)); |
58 } | 58 } |
59 | 59 |
60 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, | 60 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, |
61 const base::TimeTicks& capture_time) { | 61 const base::TimeTicks& capture_time) { |
62 DCHECK(packetizer_); | 62 DCHECK(packetizer_); |
63 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); | 63 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); |
(...skipping 20 matching lines...) Expand all Loading... |
84 bool success = false; | 84 bool success = false; |
85 | 85 |
86 if (packets_set.empty()) { | 86 if (packets_set.empty()) { |
87 VLOG(3) << "Missing all packets in frame " << static_cast<int>(frame_id); | 87 VLOG(3) << "Missing all packets in frame " << static_cast<int>(frame_id); |
88 | 88 |
89 uint16 packet_id = 0; | 89 uint16 packet_id = 0; |
90 do { | 90 do { |
91 // Get packet from storage. | 91 // Get packet from storage. |
92 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); | 92 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); |
93 | 93 |
| 94 // Check that we got at least one packet. |
| 95 DCHECK(packet_id != 0 || success) |
| 96 << "Failed to resend frame " << static_cast<int>(frame_id); |
| 97 |
94 // Resend packet to the network. | 98 // Resend packet to the network. |
95 if (success) { | 99 if (success) { |
96 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" | 100 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" |
97 << packet_id; | 101 << packet_id; |
98 // Set a unique incremental sequence number for every packet. | 102 // Set a unique incremental sequence number for every packet. |
99 PacketRef packet = packets_to_resend.back().second; | 103 PacketRef packet = packets_to_resend.back().second; |
100 UpdateSequenceNumber(&packet->data); | 104 UpdateSequenceNumber(&packet->data); |
101 // Set the size as correspond to each frame. | 105 // Set the size as correspond to each frame. |
102 ++packet_id; | 106 ++packet_id; |
103 } | 107 } |
104 } while (success); | 108 } while (success); |
105 } else { | 109 } else { |
106 // Iterate over all of the packets in the frame. | 110 // Iterate over all of the packets in the frame. |
107 for (PacketIdSet::const_iterator set_it = packets_set.begin(); | 111 for (PacketIdSet::const_iterator set_it = packets_set.begin(); |
108 set_it != packets_set.end(); | 112 set_it != packets_set.end(); |
109 ++set_it) { | 113 ++set_it) { |
110 uint16 packet_id = *set_it; | 114 uint16 packet_id = *set_it; |
111 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); | 115 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); |
112 | 116 |
| 117 // Check that we got at least one packet. |
| 118 DCHECK(set_it != packets_set.begin() || success) |
| 119 << "Failed to resend frame " << frame_id; |
| 120 |
113 // Resend packet to the network. | 121 // Resend packet to the network. |
114 if (success) { | 122 if (success) { |
115 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" | 123 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" |
116 << packet_id; | 124 << packet_id; |
117 PacketRef packet = packets_to_resend.back().second; | 125 PacketRef packet = packets_to_resend.back().second; |
118 UpdateSequenceNumber(&packet->data); | 126 UpdateSequenceNumber(&packet->data); |
119 } | 127 } |
120 } | 128 } |
121 } | 129 } |
122 transport_->ResendPackets(packets_to_resend); | 130 transport_->ResendPackets(packets_to_resend); |
(...skipping 27 matching lines...) Expand all Loading... |
150 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); | 158 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); |
151 sender_info.send_packet_count = packetizer_->send_packets_count(); | 159 sender_info.send_packet_count = packetizer_->send_packets_count(); |
152 sender_info.send_octet_count = packetizer_->send_octet_count(); | 160 sender_info.send_octet_count = packetizer_->send_octet_count(); |
153 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); | 161 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); |
154 ScheduleNextStatsReport(); | 162 ScheduleNextStatsReport(); |
155 } | 163 } |
156 | 164 |
157 } // namespace transport | 165 } // namespace transport |
158 } // namespace cast | 166 } // namespace cast |
159 } // namespace media | 167 } // namespace media |
OLD | NEW |