| Index: content/browser/media/midi_host.cc
|
| diff --git a/content/browser/media/midi_host.cc b/content/browser/media/midi_host.cc
|
| index 73d131c31a655b142b217640a75f846c42adfcf4..af57a91a8e3fa0204befbd3e095530d9452015eb 100644
|
| --- a/content/browser/media/midi_host.cc
|
| +++ b/content/browser/media/midi_host.cc
|
| @@ -6,7 +6,6 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| -#include "base/metrics/histogram_macros.h"
|
| #include "base/process/process.h"
|
| #include "base/trace_event/trace_event.h"
|
| #include "content/browser/bad_message.h"
|
| @@ -15,9 +14,9 @@
|
| #include "content/common/media/midi_messages.h"
|
| #include "content/public/browser/content_browser_client.h"
|
| #include "content/public/browser/user_metrics.h"
|
| +#include "media/midi/message_util.h"
|
| #include "media/midi/midi_manager.h"
|
| #include "media/midi/midi_message_queue.h"
|
| -#include "media/midi/midi_message_util.h"
|
|
|
| namespace content {
|
| namespace {
|
| @@ -32,16 +31,12 @@ const size_t kMaxInFlightBytes = 10 * 1024 * 1024; // 10 MB.
|
| // how many bytes will be sent before reporting back to the renderer.
|
| const size_t kAcknowledgementThresholdBytes = 1024 * 1024; // 1 MB.
|
|
|
| -bool IsDataByte(uint8_t data) {
|
| - return (data & 0x80) == 0;
|
| -}
|
| -
|
| -bool IsSystemRealTimeMessage(uint8_t data) {
|
| - return 0xf8 <= data && data <= 0xff;
|
| -}
|
| -
|
| } // namespace
|
|
|
| +using midi::IsDataByte;
|
| +using midi::IsSystemRealTimeMessage;
|
| +using midi::IsValidWebMIDIData;
|
| +using midi::MidiPortInfo;
|
| using midi::kSysExByte;
|
| using midi::kEndOfSysExByte;
|
| using midi::mojom::Result;
|
| @@ -153,14 +148,14 @@ void MidiHost::CompleteStartSession(Result result) {
|
| Send(new MidiMsg_SessionStarted(result));
|
| }
|
|
|
| -void MidiHost::AddInputPort(const midi::MidiPortInfo& info) {
|
| +void MidiHost::AddInputPort(const MidiPortInfo& info) {
|
| base::AutoLock auto_lock(messages_queues_lock_);
|
| // MidiMessageQueue is created later in ReceiveMidiData().
|
| received_messages_queues_.push_back(nullptr);
|
| Send(new MidiMsg_AddInputPort(info));
|
| }
|
|
|
| -void MidiHost::AddOutputPort(const midi::MidiPortInfo& info) {
|
| +void MidiHost::AddOutputPort(const MidiPortInfo& info) {
|
| base::AutoLock auto_lock(output_port_count_lock_);
|
| output_port_count_++;
|
| Send(new MidiMsg_AddOutputPort(info));
|
| @@ -231,42 +226,4 @@ void MidiHost::Detach() {
|
| midi_manager_ = nullptr;
|
| }
|
|
|
| -// static
|
| -bool MidiHost::IsValidWebMIDIData(const std::vector<uint8_t>& data) {
|
| - bool in_sysex = false;
|
| - size_t sysex_start_offset = 0;
|
| - size_t waiting_data_length = 0;
|
| - for (size_t i = 0; i < data.size(); ++i) {
|
| - const uint8_t current = data[i];
|
| - if (IsSystemRealTimeMessage(current))
|
| - continue; // Real time message can be placed at any point.
|
| - if (waiting_data_length > 0) {
|
| - if (!IsDataByte(current))
|
| - return false; // Error: |current| should have been data byte.
|
| - --waiting_data_length;
|
| - continue; // Found data byte as expected.
|
| - }
|
| - if (in_sysex) {
|
| - if (data[i] == kEndOfSysExByte) {
|
| - in_sysex = false;
|
| - UMA_HISTOGRAM_COUNTS("Media.Midi.SysExMessageSizeUpTo1MB",
|
| - i - sysex_start_offset + 1);
|
| - } else if (!IsDataByte(current)) {
|
| - return false; // Error: |current| should have been data byte.
|
| - }
|
| - continue; // Found data byte as expected.
|
| - }
|
| - if (current == kSysExByte) {
|
| - in_sysex = true;
|
| - sysex_start_offset = i;
|
| - continue; // Found SysEX
|
| - }
|
| - waiting_data_length = midi::GetMidiMessageLength(current);
|
| - if (waiting_data_length == 0)
|
| - return false; // Error: |current| should have been a valid status byte.
|
| - --waiting_data_length; // Found status byte
|
| - }
|
| - return waiting_data_length == 0 && !in_sysex;
|
| -}
|
| -
|
| } // namespace content
|
|
|