]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpjpegdec.c
hwcontext_vulkan: dynamically load functions
[ffmpeg] / libavformat / mpjpegdec.c
index c79a39c69d1d0ef427c5fb0daae6b638d8cf18d9..28a24184a27900b124c60fba8be01068ac2227d8 100644 (file)
@@ -328,20 +328,18 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt)
         ret = av_get_packet(s->pb, pkt, size);
     } else {
         /* no size was given -- we read until the next boundary or end-of-file */
-        int remaining = 0, len;
+        int len;
 
         const int read_chunk = 2048;
-        av_init_packet(pkt);
-        pkt->data = NULL;
-        pkt->size = 0;
+
         pkt->pos  = avio_tell(s->pb);
 
-        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) {
+        while ((ret = ffio_ensure_seekback(s->pb, read_chunk)) >= 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)) >= 0) {
             /* scan the new data */
             char *start;
 
-            len = ret + remaining;
+            len = ret;
             start = pkt->data + pkt->size - len;
             do {
                 if (!memcmp(start, mpjpeg->searchstr, mpjpeg->searchstr_len)) {
@@ -353,14 +351,13 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt)
                 len--;
                 start++;
             } while (len >= mpjpeg->searchstr_len);
-            remaining = len;
+            avio_seek(s->pb, -len, SEEK_CUR);
+            pkt->size -= len;
         }
 
         /* error or EOF occurred */
         if (ret == AVERROR_EOF) {
             ret = pkt->size > 0 ? pkt->size : AVERROR_EOF;
-        } else {
-            av_packet_unref(pkt);
         }
     }
 
@@ -383,7 +380,7 @@ static const AVClass mpjpeg_demuxer_class = {
     .version        = LIBAVUTIL_VERSION_INT,
 };
 
-AVInputFormat ff_mpjpeg_demuxer = {
+const AVInputFormat ff_mpjpeg_demuxer = {
     .name              = "mpjpeg",
     .long_name         = NULL_IF_CONFIG_SMALL("MIME multipart JPEG"),
     .mime_type         = "multipart/x-mixed-replace",