Index: media/midi/usb_midi_descriptor_parser.cc |
diff --git a/media/midi/usb_midi_descriptor_parser.cc b/media/midi/usb_midi_descriptor_parser.cc |
index d454ff9469152c7fd9f39df314eaa2775b16a673..f58f175a0d0d29635f5be22e2de659f6093b5d6c 100644 |
--- a/media/midi/usb_midi_descriptor_parser.cc |
+++ b/media/midi/usb_midi_descriptor_parser.cc |
@@ -79,6 +79,33 @@ bool UsbMidiDescriptorParser::Parse(UsbMidiDevice* device, |
return result; |
} |
+bool UsbMidiDescriptorParser::ParseDeviceInfo( |
+ const uint8* data, size_t size, DeviceInfo* info) { |
+ for (const uint8* current = data; |
+ current < data + size; |
+ current += current[0]) { |
+ uint8 length = current[0]; |
+ if (length < 2) { |
+ DVLOG(1) << "Descriptor Type is not accessible."; |
+ return false; |
+ } |
+ if (current + length > data + size) { |
+ DVLOG(1) << "The header size is incorrect."; |
+ return false; |
+ } |
+ DescriptorType descriptor_type = static_cast<DescriptorType>(current[1]); |
+ if (descriptor_type != TYPE_DEVICE) |
+ continue; |
+ bool result = ParseDevice(current, length, info); |
+ if (!result) |
+ *info = DeviceInfo(); |
Takashi Toyoshima
2015/04/22 05:25:13
Shall we initialize *info always at the beginning
yhirano
2015/04/22 06:11:09
You're right, thanks. Done.
|
+ return result; |
+ } |
+ // No DEVICE descriptor is found. |
+ *info = DeviceInfo(); |
+ return false; |
+} |
+ |
bool UsbMidiDescriptorParser::ParseInternal(UsbMidiDevice* device, |
const uint8* data, |
size_t size, |
@@ -129,6 +156,21 @@ bool UsbMidiDescriptorParser::ParseInternal(UsbMidiDevice* device, |
return true; |
} |
+bool UsbMidiDescriptorParser::ParseDevice( |
+ const uint8* data, size_t size, DeviceInfo* info) { |
+ if (size < 0x12) { |
+ DVLOG(1) << "DEVICE header size is incorrect."; |
+ return false; |
+ } |
+ |
+ info->vendor_id = data[8] | (data[9] << 8); |
+ info->product_id = data[0xa] | (data[0xb] << 8); |
+ info->bcd_device_version = data[0xc] | (data[0xd] << 8); |
+ info->manufacturer_index = data[0xe]; |
+ info->product_index = data[0xf]; |
+ return true; |
+} |
+ |
bool UsbMidiDescriptorParser::ParseInterface(const uint8* data, size_t size) { |
if (size != 9) { |
DVLOG(1) << "INTERFACE header size is incorrect."; |