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

Commit eaa5d8f9 authored by Gloria Wang's avatar Gloria Wang
Browse files

Timed text display format support:

1. Extract 3GPP global format descriptions
2. Extract 3GPP local format descriptions
3. Define data structure (TimedText) for applications to
retrieve the format metadata

Change-Id: I6eac2a78df29ee15beee456656331fdd83b24e8e
parent 8969d992
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ enum {

    // The language code for this media
    kKeyMediaLanguage     = 'lang',  // cstring

    // To store the timed text format data
    kKeyTextFormatData    = 'text',  // raw data
};

enum {
+12 −5
Original line number Diff line number Diff line
@@ -1568,7 +1568,14 @@ public class MediaPlayer
                return;
            case MEDIA_TIMED_TEXT:
                if (mOnTimedTextListener != null) {
                    mOnTimedTextListener.onTimedText(mMediaPlayer, (String)msg.obj);
                    if (msg.obj == null) {
                        mOnTimedTextListener.onTimedText(mMediaPlayer, null);
                    } else {
                        if (msg.obj instanceof byte[]) {
                            TimedText text = new TimedText((byte[])(msg.obj));
                            mOnTimedTextListener.onTimedText(mMediaPlayer, text);
                        }
                    }
                }
                return;

@@ -1755,14 +1762,14 @@ public class MediaPlayer
    public interface OnTimedTextListener
    {
        /**
         * Called to indicate the video size
         * Called to indicate an avaliable timed text
         *
         * @param mp             the MediaPlayer associated with this callback
         * @param text           the timed text sample which contains the
         *                       text needed to be displayed.
         * @param text           the timed text sample which contains the text
         *                       needed to be displayed and the display format.
         * {@hide}
         */
        public void onTimedText(MediaPlayer mp, String text);
        public void onTimedText(MediaPlayer mp, TimedText text);
    }

    /**
+655 −0

File added.

Preview size limit exceeded, changes collapsed.

+56 −6
Original line number Diff line number Diff line
@@ -889,12 +889,18 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
            uint32_t entry_count = U32_AT(&buffer[4]);

            if (entry_count > 1) {
                // For 3GPP timed text, there could be multiple tx3g boxes contain
                // multiple text display formats. These formats will be used to
                // display the timed text.
                const char *mime;
                CHECK(mLastTrack->meta->findCString(kKeyMIMEType, &mime));
                if (strcasecmp(mime, MEDIA_MIMETYPE_TEXT_3GPP)) {
                    // For now we only support a single type of media per track.

                    mLastTrack->skipTrack = true;
                    *offset += chunk_size;
                    break;
                }
            }

            off64_t stop_offset = *offset + chunk_size;
            *offset = data_offset + 8;
@@ -1324,9 +1330,53 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
            return parseDrmSINF(offset, data_offset);
        }

        case FOURCC('t', 'x', '3', 'g'):
        case FOURCC('h', 'd', 'l', 'r'):
        {
            uint32_t buffer;
            if (mDataSource->readAt(
                        data_offset + 8, &buffer, 4) < 4) {
                return ERROR_IO;
            }

            uint32_t type = ntohl(buffer);
            // For the 3GPP file format, the handler-type within the 'hdlr' box
            // shall be 'text'
            if (type == FOURCC('t', 'e', 'x', 't')) {
                mLastTrack->meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_TEXT_3GPP);
            }

            *offset += chunk_size;
            break;
        }

        case FOURCC('t', 'x', '3', 'g'):
        {
            uint32_t type;
            const void *data;
            size_t size = 0;
            if (!mLastTrack->meta->findData(
                    kKeyTextFormatData, &type, &data, &size)) {
                size = 0;
            }

            uint8_t *buffer = new uint8_t[size + chunk_size];

            if (size > 0) {
                memcpy(buffer, data, size);
            }

            if ((size_t)(mDataSource->readAt(*offset, buffer + size, chunk_size))
                    < chunk_size) {
                delete[] buffer;
                buffer = NULL;

                return ERROR_IO;
            }

            mLastTrack->meta->setData(
                    kKeyTextFormatData, 0, buffer, size + chunk_size);

            delete[] buffer;

            *offset += chunk_size;
            break;
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:=                 \
        TextDescriptions.cpp      \
        TimedTextParser.cpp       \
        TimedTextPlayer.cpp

Loading