static uint64_t get_v(ByteIOContext *bc){
uint64_t val = 0;
+ int tmp;
- for(;;)
- {
- int tmp = get_byte(bc);
-
- if (tmp&0x80)
- val= (val<<7) + tmp - 0x80;
- else{
- return (val<<7) + tmp;
- }
- }
- return -1;
+ do{
+ tmp = get_byte(bc);
+ val= (val<<7) + (tmp&127);
+ }while(tmp&128);
+ return val;
}
static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){
static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_checksum)
{
- int64_t start, size;
+ int64_t size;
// start= url_ftell(bc) - 8;
size= get_v(bc);
+ if(size > 4096)
+ get_be32(bc); //FIXME check this
init_checksum(bc, calculate_checksum ? av_crc04C11DB7_update : NULL, 0);
-// nut->packet_start[2] = start;
-// nut->written_packet_size= size;
-
return size;
}
return 0;
}
-int sp_pos_cmp(syncpoint_t *a, syncpoint_t *b){
+static int sp_pos_cmp(syncpoint_t *a, syncpoint_t *b){
return (a->pos - b->pos>>32) - (b->pos - a->pos>>32);
}
-int sp_pts_cmp(syncpoint_t *a, syncpoint_t *b){
+static int sp_pts_cmp(syncpoint_t *a, syncpoint_t *b){
return (a->ts - b->ts>>32) - (b->ts - a->ts>>32);
}
return 0;
}
-static int decode_frame_header(NUTContext *nut, int *flags_ret, int64_t *pts, int *stream_id, int frame_code){
+static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, int frame_code){
AVFormatContext *s= nut->avf;
ByteIOContext *bc = &s->pb;
StreamContext *stc;
get_v(bc);
if(flags&FLAG_CHECKSUM){
get_be32(bc); //FIXME check this
- }else if(size > 2*nut->max_distance){
+ }else if(size > 2*nut->max_distance || FFABS(stc->last_pts - *pts) > stc->max_pts_distance){
av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n");
return -1;
}
- *flags_ret= flags;
stc->last_pts= *pts;
- stc->last_key_frame= flags&FLAG_KEY; //FIXME change to last flags
+ stc->last_flags= flags;
return size;
}
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){
AVFormatContext *s= nut->avf;
ByteIOContext *bc = &s->pb;
- int size, stream_id, flags, discard;
+ int size, stream_id, discard;
int64_t pts, last_IP_pts;
+ StreamContext *stc;
- size= decode_frame_header(nut, &flags, &pts, &stream_id, frame_code);
+ size= decode_frame_header(nut, &pts, &stream_id, frame_code);
if(size < 0)
return -1;
- if (flags & FLAG_KEY)
- nut->stream[stream_id].skip_until_key_frame=0;
+ stc= &nut->stream[stream_id];
+
+ if (stc->last_flags & FLAG_KEY)
+ stc->skip_until_key_frame=0;
discard= s->streams[ stream_id ]->discard;
last_IP_pts= s->streams[ stream_id ]->last_IP_pts;
- if( (discard >= AVDISCARD_NONKEY && !(flags & FLAG_KEY))
+ if( (discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY))
||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts)
|| discard >= AVDISCARD_ALL
- || nut->stream[stream_id].skip_until_key_frame){
+ || stc->skip_until_key_frame){
url_fskip(bc, size);
return 1;
}
av_get_packet(bc, pkt, size);
pkt->stream_index = stream_id;
- if (flags & FLAG_KEY)
+ if (stc->last_flags & FLAG_KEY)
pkt->flags |= PKT_FLAG_KEY;
pkt->pts = pts;
uint64_t tmp= nut->next_startcode;
nut->next_startcode=0;
- if (url_feof(bc))
- return -1;
-
if(tmp){
pos-=8;
}else{
frame_code = get_byte(bc);
+ if(url_feof(bc))
+ return -1;
if(frame_code == 'N'){
tmp= frame_code;
for(i=1; i<8; i++)