[vlc-commits] block: have block_Init() set the callbacks

Rémi Denis-Courmont git at videolan.org
Sun Jul 8 19:48:34 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul  8 20:31:20 2018 +0300| [0642c2efd20932a8bb8967c3798e26b060f30adb] | committer: Rémi Denis-Courmont

block: have block_Init() set the callbacks

Also document block_Init().

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0642c2efd20932a8bb8967c3798e26b060f30adb
---

 include/vlc_block.h             | 20 +++++++++++++++++++-
 modules/access/screen/win32.c   |  3 +--
 modules/codec/avcodec/audio.c   |  4 ++--
 modules/codec/avcodec/encoder.c |  2 +-
 src/misc/block.c                | 23 +++++++++--------------
 5 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/include/vlc_block.h b/include/vlc_block.h
index 55a05a666d..dd1e32e3cb 100644
--- a/include/vlc_block.h
+++ b/include/vlc_block.h
@@ -131,7 +131,25 @@ struct block_t
     const struct vlc_block_callbacks *cbs;
 };
 
-VLC_API void block_Init( block_t *, void *, size_t );
+/**
+ * Initializes a custom block.
+ *
+ * This function initialize a block of timed data allocated by custom means.
+ * This allows passing data with copying even if the data has been allocated
+ * with unusual means or outside of LibVLC.
+ *
+ * Normally, blocks are allocated and initialized by block_Alloc() instead.
+ *
+ * @param block allocated block structure to initialize
+ * @param cbs structure of custom callbacks to handle the block [IN]
+ * @param base start address of the block data
+ * @param length byte length of the block data
+ *
+ * @return @c block (this function cannot fail)
+ */
+VLC_API block_t *block_Init(block_t *block,
+                            const struct vlc_block_callbacks *cbs,
+                            void *base, size_t length);
 
 /**
  * Allocates a block.
diff --git a/modules/access/screen/win32.c b/modules/access/screen/win32.c
index 067e166879..478602ab83 100644
--- a/modules/access/screen/win32.c
+++ b/modules/access/screen/win32.c
@@ -264,8 +264,7 @@ static block_t *CaptureBlockNew( demux_t *p_demux )
     int i_stride =
         ( ( ( ( p_sys->fmt.video.i_width * p_sys->fmt.video.i_bits_per_pixel ) + 31 ) & ~31 ) >> 3 );
     i_buffer = i_stride * p_sys->fmt.video.i_height;
-    block_Init( &p_block->self, p_buffer, i_buffer );
-    p_block->self.cbs = &CaptureBlockCallbacks;
+    block_Init( &p_block->self, &CaptureBlockCallbacks, p_buffer, i_buffer );
     p_block->hbmp            = hbmp;
 
     return &p_block->self;
diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index d9948f0814..c8c2c4e7d7 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -188,9 +188,9 @@ static block_t *vlc_av_frame_Wrap(AVFrame *frame)
 
     block_t *block = &b->self;
 
-    block_Init(block, frame->extended_data[0], frame->linesize[0]);
+    block_Init(block, &vlc_av_frame_cbs,
+               frame->extended_data[0], frame->linesize[0]);
     block->i_nb_samples = frame->nb_samples;
-    block->cbs = &vlc_av_frame_cbs;
     b->frame = frame;
     return block;
 }
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 0853d47f0c..a00439e939 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -1088,7 +1088,7 @@ static block_t *vlc_av_packet_Wrap(AVPacket *packet, vlc_tick_t i_length, AVCode
 
     block_t *p_block = &b->self;
 
-    block_Init( p_block, packet->data, packet->size );
+    block_Init( p_block, &vlc_av_packet_cbs, packet->data, packet->size );
     p_block->i_nb_samples = 0;
     p_block->cbs = &vlc_av_packet_cbs;
     b->packet = *packet;
diff --git a/src/misc/block.c b/src/misc/block.c
index 3c75d81f4c..28cf608e70 100644
--- a/src/misc/block.c
+++ b/src/misc/block.c
@@ -78,7 +78,8 @@ static void block_Invalidate (block_t *block)
 # define block_Invalidate(b) ((void)(b))
 #endif
 
-void block_Init( block_t *restrict b, void *buf, size_t size )
+block_t *block_Init(block_t *restrict b, const struct vlc_block_callbacks *cbs,
+                    void *buf, size_t size)
 {
     /* Fill all fields to their default */
     b->p_next = NULL;
@@ -91,9 +92,8 @@ void block_Init( block_t *restrict b, void *buf, size_t size )
     b->i_pts =
     b->i_dts = VLC_TICK_INVALID;
     b->i_length = 0;
-#ifndef NDEBUG
-    b->cbs = &block_invalid_cbs;
-#endif
+    b->cbs = cbs;
+    return b;
 }
 
 static void block_generic_Release (block_t *block)
@@ -145,13 +145,12 @@ block_t *block_Alloc (size_t size)
     if (unlikely(b == NULL))
         return NULL;
 
-    block_Init (b, b + 1, alloc - sizeof (*b));
+    block_Init(b, &block_generic_cbs, b + 1, alloc - sizeof (*b));
     static_assert ((BLOCK_PADDING % BLOCK_ALIGN) == 0,
                    "BLOCK_PADDING must be a multiple of BLOCK_ALIGN");
     b->p_buffer += BLOCK_PADDING + BLOCK_ALIGN - 1;
     b->p_buffer = (void *)(((uintptr_t)b->p_buffer) & ~(BLOCK_ALIGN - 1));
     b->i_buffer = size;
-    b->cbs = &block_generic_cbs;
     return b;
 }
 
@@ -275,9 +274,7 @@ block_t *block_heap_Alloc (void *addr, size_t length)
         return NULL;
     }
 
-    block_Init (block, addr, length);
-    block->cbs = &block_heap_cbs;
-    return block;
+    return block_Init(block, &block_heap_cbs, addr, length);
 }
 
 #ifdef HAVE_MMAP
@@ -311,10 +308,10 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
         return NULL;
     }
 
-    block_Init (block, ((char *)addr) - left, left + length + right);
+    block_Init(block, &block_mmap_cbs,
+               ((char *)addr) - left, left + length + right);
     block->p_buffer = addr;
     block->i_buffer = length;
-    block->cbs = &block_mmap_cbs;
     return block;
 }
 #else
@@ -355,10 +352,8 @@ block_t *block_shm_Alloc (void *addr, size_t length)
         return NULL;
     }
 
-    block_Init (&block->self, (uint8_t *)addr, length);
-    block->self.cbs = &block_shm_cbs;
     block->base_addr = addr;
-    return &block->self;
+    return block_Init(&block->self, &block_shm_cbs, (uint8_t *)addr, length);
 }
 #else
 block_t *block_shm_Alloc (void *addr, size_t length)



More information about the vlc-commits mailing list