| @@ -38,8 +38,8 @@ · 37 unmodified lines |
| 38 | #include "itut35.h" | 38 | #include "itut35.h" |
| 39 | #include "hwconfig.h" | 39 | #include "hwconfig.h" |
| 40 | #include "profiles.h" | 40 | #include "profiles.h" |
| | 41 | #include "progressframe.h" |
| 41 | #include "refstruct.h" | 42 | #include "refstruct.h" |
| 42 | #include "thread.h" | | |
| 43 | | 43 | |
| 44 | /**< same with Div_Lut defined in spec 7.11.3.7 */ | 44 | /**< same with Div_Lut defined in spec 7.11.3.7 */ |
| 45 | static const uint16_t div_lut[AV1_DIV_LUT_NUM] = { | 45 | static const uint16_t div_lut[AV1_DIV_LUT_NUM] = { |
| @@ -672,7 +672,7 @@ static int get_pixel_format(AVCodecContext *avctx) · 626 unmodified lines |
| 672 | | 672 | |
| 673 | static void av1_frame_unref(AV1Frame *f) | 673 | static void av1_frame_unref(AV1Frame *f) |
| 674 | { | 674 | { |
| 675 | av_frame_unref(f->f); | 675 | ff_progress_frame_unref(&f->pf); |
| 676 | ff_refstruct_unref(&f->hwaccel_picture_private); | 676 | ff_refstruct_unref(&f->hwaccel_picture_private); |
| 677 | ff_refstruct_unref(&f->header_ref); | 677 | ff_refstruct_unref(&f->header_ref); |
| 678 | f->raw_frame_header = NULL; | 678 | f->raw_frame_header = NULL; |
| @@ -683,20 +683,16 @@ static void av1_frame_unref(AV1Frame *f) · 4 unmodified lines |
| 683 | f->coded_lossless = 0; | 683 | f->coded_lossless = 0; |
| 684 | } | 684 | } |
| 685 | | 685 | |
| 686 | static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src) | 686 | static void av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src) |
| 687 | { | 687 | { |
| 688 | int ret; | | |
| 689 | | | |
| 690 | ff_refstruct_replace(&dst->header_ref, src->header_ref); | 688 | ff_refstruct_replace(&dst->header_ref, src->header_ref); |
| 691 | | 689 | |
| 692 | dst->raw_frame_header = src->raw_frame_header; | 690 | dst->raw_frame_header = src->raw_frame_header; |
| 693 | | 691 | |
| 694 | if (!src->f->buf[0]) | 692 | if (!src->f) |
| 695 | return 0; | 693 | return; |
| 696 | | 694 | |
| 697 | ret = av_frame_ref(dst->f, src->f); | 695 | ff_progress_frame_ref(&dst->pf, &src->pf); |
| 698 | if (ret < 0) | | |
| 699 | goto fail; | | |
| 700 | | 696 | |
| 701 | ff_refstruct_replace(&dst->hwaccel_picture_private, | 697 | ff_refstruct_replace(&dst->hwaccel_picture_private, |
| 702 | src->hwaccel_picture_private); | 698 | src->hwaccel_picture_private); |
| @@ -725,12 +721,6 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s · 22 unmodified lines |
| 725 | sizeof(dst->ref_frame_sign_bias)); | 721 | sizeof(dst->ref_frame_sign_bias)); |
| 726 | memcpy(dst->order_hints, src->order_hints, | 722 | memcpy(dst->order_hints, src->order_hints, |
| 727 | sizeof(dst->order_hints)); | 723 | sizeof(dst->order_hints)); |
| 728 | | | |
| 729 | return 0; | | |
| 730 | | | |
| 731 | fail: | | |
| 732 | av1_frame_unref(dst); | | |
| 733 | return AVERROR(ENOMEM); | | |
| 734 | } | 724 | } |
| 735 | | 725 | |
| 736 | static av_cold int av1_decode_free(AVCodecContext *avctx) | 726 | static av_cold int av1_decode_free(AVCodecContext *avctx) |
| @@ -738,16 +728,9 @@ static av_cold int av1_decode_free(AVCodecContext *avctx) · 1 unmodified line |
| 738 | AV1DecContext *s = avctx->priv_data; | 728 | AV1DecContext *s = avctx->priv_data; |
| 739 | AV1RawMetadataITUTT35 itut_t35; | 729 | AV1RawMetadataITUTT35 itut_t35; |
| 740 | | 730 | |
| 741 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) { | 731 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) |
| 742 | if (s->ref[i].f) { | 732 | av1_frame_unref(&s->ref[i]); |
| 743 | av1_frame_unref(&s->ref[i]); | 733 | av1_frame_unref(&s->cur_frame); |
| 744 | av_frame_free(&s->ref[i].f); | | |
| 745 | } | | |
| 746 | } | | |
| 747 | if (s->cur_frame.f) { | | |
| 748 | av1_frame_unref(&s->cur_frame); | | |
| 749 | av_frame_free(&s->cur_frame.f); | | |
| 750 | } | | |
| 751 | av_buffer_unref(&s->seq_data_ref); | 734 | av_buffer_unref(&s->seq_data_ref); |
| 752 | ff_refstruct_unref(&s->seq_ref); | 735 | ff_refstruct_unref(&s->seq_ref); |
| 753 | ff_refstruct_unref(&s->header_ref); | 736 | ff_refstruct_unref(&s->header_ref); |
| @@ -863,16 +846,6 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) · 109 unmodified lines |
| 863 | s->pkt = avctx->internal->in_pkt; | 846 | s->pkt = avctx->internal->in_pkt; |
| 864 | s->pix_fmt = AV_PIX_FMT_NONE; | 847 | s->pix_fmt = AV_PIX_FMT_NONE; |
| 865 | | 848 | |
| 866 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) { | | |
| 867 | s->ref[i].f = av_frame_alloc(); | | |
| 868 | if (!s->ref[i].f) | | |
| 869 | return AVERROR(ENOMEM); | | |
| 870 | } | | |
| 871 | | | |
| 872 | s->cur_frame.f = av_frame_alloc(); | | |
| 873 | if (!s->cur_frame.f) | | |
| 874 | return AVERROR(ENOMEM); | | |
| 875 | | | |
| 876 | ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx); | 849 | ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx); |
| 877 | if (ret < 0) | 850 | if (ret < 0) |
| 878 | return ret; | 851 | return ret; |
| @@ -934,7 +907,8 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f) · 55 unmodified lines |
| 934 | return ret; | 907 | return ret; |
| 935 | } | 908 | } |
| 936 | | 909 | |
| 937 | if ((ret = ff_thread_get_buffer(avctx, f->f, AV_GET_BUFFER_FLAG_REF)) < 0) | 910 | ret = ff_progress_frame_get_buffer(avctx, &f->pf, AV_GET_BUFFER_FLAG_REF); |
| | 911 | if (ret < 0) |
| 938 | goto fail; | 912 | goto fail; |
| 939 | | 913 | |
| 940 | frame = f->f; | 914 | frame = f->f; |
| @@ -1211,23 +1185,17 @@ FF_ENABLE_DEPRECATION_WARNINGS · 270 unmodified lines |
| 1211 | return 0; | 1185 | return 0; |
| 1212 | } | 1186 | } |
| 1213 | | 1187 | |
| 1214 | static int update_reference_list(AVCodecContext *avctx) | 1188 | static void update_reference_list(AVCodecContext *avctx) |
| 1215 | { | 1189 | { |
| 1216 | AV1DecContext *s = avctx->priv_data; | 1190 | AV1DecContext *s = avctx->priv_data; |
| 1217 | const AV1RawFrameHeader *header = s->raw_frame_header; | 1191 | const AV1RawFrameHeader *header = s->raw_frame_header; |
| 1218 | int ret; | | |
| 1219 | | 1192 | |
| 1220 | for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1193 | for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
| 1221 | if (header->refresh_frame_flags & (1 << i)) { | 1194 | if (header->refresh_frame_flags & (1 << i)) { |
| 1222 | av1_frame_unref(&s->ref[i]); | 1195 | av1_frame_unref(&s->ref[i]); |
| 1223 | if ((ret = av1_frame_ref(avctx, &s->ref[i], &s->cur_frame)) < 0) { | 1196 | av1_frame_ref(avctx, &s->ref[i], &s->cur_frame); |
| 1224 | av_log(avctx, AV_LOG_ERROR, | | |
| 1225 | "Failed to update frame %d in reference list\n", i); | | |
| 1226 | return ret; | | |
| 1227 | } | | |
| 1228 | } | 1197 | } |
| 1229 | } | 1198 | } |
| 1230 | return 0; | | |
| 1231 | } | 1199 | } |
| 1232 | | 1200 | |
| 1233 | static int get_current_frame(AVCodecContext *avctx) | 1201 | static int get_current_frame(AVCodecContext *avctx) |
| @@ -1358,20 +1326,12 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 124 unmodified lines |
| 1358 | if (s->raw_frame_header->show_existing_frame) { | 1326 | if (s->raw_frame_header->show_existing_frame) { |
| 1359 | av1_frame_unref(&s->cur_frame); | 1327 | av1_frame_unref(&s->cur_frame); |
| 1360 | | 1328 | |
| 1361 | ret = av1_frame_ref(avctx, &s->cur_frame, | 1329 | av1_frame_ref(avctx, &s->cur_frame, |
| 1362 | &s->ref[s->raw_frame_header->frame_to_show_map_idx]); | 1330 | &s->ref[s->raw_frame_header->frame_to_show_map_idx]); |
| 1363 | if (ret < 0) { | | |
| 1364 | av_log(avctx, AV_LOG_ERROR, "Failed to get reference frame.\n"); | | |
| 1365 | goto end; | | |
| 1366 | } | | |
| 1367 | | 1331 | |
| 1368 | ret = update_reference_list(avctx); | 1332 | update_reference_list(avctx); |
| 1369 | if (ret < 0) { | | |
| 1370 | av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n"); | | |
| 1371 | goto end; | | |
| 1372 | } | | |
| 1373 | | 1333 | |
| 1374 | if (s->cur_frame.f->buf[0]) { | 1334 | if (s->cur_frame.f) { |
| 1375 | ret = set_output_frame(avctx, frame); | 1335 | ret = set_output_frame(avctx, frame); |
| 1376 | if (ret < 0) | 1336 | if (ret < 0) |
| 1377 | av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n"); | 1337 | av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n"); |
| @@ -1392,7 +1352,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 14 unmodified lines |
| 1392 | s->cur_frame.spatial_id = header->spatial_id; | 1352 | s->cur_frame.spatial_id = header->spatial_id; |
| 1393 | s->cur_frame.temporal_id = header->temporal_id; | 1353 | s->cur_frame.temporal_id = header->temporal_id; |
| 1394 | | 1354 | |
| 1395 | if (avctx->hwaccel && s->cur_frame.f->buf[0]) { | 1355 | if (avctx->hwaccel && s->cur_frame.f) { |
| 1396 | ret = FF_HW_CALL(avctx, start_frame, unit->data, unit->data_size); | 1356 | ret = FF_HW_CALL(avctx, start_frame, unit->data, unit->data_size); |
| 1397 | if (ret < 0) { | 1357 | if (ret < 0) { |
| 1398 | av_log(avctx, AV_LOG_ERROR, "HW accel start frame fail.\n"); | 1358 | av_log(avctx, AV_LOG_ERROR, "HW accel start frame fail.\n"); |
| @@ -1418,7 +1378,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 19 unmodified lines |
| 1418 | if (ret < 0) | 1378 | if (ret < 0) |
| 1419 | goto end; | 1379 | goto end; |
| 1420 | | 1380 | |
| 1421 | if (avctx->hwaccel && s->cur_frame.f->buf[0]) { | 1381 | if (avctx->hwaccel && s->cur_frame.f) { |
| 1422 | ret = FF_HW_CALL(avctx, decode_slice, raw_tile_group->tile_data.data, | 1382 | ret = FF_HW_CALL(avctx, decode_slice, raw_tile_group->tile_data.data, |
| 1423 | raw_tile_group->tile_data.data_size); | 1383 | raw_tile_group->tile_data.data_size); |
| 1424 | if (ret < 0) { | 1384 | if (ret < 0) { |
| @@ -1469,7 +1429,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 44 unmodified lines |
| 1469 | | 1429 | |
| 1470 | if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) { | 1430 | if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) { |
| 1471 | int show_frame = s->raw_frame_header->show_frame; | 1431 | int show_frame = s->raw_frame_header->show_frame; |
| 1472 | if (avctx->hwaccel && s->cur_frame.f->buf[0]) { | 1432 | if (avctx->hwaccel && s->cur_frame.f) { |
| 1473 | ret = FF_HW_SIMPLE_CALL(avctx, end_frame); | 1433 | ret = FF_HW_SIMPLE_CALL(avctx, end_frame); |
| 1474 | if (ret < 0) { | 1434 | if (ret < 0) { |
| 1475 | av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n"); | 1435 | av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n"); |
| @@ -1477,13 +1437,9 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 1 unmodified line |
| 1477 | } | 1437 | } |
| 1478 | } | 1438 | } |
| 1479 | | 1439 | |
| 1480 | ret = update_reference_list(avctx); | 1440 | update_reference_list(avctx); |
| 1481 | if (ret < 0) { | | |
| 1482 | av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n"); | | |
| 1483 | goto end; | | |
| 1484 | } | | |
| 1485 | | 1441 | |
| 1486 | if (s->raw_frame_header->show_frame && s->cur_frame.f->buf[0]) { | 1442 | if (s->raw_frame_header->show_frame && s->cur_frame.f) { |
| 1487 | ret = set_output_frame(avctx, frame); | 1443 | ret = set_output_frame(avctx, frame); |
| 1488 | if (ret < 0) { | 1444 | if (ret < 0) { |
| 1489 | av_log(avctx, AV_LOG_ERROR, "Set output frame error\n"); | 1445 | av_log(avctx, AV_LOG_ERROR, "Set output frame error\n"); |
| @@ -1597,7 +1553,9 @@ const FFCodec ff_av1_decoder = { · 107 unmodified lines |
| 1597 | .close = av1_decode_free, | 1553 | .close = av1_decode_free, |
| 1598 | FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame), | 1554 | FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame), |
| 1599 | .p.capabilities = AV_CODEC_CAP_DR1, | 1555 | .p.capabilities = AV_CODEC_CAP_DR1, |
| 1600 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, | 1556 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | |
| | 1557 | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | |
| | 1558 | FF_CODEC_CAP_USES_PROGRESSFRAMES, |
| 1601 | .flush = av1_decode_flush, | 1559 | .flush = av1_decode_flush, |
| 1602 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), | 1560 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), |
| 1603 | .p.priv_class = &av1_class, | 1561 | .p.priv_class = &av1_class, |