#undef NDEBUG
#include <assert.h>
+#if FF_API_MAX_STREAMS
+#define NUT_MAX_STREAMS MAX_STREAMS
+#else
+#define NUT_MAX_STREAMS 256 /* arbitrary sanity check value */
+#endif
+
static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){
unsigned int len= ff_get_v(bc);
int64_t size;
// start= url_ftell(bc) - 8;
- startcode= be2me_64(startcode);
+ startcode= av_be2ne64(startcode);
startcode= ff_crc04C11DB7_update(0, (uint8_t*)&startcode, 8);
init_checksum(bc, ff_crc04C11DB7_update, startcode);
end += url_ftell(bc);
GET_V(tmp , tmp >=2 && tmp <= 3)
- GET_V(stream_count , tmp > 0 && tmp <=MAX_STREAMS)
+ GET_V(stream_count , tmp > 0 && tmp <= NUT_MAX_STREAMS)
nut->max_distance = ff_get_v(bc);
if(nut->max_distance > 65536){
GET_V(nut->time_base[i].den, tmp>0 && tmp<(1ULL<<31))
if(av_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){
av_log(s, AV_LOG_ERROR, "time base invalid\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
}
tmp_pts=0;
if(count == 0 || i+count > 256){
av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if(tmp_stream >= stream_count){
av_log(s, AV_LOG_ERROR, "illegal stream number\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
for(j=0; j<count; j++,i++){
rem -= nut->header_len[i];
if(rem < 0){
av_log(s, AV_LOG_ERROR, "invalid elision header\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
nut->header[i]= av_malloc(nut->header_len[i]);
get_buffer(bc, nut->header[i], nut->header_len[i]);
if(skip_reserved(bc, end) || get_checksum(bc)){
av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
nut->stream = av_mallocz(sizeof(StreamContext)*stream_count);
const char *type;
AVChapter *chapter= NULL;
AVStream *st= NULL;
+ AVMetadata **metadata = NULL;
end= get_packetheader(nut, bc, 1, INFO_STARTCODE);
end += url_ftell(bc);
chapter= ff_new_chapter(s, chapter_id,
nut->time_base[chapter_start % nut->time_base_count],
start, start + chapter_len, NULL);
- } else if(stream_id_plus1)
+ metadata = &chapter->metadata;
+ } else if(stream_id_plus1) {
st= s->streams[stream_id_plus1 - 1];
+ metadata = &st->metadata;
+ } else
+ metadata = &s->metadata;
for(i=0; i<count; i++){
get_str(bc, name, sizeof(name));
}
if(!strcmp(type, "UTF-8")){
- AVMetadata **metadata = NULL;
- if(chapter_id==0 && !strcmp(name, "Disposition"))
+ if(chapter_id==0 && !strcmp(name, "Disposition")) {
set_disposition_bits(s, str_value, stream_id_plus1 - 1);
- else if(chapter) metadata= &chapter->metadata;
- else if(stream_id_plus1) metadata= &st->metadata;
- else metadata= &s->metadata;
+ continue;
+ }
if(metadata && strcasecmp(name,"Uses")
&& strcasecmp(name,"Depends") && strcasecmp(name,"Replaces"))
av_metadata_set2(metadata, name, str_value, 0);
pos= find_startcode(bc, MAIN_STARTCODE, pos)+1;
if (pos<0+1){
av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
}while(decode_main_header(nut) < 0);
pos= find_startcode(bc, STREAM_STARTCODE, pos)+1;
if (pos<0+1){
av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if(decode_stream_header(nut) >= 0)
initialized_stream_count++;
if(startcode==0){
av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}else if(startcode == SYNCPOINT_STARTCODE){
nut->next_startcode= startcode;
break;
}
assert(nut->next_startcode == SYNCPOINT_STARTCODE);
+ ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv);
+
return 0;
}
if(url_ftell(bc) > nut->last_syncpoint_pos + nut->max_distance){
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);
- return -1;
+ return AVERROR_INVALIDDATA;
}
flags = nut->frame_code[frame_code].flags;
*header_idx = nut->frame_code[frame_code].header_idx;
if(flags & FLAG_INVALID)
- return -1;
+ return AVERROR_INVALIDDATA;
if(flags & FLAG_CODED)
flags ^= ff_get_v(bc);
if(flags & FLAG_STREAM_ID){
if(*header_idx >= (unsigned)nut->header_count){
av_log(s, AV_LOG_ERROR, "header_idx invalid\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if(size > 4096)
*header_idx=0;
get_be32(bc); //FIXME check this
}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;
+ return AVERROR_INVALIDDATA;
}
stc->last_pts= *pts;
size= decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);
if(size < 0)
- return -1;
+ return size;
stc= &nut->stream[stream_id];
av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
tmp= find_any_startcode(bc, nut->last_syncpoint_pos+1);
if(tmp==0)
- return -1;
+ return AVERROR_INVALIDDATA;
av_log(s, AV_LOG_DEBUG, "sync\n");
nut->next_startcode= tmp;
}
nut_read_close,
read_seek,
.extensions = "nut",
- .metadata_conv = ff_nut_metadata_conv,
.codec_tag = (const AVCodecTag * const []) { ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 },
};
#endif