Plugin Power Saver: Fix a nullptr crash with plugin placeholder resize.
[chromium-blink-merge.git] / media / midi / usb_midi_descriptor_parser.h
blob8f741ca4cf9b106126c5bb45e4d1373a4d71af87
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/midi/usb_midi_export.h"
13 #include "media/midi/usb_midi_jack.h"
15 namespace media {
16 namespace midi {
18 class UsbMidiDevice;
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 {
25 public:
26 struct DeviceInfo {
27 DeviceInfo()
28 : vendor_id(0),
29 product_id(0),
30 bcd_device_version(0),
31 manufacturer_index(0),
32 product_index(0) {}
33 uint16 vendor_id;
34 uint16 product_id;
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;
39 uint8 product_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
49 // never crashes.
50 bool Parse(UsbMidiDevice* device,
51 const uint8* data,
52 size_t size,
53 std::vector<UsbMidiJack>* jacks);
55 bool ParseDeviceInfo(const uint8* data, size_t size, DeviceInfo* info);
57 private:
58 bool ParseInternal(UsbMidiDevice* device,
59 const uint8* data,
60 size_t size,
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,
67 size_t size,
68 std::vector<UsbMidiJack>* jacks);
69 void Clear();
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);
80 } // namespace midi
81 } // namespace media
83 #endif // MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_