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
3 // found in the LICENSE file.
5 #ifndef MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_
6 #define MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_
11 #include "base/basictypes.h"
12 #include "media/midi/usb_midi_export.h"
13 #include "media/midi/usb_midi_jack.h"
20 // UsbMidiDescriptorParser parses USB descriptors and
21 // generates input / output lists of MIDIPortInfo.
22 // This is not a generic USB descriptor parser: this parser is designed
23 // for collecting USB-MIDI jacks information from the descriptor.
24 class USB_MIDI_EXPORT UsbMidiDescriptorParser
{
30 bcd_device_version(0),
31 manufacturer_index(0),
35 // The higher one byte represents the "major" number and the lower one byte
36 // represents the "minor" number.
37 uint16 bcd_device_version
;
38 uint8 manufacturer_index
;
41 static std::string
BcdVersionToString(uint16
);
44 UsbMidiDescriptorParser();
45 ~UsbMidiDescriptorParser();
47 // Returns true if the operation succeeds.
48 // When an incorrect input is given, this method may return true but
50 bool Parse(UsbMidiDevice
* device
,
53 std::vector
<UsbMidiJack
>* jacks
);
55 bool ParseDeviceInfo(const uint8
* data
, size_t size
, DeviceInfo
* info
);
58 bool ParseInternal(UsbMidiDevice
* device
,
61 std::vector
<UsbMidiJack
>* jacks
);
62 bool ParseDevice(const uint8
* data
, size_t size
, DeviceInfo
* info
);
63 bool ParseInterface(const uint8
* data
, size_t size
);
64 bool ParseCSInterface(UsbMidiDevice
* device
, const uint8
* data
, size_t size
);
65 bool ParseEndpoint(const uint8
* data
, size_t size
);
66 bool ParseCSEndpoint(const uint8
* data
,
68 std::vector
<UsbMidiJack
>* jacks
);
71 bool is_parsing_usb_midi_interface_
;
72 uint8 current_endpoint_address_
;
73 uint8 current_cable_number_
;
75 std::vector
<UsbMidiJack
> incomplete_jacks_
;
77 DISALLOW_COPY_AND_ASSIGN(UsbMidiDescriptorParser
);
83 #endif // MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_