Showing the changes to libavcodec (3 of 3 files). Show all
Unified · Split
| @@ -119,6 +119,7 @@ typedef struct FFV1Context { · 118 unmodified lines | ||
| 119 | 119 | int64_t picture_number; |
| 120 | 120 | int key_frame; |
| 121 | 121 | ProgressFrame picture, last_picture; |
| 122 | + uint32_t crcref; | |
| 122 | 123 | |
| 123 | 124 | const AVFrame *cur_enc_frame; |
| 124 | 125 | int plane_count; |
| @@ -502,15 +502,17 @@ static int read_extra_header(FFV1Context *f) · 501 unmodified lines | ||
| 502 | 502 | |
| 503 | 503 | if (f->version > 2) { |
| 504 | 504 | f->ec = get_symbol(&c, state, 0); |
| 505 | + if (f->ec >= 2) | |
| 506 | + f->crcref = 0x7a8c4079; | |
| 505 | 507 | if (f->micro_version > 2) |
| 506 | 508 | f->intra = get_symbol(&c, state, 0); |
| 507 | 509 | } |
| 508 | 510 | |
| 509 | 511 | if (f->version > 2) { |
| 510 | 512 | unsigned v; |
| 511 | − v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, | |
| 513 | + v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, | |
| 512 | 514 | f->avctx->extradata, f->avctx->extradata_size); |
| 513 | − if (v || f->avctx->extradata_size < 4) { | |
| 515 | + if (v != f->crcref || f->avctx->extradata_size < 4) { | |
| 514 | 516 | av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v); |
| 515 | 517 | return AVERROR_INVALIDDATA; |
| 516 | 518 | } |
| @@ -948,8 +950,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, · 431 unmodified lines | ||
| 948 | 950 | buf_p -= v; |
| 949 | 951 | |
| 950 | 952 | if (f->ec) { |
| 951 | − unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, v); | |
| 952 | − if (crc) { | |
| 953 | + unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, buf_p, v); | |
| 954 | + if (crc != f->crcref) { | |
| 953 | 955 | int64_t ts = avpkt->pts != AV_NOPTS_VALUE ? avpkt->pts : avpkt->dts; |
| 954 | 956 | av_log(f->avctx, AV_LOG_ERROR, "slice CRC mismatch %X!", crc); |
| 955 | 957 | if (ts != AV_NOPTS_VALUE && avctx->pkt_timebase.num) { |
| @@ -458,7 +458,7 @@ static int write_extradata(FFV1Context *f) · 457 unmodified lines | ||
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | f->avctx->extradata_size = ff_rac_terminate(&c, 0); |
| 461 | − v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size); | |
| 461 | + v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, f->avctx->extradata, f->avctx->extradata_size) ^ (f->crcref ? 0x8CD88196 : 0); | |
| 462 | 462 | AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v); |
| 463 | 463 | f->avctx->extradata_size += 4; |
| 464 | 464 | |
| @@ -549,7 +549,13 @@ static av_cold int encode_init(AVCodecContext *avctx) · 84 unmodified lines | ||
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | if (s->ec < 0) { |
| 552 | − s->ec = (s->version >= 3); | |
| 552 | + if (s->version >= 4) { | |
| 553 | + s->ec = 2; | |
| 554 | + s->crcref = 0x7a8c4079; | |
| 555 | + } else if (s->version >= 3) { | |
| 556 | + s->ec = 1; | |
| 557 | + } else | |
| 558 | + s->ec = 0; | |
| 553 | 559 | } |
| 554 | 560 | |
| 555 | 561 | // CRC requires version 3+ |
| @@ -1239,7 +1245,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 683 unmodified lines | ||
| 1239 | 1245 | if (f->ec) { |
| 1240 | 1246 | unsigned v; |
| 1241 | 1247 | buf_p[bytes++] = 0; |
| 1242 | − v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, bytes); | |
| 1248 | + v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, buf_p, bytes) ^ (f->crcref ? 0x8CD88196 : 0); | |
| 1243 | 1249 | AV_WL32(buf_p + bytes, v); |
| 1244 | 1250 | bytes += 4; |
| 1245 | 1251 | } |