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

Side by Side Diff: media/cast/net/rtp/rtp_parser.cc

Issue 1515433002: Replace uses of raw uint32's with a type-checked RtpTimeTicks data type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Speculative workaround fix for win8_chromium_ng compile error. Created 4 years, 11 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
« no previous file with comments | « media/cast/net/rtp/rtp_parser.h ('k') | media/cast/net/rtp/rtp_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_parser.h" 5 #include "media/cast/net/rtp/rtp_parser.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 "media/cast/constants.h" 9 #include "media/cast/constants.h"
10 #include "media/cast/net/rtp/rtp_defines.h" 10 #include "media/cast/net/rtp/rtp_defines.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return false; 55 return false;
56 header->num_csrcs = bits & kRtpNumCsrcsMask; 56 header->num_csrcs = bits & kRtpNumCsrcsMask;
57 if (bits & kRtpExtensionBitMask) 57 if (bits & kRtpExtensionBitMask)
58 return false; // We lack the implementation to skip over an extension. 58 return false; // We lack the implementation to skip over an extension.
59 if (!reader.ReadU8(&bits)) 59 if (!reader.ReadU8(&bits))
60 return false; 60 return false;
61 header->marker = !!(bits & kRtpMarkerBitMask); 61 header->marker = !!(bits & kRtpMarkerBitMask);
62 header->payload_type = bits & ~kRtpMarkerBitMask; 62 header->payload_type = bits & ~kRtpMarkerBitMask;
63 if (header->payload_type != expected_payload_type_) 63 if (header->payload_type != expected_payload_type_)
64 return false; // Punt: Unexpected payload type. 64 return false; // Punt: Unexpected payload type.
65 uint32_t truncated_rtp_timestamp;
65 if (!reader.ReadU16(&header->sequence_number) || 66 if (!reader.ReadU16(&header->sequence_number) ||
66 !reader.ReadU32(&header->rtp_timestamp) || 67 !reader.ReadU32(&truncated_rtp_timestamp) ||
67 !reader.ReadU32(&header->sender_ssrc)) { 68 !reader.ReadU32(&header->sender_ssrc) ||
69 header->sender_ssrc != expected_sender_ssrc_) {
68 return false; 70 return false;
69 } 71 }
70 if (header->sender_ssrc != expected_sender_ssrc_) 72 header->rtp_timestamp =
71 return false; // Punt: Sender's SSRC does not match the expected one. 73 last_parsed_rtp_timestamp_.Expand(truncated_rtp_timestamp);
72 74
73 // Parse the Cast header. Note that, from the RTP protocol's perspective, the 75 // Parse the Cast header. Note that, from the RTP protocol's perspective, the
74 // Cast header is part of the payload (and not meant to be an extension 76 // Cast header is part of the payload (and not meant to be an extension
75 // header). 77 // header).
76 if (!reader.ReadU8(&bits)) 78 if (!reader.ReadU8(&bits))
77 return false; 79 return false;
78 header->is_key_frame = !!(bits & kCastKeyFrameBitMask); 80 header->is_key_frame = !!(bits & kCastKeyFrameBitMask);
79 header->is_reference = !!(bits & kCastReferenceFrameIdBitMask); 81 header->is_reference = !!(bits & kCastReferenceFrameIdBitMask);
80 uint8_t truncated_frame_id; 82 uint8_t truncated_frame_id;
81 if (!reader.ReadU8(&truncated_frame_id) || 83 if (!reader.ReadU8(&truncated_frame_id) ||
(...skipping 24 matching lines...) Expand all
106 if (!reader.ReadPiece(&tmp, type_and_size & 0x3ff)) 108 if (!reader.ReadPiece(&tmp, type_and_size & 0x3ff))
107 return false; 109 return false;
108 base::BigEndianReader chunk(tmp.data(), tmp.size()); 110 base::BigEndianReader chunk(tmp.data(), tmp.size());
109 switch (type_and_size >> 10) { 111 switch (type_and_size >> 10) {
110 case kCastRtpExtensionAdaptiveLatency: 112 case kCastRtpExtensionAdaptiveLatency:
111 if (!chunk.ReadU16(&header->new_playout_delay_ms)) 113 if (!chunk.ReadU16(&header->new_playout_delay_ms))
112 return false; 114 return false;
113 } 115 }
114 } 116 }
115 117
118 last_parsed_rtp_timestamp_ = header->rtp_timestamp;
119
116 // Only the lower 8 bits of the |frame_id| were serialized, so do some magic 120 // Only the lower 8 bits of the |frame_id| were serialized, so do some magic
117 // to restore the upper 24 bits. 121 // to restore the upper 24 bits.
118 // 122 //
119 // Note: The call to |frame_id_wrap_helper_| has side effects, so we must not 123 // Note: The call to |frame_id_wrap_helper_| has side effects, so we must not
120 // call it until we know the entire deserialization will succeed. 124 // call it until we know the entire deserialization will succeed.
121 header->frame_id = 125 header->frame_id =
122 frame_id_wrap_helper_.MapTo32bitsFrameId(truncated_frame_id); 126 frame_id_wrap_helper_.MapTo32bitsFrameId(truncated_frame_id);
123 // When the upper 24 bits are restored to |reference_frame_id|, make sure 127 // When the upper 24 bits are restored to |reference_frame_id|, make sure
124 // |reference_frame_id| will be strictly less than or equal to |frame_id|. 128 // |reference_frame_id| will be strictly less than or equal to |frame_id|.
125 if (truncated_reference_frame_id <= truncated_frame_id) 129 if (truncated_reference_frame_id <= truncated_frame_id)
126 header->reference_frame_id = header->frame_id & 0xffffff00; 130 header->reference_frame_id = header->frame_id & 0xffffff00;
127 else 131 else
128 header->reference_frame_id = (header->frame_id & 0xffffff00) - 0x00000100; 132 header->reference_frame_id = (header->frame_id & 0xffffff00) - 0x00000100;
129 header->reference_frame_id |= truncated_reference_frame_id; 133 header->reference_frame_id |= truncated_reference_frame_id;
130 134
131 // All remaining data in the packet is the payload. 135 // All remaining data in the packet is the payload.
132 *payload_data = reinterpret_cast<const uint8_t*>(reader.ptr()); 136 *payload_data = reinterpret_cast<const uint8_t*>(reader.ptr());
133 *payload_size = reader.remaining(); 137 *payload_size = reader.remaining();
134 138
135 return true; 139 return true;
136 } 140 }
137 141
138 } // namespace cast 142 } // namespace cast
139 } // namespace media 143 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/rtp/rtp_parser.h ('k') | media/cast/net/rtp/rtp_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698