X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmpjpegdec.c;h=c79a39c69d1d0ef427c5fb0daae6b638d8cf18d9;hb=feaec3bc3133ff143b8445c919f2c4c56048fdf9;hp=64d880a9812aac60e881fb7c2a9a2b253bd48127;hpb=fef55251d82ca1043689dddf5d03aa96c75cd4bb;p=ffmpeg diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c index 64d880a9812..c79a39c69d1 100644 --- a/libavformat/mpjpegdec.c +++ b/libavformat/mpjpegdec.c @@ -111,22 +111,18 @@ static int mpjpeg_read_close(AVFormatContext *s) return 0; } -static int mpjpeg_read_probe(AVProbeData *p) +static int mpjpeg_read_probe(const AVProbeData *p) { - AVIOContext *pb; + AVIOContext pb; int ret = 0; int size = 0; if (p->buf_size < 2 || p->buf[0] != '-' || p->buf[1] != '-') return 0; - pb = avio_alloc_context(p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL); - if (!pb) - return 0; - - ret = (parse_multipart_header(pb, &size, "--", NULL) >= 0) ? AVPROBE_SCORE_MAX : 0; + ffio_init_context(&pb, p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL); - avio_context_free(&pb); + ret = (parse_multipart_header(&pb, &size, "--", NULL) >= 0) ? AVPROBE_SCORE_MAX : 0; return ret; } @@ -271,7 +267,7 @@ static char* mpjpeg_get_boundary(AVIOContext* pb) while (av_isspace(*start)) start++; - if (!av_stristart(start, "boundary=", &start)) { + if (av_stristart(start, "boundary=", &start)) { end = strchr(start, ';'); if (end) len = end - start - 1; @@ -306,8 +302,9 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) boundary = mpjpeg_get_boundary(s->pb); } if (boundary != NULL) { - mpjpeg->boundary = boundary; - mpjpeg->searchstr = av_asprintf( "\r\n%s\r\n", boundary ); + mpjpeg->boundary = av_asprintf("--%s", boundary); + mpjpeg->searchstr = av_asprintf("\r\n--%s\r\n", boundary); + av_freep(&boundary); } else { mpjpeg->boundary = av_strdup("--"); mpjpeg->searchstr = av_strdup("\r\n--"); @@ -339,10 +336,8 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->size = 0; pkt->pos = avio_tell(s->pb); - /* we may need to return as much as all we've read back to the buffer */ - ffio_ensure_seekback(s->pb, read_chunk); - - while ((ret = av_append_packet(s->pb, pkt, read_chunk - remaining)) >= 0) { + while ((ret = ffio_ensure_seekback(s->pb, read_chunk - remaining)) >= 0 && /* we may need to return as much as all we've read back to the buffer */ + (ret = av_append_packet(s->pb, pkt, read_chunk - remaining)) >= 0) { /* scan the new data */ char *start;