42 #define FLAC_MAX_SEQUENTIAL_HEADERS 3
44 #define FLAC_MIN_HEADERS 10
46 #define FLAC_AVG_FRAME_SIZE 8192
49 #define FLAC_HEADER_BASE_SCORE 10
50 #define FLAC_HEADER_CHANGED_PENALTY 7
51 #define FLAC_HEADER_CRC_FAIL_PENALTY 50
52 #define FLAC_HEADER_NOT_PENALIZED_YET 100000
53 #define FLAC_HEADER_NOT_SCORED_YET -100000
56 #define MAX_FRAME_HEADER_SIZE 16
113 uint8_t** wrap_buf,
int* allocated_size)
121 if (f->
end - start >= len)
128 "couldn't reallocate wrap buffer of size %d", len);
133 int seg_len =
FFMIN(f->
end - start, len);
134 memcpy(tmp_buf, start, seg_len);
135 tmp_buf = (
uint8_t*)tmp_buf + seg_len;
177 while (*end_handle) {
178 end_handle = &(*end_handle)->
next;
185 "couldn't allocate FLACHeaderMarker\n");
188 (*end_handle)->fi = fi;
189 (*end_handle)->offset =
offset;
190 (*end_handle)->link_penalty =
av_malloc(
sizeof(
int) *
205 int size = 0, mod_offset = (buf_size - 1) % 4, i, j;
208 for (i = 0; i < mod_offset; i++) {
209 if ((
AV_RB16(buf + i) & 0xFFFE) == 0xFFF8)
213 for (; i < buf_size - 1; i += 4) {
215 if (((x & ~(x + 0x01010101)) & 0x80808080)) {
216 for (j = 0; j < 4; j++) {
217 if ((
AV_RB16(buf + i + j) & 0xFFFE) == 0xFFF8)
228 int search_end,
size = 0, read_len,
temp;
234 read_len = search_end - search_start + 1;
237 search_start += read_len - 1;
240 if (search_start != search_end) {
243 wrap[0] = buf[read_len - 1];
244 read_len = search_end - search_start + 1;
250 if ((
AV_RB16(wrap) & 0xFFFE) == 0xFFF8) {
252 size =
FFMAX(size, temp);
258 size =
FFMAX(size, temp);
259 search_start += read_len - 1;
272 int log_level_offset)
275 int deduction = 0, deduction_expected = 0, i;
276 if (child_fi->samplerate != header_fi->samplerate) {
279 "sample rate change detected in adjacent frames\n");
281 if (child_fi->bps != header_fi->bps) {
284 "bits per sample change detected in adjacent frames\n");
286 if (child_fi->is_var_size != header_fi->
is_var_size) {
290 "blocking strategy change detected in adjacent frames\n");
292 if (child_fi->channels != header_fi->channels) {
295 "number of channels change detected in adjacent frames\n");
300 (child_fi->frame_or_sample_num
303 int expected_frame_num, expected_sample_num;
309 while (curr != child) {
313 expected_frame_num++;
321 if (expected_frame_num == child_fi->frame_or_sample_num ||
322 expected_sample_num == child_fi->frame_or_sample_num)
323 deduction_expected = deduction ? 0 : 1;
327 "sample/frame number mismatch in adjacent frames\n");
331 if (deduction && !deduction_expected) {
336 int inverted_test = 0;
354 while (start->
next != child)
375 if (!crc ^ !inverted_test) {
378 "crc check failed from offset %i (frame %"PRId64
") to %i (frame %"PRId64
")\n",
380 child->
offset, child_fi->frame_or_sample_num);
408 child = header->
next;
438 for (curr = fpc->
headers; curr; curr = curr->
next) {
480 const uint8_t **poutbuf,
int *poutbuf_size,
481 const uint8_t *buf,
int buf_size)
487 const uint8_t *read_start = buf;
494 *poutbuf_size = buf_size;
508 for (curr = fpc->
headers; curr != best_child; curr = temp) {
511 "dropping low score %i frame header from offset %i to %i\n",
523 for (curr = best_child->
next; curr; curr = curr->
next)
553 while ((buf && buf_size && read_end < buf + buf_size &&
555 || ((!buf || !buf_size) && !fpc->
end_padded)) {
559 if (!buf || !buf_size) {
567 read_end = read_end +
FFMIN(buf + buf_size - read_end,
575 "couldn't reallocate buffer of size %td\n",
580 if (buf && buf_size) {
582 read_end - read_start,
NULL);
591 start_offset =
FFMAX(0, start_offset);
594 if (nb_headers < 0) {
596 "find_new_headers couldn't allocate FLAC header\n");
603 if (buf && read_end < buf + buf_size) {
604 read_start = read_end;
626 read_start = read_end =
NULL;
658 return read_end - buf;