| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/net/rtp/rtp_sender.h" | 5 #include "media/cast/net/rtp/rtp_sender.h" |
| 6 | 6 |
| 7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "media/cast/net/cast_transport_defines.h" | 10 #include "media/cast/net/cast_transport_defines.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 transport_(transport), | 34 transport_(transport), |
| 35 transport_task_runner_(transport_task_runner), | 35 transport_task_runner_(transport_task_runner), |
| 36 weak_factory_(this) { | 36 weak_factory_(this) { |
| 37 // Randomly set sequence number start value. | 37 // Randomly set sequence number start value. |
| 38 config_.sequence_number = base::RandInt(0, 65535); | 38 config_.sequence_number = base::RandInt(0, 65535); |
| 39 } | 39 } |
| 40 | 40 |
| 41 RtpSender::~RtpSender() {} | 41 RtpSender::~RtpSender() {} |
| 42 | 42 |
| 43 bool RtpSender::Initialize(const CastTransportRtpConfig& config) { | 43 bool RtpSender::Initialize(const CastTransportRtpConfig& config) { |
| 44 storage_.reset(new PacketStorage(config.stored_frames)); | |
| 45 if (!storage_->IsValid()) { | |
| 46 return false; | |
| 47 } | |
| 48 config_.ssrc = config.ssrc; | 44 config_.ssrc = config.ssrc; |
| 49 config_.payload_type = config.rtp_payload_type; | 45 config_.payload_type = config.rtp_payload_type; |
| 50 packetizer_.reset(new RtpPacketizer(transport_, storage_.get(), config_)); | 46 packetizer_.reset(new RtpPacketizer(transport_, &storage_, config_)); |
| 51 return true; | 47 return true; |
| 52 } | 48 } |
| 53 | 49 |
| 54 void RtpSender::SendFrame(const EncodedFrame& frame) { | 50 void RtpSender::SendFrame(const EncodedFrame& frame) { |
| 55 DCHECK(packetizer_); | 51 DCHECK(packetizer_); |
| 56 packetizer_->SendFrameAsPackets(frame); | 52 packetizer_->SendFrameAsPackets(frame); |
| 53 LOG_IF(DFATAL, storage_.GetNumberOfStoredFrames() == kMaxUnackedFrames) |
| 54 << "Possible bug: Frames are not being actively released from storage."; |
| 57 } | 55 } |
| 58 | 56 |
| 59 void RtpSender::ResendPackets( | 57 void RtpSender::ResendPackets( |
| 60 const MissingFramesAndPacketsMap& missing_frames_and_packets, | 58 const MissingFramesAndPacketsMap& missing_frames_and_packets, |
| 61 bool cancel_rtx_if_not_in_list, const DedupInfo& dedup_info) { | 59 bool cancel_rtx_if_not_in_list, const DedupInfo& dedup_info) { |
| 62 DCHECK(storage_); | |
| 63 // Iterate over all frames in the list. | 60 // Iterate over all frames in the list. |
| 64 for (MissingFramesAndPacketsMap::const_iterator it = | 61 for (MissingFramesAndPacketsMap::const_iterator it = |
| 65 missing_frames_and_packets.begin(); | 62 missing_frames_and_packets.begin(); |
| 66 it != missing_frames_and_packets.end(); | 63 it != missing_frames_and_packets.end(); |
| 67 ++it) { | 64 ++it) { |
| 68 SendPacketVector packets_to_resend; | 65 SendPacketVector packets_to_resend; |
| 69 uint8 frame_id = it->first; | 66 uint8 frame_id = it->first; |
| 70 // Set of packets that the receiver wants us to re-send. | 67 // Set of packets that the receiver wants us to re-send. |
| 71 // If empty, we need to re-send all packets for this frame. | 68 // If empty, we need to re-send all packets for this frame. |
| 72 const PacketIdSet& missing_packet_set = it->second; | 69 const PacketIdSet& missing_packet_set = it->second; |
| 73 | 70 |
| 74 bool resend_all = missing_packet_set.find(kRtcpCastAllPacketsLost) != | 71 bool resend_all = missing_packet_set.find(kRtcpCastAllPacketsLost) != |
| 75 missing_packet_set.end(); | 72 missing_packet_set.end(); |
| 76 bool resend_last = missing_packet_set.find(kRtcpCastLastPacket) != | 73 bool resend_last = missing_packet_set.find(kRtcpCastLastPacket) != |
| 77 missing_packet_set.end(); | 74 missing_packet_set.end(); |
| 78 | 75 |
| 79 const SendPacketVector* stored_packets = storage_->GetFrame8(frame_id); | 76 const SendPacketVector* stored_packets = storage_.GetFrame8(frame_id); |
| 80 if (!stored_packets) | 77 if (!stored_packets) |
| 81 continue; | 78 continue; |
| 82 | 79 |
| 83 for (SendPacketVector::const_iterator it = stored_packets->begin(); | 80 for (SendPacketVector::const_iterator it = stored_packets->begin(); |
| 84 it != stored_packets->end(); ++it) { | 81 it != stored_packets->end(); ++it) { |
| 85 const PacketKey& packet_key = it->first; | 82 const PacketKey& packet_key = it->first; |
| 86 const uint16 packet_id = packet_key.second.second; | 83 const uint16 packet_id = packet_key.second.second; |
| 87 | 84 |
| 88 // Should we resend the packet? | 85 // Should we resend the packet? |
| 89 bool resend = resend_all; | 86 bool resend = resend_all; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 transport_->CancelSendingPacket(it->first); | 109 transport_->CancelSendingPacket(it->first); |
| 113 } | 110 } |
| 114 } | 111 } |
| 115 transport_->ResendPackets(packets_to_resend, dedup_info); | 112 transport_->ResendPackets(packets_to_resend, dedup_info); |
| 116 } | 113 } |
| 117 } | 114 } |
| 118 | 115 |
| 119 void RtpSender::CancelSendingFrames(const std::vector<uint32>& frame_ids) { | 116 void RtpSender::CancelSendingFrames(const std::vector<uint32>& frame_ids) { |
| 120 for (std::vector<uint32>::const_iterator i = frame_ids.begin(); | 117 for (std::vector<uint32>::const_iterator i = frame_ids.begin(); |
| 121 i != frame_ids.end(); ++i) { | 118 i != frame_ids.end(); ++i) { |
| 122 const SendPacketVector* stored_packets = storage_->GetFrame8(*i & 0xFF); | 119 const SendPacketVector* stored_packets = storage_.GetFrame8(*i & 0xFF); |
| 123 if (!stored_packets) | 120 if (!stored_packets) |
| 124 continue; | 121 continue; |
| 125 for (SendPacketVector::const_iterator j = stored_packets->begin(); | 122 for (SendPacketVector::const_iterator j = stored_packets->begin(); |
| 126 j != stored_packets->end(); ++j) { | 123 j != stored_packets->end(); ++j) { |
| 127 transport_->CancelSendingPacket(j->first); | 124 transport_->CancelSendingPacket(j->first); |
| 128 } | 125 } |
| 126 storage_.ReleaseFrame(*i); |
| 129 } | 127 } |
| 130 } | 128 } |
| 131 | 129 |
| 132 void RtpSender::ResendFrameForKickstart(uint32 frame_id, | 130 void RtpSender::ResendFrameForKickstart(uint32 frame_id, |
| 133 base::TimeDelta dedupe_window) { | 131 base::TimeDelta dedupe_window) { |
| 134 // Send the last packet of the encoded frame to kick start | 132 // Send the last packet of the encoded frame to kick start |
| 135 // retransmission. This gives enough information to the receiver what | 133 // retransmission. This gives enough information to the receiver what |
| 136 // packets and frames are missing. | 134 // packets and frames are missing. |
| 137 MissingFramesAndPacketsMap missing_frames_and_packets; | 135 MissingFramesAndPacketsMap missing_frames_and_packets; |
| 138 PacketIdSet missing; | 136 PacketIdSet missing; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 150 // TODO(miu): This is an abstraction violation. This needs to be a part of | 148 // TODO(miu): This is an abstraction violation. This needs to be a part of |
| 151 // the overall packet (de)serialization consolidation. | 149 // the overall packet (de)serialization consolidation. |
| 152 static const int kByteOffsetToSequenceNumber = 2; | 150 static const int kByteOffsetToSequenceNumber = 2; |
| 153 base::BigEndianWriter big_endian_writer( | 151 base::BigEndianWriter big_endian_writer( |
| 154 reinterpret_cast<char*>((&packet->front()) + kByteOffsetToSequenceNumber), | 152 reinterpret_cast<char*>((&packet->front()) + kByteOffsetToSequenceNumber), |
| 155 sizeof(uint16)); | 153 sizeof(uint16)); |
| 156 big_endian_writer.WriteU16(packetizer_->NextSequenceNumber()); | 154 big_endian_writer.WriteU16(packetizer_->NextSequenceNumber()); |
| 157 } | 155 } |
| 158 | 156 |
| 159 int64 RtpSender::GetLastByteSentForFrame(uint32 frame_id) { | 157 int64 RtpSender::GetLastByteSentForFrame(uint32 frame_id) { |
| 160 const SendPacketVector* stored_packets = storage_->GetFrame8(frame_id & 0xFF); | 158 const SendPacketVector* stored_packets = storage_.GetFrame8(frame_id & 0xFF); |
| 161 if (!stored_packets) | 159 if (!stored_packets) |
| 162 return 0; | 160 return 0; |
| 163 PacketKey last_packet_key = stored_packets->rbegin()->first; | 161 PacketKey last_packet_key = stored_packets->rbegin()->first; |
| 164 return transport_->GetLastByteSentForPacket(last_packet_key); | 162 return transport_->GetLastByteSentForPacket(last_packet_key); |
| 165 } | 163 } |
| 166 | 164 |
| 167 } // namespace cast | 165 } // namespace cast |
| 168 } // namespace media | 166 } // namespace media |
| OLD | NEW |