[FFmpeg-devel] [PATCH v4] lavc: convert frame threading to the receive_frame() pattern
From: Anton Khirnov Reorganize the code such that the frame threading code does not call the decoders directly, but instead calls back into the generic decoding code. This avoids duplicating the logic that wraps the decoder invocation and will be useful in the following commits. --- libavcodec/decode.c| 58 + libavcodec/decode.h| 7 + libavcodec/internal.h | 7 + libavcodec/pthread_frame.c | 256 - libavcodec/thread.h| 18 +-- 5 files changed, 223 insertions(+), 123 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index b184c3f55b..f1be0d7876 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -180,6 +180,11 @@ fail: return ret; } +#if !HAVE_THREADS +#define ff_thread_get_packet(avctx, pkt) (AVERROR_BUG) +#define ff_thread_receive_frame(avctx, frame) (AVERROR_BUG) +#endif + int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) { AVCodecInternal *avci = avctx->internal; @@ -188,7 +193,14 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) if (avci->draining) return AVERROR_EOF; -ret = av_bsf_receive_packet(avci->bsf, pkt); +/* If we are a worker thread, get the next packet from the threading + * context. Otherwise we are the main (user-facing) context, so we get the + * next packet from the input filterchain. + */ +if (avctx->internal->is_frame_mt) +ret = ff_thread_get_packet(avctx, pkt); +else +ret = av_bsf_receive_packet(avci->bsf, pkt); if (ret == AVERROR_EOF) avci->draining = 1; if (ret < 0) @@ -273,30 +285,25 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, return AVERROR_EOF; if (!pkt->data && -!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY || - avctx->active_thread_type & FF_THREAD_FRAME)) +!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) return AVERROR_EOF; got_frame = 0; -if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) { -ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt); -} else { -ret = codec->cb.decode(avctx, frame, &got_frame, pkt); - -if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)) -frame->pkt_dts = pkt->dts; -if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { -if(!avctx->has_b_frames) -frame->pkt_pos = pkt->pos; -//FIXME these should be under if(!avctx->has_b_frames) -/* get_buffer is supposed to set frame parameters */ -if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { -if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; -if (!frame->width)frame->width = avctx->width; -if (!frame->height) frame->height = avctx->height; -if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt; -} +ret = codec->cb.decode(avctx, frame, &got_frame, pkt); + +if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)) +frame->pkt_dts = pkt->dts; +if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { +if(!avctx->has_b_frames) +frame->pkt_pos = pkt->pos; +//FIXME these should be under if(!avctx->has_b_frames) +/* get_buffer is supposed to set frame parameters */ +if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { +if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; +if (!frame->width)frame->width = avctx->width; +if (!frame->height) frame->height = avctx->height; +if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt; } } emms_c(); @@ -546,7 +553,7 @@ static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame) return 0; } -static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) +int ff_decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) { AVCodecInternal *avci = avctx->internal; const FFCodec *const codec = ffcodec(avctx->codec); @@ -604,6 +611,13 @@ FF_ENABLE_DEPRECATION_WARNINGS return ret; } +static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) +{ +if (avctx->active_thread_type & FF_THREAD_FRAME) +return ff_thread_receive_frame(avctx, frame); +return ff_decode_receive_frame_internal(avctx, frame); +} + int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt) { AVCodecInternal *avci = avctx->internal; diff --git a/libavcodec/decode.h b/libavcodec/decode.h index 5d95369b5e..34beb70f97 100644 --- a/li
Re: [FFmpeg-devel] [PATCH v4] lavc: convert frame threading to the receive_frame() pattern
On Fri, Dec 09, 2022 at 02:37:04PM +0100, Timo Rothenpieler wrote: > From: Anton Khirnov > > Reorganize the code such that the frame threading code does not call the > decoders directly, but instead calls back into the generic decoding > code. This avoids duplicating the logic that wraps the decoder > invocation and will be useful in the following commits. > --- > libavcodec/decode.c| 58 + > libavcodec/decode.h| 7 + > libavcodec/internal.h | 7 + > libavcodec/pthread_frame.c | 256 - > libavcodec/thread.h| 18 +-- > 5 files changed, 223 insertions(+), 123 deletions(-) this patch changes the output with this: ./ffmpeg -ss 1 -i Enigma_Principles_of_Lust.flv -t 1 -bitexact -f framecrc If someone wants to look into this ill send him the file, it should be online but i failed to find it. --- /tmp/test 2022-12-10 00:29:18.585089416 +0100 +++ /tmp/ref2022-12-10 00:21:14.177412007 +0100 @@ -11,46 +11,53 @@ 0, 0, 0,1, 153360, 0x887a0c84 1, 0, 0, 482, 1928, 0x9228f7f2 1,485,485, 1024, 4096, 0x60c21370 +0, 1, 1,1, 153360, 0x49c60bc4 0, 2, 2,1, 153360, 0x22740bd4 1, 1509, 1509, 1024, 4096, 0x77933b11 0, 3, 3,1, 153360, 0x244d0bb4 1, 2536, 2536, 1024, 4096, 0xe15e8d59 +0, 4, 4,1, 153360, 0x5f660b94 1, 3560, 3560, 1024, 4096, 0x545cdd61 0, 5, 5,1, 153360, 0xb628fd45 0, 6, 6,1, 153360, 0x3839e5cd 1, 4576, 4576, 1024, 4096, 0x47154132 +0, 7, 7,1, 153360, 0xf015da05 1, 5601, 5601, 1024, 4096, 0x7822f57e 0, 8, 8,1, 153360, 0x70f1d8db 0, 9, 9,1, 153360, 0x8968d203 1, 6625, 6625, 1024, 4096, 0xb786e7ff -0, 10, 10,1, 153360, 0x5902c6cb +0, 10, 10,1, 153360, 0x9e73caed 1, 7651, 7651, 1024, 4096, 0x0b467ce8 -0, 11, 11,1, 153360, 0x68e43893 +0, 11, 11,1, 153360, 0x5902c6cb 1, 8675, 8675, 1024, 4096, 0x79229a46 -0, 12, 12,1, 153360, 0x065c5e22 -0, 13, 13,1, 153360, 0x6c2962a9 +0, 12, 12,1, 153360, 0x68e43893 +0, 13, 13,1, 153360, 0x065c5e22 1, 9702, 9702, 1024, 4096, 0x63b1e107 +0, 14, 14,1, 153360, 0x6c2962a9 1, 10726, 10726, 1024, 4096, 0x9f4355eb 0, 15, 15,1, 153360, 0xff0a88e3 1, 11753, 11753, 1024, 4096, 0xcdbae3fe -0, 16, 16,1, 153360, 0xd1395d5c -0, 17, 17,1, 153360, 0x0e1f6bc5 +0, 16, 16,1, 153360, 0x07025790 +0, 17, 17,1, 153360, 0xd1395d5c 1, 12777, 12777, 1024, 4096, 0x48a38fc7 -0, 18, 18,1, 153360, 0x1972db1e +0, 18, 18,1, 153360, 0x0e1f6bc5 1, 13793, 13793, 1024, 4096, 0x3baef67f +0, 19, 19,1, 153360, 0x1972db1e 0, 20, 20,1, 153360, 0x1d6eef56 1, 14818, 14818, 1024, 4096, 0x1009f25c 0, 21, 21,1, 153360, 0x7581f07c 1, 15842, 15842, 1024, 4096, 0x01bedb12 -0, 22, 22,1, 153360, 0xae79cdac +0, 22, 22,1, 153360, 0xe1a9d022 1, 16868, 16868, 1024, 4096, 0xa00c62b0 +0, 23, 23,1, 153360, 0xae79cdac 0, 24, 24,1, 153360, 0x9d05ebf3 1, 17892, 17892, 1024, 4096, 0x9e2f639e 0, 25, 25,1, 153360, 0x48e4e890 1, 18919, 18919, 1024, 4096, 0x0a627322 -0, 26, 26,1, 153360, 0x37e0e5d7 -0, 27, 27,1, 153360, 0x6c20f174 +0, 26, 26,1, 153360, 0x0b35e41a +0, 27, 27,1, 153360, 0x37e0e5d7 1, 19943, 19943, 1024, 4096, 0x5f670b1d -0, 28, 28,1, 153360, 0x727bf68a +0, 28, 28,1, 153360, 0x6c20f174 1, 20959, 20959, 1024, 4096, 0xb6486ba8 +0, 29, 29,1, 153360, 0x727bf68a 1, 21984, 21984, 66, 264, 0x [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Those who are best at talking, realize last or never when they are wrong. signature.asc Description: PGP signature
Re: [FFmpeg-devel] [PATCH v4] lavc: convert frame threading to the receive_frame() pattern
On 10.12.2022 00:46, Michael Niedermayer wrote: On Fri, Dec 09, 2022 at 02:37:04PM +0100, Timo Rothenpieler wrote: From: Anton Khirnov Reorganize the code such that the frame threading code does not call the decoders directly, but instead calls back into the generic decoding code. This avoids duplicating the logic that wraps the decoder invocation and will be useful in the following commits. --- libavcodec/decode.c| 58 + libavcodec/decode.h| 7 + libavcodec/internal.h | 7 + libavcodec/pthread_frame.c | 256 - libavcodec/thread.h| 18 +-- 5 files changed, 223 insertions(+), 123 deletions(-) this patch changes the output with this: ./ffmpeg -ss 1 -i Enigma_Principles_of_Lust.flv -t 1 -bitexact -f framecrc Yeah, I'd like to have that file. The change is interesting, and it looks like it might actually be legit frames? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v4] lavc: convert frame threading to the receive_frame() pattern
On Sat, Dec 10, 2022 at 09:10:18PM +0100, Timo Rothenpieler wrote: > On 10.12.2022 00:46, Michael Niedermayer wrote: > > On Fri, Dec 09, 2022 at 02:37:04PM +0100, Timo Rothenpieler wrote: > > > From: Anton Khirnov > > > > > > Reorganize the code such that the frame threading code does not call the > > > decoders directly, but instead calls back into the generic decoding > > > code. This avoids duplicating the logic that wraps the decoder > > > invocation and will be useful in the following commits. > > > --- > > > libavcodec/decode.c| 58 + > > > libavcodec/decode.h| 7 + > > > libavcodec/internal.h | 7 + > > > libavcodec/pthread_frame.c | 256 - > > > libavcodec/thread.h| 18 +-- > > > 5 files changed, 223 insertions(+), 123 deletions(-) > > > > this patch changes the output with this: > > > > ./ffmpeg -ss 1 -i Enigma_Principles_of_Lust.flv -t 1 -bitexact -f framecrc > > Yeah, I'd like to have that file. : message size 16466626 exceeds size limit 1024 of server mail.btbn.de[136.243.74.85] [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB He who knows, does not speak. He who speaks, does not know. -- Lao Tsu signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".