[vlc-commits] [Git][videolan/vlc][master] 2 commits: codec: videotoolbox: rename pic pacer variables

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Nov 29 17:39:35 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
a3ee9cb0 by François Cartegnie at 2023-11-29T17:25:06+00:00
codec: videotoolbox: rename pic pacer variables

- - - - -
592e5b29 by François Cartegnie at 2023-11-29T17:25:06+00:00
codec: videotoolbox: split pic_pacer

- - - - -


4 changed files:

- modules/codec/Makefile.am
- modules/codec/videotoolbox/decoder.c
- + modules/codec/videotoolbox/pacer.c
- + modules/codec/videotoolbox/pacer.h


Changes:

=====================================
modules/codec/Makefile.am
=====================================
@@ -350,7 +350,9 @@ liboggspots_plugin_la_LIBADD = $(OGGSPOTS_LIBS)
 EXTRA_LTLIBRARIES += liboggspots_plugin.la
 codec_LTLIBRARIES += $(LTLIBoggspots)
 
-libvideotoolbox_plugin_la_SOURCES = codec/videotoolbox/decoder.c
+libvideotoolbox_plugin_la_SOURCES = codec/videotoolbox/decoder.c \
+                                    codec/videotoolbox/pacer.c \
+                                    codec/videotoolbox/pacer.h
 libvideotoolbox_plugin_la_LIBADD = libchroma_copy.la libvlc_hxxxhelper.la libvlc_vtutils.la
 libvideotoolbox_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreFoundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo -Wl,-framework,Metal
 if HAVE_DARWIN


=====================================
modules/codec/videotoolbox/decoder.c
=====================================
@@ -37,6 +37,7 @@
 #import "../../packetizer/h264_slice.h"
 #import "../../packetizer/hxxx_nal.h"
 #import "../../packetizer/hxxx_sei.h"
+#import "pacer.h"
 
 #import <VideoToolbox/VideoToolbox.h>
 #import <VideoToolbox/VTErrors.h>
@@ -165,84 +166,11 @@ typedef struct decoder_sys_t
     date_t                      pts;
 
     vlc_video_context          *vctx;
+    /* Picture pacer to work-around the VT session allocating too many CVPX buffers
+     * that can lead to a OOM. */
     struct pic_pacer           *pic_pacer;
 } decoder_sys_t;
 
-/* Picture pacer to work-around the VT session allocating too much CVPX buffers
- * that can lead to a OOM. */
-struct pic_pacer
-{
-    vlc_mutex_t lock;
-    vlc_cond_t  wait;
-    uint8_t     nb_out;
-    uint8_t     allocated_max;
-    uint8_t     allocated_next;
-    uint8_t     queued_for_decode;
-};
-
-#define PIC_PACER_ALLOCATABLE_MAX (1 /* callback, pre-reorder */ \
-                                 + 2 /* filters */ \
-                                 + 1 /* display */ \
-                                 + 1 /* next/prev display */)
-#define PIC_PACER_DECODE_QUEUE 4  /* max async decode before callback */
-//#define PIC_PACER_DEBUG
-static void pic_pacer_UpdateReorderMax(struct pic_pacer *, uint8_t);
-
-static void pic_pacer_Destroy(void *priv)
-{
-    (void) priv;
-}
-
-static void pic_pacer_Init(struct pic_pacer *pic_pacer)
-{
-    vlc_mutex_init(&pic_pacer->lock);
-    vlc_cond_init(&pic_pacer->wait);
-    pic_pacer->nb_out = 0;
-    pic_pacer->allocated_max = 6;
-    pic_pacer->allocated_next = pic_pacer->allocated_max;
-    pic_pacer->queued_for_decode = 0;
-}
-
-static void pic_pacer_AccountAllocation(struct pic_pacer *pic_pacer)
-{
-    vlc_mutex_lock(&pic_pacer->lock);
-    pic_pacer->nb_out += 1;
-    vlc_mutex_unlock(&pic_pacer->lock);
-}
-
-static void pic_pacer_AccountScheduledDecode(struct pic_pacer *pic_pacer)
-{
-    vlc_mutex_lock(&pic_pacer->lock);
-    pic_pacer->queued_for_decode += 1;
-    vlc_mutex_unlock(&pic_pacer->lock);
-}
-
-static void pic_pacer_AccountFinishedDecode(struct pic_pacer *pic_pacer)
-{
-    vlc_mutex_lock(&pic_pacer->lock);
-    pic_pacer->queued_for_decode -= 1;
-    vlc_cond_signal(&pic_pacer->wait);
-    vlc_mutex_unlock(&pic_pacer->lock);
-}
-
-static void pic_pacer_WaitAllocatableSlot(struct pic_pacer *pic_pacer)
-{
-    vlc_mutex_lock(&pic_pacer->lock);
-    uint8_t allocatable_total = pic_pacer->allocated_max + PIC_PACER_DECODE_QUEUE;
-
-    while( pic_pacer->queued_for_decode + pic_pacer->nb_out >= allocatable_total )
-    {
-#ifdef PIC_PACER_DEBUG
-        fprintf(stderr, "input pacing %d+%d >= %d\n",
-                pic_pacer->queued_for_decode, pic_pacer->nb_out, allocatable_total);
-#endif
-        vlc_cond_wait(&pic_pacer->wait, &pic_pacer->lock);
-        /*update*/
-        allocatable_total = pic_pacer->allocated_max + PIC_PACER_DECODE_QUEUE;
-    }
-    vlc_mutex_unlock(&pic_pacer->lock);
-}
-
 #pragma mark - start & stop
 
 static OSType GetBestChroma(uint8_t i_chroma_format, uint8_t i_depth_luma,
@@ -1067,7 +995,7 @@ static void OnDecodedFrame(decoder_t *p_dec, frame_info_t *p_info)
        p_info->i_max_reorder != p_sys->i_pic_reorder_max)
     {
         p_sys->i_pic_reorder_max = p_info->i_max_reorder;
-        pic_pacer_UpdateReorderMax(p_sys->pic_pacer, p_sys->i_pic_reorder_max);
+        pic_pacer_UpdateMaxBuffering(p_sys->pic_pacer, p_sys->i_pic_reorder_max);
     }
 
     while(p_info->b_flush || p_sys->i_pic_reorder >= p_sys->i_pic_reorder_max)
@@ -1080,7 +1008,7 @@ static void OnDecodedFrame(decoder_t *p_dec, frame_info_t *p_info)
             {
                 p_sys->b_invalid_pic_reorder_max = true;
                 p_sys->i_pic_reorder_max++;
-                pic_pacer_UpdateReorderMax(p_sys->pic_pacer, p_sys->i_pic_reorder_max);
+                pic_pacer_UpdateMaxBuffering(p_sys->pic_pacer, p_sys->i_pic_reorder_max);
                 msg_Dbg(p_dec, "Raising max DPB to %"PRIu8, p_sys->i_pic_reorder_max);
                 break;
             }
@@ -1090,7 +1018,7 @@ static void OnDecodedFrame(decoder_t *p_dec, frame_info_t *p_info)
             {
                 p_sys->b_invalid_pic_reorder_max = true;
                 p_sys->i_pic_reorder_max++;
-                pic_pacer_UpdateReorderMax(p_sys->pic_pacer, p_sys->i_pic_reorder_max);
+                pic_pacer_UpdateMaxBuffering(p_sys->pic_pacer, p_sys->i_pic_reorder_max);
                 msg_Dbg(p_dec, "Raising max DPB to %"PRIu8, p_sys->i_pic_reorder_max);
                 break;
             }
@@ -1452,6 +1380,11 @@ static void StopVideoToolbox(decoder_t *p_dec)
 
 #pragma mark - module open and close
 
+static void pic_pacer_Destroy(void *priv)
+{
+    pic_pacer_Clean((struct pic_pacer *) priv);
+}
+
 static int
 CreateVideoContext(decoder_t *p_dec)
 {
@@ -2285,43 +2218,7 @@ video_context_OnPicReleased(vlc_video_context *vctx, unsigned nb_fields)
         vlc_video_context_GetCVPXPrivate(vctx, CVPX_VIDEO_CONTEXT_VIDEOTOOLBOX);
     VLC_UNUSED(nb_fields);
 
-    vlc_mutex_lock(&pic_pacer->lock);
-    assert(pic_pacer->nb_out > 0);
-    pic_pacer->nb_out -= 1;
-
-    /* our shrink condition */
-    if(pic_pacer->allocated_next < pic_pacer->allocated_max &&
-       pic_pacer->nb_out <= pic_pacer->allocated_next)
-        pic_pacer->allocated_max = pic_pacer->allocated_next;
-
-    vlc_cond_signal(&pic_pacer->wait);
-
-    vlc_mutex_unlock(&pic_pacer->lock);
-}
-
-static void
-pic_pacer_UpdateReorderMax(struct pic_pacer *pic_pacer, uint8_t pic_reorder_max)
-{
-    vlc_mutex_lock(&pic_pacer->lock);
-
-    pic_reorder_max += PIC_PACER_ALLOCATABLE_MAX;
-    bool b_growing  = pic_reorder_max > pic_pacer->allocated_max;
-#ifdef PIC_PACER_DEBUG
-    fprintf(stderr, "updating pacer max %d/%d to %d\n",
-            pic_pacer->nb_out, pic_pacer->allocated_max, pic_reorder_max);
-#endif
-    if(b_growing)
-    {
-        pic_pacer->allocated_max = pic_reorder_max;
-        pic_pacer->allocated_next = pic_reorder_max;
-        vlc_cond_signal(&pic_pacer->wait);
-    }
-    else
-    {
-        pic_pacer->allocated_next = pic_reorder_max;
-    }
-
-    vlc_mutex_unlock(&pic_pacer->lock);
+    pic_pacer_AccountDeallocation(pic_pacer);
 }
 
 static void DecoderCallback(void *decompressionOutputRefCon,


=====================================
modules/codec/videotoolbox/pacer.c
=====================================
@@ -0,0 +1,128 @@
+/*****************************************************************************
+ * pacer.c: decoder picture output pacing
+ *****************************************************************************
+ * Copyright © 2017-2022 VideoLabs, VideoLAN and VLC authors
+  *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#include <vlc_common.h>
+#include <vlc_threads.h>
+
+//#define PIC_PACER_DEBUG
+
+#include "pacer.h"
+
+#include <assert.h>
+
+#define PIC_PACER_ALLOCATABLE_MAX (1 /* callback, pre-reorder */ \
+                                 + 2 /* filters */ \
+                                 + 1 /* display */ \
+                                 + 1 /* next/prev display */)
+#define PIC_PACER_DECODE_QUEUE 4  /* max async decode before callback */
+
+void pic_pacer_Clean(struct pic_pacer *pic_pacer)
+{
+    (void) pic_pacer;
+}
+
+void pic_pacer_Init(struct pic_pacer *pic_pacer)
+{
+    vlc_mutex_init(&pic_pacer->lock);
+    vlc_cond_init(&pic_pacer->wait);
+    pic_pacer->nb_out = 0;
+    pic_pacer->allocated_max = 6;
+    pic_pacer->allocated_next = pic_pacer->allocated_max;
+    pic_pacer->queued_for_decode = 0;
+}
+
+void pic_pacer_AccountAllocation(struct pic_pacer *pic_pacer)
+{
+    vlc_mutex_lock(&pic_pacer->lock);
+    pic_pacer->nb_out += 1;
+    vlc_mutex_unlock(&pic_pacer->lock);
+}
+
+void pic_pacer_AccountScheduledDecode(struct pic_pacer *pic_pacer)
+{
+    vlc_mutex_lock(&pic_pacer->lock);
+    pic_pacer->queued_for_decode += 1;
+    vlc_mutex_unlock(&pic_pacer->lock);
+}
+
+void pic_pacer_AccountFinishedDecode(struct pic_pacer *pic_pacer)
+{
+    vlc_mutex_lock(&pic_pacer->lock);
+    pic_pacer->queued_for_decode -= 1;
+    vlc_cond_signal(&pic_pacer->wait);
+    vlc_mutex_unlock(&pic_pacer->lock);
+}
+
+void pic_pacer_WaitAllocatableSlot(struct pic_pacer *pic_pacer)
+{
+    vlc_mutex_lock(&pic_pacer->lock);
+    uint8_t allocatable_total = pic_pacer->allocated_max + PIC_PACER_DECODE_QUEUE;
+
+    while( pic_pacer->queued_for_decode + pic_pacer->nb_out >= allocatable_total )
+    {
+#ifdef PIC_PACER_DEBUG
+        fprintf(stderr, "input pacing %d+%d >= %d\n",
+                pic_pacer->queued_for_decode, pic_pacer->nb_out, allocatable_total);
+#endif
+        vlc_cond_wait(&pic_pacer->wait, &pic_pacer->lock);
+        /*update*/
+        allocatable_total = pic_pacer->allocated_max + PIC_PACER_DECODE_QUEUE;
+    }
+    vlc_mutex_unlock(&pic_pacer->lock);
+}
+
+void pic_pacer_AccountDeallocation(struct pic_pacer *pic_pacer)
+{
+    vlc_mutex_lock(&pic_pacer->lock);
+    assert(pic_pacer->nb_out > 0);
+    pic_pacer->nb_out -= 1;
+
+    /* our shrink condition */
+    if(pic_pacer->allocated_next < pic_pacer->allocated_max &&
+        pic_pacer->nb_out <= pic_pacer->allocated_next)
+        pic_pacer->allocated_max = pic_pacer->allocated_next;
+
+    vlc_cond_signal(&pic_pacer->wait);
+
+    vlc_mutex_unlock(&pic_pacer->lock);
+}
+
+void pic_pacer_UpdateMaxBuffering(struct pic_pacer *pic_pacer, uint8_t pic_max)
+{
+    vlc_mutex_lock(&pic_pacer->lock);
+
+    pic_max += PIC_PACER_ALLOCATABLE_MAX;
+    bool b_growing  = pic_max > pic_pacer->allocated_max;
+#ifdef PIC_PACER_DEBUG
+    fprintf(stderr, "updating pacer max %d/%d to %d\n",
+            pic_pacer->nb_out, pic_pacer->allocated_max, pic_reorder_max);
+#endif
+    if(b_growing)
+    {
+        pic_pacer->allocated_max = pic_max;
+        pic_pacer->allocated_next = pic_max;
+        vlc_cond_signal(&pic_pacer->wait);
+    }
+    else
+    {
+        pic_pacer->allocated_next = pic_max;
+    }
+
+    vlc_mutex_unlock(&pic_pacer->lock);
+}


=====================================
modules/codec/videotoolbox/pacer.h
=====================================
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * pacer.h: decoder picture output pacing
+ *****************************************************************************
+ * Copyright © 2017-2022 VideoLabs, VideoLAN and VLC authors
+  *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef VIDEOTOOLBOX_PACER_H
+#define VIDEOTOOLBOX_PACER_H
+
+struct pic_pacer
+{
+    vlc_mutex_t lock;
+    vlc_cond_t  wait;
+    uint8_t     nb_out;
+    uint8_t     allocated_max;
+    uint8_t     allocated_next;
+    uint8_t     queued_for_decode;
+};
+
+void pic_pacer_Clean(struct pic_pacer *);
+
+void pic_pacer_Init(struct pic_pacer *);
+
+void pic_pacer_AccountAllocation(struct pic_pacer *);
+
+void pic_pacer_AccountScheduledDecode(struct pic_pacer *);
+
+void pic_pacer_AccountFinishedDecode(struct pic_pacer *);
+
+void pic_pacer_WaitAllocatableSlot(struct pic_pacer *);
+
+void pic_pacer_AccountDeallocation(struct pic_pacer *);
+
+void pic_pacer_UpdateMaxBuffering(struct pic_pacer *, uint8_t);
+
+#endif // VIDEOTOOLBOX_PACER_H



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4e1a51d8ea35f3487d704289ab968c9b192190d3...592e5b2942bf304e50f04aad2b5eca1926ba8e9c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4e1a51d8ea35f3487d704289ab968c9b192190d3...592e5b2942bf304e50f04aad2b5eca1926ba8e9c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list