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

Side by Side Diff: media/midi/usb_midi_output_stream.cc

Issue 694733002: [WebMIDI] Fix code style to suppress a static analysis error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | 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/midi/usb_midi_output_stream.h" 5 #include "media/midi/usb_midi_output_stream.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/midi/midi_message_util.h" 8 #include "media/midi/midi_message_util.h"
9 #include "media/midi/usb_midi_device.h" 9 #include "media/midi/usb_midi_device.h"
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 115
116 bool UsbMidiOutputStream::PushSysCommonMessage( 116 bool UsbMidiOutputStream::PushSysCommonMessage(
117 const std::vector<uint8>& data, 117 const std::vector<uint8>& data,
118 size_t* current, 118 size_t* current,
119 std::vector<uint8>* data_to_send) { 119 std::vector<uint8>* data_to_send) {
120 size_t index = *current; 120 size_t index = *current;
121 uint8 first_byte = Get(data, index); 121 uint8 first_byte = Get(data, index);
122 DCHECK_LE(0xf1, first_byte); 122 DCHECK_LE(0xf1, first_byte);
123 DCHECK_LE(first_byte, 0xf7); 123 DCHECK_LE(first_byte, 0xf7);
124 DCHECK_EQ(0xf0, first_byte & 0xf8);
125 // There are only 6 message types (0xf1 - 0xf7), so the table size is 8.
124 const size_t message_size_table[8] = { 126 const size_t message_size_table[8] = {
125 0, 2, 3, 2, 1, 1, 1, 0, 127 0, 2, 3, 2, 1, 1, 1, 0,
126 }; 128 };
127 size_t message_size = message_size_table[first_byte & 0x0f]; 129 size_t message_size = message_size_table[first_byte & 0x07];
128 DCHECK_NE(0u, message_size); 130 DCHECK_NE(0u, message_size);
129 DCHECK_LE(message_size, 3u); 131 DCHECK_LE(message_size, 3u);
130 132
131 if (GetSize(data) < index + message_size) { 133 if (GetSize(data) < index + message_size) {
132 // The message is incomplete. 134 // The message is incomplete.
133 return false; 135 return false;
134 } 136 }
135 137
136 uint8 code_index = message_size == 1 ? 0x5 : static_cast<uint8>(message_size); 138 uint8 code_index = message_size == 1 ? 0x5 : static_cast<uint8>(message_size);
137 data_to_send->push_back((jack_.cable_number << 4) | code_index); 139 data_to_send->push_back((jack_.cable_number << 4) | code_index);
(...skipping 16 matching lines...) Expand all
154 data_to_send->push_back(0); 156 data_to_send->push_back(0);
155 data_to_send->push_back(0); 157 data_to_send->push_back(0);
156 *current += 1; 158 *current += 1;
157 } 159 }
158 160
159 bool UsbMidiOutputStream::PushChannelMessage(const std::vector<uint8>& data, 161 bool UsbMidiOutputStream::PushChannelMessage(const std::vector<uint8>& data,
160 size_t* current, 162 size_t* current,
161 std::vector<uint8>* data_to_send) { 163 std::vector<uint8>* data_to_send) {
162 size_t index = *current; 164 size_t index = *current;
163 uint8 first_byte = Get(data, index); 165 uint8 first_byte = Get(data, index);
166
164 DCHECK_LE(0x80, (first_byte & 0xf0)); 167 DCHECK_LE(0x80, (first_byte & 0xf0));
165 DCHECK_LE((first_byte & 0xf0), 0xe0); 168 DCHECK_LE((first_byte & 0xf0), 0xe0);
166 169 // There are only 7 message types (0x8-0xe in the higher four bits), so the
170 // table size is 8.
167 const size_t message_size_table[8] = { 171 const size_t message_size_table[8] = {
168 3, 3, 3, 3, 2, 3, 3, 0, 172 3, 3, 3, 3, 2, 3, 3, 0,
169 }; 173 };
170 uint8 code_index = first_byte >> 4; 174 uint8 code_index = first_byte >> 4;
175 DCHECK_LE(0x08, code_index);
176 DCHECK_LE(code_index, 0x0e);
171 size_t message_size = message_size_table[code_index & 0x7]; 177 size_t message_size = message_size_table[code_index & 0x7];
172 DCHECK_NE(0u, message_size); 178 DCHECK_NE(0u, message_size);
173 DCHECK_LE(message_size, 3u); 179 DCHECK_LE(message_size, 3u);
174 180
175 if (GetSize(data) < index + message_size) { 181 if (GetSize(data) < index + message_size) {
176 // The message is incomplete. 182 // The message is incomplete.
177 return false; 183 return false;
178 } 184 }
179 185
180 data_to_send->push_back((jack_.cable_number << 4) | code_index); 186 data_to_send->push_back((jack_.cable_number << 4) | code_index);
181 for (size_t i = index; i < index + 3; ++i) 187 for (size_t i = index; i < index + 3; ++i)
182 data_to_send->push_back(i < index + message_size ? Get(data, i) : 0); 188 data_to_send->push_back(i < index + message_size ? Get(data, i) : 0);
183 *current += message_size; 189 *current += message_size;
184 return true; 190 return true;
185 } 191 }
186 192
187 } // namespace media 193 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698