Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec: Use preprocessors conditions
@ 2023-01-17 11:38 pawday-at-mail.ru
  2023-01-17 12:04 ` Andreas Rheinhardt
  0 siblings, 1 reply; 5+ messages in thread
From: pawday-at-mail.ru @ 2023-01-17 11:38 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Pawday

From: Pawday <pawday@mail.ru>

---
 libavcodec/avcodec.c | 13 +++++++++----
 libavcodec/decode.c  |  5 +++--
 libavcodec/encode.c  |  8 ++++----
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a85d3c2309..1e24bdf333 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -403,10 +403,12 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
     av_frame_unref(avci->buffer_frame);
     av_packet_unref(avci->buffer_pkt);
 
-    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
+#if HAVE_THREADS
+    if (avctx->active_thread_type & FF_THREAD_FRAME)
         ff_thread_flush(avctx);
     else if (ffcodec(avctx->codec)->flush)
         ffcodec(avctx->codec)->flush(avctx);
+#endif
 }
 
 void avsubtitle_free(AVSubtitle *sub)
@@ -441,12 +443,15 @@ av_cold int avcodec_close(AVCodecContext *avctx)
     if (avcodec_is_open(avctx)) {
         AVCodecInternal *avci = avctx->internal;
 
-        if (CONFIG_FRAME_THREAD_ENCODER &&
-            avci->frame_thread_encoder && avctx->thread_count > 1) {
+#if CONFIG_FRAME_THREAD_ENCODER
+        if (avci->frame_thread_encoder && avctx->thread_count > 1) {
             ff_frame_thread_encoder_free(avctx);
         }
-        if (HAVE_THREADS && avci->thread_ctx)
+#endif
+#if HAVE_THREADS
+        if (avci->thread_ctx)
             ff_thread_free(avctx);
+#endif
         if (avci->needs_close && ffcodec(avctx->codec)->close)
             ffcodec(avctx->codec)->close(avctx);
         avci->byte_buffer_size = 0;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..7979b9277a 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -300,8 +300,8 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
         return AVERROR_EOF;
 
     got_frame = 0;
-
-    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
+#if HAVE_THREADS
+    if (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);
@@ -321,6 +321,7 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
             }
         }
     }
+#endif
     emms_c();
     actual_got_frame = got_frame;
 
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index fbe2c97cd6..6f39bfeb50 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -269,7 +269,7 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
     got_packet = 0;
 
     av_assert0(codec->cb_type == FF_CODEC_CB_TYPE_ENCODE);
-
+#if CONFIG_FRAME_THREAD_ENCODER
     if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
         /* This will unref frame. */
         ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
@@ -280,7 +280,7 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
             av_frame_unref(frame);
 #endif
     }
-
+#endif
     if (avci->draining && !got_packet)
         avci->draining_done = 1;
 
@@ -670,11 +670,11 @@ int ff_encode_preinit(AVCodecContext *avctx)
             return AVERROR(ENOMEM);
     }
 
-    if (CONFIG_FRAME_THREAD_ENCODER) {
+#if CONFIG_FRAME_THREAD_ENCODER
         ret = ff_frame_thread_encoder_init(avctx);
         if (ret < 0)
             return ret;
-    }
+#endif
 
     return 0;
 }
-- 
2.33.0.windows.2

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec: Use preprocessors conditions
  2023-01-17 11:38 [FFmpeg-devel] [PATCH] avcodec: Use preprocessors conditions pawday-at-mail.ru
@ 2023-01-17 12:04 ` Andreas Rheinhardt
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2023-01-17 12:04 UTC (permalink / raw)
  To: ffmpeg-devel

pawday-at-mail.ru@ffmpeg.org:
> From: Pawday <pawday@mail.ru>
> 
> ---
>  libavcodec/avcodec.c | 13 +++++++++----
>  libavcodec/decode.c  |  5 +++--
>  libavcodec/encode.c  |  8 ++++----
>  3 files changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index a85d3c2309..1e24bdf333 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -403,10 +403,12 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
>      av_frame_unref(avci->buffer_frame);
>      av_packet_unref(avci->buffer_pkt);
>  
> -    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
> +#if HAVE_THREADS
> +    if (avctx->active_thread_type & FF_THREAD_FRAME)
>          ff_thread_flush(avctx);
>      else if (ffcodec(avctx->codec)->flush)
>          ffcodec(avctx->codec)->flush(avctx);
> +#endif

This is wrong: You are not flushing when no threads are available.

>  }
>  
>  void avsubtitle_free(AVSubtitle *sub)
> @@ -441,12 +443,15 @@ av_cold int avcodec_close(AVCodecContext *avctx)
>      if (avcodec_is_open(avctx)) {
>          AVCodecInternal *avci = avctx->internal;
>  
> -        if (CONFIG_FRAME_THREAD_ENCODER &&
> -            avci->frame_thread_encoder && avctx->thread_count > 1) {
> +#if CONFIG_FRAME_THREAD_ENCODER
> +        if (avci->frame_thread_encoder && avctx->thread_count > 1) {
>              ff_frame_thread_encoder_free(avctx);
>          }
> -        if (HAVE_THREADS && avci->thread_ctx)
> +#endif
> +#if HAVE_THREADS
> +        if (avci->thread_ctx)
>              ff_thread_free(avctx);
> +#endif
>          if (avci->needs_close && ffcodec(avctx->codec)->close)
>              ffcodec(avctx->codec)->close(avctx);
>          avci->byte_buffer_size = 0;
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index 6be2d3d6ed..7979b9277a 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -300,8 +300,8 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
>          return AVERROR_EOF;
>  
>      got_frame = 0;
> -
> -    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
> +#if HAVE_THREADS
> +    if (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);
> @@ -321,6 +321,7 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
>              }
>          }
>      }
> +#endif

Same issue as above: In case HAVE_THREADS is false, the else branch
needs to be taken, but you #if them away.
(Have you even tested this with threading disabled? It should not work
at all.)

>      emms_c();
>      actual_got_frame = got_frame;
>  
> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> index fbe2c97cd6..6f39bfeb50 100644
> --- a/libavcodec/encode.c
> +++ b/libavcodec/encode.c
> @@ -269,7 +269,7 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
>      got_packet = 0;
>  
>      av_assert0(codec->cb_type == FF_CODEC_CB_TYPE_ENCODE);
> -
> +#if CONFIG_FRAME_THREAD_ENCODER
>      if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
>          /* This will unref frame. */
>          ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
> @@ -280,7 +280,7 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
>              av_frame_unref(frame);
>  #endif
>      }
> -
> +#endif
>      if (avci->draining && !got_packet)
>          avci->draining_done = 1;
>  
> @@ -670,11 +670,11 @@ int ff_encode_preinit(AVCodecContext *avctx)
>              return AVERROR(ENOMEM);
>      }
>  
> -    if (CONFIG_FRAME_THREAD_ENCODER) {
> +#if CONFIG_FRAME_THREAD_ENCODER
>          ret = ff_frame_thread_encoder_init(avctx);
>          if (ret < 0)
>              return ret;
> -    }
> +#endif
>  
>      return 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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH] avcodec: Use preprocessors conditions
@ 2023-01-17 19:37 pawday-at-mail.ru
  0 siblings, 0 replies; 5+ messages in thread
From: pawday-at-mail.ru @ 2023-01-17 19:37 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Pawday

From: Pawday <pawday@mail.ru>

Thank you for showing me logic substitution issues. 

So, if you curious i am trying to substitute calling thread depending
functions for unuptimized compiler where dead code illumination is not
working and it couse linking error on my microcontroller toolchain
without any thread model support.

---
 libavcodec/avcodec.c | 23 ++++++++++++++++-------
 libavcodec/decode.c  |  7 +++++--
 libavcodec/encode.c  |  9 ++++++---
 libavcodec/h264dec.c | 14 +++++++-------
 4 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a85d3c2309..9a11ab043f 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@ -403,10 +403,16 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
     av_frame_unref(avci->buffer_frame);
     av_packet_unref(avci->buffer_pkt);
 
-    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
+#if HAVE_THREADS
+    if (avctx->active_thread_type & FF_THREAD_FRAME)
         ff_thread_flush(avctx);
-    else if (ffcodec(avctx->codec)->flush)
-        ffcodec(avctx->codec)->flush(avctx);
+    else {
+#endif
+        if (ffcodec(avctx->codec)->flush)
+            ffcodec(avctx->codec)->flush(avctx);
+#if HAVE_THREADS
+    }
+#endif
 }
 
 void avsubtitle_free(AVSubtitle *sub)
@@ -441,12 +447,15 @@ av_cold int avcodec_close(AVCodecContext *avctx)
     if (avcodec_is_open(avctx)) {
         AVCodecInternal *avci = avctx->internal;
 
-        if (CONFIG_FRAME_THREAD_ENCODER &&
-            avci->frame_thread_encoder && avctx->thread_count > 1) {
+#if CONFIG_FRAME_THREAD_ENCODER
+        if (avci->frame_thread_encoder && avctx->thread_count > 1) {
             ff_frame_thread_encoder_free(avctx);
         }
-        if (HAVE_THREADS && avci->thread_ctx)
+#endif
+#if HAVE_THREADS
+        if (avci->thread_ctx)
             ff_thread_free(avctx);
+#endif
         if (avci->needs_close && ffcodec(avctx->codec)->close)
             ffcodec(avctx->codec)->close(avctx);
         avci->byte_buffer_size = 0;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..5076b8a420 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -300,10 +300,11 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
         return AVERROR_EOF;
 
     got_frame = 0;
-
-    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
+#if HAVE_THREADS
+    if (avctx->active_thread_type & FF_THREAD_FRAME) {
         ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
     } else {
+#endif
         ret = codec->cb.decode(avctx, frame, &got_frame, pkt);
 
         if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
@@ -320,7 +321,9 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
                 if (frame->format == AV_PIX_FMT_NONE) frame->format              = avctx->pix_fmt;
             }
         }
+#if HAVE_THREADS
     }
+#endif
     emms_c();
     actual_got_frame = got_frame;
 
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index fbe2c97cd6..efd1cbe6c7 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -269,17 +269,20 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
     got_packet = 0;
 
     av_assert0(codec->cb_type == FF_CODEC_CB_TYPE_ENCODE);
-
+#if CONFIG_FRAME_THREAD_ENCODER
     if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
         /* This will unref frame. */
         ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
     else {
+#endif
         ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
 #if FF_API_THREAD_SAFE_CALLBACKS
         if (frame)
             av_frame_unref(frame);
 #endif
+#if CONFIG_FRAME_THREAD_ENCODER
     }
+#endif
 
     if (avci->draining && !got_packet)
         avci->draining_done = 1;
@@ -670,11 +673,11 @@ int ff_encode_preinit(AVCodecContext *avctx)
             return AVERROR(ENOMEM);
     }
 
-    if (CONFIG_FRAME_THREAD_ENCODER) {
+#if CONFIG_FRAME_THREAD_ENCODER
         ret = ff_frame_thread_encoder_init(avctx);
         if (ret < 0)
             return ret;
-    }
+#endif
 
     return 0;
 }
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 6ede4e8c9f..4538974dab 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -933,13 +933,13 @@ static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *g
 
         *got_frame = 1;
 
-        if (CONFIG_MPEGVIDEODEC) {
-            ff_print_debug_info2(h->avctx, dst, NULL,
-                                 out->mb_type,
-                                 out->qscale_table,
-                                 out->motion_val,
-                                 out->mb_width, out->mb_height, out->mb_stride, 1);
-        }
+#if CONFIG_MPEGVIDEODEC
+        ff_print_debug_info2(h->avctx, dst, NULL,
+                             out->mb_type,
+                             out->qscale_table,
+                             out->motion_val,
+                             out->mb_width, out->mb_height, out->mb_stride, 1);
+#endif
     }
 
     return 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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec: Use preprocessors conditions
  2023-01-17 14:31 pawday-at-mail.ru
@ 2023-01-17 15:38 ` Hendrik Leppkes
  0 siblings, 0 replies; 5+ messages in thread
From: Hendrik Leppkes @ 2023-01-17 15:38 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Tue, Jan 17, 2023 at 3:36 PM <pawday-at-mail.ru@ffmpeg.org> wrote:
>
> From: Pawday <pawday@mail.ru>
>
> Thank you Andreas Rheinhardt for review
>
> Here the fixes for runtime "else" conditions
>
> ---
>  libavcodec/avcodec.c | 16 +++++++++++-----
>  libavcodec/decode.c  | 11 ++++++++---
>  libavcodec/encode.c  | 13 ++++++++-----
>  libavcodec/h264dec.c | 14 +++++++-------
>  4 files changed, 34 insertions(+), 20 deletions(-)
>
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index a85d3c2309..0e792aead9 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -403,10 +403,13 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
>      av_frame_unref(avci->buffer_frame);
>      av_packet_unref(avci->buffer_pkt);
>
> -    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
> +#if HAVE_THREADS
> +    if (avctx->active_thread_type & FF_THREAD_FRAME)
>          ff_thread_flush(avctx);
> -    else if (ffcodec(avctx->codec)->flush)
> +#else
> +    if (ffcodec(avctx->codec)->flush)
>          ffcodec(avctx->codec)->flush(avctx);
> +#endif
>  }
>

The before and after behavior are not identical. Just because threads
are supported does not imply they are always used.

>  void avsubtitle_free(AVSubtitle *sub)
> @@ -441,12 +444,15 @@ av_cold int avcodec_close(AVCodecContext *avctx)
>      if (avcodec_is_open(avctx)) {
>          AVCodecInternal *avci = avctx->internal;
>
> -        if (CONFIG_FRAME_THREAD_ENCODER &&
> -            avci->frame_thread_encoder && avctx->thread_count > 1) {
> +#if CONFIG_FRAME_THREAD_ENCODER
> +        if (avci->frame_thread_encoder && avctx->thread_count > 1) {
>              ff_frame_thread_encoder_free(avctx);
>          }
> -        if (HAVE_THREADS && avci->thread_ctx)
> +#endif
> +#if HAVE_THREADS
> +        if (avci->thread_ctx)
>              ff_thread_free(avctx);
> +#endif
>          if (avci->needs_close && ffcodec(avctx->codec)->close)
>              ffcodec(avctx->codec)->close(avctx);
>          avci->byte_buffer_size = 0;
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index 6be2d3d6ed..54ffd0f203 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -300,10 +300,14 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
>          return AVERROR_EOF;
>
>      got_frame = 0;
> -
> -    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
> +#if HAVE_THREADS
> +    if (avctx->active_thread_type & FF_THREAD_FRAME) {
>          ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
> -    } else {
> +    }
> +#endif
> +
> +#if !HAVE_THREADS
> +    if (!(avctx->active_thread_type & FF_THREAD_FRAME)) {

Same issue here. Threads are not always active even if supported.

>          ret = codec->cb.decode(avctx, frame, &got_frame, pkt);
>
>          if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
> @@ -321,6 +325,7 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
>              }
>          }
>      }
> +#endif
>      emms_c();
>      actual_got_frame = got_frame;
>
> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> index fbe2c97cd6..b19599e67e 100644
> --- a/libavcodec/encode.c
> +++ b/libavcodec/encode.c
> @@ -269,17 +269,20 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
>      got_packet = 0;
>
>      av_assert0(codec->cb_type == FF_CODEC_CB_TYPE_ENCODE);
> -
> -    if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
> +#if CONFIG_FRAME_THREAD_ENCODER
> +    if (avci->frame_thread_encoder)
>          /* This will unref frame. */
>          ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
> -    else {
> +#endif
> +#if !CONFIG_FRAME_THREAD_ENCODER
> +    if (!avci->frame_thread_encoder) {
>          ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);

And here..

>  #if FF_API_THREAD_SAFE_CALLBACKS
>          if (frame)
>              av_frame_unref(frame);
>  #endif
>      }
> +#endif // !CONFIG_FRAME_THREAD_ENCODER
>
>      if (avci->draining && !got_packet)
>          avci->draining_done = 1;
> @@ -670,11 +673,11 @@ int ff_encode_preinit(AVCodecContext *avctx)
>              return AVERROR(ENOMEM);
>      }
>
> -    if (CONFIG_FRAME_THREAD_ENCODER) {
> +#if CONFIG_FRAME_THREAD_ENCODER
>          ret = ff_frame_thread_encoder_init(avctx);
>          if (ret < 0)
>              return ret;
> -    }
> +#endif
>
>      return 0;
>  }
> diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
> index 6ede4e8c9f..4538974dab 100644
> --- a/libavcodec/h264dec.c
> +++ b/libavcodec/h264dec.c
> @@ -933,13 +933,13 @@ static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *g
>
>          *got_frame = 1;
>
> -        if (CONFIG_MPEGVIDEODEC) {
> -            ff_print_debug_info2(h->avctx, dst, NULL,
> -                                 out->mb_type,
> -                                 out->qscale_table,
> -                                 out->motion_val,
> -                                 out->mb_width, out->mb_height, out->mb_stride, 1);
> -        }
> +#if CONFIG_MPEGVIDEODEC
> +        ff_print_debug_info2(h->avctx, dst, NULL,
> +                             out->mb_type,
> +                             out->qscale_table,
> +                             out->motion_val,
> +                             out->mb_width, out->mb_height, out->mb_stride, 1);
> +#endif
>      }
>
>      return 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".
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH] avcodec: Use preprocessors conditions
@ 2023-01-17 14:31 pawday-at-mail.ru
  2023-01-17 15:38 ` Hendrik Leppkes
  0 siblings, 1 reply; 5+ messages in thread
From: pawday-at-mail.ru @ 2023-01-17 14:31 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Pawday

From: Pawday <pawday@mail.ru>

Thank you Andreas Rheinhardt for review

Here the fixes for runtime "else" conditions

---
 libavcodec/avcodec.c | 16 +++++++++++-----
 libavcodec/decode.c  | 11 ++++++++---
 libavcodec/encode.c  | 13 ++++++++-----
 libavcodec/h264dec.c | 14 +++++++-------
 4 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a85d3c2309..0e792aead9 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -403,10 +403,13 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
     av_frame_unref(avci->buffer_frame);
     av_packet_unref(avci->buffer_pkt);
 
-    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
+#if HAVE_THREADS
+    if (avctx->active_thread_type & FF_THREAD_FRAME)
         ff_thread_flush(avctx);
-    else if (ffcodec(avctx->codec)->flush)
+#else
+    if (ffcodec(avctx->codec)->flush)
         ffcodec(avctx->codec)->flush(avctx);
+#endif
 }
 
 void avsubtitle_free(AVSubtitle *sub)
@@ -441,12 +444,15 @@ av_cold int avcodec_close(AVCodecContext *avctx)
     if (avcodec_is_open(avctx)) {
         AVCodecInternal *avci = avctx->internal;
 
-        if (CONFIG_FRAME_THREAD_ENCODER &&
-            avci->frame_thread_encoder && avctx->thread_count > 1) {
+#if CONFIG_FRAME_THREAD_ENCODER
+        if (avci->frame_thread_encoder && avctx->thread_count > 1) {
             ff_frame_thread_encoder_free(avctx);
         }
-        if (HAVE_THREADS && avci->thread_ctx)
+#endif
+#if HAVE_THREADS
+        if (avci->thread_ctx)
             ff_thread_free(avctx);
+#endif
         if (avci->needs_close && ffcodec(avctx->codec)->close)
             ffcodec(avctx->codec)->close(avctx);
         avci->byte_buffer_size = 0;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..54ffd0f203 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -300,10 +300,14 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
         return AVERROR_EOF;
 
     got_frame = 0;
-
-    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
+#if HAVE_THREADS
+    if (avctx->active_thread_type & FF_THREAD_FRAME) {
         ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
-    } else {
+    }
+#endif
+
+#if !HAVE_THREADS
+    if (!(avctx->active_thread_type & FF_THREAD_FRAME)) {
         ret = codec->cb.decode(avctx, frame, &got_frame, pkt);
 
         if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
@@ -321,6 +325,7 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
             }
         }
     }
+#endif
     emms_c();
     actual_got_frame = got_frame;
 
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index fbe2c97cd6..b19599e67e 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -269,17 +269,20 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
     got_packet = 0;
 
     av_assert0(codec->cb_type == FF_CODEC_CB_TYPE_ENCODE);
-
-    if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
+#if CONFIG_FRAME_THREAD_ENCODER
+    if (avci->frame_thread_encoder)
         /* This will unref frame. */
         ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
-    else {
+#endif
+#if !CONFIG_FRAME_THREAD_ENCODER
+    if (!avci->frame_thread_encoder) {
         ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
 #if FF_API_THREAD_SAFE_CALLBACKS
         if (frame)
             av_frame_unref(frame);
 #endif
     }
+#endif // !CONFIG_FRAME_THREAD_ENCODER
 
     if (avci->draining && !got_packet)
         avci->draining_done = 1;
@@ -670,11 +673,11 @@ int ff_encode_preinit(AVCodecContext *avctx)
             return AVERROR(ENOMEM);
     }
 
-    if (CONFIG_FRAME_THREAD_ENCODER) {
+#if CONFIG_FRAME_THREAD_ENCODER
         ret = ff_frame_thread_encoder_init(avctx);
         if (ret < 0)
             return ret;
-    }
+#endif
 
     return 0;
 }
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 6ede4e8c9f..4538974dab 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -933,13 +933,13 @@ static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *g
 
         *got_frame = 1;
 
-        if (CONFIG_MPEGVIDEODEC) {
-            ff_print_debug_info2(h->avctx, dst, NULL,
-                                 out->mb_type,
-                                 out->qscale_table,
-                                 out->motion_val,
-                                 out->mb_width, out->mb_height, out->mb_stride, 1);
-        }
+#if CONFIG_MPEGVIDEODEC
+        ff_print_debug_info2(h->avctx, dst, NULL,
+                             out->mb_type,
+                             out->qscale_table,
+                             out->motion_val,
+                             out->mb_width, out->mb_height, out->mb_stride, 1);
+#endif
     }
 
     return 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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-17 19:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 11:38 [FFmpeg-devel] [PATCH] avcodec: Use preprocessors conditions pawday-at-mail.ru
2023-01-17 12:04 ` Andreas Rheinhardt
2023-01-17 14:31 pawday-at-mail.ru
2023-01-17 15:38 ` Hendrik Leppkes
2023-01-17 19:37 pawday-at-mail.ru

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