Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: media/midi/usb_midi_input_stream.h

Issue 107163008: [WebMIDI] Introduce MidiManagerUsb (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-midi-stream
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_ 5 #ifndef MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_
6 #define MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_ 6 #define MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 15 matching lines...) Expand all
26 public: 26 public:
27 virtual ~Delegate() {} 27 virtual ~Delegate() {}
28 // This function is called when some data arrives to a USB-MIDI jack. 28 // This function is called when some data arrives to a USB-MIDI jack.
29 // An input USB-MIDI jack corresponds to an input MIDIPortInfo. 29 // An input USB-MIDI jack corresponds to an input MIDIPortInfo.
30 virtual void OnReceivedData(size_t jack_index, 30 virtual void OnReceivedData(size_t jack_index,
31 const uint8* data, 31 const uint8* data,
32 size_t size, 32 size_t size,
33 double timestamp) = 0; 33 double timestamp) = 0;
34 }; 34 };
35 35
36 // This is public for testing.
37 struct JackUniqueKey {
38 JackUniqueKey(UsbMidiDevice* device, int endpoint_number, int cable_number);
39 bool operator==(const JackUniqueKey& that) const;
40 bool operator<(const JackUniqueKey& that) const;
41
42 UsbMidiDevice* device;
43 int endpoint_number;
44 int cable_number;
45 };
46
36 UsbMidiInputStream(const std::vector<UsbMidiJack>& jacks, 47 UsbMidiInputStream(const std::vector<UsbMidiJack>& jacks,
37 Delegate* delegate); 48 Delegate* delegate);
38 ~UsbMidiInputStream(); 49 ~UsbMidiInputStream();
39 50
40 // This function should be called when some data arrives to a USB-MIDI 51 // This function should be called when some data arrives to a USB-MIDI
41 // endpoint. This function converts the data to MIDI data and call 52 // endpoint. This function converts the data to MIDI data and call
42 // |delegate->OnReceivedData| with it. 53 // |delegate->OnReceivedData| with it.
43 // |size| must be a multiple of |kPacketSize|. 54 // |size| must be a multiple of |kPacketSize|.
44 void OnReceivedData(UsbMidiDevice* device, 55 void OnReceivedData(UsbMidiDevice* device,
45 int endpoint_number, 56 int endpoint_number,
46 const uint8* data, 57 const uint8* data,
47 size_t size, 58 size_t size,
48 double timestamp); 59 double timestamp);
49 60
61 // This function is for testing.
62 std::vector<JackUniqueKey> RegisteredJackKeys() const;
scherkus (not reviewing) 2014/01/27 19:23:49 instead of having a comment saying this is for tes
yhirano 2014/01/28 04:31:05 Done.
63
50 private: 64 private:
51 static const size_t kPacketSize = 4; 65 static const size_t kPacketSize = 4;
52 struct JackUniqueKey {
53 JackUniqueKey(UsbMidiDevice* device, int endpoint_number, int cable_number);
54 bool operator==(const JackUniqueKey& that) const;
55 bool operator<(const JackUniqueKey& that) const;
56
57 UsbMidiDevice* device;
58 int endpoint_number;
59 int cable_number;
60 };
61
62 // Processes a USB-MIDI Event Packet. 66 // Processes a USB-MIDI Event Packet.
63 // The first |kPacketSize| bytes of |packet| must be accessible. 67 // The first |kPacketSize| bytes of |packet| must be accessible.
64 void ProcessOnePacket(UsbMidiDevice* device, 68 void ProcessOnePacket(UsbMidiDevice* device,
65 int endpoint_number, 69 int endpoint_number,
66 const uint8* packet, 70 const uint8* packet,
67 double timestamp); 71 double timestamp);
68 72
69 // A map from UsbMidiJack to its index in |jacks_|. 73 // A map from UsbMidiJack to its index in |jacks_|.
70 std::map<JackUniqueKey, size_t> jack_dictionary_; 74 std::map<JackUniqueKey, size_t> jack_dictionary_;
71 75
72 // Not owned 76 // Not owned
73 Delegate* delegate_; 77 Delegate* delegate_;
74 78
75 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStream); 79 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStream);
76 }; 80 };
77 81
78 } // namespace media 82 } // namespace media
79 83
80 #endif // MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_ 84 #endif // MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698