History

avcodec/pngdec: Switch to ProgressFrames

Avoids implicit av_frame_ref() and therefore allocations and error checks. It also avoids explicitly allocating the AVFrames (done implicitly when getting the buffer).

Andreas Rheinhardt committed 4 years ago

Commit 2f291471 parent a807e461 file · +27 −40Browse files

Unified · Split

libavcodec/pngdec.c+27−40
@@ -42,8 +42,8 @@ · 41 unmodified lines
4242 #include "apng.h"
4343 #include "png.h"
4444 #include "pngdsp.h"
45+#include "progressframe.h"
4546 #include "thread.h"
46−#include "threadframe.h"
4747 #include "zlib_wrapper.h"
4848
4949 #include <zlib.h>
@@ -63,8 +63,8 @@ typedef struct PNGDecContext { · 13 unmodified lines
6363 AVCodecContext *avctx;
6464
6565 GetByteContext gb;
66− ThreadFrame last_picture;
67− ThreadFrame picture;
66+ ProgressFrame last_picture;
67+ ProgressFrame picture;
6868
6969 AVDictionary *frame_metadata;
7070
@@ -874,7 +874,7 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, · 803 unmodified lines
874874 s->bpp += byte_depth;
875875 }
876876
877− ff_thread_release_ext_buffer(&s->picture);
877+ ff_progress_frame_unref(&s->picture);
878878 if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
879879 /* We only need a buffer for the current picture. */
880880 ret = ff_thread_get_buffer(avctx, p, 0);
@@ -883,8 +883,8 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, · 2 unmodified lines
883883 } else if (s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) {
884884 /* We need a buffer for the current picture as well as
885885 * 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);
888888 if (ret < 0)
889889 return ret;
890890 ret = ff_thread_get_buffer(avctx, p, 0);
@@ -892,8 +892,9 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, · 1 unmodified line
892892 return ret;
893893 } else {
894894 /* 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)
897898 return ret;
898899 ret = av_frame_ref(p, s->picture.f);
899900 if (ret < 0)
@@ -1254,7 +1255,7 @@ static void handle_p_frame_png(PNGDecContext *s, AVFrame *p) · 354 unmodified lines
12541255
12551256 ls = FFMIN(ls, s->width * s->bpp);
12561257
1257− ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
1258+ ff_progress_frame_await(&s->last_picture, INT_MAX);
12581259 for (j = 0; j < s->height; j++) {
12591260 for (i = 0; i < ls; i++)
12601261 pd[i] += pd_last[i];
@@ -1286,7 +1287,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, · 25 unmodified lines
12861287 return AVERROR_PATCHWELCOME;
12871288 }
12881289
1289− ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
1290+ ff_progress_frame_await(&s->last_picture, INT_MAX);
12901291
12911292 // copy unchanged rectangles from the last frame
12921293 for (y = 0; y < s->y_offset; y++)
@@ -1674,7 +1675,7 @@ exit_loop: · 381 unmodified lines
16741675 }
16751676
16761677 /* handle P-frames only if a predecessor frame is available */
1677− if (s->last_picture.f->data[0]) {
1678+ if (s->last_picture.f) {
16781679 if ( !(avpkt->flags & AV_PKT_FLAG_KEY) && avctx->codec_tag != AV_RL32("MPNG")
16791680 && s->last_picture.f->width == p->width
16801681 && s->last_picture.f->height== p->height
@@ -1691,12 +1692,11 @@ exit_loop: · 10 unmodified lines
16911692 if (CONFIG_APNG_DECODER && s->dispose_op == APNG_DISPOSE_OP_BACKGROUND)
16921693 apng_reset_background(s, p);
16931694
1694− ff_thread_report_progress(&s->picture, INT_MAX, 0);
1695−
1696− return 0;
1697−
1695+ ret = 0;
16981696 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+
17001700 return ret;
17011701 }
17021702
@@ -1783,8 +1783,8 @@ static int decode_frame_png(AVCodecContext *avctx, AVFrame *p, · 80 unmodified lines
17831783 goto the_end;
17841784
17851785 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);
17881788 }
17891789
17901790 *got_frame = 1;
@@ -1835,12 +1835,9 @@ static int decode_frame_apng(AVCodecContext *avctx, AVFrame *p, · 44 unmodified lines
18351835 return ret;
18361836
18371837 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);
18441841 }
18451842
18461843 *got_frame = 1;
@@ -1853,8 +1850,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) · 6 unmodified lines
18531850 {
18541851 PNGDecContext *psrc = src->priv_data;
18551852 PNGDecContext *pdst = dst->priv_data;
1856− ThreadFrame *src_frame = NULL;
1857− int ret;
1853+ const ProgressFrame *src_frame;
18581854
18591855 if (dst == src)
18601856 return 0;
@@ -1879,12 +1875,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) · 18 unmodified lines
18791875 src_frame = psrc->dispose_op == APNG_DISPOSE_OP_PREVIOUS ?
18801876 &psrc->last_picture : &psrc->picture;
18811877
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);
18881879
18891880 return 0;
18901881 }
@@ -1895,10 +1886,6 @@ static av_cold int png_dec_init(AVCodecContext *avctx) · 4 unmodified lines
18951886 PNGDecContext *s = avctx->priv_data;
18961887
18971888 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);
19021889
19031890 ff_pngdsp_init(&s->dsp);
19041891
@@ -1909,10 +1896,8 @@ static av_cold int png_dec_end(AVCodecContext *avctx) · 4 unmodified lines
19091896 {
19101897 PNGDecContext *s = avctx->priv_data;
19111898
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);
19161901 av_freep(&s->buffer);
19171902 s->buffer_size = 0;
19181903 av_freep(&s->last_row);
@@ -1940,6 +1925,7 @@ const FFCodec ff_apng_decoder = { · 21 unmodified lines
19401925 UPDATE_THREAD_CONTEXT(update_thread_context),
19411926 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
19421927 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1928+ FF_CODEC_CAP_USES_PROGRESSFRAMES |
19431929 FF_CODEC_CAP_ICC_PROFILES,
19441930 };
19451931 #endif
@@ -1958,6 +1944,7 @@ const FFCodec ff_png_decoder = { · 12 unmodified lines
19581944 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
19591945 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
19601946 FF_CODEC_CAP_INIT_CLEANUP |
1947+ FF_CODEC_CAP_USES_PROGRESSFRAMES |
19611948 FF_CODEC_CAP_ICC_PROFILES,
19621949 };
19631950 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t