Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet.cc

Issue 1307663004: Add a ParseHeader method to RtcpPacket, for parsing common RTCP header. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Refactorings, unit tests Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 return true; 722 return true;
723 } 723 }
724 724
725 size_t RtcpPacket::HeaderLength() const { 725 size_t RtcpPacket::HeaderLength() const {
726 size_t length_in_bytes = BlockLength(); 726 size_t length_in_bytes = BlockLength();
727 // Length in 32-bit words minus 1. 727 // Length in 32-bit words minus 1.
728 assert(length_in_bytes > 0); 728 assert(length_in_bytes > 0);
729 return ((length_in_bytes + 3) / 4) - 1; 729 return ((length_in_bytes + 3) / 4) - 1;
730 } 730 }
731 731
732 RtcpPacket::CommonHeader::CommonHeader()
733 : count_or_format(0), payload_type(0), payload_size_bytes(0) {}
732 // From RFC 3550, RTP: A Transport Protocol for Real-Time Applications. 734 // From RFC 3550, RTP: A Transport Protocol for Real-Time Applications.
733 // 735 //
734 // RTP header format. 736 // RTP header format.
735 // 0 1 2 3 737 // 0 1 2 3
736 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 738 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
737 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 739 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
738 // |V=2|P| RC/FMT | PT | length | 740 // |V=2|P| RC/FMT | PT | length |
739 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 741 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
740 742
741 void RtcpPacket::CreateHeader( 743 void RtcpPacket::CreateHeader(
742 uint8_t count_or_format, // Depends on packet type. 744 uint8_t count_or_format, // Depends on packet type.
743 uint8_t packet_type, 745 uint8_t packet_type,
744 size_t length, 746 size_t length,
745 uint8_t* buffer, 747 uint8_t* buffer,
746 size_t* pos) const { 748 size_t* pos) {
747 assert(length <= 0xffff); 749 assert(length <= 0xffff);
748 const uint8_t kVersion = 2; 750 const uint8_t kVersion = 2;
749 AssignUWord8(buffer, pos, (kVersion << 6) + count_or_format); 751 AssignUWord8(buffer, pos, (kVersion << 6) + count_or_format);
750 AssignUWord8(buffer, pos, packet_type); 752 AssignUWord8(buffer, pos, packet_type);
751 AssignUWord16(buffer, pos, length); 753 AssignUWord16(buffer, pos, length);
752 } 754 }
753 755
756 bool RtcpPacket::ParseHeader(const uint8_t* packet,
757 size_t index,
758 size_t max_length,
759 CommonHeader* header) {
åsapersson 2015/09/03 08:57:20 Looks like RTCPUtility::RTCPParseCommonHeader can
sprang_webrtc 2015/09/04 14:12:50 I've merged this into RTCPUtility.
760 DCHECK(header != nullptr);
761 size_t length = max_length - index;
762 const size_t kHeaderLength = 4;
763 if (length < kHeaderLength) {
764 LOG(LS_WARNING) << "Too little data (" << length << " byte"
765 << (length != 1 ? "s" : "")
766 << ") remaining in buffer to parse RTCP header (4 bytes).";
767 return false;
768 }
769
770 const uint8_t kRtcpVersion = 2;
771 uint8_t version = packet[index] >> 6;
772 if (version != kRtcpVersion) {
773 LOG(LS_WARNING) << "Invalid RTCP header: Version must be " << kRtcpVersion
774 << " but was " << version;
775 return false;
776 }
777
778 size_t packet_size_words =
779 ByteReader<uint16_t>::ReadBigEndian(&packet[index + 2]) + 1;
780 if (length < packet_size_words * 4) {
781 LOG(LS_WARNING) << "Buffer too small (" << length
782 << " bytes) to fit a FeedbackPacket of "
783 << packet_size_words << " 32bit words.";
784 return false;
785 }
786
787 bool has_padding = (packet[index] & 0x20) != 0;
788 size_t payload_size = packet_size_words * 4;
789 if (has_padding) {
790 uint8_t padding_bytes = packet[index + payload_size - 1];
791 if (kHeaderLength + padding_bytes > payload_size) {
792 LOG(LS_WARNING) << "Invalid RTCP header: Too many padding bytes ("
793 << padding_bytes << ") for a packet size of "
794 << payload_size << "bytes.";
795 return false;
796 }
797 payload_size -= padding_bytes;
798 }
799 payload_size -= kHeaderLength;
800
801 header->payload_size_bytes = payload_size;
802 header->count_or_format = packet[index] & 0x1F;
803 header->payload_type = packet[index + 1];
804
805 return true;
806 }
807
754 bool Empty::Create(uint8_t* packet, 808 bool Empty::Create(uint8_t* packet,
755 size_t* index, 809 size_t* index,
756 size_t max_length, 810 size_t max_length,
757 RtcpPacket::PacketReadyCallback* callback) const { 811 RtcpPacket::PacketReadyCallback* callback) const {
758 return true; 812 return true;
759 } 813 }
760 814
761 size_t Empty::BlockLength() const { 815 size_t Empty::BlockLength() const {
762 return 0; 816 return 0;
763 } 817 }
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 return length_; 1274 return length_;
1221 } 1275 }
1222 1276
1223 void RawPacket::SetLength(size_t length) { 1277 void RawPacket::SetLength(size_t length) {
1224 assert(length <= buffer_length_); 1278 assert(length <= buffer_length_);
1225 length_ = length; 1279 length_ = length;
1226 } 1280 }
1227 1281
1228 } // namespace rtcp 1282 } // namespace rtcp
1229 } // namespace webrtc 1283 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698