From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 20/35] lavc/qsvdec: switch to the new FIFO API Date: Tue, 11 Jan 2022 21:45:55 +0100 Message-ID: <20220111204610.14262-20-anton@khirnov.net> (raw) In-Reply-To: <20220111204610.14262-1-anton@khirnov.net> --- libavcodec/qsvdec.c | 80 +++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 08370c8a0b..acdf7804f6 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -56,6 +56,11 @@ static const AVRational mfx_tb = { 1, 90000 }; AV_NOPTS_VALUE : pts_tb.num ? \ av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts) +typedef struct QSVAsyncFrame { + mfxSyncPoint *sync; + QSVFrame *frame; +} QSVAsyncFrame; + typedef struct QSVContext { // the session used for decoding mfxSession session; @@ -208,16 +213,6 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses return 0; } -static inline unsigned int qsv_fifo_item_size(void) -{ - return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*); -} - -static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo) -{ - return av_fifo_size(fifo) / qsv_fifo_item_size(); -} - static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param) { mfxSession session = NULL; @@ -235,7 +230,7 @@ static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel } if (!q->async_fifo) { - q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size()); + q->async_fifo = av_fifo_alloc2(q->async_depth, sizeof(QSVAsyncFrame), 0); if (!q->async_fifo) return AVERROR(ENOMEM); } @@ -502,7 +497,6 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *avpkt) { - QSVFrame *out_frame; mfxFrameSurface1 *insurf; mfxFrameSurface1 *outsurf; mfxSyncPoint *sync; @@ -561,6 +555,7 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q, } if (*sync) { + QSVAsyncFrame aframe; QSVFrame *out_frame = find_frame(q, outsurf); if (!out_frame) { @@ -571,35 +566,36 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q, } out_frame->queued = 1; - av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL); - av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL); + + aframe = (QSVAsyncFrame){ sync, out_frame }; + av_fifo_write(q->async_fifo, &aframe, 1); } else { av_freep(&sync); } - if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) || - (!avpkt->size && av_fifo_size(q->async_fifo))) { + if ((av_fifo_can_read(q->async_fifo) >= q->async_depth) || + (!avpkt->size && av_fifo_can_read(q->async_fifo))) { + QSVAsyncFrame aframe; AVFrame *src_frame; - av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL); - av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL); - out_frame->queued = 0; + av_fifo_read(q->async_fifo, &aframe, 1); + aframe.frame->queued = 0; if (avctx->pix_fmt != AV_PIX_FMT_QSV) { do { - ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000); + ret = MFXVideoCORE_SyncOperation(q->session, *aframe.sync, 1000); } while (ret == MFX_WRN_IN_EXECUTION); } - av_freep(&sync); + av_freep(&aframe.sync); - src_frame = out_frame->frame; + src_frame = aframe.frame->frame; ret = av_frame_ref(frame, src_frame); if (ret < 0) return ret; - outsurf = &out_frame->surface; + outsurf = &aframe.frame->surface; frame->pts = MFX_PTS_TO_PTS(outsurf->Data.TimeStamp, avctx->pkt_timebase); @@ -611,10 +607,10 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q, outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF; frame->interlaced_frame = !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE); - frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType); + frame->pict_type = ff_qsv_map_pictype(aframe.frame->dec_info.FrameType); //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs are key frames. if (avctx->codec_id == AV_CODEC_ID_H264) - frame->key_frame = !!(out_frame->dec_info.FrameType & MFX_FRAMETYPE_IDR); + frame->key_frame = !!(aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR); /* update the surface properties */ if (avctx->pix_fmt == AV_PIX_FMT_QSV) @@ -633,14 +629,11 @@ static void qsv_decode_close_qsvcontext(QSVContext *q) if (q->session) MFXVideoDECODE_Close(q->session); - while (q->async_fifo && av_fifo_size(q->async_fifo)) { - QSVFrame *out_frame; - mfxSyncPoint *sync; + while (q->async_fifo && av_fifo_can_read(q->async_fifo)) { + QSVAsyncFrame aframe; - av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL); - av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL); - - av_freep(&sync); + av_fifo_read(q->async_fifo, &aframe, 1); + av_freep(&aframe.sync); } while (cur) { @@ -650,8 +643,7 @@ static void qsv_decode_close_qsvcontext(QSVContext *q) cur = q->work_frames; } - av_fifo_free(q->async_fifo); - q->async_fifo = NULL; + av_fifo_freep(&q->async_fifo); ff_qsv_close_internal_session(&q->internal_qs); @@ -742,8 +734,8 @@ typedef struct QSVDecContext { static void qsv_clear_buffers(QSVDecContext *s) { AVPacket pkt; - while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) { - av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL); + while (av_fifo_can_read(s->packet_fifo)) { + av_fifo_read(s->packet_fifo, &pkt, 1); av_packet_unref(&pkt); } @@ -797,7 +789,8 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx) } s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12; - s->packet_fifo = av_fifo_alloc(sizeof(AVPacket)); + s->packet_fifo = av_fifo_alloc2(1, sizeof(AVPacket), + AV_FIFO_FLAG_AUTO_GROW); if (!s->packet_fifo) { ret = AVERROR(ENOMEM); goto fail; @@ -823,17 +816,10 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data, if (avpkt->size) { AVPacket input_ref; - if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) { - ret = av_fifo_realloc2(s->packet_fifo, - av_fifo_size(s->packet_fifo) + sizeof(input_ref)); - if (ret < 0) - return ret; - } - ret = av_packet_ref(&input_ref, avpkt); if (ret < 0) return ret; - av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), NULL); + av_fifo_write(s->packet_fifo, &input_ref, 1); } /* process buffered data */ @@ -841,12 +827,12 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data, /* prepare the input data */ if (s->buffer_pkt.size <= 0) { /* no more data */ - if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket)) + if (!av_fifo_can_read(s->packet_fifo)) return avpkt->size ? avpkt->size : qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt); /* in progress of reinit, no read from fifo and keep the buffer_pkt */ if (!s->qsv.reinit_flag) { av_packet_unref(&s->buffer_pkt); - av_fifo_generic_read(s->packet_fifo, &s->buffer_pkt, sizeof(s->buffer_pkt), NULL); + av_fifo_read(s->packet_fifo, &s->buffer_pkt, 1); } } -- 2.33.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-01-11 20:50 UTC|newest] Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-11 20:45 [FFmpeg-devel] [PATCH 01/35] lavu/fifo: disallow overly large fifo sizes Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 02/35] lavu/fifo: make the contents of AVFifoBuffer private on next major bump Anton Khirnov 2022-01-13 14:22 ` Andreas Rheinhardt 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 03/35] lavu/fifo: introduce the notion of element size Anton Khirnov 2022-01-13 16:50 ` Andreas Rheinhardt 2022-01-13 16:59 ` James Almer 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 04/35] lavu/fifo: add new functions for determinining reading/writing size Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 05/35] lavu/fifo: add a new FIFO grow function Anton Khirnov 2022-01-13 17:04 ` James Almer 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 06/35] lavu/fifo: add a new function for draining the FIFO Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 07/35] lavu/fifo: add new FIFO writing functions Anton Khirnov 2022-01-13 17:31 ` Andreas Rheinhardt 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 08/35] lavu/fifo: add new FIFO read/peek functions Anton Khirnov 2022-01-13 17:41 ` Andreas Rheinhardt 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 09/35] lavu/fifo: add a flag for automatically growing the FIFO as needed Anton Khirnov 2022-01-13 17:53 ` Andreas Rheinhardt 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 10/35] lavu/fifo: deprecate old API Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 11/35] lavu/tests/fifo: switch to the new API Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 12/35] lavc/avcodec: switch to new FIFO API Anton Khirnov 2022-01-13 18:21 ` Andreas Rheinhardt 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 13/35] lavc/amfenc: " Anton Khirnov 2022-01-12 14:46 ` Michael Niedermayer 2022-01-12 19:29 ` Anton Khirnov 2022-01-13 14:14 ` Michael Niedermayer 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 14/35] lavc/cuviddec: do not reallocate the fifo unnecessarily Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 15/35] lavc/cuviddec: convert to the new FIFO API Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 16/35] lavc/libvorbisenc: switch to " Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 17/35] lavc/libvpxenc: switch to the " Anton Khirnov 2022-01-12 18:15 ` James Zern 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 18/35] lavc/libvpxenc: remove unneeded context variable Anton Khirnov 2022-01-12 18:15 ` James Zern 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 19/35] lavc/nvenc: switch to the new FIFO API Anton Khirnov 2022-01-11 20:45 ` Anton Khirnov [this message] 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 21/35] lavc/qsvenc: switch to " Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 22/35] lavf/dvenc: return an error on audio/video desync Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 23/35] lavf/dvenc: switch to new FIFO API Anton Khirnov 2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 24/35] lavf/mpegenc: " Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 25/35] lavf/swfenc: " Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 26/35] lavf/udp: " Anton Khirnov 2022-01-13 18:45 ` Andreas Rheinhardt 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 27/35] lavf/async: " Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 28/35] lavd/jack: switch to the " Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 29/35] lavu/audio_fifo: drop an unnecessary include Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 30/35] lavu/audio_fifo: switch to new FIFO API Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 31/35] lavu/threadmessage: " Anton Khirnov 2022-01-13 19:03 ` Andreas Rheinhardt 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 32/35] lavfi/qsvvpp: " Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 33/35] lavfi/vf_deshake_opencl: " Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 34/35] ffplay: " Anton Khirnov 2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 35/35] ffmpeg: " Anton Khirnov 2022-01-13 13:59 ` [FFmpeg-devel] [PATCH 01/35] lavu/fifo: disallow overly large fifo sizes Andreas Rheinhardt 2022-01-13 14:27 ` Anton Khirnov 2022-01-13 14:38 ` Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220111204610.14262-20-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git