X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fnsvdec.c;h=654a968b397edd3cdf0c95a856fb25839807b7cb;hb=90f7e6176938487a77b8b4cdc8b4eaeeaca3e094;hp=aa114db097a632e28c3bfb9918e493c1c9ea6d2a;hpb=6a89b41d9780325ba6d89a37f2aeb925aa68e6a3;p=ffmpeg diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index aa114db097a..654a968b397 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavutil/mathematics.h" #include "avformat.h" #include "internal.h" @@ -186,31 +187,31 @@ typedef struct { } NSVContext; static const AVCodecTag nsv_codec_video_tags[] = { - { CODEC_ID_VP3, MKTAG('V', 'P', '3', ' ') }, - { CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') }, - { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, - { CODEC_ID_VP5, MKTAG('V', 'P', '5', ' ') }, - { CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') }, - { CODEC_ID_VP6, MKTAG('V', 'P', '6', ' ') }, - { CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') }, - { CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') }, - { CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') }, + { AV_CODEC_ID_VP3, MKTAG('V', 'P', '3', ' ') }, + { AV_CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') }, + { AV_CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, + { AV_CODEC_ID_VP5, MKTAG('V', 'P', '5', ' ') }, + { AV_CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') }, + { AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', ' ') }, + { AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') }, + { AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') }, + { AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') }, /* - { CODEC_ID_VP4, MKTAG('V', 'P', '4', ' ') }, - { CODEC_ID_VP4, MKTAG('V', 'P', '4', '0') }, + { AV_CODEC_ID_VP4, MKTAG('V', 'P', '4', ' ') }, + { AV_CODEC_ID_VP4, MKTAG('V', 'P', '4', '0') }, */ - { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') }, /* cf sample xvid decoder from nsv_codec_sdk.zip */ - { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', '3') }, - { CODEC_ID_NONE, 0 }, + { AV_CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') }, /* cf sample xvid decoder from nsv_codec_sdk.zip */ + { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', '3') }, + { AV_CODEC_ID_NONE, 0 }, }; static const AVCodecTag nsv_codec_audio_tags[] = { - { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') }, - { CODEC_ID_AAC, MKTAG('A', 'A', 'C', ' ') }, - { CODEC_ID_AAC, MKTAG('A', 'A', 'C', 'P') }, - { CODEC_ID_SPEEX, MKTAG('S', 'P', 'X', ' ') }, - { CODEC_ID_PCM_U16LE, MKTAG('P', 'C', 'M', ' ') }, - { CODEC_ID_NONE, 0 }, + { AV_CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') }, + { AV_CODEC_ID_AAC, MKTAG('A', 'A', 'C', ' ') }, + { AV_CODEC_ID_AAC, MKTAG('A', 'A', 'C', 'P') }, + { AV_CODEC_ID_SPEEX, MKTAG('S', 'P', 'X', ' ') }, + { AV_CODEC_ID_PCM_U16LE, MKTAG('P', 'C', 'M', ' ') }, + { AV_CODEC_ID_NONE, 0 }, }; //static int nsv_load_index(AVFormatContext *s); @@ -314,7 +315,9 @@ static int nsv_parse_NSVf_header(AVFormatContext *s) char *token, *value; char quote; - p = strings = av_mallocz(strings_size + 1); + p = strings = av_mallocz((size_t)strings_size + 1); + if (!p) + return AVERROR(ENOMEM); endp = strings + strings_size; avio_read(pb, strings, strings_size); while (p < endp) { @@ -349,6 +352,8 @@ static int nsv_parse_NSVf_header(AVFormatContext *s) if((unsigned)table_entries_used >= UINT_MAX / sizeof(uint32_t)) return -1; nsv->nsvs_file_offset = av_malloc((unsigned)table_entries_used * sizeof(uint32_t)); + if (!nsv->nsvs_file_offset) + return AVERROR(ENOMEM); for(i=0;insvs_file_offset[i] = avio_rl32(pb) + size; @@ -356,6 +361,8 @@ static int nsv_parse_NSVf_header(AVFormatContext *s) if(table_entries > table_entries_used && avio_rl32(pb) == MKTAG('T','O','C','2')) { nsv->nsvs_timestamps = av_malloc((unsigned)table_entries_used*sizeof(uint32_t)); + if (!nsv->nsvs_timestamps) + return AVERROR(ENOMEM); for(i=0;insvs_timestamps[i] = avio_rl32(pb); } @@ -526,11 +533,16 @@ static int nsv_read_header(AVFormatContext *s) for (i = 0; i < NSV_MAX_RESYNC_TRIES; i++) { if (nsv_resync(s) < 0) return -1; - if (nsv->state == NSV_FOUND_NSVF) + if (nsv->state == NSV_FOUND_NSVF) { err = nsv_parse_NSVf_header(s); + if (err < 0) + return err; + } /* we need the first NSVs also... */ if (nsv->state == NSV_FOUND_NSVS) { err = nsv_parse_NSVs_header(s); + if (err < 0) + return err; break; /* we just want the first one */ } } @@ -555,7 +567,6 @@ static int nsv_read_chunk(AVFormatContext *s, int fill_header) uint32_t vsize; uint16_t asize; uint16_t auxsize; - uint32_t av_unused auxtag; av_dlog(s, "%s(%d)\n", __FUNCTION__, fill_header); @@ -585,6 +596,7 @@ null_chunk_retry: av_dlog(s, "NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize); /* skip aux stuff */ for (i = 0; i < auxcount; i++) { + uint32_t av_unused auxtag; auxsize = avio_rl16(pb); auxtag = avio_rl32(pb); av_dlog(s, "NSV aux data: '%c%c%c%c', %d bytes\n", @@ -644,7 +656,7 @@ null_chunk_retry: } bps /= channels; // ??? if (bps == 8) - st[NSV_ST_AUDIO]->codec->codec_id = CODEC_ID_PCM_U8; + st[NSV_ST_AUDIO]->codec->codec_id = AV_CODEC_ID_PCM_U8; samplerate /= 4;/* UGH ??? XXX */ channels = 1; st[NSV_ST_AUDIO]->codec->channels = channels; @@ -709,7 +721,9 @@ static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp if(index < 0) return -1; - avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET); + if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + return -1; + nst->frame_offset = st->index_entries[index].timestamp; nsv->state = NSV_UNSYNC; return 0;