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

Commit d9228d7b authored by Hangyu Kuang's avatar Hangyu Kuang Committed by Android (Google) Code Review
Browse files

Merge "transcoding: Add error code in case of failure." into sc-dev

parents a69d3dc3 97b00527
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -47,12 +47,16 @@ package android.media {

  public static final class MediaTranscodeManager.TranscodingSession {
    method public void cancel();
    method public int getErrorCode();
    method @IntRange(from=0, to=100) public int getProgress();
    method public int getResult();
    method public int getSessionId();
    method public int getStatus();
    method public void setOnProgressUpdateListener(@NonNull java.util.concurrent.Executor, @Nullable android.media.MediaTranscodeManager.TranscodingSession.OnProgressUpdateListener);
    method public void setOnProgressUpdateListener(int, @NonNull java.util.concurrent.Executor, @Nullable android.media.MediaTranscodeManager.TranscodingSession.OnProgressUpdateListener);
    field public static final int ERROR_DROPPED_BY_SERVICE = 1; // 0x1
    field public static final int ERROR_NONE = 0; // 0x0
    field public static final int ERROR_SERVICE_DIED = 2; // 0x2
    field public static final int RESULT_CANCELED = 4; // 0x4
    field public static final int RESULT_ERROR = 3; // 0x3
    field public static final int RESULT_NONE = 1; // 0x1
+45 −4
Original line number Diff line number Diff line
@@ -217,7 +217,8 @@ public final class MediaTranscodeManager {

            // Updates the session status and result.
            session.updateStatusAndResult(TranscodingSession.STATUS_FINISHED,
                    TranscodingSession.RESULT_SUCCESS);
                    TranscodingSession.RESULT_SUCCESS,
                    TranscodingSession.ERROR_NONE);

            // Notifies client the session is done.
            if (session.mListener != null && session.mListenerExecutor != null) {
@@ -241,7 +242,7 @@ public final class MediaTranscodeManager {

            // Updates the session status and result.
            session.updateStatusAndResult(TranscodingSession.STATUS_FINISHED,
                    TranscodingSession.RESULT_ERROR);
                    TranscodingSession.RESULT_ERROR, errorCode);

            // Notifies client the session failed.
            if (session.mListener != null && session.mListenerExecutor != null) {
@@ -330,7 +331,8 @@ public final class MediaTranscodeManager {

                    if (session.getStatus() == TranscodingSession.STATUS_RUNNING) {
                        session.updateStatusAndResult(TranscodingSession.STATUS_FINISHED,
                                TranscodingSession.RESULT_ERROR);
                                TranscodingSession.RESULT_ERROR,
                                TranscodingSession.ERROR_SERVICE_DIED);

                        // Remove the session from pending sessions.
                        mPendingTranscodingSessions.remove(entry.getKey());
@@ -1239,6 +1241,33 @@ public final class MediaTranscodeManager {
        @Retention(RetentionPolicy.SOURCE)
        public @interface Result {}


        // The error code exposed here should be in sync with:
        // frameworks/av/media/libmediatranscoding/aidl/android/media/TranscodingErrorCode.aidl
        /** @hide */
        @IntDef(prefix = { "TRANSCODING_SESSION_ERROR_" }, value = {
                ERROR_NONE,
                ERROR_DROPPED_BY_SERVICE,
                ERROR_SERVICE_DIED})
        @Retention(RetentionPolicy.SOURCE)
        public @interface TranscodingSessionErrorCode{}
        /**
         * Constant indicating that no error occurred.
         */
        public static final int ERROR_NONE = 0;

        /**
         * Constant indicating that the session is dropped by Transcoding service due to hitting
         * the limit, e.g. too many back to back transcoding happen in a short time frame.
         */
        public static final int ERROR_DROPPED_BY_SERVICE = 1;

        /**
         * Constant indicating the backing transcoding service is died. Client should enqueue the
         * the request again.
         */
        public static final int ERROR_SERVICE_DIED = 2;

        /** Listener that gets notified when the progress changes. */
        @FunctionalInterface
        public interface OnProgressUpdateListener {
@@ -1272,6 +1301,8 @@ public final class MediaTranscodeManager {
        @GuardedBy("mLock")
        private @Result int mResult = RESULT_NONE;
        @GuardedBy("mLock")
        private @TranscodingSessionErrorCode int mErrorCode = ERROR_NONE;
        @GuardedBy("mLock")
        private boolean mHasRetried = false;
        // The original request that associated with this session.
        private final TranscodingRequest mRequest;
@@ -1325,10 +1356,20 @@ public final class MediaTranscodeManager {
        }

        private void updateStatusAndResult(@Status int sessionStatus,
                @Result int sessionResult) {
                @Result int sessionResult, @TranscodingSessionErrorCode int errorCode) {
            synchronized (mLock) {
                mStatus = sessionStatus;
                mResult = sessionResult;
                mErrorCode = errorCode;
            }
        }

        /**
         * Retrieve the error code associated with the RESULT_ERROR.
         */
        public @TranscodingSessionErrorCode int getErrorCode() {
            synchronized (mLock) {
                return mErrorCode;
            }
        }