]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/parser.c
avcodec/dxtory: use init_get_bits8()
[ffmpeg] / libavcodec / parser.c
index 2c03b7e5c53c137ad0124620be68da7a4cc6316d..83019e74ebdae0930112c57f312aaa3d77ad0b58 100644 (file)
 #include <stdint.h>
 #include <string.h>
 
+#include "libavutil/avassert.h"
 #include "libavutil/atomic.h"
 #include "libavutil/mem.h"
 
 #include "parser.h"
+#include "internal.h"
 
 static AVCodecParser *av_first_parser = NULL;
 
@@ -163,6 +165,7 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
     /* WARNING: the returned index can be negative */
     index = s->parser->parser_parse(s, avctx, (const uint8_t **) poutbuf,
                                     poutbuf_size, buf, buf_size);
+    av_assert0(index > -0x20000000); // The API does not allow returning AVERROR codes
     /* update the file pointer */
     if (*poutbuf_size) {
         /* fill the data for the current frame */
@@ -306,13 +309,14 @@ void ff_parse_close(AVCodecParserContext *s)
 
 int ff_mpeg4video_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
 {
-    int i;
     uint32_t state = -1;
+    const uint8_t *ptr = buf, *end = buf + buf_size;
 
-    for (i = 0; i < buf_size; i++) {
-        state = state << 8 | buf[i];
+    while (ptr < end) {
+        ptr = avpriv_find_start_code(ptr, end, &state);
         if (state == 0x1B3 || state == 0x1B6)
-            return i - 3;
+            return ptr - 4 - buf;
     }
+
     return 0;
 }