summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authortoyoshim <toyoshim@chromium.org>2015-04-30 07:52:02 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-30 14:52:36 +0000
commitc6475779990f6ffdfa33d42b0bd97818df5e8d3c (patch)
tree8d7993b714b48c21c570833127f06c3e6a0c545f /media
parent3140c7194502109de2f7803d00e68fc10c94d2b6 (diff)
downloadchromium_src-c6475779990f6ffdfa33d42b0bd97818df5e8d3c.zip
chromium_src-c6475779990f6ffdfa33d42b0bd97818df5e8d3c.tar.gz
chromium_src-c6475779990f6ffdfa33d42b0bd97818df5e8d3c.tar.bz2
Reland: Web MIDI: split build rules for media/midi
Changes from the first coommit. - Define right dependencies to xdisplaycheck - Fix build rules for midi_unittests_apk to run on Android - Rebase error fixes (build rule deopendency adjustments) Original commit is: https://crrev.com/31624cad1a3b5cf26950b864837ba44b3aa38331 Original description follows: Split MIDI related stuffs from media as a component in build files. Also, MIDI related unit tests are split into midi_unittests. BUG=475869 TEST=git cl try TEST=ninja midi_unittests_apk && ./build/android/test_runner.py gtest midi_unittests Review URL: https://codereview.chromium.org/1065743003 Cr-Commit-Position: refs/heads/master@{#327712}
Diffstat (limited to 'media')
-rw-r--r--media/BUILD.gn65
-rw-r--r--media/OWNERS5
-rw-r--r--media/base/android/BUILD.gn2
-rw-r--r--media/base/android/media_jni_registrar.cc6
-rw-r--r--media/media.gyp60
-rw-r--r--media/midi/BUILD.gn172
-rw-r--r--media/midi/java/src/org/chromium/media/midi/UsbMidiDeviceAndroid.java (renamed from media/base/android/java/src/org/chromium/media/UsbMidiDeviceAndroid.java)23
-rw-r--r--media/midi/java/src/org/chromium/media/midi/UsbMidiDeviceFactoryAndroid.java (renamed from media/base/android/java/src/org/chromium/media/UsbMidiDeviceFactoryAndroid.java)20
-rw-r--r--media/midi/midi.gyp235
-rw-r--r--media/midi/midi_jni_registrar.cc29
-rw-r--r--media/midi/midi_jni_registrar.h21
-rw-r--r--media/midi/midi_manager_usb.cc10
-rw-r--r--media/midi/midi_manager_win.cc6
-rw-r--r--media/midi/midi_scheduler.h3
-rw-r--r--media/midi/midi_unittests.isolate63
-rw-r--r--media/midi/usb_midi_device_android.cc18
-rw-r--r--media/midi/usb_midi_device_factory_android.cc8
-rw-r--r--media/midi/usb_midi_output_stream.cc2
18 files changed, 567 insertions, 181 deletions
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 4c8d52a..b62b0ea 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -32,9 +32,6 @@ config("media_config") {
if (use_cras) {
defines += [ "USE_CRAS" ]
}
- if (use_alsa) {
- defines += [ "USE_ALSA" ]
- }
}
config("media_implementation") {
@@ -178,30 +175,6 @@ component("media") {
"formats/webm/webm_video_client.h",
"formats/webm/webm_webvtt_parser.cc",
"formats/webm/webm_webvtt_parser.h",
- "midi/midi_manager.cc",
- "midi/midi_manager.h",
- "midi/midi_manager_mac.cc",
- "midi/midi_manager_mac.h",
- "midi/midi_manager_usb.cc",
- "midi/midi_manager_usb.h",
- "midi/midi_manager_win.cc",
- "midi/midi_manager_win.h",
- "midi/midi_message_queue.cc",
- "midi/midi_message_queue.h",
- "midi/midi_message_util.cc",
- "midi/midi_message_util.h",
- "midi/midi_port_info.cc",
- "midi/midi_port_info.h",
- "midi/midi_scheduler.cc",
- "midi/midi_scheduler.h",
- "midi/usb_midi_descriptor_parser.cc",
- "midi/usb_midi_descriptor_parser.h",
- "midi/usb_midi_device.h",
- "midi/usb_midi_input_stream.cc",
- "midi/usb_midi_input_stream.h",
- "midi/usb_midi_jack.h",
- "midi/usb_midi_output_stream.cc",
- "midi/usb_midi_output_stream.h",
"renderers/audio_renderer_impl.cc",
"renderers/audio_renderer_impl.h",
"renderers/gpu_video_accelerator_factories.h",
@@ -337,11 +310,6 @@ component("media") {
if (is_android) {
sources += [
- "midi/midi_manager_android.cc",
- "midi/usb_midi_device_android.cc",
- "midi/usb_midi_device_android.h",
- "midi/usb_midi_device_factory_android.cc",
- "midi/usb_midi_device_factory_android.h",
"video/capture/android/video_capture_device_android.cc",
"video/capture/android/video_capture_device_android.h",
"video/capture/android/video_capture_device_factory_android.cc",
@@ -370,15 +338,6 @@ component("media") {
]
}
- if (use_alsa && use_udev) {
- libs += [ "asound" ]
- sources += [
- "midi/midi_manager_alsa.cc",
- "midi/midi_manager_alsa.h",
- ]
- deps += [ "//device/udev_linux" ]
- }
-
# A simple WebM encoder for animated avatars on ChromeOS.
if (use_ozone) {
@@ -402,7 +361,6 @@ component("media") {
"//third_party/decklink",
]
libs += [
- "CoreMIDI.framework",
"CoreVideo.framework",
"OpenGL.framework",
"QTKit.framework",
@@ -421,8 +379,6 @@ component("media") {
}
if (is_win) {
- deps += [ "//device/usb" ]
-
libs += [
"mf.lib",
"mfplat.lib",
@@ -575,13 +531,6 @@ test("media_unittests") {
"formats/webm/webm_parser_unittest.cc",
"formats/webm/webm_tracks_parser_unittest.cc",
"formats/webm/webm_webvtt_parser_unittest.cc",
- "midi/midi_manager_unittest.cc",
- "midi/midi_manager_usb_unittest.cc",
- "midi/midi_message_queue_unittest.cc",
- "midi/midi_message_util_unittest.cc",
- "midi/usb_midi_descriptor_parser_unittest.cc",
- "midi/usb_midi_input_stream_unittest.cc",
- "midi/usb_midi_output_stream_unittest.cc",
"renderers/audio_renderer_impl_unittest.cc",
"renderers/renderer_impl_unittest.cc",
"renderers/video_renderer_impl_unittest.cc",
@@ -669,18 +618,8 @@ test("media_unittests") {
}
if (is_mac) {
- sources += [
- "midi/midi_manager_mac_unittest.cc",
- "video/capture/mac/video_capture_device_factory_mac_unittest.mm",
- ]
- libs = [
- # Required by midi_manager_mac_unittest.cc.
- "CoreMIDI.framework",
- ]
- }
-
- if (use_alsa && use_udev) {
- sources += [ "midi/midi_manager_alsa_unittest.cc" ]
+ sources +=
+ [ "video/capture/mac/video_capture_device_factory_mac_unittest.mm" ]
}
# include_dirs += [
diff --git a/media/OWNERS b/media/OWNERS
index b7c2a18..fdb8c86 100644
--- a/media/OWNERS
+++ b/media/OWNERS
@@ -6,10 +6,5 @@ scherkus@chromium.org
wolenetz@chromium.org
xhwang@chromium.org
-# Build rules for Web MIDI
-per-file BUILD.gn=toyoshim@chromium.org
-per-file *.gyp=toyoshim@chromium.org
-per-file *.gypi=toyoshim@chromium.org
-
per-file *.isolate=csharp@chromium.org
per-file *.isolate=maruel@chromium.org
diff --git a/media/base/android/BUILD.gn b/media/base/android/BUILD.gn
index c407b17..9ab5265 100644
--- a/media/base/android/BUILD.gn
+++ b/media/base/android/BUILD.gn
@@ -87,8 +87,6 @@ generate_jni("media_jni_headers") {
"java/src/org/chromium/media/MediaDrmBridge.java",
"java/src/org/chromium/media/MediaPlayerBridge.java",
"java/src/org/chromium/media/MediaPlayerListener.java",
- "java/src/org/chromium/media/UsbMidiDeviceAndroid.java",
- "java/src/org/chromium/media/UsbMidiDeviceFactoryAndroid.java",
"java/src/org/chromium/media/WebAudioMediaCodecBridge.java",
]
jni_package = "media"
diff --git a/media/base/android/media_jni_registrar.cc b/media/base/android/media_jni_registrar.cc
index c9b8489..9ab40e4 100644
--- a/media/base/android/media_jni_registrar.cc
+++ b/media/base/android/media_jni_registrar.cc
@@ -15,8 +15,6 @@
#include "media/base/android/media_player_bridge.h"
#include "media/base/android/media_player_listener.h"
#include "media/base/android/webaudio_media_codec_bridge.h"
-#include "media/midi/usb_midi_device_android.h"
-#include "media/midi/usb_midi_device_factory_android.h"
#include "media/video/capture/android/video_capture_device_android.h"
#include "media/video/capture/android/video_capture_device_factory_android.h"
@@ -35,10 +33,6 @@ static base::android::RegistrationMethod kMediaRegisteredMethods[] = {
MediaPlayerBridge::RegisterMediaPlayerBridge },
{ "MediaPlayerListener",
MediaPlayerListener::RegisterMediaPlayerListener },
- { "UsbMidiDevice",
- UsbMidiDeviceAndroid::RegisterUsbMidiDevice },
- { "UsbMidiDeviceFactory",
- UsbMidiDeviceFactoryAndroid::RegisterUsbMidiDeviceFactory },
{ "VideoCaptureDevice",
VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice },
{ "VideoCaptureDeviceFactory",
diff --git a/media/media.gyp b/media/media.gyp
index c228c83..dac02a3 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -512,37 +512,6 @@
'formats/webm/webm_video_client.cc',
'formats/webm/webm_video_client.h',
'formats/webm/webm_webvtt_parser.cc',
- 'midi/midi_manager.cc',
- 'midi/midi_manager.h',
- 'midi/midi_manager_alsa.cc',
- 'midi/midi_manager_alsa.h',
- 'midi/midi_manager_android.cc',
- 'midi/midi_manager_mac.cc',
- 'midi/midi_manager_mac.h',
- 'midi/midi_manager_usb.cc',
- 'midi/midi_manager_usb.h',
- 'midi/midi_manager_win.cc',
- 'midi/midi_manager_win.h',
- 'midi/midi_message_queue.cc',
- 'midi/midi_message_queue.h',
- 'midi/midi_message_util.cc',
- 'midi/midi_message_util.h',
- 'midi/midi_port_info.cc',
- 'midi/midi_port_info.h',
- 'midi/midi_scheduler.cc',
- 'midi/midi_scheduler.h',
- 'midi/usb_midi_descriptor_parser.cc',
- 'midi/usb_midi_descriptor_parser.h',
- 'midi/usb_midi_device.h',
- 'midi/usb_midi_device_android.cc',
- 'midi/usb_midi_device_android.h',
- 'midi/usb_midi_device_factory_android.cc',
- 'midi/usb_midi_device_factory_android.h',
- 'midi/usb_midi_input_stream.cc',
- 'midi/usb_midi_input_stream.h',
- 'midi/usb_midi_jack.h',
- 'midi/usb_midi_output_stream.cc',
- 'midi/usb_midi_output_stream.h',
'ozone/media_ozone_platform.cc',
'ozone/media_ozone_platform.h',
'renderers/audio_renderer_impl.cc',
@@ -956,7 +925,6 @@
'$(SDKROOT)/System/Library/Frameworks/AudioToolbox.framework',
'$(SDKROOT)/System/Library/Frameworks/AudioUnit.framework',
'$(SDKROOT)/System/Library/Frameworks/CoreAudio.framework',
- '$(SDKROOT)/System/Library/Frameworks/CoreMIDI.framework',
'$(SDKROOT)/System/Library/Frameworks/CoreVideo.framework',
'$(SDKROOT)/System/Library/Frameworks/OpenGL.framework',
'$(SDKROOT)/System/Library/Frameworks/QTKit.framework',
@@ -964,9 +932,6 @@
},
}],
['OS=="win"', {
- 'dependencies': [
- '../device/usb/usb.gyp:device_usb',
- ],
'link_settings': {
'libraries': [
'-lmf.lib',
@@ -1093,16 +1058,6 @@
'filters/source_buffer_platform.h',
]
}],
- ['use_udev==1', {
- 'dependencies': [
- '../device/udev_linux/udev.gyp:udev_linux',
- ],
- }, { # use_udev==0
- 'sources!': [
- 'midi/midi_manager_alsa.cc',
- 'midi/midi_manager_alsa.h',
- ],
- }],
], # conditions
'target_conditions': [
['OS == "ios" and _toolset != "host"', {
@@ -1274,13 +1229,6 @@
'formats/webm/webm_parser_unittest.cc',
'formats/webm/webm_tracks_parser_unittest.cc',
'formats/webm/webm_webvtt_parser_unittest.cc',
- 'midi/midi_manager_unittest.cc',
- 'midi/midi_manager_usb_unittest.cc',
- 'midi/midi_message_queue_unittest.cc',
- 'midi/midi_message_util_unittest.cc',
- 'midi/usb_midi_descriptor_parser_unittest.cc',
- 'midi/usb_midi_input_stream_unittest.cc',
- 'midi/usb_midi_output_stream_unittest.cc',
'renderers/audio_renderer_impl_unittest.cc',
'renderers/renderer_impl_unittest.cc',
'renderers/video_renderer_impl_unittest.cc',
@@ -1413,15 +1361,9 @@
}],
['OS=="mac"', {
'sources': [
- 'midi/midi_manager_mac_unittest.cc',
'video/capture/mac/video_capture_device_factory_mac_unittest.mm',
]
}],
- ['use_alsa==1 and use_udev==1', {
- 'sources': [
- 'midi/midi_manager_alsa_unittest.cc',
- ]
- }],
['use_x11==1', {
'dependencies': [
'../tools/xdisplaycheck/xdisplaycheck.gyp:xdisplaycheck',
@@ -1705,8 +1647,6 @@
'base/android/java/src/org/chromium/media/MediaDrmBridge.java',
'base/android/java/src/org/chromium/media/MediaPlayerBridge.java',
'base/android/java/src/org/chromium/media/MediaPlayerListener.java',
- 'base/android/java/src/org/chromium/media/UsbMidiDeviceAndroid.java',
- 'base/android/java/src/org/chromium/media/UsbMidiDeviceFactoryAndroid.java',
'base/android/java/src/org/chromium/media/WebAudioMediaCodecBridge.java',
],
'variables': {
diff --git a/media/midi/BUILD.gn b/media/midi/BUILD.gn
new file mode 100644
index 0000000..0faa867
--- /dev/null
+++ b/media/midi/BUILD.gn
@@ -0,0 +1,172 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/android/config.gni")
+import("//build/config/features.gni")
+import("//build/config/ui.gni")
+import("//media/media_options.gni")
+import("//testing/test.gni")
+
+if (is_android) {
+ # For generate_jni().
+ import("//build/config/android/rules.gni")
+}
+
+# Common configuration for targets in the media/midi directory.
+config("midi_config") {
+ if (use_alsa) {
+ defines = [
+ "USE_ALSA",
+ "USE_UDEV",
+ ]
+ }
+
+ visibility = [ ":*" ]
+}
+
+# USB MIDI specific source files that are used in Android port, and unit tests.
+source_set("usb_midi") {
+ sources = [
+ "midi_manager_usb.cc",
+ "midi_manager_usb.h",
+ "usb_midi_descriptor_parser.cc",
+ "usb_midi_descriptor_parser.h",
+ "usb_midi_device.h",
+ "usb_midi_input_stream.cc",
+ "usb_midi_input_stream.h",
+ "usb_midi_jack.h",
+ "usb_midi_output_stream.cc",
+ "usb_midi_output_stream.h",
+ ]
+
+ defines = [ "MEDIA_IMPLEMENTATION" ]
+ deps = [
+ "//base",
+ ]
+}
+
+# Android specific Java source files that are used to generate jni header files.
+if (is_android) {
+ android_library("midi_java") {
+ deps = [
+ "//base:base_java",
+ ]
+
+ DEPRECATED_java_in_dir = "java/src"
+ }
+
+ generate_jni("midi_jni_headers") {
+ sources = [
+ "java/src/org/chromium/media/midi/UsbMidiDeviceAndroid.java",
+ "java/src/org/chromium/media/midi/UsbMidiDeviceFactoryAndroid.java",
+ ]
+ jni_package = "media/midi"
+ }
+}
+
+component("midi") {
+ sources = [
+ "midi_manager.cc",
+ "midi_manager.h",
+ "midi_manager_mac.cc",
+ "midi_manager_mac.h",
+ "midi_manager_win.cc",
+ "midi_manager_win.h",
+ "midi_message_queue.cc",
+ "midi_message_queue.h",
+ "midi_message_util.cc",
+ "midi_message_util.h",
+ "midi_port_info.cc",
+ "midi_port_info.h",
+ "midi_scheduler.cc",
+ "midi_scheduler.h",
+ ]
+
+ configs += [ ":midi_config" ]
+
+ defines = [ "MEDIA_IMPLEMENTATION" ]
+ deps = []
+ libs = []
+
+ if (is_android) {
+ sources += [
+ "midi_jni_registrar.cc",
+ "midi_jni_registrar.h",
+ "midi_manager_android.cc",
+ "usb_midi_device_android.cc",
+ "usb_midi_device_android.h",
+ "usb_midi_device_factory_android.cc",
+ "usb_midi_device_factory_android.h",
+ ]
+
+ deps += [
+ "//base:i18n",
+ ":midi_jni_headers",
+ ":usb_midi",
+ ]
+ }
+
+ if (is_mac) {
+ libs += [
+ "CoreAudio.framework",
+ "CoreMIDI.framework",
+ ]
+ }
+
+ if (is_win) {
+ deps += [ "//device/usb" ]
+ }
+
+ if (use_alsa && use_udev) {
+ deps += [
+ "//crypto",
+ "//crypto:platform",
+ ]
+ libs += [ "asound" ]
+ sources += [
+ "midi_manager_alsa.cc",
+ "midi_manager_alsa.h",
+ ]
+ }
+
+ if (use_udev) {
+ deps += [ "//device/udev_linux" ]
+ }
+}
+
+test("midi_unittests") {
+ sources = [
+ "midi_manager_unittest.cc",
+ "midi_manager_usb_unittest.cc",
+ "midi_message_queue_unittest.cc",
+ "midi_message_util_unittest.cc",
+ "usb_midi_descriptor_parser_unittest.cc",
+ "usb_midi_input_stream_unittest.cc",
+ "usb_midi_output_stream_unittest.cc",
+ ]
+
+ configs += [ ":midi_config" ]
+ deps = [
+ ":midi",
+ "//base/test/:run_all_unittests",
+ "//base/test/:test_support",
+ "//testing/gtest",
+ ]
+
+ if (!is_android) {
+ deps += [ ":usb_midi" ]
+ }
+
+ if (is_mac) {
+ sources += [ "midi_manager_mac_unittest.cc" ]
+ }
+
+ if (use_alsa && use_udev) {
+ sources += [ "midi_manager_alsa_unittest.cc" ]
+ }
+
+ if (use_x11) {
+ deps += [ "//tools/xdisplaycheck" ]
+ }
+}
diff --git a/media/base/android/java/src/org/chromium/media/UsbMidiDeviceAndroid.java b/media/midi/java/src/org/chromium/media/midi/UsbMidiDeviceAndroid.java
index c581131..4bdd5f5 100644
--- a/media/base/android/java/src/org/chromium/media/UsbMidiDeviceAndroid.java
+++ b/media/midi/java/src/org/chromium/media/midi/UsbMidiDeviceAndroid.java
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package org.chromium.media;
+package org.chromium.media.midi;
import android.annotation.TargetApi;
import android.hardware.usb.UsbConstants;
@@ -28,7 +28,7 @@ import java.util.Map;
* Owned by its native counterpart declared in usb_midi_device_android.h.
* Refer to that class for general comments.
*/
-@JNINamespace("media")
+@JNINamespace("media::midi")
class UsbMidiDeviceAndroid {
/**
* A connection handle for this device.
@@ -184,14 +184,14 @@ class UsbMidiDeviceAndroid {
*/
private void postOnDataEvent(final int endpointNumber, final byte[] bs) {
mHandler.post(new Runnable() {
- @Override
- public void run() {
- if (mIsClosed) {
- return;
- }
- nativeOnData(mNativePointer, endpointNumber, bs);
+ @Override
+ public void run() {
+ if (mIsClosed) {
+ return;
}
- });
+ nativeOnData(mNativePointer, endpointNumber, bs);
+ }
+ });
}
UsbDevice getUsbDevice() {
@@ -321,7 +321,6 @@ class UsbMidiDeviceAndroid {
return position;
}
- private static native void nativeOnData(long nativeUsbMidiDeviceAndroid,
- int endpointNumber,
- byte[] data);
+ private static native void nativeOnData(
+ long nativeUsbMidiDeviceAndroid, int endpointNumber, byte[] data);
}
diff --git a/media/base/android/java/src/org/chromium/media/UsbMidiDeviceFactoryAndroid.java b/media/midi/java/src/org/chromium/media/midi/UsbMidiDeviceFactoryAndroid.java
index 814bb17..e003332 100644
--- a/media/base/android/java/src/org/chromium/media/UsbMidiDeviceFactoryAndroid.java
+++ b/media/midi/java/src/org/chromium/media/midi/UsbMidiDeviceFactoryAndroid.java
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package org.chromium.media;
+package org.chromium.media.midi;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
@@ -28,7 +28,7 @@ import java.util.Set;
* Owned by its native counterpart declared in
* usb_midi_device_factory_android.h. Refer to that class for general comments.
*/
-@JNINamespace("media")
+@JNINamespace("media::midi")
class UsbMidiDeviceFactoryAndroid {
/**
* The UsbManager of this system.
@@ -60,8 +60,7 @@ class UsbMidiDeviceFactoryAndroid {
*/
private long mNativePointer;
- private static final String ACTION_USB_PERMISSION =
- "org.chromium.media.USB_PERMISSION";
+ private static final String ACTION_USB_PERMISSION = "org.chromium.media.USB_PERMISSION";
/**
* Constructs a UsbMidiDeviceAndroid.
@@ -125,7 +124,7 @@ class UsbMidiDeviceFactoryAndroid {
mIsEnumeratingDevices = false;
return false;
}
- for (UsbDevice device: devices.values()) {
+ for (UsbDevice device : devices.values()) {
requestDevicePermissionIfNecessary(context, device);
}
return true;
@@ -138,7 +137,7 @@ class UsbMidiDeviceFactoryAndroid {
* @param device a USB device
*/
private void requestDevicePermissionIfNecessary(Context context, UsbDevice device) {
- for (UsbDevice d: mRequestedDevices) {
+ for (UsbDevice d : mRequestedDevices) {
if (d.getDeviceId() == device.getDeviceId()) {
// It is already requested.
return;
@@ -150,8 +149,9 @@ class UsbMidiDeviceFactoryAndroid {
if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_AUDIO
&& iface.getInterfaceSubclass() == UsbMidiDeviceAndroid.MIDI_SUBCLASS) {
// There is at least one interface supporting MIDI.
- mUsbManager.requestPermission(device, PendingIntent.getBroadcast(
- context, 0, new Intent(ACTION_USB_PERMISSION), 0));
+ mUsbManager.requestPermission(
+ device, PendingIntent.getBroadcast(
+ context, 0, new Intent(ACTION_USB_PERMISSION), 0));
mRequestedDevices.add(device);
break;
}
@@ -164,7 +164,7 @@ class UsbMidiDeviceFactoryAndroid {
* @param device a USB device
*/
private void onUsbDeviceDetached(UsbDevice device) {
- for (UsbDevice usbDevice: mRequestedDevices) {
+ for (UsbDevice usbDevice : mRequestedDevices) {
if (usbDevice.getDeviceId() == device.getDeviceId()) {
mRequestedDevices.remove(usbDevice);
break;
@@ -214,7 +214,7 @@ class UsbMidiDeviceFactoryAndroid {
}
if (device != null) {
- for (UsbMidiDeviceAndroid registered: mDevices) {
+ for (UsbMidiDeviceAndroid registered : mDevices) {
if (!registered.isClosed()
&& registered.getUsbDevice().getDeviceId() == device.getDeviceId()) {
// The device is already registered.
diff --git a/media/midi/midi.gyp b/media/midi/midi.gyp
new file mode 100644
index 0000000..554f1a9
--- /dev/null
+++ b/media/midi/midi.gyp
@@ -0,0 +1,235 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'variables': {
+ 'chromium_code': 1,
+ 'conditions': [
+ ['(OS=="linux" or OS=="freebsd" or OS=="solaris") and (embedded!=1 or (chromecast==1 and target_arch!="arm"))', {
+ 'use_alsa%': 1,
+ }, {
+ 'use_alsa%': 0,
+ }],
+ ],
+ # Source files that are used in production code for Android, and in tests
+ # for others.
+ 'usb_midi_sources': [
+ 'midi_manager_usb.cc',
+ 'midi_manager_usb.h',
+ 'usb_midi_descriptor_parser.cc',
+ 'usb_midi_descriptor_parser.h',
+ 'usb_midi_device.h',
+ 'usb_midi_input_stream.cc',
+ 'usb_midi_input_stream.h',
+ 'usb_midi_jack.h',
+ 'usb_midi_output_stream.cc',
+ 'usb_midi_output_stream.h',
+ ],
+ },
+ 'targets': [
+ {
+ # GN version: //media/midi
+ 'target_name': 'midi',
+ 'type': '<(component)',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ ],
+ 'defines': [
+ 'MEDIA_IMPLEMENTATION',
+ ],
+ 'include_dirs': [
+ '../..',
+ ],
+ 'sources': [
+ 'midi_manager.cc',
+ 'midi_manager.h',
+ 'midi_manager_android.cc',
+ 'midi_manager_mac.cc',
+ 'midi_manager_mac.h',
+ 'midi_manager_win.cc',
+ 'midi_manager_win.h',
+ 'midi_message_queue.cc',
+ 'midi_message_queue.h',
+ 'midi_message_util.cc',
+ 'midi_message_util.h',
+ 'midi_port_info.cc',
+ 'midi_port_info.h',
+ 'midi_scheduler.cc',
+ 'midi_scheduler.h',
+ 'usb_midi_device_android.cc',
+ 'usb_midi_device_android.h',
+ 'usb_midi_device_factory_android.cc',
+ 'usb_midi_device_factory_android.h',
+ ],
+ 'direct_dependent_settings': {
+ 'include_dirs': [
+ '../..',
+ ],
+ },
+ 'conditions': [
+ ['use_alsa==1 and use_udev==1', {
+ 'dependencies': [
+ '../../crypto/crypto.gyp:crypto',
+ '../../device/udev_linux/udev.gyp:udev_linux',
+ ],
+ 'defines': [
+ 'USE_ALSA',
+ 'USE_UDEV',
+ ],
+ 'sources': [
+ 'midi_manager_alsa.cc',
+ 'midi_manager_alsa.h',
+ ],
+ 'link_settings': {
+ 'libraries': [
+ '-lasound',
+ ],
+ },
+ }],
+ ['OS=="android"', {
+ 'dependencies': [
+ '../../base/base.gyp:base_i18n',
+ 'midi_jni_headers',
+ 'midi_java',
+ ],
+ 'sources': [
+ '<@(usb_midi_sources)',
+ 'midi_jni_registrar.cc',
+ 'midi_jni_registrar.h',
+ ],
+ }],
+ ['OS=="mac"', {
+ 'link_settings': {
+ 'libraries': [
+ '$(SDKROOT)/System/Library/Frameworks/CoreAudio.framework',
+ '$(SDKROOT)/System/Library/Frameworks/CoreMIDI.framework',
+ ],
+ },
+ }],
+ ['OS=="win"', {
+ 'dependencies': [
+ '../../device/usb/usb.gyp:device_usb',
+ ],
+ }],
+ ], # conditions
+ },
+ {
+ # GN version: //media/midi:midi_unittests
+ 'target_name': 'midi_unittests',
+ 'type': '<(gtest_target_type)',
+ 'dependencies': [
+ 'midi',
+ '../../base/base.gyp:base',
+ '../../base/base.gyp:run_all_unittests',
+ '../../testing/gtest.gyp:gtest',
+ ],
+ 'defines': [
+ 'MEDIA_IMPLEMENTATION',
+ ],
+ 'include_dirs': [
+ '../..',
+ ],
+ 'sources': [
+ 'midi_manager_unittest.cc',
+ 'midi_manager_usb_unittest.cc',
+ 'midi_message_queue_unittest.cc',
+ 'midi_message_util_unittest.cc',
+ 'usb_midi_descriptor_parser_unittest.cc',
+ 'usb_midi_input_stream_unittest.cc',
+ 'usb_midi_output_stream_unittest.cc',
+ ],
+ 'conditions': [
+ ['use_alsa==1 and use_udev==1', {
+ 'defines': [
+ 'USE_ALSA',
+ 'USE_UDEV',
+ ],
+ 'sources': [
+ 'midi_manager_alsa_unittest.cc',
+ ],
+ }],
+ ['use_x11==1', {
+ 'dependencies': [
+ '../../tools/xdisplaycheck/xdisplaycheck.gyp:xdisplaycheck',
+ ],
+ }],
+ ['OS=="android"', {
+ 'dependencies': [
+ '../../testing/android/native_test.gyp:native_test_native_code',
+ ],
+ }, {
+ 'sources': [
+ '<@(usb_midi_sources)',
+ ],
+ }],
+ ['OS=="mac"', {
+ 'sources': [
+ 'midi_manager_mac_unittest.cc',
+ ],
+ }],
+ ],
+ },
+ ],
+ 'conditions': [
+ ['OS=="android"', {
+ 'targets': [
+ {
+ # TODO(GN)
+ 'target_name': 'midi_unittests_apk',
+ 'type': 'none',
+ 'dependencies': [
+ 'midi_java',
+ 'midi_unittests',
+ ],
+ 'variables': {
+ 'test_suite_name': 'midi_unittests',
+ },
+ 'includes': ['../../build/apk_test.gypi'],
+ },
+ {
+ # GN: //media/midi:midi_java
+ 'target_name': 'midi_java',
+ 'type': 'none',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ ],
+ 'variables': {
+ 'java_in_dir': 'java',
+ },
+ 'includes': ['../../build/java.gypi' ],
+ },
+ {
+ # GN: //media/midi:midi_jni_headers
+ 'target_name': 'midi_jni_headers',
+ 'type': 'none',
+ 'sources': [
+ 'java/src/org/chromium/media/midi/UsbMidiDeviceAndroid.java',
+ 'java/src/org/chromium/media/midi/UsbMidiDeviceFactoryAndroid.java',
+ ],
+ 'variables': {
+ 'jni_gen_package': 'media/midi',
+ },
+ 'includes': ['../../build/jni_generator.gypi'],
+ },
+ ],
+ }],
+ ['test_isolation_mode != "noop"', {
+ 'targets': [
+ {
+ 'target_name': 'midi_unittests_run',
+ 'type': 'none',
+ 'dependencies': [
+ 'midi_unittests',
+ ],
+ 'includes': [
+ '../../build/isolate.gypi',
+ ],
+ 'sources': [
+ 'midi_unittests.isolate',
+ ],
+ },
+ ],
+ }],
+ ],
+}
diff --git a/media/midi/midi_jni_registrar.cc b/media/midi/midi_jni_registrar.cc
new file mode 100644
index 0000000..a0028cd
--- /dev/null
+++ b/media/midi/midi_jni_registrar.cc
@@ -0,0 +1,29 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/midi/midi_jni_registrar.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_registrar.h"
+#include "base/basictypes.h"
+
+#include "media/midi/usb_midi_device_android.h"
+#include "media/midi/usb_midi_device_factory_android.h"
+
+namespace media {
+namespace midi {
+
+static base::android::RegistrationMethod kMediaRegisteredMethods[] = {
+ {"UsbMidiDevice", UsbMidiDeviceAndroid::RegisterUsbMidiDevice},
+ {"UsbMidiDeviceFactory",
+ UsbMidiDeviceFactoryAndroid::RegisterUsbMidiDeviceFactory},
+};
+
+bool RegisterJni(JNIEnv* env) {
+ return base::android::RegisterNativeMethods(
+ env, kMediaRegisteredMethods, arraysize(kMediaRegisteredMethods));
+}
+
+} // namespace midi
+} // namespace media
diff --git a/media/midi/midi_jni_registrar.h b/media/midi/midi_jni_registrar.h
new file mode 100644
index 0000000..f981e5c
--- /dev/null
+++ b/media/midi/midi_jni_registrar.h
@@ -0,0 +1,21 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_MIDI_MIDI_JNI_REGISTRAR_H_
+#define MEDIA_MIDI_MIDI_JNI_REGISTRAR_H_
+
+#include <jni.h>
+
+#include "media/base/media_export.h"
+
+namespace media {
+namespace midi {
+
+// Register all JNI bindings necessary for media/midi.
+MEDIA_EXPORT bool RegisterJni(JNIEnv* env);
+
+} // namespace midi
+} // namespace media
+
+#endif // MEDIA_MIDI_MIDI_JNI_REGISTRAR_H_
diff --git a/media/midi/midi_manager_usb.cc b/media/midi/midi_manager_usb.cc
index 346098c..4548a89 100644
--- a/media/midi/midi_manager_usb.cc
+++ b/media/midi/midi_manager_usb.cc
@@ -74,7 +74,7 @@ void MidiManagerUsb::ReceiveUsbMidiData(UsbMidiDevice* device,
}
void MidiManagerUsb::OnDeviceAttached(scoped_ptr<UsbMidiDevice> device) {
- int device_id = devices_.size();
+ int device_id = static_cast<int>(devices_.size());
devices_.push_back(device.release());
AddPorts(devices_.back(), device_id);
}
@@ -86,13 +86,13 @@ void MidiManagerUsb::OnDeviceDetached(size_t index) {
UsbMidiDevice* device = devices_[index];
for (size_t i = 0; i < output_streams_.size(); ++i) {
if (output_streams_[i]->jack().device == device) {
- SetOutputPortState(i, MIDI_PORT_DISCONNECTED);
+ SetOutputPortState(static_cast<uint32>(i), MIDI_PORT_DISCONNECTED);
}
}
const std::vector<UsbMidiJack>& input_jacks = input_stream_->jacks();
for (size_t i = 0; i < input_jacks.size(); ++i) {
if (input_jacks[i].device == device) {
- SetInputPortState(i, MIDI_PORT_DISCONNECTED);
+ SetInputPortState(static_cast<uint32>(i), MIDI_PORT_DISCONNECTED);
}
}
}
@@ -101,7 +101,7 @@ void MidiManagerUsb::OnReceivedData(size_t jack_index,
const uint8* data,
size_t size,
base::TimeTicks time) {
- ReceiveMidiData(jack_index, data, size, time);
+ ReceiveMidiData(static_cast<uint32>(jack_index), data, size, time);
}
@@ -114,7 +114,7 @@ void MidiManagerUsb::OnEnumerateDevicesDone(bool result,
input_stream_.reset(new UsbMidiInputStream(this));
devices->swap(devices_);
for (size_t i = 0; i < devices_.size(); ++i) {
- if (!AddPorts(devices_[i], i)) {
+ if (!AddPorts(devices_[i], static_cast<int>(i))) {
initialize_callback_.Run(MIDI_INITIALIZATION_ERROR);
return;
}
diff --git a/media/midi/midi_manager_win.cc b/media/midi/midi_manager_win.cc
index 5937278..eb729ea 100644
--- a/media/midi/midi_manager_win.cc
+++ b/media/midi/midi_manager_win.cc
@@ -101,7 +101,7 @@ ScopedMIDIHDR CreateMIDIHDR(size_t size) {
ScopedMIDIHDR header(new MIDIHDR);
ZeroMemory(header.get(), sizeof(*header));
header->lpData = new char[size];
- header->dwBufferLength = size;
+ header->dwBufferLength = static_cast<DWORD>(size);
return header.Pass();
}
@@ -619,7 +619,7 @@ class MidiServiceWinImpl : public MidiServiceWin,
base::AutoLock auto_lock(input_ports_lock_);
const auto it = unused_input_ports_.find(state_device_info);
if (it == unused_input_ports_.end()) {
- port_number = input_ports_.size();
+ port_number = static_cast<uint32>(input_ports_.size());
add_new_port = true;
input_ports_.push_back(nullptr);
input_ports_ages_.push_back(0);
@@ -800,7 +800,7 @@ class MidiServiceWinImpl : public MidiServiceWin,
base::AutoLock auto_lock(output_ports_lock_);
const auto it = unused_output_ports_.find(state_device_info);
if (it == unused_output_ports_.end()) {
- port_number = output_ports_.size();
+ port_number = static_cast<uint32>(output_ports_.size());
add_new_port = true;
output_ports_.push_back(nullptr);
output_ports_ages_.push_back(0);
diff --git a/media/midi/midi_scheduler.h b/media/midi/midi_scheduler.h
index 73c8bc6..452328b 100644
--- a/media/midi/midi_scheduler.h
+++ b/media/midi/midi_scheduler.h
@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
+#include "media/base/media_export.h"
namespace media {
@@ -14,7 +15,7 @@ class MidiManager;
class MidiManagerClient;
// TODO(crbug.com/467442): Make tasks cancelable per client.
-class MidiScheduler final {
+class MEDIA_EXPORT MidiScheduler final {
public:
explicit MidiScheduler(MidiManager* manager);
~MidiScheduler();
diff --git a/media/midi/midi_unittests.isolate b/media/midi/midi_unittests.isolate
new file mode 100644
index 0000000..dca0d35
--- /dev/null
+++ b/media/midi/midi_unittests.isolate
@@ -0,0 +1,63 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+{
+ 'includes': [
+ '../../base/base.isolate',
+ ],
+ 'conditions': [
+ ['use_x11==0', {
+ 'variables': {
+ 'command': [
+ '../../testing/test_env.py',
+ '<(PRODUCT_DIR)/midi_unittests<(EXECUTABLE_SUFFIX)',
+ '--brave-new-test-launcher',
+ '--test-launcher-bot-mode',
+ '--asan=<(asan)',
+ '--msan=<(msan)',
+ '--tsan=<(tsan)',
+ ],
+ },
+ }],
+ ['use_x11==1', {
+ 'variables': {
+ 'command': [
+ '../../testing/xvfb.py',
+ '<(PRODUCT_DIR)',
+ '<(PRODUCT_DIR)/midi_unittests',
+ '--brave-new-test-launcher',
+ '--test-launcher-bot-mode',
+ '--asan=<(asan)',
+ '--msan=<(msan)',
+ '--tsan=<(tsan)',
+ ],
+ 'files': [
+ '../../testing/xvfb.py',
+ '<(PRODUCT_DIR)/xdisplaycheck',
+ ],
+ },
+ }],
+ ['OS=="linux" or OS=="mac" or OS=="win"', {
+ 'variables': {
+ 'files': [
+ '../../testing/test_env.py',
+ '<(PRODUCT_DIR)/midi_unittests<(EXECUTABLE_SUFFIX)',
+ ],
+ },
+ }],
+ ['OS=="mac" and asan==1 and fastbuild==0', {
+ 'variables': {
+ 'files': [
+ '<(PRODUCT_DIR)/midi_unittests.dSYM/',
+ ],
+ },
+ }],
+ ['OS=="win" and (fastbuild==0 or fastbuild==1)', {
+ 'variables': {
+ 'files': [
+ '<(PRODUCT_DIR)/midi_unittests.exe.pdb',
+ ],
+ },
+ }],
+ ],
+}
diff --git a/media/midi/usb_midi_device_android.cc b/media/midi/usb_midi_device_android.cc
index f62eb86..640ef22 100644
--- a/media/midi/usb_midi_device_android.cc
+++ b/media/midi/usb_midi_device_android.cc
@@ -20,8 +20,8 @@ UsbMidiDeviceAndroid::UsbMidiDeviceAndroid(ObjectRef raw_device,
UsbMidiDeviceDelegate* delegate)
: raw_device_(raw_device), delegate_(delegate) {
JNIEnv* env = base::android::AttachCurrentThread();
- Java_UsbMidiDeviceAndroid_registerSelf(
- env, raw_device_.obj(), reinterpret_cast<jlong>(this));
+ midi::Java_UsbMidiDeviceAndroid_registerSelf(env, raw_device_.obj(),
+ reinterpret_cast<jlong>(this));
GetDescriptorsInternal();
InitDeviceInfo();
@@ -29,7 +29,7 @@ UsbMidiDeviceAndroid::UsbMidiDeviceAndroid(ObjectRef raw_device,
UsbMidiDeviceAndroid::~UsbMidiDeviceAndroid() {
JNIEnv* env = base::android::AttachCurrentThread();
- Java_UsbMidiDeviceAndroid_close(env, raw_device_.obj());
+ midi::Java_UsbMidiDeviceAndroid_close(env, raw_device_.obj());
}
std::vector<uint8> UsbMidiDeviceAndroid::GetDescriptors() {
@@ -55,8 +55,8 @@ void UsbMidiDeviceAndroid::Send(int endpoint_number,
ScopedJavaLocalRef<jbyteArray> data_to_pass =
base::android::ToJavaByteArray(env, head, data.size());
- Java_UsbMidiDeviceAndroid_send(
- env, raw_device_.obj(), endpoint_number, data_to_pass.obj());
+ midi::Java_UsbMidiDeviceAndroid_send(env, raw_device_.obj(), endpoint_number,
+ data_to_pass.obj());
}
void UsbMidiDeviceAndroid::OnData(JNIEnv* env,
@@ -72,13 +72,13 @@ void UsbMidiDeviceAndroid::OnData(JNIEnv* env,
}
bool UsbMidiDeviceAndroid::RegisterUsbMidiDevice(JNIEnv* env) {
- return RegisterNativesImpl(env);
+ return midi::RegisterNativesImpl(env);
}
void UsbMidiDeviceAndroid::GetDescriptorsInternal() {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jbyteArray> descriptors =
- Java_UsbMidiDeviceAndroid_getDescriptors(env, raw_device_.obj());
+ midi::Java_UsbMidiDeviceAndroid_getDescriptors(env, raw_device_.obj());
base::android::JavaByteArrayToByteVector(env, descriptors.obj(),
&descriptors_);
@@ -111,8 +111,8 @@ void UsbMidiDeviceAndroid::InitDeviceInfo() {
std::vector<uint8> UsbMidiDeviceAndroid::GetStringDescriptor(int index) {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jbyteArray> descriptors =
- Java_UsbMidiDeviceAndroid_getStringDescriptor(env, raw_device_.obj(),
- index);
+ midi::Java_UsbMidiDeviceAndroid_getStringDescriptor(
+ env, raw_device_.obj(), index);
std::vector<uint8> ret;
base::android::JavaByteArrayToByteVector(env, descriptors.obj(), &ret);
diff --git a/media/midi/usb_midi_device_factory_android.cc b/media/midi/usb_midi_device_factory_android.cc
index 6302572..f066428 100644
--- a/media/midi/usb_midi_device_factory_android.cc
+++ b/media/midi/usb_midi_device_factory_android.cc
@@ -30,7 +30,7 @@ UsbMidiDeviceFactoryAndroid::UsbMidiDeviceFactoryAndroid() : delegate_(NULL) {}
UsbMidiDeviceFactoryAndroid::~UsbMidiDeviceFactoryAndroid() {
JNIEnv* env = base::android::AttachCurrentThread();
if (!raw_factory_.is_null())
- Java_UsbMidiDeviceFactoryAndroid_close(
+ midi::Java_UsbMidiDeviceFactoryAndroid_close(
env, raw_factory_.obj(), base::android::GetApplicationContext());
}
@@ -40,13 +40,13 @@ void UsbMidiDeviceFactoryAndroid::EnumerateDevices(
DCHECK(!delegate_);
JNIEnv* env = base::android::AttachCurrentThread();
uintptr_t pointer = reinterpret_cast<uintptr_t>(this);
- raw_factory_.Reset(Java_UsbMidiDeviceFactoryAndroid_create(
+ raw_factory_.Reset(midi::Java_UsbMidiDeviceFactoryAndroid_create(
env, base::android::GetApplicationContext(), pointer));
delegate_ = delegate;
callback_ = callback;
- if (Java_UsbMidiDeviceFactoryAndroid_enumerateDevices(
+ if (midi::Java_UsbMidiDeviceFactoryAndroid_enumerateDevices(
env, raw_factory_.obj(), base::android::GetApplicationContext())) {
// Asynchronous operation.
return;
@@ -92,7 +92,7 @@ void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceDetached(
}
bool UsbMidiDeviceFactoryAndroid::RegisterUsbMidiDeviceFactory(JNIEnv* env) {
- return RegisterNativesImpl(env);
+ return midi::RegisterNativesImpl(env);
}
} // namespace media
diff --git a/media/midi/usb_midi_output_stream.cc b/media/midi/usb_midi_output_stream.cc
index 2f32897..8f1af70 100644
--- a/media/midi/usb_midi_output_stream.cc
+++ b/media/midi/usb_midi_output_stream.cc
@@ -98,7 +98,7 @@ bool UsbMidiOutputStream::PushSysExMessage(const std::vector<uint8>& data,
message[message_size] = byte;
++message_size;
if (byte == kEndOfSysExByte) {
- uint8 code_index = message_size + 0x4;
+ uint8 code_index = static_cast<uint8>(message_size) + 0x4;
DCHECK(code_index == 0x5 || code_index == 0x6 || code_index == 0x7);
data_to_send->push_back((jack_.cable_number << 4) | code_index);
data_to_send->insert(data_to_send->end(),