OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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_INPUT_STREAM_H_ |
| 6 #define MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/containers/hash_tables.h" |
| 12 #include "media/base/media_export.h" |
| 13 #include "media/midi/usb_midi_jack.h" |
| 14 |
| 15 namespace media { |
| 16 |
| 17 class UsbMidiDevice; |
| 18 |
| 19 // UsbMidiInputStream converts USB-MIDI data to MIDI data. |
| 20 // See "USB Device Class Definition for MIDI Devices" Release 1.0, |
| 21 // Section 4 "USB-MIDI Event Packets" for details. |
| 22 class MEDIA_EXPORT UsbMidiInputStream { |
| 23 public: |
| 24 class Delegate { |
| 25 public: |
| 26 virtual ~Delegate() {} |
| 27 // This function is called when some data arrives to a USB-MIDI jack. |
| 28 // An input USB-MIDI jack corresponds to an input MIDIPortInfo. |
| 29 virtual void OnReceivedData(size_t jack_index, |
| 30 const uint8* data, |
| 31 size_t size, |
| 32 double timestamp) = 0; |
| 33 }; |
| 34 |
| 35 UsbMidiInputStream(const std::vector<UsbMidiJack>& jacks, |
| 36 Delegate* delegate); |
| 37 ~UsbMidiInputStream(); |
| 38 void OnReceivedData(UsbMidiDevice* device, |
| 39 int endpoint_number, |
| 40 const uint8* data, |
| 41 size_t size, |
| 42 double timestamp); |
| 43 const std::vector<UsbMidiJack>& jacks() const { return jacks_; } |
| 44 |
| 45 private: |
| 46 static const size_t kPacketSize = 4; |
| 47 struct JackUniqueKey { |
| 48 JackUniqueKey(UsbMidiDevice* device, int endpoint_number, int cable_number); |
| 49 bool operator==(const JackUniqueKey& key) const; |
| 50 |
| 51 UsbMidiDevice* device; |
| 52 int endpoint_number; |
| 53 int cable_number; |
| 54 }; |
| 55 |
| 56 struct JackHash { |
| 57 size_t operator()(const JackUniqueKey& key) const; |
| 58 }; |
| 59 |
| 60 // |size| must be a multiple of |kPacketSize|. |
| 61 void OnReceivedData(size_t jack_index, |
| 62 const uint8* data, |
| 63 size_t size, |
| 64 double timestamp); |
| 65 |
| 66 // Processes a USB-MIDI Event Packet. |
| 67 // The first |kPacketSize| bytes of |packet| must be accessible. |
| 68 void ProcessOnePacket(UsbMidiDevice* device, |
| 69 int endpoint_number, |
| 70 const uint8* packet, |
| 71 double timestamp); |
| 72 |
| 73 const std::vector<UsbMidiJack> jacks_; |
| 74 // A map from UsbMidiJack to its index in |jacks_|. |
| 75 base::hash_map<JackUniqueKey, size_t, JackHash> jack_dictionary_; |
| 76 |
| 77 // Not owned |
| 78 Delegate* delegate_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStream); |
| 81 }; |
| 82 |
| 83 } // namespace media |
| 84 |
| 85 #endif // MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_ |
OLD | NEW |