Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 | 82 |
| 83 ForwardErrorCorrection::PacketList MediaPacketGenerator::ConstructMediaPackets( | 83 ForwardErrorCorrection::PacketList MediaPacketGenerator::ConstructMediaPackets( |
| 84 int num_media_packets) { | 84 int num_media_packets) { |
| 85 return ConstructMediaPackets(num_media_packets, random_->Rand<uint16_t>()); | 85 return ConstructMediaPackets(num_media_packets, random_->Rand<uint16_t>()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 uint16_t MediaPacketGenerator::GetFecSeqNum() { | 88 uint16_t MediaPacketGenerator::GetFecSeqNum() { |
| 89 return fec_seq_num_; | 89 return fec_seq_num_; |
| 90 } | 90 } |
| 91 | 91 |
| 92 UlpfecPacketGenerator::UlpfecPacketGenerator() | 92 AugmentedPacketGenerator::AugmentedPacketGenerator(uint32_t ssrc) |
| 93 : num_packets_(0), seq_num_(0), timestamp_(0) {} | 93 : num_packets_(0), ssrc_(ssrc), seq_num_(0), timestamp_(0) {} |
| 94 | 94 |
| 95 void UlpfecPacketGenerator::NewFrame(int num_packets) { | 95 void AugmentedPacketGenerator::NewFrame(size_t num_packets) { |
| 96 num_packets_ = num_packets; | 96 num_packets_ = num_packets; |
| 97 timestamp_ += 3000; | 97 timestamp_ += 3000; |
| 98 } | 98 } |
| 99 | 99 |
| 100 uint16_t UlpfecPacketGenerator::NextSeqNum() { | 100 uint16_t AugmentedPacketGenerator::NextSeqNum() { |
| 101 return ++seq_num_; | 101 return ++seq_num_; |
| 102 } | 102 } |
| 103 | 103 |
| 104 RawRtpPacket* UlpfecPacketGenerator::NextPacket(int offset, size_t length) { | 104 std::unique_ptr<AugmentedPacket> AugmentedPacketGenerator::NextPacket( |
| 105 RawRtpPacket* rtp_packet = new RawRtpPacket; | 105 size_t offset, |
| 106 for (size_t i = 0; i < length; ++i) | 106 size_t length) { |
| 107 rtp_packet->data[i + kRtpHeaderSize] = offset + i; | 107 std::unique_ptr<AugmentedPacket> packet(new AugmentedPacket()); |
| 108 rtp_packet->length = length + kRtpHeaderSize; | 108 |
| 109 memset(&rtp_packet->header, 0, sizeof(WebRtcRTPHeader)); | 109 for (size_t i = 0; i < length; ++i) { |
|
philipel
2016/09/22 11:29:30
remove {}
brandtr
2016/09/22 14:21:38
Do I have to? :(
philipel
2016/09/23 11:52:14
Yes, also remove from for loop at line 67 :)
| |
| 110 rtp_packet->header.frameType = kVideoFrameDelta; | 110 packet->data[i + kRtpHeaderSize] = offset + i; |
| 111 rtp_packet->header.header.headerLength = kRtpHeaderSize; | 111 } |
| 112 rtp_packet->header.header.markerBit = (num_packets_ == 1); | 112 packet->length = length + kRtpHeaderSize; |
| 113 rtp_packet->header.header.sequenceNumber = seq_num_; | 113 memset(&packet->header, 0, sizeof(WebRtcRTPHeader)); |
| 114 rtp_packet->header.header.timestamp = timestamp_; | 114 packet->header.frameType = kVideoFrameDelta; |
| 115 rtp_packet->header.header.payloadType = kVp8PayloadType; | 115 packet->header.header.headerLength = kRtpHeaderSize; |
| 116 BuildRtpHeader(rtp_packet->data, &rtp_packet->header.header); | 116 packet->header.header.markerBit = (num_packets_ == 1); |
| 117 packet->header.header.payloadType = kVp8PayloadType; | |
| 118 packet->header.header.sequenceNumber = seq_num_; | |
| 119 packet->header.header.timestamp = timestamp_; | |
| 120 packet->header.header.ssrc = ssrc_; | |
| 121 WriteRtpHeader(packet->header.header, packet->data); | |
| 117 ++seq_num_; | 122 ++seq_num_; |
| 118 --num_packets_; | 123 --num_packets_; |
| 119 return rtp_packet; | 124 |
| 125 return packet; | |
| 120 } | 126 } |
| 121 | 127 |
| 122 // Creates a new RtpPacket with the RED header added to the packet. | 128 void AugmentedPacketGenerator::WriteRtpHeader(const RTPHeader& header, |
| 123 RawRtpPacket* UlpfecPacketGenerator::BuildMediaRedPacket( | 129 uint8_t* data) { |
| 124 const RawRtpPacket* packet) { | 130 data[0] = 0x80; // Version 2. |
| 125 const size_t kHeaderLength = packet->header.header.headerLength; | 131 data[1] = header.payloadType; |
| 126 RawRtpPacket* red_packet = new RawRtpPacket; | 132 data[1] |= (header.markerBit ? kRtpMarkerBitMask : 0); |
| 127 red_packet->header = packet->header; | 133 ByteWriter<uint16_t>::WriteBigEndian(data + 2, header.sequenceNumber); |
| 128 red_packet->length = packet->length + 1; // 1 byte RED header. | 134 ByteWriter<uint32_t>::WriteBigEndian(data + 4, header.timestamp); |
| 135 ByteWriter<uint32_t>::WriteBigEndian(data + 8, header.ssrc); | |
| 136 } | |
| 137 | |
| 138 UlpfecPacketGenerator::UlpfecPacketGenerator(uint32_t ssrc) | |
| 139 : AugmentedPacketGenerator(ssrc) {} | |
| 140 | |
| 141 std::unique_ptr<AugmentedPacket> UlpfecPacketGenerator::BuildMediaRedPacket( | |
| 142 const AugmentedPacket& packet) { | |
| 143 std::unique_ptr<AugmentedPacket> red_packet(new AugmentedPacket()); | |
| 144 | |
| 145 const size_t kHeaderLength = packet.header.header.headerLength; | |
| 146 red_packet->header = packet.header; | |
| 147 red_packet->length = packet.length + 1; // 1 byte RED header. | |
| 129 memset(red_packet->data, 0, red_packet->length); | 148 memset(red_packet->data, 0, red_packet->length); |
| 130 // Copy RTP header. | 149 // Copy RTP header. |
| 131 memcpy(red_packet->data, packet->data, kHeaderLength); | 150 memcpy(red_packet->data, packet.data, kHeaderLength); |
| 132 SetRedHeader(red_packet, red_packet->data[1] & 0x7f, kHeaderLength); | 151 SetRedHeader(red_packet->data[1] & 0x7f, kHeaderLength, red_packet.get()); |
| 133 memcpy(red_packet->data + kHeaderLength + 1, packet->data + kHeaderLength, | 152 memcpy(red_packet->data + kHeaderLength + 1, packet.data + kHeaderLength, |
| 134 packet->length - kHeaderLength); | 153 packet.length - kHeaderLength); |
| 154 | |
| 135 return red_packet; | 155 return red_packet; |
| 136 } | 156 } |
| 137 | 157 |
| 138 // Creates a new RtpPacket with FEC payload and RED header. Does this by | 158 std::unique_ptr<AugmentedPacket> UlpfecPacketGenerator::BuildUlpfecRedPacket( |
| 139 // creating a new fake media RtpPacket, clears the marker bit and adds a RED | 159 const ForwardErrorCorrection::Packet& packet) { |
| 140 // header. Finally replaces the payload with the content of |packet->data|. | |
| 141 RawRtpPacket* UlpfecPacketGenerator::BuildFecRedPacket( | |
| 142 const ForwardErrorCorrection::Packet* packet) { | |
| 143 // Create a fake media packet to get a correct header. 1 byte RED header. | 160 // Create a fake media packet to get a correct header. 1 byte RED header. |
| 144 ++num_packets_; | 161 ++num_packets_; |
| 145 RawRtpPacket* red_packet = NextPacket(0, packet->length + 1); | 162 std::unique_ptr<AugmentedPacket> red_packet = |
| 163 NextPacket(0, packet.length + 1); | |
| 164 | |
| 146 red_packet->data[1] &= ~0x80; // Clear marker bit. | 165 red_packet->data[1] &= ~0x80; // Clear marker bit. |
| 147 const size_t kHeaderLength = red_packet->header.header.headerLength; | 166 const size_t kHeaderLength = red_packet->header.header.headerLength; |
| 148 SetRedHeader(red_packet, kFecPayloadType, kHeaderLength); | 167 SetRedHeader(kFecPayloadType, kHeaderLength, red_packet.get()); |
| 149 memcpy(red_packet->data + kHeaderLength + 1, packet->data, packet->length); | 168 memcpy(red_packet->data + kHeaderLength + 1, packet.data, packet.length); |
| 150 red_packet->length = kHeaderLength + 1 + packet->length; | 169 red_packet->length = kHeaderLength + 1 + packet.length; |
| 170 | |
| 151 return red_packet; | 171 return red_packet; |
| 152 } | 172 } |
| 153 | 173 |
| 154 void UlpfecPacketGenerator::SetRedHeader( | 174 void UlpfecPacketGenerator::SetRedHeader(uint8_t payload_type, |
| 155 ForwardErrorCorrection::Packet* red_packet, | 175 size_t header_length, |
| 156 uint8_t payload_type, | 176 AugmentedPacket* red_packet) { |
| 157 size_t header_length) const { | 177 // Replace payload type. |
| 158 // Replace pltype. | |
| 159 red_packet->data[1] &= 0x80; // Reset. | 178 red_packet->data[1] &= 0x80; // Reset. |
| 160 red_packet->data[1] += kRedPayloadType; // Replace. | 179 red_packet->data[1] += kRedPayloadType; // Replace. |
| 161 | 180 |
| 162 // Add RED header, f-bit always 0. | 181 // Add RED header, f-bit always 0. |
| 163 red_packet->data[header_length] = payload_type; | 182 red_packet->data[header_length] = payload_type; |
| 164 } | 183 } |
| 165 | 184 |
| 166 void UlpfecPacketGenerator::BuildRtpHeader(uint8_t* data, | |
| 167 const RTPHeader* header) { | |
| 168 data[0] = 0x80; // Version 2. | |
| 169 data[1] = header->payloadType; | |
| 170 data[1] |= (header->markerBit ? kRtpMarkerBitMask : 0); | |
| 171 ByteWriter<uint16_t>::WriteBigEndian(data + 2, header->sequenceNumber); | |
| 172 ByteWriter<uint32_t>::WriteBigEndian(data + 4, header->timestamp); | |
| 173 ByteWriter<uint32_t>::WriteBigEndian(data + 8, header->ssrc); | |
| 174 } | |
| 175 | |
| 176 } // namespace fec | 185 } // namespace fec |
| 177 } // namespace test | 186 } // namespace test |
| 178 } // namespace webrtc | 187 } // namespace webrtc |
| OLD | NEW |