Add some instrumentation for jank in URLRequest::Start.
[chromium-blink-merge.git] / media / midi / usb_midi_input_stream.h
blobbd12706eb203ddb18aef0bb0aeb441314928bf44
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/base/media_export.h"
15 #include "media/midi/usb_midi_jack.h"
17 namespace media {
19 class UsbMidiDevice;
21 // UsbMidiInputStream converts USB-MIDI data to MIDI data.
22 // See "USB Device Class Definition for MIDI Devices" Release 1.0,
23 // Section 4 "USB-MIDI Event Packets" for details.
24 class MEDIA_EXPORT UsbMidiInputStream {
25 public:
26 class MEDIA_EXPORT Delegate {
27 public:
28 virtual ~Delegate() {}
29 // This function is called when some data arrives to a USB-MIDI jack.
30 // An input USB-MIDI jack corresponds to an input MIDIPortInfo.
31 virtual void OnReceivedData(size_t jack_index,
32 const uint8* data,
33 size_t size,
34 base::TimeTicks time) = 0;
37 // This is public for testing.
38 struct JackUniqueKey {
39 JackUniqueKey(UsbMidiDevice* device, int endpoint_number, int cable_number);
40 bool operator==(const JackUniqueKey& that) const;
41 bool operator<(const JackUniqueKey& that) const;
43 UsbMidiDevice* device;
44 int endpoint_number;
45 int cable_number;
48 explicit UsbMidiInputStream(Delegate* delegate);
49 ~UsbMidiInputStream();
51 void Add(const UsbMidiJack& jack);
53 // This function should be called when some data arrives to a USB-MIDI
54 // endpoint. This function converts the data to MIDI data and call
55 // |delegate->OnReceivedData| with it.
56 // |size| must be a multiple of |kPacketSize|.
57 void OnReceivedData(UsbMidiDevice* device,
58 int endpoint_number,
59 const uint8* data,
60 size_t size,
61 base::TimeTicks time);
63 const std::vector<UsbMidiJack>& jacks() const { return jacks_; }
65 private:
66 static const size_t kPacketSize = 4;
67 // Processes a USB-MIDI Event Packet.
68 // The first |kPacketSize| bytes of |packet| must be accessible.
69 void ProcessOnePacket(UsbMidiDevice* device,
70 int endpoint_number,
71 const uint8* packet,
72 base::TimeTicks time);
74 std::vector<UsbMidiJack> jacks_;
75 // A map from UsbMidiJack to its index in |jacks_|.
76 std::map<JackUniqueKey, size_t> jack_dictionary_;
78 // Not owned
79 Delegate* delegate_;
81 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStream);
84 } // namespace media
86 #endif // MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_