OLD | NEW |
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 #include "media/midi/usb_midi_input_stream.h" | 5 #include "media/midi/usb_midi_input_stream.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/midi/usb_midi_device.h" | 10 #include "media/midi/usb_midi_device.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 jack.endpoint_number(), | 45 jack.endpoint_number(), |
46 jack.cable_number); | 46 jack.cable_number); |
47 | 47 |
48 jacks_.push_back(jack); | 48 jacks_.push_back(jack); |
49 DCHECK(jack_dictionary_.end() == jack_dictionary_.find(key)); | 49 DCHECK(jack_dictionary_.end() == jack_dictionary_.find(key)); |
50 jack_dictionary_.insert(std::make_pair(key, jack_dictionary_.size())); | 50 jack_dictionary_.insert(std::make_pair(key, jack_dictionary_.size())); |
51 } | 51 } |
52 | 52 |
53 void UsbMidiInputStream::OnReceivedData(UsbMidiDevice* device, | 53 void UsbMidiInputStream::OnReceivedData(UsbMidiDevice* device, |
54 int endpoint_number, | 54 int endpoint_number, |
55 const uint8* data, | 55 const uint8_t* data, |
56 size_t size, | 56 size_t size, |
57 base::TimeTicks time) { | 57 base::TimeTicks time) { |
58 DCHECK_EQ(0u, size % kPacketSize); | 58 DCHECK_EQ(0u, size % kPacketSize); |
59 size_t current = 0; | 59 size_t current = 0; |
60 while (current + kPacketSize <= size) { | 60 while (current + kPacketSize <= size) { |
61 ProcessOnePacket(device, endpoint_number, &data[current], time); | 61 ProcessOnePacket(device, endpoint_number, &data[current], time); |
62 current += kPacketSize; | 62 current += kPacketSize; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void UsbMidiInputStream::ProcessOnePacket(UsbMidiDevice* device, | 66 void UsbMidiInputStream::ProcessOnePacket(UsbMidiDevice* device, |
67 int endpoint_number, | 67 int endpoint_number, |
68 const uint8* packet, | 68 const uint8_t* packet, |
69 base::TimeTicks time) { | 69 base::TimeTicks time) { |
70 // The first 4 bytes of the packet is accessible here. | 70 // The first 4 bytes of the packet is accessible here. |
71 uint8 code_index = packet[0] & 0x0f; | 71 uint8_t code_index = packet[0] & 0x0f; |
72 uint8 cable_number = packet[0] >> 4; | 72 uint8_t cable_number = packet[0] >> 4; |
73 const size_t packet_size_table[16] = { | 73 const size_t packet_size_table[16] = { |
74 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1, | 74 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1, |
75 }; | 75 }; |
76 size_t packet_size = packet_size_table[code_index]; | 76 size_t packet_size = packet_size_table[code_index]; |
77 if (packet_size == 0) { | 77 if (packet_size == 0) { |
78 // These CINs are reserved. Ignore them. | 78 // These CINs are reserved. Ignore them. |
79 DVLOG(1) << "code index number (" << code_index << ") arrives " | 79 DVLOG(1) << "code index number (" << code_index << ") arrives " |
80 << "but it is reserved."; | 80 << "but it is reserved."; |
81 return; | 81 return; |
82 } | 82 } |
83 std::map<JackUniqueKey, size_t>::const_iterator it = | 83 std::map<JackUniqueKey, size_t>::const_iterator it = |
84 jack_dictionary_.find(JackUniqueKey(device, | 84 jack_dictionary_.find(JackUniqueKey(device, |
85 endpoint_number, | 85 endpoint_number, |
86 cable_number)); | 86 cable_number)); |
87 if (it != jack_dictionary_.end()) | 87 if (it != jack_dictionary_.end()) |
88 delegate_->OnReceivedData(it->second, &packet[1], packet_size, time); | 88 delegate_->OnReceivedData(it->second, &packet[1], packet_size, time); |
89 } | 89 } |
90 | 90 |
91 } // namespace midi | 91 } // namespace midi |
92 } // namespace media | 92 } // namespace media |
OLD | NEW |