• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_
6 #define MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_
7 
8 #include <vector>
9 
10 #include "base/basictypes.h"
11 #include "media/base/media_export.h"
12 #include "media/midi/usb_midi_jack.h"
13 
14 namespace media {
15 
16 class UsbMidiDevice;
17 
18 // UsbMidiDescriptorParser parses USB descriptors and
19 // generates input / output lists of MIDIPortInfo.
20 // This is not a generic USB descriptor parser: this parser is designed
21 // for collecting USB-MIDI jacks information from the descriptor.
22 class MEDIA_EXPORT UsbMidiDescriptorParser {
23  public:
24   UsbMidiDescriptorParser();
25   ~UsbMidiDescriptorParser();
26 
27   // Returns true if the operation succeeds.
28   // When an incorrect input is given, this method may return true but
29   // never crashes.
30   bool Parse(UsbMidiDevice* device,
31              const uint8* data,
32              size_t size,
33              std::vector<UsbMidiJack>* jacks);
34 
35  private:
36   bool ParseInternal(UsbMidiDevice* device,
37                      const uint8* data,
38                      size_t size,
39                      std::vector<UsbMidiJack>* jacks);
40   bool ParseInterface(const uint8* data, size_t size);
41   bool ParseCSInterface(UsbMidiDevice* device, const uint8* data, size_t size);
42   bool ParseEndpoint(const uint8* data, size_t size);
43   bool ParseCSEndpoint(const uint8* data,
44                        size_t size,
45                        std::vector<UsbMidiJack>* jacks);
46   void Clear();
47 
48   bool is_parsing_usb_midi_interface_;
49   uint8 current_endpoint_address_;
50   uint8 current_cable_number_;
51 
52   std::vector<UsbMidiJack> incomplete_jacks_;
53 
54   DISALLOW_COPY_AND_ASSIGN(UsbMidiDescriptorParser);
55 };
56 
57 
58 }  // namespace media
59 
60 #endif  // MEDIA_MIDI_USB_MIDI_DESCRIPTOR_PARSER_H_
61