summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
Diffstat (limited to 'media/java')
-rw-r--r--media/java/android/media/MediaCodecInfo.java15
-rw-r--r--media/java/android/media/midi/MidiDevice.java12
-rw-r--r--media/java/android/media/midi/package.html63
3 files changed, 82 insertions, 8 deletions
diff --git a/media/java/android/media/MediaCodecInfo.java b/media/java/android/media/MediaCodecInfo.java
index 65d0450..8243d40 100644
--- a/media/java/android/media/MediaCodecInfo.java
+++ b/media/java/android/media/MediaCodecInfo.java
@@ -1198,15 +1198,20 @@ public final class MediaCodecInfo {
(double) mFrameRateRange.getUpper()));
}
+ private int getBlockCount(int width, int height) {
+ return Utils.divUp(width, mBlockWidth) * Utils.divUp(height, mBlockHeight);
+ }
+
@NonNull
private Size findClosestSize(int width, int height) {
- int targetPixels = width * height;
+ int targetBlockCount = getBlockCount(width, height);
Size closestSize = null;
- int mimPixelsDiff = Integer.MAX_VALUE;
+ int minDiff = Integer.MAX_VALUE;
for (Size size : mMeasuredFrameRates.keySet()) {
- int pixelsDiff = Math.abs(targetPixels - size.getWidth() * size.getHeight());
- if (pixelsDiff < mimPixelsDiff) {
- mimPixelsDiff = pixelsDiff;
+ int diff = Math.abs(targetBlockCount -
+ getBlockCount(size.getWidth(), size.getHeight()));
+ if (diff < minDiff) {
+ minDiff = diff;
closestSize = size;
}
}
diff --git a/media/java/android/media/midi/MidiDevice.java b/media/java/android/media/midi/MidiDevice.java
index 93fb6d2..e1990cd 100644
--- a/media/java/android/media/midi/MidiDevice.java
+++ b/media/java/android/media/midi/MidiDevice.java
@@ -113,8 +113,13 @@ public final class MidiDevice implements Closeable {
/**
* Called to open a {@link MidiInputPort} for the specified port number.
*
+ * An input port can only be used by one sender at a time.
+ * Opening an input port will fail if another application has already opened it for use.
+ * A {@link MidiDeviceStatus} can be used to determine if an input port is already open.
+ *
* @param portNumber the number of the input port to open
- * @return the {@link MidiInputPort}
+ * @return the {@link MidiInputPort} if the open is successful,
+ * or null in case of failure.
*/
public MidiInputPort openInputPort(int portNumber) {
try {
@@ -133,8 +138,11 @@ public final class MidiDevice implements Closeable {
/**
* Called to open a {@link MidiOutputPort} for the specified port number.
*
+ * An output port may be opened by multiple applications.
+ *
* @param portNumber the number of the output port to open
- * @return the {@link MidiOutputPort}
+ * @return the {@link MidiOutputPort} if the open is successful,
+ * or null in case of failure.
*/
public MidiOutputPort openOutputPort(int portNumber) {
try {
diff --git a/media/java/android/media/midi/package.html b/media/java/android/media/midi/package.html
index 673c4ba..7baa5bc 100644
--- a/media/java/android/media/midi/package.html
+++ b/media/java/android/media/midi/package.html
@@ -31,7 +31,7 @@ capabilities, etc.</li>
<li> Timestamps to avoid jitter.</li>
<li> Support creation of <em>virtual MIDI devices</em> that can be connected to other devices.
An example might be a synthesizer app that can be controlled by a composing app.</li>
- <li> Support direction connection or &ldquo;patching&rdquo; of devices for lower latency.</li>
+ <li> Support direct connection or &ldquo;patching&rdquo; of devices for lower latency.</li>
</ul>
<h2 id=transports_supported>Transports Supported</h2>
@@ -75,6 +75,18 @@ Then the app will not appear in the Play Store for old devices that do not suppo
&lt;uses-feature android:name="android.software.midi" android:required="true"/>
</pre>
+<h2 id=check_feature>Check for Feature Support</h2>
+
+<p>An app can also check at run-time whether the MIDI feature is supported on a platform.
+This is particularly useful during development when you install apps directly on a device.
+</p>
+
+<pre class=prettyprint>
+if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
+ // do MIDI stuff
+}
+</pre>
+
<h2 id=the_midimanager>The MidiManager</h2>
@@ -338,5 +350,54 @@ public class MidiSynthDeviceService extends MidiDeviceService {
}
}
</pre>
+
+<h1 id=using_midi_btle>Using MIDI Over Bluetooth LE</h1>
+
+<p>MIDI devices can be connected to Android using Bluetooth LE.</p>
+
+<p>Before using the device, the app must scan for available BTLE devices and then allow
+the user to connect. An example program
+will be provided so look for it on the Android developer website.</p>
+
+<h2 id=btle_location_permissions>Request Location Permission for BTLE</h2>
+
+<p>Applications that scan for Bluetooth devices must request permission in the
+manifest file. This LOCATION permission is required because it may be possible to
+guess the location of an Android device by seeing which BTLE devices are nearby.</p>
+
+<pre class=prettyprint>
+&lt;uses-permission android:name="android.permission.BLUETOOTH"/>
+&lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+&lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+</pre>
+
+<p>Apps must also request location permission from the user at run-time.
+See the documentation for <code>Activity.requestPermissions()</code> for details and an example.
+</p>
+
+<h2 id=btle_scan_devices>Scan for MIDI Devices</h2>
+
+<p>The app will only want to see MIDI devices and not mice or other non-MIDI devices.
+So construct a ScanFilter using the UUID for standard MIDI over BTLE.</p>
+
+<pre class=prettyprint>
+MIDI over BTLE UUID = "03B80E5A-EDE8-4B33-A751-6CE34EC4C700"
+</pre>
+
+<h2 id=btle_open_device>Open a MIDI Bluetooth Device</h2>
+
+<p>See the documentation for <code>android.bluetooth.le.BluetoothLeScanner.startScan()</code>
+method for details. When the user selects a MIDI/BTLE device then you can open it
+using the MidiManager.</p>
+
+<pre class=prettyprint>
+m.openBluetoothDevice(bluetoothDevice, callback, handler);
+</pre>
+
+<p>Once the MIDI/BTLE device has been opened by one app then it will also become available to other
+apps using the
+<a href="#get_list_of_already_plugged_in_entities">MIDI device discovery calls described above</a>.
+</p>
+
</body>
</html>