Ticket #5071: matroskadec.c.latest2.diff

File matroskadec.c.latest2.diff, 5.0 KB (added by matsp888, 11 years ago)
  • matroskadec.c

    old new  
    310310    /* File has SSA subtitles which prevent incremental cluster parsing. */
    311311    int contains_ssa;
    312312
    313313    /* WebM DASH Manifest live flag/ */
    314314    int is_live;
     315
     316    uint8_t *pal;
    315317} MatroskaDemuxContext;
    316318
    317319typedef struct MatroskaBlock {
    318320    uint64_t duration;
    319321    int64_t  reference;
     
    18531855            if (ret < 0)
    18541856                return ret;
    18551857            codec_id         = st->codec->codec_id;
    18561858            extradata_offset = FFMIN(track->codec_priv.size, 18);
    18571859        } else if (!strcmp(track->codec_id, "A_QUICKTIME")
    1858                    && (track->codec_priv.size >= 86)
     1860                   && (track->codec_priv.size >= 36)
    18591861                   && (track->codec_priv.data)) {
    18601862            fourcc = AV_RL32(track->codec_priv.data + 4);
    18611863            codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc);
    18621864            if (ff_codec_get_id(ff_codec_movaudio_tags, AV_RL32(track->codec_priv.data))) {
    18631865                fourcc = AV_RL32(track->codec_priv.data);
    18641866                codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc);
    18651867            }
    18661868        } else if (!strcmp(track->codec_id, "V_QUICKTIME") &&
    18671869                   (track->codec_priv.size >= 21)          &&
    18681870                   (track->codec_priv.data)) {
    1869             fourcc   = AV_RL32(track->codec_priv.data + 4);
     1871            AVIOContext pb;
     1872            MOVContext *mc;
     1873            MOVStreamContext *msc;
     1874            void *priv_data;
     1875            int nb_streams;
     1876            fourcc = AV_RL32(track->codec_priv.data + 4);
    18701877            codec_id = ff_codec_get_id(ff_codec_movvideo_tags, fourcc);
    18711878            if (ff_codec_get_id(ff_codec_movvideo_tags, AV_RL32(track->codec_priv.data))) {
    18721879                fourcc   = AV_RL32(track->codec_priv.data);
    18731880                codec_id = ff_codec_get_id(ff_codec_movvideo_tags, fourcc);
    18741881            }
     
    18781885                char buf[32];
    18791886                av_get_codec_tag_string(buf, sizeof(buf), fourcc);
    18801887                av_log(matroska->ctx, AV_LOG_ERROR,
    18811888                       "mov FourCC not found %s.\n", buf);
    18821889            }
     1890            priv_data = st->priv_data;
     1891            nb_streams = s->nb_streams;
     1892            mc = av_mallocz(sizeof(*mc));
     1893            if (! mc)
     1894                return AVERROR(ENOMEM);
     1895            mc->fc = s;
     1896            st->priv_data = msc = av_mallocz(sizeof(MOVStreamContext));
     1897            if (!msc) {
     1898                av_free(mc);
     1899                st->priv_data = priv_data;
     1900                return AVERROR(ENOMEM);
     1901            }
     1902            ffio_init_context(&pb, track->codec_priv.data, track->codec_priv.size, 0, NULL, NULL, NULL, NULL);
     1903            /* ff_mov_read_stsd_entries updates stream s->nb_streams-1,
     1904             * so set it temporarily to indicate which stream to update. */
     1905            s->nb_streams = st->index + 1;
     1906            ff_mov_read_stsd_entries(mc, &pb, 1);
     1907            if (msc->has_palette) {
     1908                if ((matroska->pal = av_malloc(AVPALETTE_SIZE))) {
     1909                    memcpy(matroska->pal, msc->palette, AVPALETTE_SIZE);
     1910                    if ((extradata = av_malloc(AVPALETTE_SIZE))) {
     1911                        memcpy(extradata, msc->palette, AVPALETTE_SIZE);
     1912                        extradata_size = AVPALETTE_SIZE;
     1913                    }
     1914                }
     1915                if (!matroska->pal || !extradata) {
     1916                    av_free(msc);
     1917                    av_free(mc);
     1918                    if (matroska->pal) av_freep(&matroska->pal);
     1919                    if (extradata) av_freep(&extradata);
     1920                    st->priv_data = priv_data;
     1921                    s->nb_streams = nb_streams;
     1922                    return AVERROR(ENOMEM);
     1923                }
     1924            }
     1925            av_free(msc);
     1926            av_free(mc);
     1927            st->priv_data = priv_data;
     1928            s->nb_streams = nb_streams;
    18831929        } else if (codec_id == AV_CODEC_ID_PCM_S16BE) {
    18841930            switch (track->audio.bitdepth) {
    18851931            case  8:
    18861932                codec_id = AV_CODEC_ID_PCM_U8;
    18871933                break;
     
    23222368                                   AVPacket *pkt)
    23232369{
    23242370    if (matroska->num_packets > 0) {
    23252371        memcpy(pkt, matroska->packets[0], sizeof(AVPacket));
    23262372        av_freep(&matroska->packets[0]);
     2373        if (matroska->pal) {
     2374            uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
     2375            if (!pal) {
     2376                av_log(matroska->ctx, AV_LOG_ERROR, "Cannot append palette to packet\n");
     2377            } else {
     2378                memcpy(pal, matroska->pal, AVPALETTE_SIZE);
     2379            }
     2380            av_freep(&matroska->pal);
     2381        }
    23272382        if (matroska->num_packets > 1) {
    23282383            void *newpackets;
    23292384            memmove(&matroska->packets[0], &matroska->packets[1],
    23302385                    (matroska->num_packets - 1) * sizeof(AVPacket *));
    23312386            newpackets = av_realloc(matroska->packets,