2 * "NUT" Container Format demuxer
3 * Copyright (c) 2004-2006 Michael Niedermayer
4 * Copyright (c) 2003 Alex Beregszaszi
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 static uint64_t get_v(ByteIOContext *bc){
36 val= (val<<7) + (tmp&127);
41 static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){
42 unsigned int len= get_v(bc);
45 get_buffer(bc, string, FFMIN(len, maxlen));
52 string[FFMIN(len, maxlen-1)]= 0;
60 static int64_t get_s(ByteIOContext *bc){
61 int64_t v = get_v(bc) + 1;
63 if (v&1) return -(v>>1);
67 static uint64_t get_fourcc(ByteIOContext *bc){
68 unsigned int len= get_v(bc);
70 if (len==2) return get_le16(bc);
71 else if(len==4) return get_le32(bc);
76 static inline uint64_t get_v_trace(ByteIOContext *bc, char *file, char *func, int line){
77 uint64_t v= get_v(bc);
79 av_log(NULL, AV_LOG_DEBUG, "get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
83 static inline int64_t get_s_trace(ByteIOContext *bc, char *file, char *func, int line){
86 av_log(NULL, AV_LOG_DEBUG, "get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
90 static inline uint64_t get_vb_trace(ByteIOContext *bc, char *file, char *func, int line){
91 uint64_t v= get_vb(bc);
93 av_log(NULL, AV_LOG_DEBUG, "get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
96 #define get_v(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
97 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
98 #define get_vb(bc) get_vb_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
101 static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_checksum, uint64_t startcode)
104 // start= url_ftell(bc) - 8;
106 startcode= be2me_64(startcode);
107 startcode= av_crc04C11DB7_update(0, &startcode, 8);
109 init_checksum(bc, av_crc04C11DB7_update, startcode);
113 if(get_checksum(bc) && size > 4096)
116 init_checksum(bc, calculate_checksum ? av_crc04C11DB7_update : NULL, 0);
121 static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){
125 url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream is not seekable, but that should not matter, as in this case we simply start where we are currently
127 while(!url_feof(bc)){
128 state= (state<<8) | get_byte(bc);
129 if((state>>56) != 'N')
133 case STREAM_STARTCODE:
134 case SYNCPOINT_STARTCODE:
136 case INDEX_STARTCODE:
145 * Find the given startcode.
146 * @param code the startcode
147 * @param pos the start position of the search, or -1 if the current position
148 * @returns the position of the startcode or -1 if not found
150 static int64_t find_startcode(ByteIOContext *bc, uint64_t code, int64_t pos){
152 uint64_t startcode= find_any_startcode(bc, pos);
153 if(startcode == code)
154 return url_ftell(bc) - 8;
155 else if(startcode == 0)
161 static int nut_probe(AVProbeData *p){
165 for (i = 0; i < p->buf_size; i++) {
166 code = (code << 8) | p->buf[i];
167 if (code == MAIN_STARTCODE)
168 return AVPROBE_SCORE_MAX;
173 #define GET_V(dst, check) \
176 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp);\
181 static int skip_reserved(ByteIOContext *bc, int64_t pos){
182 pos -= url_ftell(bc);
184 url_fseek(bc, pos, SEEK_CUR);
193 static int decode_main_header(NUTContext *nut){
194 AVFormatContext *s= nut->avf;
195 ByteIOContext *bc = &s->pb;
197 unsigned int stream_count;
198 int i, j, tmp_stream, tmp_mul, tmp_pts, tmp_size, count, tmp_res;
200 end= get_packetheader(nut, bc, 1, MAIN_STARTCODE);
201 end += url_ftell(bc);
203 GET_V(tmp , tmp >=2 && tmp <= 3)
204 GET_V(stream_count , tmp > 0 && tmp <=MAX_STREAMS)
206 nut->max_distance = get_v(bc);
207 if(nut->max_distance > 65536){
208 av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance);
209 nut->max_distance= 65536;
212 GET_V(nut->time_base_count, tmp>0 && tmp<INT_MAX / sizeof(AVRational))
213 nut->time_base= av_malloc(nut->time_base_count * sizeof(AVRational));
215 for(i=0; i<nut->time_base_count; i++){
216 GET_V(nut->time_base[i].num, tmp>0 && tmp<(1ULL<<31))
217 GET_V(nut->time_base[i].den, tmp>0 && tmp<(1ULL<<31))
218 if(ff_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){
219 av_log(s, AV_LOG_ERROR, "time base invalid\n");
227 int tmp_flags = get_v(bc);
228 int tmp_fields= get_v(bc);
229 if(tmp_fields>0) tmp_pts = get_s(bc);
230 if(tmp_fields>1) tmp_mul = get_v(bc);
231 if(tmp_fields>2) tmp_stream= get_v(bc);
232 if(tmp_fields>3) tmp_size = get_v(bc);
234 if(tmp_fields>4) tmp_res = get_v(bc);
236 if(tmp_fields>5) count = get_v(bc);
237 else count = tmp_mul - tmp_size;
239 while(tmp_fields-- > 6)
242 if(count == 0 || i+count > 256){
243 av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
246 if(tmp_stream >= stream_count){
247 av_log(s, AV_LOG_ERROR, "illegal stream number\n");
251 for(j=0; j<count; j++,i++){
253 nut->frame_code[i].flags= FLAG_INVALID;
257 nut->frame_code[i].flags = tmp_flags ;
258 nut->frame_code[i].pts_delta = tmp_pts ;
259 nut->frame_code[i].stream_id = tmp_stream;
260 nut->frame_code[i].size_mul = tmp_mul ;
261 nut->frame_code[i].size_lsb = tmp_size+j;
262 nut->frame_code[i].reserved_count = tmp_res ;
265 assert(nut->frame_code['N'].flags == FLAG_INVALID);
267 if(skip_reserved(bc, end) || get_checksum(bc)){
268 av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
272 nut->stream = av_mallocz(sizeof(StreamContext)*stream_count);
273 for(i=0; i<stream_count; i++){
280 static int decode_stream_header(NUTContext *nut){
281 AVFormatContext *s= nut->avf;
282 ByteIOContext *bc = &s->pb;
284 int class, stream_id;
288 end= get_packetheader(nut, bc, 1, STREAM_STARTCODE);
289 end += url_ftell(bc);
291 GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base);
292 stc= &nut->stream[stream_id];
294 st = s->streams[stream_id];
296 return AVERROR(ENOMEM);
299 tmp = get_fourcc(bc);
300 st->codec->codec_tag= tmp;
304 st->codec->codec_type = CODEC_TYPE_VIDEO;
305 st->codec->codec_id = codec_get_id(codec_bmp_tags, tmp);
306 if (st->codec->codec_id == CODEC_ID_NONE)
307 av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
310 st->codec->codec_type = CODEC_TYPE_AUDIO;
311 st->codec->codec_id = codec_get_id(codec_wav_tags, tmp);
312 if (st->codec->codec_id == CODEC_ID_NONE)
313 av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
316 // st->codec->codec_type = CODEC_TYPE_TEXT;
319 st->codec->codec_type = CODEC_TYPE_DATA;
322 av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class);
325 GET_V(stc->time_base_id , tmp < nut->time_base_count);
326 GET_V(stc->msb_pts_shift , tmp < 16);
327 stc->max_pts_distance= get_v(bc);
328 GET_V(stc->decode_delay , tmp < 1000); //sanity limit, raise this if Moore's law is true
329 st->codec->has_b_frames= stc->decode_delay;
330 get_v(bc); //stream flags
332 GET_V(st->codec->extradata_size, tmp < (1<<30));
333 if(st->codec->extradata_size){
334 st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
335 get_buffer(bc, st->codec->extradata, st->codec->extradata_size);
338 if (st->codec->codec_type == CODEC_TYPE_VIDEO){
339 GET_V(st->codec->width , tmp > 0)
340 GET_V(st->codec->height, tmp > 0)
341 st->codec->sample_aspect_ratio.num= get_v(bc);
342 st->codec->sample_aspect_ratio.den= get_v(bc);
343 if((!st->codec->sample_aspect_ratio.num) != (!st->codec->sample_aspect_ratio.den)){
344 av_log(s, AV_LOG_ERROR, "invalid aspect ratio\n");
347 get_v(bc); /* csp type */
348 }else if (st->codec->codec_type == CODEC_TYPE_AUDIO){
349 GET_V(st->codec->sample_rate , tmp > 0)
350 tmp= get_v(bc); // samplerate_den
351 if(tmp > st->codec->sample_rate){
352 av_log(s, AV_LOG_ERROR, "Bleh, libnut muxed this ;)\n");
353 st->codec->sample_rate= tmp;
355 GET_V(st->codec->channels, tmp > 0)
357 if(skip_reserved(bc, end) || get_checksum(bc)){
358 av_log(s, AV_LOG_ERROR, "stream header %d checksum mismatch\n", stream_id);
361 stc->time_base= &nut->time_base[stc->time_base_id];
362 av_set_pts_info(s->streams[stream_id], 63, stc->time_base->num, stc->time_base->den);
366 static int decode_info_header(NUTContext *nut){
367 AVFormatContext *s= nut->avf;
368 ByteIOContext *bc = &s->pb;
370 unsigned int stream_id_plus1, chapter_start, chapter_len, count;
373 char name[256], str_value[1024], type_str[256], *type= type_str;
375 end= get_packetheader(nut, bc, 1, INFO_STARTCODE);
376 end += url_ftell(bc);
378 GET_V(stream_id_plus1, tmp <= s->nb_streams)
379 chapter_id = get_s(bc);
380 chapter_start= get_v(bc);
381 chapter_len = get_v(bc);
383 for(i=0; i<count; i++){
384 get_str(bc, name, sizeof(name));
388 get_str(bc, str_value, sizeof(str_value));
389 }else if(value == -2){
390 get_str(bc, type, sizeof(type));
391 get_str(bc, str_value, sizeof(str_value));
392 }else if(value == -3){
395 }else if(value == -4){
398 }else if(value < -4){
405 if(chapter_id==0 && !strcmp(type, "UTF-8")){
406 if (!strcmp(name, "Author"))
407 av_strlcpy(s->author , str_value, sizeof(s->author));
408 else if(!strcmp(name, "Title"))
409 av_strlcpy(s->title , str_value, sizeof(s->title));
410 else if(!strcmp(name, "Copyright"))
411 av_strlcpy(s->copyright, str_value, sizeof(s->copyright));
412 else if(!strcmp(name, "Description"))
413 av_strlcpy(s->comment , str_value, sizeof(s->comment));
417 if(skip_reserved(bc, end) || get_checksum(bc)){
418 av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");
424 static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr){
425 AVFormatContext *s= nut->avf;
426 ByteIOContext *bc = &s->pb;
428 AVRational time_base;
430 nut->last_syncpoint_pos= url_ftell(bc)-8;
432 end= get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE);
433 end += url_ftell(bc);
436 *back_ptr= nut->last_syncpoint_pos - 16*get_v(bc);
440 ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count], tmp);
442 if(skip_reserved(bc, end) || get_checksum(bc)){
443 av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
447 *ts= tmp / s->nb_streams * av_q2d(nut->time_base[tmp % s->nb_streams])*AV_TIME_BASE;
448 ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts);
453 static int find_and_decode_index(NUTContext *nut){
454 AVFormatContext *s= nut->avf;
455 ByteIOContext *bc = &s->pb;
457 int i, j, syncpoint_count;
458 int64_t filesize= url_fsize(bc);
460 int8_t *has_keyframe;
462 url_fseek(bc, filesize-12, SEEK_SET);
463 url_fseek(bc, filesize-get_be64(bc), SEEK_SET);
464 if(get_be64(bc) != INDEX_STARTCODE){
465 av_log(s, AV_LOG_ERROR, "no index at the end\n");
469 end= get_packetheader(nut, bc, 1, INDEX_STARTCODE);
470 end += url_ftell(bc);
473 GET_V(syncpoint_count, tmp < INT_MAX/8 && tmp > 0)
474 syncpoints= av_malloc(sizeof(int64_t)*syncpoint_count);
475 has_keyframe= av_malloc(sizeof(int8_t)*(syncpoint_count+1));
476 for(i=0; i<syncpoint_count; i++){
477 GET_V(syncpoints[i], tmp>0)
479 syncpoints[i] += syncpoints[i-1];
482 for(i=0; i<s->nb_streams; i++){
483 int64_t last_pts= -1;
484 for(j=0; j<syncpoint_count;){
485 uint64_t x= get_v(bc);
492 if(n+x >= syncpoint_count + 1){
493 av_log(s, AV_LOG_ERROR, "index overflow A\n");
497 has_keyframe[n++]= flag;
498 has_keyframe[n++]= !flag;
501 if(n>=syncpoint_count + 1){
502 av_log(s, AV_LOG_ERROR, "index overflow B\n");
505 has_keyframe[n++]= x&1;
510 av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
513 assert(n<=syncpoint_count+1);
516 uint64_t B, A= get_v(bc);
520 //eor_pts[j][i] = last_pts + A + B
536 if(skip_reserved(bc, end) || get_checksum(bc)){
537 av_log(s, AV_LOG_ERROR, "index checksum mismatch\n");
543 static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
545 NUTContext *nut = s->priv_data;
546 ByteIOContext *bc = &s->pb;
548 int inited_stream_count;
555 pos= find_startcode(bc, MAIN_STARTCODE, pos)+1;
557 av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
560 }while(decode_main_header(nut) < 0);
564 for(inited_stream_count=0; inited_stream_count < s->nb_streams;){
565 pos= find_startcode(bc, STREAM_STARTCODE, pos)+1;
567 av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
570 if(decode_stream_header(nut) >= 0)
571 inited_stream_count++;
577 uint64_t startcode= find_any_startcode(bc, pos);
581 av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
583 }else if(startcode == SYNCPOINT_STARTCODE){
584 nut->next_startcode= startcode;
586 }else if(startcode != INFO_STARTCODE){
590 decode_info_header(nut);
593 s->data_offset= pos-8;
595 if(!url_is_streamed(bc)){
596 int64_t orig_pos= url_ftell(bc);
597 find_and_decode_index(nut);
598 url_fseek(bc, orig_pos, SEEK_SET);
600 assert(nut->next_startcode == SYNCPOINT_STARTCODE);
605 static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, int frame_code){
606 AVFormatContext *s= nut->avf;
607 ByteIOContext *bc = &s->pb;
609 int size, flags, size_mul, pts_delta, i, reserved_count;
612 if(url_ftell(bc) > nut->last_syncpoint_pos + nut->max_distance){
613 av_log(s, AV_LOG_ERROR, "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n", url_ftell(bc), nut->last_syncpoint_pos, nut->max_distance);
617 flags = nut->frame_code[frame_code].flags;
618 size_mul = nut->frame_code[frame_code].size_mul;
619 size = nut->frame_code[frame_code].size_lsb;
620 *stream_id = nut->frame_code[frame_code].stream_id;
621 pts_delta = nut->frame_code[frame_code].pts_delta;
622 reserved_count = nut->frame_code[frame_code].reserved_count;
624 if(flags & FLAG_INVALID)
626 if(flags & FLAG_CODED)
628 if(flags & FLAG_STREAM_ID){
629 GET_V(*stream_id, tmp < s->nb_streams)
631 stc= &nut->stream[*stream_id];
632 if(flags&FLAG_CODED_PTS){
633 int coded_pts= get_v(bc);
634 //FIXME check last_pts validity?
635 if(coded_pts < (1<<stc->msb_pts_shift)){
636 *pts=ff_lsb2full(stc, coded_pts);
638 *pts=coded_pts - (1<<stc->msb_pts_shift);
640 *pts= stc->last_pts + pts_delta;
641 if(flags&FLAG_SIZE_MSB){
642 size += size_mul*get_v(bc);
644 if(flags&FLAG_RESERVED)
645 reserved_count= get_v(bc);
646 for(i=0; i<reserved_count; i++)
648 if(flags&FLAG_CHECKSUM){
649 get_be32(bc); //FIXME check this
650 }else if(size > 2*nut->max_distance || FFABS(stc->last_pts - *pts) > stc->max_pts_distance){
651 av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n");
656 stc->last_flags= flags;
661 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){
662 AVFormatContext *s= nut->avf;
663 ByteIOContext *bc = &s->pb;
664 int size, stream_id, discard;
665 int64_t pts, last_IP_pts;
668 size= decode_frame_header(nut, &pts, &stream_id, frame_code);
672 stc= &nut->stream[stream_id];
674 if (stc->last_flags & FLAG_KEY)
675 stc->skip_until_key_frame=0;
677 discard= s->streams[ stream_id ]->discard;
678 last_IP_pts= s->streams[ stream_id ]->last_IP_pts;
679 if( (discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY))
680 ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts)
681 || discard >= AVDISCARD_ALL
682 || stc->skip_until_key_frame){
687 av_get_packet(bc, pkt, size);
688 pkt->stream_index = stream_id;
689 if (stc->last_flags & FLAG_KEY)
690 pkt->flags |= PKT_FLAG_KEY;
696 static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
698 NUTContext *nut = s->priv_data;
699 ByteIOContext *bc = &s->pb;
700 int i, frame_code=0, ret, skip;
701 int64_t ts, back_ptr;
704 int64_t pos= url_ftell(bc);
705 uint64_t tmp= nut->next_startcode;
706 nut->next_startcode=0;
711 frame_code = get_byte(bc);
714 if(frame_code == 'N'){
717 tmp = (tmp<<8) + get_byte(bc);
722 case STREAM_STARTCODE:
723 case INDEX_STARTCODE:
724 skip= get_packetheader(nut, bc, 0, tmp);
725 url_fseek(bc, skip, SEEK_CUR);
728 if(decode_info_header(nut)<0)
731 case SYNCPOINT_STARTCODE:
732 if(decode_syncpoint(nut, &ts, &back_ptr)<0)
734 frame_code = get_byte(bc);
736 ret= decode_frame(nut, pkt, frame_code);
739 else if(ret==1) //ok but discard packet
743 av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
744 tmp= find_any_startcode(bc, nut->last_syncpoint_pos+1);
747 av_log(s, AV_LOG_DEBUG, "sync\n");
748 nut->next_startcode= tmp;
753 static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit){
754 NUTContext *nut = s->priv_data;
755 ByteIOContext *bc = &s->pb;
756 int64_t pos, pts, back_ptr;
757 av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n", stream_index, *pos_arg, pos_limit);
762 pos= find_startcode(bc, SYNCPOINT_STARTCODE, pos)+1;
764 assert(nut->next_startcode == 0);
765 av_log(s, AV_LOG_ERROR, "read_timestamp failed.\n");
766 return AV_NOPTS_VALUE;
768 }while(decode_syncpoint(nut, &pts, &back_ptr) < 0);
770 assert(nut->last_syncpoint_pos == *pos_arg);
772 av_log(s, AV_LOG_DEBUG, "return %"PRId64" %"PRId64"\n", pts,back_ptr );
773 if (stream_index == -1) return pts;
774 else if(stream_index == -2) return back_ptr;
779 static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags){
780 NUTContext *nut = s->priv_data;
781 AVStream *st= s->streams[stream_index];
782 syncpoint_t dummy={.ts= pts*av_q2d(st->time_base)*AV_TIME_BASE};
783 syncpoint_t nopts_sp= {.ts= AV_NOPTS_VALUE, .back_ptr= AV_NOPTS_VALUE};
784 syncpoint_t *sp, *next_node[2]= {&nopts_sp, &nopts_sp};
785 int64_t pos, pos2, ts;
788 if(st->index_entries){
789 int index= av_index_search_timestamp(st, pts, flags);
793 pos2= st->index_entries[index].pos;
794 ts = st->index_entries[index].timestamp;
796 av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, next_node);
797 av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos,
798 next_node[0]->ts , next_node[1]->ts);
799 pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos,
800 next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp);
802 if(!(flags & AVSEEK_FLAG_BACKWARD)){
804 next_node[1]= &nopts_sp;
805 av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, next_node);
806 pos2= av_gen_search(s, -2, dummy.pos, next_node[0]->pos , next_node[1]->pos, next_node[1]->pos,
807 next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp);
810 //FIXME dir but i think it does not matter
813 sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL);
816 pos2= sp->back_ptr - 15;
818 av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2);
819 pos= find_startcode(&s->pb, SYNCPOINT_STARTCODE, pos2);
820 url_fseek(&s->pb, pos, SEEK_SET);
821 av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos);
822 if(pos2 > pos || pos2 + 15 < pos){
823 av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n");
825 for(i=0; i<s->nb_streams; i++)
826 nut->stream[i].skip_until_key_frame=1;
831 static int nut_read_close(AVFormatContext *s)
833 NUTContext *nut = s->priv_data;
835 av_freep(&nut->time_base);
836 av_freep(&nut->stream);
841 #ifdef CONFIG_NUT_DEMUXER
842 AVInputFormat nut_demuxer = {