Re: [FFmpeg-devel] [PATCH v3] lavc: convert frame threading to the receive_frame() pattern

2022-12-09 Thread Michael Niedermayer
On Fri, Dec 09, 2022 at 02:09:45PM +0100, Timo Rothenpieler wrote:
> On 07/12/2022 23:22, Michael Niedermayer wrote:
> > On Wed, Dec 07, 2022 at 02:20:23PM +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|  57 +
> > >   libavcodec/decode.h|   7 +
> > >   libavcodec/internal.h  |   7 +
> > >   libavcodec/pthread_frame.c | 256 -
> > >   libavcodec/thread.h|  18 +--
> > >   5 files changed, 222 insertions(+), 123 deletions(-)
> > 
> > This breaks on arm (probably lack of pthread support) in this env
> > 
> > libavcodec/libavcodec.a(decode.o): In function 
> > `decode_receive_frame_internal':
> > arm/src/libavcodec/decode.c:616: undefined reference to 
> > `ff_thread_receive_frame'
> > arm/src/libavcodec/decode.c:616: undefined reference to 
> > `ff_thread_receive_frame'
> > collect2: error: ld returned 1 exit status
> > Makefile:131: recipe for target 'ffprobe_g' failed
> > make: *** [ffprobe_g] Error 1
> 
> Probably just missing an #if somewhere.

> Why does arm not support pthreads though?
> Or is that just this specific configuration?

just this specific environment 
i could fix that but then noone will test the lack of pthreads so i think
its better if i leave it :)

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato


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".


Re: [FFmpeg-devel] [PATCH v3] lavc: convert frame threading to the receive_frame() pattern

2022-12-09 Thread James Almer

On 12/9/2022 10:09 AM, Timo Rothenpieler wrote:

On 07/12/2022 23:22, Michael Niedermayer wrote:

On Wed, Dec 07, 2022 at 02:20:23PM +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    |  57 +
  libavcodec/decode.h    |   7 +
  libavcodec/internal.h  |   7 +
  libavcodec/pthread_frame.c | 256 -
  libavcodec/thread.h    |  18 +--
  5 files changed, 222 insertions(+), 123 deletions(-)


This breaks on arm (probably lack of pthread support) in this env

libavcodec/libavcodec.a(decode.o): In function 
`decode_receive_frame_internal':
arm/src/libavcodec/decode.c:616: undefined reference to 
`ff_thread_receive_frame'
arm/src/libavcodec/decode.c:616: undefined reference to 
`ff_thread_receive_frame'

collect2: error: ld returned 1 exit status
Makefile:131: recipe for target 'ffprobe_g' failed
make: *** [ffprobe_g] Error 1


Probably just missing an #if somewhere.


Yes.


+static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
+{
+if (avctx->active_thread_type & FF_THREAD_FRAME)


Should be if (HAVE_THREADS && ...


+return ff_thread_receive_frame(avctx, frame);
+return ff_decode_receive_frame_internal(avctx, frame);
+}


___
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 v3] lavc: convert frame threading to the receive_frame() pattern

2022-12-09 Thread Timo Rothenpieler

On 07/12/2022 23:22, Michael Niedermayer wrote:

On Wed, Dec 07, 2022 at 02:20:23PM +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|  57 +
  libavcodec/decode.h|   7 +
  libavcodec/internal.h  |   7 +
  libavcodec/pthread_frame.c | 256 -
  libavcodec/thread.h|  18 +--
  5 files changed, 222 insertions(+), 123 deletions(-)


This breaks on arm (probably lack of pthread support) in this env

libavcodec/libavcodec.a(decode.o): In function `decode_receive_frame_internal':
arm/src/libavcodec/decode.c:616: undefined reference to 
`ff_thread_receive_frame'
arm/src/libavcodec/decode.c:616: undefined reference to 
`ff_thread_receive_frame'
collect2: error: ld returned 1 exit status
Makefile:131: recipe for target 'ffprobe_g' failed
make: *** [ffprobe_g] Error 1


Probably just missing an #if somewhere.
Why does arm not support pthreads though?
Or is that just this specific configuration?
___
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 v3] lavc: convert frame threading to the receive_frame() pattern

2022-12-07 Thread Michael Niedermayer
On Wed, Dec 07, 2022 at 02:20:23PM +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|  57 +
>  libavcodec/decode.h|   7 +
>  libavcodec/internal.h  |   7 +
>  libavcodec/pthread_frame.c | 256 -
>  libavcodec/thread.h|  18 +--
>  5 files changed, 222 insertions(+), 123 deletions(-)

This breaks on arm (probably lack of pthread support) in this env

libavcodec/libavcodec.a(decode.o): In function `decode_receive_frame_internal':
arm/src/libavcodec/decode.c:616: undefined reference to 
`ff_thread_receive_frame'
arm/src/libavcodec/decode.c:616: undefined reference to 
`ff_thread_receive_frame'
collect2: error: ld returned 1 exit status
Makefile:131: recipe for target 'ffprobe_g' failed
make: *** [ffprobe_g] Error 1

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf


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".


[FFmpeg-devel] [PATCH v3] lavc: convert frame threading to the receive_frame() pattern

2022-12-07 Thread Timo Rothenpieler
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|  57 +
 libavcodec/decode.h|   7 +
 libavcodec/internal.h  |   7 +
 libavcodec/pthread_frame.c | 256 -
 libavcodec/thread.h|  18 +--
 5 files changed, 222 insertions(+), 123 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index b184c3f55b..ce0b2830bd 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -180,6 +180,10 @@ fail:
 return ret;
 }
 
+#if !HAVE_THREADS
+#define ff_thread_get_packet(avctx, pkt) (AVERROR_BUG)
+#endif
+
 int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
 {
 AVCodecInternal *avci = avctx->internal;
@@ -188,7 +192,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 +284,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 +552,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 +610,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/libavcodec/decode.h
+++ b/libavcodec/decode.h
@@ -58,6 +58,13 @