]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/flac_parser.c
avfilter/vf_identity: fix typo
[ffmpeg] / libavcodec / flac_parser.c
index 1dcb3ef2db521aabc721bf5d711db87ce3c9ab75..d3d9c889a1c399a6252d7fd998f1480e02554a24 100644 (file)
@@ -113,8 +113,8 @@ static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,
  * This function is based on av_fifo_generic_read, which is why there is a comment
  * about a memory barrier for SMP.
  */
-static uint8_tflac_fifo_read_wrap(FLACParseContext *fpc, int offset, int len,
-                               uint8_t** wrap_buf, int* allocated_size)
+static uint8_t *flac_fifo_read_wrap(FLACParseContext *fpc, int offset, int len,
+                                    uint8_t **wrap_buf, int *allocated_size)
 {
     AVFifoBuffer *f   = fpc->fifo_buf;
     uint8_t *start    = f->rptr + offset;
@@ -153,7 +153,7 @@ static uint8_t* flac_fifo_read_wrap(FLACParseContext *fpc, int offset, int len,
  * A second call to flac_fifo_read (with new offset and len) should be called
  * to get the post-wrap buf if the returned len is less than the requested.
  **/
-static uint8_tflac_fifo_read(FLACParseContext *fpc, int offset, int *len)
+static uint8_t *flac_fifo_read(FLACParseContext *fpc, int offset, int *len)
 {
     AVFifoBuffer *f   = fpc->fifo_buf;
     uint8_t *start    = f->rptr + offset;
@@ -189,8 +189,8 @@ static int find_headers_search_validate(FLACParseContext *fpc, int offset)
                    "couldn't allocate FLACHeaderMarker\n");
             return AVERROR(ENOMEM);
         }
-        (*end_handle)->fi           = fi;
-        (*end_handle)->offset       = offset;
+        (*end_handle)->fi     = fi;
+        (*end_handle)->offset = offset;
 
         for (i = 0; i < FLAC_MAX_SEQUENTIAL_HEADERS; i++)
             (*end_handle)->link_penalty[i] = FLAC_HEADER_NOT_PENALIZED_YET;
@@ -201,24 +201,27 @@ static int find_headers_search_validate(FLACParseContext *fpc, int offset)
     return size;
 }
 
-static int find_headers_search(FLACParseContext *fpc, uint8_t *buf, int buf_size,
-                               int search_start)
-
+static int find_headers_search(FLACParseContext *fpc, uint8_t *buf,
+                               int buf_size, int search_start)
 {
     int size = 0, mod_offset = (buf_size - 1) % 4, i, j;
     uint32_t x;
 
     for (i = 0; i < mod_offset; i++) {
-        if ((AV_RB16(buf + i) & 0xFFFE) == 0xFFF8)
-            size = find_headers_search_validate(fpc, search_start + i);
+        if ((AV_RB16(buf + i) & 0xFFFE) == 0xFFF8) {
+            int ret = find_headers_search_validate(fpc, search_start + i);
+            size = FFMAX(size, ret);
+        }
     }
 
     for (; i < buf_size - 1; i += 4) {
         x = AV_RN32(buf + i);
         if (((x & ~(x + 0x01010101)) & 0x80808080)) {
             for (j = 0; j < 4; j++) {
-                if ((AV_RB16(buf + i + j) & 0xFFFE) == 0xFFF8)
-                    size = find_headers_search_validate(fpc, search_start + i + j);
+                if ((AV_RB16(buf + i + j) & 0xFFFE) == 0xFFF8) {
+                    int ret = find_headers_search_validate(fpc, search_start + i + j);
+                    size = FFMAX(size, ret);
+                }
             }
         }
     }
@@ -314,7 +317,7 @@ static int check_header_mismatch(FLACParseContext  *fpc,
         (child_fi->frame_or_sample_num
          != header_fi->frame_or_sample_num + 1)) {
         FLACHeaderMarker *curr;
-        int expected_frame_num, expected_sample_num;
+        int64_t expected_frame_num, expected_sample_num;
         /* If there are frames in the middle we expect this deduction,
            as they are probably valid and this one follows it */
 
@@ -464,7 +467,7 @@ static void score_sequences(FLACParseContext *fpc)
     }
 }
 
-static int get_best_header(FLACParseContextfpc, const uint8_t **poutbuf,
+static int get_best_header(FLACParseContext *fpc, const uint8_t **poutbuf,
                            int *poutbuf_size)
 {
     FLACHeaderMarker *header = fpc->best_header;
@@ -490,7 +493,7 @@ static int get_best_header(FLACParseContext* fpc, const uint8_t **poutbuf,
                                         &fpc->wrap_buf_allocated_size);
 
 
-    if (fpc->pc->flags & PARSER_FLAG_USE_CODEC_TS){
+    if (fpc->pc->flags & PARSER_FLAG_USE_CODEC_TS) {
         if (header->fi.is_var_size)
           fpc->pc->pts = header->fi.frame_or_sample_num;
         else if (header->best_child)
@@ -524,7 +527,7 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
             s->duration = fi.blocksize;
             if (!avctx->sample_rate)
                 avctx->sample_rate = fi.samplerate;
-            if (fpc->pc->flags & PARSER_FLAG_USE_CODEC_TS){
+            if (fpc->pc->flags & PARSER_FLAG_USE_CODEC_TS) {
                 fpc->pc->pts = fi.frame_or_sample_num;
                 if (!fi.is_var_size)
                   fpc->pc->pts *= fi.blocksize;
@@ -594,8 +597,7 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
 
         /* Pad the end once if EOF, to check the final region for headers. */
         if (!buf_size) {
-            fpc->end_padded      = 1;
-            buf_size = MAX_FRAME_HEADER_SIZE;
+            fpc->end_padded = 1;
             read_end = read_start + MAX_FRAME_HEADER_SIZE;
         } else {
             /* The maximum read size is the upper-bound of what the parser
@@ -668,7 +670,6 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
                 fpc->fifo_buf->wptr += fpc->fifo_buf->end -
                     fpc->fifo_buf->buffer;
             }
-            buf_size = 0;
             read_start = read_end = NULL;
         }
     }
@@ -693,13 +694,13 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
                    fpc->best_header->offset);
 
             /* Set duration to 0. It is unknown or invalid in a junk frame. */
-            s->duration = 0;
-            *poutbuf_size     = fpc->best_header->offset;
-            *poutbuf          = flac_fifo_read_wrap(fpc, 0, *poutbuf_size,
-                                                    &fpc->wrap_buf,
-                                                    &fpc->wrap_buf_allocated_size);
+            s->duration   = 0;
+            *poutbuf_size = fpc->best_header->offset;
+            *poutbuf      = flac_fifo_read_wrap(fpc, 0, *poutbuf_size,
+                                                &fpc->wrap_buf,
+                                                &fpc->wrap_buf_allocated_size);
             return buf_size ? (read_end - buf) : (fpc->best_header->offset -
-                                           av_fifo_size(fpc->fifo_buf));
+                                                  av_fifo_size(fpc->fifo_buf));
         }
         if (!buf_size)
             return get_best_header(fpc, poutbuf, poutbuf_size);
@@ -736,11 +737,12 @@ static void flac_parse_close(AVCodecParserContext *c)
         av_free(curr);
         curr = temp;
     }
+    fpc->headers = NULL;
     av_fifo_freep(&fpc->fifo_buf);
     av_freep(&fpc->wrap_buf);
 }
 
-AVCodecParser ff_flac_parser = {
+const AVCodecParser ff_flac_parser = {
     .codec_ids      = { AV_CODEC_ID_FLAC },
     .priv_data_size = sizeof(FLACParseContext),
     .parser_init    = flac_parse_init,