Avoids implicit av_frame_ref() and therefore allocations and error checks. It also avoids explicitly allocating the AVFrames (done implicitly when getting the buffer).
Unified · Split
| @@ -42,8 +42,8 @@ · 41 unmodified lines | ||
| 42 | 42 | #include "apng.h" |
| 43 | 43 | #include "png.h" |
| 44 | 44 | #include "pngdsp.h" |
| 45 | +#include "progressframe.h" | |
| 45 | 46 | #include "thread.h" |
| 46 | −#include "threadframe.h" | |
| 47 | 47 | #include "zlib_wrapper.h" |
| 48 | 48 | |
| 49 | 49 | #include <zlib.h> |
| @@ -63,8 +63,8 @@ typedef struct PNGDecContext { · 13 unmodified lines | ||
| 63 | 63 | AVCodecContext *avctx; |
| 64 | 64 | |
| 65 | 65 | GetByteContext gb; |
| 66 | − ThreadFrame last_picture; | |
| 67 | − ThreadFrame picture; | |
| 66 | + ProgressFrame last_picture; | |
| 67 | + ProgressFrame picture; | |
| 68 | 68 | |
| 69 | 69 | AVDictionary *frame_metadata; |
| 70 | 70 | |
| @@ -874,7 +874,7 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, · 803 unmodified lines | ||
| 874 | 874 | s->bpp += byte_depth; |
| 875 | 875 | } |
| 876 | 876 | |
| 877 | − ff_thread_release_ext_buffer(&s->picture); | |
| 877 | + ff_progress_frame_unref(&s->picture); | |
| 878 | 878 | if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) { |
| 879 | 879 | /* We only need a buffer for the current picture. */ |
| 880 | 880 | ret = ff_thread_get_buffer(avctx, p, 0); |
| @@ -883,8 +883,8 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, · 2 unmodified lines | ||
| 883 | 883 | } else if (s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) { |
| 884 | 884 | /* We need a buffer for the current picture as well as |
| 885 | 885 | * a buffer for the reference to retain. */ |
| 886 | − ret = ff_thread_get_ext_buffer(avctx, &s->picture, | |
| 887 | − AV_GET_BUFFER_FLAG_REF); | |
| 886 | + ret = ff_progress_frame_get_buffer(avctx, &s->picture, | |
| 887 | + AV_GET_BUFFER_FLAG_REF); | |
| 888 | 888 | if (ret < 0) |
| 889 | 889 | return ret; |
| 890 | 890 | ret = ff_thread_get_buffer(avctx, p, 0); |
| @@ -892,8 +892,9 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, · 1 unmodified line | ||
| 892 | 892 | return ret; |
| 893 | 893 | } else { |
| 894 | 894 | /* The picture output this time and the reference to retain coincide. */ |
| 895 | − if ((ret = ff_thread_get_ext_buffer(avctx, &s->picture, | |
| 896 | − AV_GET_BUFFER_FLAG_REF)) < 0) | |
| 895 | + ret = ff_progress_frame_get_buffer(avctx, &s->picture, | |
| 896 | + AV_GET_BUFFER_FLAG_REF); | |
| 897 | + if (ret < 0) | |
| 897 | 898 | return ret; |
| 898 | 899 | ret = av_frame_ref(p, s->picture.f); |
| 899 | 900 | if (ret < 0) |
| @@ -1254,7 +1255,7 @@ static void handle_p_frame_png(PNGDecContext *s, AVFrame *p) · 354 unmodified lines | ||
| 1254 | 1255 | |
| 1255 | 1256 | ls = FFMIN(ls, s->width * s->bpp); |
| 1256 | 1257 | |
| 1257 | − ff_thread_await_progress(&s->last_picture, INT_MAX, 0); | |
| 1258 | + ff_progress_frame_await(&s->last_picture, INT_MAX); | |
| 1258 | 1259 | for (j = 0; j < s->height; j++) { |
| 1259 | 1260 | for (i = 0; i < ls; i++) |
| 1260 | 1261 | pd[i] += pd_last[i]; |
| @@ -1286,7 +1287,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, · 25 unmodified lines | ||
| 1286 | 1287 | return AVERROR_PATCHWELCOME; |
| 1287 | 1288 | } |
| 1288 | 1289 | |
| 1289 | − ff_thread_await_progress(&s->last_picture, INT_MAX, 0); | |
| 1290 | + ff_progress_frame_await(&s->last_picture, INT_MAX); | |
| 1290 | 1291 | |
| 1291 | 1292 | // copy unchanged rectangles from the last frame |
| 1292 | 1293 | for (y = 0; y < s->y_offset; y++) |
| @@ -1674,7 +1675,7 @@ exit_loop: · 381 unmodified lines | ||
| 1674 | 1675 | } |
| 1675 | 1676 | |
| 1676 | 1677 | /* handle P-frames only if a predecessor frame is available */ |
| 1677 | − if (s->last_picture.f->data[0]) { | |
| 1678 | + if (s->last_picture.f) { | |
| 1678 | 1679 | if ( !(avpkt->flags & AV_PKT_FLAG_KEY) && avctx->codec_tag != AV_RL32("MPNG") |
| 1679 | 1680 | && s->last_picture.f->width == p->width |
| 1680 | 1681 | && s->last_picture.f->height== p->height |
| @@ -1691,12 +1692,11 @@ exit_loop: · 10 unmodified lines | ||
| 1691 | 1692 | if (CONFIG_APNG_DECODER && s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) |
| 1692 | 1693 | apng_reset_background(s, p); |
| 1693 | 1694 | |
| 1694 | − ff_thread_report_progress(&s->picture, INT_MAX, 0); | |
| 1695 | − | |
| 1696 | − return 0; | |
| 1697 | − | |
| 1695 | + ret = 0; | |
| 1698 | 1696 | fail: |
| 1699 | − ff_thread_report_progress(&s->picture, INT_MAX, 0); | |
| 1697 | + if (s->picture.f) | |
| 1698 | + ff_progress_frame_report(&s->picture, INT_MAX); | |
| 1699 | + | |
| 1700 | 1700 | return ret; |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| @@ -1783,8 +1783,8 @@ static int decode_frame_png(AVCodecContext *avctx, AVFrame *p, · 80 unmodified lines | ||
| 1783 | 1783 | goto the_end; |
| 1784 | 1784 | |
| 1785 | 1785 | if (!(avctx->active_thread_type & FF_THREAD_FRAME)) { |
| 1786 | − ff_thread_release_ext_buffer(&s->last_picture); | |
| 1787 | − FFSWAP(ThreadFrame, s->picture, s->last_picture); | |
| 1786 | + ff_progress_frame_unref(&s->last_picture); | |
| 1787 | + FFSWAP(ProgressFrame, s->picture, s->last_picture); | |
| 1788 | 1788 | } |
| 1789 | 1789 | |
| 1790 | 1790 | *got_frame = 1; |
| @@ -1835,12 +1835,9 @@ static int decode_frame_apng(AVCodecContext *avctx, AVFrame *p, · 44 unmodified lines | ||
| 1835 | 1835 | return ret; |
| 1836 | 1836 | |
| 1837 | 1837 | if (!(avctx->active_thread_type & FF_THREAD_FRAME)) { |
| 1838 | − if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) { | |
| 1839 | − ff_thread_release_ext_buffer(&s->picture); | |
| 1840 | − } else { | |
| 1841 | − ff_thread_release_ext_buffer(&s->last_picture); | |
| 1842 | − FFSWAP(ThreadFrame, s->picture, s->last_picture); | |
| 1843 | − } | |
| 1838 | + if (s->dispose_op != APNG_DISPOSE_OP_PREVIOUS) | |
| 1839 | + FFSWAP(ProgressFrame, s->picture, s->last_picture); | |
| 1840 | + ff_progress_frame_unref(&s->picture); | |
| 1844 | 1841 | } |
| 1845 | 1842 | |
| 1846 | 1843 | *got_frame = 1; |
| @@ -1853,8 +1850,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) · 6 unmodified lines | ||
| 1853 | 1850 | { |
| 1854 | 1851 | PNGDecContext *psrc = src->priv_data; |
| 1855 | 1852 | PNGDecContext *pdst = dst->priv_data; |
| 1856 | − ThreadFrame *src_frame = NULL; | |
| 1857 | − int ret; | |
| 1853 | + const ProgressFrame *src_frame; | |
| 1858 | 1854 | |
| 1859 | 1855 | if (dst == src) |
| 1860 | 1856 | return 0; |
| @@ -1879,12 +1875,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) · 18 unmodified lines | ||
| 1879 | 1875 | src_frame = psrc->dispose_op == APNG_DISPOSE_OP_PREVIOUS ? |
| 1880 | 1876 | &psrc->last_picture : &psrc->picture; |
| 1881 | 1877 | |
| 1882 | − ff_thread_release_ext_buffer(&pdst->last_picture); | |
| 1883 | − if (src_frame && src_frame->f->data[0]) { | |
| 1884 | − ret = ff_thread_ref_frame(&pdst->last_picture, src_frame); | |
| 1885 | − if (ret < 0) | |
| 1886 | − return ret; | |
| 1887 | − } | |
| 1878 | + ff_progress_frame_replace(&pdst->last_picture, src_frame); | |
| 1888 | 1879 | |
| 1889 | 1880 | return 0; |
| 1890 | 1881 | } |
| @@ -1895,10 +1886,6 @@ static av_cold int png_dec_init(AVCodecContext *avctx) · 4 unmodified lines | ||
| 1895 | 1886 | PNGDecContext *s = avctx->priv_data; |
| 1896 | 1887 | |
| 1897 | 1888 | s->avctx = avctx; |
| 1898 | − s->last_picture.f = av_frame_alloc(); | |
| 1899 | − s->picture.f = av_frame_alloc(); | |
| 1900 | − if (!s->last_picture.f || !s->picture.f) | |
| 1901 | − return AVERROR(ENOMEM); | |
| 1902 | 1889 | |
| 1903 | 1890 | ff_pngdsp_init(&s->dsp); |
| 1904 | 1891 | |
| @@ -1909,10 +1896,8 @@ static av_cold int png_dec_end(AVCodecContext *avctx) · 4 unmodified lines | ||
| 1909 | 1896 | { |
| 1910 | 1897 | PNGDecContext *s = avctx->priv_data; |
| 1911 | 1898 | |
| 1912 | − ff_thread_release_ext_buffer(&s->last_picture); | |
| 1913 | − av_frame_free(&s->last_picture.f); | |
| 1914 | − ff_thread_release_ext_buffer(&s->picture); | |
| 1915 | − av_frame_free(&s->picture.f); | |
| 1899 | + ff_progress_frame_unref(&s->last_picture); | |
| 1900 | + ff_progress_frame_unref(&s->picture); | |
| 1916 | 1901 | av_freep(&s->buffer); |
| 1917 | 1902 | s->buffer_size = 0; |
| 1918 | 1903 | av_freep(&s->last_row); |
| @@ -1940,6 +1925,7 @@ const FFCodec ff_apng_decoder = { · 21 unmodified lines | ||
| 1940 | 1925 | UPDATE_THREAD_CONTEXT(update_thread_context), |
| 1941 | 1926 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, |
| 1942 | 1927 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | |
| 1928 | + FF_CODEC_CAP_USES_PROGRESSFRAMES | | |
| 1943 | 1929 | FF_CODEC_CAP_ICC_PROFILES, |
| 1944 | 1930 | }; |
| 1945 | 1931 | #endif |
| @@ -1958,6 +1944,7 @@ const FFCodec ff_png_decoder = { · 12 unmodified lines | ||
| 1958 | 1944 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, |
| 1959 | 1945 | .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | |
| 1960 | 1946 | FF_CODEC_CAP_INIT_CLEANUP | |
| 1947 | + FF_CODEC_CAP_USES_PROGRESSFRAMES | | |
| 1961 | 1948 | FF_CODEC_CAP_ICC_PROFILES, |
| 1962 | 1949 | }; |
| 1963 | 1950 | #endif |