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_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 Loading... |
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 Loading... |
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 |
OLD | NEW |