if (sc->keyframes) { a = 0; b = sc->keyframe_count - 1;  while (a < b) { m = (a + b + 1) >> 1; if (sc->keyframes[m] > sc->current_sample) { b = m - 1; } else { a = m; } }  if (sc->keyframes[a] == sc->current_sample) pkt->flags |= PKT_FLAG_KEY; } else pkt->flags |= PKT_FLAG_KEY;
static int mov_read_packet(AVFormatContext *s, AVPacket *pkt){    MOVContext *mov = (MOVContext *) s->priv_data;    MOVStreamContext *sc;    int64_t offset = 0x0FFFFFFFFFFFFFFFLL;    int i;    int size;    size = 0x0FFFFFFF;#ifdef MOV_SPLIT_CHUNKS    if (mov->partial) {        int idx;	sc = mov->partial;	idx = sc->sample_to_chunk_index;        if (idx < 0) return 0;	size = sc->sample_sizes[sc->current_sample];        sc->current_sample++;        sc->left_in_chunk--;        if (sc->left_in_chunk <= 0)            mov->partial = 0;        offset = mov->next_chunk_offset;        /* extract the sample */        goto readchunk;    }#endifagain:    sc = 0;    for(i=0; i<mov->total_streams; i++) {	MOVStreamContext *msc = mov->streams[i];	//printf("MOCHUNK %ld  %d   %p  pos:%Ld\n", mov->streams[i]->next_chunk, mov->total_streams, mov->streams[i], url_ftell(&s->pb));        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];	    //printf("SELETED  %Ld  i:%d\n", offset, i);        }    }    if (!sc || offset==0x0FFFFFFFFFFFFFFFLL)	return -1;    sc->next_chunk++;    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(!sc->is_ff_stream) {        url_fskip(&s->pb, (offset - mov->next_chunk_offset));        mov->next_chunk_offset = offset;	offset = 0x0FFFFFFFFFFFFFFFLL;        goto again;    }    /* now get the chunk size... */    for(i=0; i<mov->total_streams; i++) {	MOVStreamContext *msc = mov->streams[i];	if ((msc->next_chunk < msc->chunk_count)	    && ((msc->chunk_offsets[msc->next_chunk] - offset) < size))	    size = msc->chunk_offsets[msc->next_chunk] - offset;    }#ifdef MOV_MINOLTA_FIX    //Make sure that size is according to sample_size (Needed by .mov files     //created on a Minolta Dimage Xi where audio chunks contains waste data in the end)    //Maybe we should really not only check sc->sample_size, but also sc->sample_sizes    //but I have no such movies    if (sc->sample_size > 0) {         int foundsize=0;        for(i=0; i<(sc->sample_to_chunk_sz); i++) {            if( (sc->sample_to_chunk[i].first)<=(sc->next_chunk) && (sc->sample_size>0) )            {                foundsize=sc->sample_to_chunk[i].count*sc->sample_size;            }#ifdef DEBUG            /*printf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id);*/#endif        }        if( (foundsize>0) && (foundsize<size) )        {#ifdef DEBUG            /*printf("this size should actually be %d\n",foundsize);*/#endif            size=foundsize;        }    }#endif //MOV_MINOLTA_FIX#ifdef MOV_SPLIT_CHUNKS    /* split chunks into samples */    if (sc->sample_size == 0) {        int idx = sc->sample_to_chunk_index;        if ((idx + 1 < sc->sample_to_chunk_sz)	    && (sc->next_chunk >= sc->sample_to_chunk[idx + 1].first))           idx++;        sc->sample_to_chunk_index = idx;        if (idx >= 0 && sc->sample_to_chunk[idx].count != 1) {	    mov->partial = sc;            /* we'll have to get those samples before next chunk */            sc->left_in_chunk = sc->sample_to_chunk[idx].count - 1;            size = sc->sample_sizes[sc->current_sample];        }        sc->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);    //printf("READCHUNK hlen: %d  %d off: %Ld   pos:%Ld\n", size, sc->header_len, offset, url_ftell(&s->pb));    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;}