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

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

Issue 493823002: Implement adaptive target delay extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: explicit masking Created 6 years, 4 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_packetizer.cc ('k') | media/cast/net/rtp/rtp_receiver_defines.h » ('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/cast_defines.h" 9 #include "media/cast/cast_defines.h"
10 #include "media/cast/net/rtp/rtp_defines.h"
10 11
11 namespace media { 12 namespace media {
12 namespace cast { 13 namespace cast {
13 14
14 static const size_t kRtpHeaderLength = 12;
15 static const size_t kCastHeaderLength = 7;
16 static const uint8 kRtpExtensionBitMask = 0x10;
17 static const uint8 kRtpMarkerBitMask = 0x80;
18 static const uint8 kCastKeyFrameBitMask = 0x80;
19 static const uint8 kCastReferenceFrameIdBitMask = 0x40;
20
21 RtpParser::RtpParser(uint32 expected_sender_ssrc, uint8 expected_payload_type) 15 RtpParser::RtpParser(uint32 expected_sender_ssrc, uint8 expected_payload_type)
22 : expected_sender_ssrc_(expected_sender_ssrc), 16 : expected_sender_ssrc_(expected_sender_ssrc),
23 expected_payload_type_(expected_payload_type) {} 17 expected_payload_type_(expected_payload_type) {}
24 18
25 RtpParser::~RtpParser() {} 19 RtpParser::~RtpParser() {}
26 20
27 bool RtpParser::ParsePacket(const uint8* packet, 21 bool RtpParser::ParsePacket(const uint8* packet,
28 size_t length, 22 size_t length,
29 RtpCastHeader* header, 23 RtpCastHeader* header,
30 const uint8** payload_data, 24 const uint8** payload_data,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (!includes_specific_frame_reference) { 79 if (!includes_specific_frame_reference) {
86 // By default, a key frame only references itself; and non-key frames 80 // By default, a key frame only references itself; and non-key frames
87 // reference their direct predecessor. 81 // reference their direct predecessor.
88 truncated_reference_frame_id = truncated_frame_id; 82 truncated_reference_frame_id = truncated_frame_id;
89 if (!header->is_key_frame) 83 if (!header->is_key_frame)
90 --truncated_reference_frame_id; 84 --truncated_reference_frame_id;
91 } else if (!reader.ReadU8(&truncated_reference_frame_id)) { 85 } else if (!reader.ReadU8(&truncated_reference_frame_id)) {
92 return false; 86 return false;
93 } 87 }
94 88
89 for (int i = 0; i < (bits & kCastExtensionCountmask); i++) {
90 uint16 type_and_size;
91 if (!reader.ReadU16(&type_and_size))
92 return false;
93 base::StringPiece tmp;
94 if (!reader.ReadPiece(&tmp, type_and_size & 0x3ff))
95 return false;
96 base::BigEndianReader chunk(tmp.data(), tmp.size());
97 switch (type_and_size >> 10) {
98 case kCastRtpExtensionAdaptiveLatency:
99 if (!chunk.ReadU16(&header->new_playout_delay_ms))
100 return false;
101
102 }
103 }
104
95 // Only the lower 8 bits of the |frame_id| were serialized, so do some magic 105 // Only the lower 8 bits of the |frame_id| were serialized, so do some magic
96 // to restore the upper 24 bits. 106 // to restore the upper 24 bits.
97 // 107 //
98 // Note: The call to |frame_id_wrap_helper_| has side effects, so we must not 108 // Note: The call to |frame_id_wrap_helper_| has side effects, so we must not
99 // call it until we know the entire deserialization will succeed. 109 // call it until we know the entire deserialization will succeed.
100 header->frame_id = 110 header->frame_id =
101 frame_id_wrap_helper_.MapTo32bitsFrameId(truncated_frame_id); 111 frame_id_wrap_helper_.MapTo32bitsFrameId(truncated_frame_id);
102 // When the upper 24 bits are restored to |reference_frame_id|, make sure 112 // When the upper 24 bits are restored to |reference_frame_id|, make sure
103 // |reference_frame_id| will be strictly less than or equal to |frame_id|. 113 // |reference_frame_id| will be strictly less than or equal to |frame_id|.
104 if (truncated_reference_frame_id <= truncated_frame_id) 114 if (truncated_reference_frame_id <= truncated_frame_id)
105 header->reference_frame_id = header->frame_id & 0xffffff00; 115 header->reference_frame_id = header->frame_id & 0xffffff00;
106 else 116 else
107 header->reference_frame_id = (header->frame_id & 0xffffff00) - 0x00000100; 117 header->reference_frame_id = (header->frame_id & 0xffffff00) - 0x00000100;
108 header->reference_frame_id |= truncated_reference_frame_id; 118 header->reference_frame_id |= truncated_reference_frame_id;
109 119
110 // All remaining data in the packet is the payload. 120 // All remaining data in the packet is the payload.
111 *payload_data = reinterpret_cast<const uint8*>(reader.ptr()); 121 *payload_data = reinterpret_cast<const uint8*>(reader.ptr());
112 *payload_size = reader.remaining(); 122 *payload_size = reader.remaining();
113 123
114 return true; 124 return true;
115 } 125 }
116 126
117 } // namespace cast 127 } // namespace cast
118 } // namespace media 128 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/rtp/rtp_packetizer.cc ('k') | media/cast/net/rtp/rtp_receiver_defines.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698