Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eba1c0bb authored by Dongwon Kang's avatar Dongwon Kang Committed by Android (Google) Code Review
Browse files

Merge "do not merge. Implement onVideoAvailable/Unavailable in TIF." into lmp-dev

parents 1677476a 9b08edff
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -16166,6 +16166,10 @@ package android.media.tv {
  public final class TvInputManager {
  public final class TvInputManager {
    method public boolean getAvailability(java.lang.String);
    method public boolean getAvailability(java.lang.String);
    method public java.util.List<android.media.tv.TvInputInfo> getTvInputList();
    method public java.util.List<android.media.tv.TvInputInfo> getTvInputList();
    field public static final int VIDEO_UNAVAILABLE_REASON_BUFFERING = 3; // 0x3
    field public static final int VIDEO_UNAVAILABLE_REASON_TUNE = 1; // 0x1
    field public static final int VIDEO_UNAVAILABLE_REASON_UNKNOWN = 0; // 0x0
    field public static final int VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL = 2; // 0x2
  }
  }
  public static abstract class TvInputManager.TvInputListener {
  public static abstract class TvInputManager.TvInputListener {
@@ -16185,6 +16189,8 @@ package android.media.tv {
    ctor public TvInputService.Session();
    ctor public TvInputService.Session();
    method public void dispatchChannelRetuned(android.net.Uri);
    method public void dispatchChannelRetuned(android.net.Uri);
    method public void dispatchTrackInfoChanged(java.util.List<android.media.tv.TvTrackInfo>);
    method public void dispatchTrackInfoChanged(java.util.List<android.media.tv.TvTrackInfo>);
    method public void dispatchVideoAvailable();
    method public void dispatchVideoUnavailable(int);
    method public android.view.View onCreateOverlayView();
    method public android.view.View onCreateOverlayView();
    method public boolean onGenericMotionEvent(android.view.MotionEvent);
    method public boolean onGenericMotionEvent(android.view.MotionEvent);
    method public boolean onKeyDown(int, android.view.KeyEvent);
    method public boolean onKeyDown(int, android.view.KeyEvent);
@@ -16263,6 +16269,8 @@ package android.media.tv {
    method public void onError(java.lang.String, int);
    method public void onError(java.lang.String, int);
    method public void onTrackInfoChanged(java.lang.String, java.util.List<android.media.tv.TvTrackInfo>);
    method public void onTrackInfoChanged(java.lang.String, java.util.List<android.media.tv.TvTrackInfo>);
    method public void onVideoSizeChanged(java.lang.String, int, int);
    method public void onVideoSizeChanged(java.lang.String, int, int);
    method public void onVideoAvailable(java.lang.String);
    method public void onVideoUnavailable(java.lang.String, int);
  }
  }
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -35,4 +35,6 @@ oneway interface ITvInputClient {
    void onSessionEvent(in String name, in Bundle args, int seq);
    void onSessionEvent(in String name, in Bundle args, int seq);
    void onChannelRetuned(in Uri channelUri, int seq);
    void onChannelRetuned(in Uri channelUri, int seq);
    void onTrackInfoChanged(in List<TvTrackInfo> tracks, int seq);
    void onTrackInfoChanged(in List<TvTrackInfo> tracks, int seq);
    void onVideoAvailable(int seq);
    void onVideoUnavailable(int reason, int seq);
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -31,4 +31,6 @@ oneway interface ITvInputSessionCallback {
    void onSessionEvent(in String name, in Bundle args);
    void onSessionEvent(in String name, in Bundle args);
    void onChannelRetuned(in Uri channelUri);
    void onChannelRetuned(in Uri channelUri);
    void onTrackInfoChanged(in List<TvTrackInfo> tracks);
    void onTrackInfoChanged(in List<TvTrackInfo> tracks);
    void onVideoAvailable();
    void onVideoUnavailable(int reason);
}
}
+83 −0
Original line number Original line Diff line number Diff line
@@ -47,6 +47,24 @@ import java.util.Map;
public final class TvInputManager {
public final class TvInputManager {
    private static final String TAG = "TvInputManager";
    private static final String TAG = "TvInputManager";


    /**
     * A generic reason. Video is not available due to an unspecified error.
     */
    public static final int VIDEO_UNAVAILABLE_REASON_UNKNOWN = 0;
    /**
     * Video is not available because the TV input is tuning to another channel.
     */
    public static final int VIDEO_UNAVAILABLE_REASON_TUNE = 1;
    /**
     * Video is not available due to the weak TV signal.
     */
    public static final int VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL = 2;
    /**
     * Video is not available because the TV input stopped the playback temporarily to buffer more
     * data.
     */
    public static final int VIDEO_UNAVAILABLE_REASON_BUFFERING = 3;

    private final ITvInputManager mService;
    private final ITvInputManager mService;


    // A mapping from an input to the list of its TvInputListenerRecords.
    // A mapping from an input to the list of its TvInputListenerRecords.
@@ -107,6 +125,29 @@ public final class TvInputManager {
        public void onTrackInfoChanged(Session session, List<TvTrackInfo> tracks) {
        public void onTrackInfoChanged(Session session, List<TvTrackInfo> tracks) {
        }
        }


        /**
         * This is called when the video is available, so the TV input starts the playback.
         *
         * @param session A {@link TvInputManager.Session} associated with this callback
         */
        public void onVideoAvailable(Session session) {
        }

        /**
         * This is called when the video is not available, so the TV input stops the playback.
         *
         * @param session A {@link TvInputManager.Session} associated with this callback
         * @param reason The reason why the TV input stopped the playback:
         * <ul>
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_UNKNOWN}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_TUNE}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_BUFFERING}
         * </ul>
         */
        public void onVideoUnavailable(Session session, int reason) {
        }

        /**
        /**
         * This is called when a custom event has been sent from this session.
         * This is called when a custom event has been sent from this session.
         *
         *
@@ -168,6 +209,24 @@ public final class TvInputManager {
            });
            });
        }
        }


        public void postVideoAvailable() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mSessionCallback.onVideoAvailable(mSession);
                }
            });
        }

        public void postVideoUnavailable(final int reason) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mSessionCallback.onVideoUnavailable(mSession, reason);
                }
            });
        }

        public void postSessionEvent(final String eventType, final Bundle eventArgs) {
        public void postSessionEvent(final String eventType, final Bundle eventArgs) {
            mHandler.post(new Runnable() {
            mHandler.post(new Runnable() {
                @Override
                @Override
@@ -279,6 +338,30 @@ public final class TvInputManager {
                }
                }
            }
            }


            @Override
            public void onVideoAvailable(int seq) {
                synchronized (mSessionCallbackRecordMap) {
                    SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
                    if (record == null) {
                        Log.e(TAG, "Callback not found for seq " + seq);
                        return;
                    }
                    record.postVideoAvailable();
                }
            }

            @Override
            public void onVideoUnavailable(int reason, int seq) {
                synchronized (mSessionCallbackRecordMap) {
                    SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
                    if (record == null) {
                        Log.e(TAG, "Callback not found for seq " + seq);
                        return;
                    }
                    record.postVideoUnavailable(reason);
                }
            }

            @Override
            @Override
            public void onSessionEvent(String eventType, Bundle eventArgs, int seq) {
            public void onSessionEvent(String eventType, Bundle eventArgs, int seq) {
                synchronized (mSessionCallbackRecordMap) {
                synchronized (mSessionCallbackRecordMap) {
+53 −1
Original line number Original line Diff line number Diff line
@@ -266,6 +266,56 @@ public abstract class TvInputService extends Service {
            });
            });
        }
        }


        /**
         * Informs the application that video is available and the playback of the TV stream has
         * been started.
         */
        public void dispatchVideoAvailable() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "dispatchVideoAvailable");
                        mSessionCallback.onVideoAvailable();
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in dispatchVideoAvailable");
                    }
                }
            });
        }

        /**
         * Informs the application that video is not available, so the TV input cannot continue
         * playing the TV stream.
         *
         * @param reason The reason why the TV input stopped the playback:
         * <ul>
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_UNKNOWN}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_TUNE}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_BUFFERING}
         * </ul>
         */
        public void dispatchVideoUnavailable(final int reason) {
            if (reason != TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN
                    && reason != TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNE
                    && reason != TvInputManager.VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL
                    && reason != TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING) {
                throw new IllegalArgumentException("Unknown reason: " + reason);
            }
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "dispatchVideoUnavailable");
                        mSessionCallback.onVideoUnavailable(reason);
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in dispatchVideoUnavailable");
                    }
                }
            });
        }

        /**
        /**
         * Called when the session is released.
         * Called when the session is released.
         */
         */
@@ -289,7 +339,9 @@ public abstract class TvInputService extends Service {
        public abstract void onSetStreamVolume(float volume);
        public abstract void onSetStreamVolume(float volume);


        /**
        /**
         * Tunes to a given channel.
         * Tunes to a given channel. When the video is available, {@link #dispatchVideoAvailable()}
         * should be called. Also, {@link #dispatchVideoUnavailable(int)} should be called when the
         * TV input cannot continue playing the given channel.
         *
         *
         * @param channelUri The URI of the channel.
         * @param channelUri The URI of the channel.
         * @return {@code true} the tuning was successful, {@code false} otherwise.
         * @return {@code true} the tuning was successful, {@code false} otherwise.
Loading