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

Commit 4c2e8620 authored by Dongwon Kang's avatar Dongwon Kang
Browse files

MediaPlayer2: use protobuf instead of parcel for TimedText

Test: MediaPlayer2Test
Bug: 112767225
Change-Id: I374427125af3d470224876c947d69dda243625cd
parent 63f28a9e
Loading
Loading
Loading
Loading
+56 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.graphics.SurfaceTexture;
import android.graphics.Rect;
import android.media.MediaPlayer2Proto;
import android.media.MediaPlayer2Proto.PlayerMessage;
import android.media.MediaPlayer2Proto.Value;
@@ -2983,7 +2984,7 @@ public final class MediaPlayer2Impl extends MediaPlayer2 {
                        Log.w(TAG, "Failed to parse timed text.", e);
                        return;
                    }
                    text = null; // TODO: convert PlayerMessage to new TimedText(playerMsg);
                    text = TimedTextUtil.parsePlayerMessage(playerMsg);
                } else {
                    text = null;
                }
@@ -4276,6 +4277,60 @@ public final class MediaPlayer2Impl extends MediaPlayer2 {
                mode == VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
    }

    private static class TimedTextUtil {
        // These keys must be in sync with the keys in TextDescription2.h
        private static final int KEY_START_TIME                     = 7; // int
        private static final int KEY_STRUCT_TEXT_POS               = 14; // TextPos
        private static final int KEY_STRUCT_TEXT                   = 16; // Text
        private static final int KEY_GLOBAL_SETTING               = 101;
        private static final int KEY_LOCAL_SETTING                = 102;

        private static TimedText parsePlayerMessage(PlayerMessage playerMsg) {
            if (playerMsg.getValuesCount() == 0) {
                return null;
            }

            String textChars = null;
            Rect textBounds = null;
            Iterator<Value> in = playerMsg.getValuesList().iterator();
            int type = in.next().getInt32Value();
            if (type == KEY_LOCAL_SETTING) {
                type = in.next().getInt32Value();
                if (type != KEY_START_TIME) {
                    return null;
                }
                int startTimeMs = in.next().getInt32Value();

                type = in.next().getInt32Value();
                if (type != KEY_STRUCT_TEXT) {
                    return null;
                }

                byte[] text = in.next().getBytesValue().toByteArray();
                if (text == null || text.length == 0) {
                    textChars = null;
                } else {
                    textChars = new String(text);
                }

            } else if (type != KEY_GLOBAL_SETTING) {
                Log.w(TAG, "Invalid timed text key found: " + type);
                return null;
            }
            if (in.hasNext()) {
                type = in.next().getInt32Value();
                if (type == KEY_STRUCT_TEXT_POS) {
                    int top = in.next().getInt32Value();
                    int left = in.next().getInt32Value();
                    int bottom = in.next().getInt32Value();
                    int right = in.next().getInt32Value();
                    textBounds = new Rect(left, top, right, bottom);
                }
            }
            return new TimedText(textChars, textBounds);
        }
    }

    /** @hide */
    static class TimeProvider implements MediaTimeProvider {
        private static final String TAG = "MTP";
+10 −0
Original line number Diff line number Diff line
@@ -363,6 +363,16 @@ public final class TimedText
        }
    }

    /**
     * @param text the characters in the timed text.
     * @param bounds the rectangle area or region for rendering the timed text.
     * {@hide}
     */
    public TimedText(String text, Rect bounds) {
        mTextChars = text;
        mTextBounds = bounds;
    }

    /**
     * Get the characters in the timed text.
     *
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ cc_library_shared {
        "libstagefright_nuplayer2",
        "libstagefright_player2",
        "libstagefright_rtsp",
        "libstagefright_timedtext",
        "libstagefright_timedtext2",
        "libunwindstack",
        "libutilscallstack",
        "libziparchive",
+0 −5
Original line number Diff line number Diff line
@@ -199,11 +199,6 @@ void JNIMediaPlayer2Listener::notify(int64_t srcId, int msg, int ext1, int ext2,
{
    JNIEnv *env = JavaVMHelper::getJNIEnv();
    if (obj != NULL) {
        // TODO: replace the following Parcel usages with proto.
        // 1. MEDIA_DRM_INFO : DrmInfo
        // 2. MEDIA_TIMED_TEXT : TimedText
        // 2. MEDIA_SUBTITLE_DATA : SubtitleData
        // 4. MEDIA_META_DATA : TimedMetaData
        int size = obj->ByteSize();
        jbyte* temp = new jbyte[size];
        obj->SerializeToArray(temp, size);