Mercurial > libavformat.hg
comparison nutdec.c @ 1501:1d17ea4b6e94 libavformat
seeking with index
author | michael |
---|---|
date | Tue, 14 Nov 2006 13:32:14 +0000 |
parents | 2ac9e4f39a67 |
children | eae8cc31215e |
comparison
equal
deleted
inserted
replaced
1500:2ac9e4f39a67 | 1501:1d17ea4b6e94 |
---|---|
631 decode_info_header(nut); | 631 decode_info_header(nut); |
632 } | 632 } |
633 | 633 |
634 s->data_offset= pos-8; | 634 s->data_offset= pos-8; |
635 | 635 |
636 if(0 &&!url_is_streamed(bc)){ | 636 if(!url_is_streamed(bc)){ |
637 int64_t orig_pos= url_ftell(bc); | 637 int64_t orig_pos= url_ftell(bc); |
638 find_and_decode_index(nut); | 638 find_and_decode_index(nut); |
639 url_fseek(bc, orig_pos, SEEK_SET); | 639 url_fseek(bc, orig_pos, SEEK_SET); |
640 } | 640 } |
641 assert(nut->next_startcode == SYNCPOINT_STARTCODE); | 641 assert(nut->next_startcode == SYNCPOINT_STARTCODE); |
691 } | 691 } |
692 *flags_ret= flags; | 692 *flags_ret= flags; |
693 | 693 |
694 stc->last_pts= *pts; | 694 stc->last_pts= *pts; |
695 stc->last_key_frame= flags&FLAG_KEY; //FIXME change to last flags | 695 stc->last_key_frame= flags&FLAG_KEY; //FIXME change to last flags |
696 | |
697 if(flags&FLAG_KEY){ | |
698 av_add_index_entry( | |
699 s->streams[*stream_id], | |
700 nut->last_syncpoint_pos, | |
701 *pts, | |
702 0, | |
703 0, | |
704 AVINDEX_KEYFRAME); | |
705 } | |
706 | 696 |
707 return size; | 697 return size; |
708 } | 698 } |
709 | 699 |
710 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ | 700 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ |
844 syncpoint_t dummy={.ts= pts*av_q2d(st->time_base)*AV_TIME_BASE}; | 834 syncpoint_t dummy={.ts= pts*av_q2d(st->time_base)*AV_TIME_BASE}; |
845 syncpoint_t nopts_sp= {.ts= AV_NOPTS_VALUE, .back_ptr= AV_NOPTS_VALUE}; | 835 syncpoint_t nopts_sp= {.ts= AV_NOPTS_VALUE, .back_ptr= AV_NOPTS_VALUE}; |
846 syncpoint_t *sp, *next_node[2]= {&nopts_sp, &nopts_sp}; | 836 syncpoint_t *sp, *next_node[2]= {&nopts_sp, &nopts_sp}; |
847 int64_t pos, pos2, ts; | 837 int64_t pos, pos2, ts; |
848 | 838 |
839 if(st->index_entries){ | |
840 int index= av_index_search_timestamp(st, pts, flags); | |
841 if(index<0) | |
842 return -1; | |
843 | |
844 pos2= st->index_entries[index].pos; | |
845 ts = st->index_entries[index].timestamp; | |
846 }else{ | |
849 av_tree_find(nut->syncpoints, &dummy, sp_pts_cmp, next_node); | 847 av_tree_find(nut->syncpoints, &dummy, sp_pts_cmp, next_node); |
850 av_log(s, AV_LOG_DEBUG, "%Ld-%Ld %Ld-%Ld\n", next_node[0]->pos, next_node[1]->pos, | 848 av_log(s, AV_LOG_DEBUG, "%Ld-%Ld %Ld-%Ld\n", next_node[0]->pos, next_node[1]->pos, |
851 next_node[0]->ts , next_node[1]->ts); | 849 next_node[0]->ts , next_node[1]->ts); |
852 pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, | 850 pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, |
853 next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp); | 851 next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp); |
864 } | 862 } |
865 dummy.pos= pos; | 863 dummy.pos= pos; |
866 sp= av_tree_find(nut->syncpoints, &dummy, sp_pos_cmp, NULL); | 864 sp= av_tree_find(nut->syncpoints, &dummy, sp_pos_cmp, NULL); |
867 | 865 |
868 assert(sp); | 866 assert(sp); |
869 | 867 pos2= sp->back_ptr - 15; |
870 av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", sp->back_ptr); | 868 } |
871 pos= find_startcode(&s->pb, SYNCPOINT_STARTCODE, sp->back_ptr - 15); | 869 av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2); |
870 pos= find_startcode(&s->pb, SYNCPOINT_STARTCODE, pos2); | |
872 url_fseek(&s->pb, pos, SEEK_SET); | 871 url_fseek(&s->pb, pos, SEEK_SET); |
873 av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos); | 872 av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos); |
874 if(sp->back_ptr - 15 > pos || sp->back_ptr < pos){ | 873 if(pos2 > pos || pos2 + 15 < pos){ |
875 av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n"); | 874 av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n"); |
876 } | 875 } |
877 return 0; | 876 return 0; |
878 } | 877 } |
879 | 878 |