[Extensions Toolbar] Move context menu logic to view delegates
[chromium-blink-merge.git] / media / midi / usb_midi_descriptor_parser.h
blobcc07be3b259673ed64ca33e0b377730a39b401e3
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_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "media/base/media_export.h"
13 #include "media/midi/usb_midi_jack.h"
15 namespace media {
17 class UsbMidiDevice;
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 {
24 public:
25 struct DeviceInfo {
26 DeviceInfo()
27 : vendor_id(0),
28 product_id(0),
29 bcd_device_version(0),
30 manufacturer_index(0),
31 product_index(0) {}
32 uint16 vendor_id;
33 uint16 product_id;
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;
38 uint8 product_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
48 // never crashes.
49 bool Parse(UsbMidiDevice* device,
50 const uint8* data,
51 size_t size,
52 std::vector<UsbMidiJack>* jacks);
54 bool ParseDeviceInfo(const uint8* data, size_t size, DeviceInfo* info);
56 private:
57 bool ParseInternal(UsbMidiDevice* device,
58 const uint8* data,
59 size_t size,
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,
66 size_t size,
67 std::vector<UsbMidiJack>* jacks);
68 void Clear();
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);
80 } // namespace media
82 #endif // MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_