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