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

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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 return false; 113 return false;
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 // There are only 6 message types (0xf1 - 0xf7), so we have the size table of
Takashi Toyoshima 2014/10/31 07:13:37 Is this place intended? It sounds like a descripti
yhirano 2014/10/31 07:42:54 Done.
123 // size 8.
122 DCHECK_LE(0xf1, first_byte); 124 DCHECK_LE(0xf1, first_byte);
123 DCHECK_LE(first_byte, 0xf7); 125 DCHECK_LE(first_byte, 0xf7);
126 DCHECK_EQ(0xf0, first_byte & 0xf8);
124 const size_t message_size_table[8] = { 127 const size_t message_size_table[8] = {
125 0, 2, 3, 2, 1, 1, 1, 0, 128 0, 2, 3, 2, 1, 1, 1, 0,
126 }; 129 };
127 size_t message_size = message_size_table[first_byte & 0x0f]; 130 size_t message_size = message_size_table[first_byte & 0x07];
128 DCHECK_NE(0u, message_size); 131 DCHECK_NE(0u, message_size);
129 DCHECK_LE(message_size, 3u); 132 DCHECK_LE(message_size, 3u);
130 133
131 if (GetSize(data) < index + message_size) { 134 if (GetSize(data) < index + message_size) {
132 // The message is incomplete. 135 // The message is incomplete.
133 return false; 136 return false;
134 } 137 }
135 138
136 uint8 code_index = message_size == 1 ? 0x5 : static_cast<uint8>(message_size); 139 uint8 code_index = message_size == 1 ? 0x5 : static_cast<uint8>(message_size);
137 data_to_send->push_back((jack_.cable_number << 4) | code_index); 140 data_to_send->push_back((jack_.cable_number << 4) | code_index);
(...skipping 16 matching lines...) Expand all
154 data_to_send->push_back(0); 157 data_to_send->push_back(0);
155 data_to_send->push_back(0); 158 data_to_send->push_back(0);
156 *current += 1; 159 *current += 1;
157 } 160 }
158 161
159 bool UsbMidiOutputStream::PushChannelMessage(const std::vector<uint8>& data, 162 bool UsbMidiOutputStream::PushChannelMessage(const std::vector<uint8>& data,
160 size_t* current, 163 size_t* current,
161 std::vector<uint8>* data_to_send) { 164 std::vector<uint8>* data_to_send) {
162 size_t index = *current; 165 size_t index = *current;
163 uint8 first_byte = Get(data, index); 166 uint8 first_byte = Get(data, index);
167
168 // There are only 7 message types (0x80 - 0xe0), so we have the size table
Takashi Toyoshima 2014/10/31 07:13:37 Same. Is this for message_size_table at line 172?
yhirano 2014/10/31 07:42:54 Done.
169 // of size 8.
164 DCHECK_LE(0x80, (first_byte & 0xf0)); 170 DCHECK_LE(0x80, (first_byte & 0xf0));
165 DCHECK_LE((first_byte & 0xf0), 0xe0); 171 DCHECK_LE((first_byte & 0xf0), 0xe0);
166
167 const size_t message_size_table[8] = { 172 const size_t message_size_table[8] = {
168 3, 3, 3, 3, 2, 3, 3, 0, 173 3, 3, 3, 3, 2, 3, 3, 0,
169 }; 174 };
170 uint8 code_index = first_byte >> 4; 175 uint8 code_index = first_byte >> 4;
176 DCHECK_LE(0x08, code_index);
177 DCHECK_LE(code_index, 0x0e);
171 size_t message_size = message_size_table[code_index & 0x7]; 178 size_t message_size = message_size_table[code_index & 0x7];
172 DCHECK_NE(0u, message_size); 179 DCHECK_NE(0u, message_size);
173 DCHECK_LE(message_size, 3u); 180 DCHECK_LE(message_size, 3u);
174 181
175 if (GetSize(data) < index + message_size) { 182 if (GetSize(data) < index + message_size) {
176 // The message is incomplete. 183 // The message is incomplete.
177 return false; 184 return false;
178 } 185 }
179 186
180 data_to_send->push_back((jack_.cable_number << 4) | code_index); 187 data_to_send->push_back((jack_.cable_number << 4) | code_index);
181 for (size_t i = index; i < index + 3; ++i) 188 for (size_t i = index; i < index + 3; ++i)
182 data_to_send->push_back(i < index + message_size ? Get(data, i) : 0); 189 data_to_send->push_back(i < index + message_size ? Get(data, i) : 0);
183 *current += message_size; 190 *current += message_size;
184 return true; 191 return true;
185 } 192 }
186 193
187 } // namespace media 194 } // 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