Update V8 to version 4.7.42.
[chromium-blink-merge.git] / media / midi / usb_midi_input_stream.h
blob8fb732e8017b47442681a5c54aefa129e597e2bd
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_INPUT_STREAM_H_
6 #define MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_
8 #include <map>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/time/time.h"
14 #include "media/midi/usb_midi_export.h"
15 #include "media/midi/usb_midi_jack.h"
17 namespace media {
18 namespace midi {
20 class UsbMidiDevice;
22 // UsbMidiInputStream converts USB-MIDI data to MIDI data.
23 // See "USB Device Class Definition for MIDI Devices" Release 1.0,
24 // Section 4 "USB-MIDI Event Packets" for details.
25 class USB_MIDI_EXPORT UsbMidiInputStream {
26 public:
27 class USB_MIDI_EXPORT Delegate {
28 public:
29 virtual ~Delegate() {}
30 // This function is called when some data arrives to a USB-MIDI jack.
31 // An input USB-MIDI jack corresponds to an input MIDIPortInfo.
32 virtual void OnReceivedData(size_t jack_index,
33 const uint8* data,
34 size_t size,
35 base::TimeTicks time) = 0;
38 // This is public for testing.
39 struct JackUniqueKey {
40 JackUniqueKey(UsbMidiDevice* device, int endpoint_number, int cable_number);
41 bool operator==(const JackUniqueKey& that) const;
42 bool operator<(const JackUniqueKey& that) const;
44 UsbMidiDevice* device;
45 int endpoint_number;
46 int cable_number;
49 explicit UsbMidiInputStream(Delegate* delegate);
50 ~UsbMidiInputStream();
52 void Add(const UsbMidiJack& jack);
54 // This function should be called when some data arrives to a USB-MIDI
55 // endpoint. This function converts the data to MIDI data and call
56 // |delegate->OnReceivedData| with it.
57 // |size| must be a multiple of |kPacketSize|.
58 void OnReceivedData(UsbMidiDevice* device,
59 int endpoint_number,
60 const uint8* data,
61 size_t size,
62 base::TimeTicks time);
64 const std::vector<UsbMidiJack>& jacks() const { return jacks_; }
66 private:
67 static const size_t kPacketSize = 4;
68 // Processes a USB-MIDI Event Packet.
69 // The first |kPacketSize| bytes of |packet| must be accessible.
70 void ProcessOnePacket(UsbMidiDevice* device,
71 int endpoint_number,
72 const uint8* packet,
73 base::TimeTicks time);
75 std::vector<UsbMidiJack> jacks_;
76 // A map from UsbMidiJack to its index in |jacks_|.
77 std::map<JackUniqueKey, size_t> jack_dictionary_;
79 // Not owned
80 Delegate* delegate_;
82 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStream);
85 } // namespace midi
86 } // namespace media
88 #endif // MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_