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_
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"
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
{
26 class MEDIA_EXPORT Delegate
{
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
,
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
;
48 UsbMidiInputStream(const std::vector
<UsbMidiJack
>& jacks
,
50 ~UsbMidiInputStream();
52 // This function should be called when some data arrives to a USB-MIDI
53 // endpoint. This function converts the data to MIDI data and call
54 // |delegate->OnReceivedData| with it.
55 // |size| must be a multiple of |kPacketSize|.
56 void OnReceivedData(UsbMidiDevice
* device
,
60 base::TimeTicks time
);
62 std::vector
<JackUniqueKey
> RegisteredJackKeysForTesting() const;
65 static const size_t kPacketSize
= 4;
66 // Processes a USB-MIDI Event Packet.
67 // The first |kPacketSize| bytes of |packet| must be accessible.
68 void ProcessOnePacket(UsbMidiDevice
* device
,
71 base::TimeTicks time
);
73 // A map from UsbMidiJack to its index in |jacks_|.
74 std::map
<JackUniqueKey
, size_t> jack_dictionary_
;
79 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStream
);
84 #endif // MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_