X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fnsvdec.c;h=b79d0dcc62ecb3a09db0e733958d37bca1e78785;hb=bc70684e74a185d7b80c8b80bdedda659cb581b8;hp=92f7d178f68887e4fbee9c77f9a60d32bf07344c;hpb=5ca7eb36b7353f9e6af05a5a952eead5f6d326dd;p=ffmpeg diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index 92f7d178f68..b79d0dcc62e 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -211,6 +211,7 @@ static const AVCodecTag nsv_codec_audio_tags[] = { //static int nsv_load_index(AVFormatContext *s); static int nsv_read_chunk(AVFormatContext *s, int fill_header); +static int nsv_read_close(AVFormatContext *s); /* try to find something we recognize, and set the state accordingly */ static int nsv_resync(AVFormatContext *s) @@ -492,25 +493,32 @@ static int nsv_read_header(AVFormatContext *s) nsv->ahead[0].data = nsv->ahead[1].data = NULL; for (i = 0; i < NSV_MAX_RESYNC_TRIES; i++) { - if (nsv_resync(s) < 0) - return -1; + err = nsv_resync(s); + if (err < 0) + goto fail; if (nsv->state == NSV_FOUND_NSVF) { err = nsv_parse_NSVf_header(s); if (err < 0) - return err; + goto fail; } /* we need the first NSVs also... */ if (nsv->state == NSV_FOUND_NSVS) { err = nsv_parse_NSVs_header(s); if (err < 0) - return err; + goto fail; break; /* we just want the first one */ } } - if (s->nb_streams < 1) /* no luck so far */ - return -1; + if (s->nb_streams < 1) { /* no luck so far */ + err = AVERROR_INVALIDDATA; + goto fail; + } + /* now read the first chunk, so we can attempt to decode more info */ err = nsv_read_chunk(s, 1); +fail: + if (err < 0) + nsv_read_close(s); av_log(s, AV_LOG_TRACE, "parsed header\n"); return err; @@ -654,10 +662,8 @@ static int nsv_read_packet(AVFormatContext *s, AVPacket *pkt) /* now pick one of the plates */ for (i = 0; i < 2; i++) { if (nsv->ahead[i].data) { - /* avoid the cost of new_packet + memcpy(->data) */ - memcpy(pkt, &nsv->ahead[i], sizeof(AVPacket)); - nsv->ahead[i].data = NULL; /* we ate that one */ - return pkt->size; + av_packet_move_ref(pkt, &nsv->ahead[i]); + return 0; } } @@ -676,10 +682,10 @@ static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp if(index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; - nst->frame_offset = st->index_entries[index].timestamp; + nst->frame_offset = st->internal->index_entries[index].timestamp; nsv->state = NSV_UNSYNC; return 0; } @@ -697,7 +703,7 @@ static int nsv_read_close(AVFormatContext *s) return 0; } -static int nsv_probe(AVProbeData *p) +static int nsv_probe(const AVProbeData *p) { int i, score = 0; @@ -728,7 +734,7 @@ static int nsv_probe(AVProbeData *p) return score; } -AVInputFormat ff_nsv_demuxer = { +const AVInputFormat ff_nsv_demuxer = { .name = "nsv", .long_name = NULL_IF_CONFIG_SMALL("Nullsoft Streaming Video"), .priv_data_size = sizeof(NSVContext),