[vlc-commits] block: move callback to separate const structure
Rémi Denis-Courmont
git at videolan.org
Sun Jul 8 19:48:30 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 8 20:20:09 2018 +0300| [a17540a52174bd77f4e958d31aead357b2cbb8c5] | committer: Rémi Denis-Courmont
block: move callback to separate const structure
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a17540a52174bd77f4e958d31aead357b2cbb8c5
---
include/vlc_block.h | 10 ++++++----
modules/access/screen/win32.c | 7 ++++++-
modules/codec/avcodec/audio.c | 7 ++++++-
modules/codec/avcodec/encoder.c | 7 ++++++-
src/misc/block.c | 39 ++++++++++++++++++++++++++++++++-------
5 files changed, 56 insertions(+), 14 deletions(-)
diff --git a/include/vlc_block.h b/include/vlc_block.h
index e6aae5e56b..55a05a666d 100644
--- a/include/vlc_block.h
+++ b/include/vlc_block.h
@@ -107,7 +107,10 @@
#define BLOCK_FLAG_PRIVATE_MASK 0xff000000
#define BLOCK_FLAG_PRIVATE_SHIFT 24
-typedef void (*block_free_t) (block_t *);
+struct vlc_block_callbacks
+{
+ void (*free)(block_t *);
+};
struct block_t
{
@@ -125,8 +128,7 @@ struct block_t
vlc_tick_t i_dts;
vlc_tick_t i_length;
- /* Rudimentary support for overloading block (de)allocation. */
- block_free_t pf_release;
+ const struct vlc_block_callbacks *cbs;
};
VLC_API void block_Init( block_t *, void *, size_t );
@@ -181,7 +183,7 @@ VLC_API block_t *block_Realloc(block_t *, ssize_t pre, size_t body) VLC_USED;
*/
static inline void block_Release(block_t *block)
{
- block->pf_release(block);
+ block->cbs->free(block);
}
static inline void block_CopyProperties( block_t *dst, block_t *src )
diff --git a/modules/access/screen/win32.c b/modules/access/screen/win32.c
index 03cbdaf284..067e166879 100644
--- a/modules/access/screen/win32.c
+++ b/modules/access/screen/win32.c
@@ -193,6 +193,11 @@ static void CaptureBlockRelease( block_t *p_block )
free( p_block );
}
+static const struct vlc_block_callbacks CaptureBlockCallbacks =
+{
+ CaptureBlockRelease,
+};
+
static block_t *CaptureBlockNew( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
@@ -260,7 +265,7 @@ static block_t *CaptureBlockNew( demux_t *p_demux )
( ( ( ( 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.pf_release = CaptureBlockRelease;
+ p_block->self.cbs = &CaptureBlockCallbacks;
p_block->hbmp = hbmp;
return &p_block->self;
diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 4be9d979f3..d9948f0814 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -169,6 +169,11 @@ static void vlc_av_frame_Release(block_t *block)
free(b);
}
+static const struct vlc_block_callbacks vlc_av_frame_cbs =
+{
+ vlc_av_frame_Release,
+};
+
static block_t *vlc_av_frame_Wrap(AVFrame *frame)
{
for (unsigned i = 1; i < AV_NUM_DATA_POINTERS; i++)
@@ -185,7 +190,7 @@ static block_t *vlc_av_frame_Wrap(AVFrame *frame)
block_Init(block, frame->extended_data[0], frame->linesize[0]);
block->i_nb_samples = frame->nb_samples;
- block->pf_release = vlc_av_frame_Release;
+ 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 893146f6f0..0853d47f0c 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -1069,6 +1069,11 @@ static void vlc_av_packet_Release(block_t *block)
free(b);
}
+static const struct vlc_block_callbacks vlc_av_packet_cbs =
+{
+ vlc_av_packet_Release,
+};
+
static block_t *vlc_av_packet_Wrap(AVPacket *packet, vlc_tick_t i_length, AVCodecContext *context )
{
if ( packet->data == NULL &&
@@ -1085,7 +1090,7 @@ static block_t *vlc_av_packet_Wrap(AVPacket *packet, vlc_tick_t i_length, AVCode
block_Init( p_block, packet->data, packet->size );
p_block->i_nb_samples = 0;
- p_block->pf_release = vlc_av_packet_Release;
+ p_block->cbs = &vlc_av_packet_cbs;
b->packet = *packet;
p_block->i_length = i_length;
diff --git a/src/misc/block.c b/src/misc/block.c
index 3fa279ccd1..3c75d81f4c 100644
--- a/src/misc/block.c
+++ b/src/misc/block.c
@@ -43,6 +43,11 @@ static void BlockNoRelease( block_t *b )
abort();
}
+static const struct vlc_block_callbacks block_invalid_cbs =
+{
+ BlockNoRelease,
+};
+
static void block_Check (block_t *block)
{
while (block != NULL)
@@ -52,7 +57,7 @@ static void block_Check (block_t *block)
unsigned char *bufstart = block->p_buffer;
unsigned char *bufend = block->p_buffer + block->i_buffer;
- assert (block->pf_release != BlockNoRelease);
+ assert(block->cbs != &block_invalid_cbs);
assert (start <= end);
assert (bufstart <= bufend);
assert (bufstart >= start);
@@ -66,7 +71,7 @@ static void block_Invalidate (block_t *block)
{
block->p_next = NULL;
block_Check (block);
- block->pf_release = BlockNoRelease;
+ block->cbs = &block_invalid_cbs;
}
#else
# define block_Check(b) ((void)(b))
@@ -87,7 +92,7 @@ void block_Init( block_t *restrict b, void *buf, size_t size )
b->i_dts = VLC_TICK_INVALID;
b->i_length = 0;
#ifndef NDEBUG
- b->pf_release = BlockNoRelease;
+ b->cbs = &block_invalid_cbs;
#endif
}
@@ -99,6 +104,11 @@ static void block_generic_Release (block_t *block)
free (block);
}
+static const struct vlc_block_callbacks block_generic_cbs =
+{
+ block_generic_Release,
+};
+
static void BlockMetaCopy( block_t *restrict out, const block_t *in )
{
out->p_next = in->p_next;
@@ -141,7 +151,7 @@ block_t *block_Alloc (size_t size)
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->pf_release = block_generic_Release;
+ b->cbs = &block_generic_cbs;
return b;
}
@@ -251,6 +261,11 @@ static void block_heap_Release (block_t *block)
free (block);
}
+static const struct vlc_block_callbacks block_heap_cbs =
+{
+ block_heap_Release,
+};
+
block_t *block_heap_Alloc (void *addr, size_t length)
{
block_t *block = malloc (sizeof (*block));
@@ -261,7 +276,7 @@ block_t *block_heap_Alloc (void *addr, size_t length)
}
block_Init (block, addr, length);
- block->pf_release = block_heap_Release;
+ block->cbs = &block_heap_cbs;
return block;
}
@@ -275,6 +290,11 @@ static void block_mmap_Release (block_t *block)
free (block);
}
+static const struct vlc_block_callbacks block_mmap_cbs =
+{
+ block_mmap_Release,
+};
+
block_t *block_mmap_Alloc (void *addr, size_t length)
{
if (addr == MAP_FAILED)
@@ -294,7 +314,7 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
block_Init (block, ((char *)addr) - left, left + length + right);
block->p_buffer = addr;
block->i_buffer = length;
- block->pf_release = block_mmap_Release;
+ block->cbs = &block_mmap_cbs;
return block;
}
#else
@@ -321,6 +341,11 @@ static void block_shm_Release (block_t *block)
free (p_sys);
}
+static const struct vlc_block_callbacks block_shm_cbs =
+{
+ block_shm_Release,
+};
+
block_t *block_shm_Alloc (void *addr, size_t length)
{
block_shm_t *block = malloc (sizeof (*block));
@@ -331,7 +356,7 @@ block_t *block_shm_Alloc (void *addr, size_t length)
}
block_Init (&block->self, (uint8_t *)addr, length);
- block->self.pf_release = block_shm_Release;
+ block->self.cbs = &block_shm_cbs;
block->base_addr = addr;
return &block->self;
}
More information about the vlc-commits
mailing list