if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count) && (mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] < offset)) { st_id = i; offset = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk];
MOVStreamContext *msc = mov->streams[i];  if ((msc->next_chunk < msc->chunk_count) && msc->next_chunk >= 0 && (msc->chunk_offsets[msc->next_chunk] < offset)) { sc = msc; offset = msc->chunk_offsets[msc->next_chunk];
static int mov_read_packet(AVFormatContext *s, AVPacket *pkt){    MOVContext *mov = s->priv_data;    MOVStreamContext *sc;    int64_t offset = 0x0FFFFFFFFFFFFFFF;    int i;    int st_id = 0, size;    size = 0x0FFFFFFF;    #ifdef MOV_SPLIT_CHUNKS    if (mov->partial) {                int idx;        st_id = mov->partial - 1;        idx = mov->streams[st_id]->sample_to_chunk_index;        if (idx < 0) return 0;        size = mov->streams[st_id]->sample_sizes[mov->streams[st_id]->current_sample];        mov->streams[st_id]->current_sample++;        mov->streams[st_id]->left_in_chunk--;        if(mov->streams[st_id]->left_in_chunk <= 0)            mov->partial = 0;        offset = mov->next_chunk_offset;        /* extract the sample */        goto readchunk;    }#endifagain:    for(i=0; i<mov->total_streams; i++) {        if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)        && (mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] < offset)) {            st_id = i;            offset = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk];        }    }    mov->streams[st_id]->next_chunk++;    if(offset==0x0FFFFFFFFFFFFFFF)        return -1;        if(mov->next_chunk_offset < offset) { /* some meta data */        url_fskip(&s->pb, (offset - mov->next_chunk_offset));        mov->next_chunk_offset = offset;    }//printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset);    if(!mov->streams[st_id]->is_ff_stream) {        url_fskip(&s->pb, (offset - mov->next_chunk_offset));        mov->next_chunk_offset = offset;        offset = 0x0FFFFFFFFFFFFFFF;        goto again;    }    /* now get the chunk size... */    for(i=0; i<mov->total_streams; i++) {        if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)        && ((mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset) < size)) {            size = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset;        }    }#ifdef MOV_SPLIT_CHUNKS    /* split chunks into samples */    if(mov->streams[st_id]->sample_size == 0) {        int idx;        idx = mov->streams[st_id]->sample_to_chunk_index;        if ((idx + 1 < mov->streams[st_id]->sample_to_chunk_sz)               && (mov->streams[st_id]->next_chunk >= mov->streams[st_id]->sample_to_chunk[idx + 1].first))           idx++;         mov->streams[st_id]->sample_to_chunk_index = idx;        if(idx >= 0 && mov->streams[st_id]->sample_to_chunk[idx].count != 1) {            mov->partial = st_id+1;            /* we'll have to get those samples before next chunk */            mov->streams[st_id]->left_in_chunk = (mov->streams[st_id]->sample_to_chunk[idx].count) - 1;            size = mov->streams[st_id]->sample_sizes[mov->streams[st_id]->current_sample];        }        mov->streams[st_id]->current_sample++;    }#endifreadchunk://printf("chunk: [%i] %lli -> %lli (%i)\n", st_id, offset, offset + size, size);    if(size == 0x0FFFFFFF)        size = mov->mdat_size + mov->mdat_offset - offset;    if(size < 0)        return -1;    if(size == 0)        return -1;    url_fseek(&s->pb, offset, SEEK_SET);    sc = mov->streams[st_id];    if (sc->header_len > 0) {        av_new_packet(pkt, size + sc->header_len);        memcpy(pkt->data, sc->header_data, sc->header_len);        get_buffer(&s->pb, pkt->data + sc->header_len, size);        /* free header */        av_freep(&sc->header_data);        sc->header_len = 0;    } else {        av_new_packet(pkt, size);        get_buffer(&s->pb, pkt->data, pkt->size);    }    pkt->stream_index = sc->ffindex;#ifdef DEBUG/*    printf("Packet (%d, %d, %ld) ", pkt->stream_index, st_id, pkt->size);    for(i=0; i<8; i++)        printf("%02x ", pkt->data[i]);    for(i=0; i<8; i++)        printf("%c ", (pkt->data[i]) & 0x7F);    puts("");*/#endif    mov->next_chunk_offset = offset + size;    return 0;}