#include "libavutil/crc.h"
#include "bytestream.h"
#include "parser.h"
-#include "flac.h"
+#include "flac_parse.h"
/** maximum number of adjacent headers that compare CRCs against each other */
#define FLAC_MAX_SEQUENTIAL_HEADERS 4
int log_level_offset)
{
FLACFrameInfo *header_fi = &header->fi, *child_fi = &child->fi;
- int deduction, deduction_expected = 0, i;
+ int check_crc, deduction, deduction_expected = 0, i;
deduction = check_header_fi_mismatch(fpc, header_fi, child_fi,
log_level_offset);
/* Check sample and frame numbers. */
"sample/frame number mismatch in adjacent frames\n");
}
+ if (fpc->last_fi.is_var_size == header_fi->is_var_size) {
+ if (fpc->last_fi.is_var_size &&
+ fpc->last_fi.frame_or_sample_num + fpc->last_fi.blocksize == header_fi->frame_or_sample_num) {
+ check_crc = 0;
+ } else if (!fpc->last_fi.is_var_size &&
+ fpc->last_fi.frame_or_sample_num + 1 == header_fi->frame_or_sample_num) {
+ check_crc = 0;
+ } else {
+ check_crc = !deduction && !deduction_expected;
+ }
+ } else {
+ check_crc = !deduction && !deduction_expected;
+ }
+
/* If we have suspicious headers, check the CRC between them */
- if (deduction && !deduction_expected) {
+ if (check_crc || (deduction && !deduction_expected)) {
FLACHeaderMarker *curr;
int read_len;
uint8_t *buf;
static void score_sequences(FLACParseContext *fpc)
{
FLACHeaderMarker *curr;
- int best_score = 0;//FLAC_HEADER_NOT_SCORED_YET;
+ int best_score = FLAC_HEADER_NOT_SCORED_YET;
/* First pass to clear all old scores. */
for (curr = fpc->headers; curr; curr = curr->next)
curr->max_score = FLAC_HEADER_NOT_SCORED_YET;
/* Return the negative overread index so the client can compute pos.
This should be the amount overread to the beginning of the child */
- if (child)
- return child->offset - flac_fifo_size(&fpc->fifo_buf);
+ if (child) {
+ int64_t offset = child->offset - flac_fifo_size(&fpc->fifo_buf);
+ if (offset > -(1 << 28))
+ return offset;
+ }
return 0;
}
}
fpc->avctx = avctx;
- if (fpc->best_header_valid)
+ if (fpc->best_header_valid && fpc->nb_headers_buffered >= FLAC_MIN_HEADERS)
return get_best_header(fpc, poutbuf, poutbuf_size);
/* If a best_header was found last call remove it with the buffer data. */