| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 return false; | 54 return false; |
| 55 header->num_csrcs = bits & kRtpNumCsrcsMask; | 55 header->num_csrcs = bits & kRtpNumCsrcsMask; |
| 56 if (bits & kRtpExtensionBitMask) | 56 if (bits & kRtpExtensionBitMask) |
| 57 return false; // We lack the implementation to skip over an extension. | 57 return false; // We lack the implementation to skip over an extension. |
| 58 if (!reader.ReadU8(&bits)) | 58 if (!reader.ReadU8(&bits)) |
| 59 return false; | 59 return false; |
| 60 header->marker = !!(bits & kRtpMarkerBitMask); | 60 header->marker = !!(bits & kRtpMarkerBitMask); |
| 61 header->payload_type = bits & ~kRtpMarkerBitMask; | 61 header->payload_type = bits & ~kRtpMarkerBitMask; |
| 62 if (header->payload_type != expected_payload_type_) | 62 if (header->payload_type != expected_payload_type_) |
| 63 return false; // Punt: Unexpected payload type. | 63 return false; // Punt: Unexpected payload type. |
| 64 uint32_t truncated_rtp_timestamp; |
| 64 if (!reader.ReadU16(&header->sequence_number) || | 65 if (!reader.ReadU16(&header->sequence_number) || |
| 65 !reader.ReadU32(&header->rtp_timestamp) || | 66 !reader.ReadU32(&truncated_rtp_timestamp) || |
| 66 !reader.ReadU32(&header->sender_ssrc)) { | 67 !reader.ReadU32(&header->sender_ssrc) || |
| 68 header->sender_ssrc != expected_sender_ssrc_) { |
| 67 return false; | 69 return false; |
| 68 } | 70 } |
| 69 if (header->sender_ssrc != expected_sender_ssrc_) | 71 header->rtp_timestamp = |
| 70 return false; // Punt: Sender's SSRC does not match the expected one. | 72 last_parsed_rtp_timestamp_.Expand(truncated_rtp_timestamp); |
| 71 | 73 |
| 72 // Parse the Cast header. Note that, from the RTP protocol's perspective, the | 74 // Parse the Cast header. Note that, from the RTP protocol's perspective, the |
| 73 // Cast header is part of the payload (and not meant to be an extension | 75 // Cast header is part of the payload (and not meant to be an extension |
| 74 // header). | 76 // header). |
| 75 if (!reader.ReadU8(&bits)) | 77 if (!reader.ReadU8(&bits)) |
| 76 return false; | 78 return false; |
| 77 header->is_key_frame = !!(bits & kCastKeyFrameBitMask); | 79 header->is_key_frame = !!(bits & kCastKeyFrameBitMask); |
| 78 header->is_reference = !!(bits & kCastReferenceFrameIdBitMask); | 80 header->is_reference = !!(bits & kCastReferenceFrameIdBitMask); |
| 79 uint8 truncated_frame_id; | 81 uint8 truncated_frame_id; |
| 80 if (!reader.ReadU8(&truncated_frame_id) || | 82 if (!reader.ReadU8(&truncated_frame_id) || |
| (...skipping 24 matching lines...) Expand all Loading... |
| 105 if (!reader.ReadPiece(&tmp, type_and_size & 0x3ff)) | 107 if (!reader.ReadPiece(&tmp, type_and_size & 0x3ff)) |
| 106 return false; | 108 return false; |
| 107 base::BigEndianReader chunk(tmp.data(), tmp.size()); | 109 base::BigEndianReader chunk(tmp.data(), tmp.size()); |
| 108 switch (type_and_size >> 10) { | 110 switch (type_and_size >> 10) { |
| 109 case kCastRtpExtensionAdaptiveLatency: | 111 case kCastRtpExtensionAdaptiveLatency: |
| 110 if (!chunk.ReadU16(&header->new_playout_delay_ms)) | 112 if (!chunk.ReadU16(&header->new_playout_delay_ms)) |
| 111 return false; | 113 return false; |
| 112 } | 114 } |
| 113 } | 115 } |
| 114 | 116 |
| 117 last_parsed_rtp_timestamp_ = header->rtp_timestamp; |
| 118 |
| 115 // Only the lower 8 bits of the |frame_id| were serialized, so do some magic | 119 // Only the lower 8 bits of the |frame_id| were serialized, so do some magic |
| 116 // to restore the upper 24 bits. | 120 // to restore the upper 24 bits. |
| 117 // | 121 // |
| 118 // Note: The call to |frame_id_wrap_helper_| has side effects, so we must not | 122 // Note: The call to |frame_id_wrap_helper_| has side effects, so we must not |
| 119 // call it until we know the entire deserialization will succeed. | 123 // call it until we know the entire deserialization will succeed. |
| 120 header->frame_id = | 124 header->frame_id = |
| 121 frame_id_wrap_helper_.MapTo32bitsFrameId(truncated_frame_id); | 125 frame_id_wrap_helper_.MapTo32bitsFrameId(truncated_frame_id); |
| 122 // When the upper 24 bits are restored to |reference_frame_id|, make sure | 126 // When the upper 24 bits are restored to |reference_frame_id|, make sure |
| 123 // |reference_frame_id| will be strictly less than or equal to |frame_id|. | 127 // |reference_frame_id| will be strictly less than or equal to |frame_id|. |
| 124 if (truncated_reference_frame_id <= truncated_frame_id) | 128 if (truncated_reference_frame_id <= truncated_frame_id) |
| 125 header->reference_frame_id = header->frame_id & 0xffffff00; | 129 header->reference_frame_id = header->frame_id & 0xffffff00; |
| 126 else | 130 else |
| 127 header->reference_frame_id = (header->frame_id & 0xffffff00) - 0x00000100; | 131 header->reference_frame_id = (header->frame_id & 0xffffff00) - 0x00000100; |
| 128 header->reference_frame_id |= truncated_reference_frame_id; | 132 header->reference_frame_id |= truncated_reference_frame_id; |
| 129 | 133 |
| 130 // All remaining data in the packet is the payload. | 134 // All remaining data in the packet is the payload. |
| 131 *payload_data = reinterpret_cast<const uint8*>(reader.ptr()); | 135 *payload_data = reinterpret_cast<const uint8*>(reader.ptr()); |
| 132 *payload_size = reader.remaining(); | 136 *payload_size = reader.remaining(); |
| 133 | 137 |
| 134 return true; | 138 return true; |
| 135 } | 139 } |
| 136 | 140 |
| 137 } // namespace cast | 141 } // namespace cast |
| 138 } // namespace media | 142 } // namespace media |
| OLD | NEW |