Avoids allocations and error checks for these allocations; e.g. syncing buffers across threads can't fail any more and needn't be checked. It also gets rid of casts and indirections.
Unified · Split
| @@ -77,15 +77,15 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, · 76 unmodified lines | |||
| 77 | av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); | 77 | av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); |
| 78 | return AVERROR_INVALIDDATA; | 78 | return AVERROR_INVALIDDATA; |
| 79 | } | 79 | } |
| 80 | ps->pps = (HEVCPPS*)ps->pps_list[pps_id]->data; | 80 | ps->pps = ps->pps_list[pps_id]; |
| 81 | 81 | ||
| 82 | if (ps->pps->sps_id >= HEVC_MAX_SPS_COUNT || !ps->sps_list[ps->pps->sps_id]) { | 82 | if (ps->pps->sps_id >= HEVC_MAX_SPS_COUNT || !ps->sps_list[ps->pps->sps_id]) { |
| 83 | av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", ps->pps->sps_id); | 83 | av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", ps->pps->sps_id); |
| 84 | return AVERROR_INVALIDDATA; | 84 | return AVERROR_INVALIDDATA; |
| 85 | } | 85 | } |
| 86 | if (ps->sps != (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data) { | 86 | if (ps->sps != ps->sps_list[ps->pps->sps_id]) { |
| 87 | ps->sps = (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data; | 87 | ps->sps = ps->sps_list[ps->pps->sps_id]; |
| 88 | ps->vps = (HEVCVPS*)ps->vps_list[ps->sps->vps_id]->data; | 88 | ps->vps = ps->vps_list[ps->sps->vps_id]; |
| 89 | } | 89 | } |
| 90 | ow = &ps->sps->output_window; | 90 | ow = &ps->sps->output_window; |
| 91 | 91 | ||
| @@ -28,6 +28,7 @@ · 27 unmodified lines | |||
| 28 | #include "h2645_vui.h" | 28 | #include "h2645_vui.h" |
| 29 | #include "hevc_data.h" | 29 | #include "hevc_data.h" |
| 30 | #include "hevc_ps.h" | 30 | #include "hevc_ps.h" |
| 31 | #include "refstruct.h" | ||
| 31 | 32 | ||
| 32 | static const uint8_t default_scaling_list_intra[] = { | 33 | static const uint8_t default_scaling_list_intra[] = { |
| 33 | 16, 16, 16, 16, 17, 18, 21, 24, | 34 | 16, 16, 16, 16, 17, 18, 21, 24, |
| @@ -61,40 +62,40 @@ static const uint8_t hevc_sub_height_c[] = { · 27 unmodified lines | |||
| 61 | 62 | ||
| 62 | static void remove_pps(HEVCParamSets *s, int id) | 63 | static void remove_pps(HEVCParamSets *s, int id) |
| 63 | { | 64 | { |
| 64 | if (s->pps_list[id] && s->pps == (const HEVCPPS*)s->pps_list[id]->data) | 65 | if (s->pps == s->pps_list[id]) |
| 65 | s->pps = NULL; | 66 | s->pps = NULL; |
| 66 | av_buffer_unref(&s->pps_list[id]); | 67 | ff_refstruct_unref(&s->pps_list[id]); |
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | static void remove_sps(HEVCParamSets *s, int id) | 70 | static void remove_sps(HEVCParamSets *s, int id) |
| 70 | { | 71 | { |
| 71 | int i; | 72 | int i; |
| 72 | if (s->sps_list[id]) { | 73 | if (s->sps_list[id]) { |
| 73 | if (s->sps == (const HEVCSPS*)s->sps_list[id]->data) | 74 | if (s->sps == s->sps_list[id]) |
| 74 | s->sps = NULL; | 75 | s->sps = NULL; |
| 75 | 76 | ||
| 76 | /* drop all PPS that depend on this SPS */ | 77 | /* drop all PPS that depend on this SPS */ |
| 77 | for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) | 78 | for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) |
| 78 | if (s->pps_list[i] && ((HEVCPPS*)s->pps_list[i]->data)->sps_id == id) | 79 | if (s->pps_list[i] && s->pps_list[i]->sps_id == id) |
| 79 | remove_pps(s, i); | 80 | remove_pps(s, i); |
| 80 | 81 | ||
| 81 | av_assert0(!(s->sps_list[id] && s->sps == (HEVCSPS*)s->sps_list[id]->data)); | 82 | av_assert0(!(s->sps_list[id] && s->sps == s->sps_list[id])); |
| 83 | ff_refstruct_unref(&s->sps_list[id]); | ||
| 82 | } | 84 | } |
| 83 | av_buffer_unref(&s->sps_list[id]); | ||
| 84 | } | 85 | } |
| 85 | 86 | ||
| 86 | static void remove_vps(HEVCParamSets *s, int id) | 87 | static void remove_vps(HEVCParamSets *s, int id) |
| 87 | { | 88 | { |
| 88 | int i; | 89 | int i; |
| 89 | if (s->vps_list[id]) { | 90 | if (s->vps_list[id]) { |
| 90 | if (s->vps == (const HEVCVPS*)s->vps_list[id]->data) | 91 | if (s->vps == s->vps_list[id]) |
| 91 | s->vps = NULL; | 92 | s->vps = NULL; |
| 92 | 93 | ||
| 93 | for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) | 94 | for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) |
| 94 | if (s->sps_list[i] && ((HEVCSPS*)s->sps_list[i]->data)->vps_id == id) | 95 | if (s->sps_list[i] && s->sps_list[i]->vps_id == id) |
| 95 | remove_sps(s, i); | 96 | remove_sps(s, i); |
| 97 | ff_refstruct_unref(&s->vps_list[id]); | ||
| 96 | } | 98 | } |
| 97 | av_buffer_unref(&s->vps_list[id]); | ||
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, | 101 | int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, |
| @@ -442,12 +443,10 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, · 341 unmodified lines | |||
| 442 | int i,j; | 443 | int i,j; |
| 443 | int vps_id = 0; | 444 | int vps_id = 0; |
| 444 | ptrdiff_t nal_size; | 445 | ptrdiff_t nal_size; |
| 445 | HEVCVPS *vps; | 446 | HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps)); |
| 446 | AVBufferRef *vps_buf = av_buffer_allocz(sizeof(*vps)); | ||
| 447 | 447 | ||
| 448 | if (!vps_buf) | 448 | if (!vps) |
| 449 | return AVERROR(ENOMEM); | 449 | return AVERROR(ENOMEM); |
| 450 | vps = (HEVCVPS*)vps_buf->data; | ||
| 451 | 450 | ||
| 452 | av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n"); | 451 | av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n"); |
| 453 | 452 | ||
| @@ -553,17 +552,17 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, · 99 unmodified lines | |||
| 553 | } | 552 | } |
| 554 | 553 | ||
| 555 | if (ps->vps_list[vps_id] && | 554 | if (ps->vps_list[vps_id] && |
| 556 | !memcmp(ps->vps_list[vps_id]->data, vps_buf->data, vps_buf->size)) { | 555 | !memcmp(ps->vps_list[vps_id], vps, sizeof(*vps))) { |
| 557 | av_buffer_unref(&vps_buf); | 556 | ff_refstruct_unref(&vps); |
| 558 | } else { | 557 | } else { |
| 559 | remove_vps(ps, vps_id); | 558 | remove_vps(ps, vps_id); |
| 560 | ps->vps_list[vps_id] = vps_buf; | 559 | ps->vps_list[vps_id] = vps; |
| 561 | } | 560 | } |
| 562 | 561 | ||
| 563 | return 0; | 562 | return 0; |
| 564 | 563 | ||
| 565 | err: | 564 | err: |
| 566 | av_buffer_unref(&vps_buf); | 565 | ff_refstruct_unref(&vps); |
| 567 | return AVERROR_INVALIDDATA; | 566 | return AVERROR_INVALIDDATA; |
| 568 | } | 567 | } |
| 569 | 568 | ||
| @@ -851,7 +850,8 @@ static int map_pixel_format(AVCodecContext *avctx, HEVCSPS *sps) · 281 unmodified lines | |||
| 851 | } | 850 | } |
| 852 | 851 | ||
| 853 | int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, | 852 | int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, |
| 854 | int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx) | 853 | int apply_defdispwin, const HEVCVPS * const *vps_list, |
| 854 | AVCodecContext *avctx) | ||
| 855 | { | 855 | { |
| 856 | HEVCWindow *ow; | 856 | HEVCWindow *ow; |
| 857 | int ret = 0; | 857 | int ret = 0; |
| @@ -1269,15 +1269,13 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, · 411 unmodified lines | |||
| 1269 | int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, | 1269 | int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, |
| 1270 | HEVCParamSets *ps, int apply_defdispwin) | 1270 | HEVCParamSets *ps, int apply_defdispwin) |
| 1271 | { | 1271 | { |
| 1272 | HEVCSPS *sps; | 1272 | HEVCSPS *sps = ff_refstruct_allocz(sizeof(*sps)); |
| 1273 | AVBufferRef *sps_buf = av_buffer_allocz(sizeof(*sps)); | ||
| 1274 | unsigned int sps_id; | 1273 | unsigned int sps_id; |
| 1275 | int ret; | 1274 | int ret; |
| 1276 | ptrdiff_t nal_size; | 1275 | ptrdiff_t nal_size; |
| 1277 | 1276 | ||
| 1278 | if (!sps_buf) | 1277 | if (!sps) |
| 1279 | return AVERROR(ENOMEM); | 1278 | return AVERROR(ENOMEM); |
| 1280 | sps = (HEVCSPS*)sps_buf->data; | ||
| 1281 | 1279 | ||
| 1282 | av_log(avctx, AV_LOG_DEBUG, "Decoding SPS\n"); | 1280 | av_log(avctx, AV_LOG_DEBUG, "Decoding SPS\n"); |
| 1283 | 1281 | ||
| @@ -1296,7 +1294,7 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, · 12 unmodified lines | |||
| 1296 | apply_defdispwin, | 1294 | apply_defdispwin, |
| 1297 | ps->vps_list, avctx); | 1295 | ps->vps_list, avctx); |
| 1298 | if (ret < 0) { | 1296 | if (ret < 0) { |
| 1299 | av_buffer_unref(&sps_buf); | 1297 | ff_refstruct_unref(&sps); |
| 1300 | return ret; | 1298 | return ret; |
| 1301 | } | 1299 | } |
| 1302 | 1300 | ||
| @@ -1314,19 +1312,19 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, · 11 unmodified lines | |||
| 1314 | * original one. | 1312 | * original one. |
| 1315 | * otherwise drop all PPSes that depend on it */ | 1313 | * otherwise drop all PPSes that depend on it */ |
| 1316 | if (ps->sps_list[sps_id] && | 1314 | if (ps->sps_list[sps_id] && |
| 1317 | !memcmp(ps->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) { | 1315 | !memcmp(ps->sps_list[sps_id], sps, sizeof(*sps))) { |
| 1318 | av_buffer_unref(&sps_buf); | 1316 | ff_refstruct_unref(&sps); |
| 1319 | } else { | 1317 | } else { |
| 1320 | remove_sps(ps, sps_id); | 1318 | remove_sps(ps, sps_id); |
| 1321 | ps->sps_list[sps_id] = sps_buf; | 1319 | ps->sps_list[sps_id] = sps; |
| 1322 | } | 1320 | } |
| 1323 | 1321 | ||
| 1324 | return 0; | 1322 | return 0; |
| 1325 | } | 1323 | } |
| 1326 | 1324 | ||
| 1327 | static void hevc_pps_free(void *opaque, uint8_t *data) | 1325 | static void hevc_pps_free(FFRefStructOpaque unused, void *obj) |
| 1328 | { | 1326 | { |
| 1329 | HEVCPPS *pps = (HEVCPPS*)data; | 1327 | HEVCPPS *pps = obj; |
| 1330 | 1328 | ||
| 1331 | av_freep(&pps->column_width); | 1329 | av_freep(&pps->column_width); |
| 1332 | av_freep(&pps->row_height); | 1330 | av_freep(&pps->row_height); |
| @@ -1338,8 +1336,6 @@ static void hevc_pps_free(void *opaque, uint8_t *data) · 5 unmodified lines | |||
| 1338 | av_freep(&pps->tile_pos_rs); | 1336 | av_freep(&pps->tile_pos_rs); |
| 1339 | av_freep(&pps->tile_id); | 1337 | av_freep(&pps->tile_id); |
| 1340 | av_freep(&pps->min_tb_addr_zs_tab); | 1338 | av_freep(&pps->min_tb_addr_zs_tab); |
| 1341 | |||
| 1342 | av_freep(&pps); | ||
| 1343 | } | 1339 | } |
| 1344 | 1340 | ||
| 1345 | static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_depth, | 1341 | static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_depth, |
| @@ -1742,19 +1738,11 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, · 396 unmodified lines | |||
| 1742 | ptrdiff_t nal_size; | 1738 | ptrdiff_t nal_size; |
| 1743 | unsigned log2_parallel_merge_level_minus2; | 1739 | unsigned log2_parallel_merge_level_minus2; |
| 1744 | 1740 | ||
| 1745 | AVBufferRef *pps_buf; | 1741 | HEVCPPS *pps = ff_refstruct_alloc_ext(sizeof(*pps), 0, NULL, hevc_pps_free); |
| 1746 | HEVCPPS *pps = av_mallocz(sizeof(*pps)); | ||
| 1747 | 1742 | ||
| 1748 | if (!pps) | 1743 | if (!pps) |
| 1749 | return AVERROR(ENOMEM); | 1744 | return AVERROR(ENOMEM); |
| 1750 | 1745 | ||
| 1751 | pps_buf = av_buffer_create((uint8_t *)pps, sizeof(*pps), | ||
| 1752 | hevc_pps_free, NULL, 0); | ||
| 1753 | if (!pps_buf) { | ||
| 1754 | av_freep(&pps); | ||
| 1755 | return AVERROR(ENOMEM); | ||
| 1756 | } | ||
| 1757 | |||
| 1758 | av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n"); | 1746 | av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n"); |
| 1759 | 1747 | ||
| 1760 | nal_size = gb->buffer_end - gb->buffer; | 1748 | nal_size = gb->buffer_end - gb->buffer; |
| @@ -1796,8 +1784,8 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, · 35 unmodified lines | |||
| 1796 | ret = AVERROR_INVALIDDATA; | 1784 | ret = AVERROR_INVALIDDATA; |
| 1797 | goto err; | 1785 | goto err; |
| 1798 | } | 1786 | } |
| 1799 | sps = (HEVCSPS *)ps->sps_list[pps->sps_id]->data; | 1787 | sps = ps->sps_list[pps->sps_id]; |
| 1800 | vps = (HEVCVPS *)ps->vps_list[sps->vps_id]->data; | 1788 | vps = ps->vps_list[sps->vps_id]; |
| 1801 | 1789 | ||
| 1802 | pps->dependent_slice_segments_enabled_flag = get_bits1(gb); | 1790 | pps->dependent_slice_segments_enabled_flag = get_bits1(gb); |
| 1803 | pps->output_flag_present_flag = get_bits1(gb); | 1791 | pps->output_flag_present_flag = get_bits1(gb); |
| @@ -1998,12 +1986,12 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, · 194 unmodified lines | |||
| 1998 | } | 1986 | } |
| 1999 | 1987 | ||
| 2000 | remove_pps(ps, pps_id); | 1988 | remove_pps(ps, pps_id); |
| 2001 | ps->pps_list[pps_id] = pps_buf; | 1989 | ps->pps_list[pps_id] = pps; |
| 2002 | 1990 | ||
| 2003 | return 0; | 1991 | return 0; |
| 2004 | 1992 | ||
| 2005 | err: | 1993 | err: |
| 2006 | av_buffer_unref(&pps_buf); | 1994 | ff_refstruct_unref(&pps); |
| 2007 | return ret; | 1995 | return ret; |
| 2008 | } | 1996 | } |
| 2009 | 1997 | ||
| @@ -2012,11 +2000,11 @@ void ff_hevc_ps_uninit(HEVCParamSets *ps) · 2 unmodified lines | |||
| 2012 | int i; | 2000 | int i; |
| 2013 | 2001 | ||
| 2014 | for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++) | 2002 | for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++) |
| 2015 | av_buffer_unref(&ps->vps_list[i]); | 2003 | ff_refstruct_unref(&ps->vps_list[i]); |
| 2016 | for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++) | 2004 | for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++) |
| 2017 | av_buffer_unref(&ps->sps_list[i]); | 2005 | ff_refstruct_unref(&ps->sps_list[i]); |
| 2018 | for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) | 2006 | for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) |
| 2019 | av_buffer_unref(&ps->pps_list[i]); | 2007 | ff_refstruct_unref(&ps->pps_list[i]); |
| 2020 | 2008 | ||
| 2021 | ps->sps = NULL; | 2009 | ps->sps = NULL; |
| 2022 | ps->pps = NULL; | 2010 | ps->pps = NULL; |
| @@ -23,7 +23,6 @@ · 22 unmodified lines | |||
| 23 | 23 | ||
| 24 | #include <stdint.h> | 24 | #include <stdint.h> |
| 25 | 25 | ||
| 26 | #include "libavutil/buffer.h" | ||
| 27 | #include "libavutil/pixfmt.h" | 26 | #include "libavutil/pixfmt.h" |
| 28 | #include "libavutil/rational.h" | 27 | #include "libavutil/rational.h" |
| 29 | 28 | ||
| @@ -437,9 +436,9 @@ typedef struct HEVCPPS { · 407 unmodified lines | |||
| 437 | } HEVCPPS; | 436 | } HEVCPPS; |
| 438 | 437 | ||
| 439 | typedef struct HEVCParamSets { | 438 | typedef struct HEVCParamSets { |
| 440 | AVBufferRef *vps_list[HEVC_MAX_VPS_COUNT]; | 439 | const HEVCVPS *vps_list[HEVC_MAX_VPS_COUNT]; ///< RefStruct references |
| 441 | AVBufferRef *sps_list[HEVC_MAX_SPS_COUNT]; | 440 | const HEVCSPS *sps_list[HEVC_MAX_SPS_COUNT]; ///< RefStruct references |
| 442 | AVBufferRef *pps_list[HEVC_MAX_PPS_COUNT]; | 441 | const HEVCPPS *pps_list[HEVC_MAX_PPS_COUNT]; ///< RefStruct references |
| 443 | 442 | ||
| 444 | /* currently active parameter sets */ | 443 | /* currently active parameter sets */ |
| 445 | const HEVCVPS *vps; | 444 | const HEVCVPS *vps; |
| @@ -457,7 +456,8 @@ typedef struct HEVCParamSets { · 11 unmodified lines | |||
| 457 | * to an existing VPS | 456 | * to an existing VPS |
| 458 | */ | 457 | */ |
| 459 | int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, | 458 | int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, |
| 460 | int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx); | 459 | int apply_defdispwin, const HEVCVPS * const *vps_list, |
| 460 | AVCodecContext *avctx); | ||
| 461 | 461 | ||
| 462 | int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, | 462 | int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, |
| 463 | HEVCParamSets *ps); | 463 | HEVCParamSets *ps); |
| @@ -53,11 +53,10 @@ static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, · 52 unmodified lines | |||
| 53 | const HEVCParamSets *ps, void *logctx) | 53 | const HEVCParamSets *ps, void *logctx) |
| 54 | { | 54 | { |
| 55 | HEVCSEIPictureTiming *h = &s->picture_timing; | 55 | HEVCSEIPictureTiming *h = &s->picture_timing; |
| 56 | HEVCSPS *sps; | 56 | const HEVCSPS *sps = ps->sps_list[s->active_seq_parameter_set_id]; |
| 57 | 57 | ||
| 58 | if (!ps->sps_list[s->active_seq_parameter_set_id]) | 58 | if (!sps) |
| 59 | return(AVERROR(ENOMEM)); | 59 | return(AVERROR(ENOMEM)); |
| 60 | sps = (HEVCSPS*)ps->sps_list[s->active_seq_parameter_set_id]->data; | ||
| 61 | 60 | ||
| 62 | if (sps->vui.frame_field_info_present_flag) { | 61 | if (sps->vui.frame_field_info_present_flag) { |
| 63 | int pic_struct = get_bits(gb, 4); | 62 | int pic_struct = get_bits(gb, 4); |
| @@ -50,6 +50,7 @@ · 49 unmodified lines | |||
| 50 | #include "hwconfig.h" | 50 | #include "hwconfig.h" |
| 51 | #include "internal.h" | 51 | #include "internal.h" |
| 52 | #include "profiles.h" | 52 | #include "profiles.h" |
| 53 | #include "refstruct.h" | ||
| 53 | #include "thread.h" | 54 | #include "thread.h" |
| 54 | #include "threadframe.h" | 55 | #include "threadframe.h" |
| 55 | 56 | ||
| @@ -326,7 +327,7 @@ static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) · 270 unmodified lines | |||
| 326 | { | 327 | { |
| 327 | AVCodecContext *avctx = s->avctx; | 328 | AVCodecContext *avctx = s->avctx; |
| 328 | const HEVCParamSets *ps = &s->ps; | 329 | const HEVCParamSets *ps = &s->ps; |
| 329 | const HEVCVPS *vps = (const HEVCVPS*)ps->vps_list[sps->vps_id]->data; | 330 | const HEVCVPS *vps = ps->vps_list[sps->vps_id]; |
| 330 | const HEVCWindow *ow = &sps->output_window; | 331 | const HEVCWindow *ow = &sps->output_window; |
| 331 | unsigned int num = 0, den = 0; | 332 | unsigned int num = 0, den = 0; |
| 332 | 333 | ||
| @@ -573,7 +574,7 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps, · 240 unmodified lines | |||
| 573 | } | 574 | } |
| 574 | 575 | ||
| 575 | s->ps.sps = sps; | 576 | s->ps.sps = sps; |
| 576 | s->ps.vps = (HEVCVPS*) s->ps.vps_list[s->ps.sps->vps_id]->data; | 577 | s->ps.vps = s->ps.vps_list[s->ps.sps->vps_id]; |
| 577 | 578 | ||
| 578 | return 0; | 579 | return 0; |
| 579 | 580 | ||
| @@ -616,16 +617,16 @@ static int hls_slice_header(HEVCContext *s) · 36 unmodified lines | |||
| 616 | return AVERROR_INVALIDDATA; | 617 | return AVERROR_INVALIDDATA; |
| 617 | } | 618 | } |
| 618 | if (!sh->first_slice_in_pic_flag && | 619 | if (!sh->first_slice_in_pic_flag && |
| 619 | s->ps.pps != (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data) { | 620 | s->ps.pps != s->ps.pps_list[sh->pps_id]) { |
| 620 | av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); | 621 | av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); |
| 621 | return AVERROR_INVALIDDATA; | 622 | return AVERROR_INVALIDDATA; |
| 622 | } | 623 | } |
| 623 | s->ps.pps = (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data; | 624 | s->ps.pps = s->ps.pps_list[sh->pps_id]; |
| 624 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) | 625 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) |
| 625 | sh->no_output_of_prior_pics_flag = 1; | 626 | sh->no_output_of_prior_pics_flag = 1; |
| 626 | 627 | ||
| 627 | if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) { | 628 | if (s->ps.sps != s->ps.sps_list[s->ps.pps->sps_id]) { |
| 628 | const HEVCSPS *sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data; | 629 | const HEVCSPS *sps = s->ps.sps_list[s->ps.pps->sps_id]; |
| 629 | enum AVPixelFormat pix_fmt; | 630 | enum AVPixelFormat pix_fmt; |
| 630 | 631 | ||
| 631 | ff_hevc_clear_refs(s); | 632 | ff_hevc_clear_refs(s); |
| @@ -3304,7 +3305,7 @@ static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int f · 2672 unmodified lines | |||
| 3304 | /* export stream parameters from the first SPS */ | 3305 | /* export stream parameters from the first SPS */ |
| 3305 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { | 3306 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { |
| 3306 | if (first && s->ps.sps_list[i]) { | 3307 | if (first && s->ps.sps_list[i]) { |
| 3307 | const HEVCSPS *sps = (const HEVCSPS*)s->ps.sps_list[i]->data; | 3308 | const HEVCSPS *sps = s->ps.sps_list[i]; |
| 3308 | export_stream_params(s, sps); | 3309 | export_stream_params(s, sps); |
| 3309 | break; | 3310 | break; |
| 3310 | } | 3311 | } |
| @@ -3549,23 +3550,14 @@ static int hevc_update_thread_context(AVCodecContext *dst, · 238 unmodified lines | |||
| 3549 | 3550 | ||
| 3550 | if (s->ps.sps != s0->ps.sps) | 3551 | if (s->ps.sps != s0->ps.sps) |
| 3551 | s->ps.sps = NULL; | 3552 | s->ps.sps = NULL; |
| 3552 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) { | 3553 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) |
| 3553 | ret = av_buffer_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); | 3554 | ff_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); |
| 3554 | if (ret < 0) | ||
| 3555 | return ret; | ||
| 3556 | } | ||
| 3557 | 3555 | ||
| 3558 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { | 3556 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) |
| 3559 | ret = av_buffer_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); | 3557 | ff_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); |
| 3560 | if (ret < 0) | ||
| 3561 | return ret; | ||
| 3562 | } | ||
| 3563 | 3558 | ||
| 3564 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) { | 3559 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) |
| 3565 | ret = av_buffer_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); | 3560 | ff_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); |
| 3566 | if (ret < 0) | ||
| 3567 | return ret; | ||
| 3568 | } | ||
| 3569 | 3561 | ||
| 3570 | if (s->ps.sps != s0->ps.sps) | 3562 | if (s->ps.sps != s0->ps.sps) |
| 3571 | if ((ret = set_sps(s, s0->ps.sps, src->pix_fmt)) < 0) | 3563 | if ((ret = set_sps(s, s0->ps.sps, src->pix_fmt)) < 0) |
| @@ -223,21 +223,21 @@ static int hevc_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format) · 222 unmodified lines | |||
| 223 | 223 | ||
| 224 | for (i = 0; i < HEVC_MAX_VPS_COUNT; i++) { | 224 | for (i = 0; i < HEVC_MAX_VPS_COUNT; i++) { |
| 225 | if (ps.vps_list[i]) { | 225 | if (ps.vps_list[i]) { |
| 226 | vps = (const HEVCVPS*)ps.vps_list[i]->data; | 226 | vps = ps.vps_list[i]; |
| 227 | break; | 227 | break; |
| 228 | } | 228 | } |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | for (i = 0; i < HEVC_MAX_PPS_COUNT; i++) { | 231 | for (i = 0; i < HEVC_MAX_PPS_COUNT; i++) { |
| 232 | if (ps.pps_list[i]) { | 232 | if (ps.pps_list[i]) { |
| 233 | pps = (const HEVCPPS*)ps.pps_list[i]->data; | 233 | pps = ps.pps_list[i]; |
| 234 | break; | 234 | break; |
| 235 | } | 235 | } |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | if (pps) { | 238 | if (pps) { |
| 239 | if (ps.sps_list[pps->sps_id]) { | 239 | if (ps.sps_list[pps->sps_id]) { |
| 240 | sps = (const HEVCSPS*)ps.sps_list[pps->sps_id]->data; | 240 | sps = ps.sps_list[pps->sps_id]; |
| 241 | } | 241 | } |
| 242 | } | 242 | } |
| 243 | 243 | ||
| @@ -246,7 +246,7 @@ CFDataRef ff_videotoolbox_hvcc_extradata_create(AVCodecContext *avctx) · 245 unmodified lines | |||
| 246 | #define COUNT_SIZE_PS(T, t) \ | 246 | #define COUNT_SIZE_PS(T, t) \ |
| 247 | for (i = 0; i < HEVC_MAX_##T##PS_COUNT; i++) { \ | 247 | for (i = 0; i < HEVC_MAX_##T##PS_COUNT; i++) { \ |
| 248 | if (h->ps.t##ps_list[i]) { \ | 248 | if (h->ps.t##ps_list[i]) { \ |
| 249 | const HEVC##T##PS *lps = (const HEVC##T##PS *)h->ps.t##ps_list[i]->data; \ | 249 | const HEVC##T##PS *lps = h->ps.t##ps_list[i]; \ |
| 250 | vt_extradata_size += 2 + escape_ps(NULL, lps->data, lps->data_size); \ | 250 | vt_extradata_size += 2 + escape_ps(NULL, lps->data, lps->data_size); \ |
| 251 | num_##t##ps++; \ | 251 | num_##t##ps++; \ |
| 252 | } \ | 252 | } \ |
| @@ -369,7 +369,7 @@ CFDataRef ff_videotoolbox_hvcc_extradata_create(AVCodecContext *avctx) · 116 unmodified lines | |||
| 369 | p += 3; \ | 369 | p += 3; \ |
| 370 | for (i = 0; i < HEVC_MAX_##T##PS_COUNT; i++) { \ | 370 | for (i = 0; i < HEVC_MAX_##T##PS_COUNT; i++) { \ |
| 371 | if (h->ps.t##ps_list[i]) { \ | 371 | if (h->ps.t##ps_list[i]) { \ |
| 372 | const HEVC##T##PS *lps = (const HEVC##T##PS *)h->ps.t##ps_list[i]->data; \ | 372 | const HEVC##T##PS *lps = h->ps.t##ps_list[i]; \ |
| 373 | int size = escape_ps(p + 2, lps->data, lps->data_size); \ | 373 | int size = escape_ps(p + 2, lps->data, lps->data_size); \ |
| 374 | /* unsigned int(16) nalUnitLength; */ \ | 374 | /* unsigned int(16) nalUnitLength; */ \ |
| 375 | AV_WB16(p, size); \ | 375 | AV_WB16(p, size); \ |
| @@ -71,14 +71,14 @@ typedef struct HEVCHeaderSet { · 70 unmodified lines | |||
| 71 | static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, | 71 | static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, |
| 72 | int nb_vps, | 72 | int nb_vps, |
| 73 | const int vps_list_idx[HEVC_MAX_VPS_COUNT], | 73 | const int vps_list_idx[HEVC_MAX_VPS_COUNT], |
| 74 | AVBufferRef * const vps_list[HEVC_MAX_VPS_COUNT]) | 74 | const HEVCVPS * const vps_list[HEVC_MAX_VPS_COUNT]) |
| 75 | { | 75 | { |
| 76 | uint8_t *data_ptr; | 76 | uint8_t *data_ptr; |
| 77 | HEVCHeaderSet *hdr; | 77 | HEVCHeaderSet *hdr; |
| 78 | 78 | ||
| 79 | size_t buf_size = sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS); | 79 | size_t buf_size = sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS); |
| 80 | for (int i = 0; i < nb_vps; i++) { | 80 | for (int i = 0; i < nb_vps; i++) { |
| 81 | const HEVCVPS *vps = (const HEVCVPS *)vps_list[vps_list_idx[i]]->data; | 81 | const HEVCVPS *vps = vps_list[vps_list_idx[i]]; |
| 82 | buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; | 82 | buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; |
| 83 | } | 83 | } |
| 84 | 84 | ||
| @@ -97,7 +97,7 @@ static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, · 12 unmodified lines | |||
| 97 | hdr->hvps = (HEVCHeaderVPS *)(data_ptr + sizeof(HEVCHeaderSet)); | 97 | hdr->hvps = (HEVCHeaderVPS *)(data_ptr + sizeof(HEVCHeaderSet)); |
| 98 | data_ptr += sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS); | 98 | data_ptr += sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS); |
| 99 | for (int i = 0; i < nb_vps; i++) { | 99 | for (int i = 0; i < nb_vps; i++) { |
| 100 | const HEVCVPS *vps = (const HEVCVPS *)vps_list[vps_list_idx[i]]->data; | 100 | const HEVCVPS *vps = vps_list[vps_list_idx[i]]; |
| 101 | hdr->hvps[i].sls = (HEVCHeaderVPSSet *)data_ptr; | 101 | hdr->hvps[i].sls = (HEVCHeaderVPSSet *)data_ptr; |
| 102 | data_ptr += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; | 102 | data_ptr += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; |
| 103 | } | 103 | } |
| @@ -677,7 +677,7 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) · 573 unmodified lines | |||
| 677 | /* SPS list */ | 677 | /* SPS list */ |
| 678 | for (int i = 0; i < HEVC_MAX_SPS_COUNT; i++) { | 678 | for (int i = 0; i < HEVC_MAX_SPS_COUNT; i++) { |
| 679 | if (h->ps.sps_list[i]) { | 679 | if (h->ps.sps_list[i]) { |
| 680 | const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data; | 680 | const HEVCSPS *sps_l = h->ps.sps_list[i]; |
| 681 | int idx = h265_params_info.stdSPSCount++; | 681 | int idx = h265_params_info.stdSPSCount++; |
| 682 | set_sps(sps_l, i, &hdr->hsps[idx].scaling, &hdr->hsps[idx].vui_header, | 682 | set_sps(sps_l, i, &hdr->hsps[idx].scaling, &hdr->hsps[idx].vui_header, |
| 683 | &hdr->hsps[idx].vui, &hdr->sps[idx], hdr->hsps[idx].nal_hdr, | 683 | &hdr->hsps[idx].vui, &hdr->sps[idx], hdr->hsps[idx].nal_hdr, |
| @@ -689,8 +689,8 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) · 5 unmodified lines | |||
| 689 | /* PPS list */ | 689 | /* PPS list */ |
| 690 | for (int i = 0; i < HEVC_MAX_PPS_COUNT; i++) { | 690 | for (int i = 0; i < HEVC_MAX_PPS_COUNT; i++) { |
| 691 | if (h->ps.pps_list[i]) { | 691 | if (h->ps.pps_list[i]) { |
| 692 | const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data; | 692 | const HEVCPPS *pps_l = h->ps.pps_list[i]; |
| 693 | const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[pps_l->sps_id]->data; | 693 | const HEVCSPS *sps_l = h->ps.sps_list[pps_l->sps_id]; |
| 694 | int idx = h265_params_info.stdPPSCount++; | 694 | int idx = h265_params_info.stdPPSCount++; |
| 695 | set_pps(pps_l, sps_l, &hdr->hpps[idx].scaling, | 695 | set_pps(pps_l, sps_l, &hdr->hpps[idx].scaling, |
| 696 | &hdr->pps[idx], &hdr->hpps[idx].pal); | 696 | &hdr->pps[idx], &hdr->hpps[idx].pal); |
| @@ -699,7 +699,7 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) · 2 unmodified lines | |||
| 699 | 699 | ||
| 700 | /* VPS list */ | 700 | /* VPS list */ |
| 701 | for (int i = 0; i < nb_vps; i++) { | 701 | for (int i = 0; i < nb_vps; i++) { |
| 702 | const HEVCVPS *vps_l = (const HEVCVPS *)h->ps.vps_list[vps_list_idx[i]]->data; | 702 | const HEVCVPS *vps_l = h->ps.vps_list[vps_list_idx[i]]; |
| 703 | set_vps(vps_l, &hdr->vps[i], &hdr->hvps[i].ptl, &hdr->hvps[i].dpbm, | 703 | set_vps(vps_l, &hdr->vps[i], &hdr->hvps[i].ptl, &hdr->hvps[i].dpbm, |
| 704 | hdr->hvps[i].hdr, hdr->hvps[i].sls); | 704 | hdr->hvps[i].hdr, hdr->hvps[i].sls); |
| 705 | h265_params_info.stdVPSCount++; | 705 | h265_params_info.stdVPSCount++; |
| @@ -879,7 +879,7 @@ static int vk_hevc_end_frame(AVCodecContext *avctx) · 173 unmodified lines | |||
| 879 | if (!pps) { | 879 | if (!pps) { |
| 880 | unsigned int pps_id = h->sh.pps_id; | 880 | unsigned int pps_id = h->sh.pps_id; |
| 881 | if (pps_id < HEVC_MAX_PPS_COUNT && h->ps.pps_list[pps_id] != NULL) | 881 | if (pps_id < HEVC_MAX_PPS_COUNT && h->ps.pps_list[pps_id] != NULL) |
| 882 | pps = (const HEVCPPS *)h->ps.pps_list[pps_id]->data; | 882 | pps = h->ps.pps_list[pps_id]; |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | if (!pps) { | 885 | if (!pps) { |