diff --git a/api/system-current.txt b/api/system-current.txt index c909b285277c9..98c6fcad17d76 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4424,11 +4424,11 @@ package android.media { } public class MediaPlayer implements android.media.AudioRouting android.media.VolumeAutomation { - method @RequiresPermission("android.permission.BIND_IMS_SERVICE") public void setOnImsRxNoticeListener(@Nullable android.media.MediaPlayer.OnImsRxNoticeListener, @Nullable android.os.Handler); + method @RequiresPermission("android.permission.BIND_IMS_SERVICE") public void setOnRtpRxNoticeListener(@NonNull android.content.Context, @NonNull android.media.MediaPlayer.OnRtpRxNoticeListener, @Nullable android.os.Handler); } - public static interface MediaPlayer.OnImsRxNoticeListener { - method public void onImsRxNotice(@NonNull android.media.MediaPlayer, @NonNull byte[]); + public static interface MediaPlayer.OnRtpRxNoticeListener { + method public void onRtpRxNotice(@NonNull android.media.MediaPlayer, int, @NonNull int[]); } public final class MediaRecorder.AudioSource { diff --git a/api/system-lint-baseline.txt b/api/system-lint-baseline.txt index 773ecd034a8e1..3ef1f354d9e8e 100644 --- a/api/system-lint-baseline.txt +++ b/api/system-lint-baseline.txt @@ -41,8 +41,8 @@ BuilderSetStyle: android.net.IpSecTransform.Builder#buildTunnelModeTransform(jav Builder methods names should use setFoo() / addFoo() / clearFoo() style: method android.net.IpSecTransform.Builder.buildTunnelModeTransform(java.net.InetAddress,android.net.IpSecManager.SecurityParameterIndex) -ExecutorRegistration: android.media.MediaPlayer#setOnImsRxNoticeListener(android.media.MediaPlayer.OnImsRxNoticeListener, android.os.Handler): - Registration methods should have overload that accepts delivery Executor: `setOnImsRxNoticeListener` +ExecutorRegistration: android.media.MediaPlayer#setOnRtpRxNoticeListener(android.content.Context, android.media.MediaPlayer.OnRtpRxNoticeListener, android.os.Handler): + Registration methods should have overload that accepts delivery Executor: `setOnRtpRxNoticeListener` ExecutorRegistration: android.net.wifi.p2p.WifiP2pManager#deletePersistentGroup(android.net.wifi.p2p.WifiP2pManager.Channel, int, android.net.wifi.p2p.WifiP2pManager.ActionListener): ExecutorRegistration: android.net.wifi.p2p.WifiP2pManager#factoryReset(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.ActionListener): @@ -377,8 +377,8 @@ SamShouldBeLast: android.media.AudioRouting#addOnRoutingChangedListener(android. SamShouldBeLast: android.media.AudioTrack#addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener, android.os.Handler): SAM-compatible parameters (such as parameter 1, "listener", in android.media.AudioTrack.addOnRoutingChangedListener) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions -SamShouldBeLast: android.media.MediaPlayer#setOnImsRxNoticeListener(android.media.MediaPlayer.OnImsRxNoticeListener, android.os.Handler): - SAM-compatible parameters (such as parameter 1, "listener", in android.media.MediaPlayer.setOnImsRxNoticeListener) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions +SamShouldBeLast: android.media.MediaPlayer#setOnRtpRxNoticeListener(android.content.Context, android.media.MediaPlayer.OnRtpRxNoticeListener, android.os.Handler): + SAM-compatible parameters (such as parameter 2, "listener", in android.media.MediaPlayer.setOnRtpRxNoticeListener) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions SamShouldBeLast: android.media.MediaRecorder#addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener, android.os.Handler): SamShouldBeLast: android.media.MediaRecorder#registerAudioRecordingCallback(java.util.concurrent.Executor, android.media.AudioManager.AudioRecordingCallback): diff --git a/core/api/system-current.txt b/core/api/system-current.txt index afa76101befff..4cc4b1664cf22 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -4364,11 +4364,11 @@ package android.media { } public class MediaPlayer implements android.media.AudioRouting android.media.VolumeAutomation { - method @RequiresPermission("android.permission.BIND_IMS_SERVICE") public void setOnImsRxNoticeListener(@Nullable android.media.MediaPlayer.OnImsRxNoticeListener, @Nullable android.os.Handler); + method @RequiresPermission("android.permission.BIND_IMS_SERVICE") public void setOnRtpRxNoticeListener(@NonNull android.content.Context, @NonNull android.media.MediaPlayer.OnRtpRxNoticeListener, @Nullable android.os.Handler); } - public static interface MediaPlayer.OnImsRxNoticeListener { - method public void onImsRxNotice(@NonNull android.media.MediaPlayer, @NonNull byte[]); + public static interface MediaPlayer.OnRtpRxNoticeListener { + method public void onRtpRxNotice(@NonNull android.media.MediaPlayer, int, @NonNull int[]); } public final class MediaRecorder.AudioSource { diff --git a/core/api/system-lint-baseline.txt b/core/api/system-lint-baseline.txt index 4db55e7e07ebe..a3fb06cbd92fd 100644 --- a/core/api/system-lint-baseline.txt +++ b/core/api/system-lint-baseline.txt @@ -6,7 +6,8 @@ ArrayReturn: android.view.contentcapture.ViewNode#getAutofillOptions(): BuilderSetStyle: android.net.IpSecTransform.Builder#buildTunnelModeTransform(java.net.InetAddress, android.net.IpSecManager.SecurityParameterIndex): Builder methods names should use setFoo() / addFoo() / clearFoo() style: method android.net.IpSecTransform.Builder.buildTunnelModeTransform(java.net.InetAddress,android.net.IpSecManager.SecurityParameterIndex) -ExecutorRegistration: android.media.MediaPlayer#setOnImsRxNoticeListener(android.media.MediaPlayer.OnImsRxNoticeListener, android.os.Handler): +ExecutorRegistration: android.media.MediaPlayer#setOnRtpRxNoticeListener(android.content.Context, android.media.MediaPlayer.OnRtpRxNoticeListener, android.os.Handler): + Registration methods should have overload that accepts delivery Executor: `setOnRtpRxNoticeListener` GenericException: android.app.prediction.AppPredictor#finalize(): @@ -182,7 +183,8 @@ SamShouldBeLast: android.media.AudioRecordingMonitor#registerAudioRecordingCallb SamShouldBeLast: android.media.AudioRouting#addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener, android.os.Handler): -SamShouldBeLast: android.media.MediaPlayer#setOnImsRxNoticeListener(android.media.MediaPlayer.OnImsRxNoticeListener, android.os.Handler): +SamShouldBeLast: android.media.MediaPlayer#setOnRtpRxNoticeListener(android.content.Context, android.media.MediaPlayer.OnRtpRxNoticeListener, android.os.Handler): + SAM-compatible parameters (such as parameter 2, "listener", in android.media.MediaPlayer.setOnRtpRxNoticeListener) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions SamShouldBeLast: android.media.AudioTrack#addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener, android.os.Handler): diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java index 42e39101de136..655454466b3d1 100644 --- a/media/java/android/media/MediaPlayer.java +++ b/media/java/android/media/MediaPlayer.java @@ -16,6 +16,9 @@ package android.media; +import static android.Manifest.permission.BIND_IMS_SERVICE; +import static android.content.pm.PackageManager.PERMISSION_GRANTED; + import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; @@ -83,6 +86,7 @@ import java.util.BitSet; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Scanner; import java.util.Set; import java.util.UUID; @@ -2109,8 +2113,8 @@ public class MediaPlayer extends PlayerBase mOnInfoListener = null; mOnVideoSizeChangedListener = null; mOnTimedTextListener = null; - mOnImsRxNoticeListener = null; - mOnImsRxNoticeHandler = null; + mOnRtpRxNoticeListener = null; + mOnRtpRxNoticeHandler = null; synchronized (mTimeProviderLock) { if (mTimeProvider != null) { mTimeProvider.close(); @@ -3323,7 +3327,7 @@ public class MediaPlayer extends PlayerBase private static final int MEDIA_META_DATA = 202; private static final int MEDIA_DRM_INFO = 210; private static final int MEDIA_TIME_DISCONTINUITY = 211; - private static final int MEDIA_IMS_RX_NOTICE = 300; + private static final int MEDIA_RTP_RX_NOTICE = 300; private static final int MEDIA_AUDIO_ROUTING_CHANGED = 10000; private TimeProvider mTimeProvider; @@ -3633,31 +3637,34 @@ public class MediaPlayer extends PlayerBase } return; - case MEDIA_IMS_RX_NOTICE: - final OnImsRxNoticeListener imsRxNoticeListener; - final Handler imsRxNoticeHandler; - imsRxNoticeListener = mOnImsRxNoticeListener; - imsRxNoticeHandler = mOnImsRxNoticeHandler; - if (imsRxNoticeListener == null) { + case MEDIA_RTP_RX_NOTICE: + final OnRtpRxNoticeListener rtpRxNoticeListener = mOnRtpRxNoticeListener; + final Handler rtpRxNoticeHandler = mOnRtpRxNoticeHandler; + if (rtpRxNoticeListener == null) { return; } if (msg.obj instanceof Parcel) { Parcel parcel = (Parcel) msg.obj; - byte[] event; + parcel.setDataPosition(0); + int noticeType; + int[] data; try { - event = parcel.marshall(); + noticeType = parcel.readInt(); + int numOfArgs = parcel.dataAvail() / 4; + data = new int[numOfArgs]; + for (int i = 0; i < numOfArgs; i++) { + data[i] = parcel.readInt(); + } } finally { parcel.recycle(); } - if (imsRxNoticeHandler == null) { - imsRxNoticeListener.onImsRxNotice(mMediaPlayer, event); + if (rtpRxNoticeHandler == null) { + rtpRxNoticeListener.onRtpRxNotice(mMediaPlayer, noticeType, data); } else { - imsRxNoticeHandler.post(new Runnable() { - @Override - public void run() { - imsRxNoticeListener.onImsRxNotice(mMediaPlayer, event); - } - }); + rtpRxNoticeHandler.post( + () -> + rtpRxNoticeListener + .onRtpRxNotice(mMediaPlayer, noticeType, data)); } } return; @@ -4103,18 +4110,18 @@ public class MediaPlayer extends PlayerBase /** * Interface definition of a callback to be invoked when - * IMS Rx connection has a notice. + * RTP Rx connection has a notice. * - * @see MediaPlayer.setOnImsRxNoticeListener + * @see #setOnRtpRxNoticeListener * * @hide */ @SystemApi - public interface OnImsRxNoticeListener + public interface OnRtpRxNoticeListener { /** - * Called to indicate an IMS event noticed from native media frameworks. - *

+ * Called when an RTP Rx connection has a notice. + *

* Basic format. All TYPE and ARG are 4 bytes unsigned integer in native byte order. *

{@code
          * 0                4               8                12
@@ -4169,14 +4176,14 @@ public class MediaPlayer extends PlayerBase
          * TYPE 205 - Transport layer Feedback message. (RFC-5104 Sec.4.2)
          * 0                4               8                12
          * +----------------+---------------+----------------+----------------+
-         * |      205       |      SSRC     | FB type(1 or 3)|     value      |
+         * |      205       |FB type(1 or 3)|      SSRC      |      Value     |
          * +----------------+---------------+----------------+----------------+
-         * SSRC
-         *      - Remote side's SSRC value of the media sender (RFC-3550 Sec.5.1)
          * Feedback (FB) type: determines the type of the event.
          *      - if 1, we received a NACK request from the remote side.
          *      - if 3, we received a TMMBR (Temporary Maximum Media Stream Bit Rate Request) from
          *        the remote side.
+         * SSRC
+         *      - Remote side's SSRC value of the media sender (RFC-3550 Sec.5.1)
          * Value: the FCI (Feedback Control Information) depending on the value of FB type
          *      - if FB type is 1, the Generic NACK as specified in RFC-4585 Sec.6.2.1
          *      - if FB type is 3, the TMMBR as specified in RFC-5104 Sec.4.2.1.1
@@ -4185,13 +4192,13 @@ public class MediaPlayer extends PlayerBase
          * TYPE 206 - Payload-specific Feedback message. (RFC-5104 Sec.4.3)
          * 0                4               8
          * +----------------+---------------+----------------+
-         * |      206       |      SSRC     | FB type(1 or 4)|
+         * |      206       |FB type(1 or 4)|      SSRC      |
          * +----------------+---------------+----------------+
-         * SSRC
-         *      - Remote side's SSRC value of the media sender (RFC-3550 Sec.5.1)
          * Feedback (FB) type: determines the type of the event.
          *      - if 1, we received a PLI request from the remote side.
          *      - if 4, we received a FIR request from the remote side.
+         * SSRC
+         *      - Remote side's SSRC value of the media sender (RFC-3550 Sec.5.1)
          *
          *
          * TYPE 300 - CVO (RTP Extension) message.
@@ -4212,34 +4219,39 @@ public class MediaPlayer extends PlayerBase
          * }
* * @param mp the {@code MediaPlayer} associated with this callback. - * @param event an IMS media event serialized as byte[] array. + * @param noticeType TYPE of the event. + * @param params RTP Rx media data serialized as int[] array. */ - void onImsRxNotice(@NonNull MediaPlayer mp, @NonNull byte[] event); + void onRtpRxNotice(@NonNull MediaPlayer mp, int noticeType, @NonNull int[] params); } /** - * Register a callback to be invoked when IMS Rx connection has a notice. - * The callback required if mediaplayer configured for RTPSource by - * MediaPlayer.setDataSource(String8 rtpParams) of mediaplayer.h + * Sets the listener to be invoked when an RTP Rx connection has a notice. + * The listener is required if MediaPlayer is configured for RTPSource by + * MediaPlayer.setDataSource(String8 rtpParams) of mediaplayer.h. * - * @see MediaPlayer.OnImsRxNoticeListener + * @see OnRtpRxNoticeListener * - * @param listener the callback that will be run - * @param handler Specifies Handler object for the thread on which to execute - * the callback. If null, the handler on the main looper will be used. + * @param listener the listener called after a notice from RTP Rx + * @param handler the {@link Handler} that receives RTP Tx events * * @hide */ @SystemApi @RequiresPermission("android.permission.BIND_IMS_SERVICE") - public void setOnImsRxNoticeListener( - @Nullable OnImsRxNoticeListener listener, @Nullable Handler handler) { - mOnImsRxNoticeListener = listener; - mOnImsRxNoticeHandler = handler; + public void setOnRtpRxNoticeListener( + @NonNull Context context, + @NonNull OnRtpRxNoticeListener listener, @Nullable Handler handler) { + Objects.requireNonNull(context); + Preconditions.checkArgument( + context.checkSelfPermission(BIND_IMS_SERVICE) == PERMISSION_GRANTED, + "android.permission.BIND_IMS_SERVICE permission not granted."); + mOnRtpRxNoticeListener = Objects.requireNonNull(listener); + mOnRtpRxNoticeHandler = handler; } - private OnImsRxNoticeListener mOnImsRxNoticeListener; - private Handler mOnImsRxNoticeHandler; + private OnRtpRxNoticeListener mOnRtpRxNoticeListener; + private Handler mOnRtpRxNoticeHandler; /** * Register a callback to be invoked when a selected track has timed metadata available.