Ignore:
Timestamp:
03/25/08 16:31:41 (16 years ago)
Author:
r2d
Message:
  • added mpcchap utility to add (and later dump) chapters in a sv8 mpc file
  • moved tag.c from mpcenc to common, as used by mpcchap
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpc/trunk/libmpcdec/mpc_demux.c

    r377 r384  
    258258        mpc_uint64_t ptr;
    259259        mpc_block b;
     260        int st_head_size;
    260261
    261262        cur = mpc_demux_pos(d);
    262263        mpc_bits_get_size(&d->bits_reader, &ptr);
    263264        mpc_demux_seek(d, (ptr - size) * 8 + cur, 11);
    264         mpc_bits_get_block(&d->bits_reader, &b);
     265        st_head_size = mpc_bits_get_block(&d->bits_reader, &b);
    265266        if (memcmp(b.key, "ST", 2) == 0) {
     267                d->chap_pos = (ptr - size + b.size + st_head_size) * 8 + cur;
     268                d->chap_nb = -1;
    266269                mpc_demux_fill(d, (mpc_uint32_t) b.size, 0);
    267270                mpc_demux_ST(d);
     
    270273}
    271274
     275static void mpc_demux_chap_find(mpc_demux * d)
     276{
     277        if (d->chap_pos == 0) {
     278                // FIXME : find chapters from end of file
     279        }
     280        mpc_block b;
     281        int tag_size = 0, chap_size = 0, size, i = 0;
     282        d->chap_nb = 0;
     283        mpc_demux_seek(d, d->chap_pos, 20);
     284        size = mpc_bits_get_block(&d->bits_reader, &b);
     285        while (memcmp(b.key, "CT", 2) == 0) {
     286                mpc_uint64_t chap_sample;
     287                d->chap_nb++;
     288                chap_size += size;
     289                size = mpc_bits_get_size(&d->bits_reader, &chap_sample);
     290                chap_size += size;
     291                tag_size += b.size - size;
     292                mpc_demux_seek(d, d->chap_pos + (chap_size + tag_size) * 8, 20);
     293                size = mpc_bits_get_block(&d->bits_reader, &b);
     294        }
     295
     296        d->chap = malloc(sizeof(mpc_chap_t) * d->chap_nb + tag_size);
     297        char * ptag = (char*)(d->chap + d->chap_nb);
     298
     299        mpc_demux_seek(d, d->chap_pos, 11);
     300        size = mpc_bits_get_block(&d->bits_reader, &b);
     301        while (memcmp(b.key, "CT", 2) == 0) {
     302                mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0);
     303                size = mpc_bits_get_size(&d->bits_reader, &d->chap[i].sample);
     304                memcpy(ptag, d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3), b.size - size);
     305                d->bits_reader.buff += b.size - size;
     306                d->chap[i].tag_size = b.size - size;
     307                d->chap[i].tag = ptag;
     308                ptag += b.size - size;
     309                i++;
     310                size = mpc_bits_get_block(&d->bits_reader, &b);
     311        }
     312       
     313        d->bits_reader.buff -= size;
     314}
     315
     316mpc_int_t mpc_demux_chap_nb(mpc_demux * d)
     317{
     318        if (d->chap_nb == -1)
     319                mpc_demux_chap_find(d);
     320        return d->chap_nb;
     321}
     322
     323mpc_uint64_t mpc_demux_chap(mpc_demux * d, int chap_nb, char ** tag, mpc_uint_t * tag_size)
     324{
     325        if (d->chap_nb == -1)
     326                mpc_demux_chap_find(d);
     327        if (chap_nb >= d->chap_nb)
     328                return 0;
     329        if (tag != 0 && tag_size != 0) {
     330                *tag = d->chap[chap_nb].tag;
     331                *tag_size = d->chap[chap_nb].tag_size;
     332        }
     333        return d->chap[chap_nb].sample;
     334}
     335               
    272336static mpc_status mpc_demux_header(mpc_demux * d)
    273337{
     
    339403                memset(p_tmp, 0, sizeof(mpc_demux));
    340404                p_tmp->r = p_reader;
     405                p_tmp->chap_nb = -1;
    341406                mpc_demux_clear_buff(p_tmp);
    342407                if (mpc_demux_header(p_tmp) == MPC_STATUS_OK &&
     
    358423        mpc_decoder_exit(d->d);
    359424        free(d->seek_table);
     425        free(d->chap);
    360426        free(d);
    361427}
Note: See TracChangeset for help on using the changeset viewer.