OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 class MEDIA_EXPORT UsbMidiInputStream { |
| 21 public: |
| 22 class Delegate { |
| 23 public: |
| 24 virtual ~Delegate() {} |
| 25 // This function is called when some data arrives to a USB-MIDI jack. |
| 26 // An input USB-MIDI jack corresponds to an input MIDIPortInfo. |
| 27 virtual void OnReceivedData(size_t jack_index, |
| 28 const uint8* data, |
| 29 size_t size, |
| 30 double timestamp) = 0; |
| 31 }; |
| 32 |
| 33 UsbMidiInputStream(const std::vector<UsbMidiJack>& jacks, |
| 34 Delegate* delegate); |
| 35 ~UsbMidiInputStream(); |
| 36 void OnReceivedData(UsbMidiDevice* device, |
| 37 int endpoint_number, |
| 38 const uint8* data, |
| 39 size_t size, |
| 40 double timestamp); |
| 41 const std::vector<UsbMidiJack>& jacks() const { return jacks_; } |
| 42 |
| 43 private: |
| 44 static const size_t kPacketSize = 4; |
| 45 struct JackUniqueKey { |
| 46 JackUniqueKey(UsbMidiDevice* device, int endpoint_number, int cable_number); |
| 47 bool operator==(const JackUniqueKey& key) const; |
| 48 |
| 49 UsbMidiDevice* device; |
| 50 int endpoint_number; |
| 51 int cable_number; |
| 52 }; |
| 53 |
| 54 struct JackHash { |
| 55 size_t operator()(const JackUniqueKey& key) const; |
| 56 }; |
| 57 |
| 58 void OnReceivedData(size_t jack_index, |
| 59 const uint8* data, |
| 60 size_t size, |
| 61 double timestamp); |
| 62 // |packet[0:4]| must be accessible. |
| 63 void ProcessOnePacket(UsbMidiDevice* device, |
| 64 int endpoint_number, |
| 65 const uint8* packet, |
| 66 double timestamp); |
| 67 |
| 68 const std::vector<UsbMidiJack> jacks_; |
| 69 // A map from UsbMidiJack to its index in |jacks_|. |
| 70 base::hash_map<JackUniqueKey, size_t, JackHash> jack_dictionary_; |
| 71 |
| 72 // Not owned |
| 73 Delegate* delegate_; |
| 74 uint8 pending_data_[kPacketSize]; |
| 75 size_t pending_size_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStream); |
| 78 }; |
| 79 |
| 80 } // namespace media |
| 81 |
| 82 #endif // MEDIA_MIDI_USB_MIDI_INPUT_STREAM_H_ |
OLD | NEW |