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/base/media_export.h"
13 #include "media/midi/usb_midi_jack.h"
19 // UsbMidiDescriptorParser parses USB descriptors and
20 // generates input / output lists of MIDIPortInfo.
21 // This is not a generic USB descriptor parser: this parser is designed
22 // for collecting USB-MIDI jacks information from the descriptor.
23 class MEDIA_EXPORT UsbMidiDescriptorParser
{
29 bcd_device_version(0),
30 manufacturer_index(0),
34 // The higher one byte represents the "major" number and the lower one byte
35 // represents the "minor" number.
36 uint16 bcd_device_version
;
37 uint8 manufacturer_index
;
40 static std::string
BcdVersionToString(uint16
);
43 UsbMidiDescriptorParser();
44 ~UsbMidiDescriptorParser();
46 // Returns true if the operation succeeds.
47 // When an incorrect input is given, this method may return true but
49 bool Parse(UsbMidiDevice
* device
,
52 std::vector
<UsbMidiJack
>* jacks
);
54 bool ParseDeviceInfo(const uint8
* data
, size_t size
, DeviceInfo
* info
);
57 bool ParseInternal(UsbMidiDevice
* device
,
60 std::vector
<UsbMidiJack
>* jacks
);
61 bool ParseDevice(const uint8
* data
, size_t size
, DeviceInfo
* info
);
62 bool ParseInterface(const uint8
* data
, size_t size
);
63 bool ParseCSInterface(UsbMidiDevice
* device
, const uint8
* data
, size_t size
);
64 bool ParseEndpoint(const uint8
* data
, size_t size
);
65 bool ParseCSEndpoint(const uint8
* data
,
67 std::vector
<UsbMidiJack
>* jacks
);
70 bool is_parsing_usb_midi_interface_
;
71 uint8 current_endpoint_address_
;
72 uint8 current_cable_number_
;
74 std::vector
<UsbMidiJack
> incomplete_jacks_
;
76 DISALLOW_COPY_AND_ASSIGN(UsbMidiDescriptorParser
);
82 #endif // MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_