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

Side by Side Diff: remoting/protocol/rtp_utils.cc

Issue 4229003: Add VideoReader and VideoWriter interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/rtp_reader.cc ('k') | remoting/protocol/rtp_video_reader.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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "remoting/protocol/rtp_utils.h" 5 #include "remoting/protocol/rtp_utils.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/libjingle/source/talk/base/byteorder.h" 8 #include "third_party/libjingle/source/talk/base/byteorder.h"
9 9
10 using talk_base::GetBE16; 10 using talk_base::GetBE16;
(...skipping 30 matching lines...) Expand all
41 SetBE16(buffer + 2, header.sequence_number); 41 SetBE16(buffer + 2, header.sequence_number);
42 SetBE32(buffer + 4, header.timestamp); 42 SetBE32(buffer + 4, header.timestamp);
43 SetBE32(buffer + 8, header.sync_source_id); 43 SetBE32(buffer + 8, header.sync_source_id);
44 44
45 for (int i = 0; i < header.sources; i++) { 45 for (int i = 0; i < header.sources; i++) {
46 SetBE32(buffer + i * 4 + 12, header.source_id[i]); 46 SetBE32(buffer + i * 4 + 12, header.source_id[i]);
47 } 47 }
48 } 48 }
49 49
50 static inline uint8 ExtractBits(uint8 byte, int bits_count, int shift) { 50 static inline uint8 ExtractBits(uint8 byte, int bits_count, int shift) {
51 return (byte >> shift) && ((1 << bits_count) - 1); 51 return (byte >> shift) & ((1 << bits_count) - 1);
52 } 52 }
53 53
54 int UnpackRtpHeader(const uint8* buffer, int buffer_size, RtpHeader* header) { 54 int UnpackRtpHeader(const uint8* buffer, int buffer_size, RtpHeader* header) {
55 DCHECK_LT(header->sources, 1 << 4);
56 DCHECK_LT(header->payload_type, 1 << 7);
57
58 if (buffer_size < kRtpBaseHeaderSize) { 55 if (buffer_size < kRtpBaseHeaderSize) {
59 return -1; 56 return -1;
60 } 57 }
61 58
62 int version = ExtractBits(buffer[0], 2, 6); 59 int version = ExtractBits(buffer[0], 2, 6);
63 if (version != kRtpVersionNumber) { 60 if (version != kRtpVersionNumber) {
64 return -1; 61 return -1;
65 } 62 }
66 63
67 header->padding = ExtractBits(buffer[0], 1, 5) != 0; 64 header->padding = ExtractBits(buffer[0], 1, 5) != 0;
68 header->extension = ExtractBits(buffer[0], 1, 4) != 0; 65 header->extension = ExtractBits(buffer[0], 1, 4) != 0;
69 header->sources = ExtractBits(buffer[0], 4, 0); 66 header->sources = ExtractBits(buffer[0], 4, 0);
70 67
71 header->marker = ExtractBits(buffer[1], 1, 7) != 0; 68 header->marker = ExtractBits(buffer[1], 1, 7) != 0;
72 header->sources = ExtractBits(buffer[1], 7, 0); 69 header->payload_type = ExtractBits(buffer[1], 7, 0);
73 70
74 header->sequence_number = GetBE16(buffer + 2); 71 header->sequence_number = GetBE16(buffer + 2);
75 header->timestamp = GetBE32(buffer + 4); 72 header->timestamp = GetBE32(buffer + 4);
76 header->sync_source_id = GetBE32(buffer + 8); 73 header->sync_source_id = GetBE32(buffer + 8);
77 74
78 DCHECK_LE(header->sources, 16); 75 DCHECK_LT(header->sources, 16);
79 76
80 if (buffer_size < GetRtpHeaderSize(header->sources)) { 77 if (buffer_size < GetRtpHeaderSize(header->sources)) {
81 return -1; 78 return -1;
82 } 79 }
83 for (int i = 0; i < header->sources; i++) { 80 for (int i = 0; i < header->sources; i++) {
84 header->source_id[i] = GetBE32(buffer + i * 4 + 12); 81 header->source_id[i] = GetBE32(buffer + i * 4 + 12);
85 } 82 }
86 83
87 return GetRtpHeaderSize(header->sources); 84 return GetRtpHeaderSize(header->sources);
88 } 85 }
89 86
90 } // namespace remoting 87 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/rtp_reader.cc ('k') | remoting/protocol/rtp_video_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698