[vlc-commits] [Git][videolan/vlc][master] 8 commits: block: refactor block duplication

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu Dec 23 21:38:39 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
d1a5137a by Thomas Guillem at 2021-12-23T21:24:01+00:00
block: refactor block duplication

- - - - -
0ba9fb3e by Thomas Guillem at 2021-12-23T21:24:01+00:00
core: move block.c to frame.c

No functional changes

Refs #18762

- - - - -
66dcab31 by Thomas Guillem at 2021-12-23T21:24:01+00:00
core: move block management from vlc_block.h to vlc_frame.h

Refs #18762

- - - - -
173b0ed2 by Thomas Guillem at 2021-12-23T21:24:01+00:00
http: always use a block_t

- - - - -
dd1c4288 by Thomas Guillem at 2021-12-23T21:24:01+00:00
core: rename block_t to vlc_frame_t

But leave the old block_t name via
 - typedef struct vlc_frame_t block_t;
 - defines of functions, struct and defines

vlc_fifo will be handled in the next commit.

Refs #18762

- - - - -
fbbc06b6 by Thomas Guillem at 2021-12-23T21:24:01+00:00
core: rename block_fifo_t to vlc_fifo_t

The vlc_fifo_t name already existed and was a typedef to block_fifo_t.

But leave the old block_Fifo/block_fifo_t name via
 - typedef struct vlc_fifo_t block_fifo_t;
 - defines of functions, struct and defines

Refs #18762

- - - - -
27b52c24 by Thomas Guillem at 2021-12-23T21:24:01+00:00
core: document block_t

- - - - -
543d402e by Thomas Guillem at 2021-12-23T21:24:01+00:00
vlc_codec: use vlc_frame_t

- - - - -


21 changed files:

- include/vlc_block.h
- include/vlc_codec.h
- include/vlc_common.h
- + include/vlc_frame.h
- modules/access/http/file.h
- modules/access/http/file_test.c
- modules/access/http/h1conn_test.c
- modules/access/http/h2conn_test.c
- modules/access/http/live.c
- modules/access/http/live.h
- modules/access/http/message.h
- modules/access/http/outfile.h
- modules/access/http/resource.c
- modules/access/http/resource.h
- modules/demux/adaptive/http/Chunk.h
- po/POTFILES.in
- src/Makefile.am
- src/input/decoder.c
- src/libvlccore.sym
- src/misc/fifo.c
- src/misc/block.c → src/misc/frame.c


Changes:

=====================================
include/vlc_block.h
=====================================
@@ -23,752 +23,90 @@
 #ifndef VLC_BLOCK_H
 #define VLC_BLOCK_H 1
 
+#include <vlc_frame.h>
+
 /**
- * \defgroup block Data blocks
+ * \defgroup block
  * \ingroup input
  *
  * Blocks of binary data.
  *
  * @ref block_t is a generic structure to represent a binary blob within VLC.
  * The primary goal of the structure is to avoid memory copying as data is
- * passed around. It is notably used between the \ref demux, the packetizer
- * (if present) and the \ref decoder, and for audio, between the \ref decoder,
- * the audio filters, and the \ref audio_output.
- *
- * @{
- * \file
- * Data block definition and functions
- */
-
-#include <sys/types.h>  /* for ssize_t */
-
-/****************************************************************************
- * block:
- ****************************************************************************
- * - i_flags may not always be set (ie could be 0, even for a key frame
- *      it depends where you receive the buffer (before/after a packetizer
- *      and the demux/packetizer implementations.
- * - i_dts/i_pts could be VLC_TICK_INVALID, it means no pts/dts
- * - i_length: length in microseond of the packet, can be null except in the
- *      sout where it is mandatory.
- *
- * - i_buffer number of valid data pointed by p_buffer
- *      you can freely decrease it but never increase it yourself
- *      (use block_Realloc)
- * - p_buffer: pointer over datas. You should never overwrite it, you can
- *   only incremment it to skip datas, in others cases use block_Realloc
- *   (don't duplicate yourself in a bigger buffer, block_Realloc is
- *   optimised for preheader/postdatas increase)
- ****************************************************************************/
-
-/** The content doesn't follow the last block, possible some blocks in between
- *  have been lost */
-#define BLOCK_FLAG_DISCONTINUITY 0x0001
-/** Intra frame */
-#define BLOCK_FLAG_TYPE_I        0x0002
-/** Inter frame with backward reference only */
-#define BLOCK_FLAG_TYPE_P        0x0004
-/** Inter frame with backward and forward reference */
-#define BLOCK_FLAG_TYPE_B        0x0008
-/** For inter frame when you don't know the real type */
-#define BLOCK_FLAG_TYPE_PB       0x0010
-/** Warn that this block is a header one */
-#define BLOCK_FLAG_HEADER        0x0020
-/** This block contains the last part of a sequence  */
-#define BLOCK_FLAG_END_OF_SEQUENCE 0x0040
-/** This block contains a clock reference */
-#define BLOCK_FLAG_CLOCK         0x0080
-/** This block is scrambled */
-#define BLOCK_FLAG_SCRAMBLED     0x0100
-/** This block has to be decoded but not be displayed */
-#define BLOCK_FLAG_PREROLL       0x0200
-/** This block is corrupted and/or there is data loss  */
-#define BLOCK_FLAG_CORRUPTED     0x0400
-/** This block is last of its access unit */
-#define BLOCK_FLAG_AU_END        0x0800
-/** This block contains an interlaced picture with top field stored first */
-#define BLOCK_FLAG_TOP_FIELD_FIRST 0x1000
-/** This block contains an interlaced picture with bottom field stored first */
-#define BLOCK_FLAG_BOTTOM_FIELD_FIRST 0x2000
-/** This block contains a single field from interlaced picture. */
-#define BLOCK_FLAG_SINGLE_FIELD  0x4000
-
-/** This block contains an interlaced picture */
-#define BLOCK_FLAG_INTERLACED_MASK \
-    (BLOCK_FLAG_TOP_FIELD_FIRST|BLOCK_FLAG_BOTTOM_FIELD_FIRST|BLOCK_FLAG_SINGLE_FIELD)
-
-#define BLOCK_FLAG_TYPE_MASK \
-    (BLOCK_FLAG_TYPE_I|BLOCK_FLAG_TYPE_P|BLOCK_FLAG_TYPE_B|BLOCK_FLAG_TYPE_PB)
-
-/* These are for input core private usage only */
-#define BLOCK_FLAG_CORE_PRIVATE_MASK  0x00ff0000
-#define BLOCK_FLAG_CORE_PRIVATE_SHIFT 16
-
-/* These are for module private usage only */
-#define BLOCK_FLAG_PRIVATE_MASK  0xff000000
-#define BLOCK_FLAG_PRIVATE_SHIFT 24
-
-struct vlc_block_callbacks
-{
-    void (*free)(block_t *);
-};
-
-struct block_t
-{
-    block_t    *p_next;
-
-    uint8_t    *p_buffer; /**< Payload start */
-    size_t      i_buffer; /**< Payload length */
-    uint8_t    *p_start; /**< Buffer start */
-    size_t      i_size; /**< Buffer total size */
-
-    uint32_t    i_flags;
-    unsigned    i_nb_samples; /* Used for audio */
-
-    vlc_tick_t  i_pts;
-    vlc_tick_t  i_dts;
-    vlc_tick_t  i_length;
-
-    const struct vlc_block_callbacks *cbs;
-};
-
-/**
- * Initializes a custom block.
- *
- * This function initialize a block of timed data allocated by custom means.
- * This allows passing data without 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.
- *
- * Creates a new block with the requested size.
- * The block must be released with block_Release().
- *
- * @param size size in bytes (possibly zero)
- * @return the created block, or NULL on memory error.
- */
-VLC_API block_t *block_Alloc(size_t size) VLC_USED VLC_MALLOC;
-
-VLC_API block_t *block_TryRealloc(block_t *, ssize_t pre, size_t body) VLC_USED;
-
-/**
- * Reallocates a block.
- *
- * This function expands, shrinks or moves a data block.
- * In many cases, this function can return without any memory allocation by
- * reusing spare buffer space. Otherwise, a new block is created and data is
- * copied.
- *
- * @param pre count of bytes to prepend if positive,
- *            count of leading bytes to discard if negative
- * @param body new bytes size of the block
- *
- * @return the reallocated block on succes, NULL on error.
- *
- * @note Skipping leading bytes can be achieved directly by subtracting from
- * block_t.i_buffer and adding block_t.p_buffer.
- * @note Discard trailing bytes can be achieved directly by subtracting from
- * block_t.i_buffer.
- * @note On error, the block is discarded.
- * To avoid that, use block_TryRealloc() instead.
- */
-VLC_API block_t *block_Realloc(block_t *, ssize_t pre, size_t body) VLC_USED;
-
-/**
- * Releases a block.
- *
- * This function works for any @ref block_t block, regardless of the way it was
- * allocated.
- *
- * @note
- * If the block is in a chain, this function does <b>not</b> release any
- * subsequent block in the chain. Use block_ChainRelease() for that purpose.
- *
- * @param block block to release (cannot be NULL)
- */
-VLC_API void block_Release(block_t *block);
-
-static inline void block_CopyProperties( block_t *dst, const block_t *src )
-{
-    dst->i_flags   = src->i_flags;
-    dst->i_nb_samples = src->i_nb_samples;
-    dst->i_dts     = src->i_dts;
-    dst->i_pts     = src->i_pts;
-    dst->i_length  = src->i_length;
-}
-
-/**
- * Duplicates a block.
- *
- * Creates a writeable duplicate of a block.
- *
- * @return the duplicate on success, NULL on error.
- */
-VLC_USED
-static inline block_t *block_Duplicate( const block_t *p_block )
-{
-    block_t *p_dup = block_Alloc( p_block->i_buffer );
-    if( p_dup == NULL )
-        return NULL;
-
-    block_CopyProperties( p_dup, p_block );
-    memcpy( p_dup->p_buffer, p_block->p_buffer, p_block->i_buffer );
-
-    return p_dup;
-}
-
-/**
- * Wraps heap in a block.
- *
- * Creates a @ref block_t out of an existing heap allocation.
- * This is provided by LibVLC so that manually heap-allocated blocks can safely
- * be deallocated even after the origin plugin has been unloaded from memory.
- *
- * When block_Release() is called, VLC will free() the specified pointer..
- *
- * @param addr base address of the heap allocation (will be free()'d)
- * @param length bytes length of the heap allocation
- * @return NULL in case of error (ptr free()'d in that case), or a valid
- * block_t pointer.
- */
-VLC_API block_t *block_heap_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
-
-/**
- * Wraps a memory mapping in a block
- *
- * Creates a @ref block_t from a virtual address memory mapping (mmap).
- * This is provided by LibVLC so that mmap blocks can safely be deallocated
- * even after the allocating plugin has been unloaded from memory.
- *
- * @param addr base address of the mapping (as returned by mmap)
- * @param length length (bytes) of the mapping (as passed to mmap)
- * @return NULL if addr is MAP_FAILED, or an error occurred (in the later
- * case, munmap(addr, length) is invoked before returning).
- */
-VLC_API block_t *block_mmap_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
-
-/**
- * Wraps a System V memory segment in a block
- *
- * Creates a @ref block_t from a System V shared memory segment (shmget()).
- * This is provided by LibVLC so that segments can safely be deallocated
- * even after the allocating plugin has been unloaded from memory.
- *
- * @param addr base address of the segment (as returned by shmat())
- * @param length length (bytes) of the segment (as passed to shmget())
- * @return NULL if an error occurred (in that case, shmdt(addr) is invoked
- * before returning NULL).
- */
-VLC_API block_t * block_shm_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
-
-/**
- * Maps a file handle in memory.
- *
- * Loads a file into a block of memory through a file descriptor.
- * If possible a private file mapping is created. Otherwise, the file is read
- * normally. This function is a cancellation point.
- *
- * @note On 32-bits platforms,
- * this function will not work for very large files,
- * due to memory space constraints.
- *
- * @param fd file descriptor to load from
- * @param write If true, request a read/write private mapping.
- *              If false, request a read-only potentially shared mapping..
- *
- * @return a new block with the file content at p_buffer, and file length at
- * i_buffer (release it with block_Release()), or NULL upon error (see errno).
- */
-VLC_API block_t *block_File(int fd, bool write) VLC_USED VLC_MALLOC;
-
-/**
- * Maps a file in memory.
- *
- * Loads a file into a block of memory from a path to the file.
- * See also block_File().
- *
- * @param write If true, request a read/write private mapping.
- *              If false, request a read-only potentially shared mapping..
- */
-VLC_API block_t *block_FilePath(const char *, bool write) VLC_USED VLC_MALLOC;
-
-static inline void block_Cleanup (void *block)
-{
-    block_Release ((block_t *)block);
-}
-#define block_cleanup_push( block ) vlc_cleanup_push (block_Cleanup, block)
-
-/**
- * \defgroup block_chain Block chain
- * @{
- */
-
-/**
- * Appends a @ref block_t to the chain
- *
- * The given block is appended to the last block of the given chain.
- *
- * @attention
- *  Using this function on long chains or repeatedly calling it
- *  to append a lot of blocks can be slow, as it has to iterate the
- *  whole chain to append the block.
- *  In these cases @ref block_ChainLastAppend should be used.
- *
- * @param pp_list   Pointer to the block_t chain
- * @param p_block   The block_t to append (can be NULL)
- *
- * @see block_ChainLastAppend()
- *
- * Example:
- * @code{.c}
- * block_t *p_chain = NULL;
- *
- * block_ChainAppend(&p_chain, p_block);
- * @endcode
- */
-static inline void block_ChainAppend( block_t **pp_list, block_t *p_block )
-{
-    if( *pp_list == NULL )
-    {
-        *pp_list = p_block;
-    }
-    else
-    {
-        block_t *p = *pp_list;
-
-        while( p->p_next ) p = p->p_next;
-        p->p_next = p_block;
-    }
-}
-
-/**
- * Appends a @ref block_t to the last block pointer and update it
- *
- * Uses a pointer over a pointer to p_next of the last block of the block chain
- * to append a block at the end of the chain and updates the pointer to the new
- * last block's @c p_next. If the appended block is itself a chain, it is iterated
- * till the end to correctly update @c ppp_last.
- *
- * @param[in,out] ppp_last  Pointer to pointer to the end of the chain
- *                          (The block_t::p_next of the last block_t in the chain)
- * @param         p_block   The block_t to append
- *
- * Example:
- * @code{.c}
- * block_t *p_block = NULL;
- * block_t **pp_block_last = &p_block;
- *
- * block_ChainLastAppend(&pp_block_last, p_other_block);
- * @endcode
- */
-static inline void block_ChainLastAppend( block_t ***ppp_last, block_t *p_block )
-{
-    block_t *p_last = p_block;
-
-    **ppp_last = p_block;
-
-    while( p_last->p_next ) p_last = p_last->p_next;
-    *ppp_last = &p_last->p_next;
-}
-
-/**
- * Releases a chain of blocks
- *
- * The block pointed to by p_block and all following blocks in the
- * chain are released.
- *
- * @param p_block   Pointer to first block_t of the chain to release
- *
- * @see block_Release()
- */
-static inline void block_ChainRelease( block_t *p_block )
-{
-    while( p_block )
-    {
-        block_t *p_next = p_block->p_next;
-        block_Release( p_block );
-        p_block = p_next;
-    }
-}
-
-/**
- * Extracts data from a chain of blocks
- *
- * Copies the specified amount of data from the chain into the given buffer.
- * If the data in the chain is less than the maximum amount given, the remainder
- * of the buffer is not modified.
- *
- * @param      p_list   Pointer to the first block_t of the chain to copy from
- * @param[out] p_data   Destination buffer to copy the data to
- * @param      i_max    Number of bytes to copy
- * @return              Number of bytes actually copied
- *
- * @see block_ChainGather()
- */
-static size_t block_ChainExtract( block_t *p_list, void *p_data, size_t i_max )
-{
-    size_t  i_total = 0;
-    uint8_t *p = (uint8_t*)p_data;
-
-    while( p_list && i_max )
-    {
-        size_t i_copy = __MIN( i_max, p_list->i_buffer );
-        memcpy( p, p_list->p_buffer, i_copy );
-        i_max   -= i_copy;
-        i_total += i_copy;
-        p       += i_copy;
-
-        p_list = p_list->p_next;
-    }
-    return i_total;
-}
-
-/**
- * Retrives chain properties
- *
- * Can be used to retrieve count of blocks, number of bytes and the duration
- * of the chain.
- *
- * @param       p_list      Pointer to the first block_t of the chain
- * @param[out]  pi_count    Pointer to count of blocks in the chain (may be NULL)
- * @param[out]  pi_size     Pointer to number of bytes in the chain (may be NULL)
- * @param[out]  pi_length   Pointer to length (duration) of the chain (may be NULL)
- */
-static inline void block_ChainProperties( block_t *p_list, int *pi_count, size_t *pi_size, vlc_tick_t *pi_length )
-{
-    size_t i_size = 0;
-    vlc_tick_t i_length = 0;
-    int i_count = 0;
-
-    while( p_list )
-    {
-        i_size += p_list->i_buffer;
-        i_length += p_list->i_length;
-        i_count++;
-
-        p_list = p_list->p_next;
-    }
-
-    if( pi_size )
-        *pi_size = i_size;
-    if( pi_length )
-        *pi_length = i_length;
-    if( pi_count )
-        *pi_count = i_count;
-}
-
-/**
- * Gathers a chain into a single block_t
- *
- * All blocks in the chain are gathered into a single block_t and the
- * original chain is released.
- * 
- * @param   p_list  Pointer to the first block_t of the chain to gather
- * @return  Returns a pointer to a new block_t or NULL if the block can not
- *          be allocated, in which case the original chain is not released.
- *          If the chain pointed to by p_list is already gathered, a pointer
- *          to it is returned and no new block will be allocated.
- *
- * @see block_ChainExtract()
- */
-static inline block_t *block_ChainGather( block_t *p_list )
-{
-    size_t  i_total = 0;
-    vlc_tick_t i_length = 0;
-    block_t *g;
-
-    if( p_list->p_next == NULL )
-        return p_list;  /* Already gathered */
-
-    block_ChainProperties( p_list, NULL, &i_total, &i_length );
-
-    g = block_Alloc( i_total );
-    if( !g )
-        return NULL;
-    block_ChainExtract( p_list, g->p_buffer, g->i_buffer );
-
-    g->i_flags = p_list->i_flags;
-    g->i_pts   = p_list->i_pts;
-    g->i_dts   = p_list->i_dts;
-    g->i_length = i_length;
-
-    /* free p_list */
-    block_ChainRelease( p_list );
-    return g;
-}
-
-/**
- * @}
- * \defgroup block_fifo Block FIFO
- * Thread-safe block queue functions
- * @{
- */
-
-#include <vlc_queue.h>
-
-/**
- * Creates a thread-safe FIFO queue of blocks.
- *
- * See also block_FifoPut() and block_FifoGet().
- * The created queue must be released with block_FifoRelease().
- *
- * @return the FIFO or NULL on memory error
- */
-VLC_API block_fifo_t *block_FifoNew(void) VLC_USED VLC_MALLOC;
-
-/**
- * Destroys a FIFO created by block_FifoNew().
- *
- * @note Any queued blocks are also destroyed.
- * @warning No other threads may be using the FIFO when this function is
- * called. Otherwise, undefined behaviour will occur.
- */
-VLC_API void block_FifoRelease(block_fifo_t *);
-
-/**
- * Dequeue the first block from the FIFO. If necessary, wait until there is
- * one block in the queue. This function is (always) cancellation point.
- *
- * @return a valid block
- */
-VLC_API block_t *block_FifoGet(block_fifo_t *) VLC_USED;
-
-/**
- * Peeks the first block in the FIFO.
- *
- * @warning This function leaves the block in the FIFO.
- * You need to protect against concurrent threads who could dequeue the block.
- * Preferably, there should be only one thread reading from the FIFO.
- *
- * @warning This function is undefined if the FIFO is empty.
- *
- * @return a valid block.
- */
-VLC_API block_t *block_FifoShow(block_fifo_t *);
-
-typedef struct block_fifo_t vlc_fifo_t;
-
-static inline vlc_queue_t *vlc_fifo_queue(const vlc_fifo_t *fifo)
-{
-    return (vlc_queue_t *)fifo;
-}
-
-/**
- * Locks a block FIFO.
- *
- * No more than one thread can lock the FIFO at any given
- * time, and no other thread can modify the FIFO while it is locked.
- * vlc_fifo_Unlock() releases the lock.
- *
- * @note If the FIFO is already locked by another thread, this function waits.
- * This function is not a cancellation point.
- *
- * @warning Recursively locking a single FIFO is undefined. Locking more than
- * one FIFO at a time may lead to lock inversion; mind the locking order..
- */
-static inline void vlc_fifo_Lock(vlc_fifo_t *fifo)
-{
-    vlc_queue_Lock(vlc_fifo_queue(fifo));
-}
-
-/**
- * Unlocks a block FIFO.
- *
- * The calling thread must have locked the FIFO previously with
- * vlc_fifo_Lock(). Otherwise, the behaviour is undefined.
- *
- * @note This function is not a cancellation point.
- */
-static inline void vlc_fifo_Unlock(vlc_fifo_t *fifo)
-{
-    vlc_queue_Unlock(vlc_fifo_queue(fifo));
-}
-
-/**
- * Wakes up one thread waiting on the FIFO, if any.
- *
- * @note This function is not a cancellation point.
- *
- * @warning For race-free operations, the FIFO should be locked by the calling
- * thread. The function can be called on a unlocked FIFO however.
- */
-static inline void vlc_fifo_Signal(vlc_fifo_t *fifo)
-{
-    vlc_queue_Signal(vlc_fifo_queue(fifo));
-}
-
-/**
- * Waits on the FIFO.
- *
- * Atomically unlocks the FIFO and waits until one thread signals the FIFO,
- * then locks the FIFO again. A signal can be sent by queueing a block to the
- * previously empty FIFO or by calling vlc_fifo_Signal() directly.
- * This function may also return spuriously at any moment.
- *
- * @note This function is a cancellation point. In case of cancellation, the
- * the FIFO will be locked before cancellation cleanup handlers are processed.
- */
-static inline void vlc_fifo_Wait(vlc_fifo_t *fifo)
-{
-    vlc_queue_Wait(vlc_fifo_queue(fifo));
-}
-
-static inline void vlc_fifo_WaitCond(vlc_fifo_t *fifo, vlc_cond_t *condvar)
-{
-    vlc_queue_t *q = vlc_fifo_queue(fifo);
-
-    vlc_cond_wait(condvar, &q->lock);
-}
-
-/**
- * Queues a linked-list of blocks into a locked FIFO.
- *
- * @param block the head of the list of blocks
- *              (if NULL, this function has no effects)
- *
- * @note This function is not a cancellation point.
- *
- * @warning The FIFO must be locked by the calling thread using
- * vlc_fifo_Lock(). Otherwise behaviour is undefined.
- */
-VLC_API void vlc_fifo_QueueUnlocked(vlc_fifo_t *fifo, block_t *block);
-
-/**
- * Dequeues the first block from a locked FIFO, if any.
- *
- * @note This function is not a cancellation point.
- *
- * @warning The FIFO must be locked by the calling thread using
- * vlc_fifo_Lock(). Otherwise behaviour is undefined.
- *
- * @return the first block in the FIFO or NULL if the FIFO is empty
- */
-VLC_API block_t *vlc_fifo_DequeueUnlocked(vlc_fifo_t *) VLC_USED;
-
-/**
- * Dequeues the all blocks from a locked FIFO.
- *
- * This is equivalent to calling vlc_fifo_DequeueUnlocked() repeatedly until
- * the FIFO is emptied, but this function is much faster.
- *
- * @note This function is not a cancellation point.
- *
- * @warning The FIFO must be locked by the calling thread using
- * vlc_fifo_Lock(). Otherwise behaviour is undefined.
- *
- * @return a linked-list of all blocks in the FIFO (possibly NULL)
- */
-VLC_API block_t *vlc_fifo_DequeueAllUnlocked(vlc_fifo_t *) VLC_USED;
-
-/**
- * Counts blocks in a FIFO.
- *
- * Checks how many blocks are queued in a locked FIFO.
- *
- * @note This function is not cancellation point.
- *
- * @warning The FIFO must be locked by the calling thread using
- * vlc_fifo_Lock(). Otherwise behaviour is undefined.
- *
- * @return the number of blocks in the FIFO (zero if it is empty)
- */
-VLC_API size_t vlc_fifo_GetCount(const vlc_fifo_t *) VLC_USED;
-
-/**
- * Counts bytes in a FIFO.
- *
- * Checks how many bytes are queued in a locked FIFO.
- *
- * @note This function is not cancellation point.
- *
- * @warning The FIFO must be locked by the calling thread using
- * vlc_fifo_Lock(). Otherwise behaviour is undefined.
- *
- * @return the total number of bytes
- *
- * @note Zero bytes does not necessarily mean that the FIFO is empty since
- * a block could contain zero bytes. Use vlc_fifo_GetCount() to determine if
- * a FIFO is empty.
- */
-VLC_API size_t vlc_fifo_GetBytes(const vlc_fifo_t *) VLC_USED;
-
-VLC_USED static inline bool vlc_fifo_IsEmpty(const vlc_fifo_t *fifo)
-{
-    return vlc_queue_IsEmpty(vlc_fifo_queue(fifo));
-}
-
-static inline void vlc_fifo_Cleanup(void *fifo)
-{
-    vlc_fifo_Unlock((vlc_fifo_t *)fifo);
-}
-#define vlc_fifo_CleanupPush(fifo) vlc_cleanup_push(vlc_fifo_Cleanup, fifo)
-
-/**
- * Clears all blocks in a FIFO.
- */
-static inline void block_FifoEmpty(block_fifo_t *fifo)
-{
-    block_t *block;
-
-    vlc_fifo_Lock(fifo);
-    block = vlc_fifo_DequeueAllUnlocked(fifo);
-    vlc_fifo_Unlock(fifo);
-    block_ChainRelease(block);
-}
-
-/**
- * Immediately queue one block at the end of a FIFO.
- *
- * @param fifo queue
- * @param block head of a block list to queue (may be NULL)
- */
-static inline void block_FifoPut(block_fifo_t *fifo, block_t *block)
-{
-    vlc_fifo_Lock(fifo);
-    vlc_fifo_QueueUnlocked(fifo, block);
-    vlc_fifo_Unlock(fifo);
-}
-
-/* FIXME: not (really) thread-safe */
-VLC_USED VLC_DEPRECATED
-static inline size_t block_FifoSize (block_fifo_t *fifo)
-{
-    size_t size;
-
-    vlc_fifo_Lock(fifo);
-    size = vlc_fifo_GetBytes(fifo);
-    vlc_fifo_Unlock(fifo);
-    return size;
-}
-
-/* FIXME: not (really) thread-safe */
-VLC_USED VLC_DEPRECATED
-static inline size_t block_FifoCount (block_fifo_t *fifo)
-{
-    size_t depth;
-
-    vlc_fifo_Lock(fifo);
-    depth = vlc_fifo_GetCount(fifo);
-    vlc_fifo_Unlock(fifo);
-    return depth;
-}
-
-/** @} */
-
-/** @} */
+ * passed around.
+ *
+ * It is notably used in:
+ *  - access_t
+ *  - stream_t
+ *  - demux_t (read block_t but send vlc_frame_t from es_out_Send)A
+ *
+ * TODO: remove the vlc_frame_t typedef and create a block_t struct like the
+ * following:
+ * @verbatim
+ * struct block_t
+ * {
+ *     struct block_t *p_next;
+ *     uint8_t    *p_buffer;
+ *     size_t      i_buffer;
+ *     uint8_t    *p_start;
+ *     size_t      i_size;
+ *     const struct block_callbacks *cbs;
+ * } @endverbatim
+ */
+
+#define BLOCK_FLAG_DISCONTINUITY VLC_FRAME_FLAG_DISCONTINUITY
+
+#define BLOCK_FLAG_TYPE_I VLC_FRAME_FLAG_TYPE_I
+#define BLOCK_FLAG_TYPE_P VLC_FRAME_FLAG_TYPE_P
+#define BLOCK_FLAG_TYPE_B VLC_FRAME_FLAG_TYPE_B
+#define BLOCK_FLAG_TYPE_PB VLC_FRAME_FLAG_TYPE_PB
+#define BLOCK_FLAG_HEADER VLC_FRAME_FLAG_HEADER
+#define BLOCK_FLAG_END_OF_SEQUENCE VLC_FRAME_FLAG_END_OF_SEQUENCE
+#define BLOCK_FLAG_CLOCK VLC_FRAME_FLAG_CLOCK
+#define BLOCK_FLAG_SCRAMBLED VLC_FRAME_FLAG_SCRAMBLED
+#define BLOCK_FLAG_PREROLL VLC_FRAME_FLAG_PREROLL
+#define BLOCK_FLAG_CORRUPTED VLC_FRAME_FLAG_CORRUPTED
+#define BLOCK_FLAG_AU_END VLC_FRAME_FLAG_AU_END
+#define BLOCK_FLAG_TOP_FIELD_FIRST VLC_FRAME_FLAG_TOP_FIELD_FIRST
+#define BLOCK_FLAG_BOTTOM_FIELD_FIRST VLC_FRAME_FLAG_BOTTOM_FIELD_FIRST
+#define BLOCK_FLAG_SINGLE_FIELD VLC_FRAME_FLAG_SINGLE_FIELD
+#define BLOCK_FLAG_INTERLACED_MASK VLC_FRAME_FLAG_INTERLACED_MASK
+#define BLOCK_FLAG_TYPE_MASK VLC_FRAME_FLAG_TYPE_MASK
+#define BLOCK_FLAG_CORE_PRIVATE_MASK VLC_FRAME_FLAG_CORE_PRIVATE_MASK
+#define BLOCK_FLAG_CORE_PRIVATE_SHIFT VLC_FRAME_FLAG_CORE_PRIVATE_SHIFT
+#define BLOCK_FLAG_PRIVATE_MASK VLC_FRAME_FLAG_PRIVATE_MASK
+#define BLOCK_FLAG_PRIVATE_SHIFT VLC_FRAME_FLAG_PRIVATE_SHIFT
+
+#define vlc_block_callbacks vlc_frame_callbacks
+
+#define block_Init vlc_frame_Init
+#define block_Alloc vlc_frame_Alloc
+#define block_TryRealloc vlc_frame_TryRealloc
+#define block_Realloc vlc_frame_Realloc
+#define block_Release vlc_frame_Release
+#define block_CopyProperties vlc_frame_CopyProperties
+#define block_Duplicate vlc_frame_Duplicate
+#define block_heap_Alloc vlc_frame_heap_Alloc
+#define block_mmap_Alloc vlc_frame_mmap_Alloc
+#define block_shm_Alloc vlc_frame_shm_Alloc
+#define block_File vlc_frame_File
+#define block_FilePath vlc_frame_FilePath
+#define block_Cleanup vlc_frame_Cleanup
+#define block_cleanup_push vlc_frame_cleanup_push
+#define block_ChainAppend vlc_frame_ChainAppend
+#define block_ChainLastAppend vlc_frame_ChainLastAppend
+#define block_ChainRelease vlc_frame_ChainRelease
+#define block_ChainExtract vlc_frame_ChainExtract
+#define block_ChainProperties vlc_frame_ChainProperties
+#define block_ChainGather vlc_frame_ChainGather
+
+#define block_FifoPut vlc_fifo_Put
+#define block_FifoNew vlc_fifo_New
+#define block_FifoRelease vlc_fifo_Release
+#define block_FifoSize vlc_fifo_Size
+#define block_FifoGet vlc_fifo_Get
+#define block_FifoCount vlc_fifo_Count
+#define block_FifoEmpty vlc_fifo_Empty
+#define block_FifoShow vlc_fifo_Show
 
 #endif /* VLC_BLOCK_H */


=====================================
include/vlc_codec.h
=====================================
@@ -57,7 +57,7 @@ struct decoder_owner_callbacks
             /* cf.decoder_QueueVideo */
             void        (*queue)( decoder_t *, picture_t * );
             /* cf.decoder_QueueCC */
-            void        (*queue_cc)( decoder_t *, block_t *,
+            void        (*queue_cc)( decoder_t *, vlc_frame_t *,
                                      const decoder_cc_desc_t * );
 
             /* Display date
@@ -72,7 +72,7 @@ struct decoder_owner_callbacks
             int     (*format_update)( decoder_t * );
 
             /* cf.decoder_QueueAudio */
-            void    (*queue)( decoder_t *, block_t * );
+            void    (*queue)( decoder_t *, vlc_frame_t * );
         } audio;
         struct
         {
@@ -132,7 +132,7 @@ struct decoder_t
          * send output frames/blocks via decoder_QueueVideo(), decoder_QueueAudio()
          * or decoder_QueueSub().
          *
-         * If p_block is NULL, the decoder asks the module to drain itself. The
+         * If frame is NULL, the decoder asks the module to drain itself. The
          * module should return all available output frames/block via the queue
          * functions.
          *
@@ -143,10 +143,10 @@ struct decoder_t
          *  VLCDEC_RELOAD: Request that the decoder should be reloaded. The current
          *  module will be unloaded. Reloading a module may cause a loss of frames.
          *  When returning this status, the implementation shouldn't release or
-         *  modify the p_block in argument (The same p_block will be feed to the
+         *  modify the frame in argument (The same frame will be feed to the
          *  next decoder module).
          */
-        int             ( * pf_decode )   ( decoder_t *, block_t *p_block );
+        int             ( * pf_decode )   ( decoder_t *, vlc_frame_t *frame );
 
         /* This function is called in a loop with the same pp_block argument until
          * it returns NULL. This allows a module implementation to return more than
@@ -157,25 +157,25 @@ struct decoder_t
          * If pp_block and *pp_block are not NULL, the module implementation will
          * own the input block (*pp_block) and should process and release it. The
          * module can also process a part of the block. In that case, it should
-         * modify (*pp_block)->p_buffer/i_buffer accordingly and return a valid
-         * output block. The module can also set *pp_block to NULL when the input
+         * modify (*ppframe)->p_buffer/i_buffer accordingly and return a valid
+         * output block. The module can also set *ppframe to NULL when the input
          * block is consumed.
          *
-         * If pp_block is not NULL but *pp_block is NULL, a previous call of the pf
-         * function has set the *pp_block to NULL. Here, the module can return new
+         * If ppframe is not NULL but *ppframe is NULL, a previous call of the pf
+         * function has set the *ppframe to NULL. Here, the module can return new
          * output block for the same, already processed, input block (the
          * pf_packetize function will be called as long as the module return an
          * output block).
          *
          * When the pf function returns NULL, the next call to this function will
-         * have a new a valid pp_block (if the packetizer is not drained).
+         * have a new a valid ppframe (if the packetizer is not drained)..
          *
-         * If pp_block is NULL, the packetizer asks the module to drain itself. In
+         * If ppframe is NULL, the packetizer asks the module to drain itself. In
          * that case, the module has to return all output frames available (the
          * pf_packetize function will be called as long as the module return an
          * output block).
          */
-        block_t *       ( * pf_packetize )( decoder_t *, block_t **pp_block );
+        vlc_frame_t *   ( * pf_packetize )( decoder_t *, vlc_frame_t  **ppframe );
     };
 
     /* */
@@ -187,7 +187,7 @@ struct decoder_t
      * channel bitmaps will be used to known which cc channel are present (but
      * globaly, not necessary for the current packet. Video decoders should use
      * the decoder_QueueCc() function to pass closed captions. */
-    block_t *           ( * pf_get_cc )      ( decoder_t *, decoder_cc_desc_t * );
+    vlc_frame_t *       ( * pf_get_cc )      ( decoder_t *, decoder_cc_desc_t * );
 
     /* Meta data at codec level
      *  The decoder owner set it back to NULL once it has retreived what it needs.
@@ -402,7 +402,7 @@ static inline void decoder_QueueVideo( decoder_t *dec, picture_t *p_pic )
  * \param p_cc the closed-caption to queue
  * \param p_desc decoder_cc_desc_t description structure
  */
-static inline void decoder_QueueCc( decoder_t *dec, block_t *p_cc,
+static inline void decoder_QueueCc( decoder_t *dec, vlc_frame_t *p_cc,
                                    const decoder_cc_desc_t *p_desc )
 {
     vlc_assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
@@ -420,7 +420,7 @@ static inline void decoder_QueueCc( decoder_t *dec, block_t *p_cc,
  * The caller doesn't own the audio block anymore after this call (even in case
  * of error).
  */
-static inline void decoder_QueueAudio( decoder_t *dec, block_t *p_aout_buf )
+static inline void decoder_QueueAudio( decoder_t *dec, vlc_frame_t *p_aout_buf )
 {
     vlc_assert( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs != NULL );
     vlc_assert( p_aout_buf->p_next == NULL );
@@ -464,7 +464,7 @@ static inline int decoder_UpdateAudioFormat( decoder_t *dec )
  * output buffer. It must be released with block_Release() or returned it to
  * the caller as a decoder_QueueAudio parameter.
  */
-VLC_API block_t * decoder_NewAudioBuffer( decoder_t *, int i_nb_samples ) VLC_USED;
+VLC_API vlc_frame_t * decoder_NewAudioBuffer( decoder_t *, int i_nb_samples ) VLC_USED;
 
 /**
  * This function will return a new subpicture usable by a decoder as an output


=====================================
include/vlc_common.h
=====================================
@@ -424,8 +424,9 @@ typedef struct vlc_url_t vlc_url_t;
 typedef struct iso639_lang_t iso639_lang_t;
 
 /* block */
-typedef struct block_t      block_t;
-typedef struct block_fifo_t block_fifo_t;
+typedef struct vlc_frame_t  block_t;
+typedef struct vlc_fifo_t vlc_fifo_t;
+typedef struct vlc_fifo_t block_fifo_t;
 
 /* Hashing */
 typedef struct vlc_hash_md5_ctx vlc_hash_md5_t;


=====================================
include/vlc_frame.h
=====================================
@@ -0,0 +1,774 @@
+/*****************************************************************************
+ * vlc_frame.h: frame management functions
+ *****************************************************************************
+ * Copyright (C) 2003 VLC authors and VideoLAN
+ *
+ * Authors: Laurent Aimar <fenrir at via.ecp.fr>
+ *
+ * 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 VLC_FRAME_H
+#define VLC_FRAME_H 1
+
+/**
+ * \defgroup frame Frames
+ * \ingroup input
+ *
+ * Frames of binary data.
+ *
+ * @ref vlc_frame_t is a generic structure to represent a binary blob within VLC.
+ * The primary goal of the structure is to avoid memory copying as data is
+ * passed around. It is notably used between the \ref demux, the packetizer
+ * (if present) and the \ref decoder, and for audio, between the \ref decoder,
+ * the audio filters, and the \ref audio_output.
+ *
+ * @{
+ * \file
+ * Frames definition and functions
+ */
+
+#include <sys/types.h>  /* for ssize_t */
+
+/****************************************************************************
+ * frame:
+ ****************************************************************************
+ * - i_flags may not always be set (ie could be 0, even for a key frame
+ *      it depends where you receive the buffer (before/after a packetizer
+ *      and the demux/packetizer implementations.
+ * - i_dts/i_pts could be VLC_TICK_INVALID, it means no pts/dts
+ * - i_length: length in microseond of the packet, can be null except in the
+ *      sout where it is mandatory.
+ *
+ * - i_buffer number of valid data pointed by p_buffer
+ *      you can freely decrease it but never increase it yourself
+ *      (use vlc_frame_Realloc)
+ * - p_buffer: pointer over datas. You should never overwrite it, you can
+ *   only incremment it to skip datas, in others cases use vlc_frame_Realloc
+ *   (don't duplicate yourself in a bigger buffer, vlc_frame_Realloc is
+ *   optimised for preheader/postdatas increase)
+ ****************************************************************************/
+
+typedef struct vlc_frame_t vlc_frame_t;
+
+/** The content doesn't follow the last frame, possible some frames in between
+ *  have been lost */
+#define VLC_FRAME_FLAG_DISCONTINUITY 0x0001
+/** Intra frame */
+#define VLC_FRAME_FLAG_TYPE_I        0x0002
+/** Inter frame with backward reference only */
+#define VLC_FRAME_FLAG_TYPE_P        0x0004
+/** Inter frame with backward and forward reference */
+#define VLC_FRAME_FLAG_TYPE_B        0x0008
+/** For inter frame when you don't know the real type */
+#define VLC_FRAME_FLAG_TYPE_PB       0x0010
+/** Warn that this frame is a header one */
+#define VLC_FRAME_FLAG_HEADER        0x0020
+/** This frame contains the last part of a sequence  */
+#define VLC_FRAME_FLAG_END_OF_SEQUENCE 0x0040
+/** This frame contains a clock reference */
+#define VLC_FRAME_FLAG_CLOCK         0x0080
+/** This frame is scrambled */
+#define VLC_FRAME_FLAG_SCRAMBLED     0x0100
+/** This frame has to be decoded but not be displayed */
+#define VLC_FRAME_FLAG_PREROLL       0x0200
+/** This frame is corrupted and/or there is data loss  */
+#define VLC_FRAME_FLAG_CORRUPTED     0x0400
+/** This frame is last of its access unit */
+#define VLC_FRAME_FLAG_AU_END        0x0800
+/** This frame contains an interlaced picture with top field stored first */
+#define VLC_FRAME_FLAG_TOP_FIELD_FIRST 0x1000
+/** This frame contains an interlaced picture with bottom field stored first */
+#define VLC_FRAME_FLAG_BOTTOM_FIELD_FIRST 0x2000
+/** This frame contains a single field from interlaced picture. */
+#define VLC_FRAME_FLAG_SINGLE_FIELD  0x4000
+
+/** This frame contains an interlaced picture */
+#define VLC_FRAME_FLAG_INTERLACED_MASK \
+    (VLC_FRAME_FLAG_TOP_FIELD_FIRST|VLC_FRAME_FLAG_BOTTOM_FIELD_FIRST|VLC_FRAME_FLAG_SINGLE_FIELD)
+
+#define VLC_FRAME_FLAG_TYPE_MASK \
+    (VLC_FRAME_FLAG_TYPE_I|VLC_FRAME_FLAG_TYPE_P|VLC_FRAME_FLAG_TYPE_B|VLC_FRAME_FLAG_TYPE_PB)
+
+/* These are for input core private usage only */
+#define VLC_FRAME_FLAG_CORE_PRIVATE_MASK  0x00ff0000
+#define VLC_FRAME_FLAG_CORE_PRIVATE_SHIFT 16
+
+/* These are for module private usage only */
+#define VLC_FRAME_FLAG_PRIVATE_MASK  0xff000000
+#define VLC_FRAME_FLAG_PRIVATE_SHIFT 24
+
+struct vlc_frame_callbacks
+{
+    void (*free)(vlc_frame_t *);
+};
+
+struct vlc_frame_t
+{
+    vlc_frame_t    *p_next;
+
+    uint8_t    *p_buffer; /**< Payload start */
+    size_t      i_buffer; /**< Payload length */
+    uint8_t    *p_start; /**< Buffer start */
+    size_t      i_size; /**< Buffer total size */
+
+    uint32_t    i_flags;
+    unsigned    i_nb_samples; /* Used for audio */
+
+    vlc_tick_t  i_pts;
+    vlc_tick_t  i_dts;
+    vlc_tick_t  i_length;
+
+    const struct vlc_frame_callbacks *cbs;
+};
+
+/**
+ * Initializes a custom frame.
+ *
+ * This function initialize a frame of timed data allocated by custom means.
+ * This allows passing data without copying even if the data has been allocated
+ * with unusual means or outside of LibVLC.
+ *
+ * Normally, frames are allocated and initialized by vlc_frame_Alloc() instead.
+ *
+ * @param frame allocated frame structure to initialize
+ * @param cbs structure of custom callbacks to handle the frame [IN]
+ * @param base start address of the frame data
+ * @param length byte length of the frame data
+ *
+ * @return @c frame (this function cannot fail)
+ */
+VLC_API vlc_frame_t *vlc_frame_Init(vlc_frame_t *frame,
+                                    const struct vlc_frame_callbacks *cbs,
+                                    void *base, size_t length);
+
+/**
+ * Allocates a frame.
+ *
+ * Creates a new frame with the requested size.
+ * The frame must be released with vlc_frame_Release().
+ *
+ * @param size size in bytes (possibly zero)
+ * @return the created frame, or NULL on memory error.
+ */
+VLC_API vlc_frame_t *vlc_frame_Alloc(size_t size) VLC_USED VLC_MALLOC;
+
+VLC_API vlc_frame_t *vlc_frame_TryRealloc(vlc_frame_t *, ssize_t pre, size_t body) VLC_USED;
+
+/**
+ * Reallocates a frame.
+ *
+ * This function expands, shrinks or moves a data frame.
+ * In many cases, this function can return without any memory allocation by
+ * reusing spare buffer space. Otherwise, a new frame is created and data is
+ * copied.
+ *
+ * @param pre count of bytes to prepend if positive,
+ *            count of leading bytes to discard if negative
+ * @param body new bytes size of the frame
+ *
+ * @return the reallocated frame on succes, NULL on error.
+ *
+ * @note Skipping leading bytes can be achieved directly by subtracting from
+ * vlc_frame_t.i_buffer and adding vlc_frame_t.p_buffer.
+ * @note Discard trailing bytes can be achieved directly by subtracting from
+ * vlc_frame_t.i_buffer.
+ * @note On error, the frame is discarded.
+ * To avoid that, use vlc_frame_TryRealloc() instead.
+ */
+VLC_API vlc_frame_t *vlc_frame_Realloc(vlc_frame_t *, ssize_t pre, size_t body) VLC_USED;
+
+/**
+ * Releases a frame.
+ *
+ * This function works for any @ref vlc_frame_t frame, regardless of the way it was
+ * allocated.
+ *
+ * @note
+ * If the frame is in a chain, this function does <b>not</b> release any
+ * subsequent frame in the chain. Use vlc_frame_ChainRelease() for that purpose.
+ *
+ * @param frame frame to release (cannot be NULL)
+ */
+VLC_API void vlc_frame_Release(vlc_frame_t *frame);
+
+static inline void vlc_frame_CopyProperties( vlc_frame_t *dst, const vlc_frame_t *src )
+{
+    dst->i_flags   = src->i_flags;
+    dst->i_nb_samples = src->i_nb_samples;
+    dst->i_dts     = src->i_dts;
+    dst->i_pts     = src->i_pts;
+    dst->i_length  = src->i_length;
+}
+
+/**
+ * Duplicates a frame.
+ *
+ * Creates a writeable duplicate of a frame.
+ *
+ * @return the duplicate on success, NULL on error.
+ */
+VLC_USED
+static inline vlc_frame_t *vlc_frame_Duplicate( const vlc_frame_t *frame )
+{
+    vlc_frame_t *p_dup = vlc_frame_Alloc( frame->i_buffer );
+    if( p_dup == NULL )
+        return NULL;
+
+    vlc_frame_CopyProperties( p_dup, frame );
+    memcpy( p_dup->p_buffer, frame->p_buffer, frame->i_buffer );
+
+    return p_dup;
+}
+
+/**
+ * Wraps heap in a frame.
+ *
+ * Creates a @ref vlc_frame_t out of an existing heap allocation.
+ * This is provided by LibVLC so that manually heap-allocated frames can safely
+ * be deallocated even after the origin plugin has been unloaded from memory.
+ *
+ * When vlc_frame_Release() is called, VLC will free() the specified pointer.
+ *
+ * @param addr base address of the heap allocation (will be free()'d)
+ * @param length bytes length of the heap allocation
+ * @return NULL in case of error (ptr free()'d in that case), or a valid
+ * vlc_frame_t pointer.
+ */
+VLC_API vlc_frame_t *vlc_frame_heap_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
+
+/**
+ * Wraps a memory mapping in a frame
+ *
+ * Creates a @ref vlc_frame_t from a virtual address memory mapping (mmap).
+ * This is provided by LibVLC so that mmap frames can safely be deallocated
+ * even after the allocating plugin has been unloaded from memory.
+ *
+ * @param addr base address of the mapping (as returned by mmap)
+ * @param length length (bytes) of the mapping (as passed to mmap)
+ * @return NULL if addr is MAP_FAILED, or an error occurred (in the later
+ * case, munmap(addr, length) is invoked before returning).
+ */
+VLC_API vlc_frame_t *vlc_frame_mmap_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
+
+/**
+ * Wraps a System V memory segment in a frame
+ *
+ * Creates a @ref vlc_frame_t from a System V shared memory segment (shmget()).
+ * This is provided by LibVLC so that segments can safely be deallocated
+ * even after the allocating plugin has been unloaded from memory.
+ *
+ * @param addr base address of the segment (as returned by shmat())
+ * @param length length (bytes) of the segment (as passed to shmget())
+ * @return NULL if an error occurred (in that case, shmdt(addr) is invoked
+ * before returning NULL).
+ */
+VLC_API vlc_frame_t * vlc_frame_shm_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
+
+/**
+ * Maps a file handle in memory.
+ *
+ * Loads a file into a frame of memory through a file descriptor.
+ * If possible a private file mapping is created. Otherwise, the file is read
+ * normally. This function is a cancellation point.
+ *
+ * @note On 32-bits platforms,
+ * this function will not work for very large files,
+ * due to memory space constraints.
+ *
+ * @param fd file descriptor to load from
+ * @param write If true, request a read/write private mapping.
+ *              If false, request a read-only potentially shared mapping..
+ *
+ * @return a new frame with the file content at p_buffer, and file length at
+ * i_buffer (release it with vlc_frame_Release()), or NULL upon error (see errno).
+ */
+VLC_API vlc_frame_t *vlc_frame_File(int fd, bool write) VLC_USED VLC_MALLOC;
+
+/**
+ * Maps a file in memory.
+ *
+ * Loads a file into a frame of memory from a path to the file.
+ * See also vlc_frame_File().
+ *
+ * @param write If true, request a read/write private mapping.
+ *              If false, request a read-only potentially shared mapping..
+ */
+VLC_API vlc_frame_t *vlc_frame_FilePath(const char *, bool write) VLC_USED VLC_MALLOC;
+
+static inline void vlc_frame_Cleanup (void *frame)
+{
+    vlc_frame_Release ((vlc_frame_t *)frame);
+}
+#define vlc_frame_cleanup_push( frame ) vlc_cleanup_push (vlc_frame_Cleanup, frame)
+
+/**
+ * \defgroup vlc_frame_chain Frame chain
+ * @{
+ */
+
+/**
+ * Appends a @ref vlc_frame_t to the chain
+ *
+ * The given frame is appended to the last frame of the given chain.
+ *
+ * @attention
+ *  Using this function on long chains or repeatedly calling it
+ *  to append a lot of frames can be slow, as it has to iterate the
+ *  whole chain to append the frame.
+ *  In these cases @ref vlc_frame_ChainLastAppend should be used.
+ *
+ * @param pp_list   Pointer to the vlc_frame_t chain
+ * @param frame   The vlc_frame_t to append (can be NULL)
+ *
+ * @see vlc_frame_ChainLastAppend()
+ *
+ * Example:
+ * @code{.c}
+ * vlc_frame_t *p_chain = NULL;
+ *
+ * vlc_frame_ChainAppend(&p_chain, p_frame);
+ * @endcode
+ */
+static inline void vlc_frame_ChainAppend( vlc_frame_t **pp_list, vlc_frame_t *frame )
+{
+    if( *pp_list == NULL )
+    {
+        *pp_list = frame;
+    }
+    else
+    {
+        vlc_frame_t *p = *pp_list;
+
+        while( p->p_next ) p = p->p_next;
+        p->p_next = frame;
+    }
+}
+
+/**
+ * Appends a @ref vlc_frame_t to the last frame pointer and update it
+ *
+ * Uses a pointer over a pointer to p_next of the last frame of the frame chain
+ * to append a frame at the end of the chain and updates the pointer to the new
+ * last frame's @c p_next. If the appended frame is itself a chain, it is iterated
+ * till the end to correctly update @c ppp_last.
+ *
+ * @param[in,out] ppp_last  Pointer to pointer to the end of the chain
+ *                          (The vlc_frame_t::p_next of the last vlc_frame_t in the chain)
+ * @param         frame   The vlc_frame_t to append
+ *
+ * Example:
+ * @code{.c}
+ * vlc_frame_t *p_frame = NULL;
+ * vlc_frame_t **pp_frame_last = &p_frame;
+ *
+ * vlc_frame_ChainLastAppend(&pp_frame_last, p_other_frame);
+ * @endcode
+ */
+static inline void vlc_frame_ChainLastAppend( vlc_frame_t ***ppp_last, vlc_frame_t *frame )
+{
+    vlc_frame_t *p_last = frame;
+
+    **ppp_last = frame;
+
+    while( p_last->p_next ) p_last = p_last->p_next;
+    *ppp_last = &p_last->p_next;
+}
+
+/**
+ * Releases a chain of blocks
+ *
+ * The frame pointed to by frame and all following frames in the
+ * chain are released.
+ *
+ * @param frame   Pointer to first vlc_frame_t of the chain to release
+ *
+ * @see vlc_frame_Release()
+ */
+static inline void vlc_frame_ChainRelease( vlc_frame_t *frame )
+{
+    while( frame )
+    {
+        vlc_frame_t *p_next = frame->p_next;
+        vlc_frame_Release( frame );
+        frame = p_next;
+    }
+}
+
+/**
+ * Extracts data from a chain of frames
+ *
+ * Copies the specified amount of data from the chain into the given buffer.
+ * If the data in the chain is less than the maximum amount given, the remainder
+ * of the buffer is not modified.
+ *
+ * @param      p_list   Pointer to the first vlc_frame_t of the chain to copy from
+ * @param[out] p_data   Destination buffer to copy the data to
+ * @param      i_max    Number of bytes to copy
+ * @return              Number of bytes actually copied
+ *
+ * @see vlc_frame_ChainGather()
+ */
+static size_t vlc_frame_ChainExtract( vlc_frame_t *p_list, void *p_data, size_t i_max )
+{
+    size_t  i_total = 0;
+    uint8_t *p = (uint8_t*)p_data;
+
+    while( p_list && i_max )
+    {
+        size_t i_copy = __MIN( i_max, p_list->i_buffer );
+        memcpy( p, p_list->p_buffer, i_copy );
+        i_max   -= i_copy;
+        i_total += i_copy;
+        p       += i_copy;
+
+        p_list = p_list->p_next;
+    }
+    return i_total;
+}
+
+/**
+ * Retrives chain properties
+ *
+ * Can be used to retrieve count of frames, number of bytes and the duration
+ * of the chain.
+ *
+ * @param       p_list      Pointer to the first vlc_frame_t of the chain
+ * @param[out]  pi_count    Pointer to count of frames in the chain (may be NULL)
+ * @param[out]  pi_size     Pointer to number of bytes in the chain (may be NULL)
+ * @param[out]  pi_length   Pointer to length (duration) of the chain (may be NULL)
+ */
+static inline void vlc_frame_ChainProperties( vlc_frame_t *p_list, int *pi_count, size_t *pi_size, vlc_tick_t *pi_length )
+{
+    size_t i_size = 0;
+    vlc_tick_t i_length = 0;
+    int i_count = 0;
+
+    while( p_list )
+    {
+        i_size += p_list->i_buffer;
+        i_length += p_list->i_length;
+        i_count++;
+
+        p_list = p_list->p_next;
+    }
+
+    if( pi_size )
+        *pi_size = i_size;
+    if( pi_length )
+        *pi_length = i_length;
+    if( pi_count )
+        *pi_count = i_count;
+}
+
+/**
+ * Gathers a chain into a single vlc_frame_t
+ *
+ * All frames in the chain are gathered into a single vlc_frame_t and the
+ * original chain is released.
+ * 
+ * @param   p_list  Pointer to the first vlc_frame_t of the chain to gather
+ * @return  Returns a pointer to a new vlc_frame_t or NULL if the frame can not
+ *          be allocated, in which case the original chain is not released.
+ *          If the chain pointed to by p_list is already gathered, a pointer
+ *          to it is returned and no new frame will be allocated.
+ *
+ * @see vlc_frame_ChainExtract()
+ */
+static inline vlc_frame_t *vlc_frame_ChainGather( vlc_frame_t *p_list )
+{
+    size_t  i_total = 0;
+    vlc_tick_t i_length = 0;
+    vlc_frame_t *g;
+
+    if( p_list->p_next == NULL )
+        return p_list;  /* Already gathered */
+
+    vlc_frame_ChainProperties( p_list, NULL, &i_total, &i_length );
+
+    g = vlc_frame_Alloc( i_total );
+    if( !g )
+        return NULL;
+    vlc_frame_ChainExtract( p_list, g->p_buffer, g->i_buffer );
+
+    g->i_flags = p_list->i_flags;
+    g->i_pts   = p_list->i_pts;
+    g->i_dts   = p_list->i_dts;
+    g->i_length = i_length;
+
+    /* free p_list */
+    vlc_frame_ChainRelease( p_list );
+    return g;
+}
+
+/**
+ * @}
+ * \defgroup block_fifo Block FIFO
+ * Thread-safe block queue functions
+ * @{
+ */
+
+#include <vlc_queue.h>
+
+/**
+ * Creates a thread-safe FIFO queue of blocks.
+ *
+ * See also vlc_fifo_Put() and vlc_fifo_Get().
+ * The created queue must be released with vlc_fifo_Release().
+ *
+ * @return the FIFO or NULL on memory error
+ */
+VLC_API vlc_fifo_t *vlc_fifo_New(void) VLC_USED VLC_MALLOC;
+
+/**
+ * Destroys a FIFO created by vlc_fifo_New().
+ *
+ * @note Any queued blocks are also destroyed.
+ * @warning No other threads may be using the FIFO when this function is
+ * called. Otherwise, undefined behaviour will occur.
+ */
+VLC_API void vlc_fifo_Release(vlc_fifo_t *);
+
+/**
+ * Dequeue the first block from the FIFO. If necessary, wait until there is
+ * one block in the queue. This function is (always) cancellation point.
+ *
+ * @return a valid block
+ */
+VLC_API vlc_frame_t *vlc_fifo_Get(vlc_fifo_t *) VLC_USED;
+
+/**
+ * Peeks the first block in the FIFO.
+ *
+ * @warning This function leaves the block in the FIFO.
+ * You need to protect against concurrent threads who could dequeue the block.
+ * Preferably, there should be only one thread reading from the FIFO.
+ *
+ * @warning This function is undefined if the FIFO is empty.
+ *
+ * @return a valid block.
+ */
+VLC_API vlc_frame_t *vlc_fifo_Show(vlc_fifo_t *);
+
+static inline vlc_queue_t *vlc_fifo_queue(const vlc_fifo_t *fifo)
+{
+    return (vlc_queue_t *)fifo;
+}
+
+/**
+ * Locks a block FIFO.
+ *
+ * No more than one thread can lock the FIFO at any given
+ * time, and no other thread can modify the FIFO while it is locked.
+ * vlc_fifo_Unlock() releases the lock.
+ *
+ * @note If the FIFO is already locked by another thread, this function waits.
+ * This function is not a cancellation point.
+ *
+ * @warning Recursively locking a single FIFO is undefined. Locking more than
+ * one FIFO at a time may lead to lock inversion; mind the locking order..
+ */
+static inline void vlc_fifo_Lock(vlc_fifo_t *fifo)
+{
+    vlc_queue_Lock(vlc_fifo_queue(fifo));
+}
+
+/**
+ * Unlocks a block FIFO.
+ *
+ * The calling thread must have locked the FIFO previously with
+ * vlc_fifo_Lock(). Otherwise, the behaviour is undefined.
+ *
+ * @note This function is not a cancellation point.
+ */
+static inline void vlc_fifo_Unlock(vlc_fifo_t *fifo)
+{
+    vlc_queue_Unlock(vlc_fifo_queue(fifo));
+}
+
+/**
+ * Wakes up one thread waiting on the FIFO, if any.
+ *
+ * @note This function is not a cancellation point.
+ *
+ * @warning For race-free operations, the FIFO should be locked by the calling
+ * thread. The function can be called on a unlocked FIFO however.
+ */
+static inline void vlc_fifo_Signal(vlc_fifo_t *fifo)
+{
+    vlc_queue_Signal(vlc_fifo_queue(fifo));
+}
+
+/**
+ * Waits on the FIFO.
+ *
+ * Atomically unlocks the FIFO and waits until one thread signals the FIFO,
+ * then locks the FIFO again. A signal can be sent by queueing a block to the
+ * previously empty FIFO or by calling vlc_fifo_Signal() directly.
+ * This function may also return spuriously at any moment.
+ *
+ * @note This function is a cancellation point. In case of cancellation, the
+ * the FIFO will be locked before cancellation cleanup handlers are processed.
+ */
+static inline void vlc_fifo_Wait(vlc_fifo_t *fifo)
+{
+    vlc_queue_Wait(vlc_fifo_queue(fifo));
+}
+
+static inline void vlc_fifo_WaitCond(vlc_fifo_t *fifo, vlc_cond_t *condvar)
+{
+    vlc_queue_t *q = vlc_fifo_queue(fifo);
+
+    vlc_cond_wait(condvar, &q->lock);
+}
+
+/**
+ * Queues a linked-list of blocks into a locked FIFO.
+ *
+ * @param block the head of the list of blocks
+ *              (if NULL, this function has no effects)
+ *
+ * @note This function is not a cancellation point.
+ *
+ * @warning The FIFO must be locked by the calling thread using
+ * vlc_fifo_Lock(). Otherwise behaviour is undefined.
+ */
+VLC_API void vlc_fifo_QueueUnlocked(vlc_fifo_t *fifo, vlc_frame_t *block);
+
+/**
+ * Dequeues the first block from a locked FIFO, if any.
+ *
+ * @note This function is not a cancellation point.
+ *
+ * @warning The FIFO must be locked by the calling thread using
+ * vlc_fifo_Lock(). Otherwise behaviour is undefined.
+ *
+ * @return the first block in the FIFO or NULL if the FIFO is empty
+ */
+VLC_API vlc_frame_t *vlc_fifo_DequeueUnlocked(vlc_fifo_t *) VLC_USED;
+
+/**
+ * Dequeues the all blocks from a locked FIFO.
+ *
+ * This is equivalent to calling vlc_fifo_DequeueUnlocked() repeatedly until
+ * the FIFO is emptied, but this function is much faster.
+ *
+ * @note This function is not a cancellation point.
+ *
+ * @warning The FIFO must be locked by the calling thread using
+ * vlc_fifo_Lock(). Otherwise behaviour is undefined.
+ *
+ * @return a linked-list of all blocks in the FIFO (possibly NULL)
+ */
+VLC_API vlc_frame_t *vlc_fifo_DequeueAllUnlocked(vlc_fifo_t *) VLC_USED;
+
+/**
+ * Counts blocks in a FIFO.
+ *
+ * Checks how many blocks are queued in a locked FIFO.
+ *
+ * @note This function is not cancellation point.
+ *
+ * @warning The FIFO must be locked by the calling thread using
+ * vlc_fifo_Lock(). Otherwise behaviour is undefined.
+ *
+ * @return the number of blocks in the FIFO (zero if it is empty)
+ */
+VLC_API size_t vlc_fifo_GetCount(const vlc_fifo_t *) VLC_USED;
+
+/**
+ * Counts bytes in a FIFO.
+ *
+ * Checks how many bytes are queued in a locked FIFO.
+ *
+ * @note This function is not cancellation point.
+ *
+ * @warning The FIFO must be locked by the calling thread using
+ * vlc_fifo_Lock(). Otherwise behaviour is undefined.
+ *
+ * @return the total number of bytes
+ *
+ * @note Zero bytes does not necessarily mean that the FIFO is empty since
+ * a block could contain zero bytes. Use vlc_fifo_GetCount() to determine if
+ * a FIFO is empty.
+ */
+VLC_API size_t vlc_fifo_GetBytes(const vlc_fifo_t *) VLC_USED;
+
+VLC_USED static inline bool vlc_fifo_IsEmpty(const vlc_fifo_t *fifo)
+{
+    return vlc_queue_IsEmpty(vlc_fifo_queue(fifo));
+}
+
+static inline void vlc_fifo_Cleanup(void *fifo)
+{
+    vlc_fifo_Unlock((vlc_fifo_t *)fifo);
+}
+#define vlc_fifo_CleanupPush(fifo) vlc_cleanup_push(vlc_fifo_Cleanup, fifo)
+
+/**
+ * Clears all blocks in a FIFO.
+ */
+static inline void vlc_fifo_Empty(vlc_fifo_t *fifo)
+{
+    vlc_frame_t *block;
+
+    vlc_fifo_Lock(fifo);
+    block = vlc_fifo_DequeueAllUnlocked(fifo);
+    vlc_fifo_Unlock(fifo);
+    vlc_frame_ChainRelease(block);
+}
+
+/**
+ * Immediately queue one block at the end of a FIFO.
+ *
+ * @param fifo queue
+ * @param block head of a block list to queue (may be NULL)
+ */
+static inline void vlc_fifo_Put(vlc_fifo_t *fifo, vlc_frame_t *block)
+{
+    vlc_fifo_Lock(fifo);
+    vlc_fifo_QueueUnlocked(fifo, block);
+    vlc_fifo_Unlock(fifo);
+}
+
+/* FIXME: not (really) thread-safe */
+VLC_USED VLC_DEPRECATED
+static inline size_t vlc_fifo_Size (vlc_fifo_t *fifo)
+{
+    size_t size;
+
+    vlc_fifo_Lock(fifo);
+    size = vlc_fifo_GetBytes(fifo);
+    vlc_fifo_Unlock(fifo);
+    return size;
+}
+
+/* FIXME: not (really) thread-safe */
+VLC_USED VLC_DEPRECATED
+static inline size_t vlc_fifo_Count (vlc_fifo_t *fifo)
+{
+    size_t depth;
+
+    vlc_fifo_Lock(fifo);
+    depth = vlc_fifo_GetCount(fifo);
+    vlc_fifo_Unlock(fifo);
+    return depth;
+}
+
+/** @} */
+
+/** @} */
+
+#endif /* VLC_FRAME_H */


=====================================
modules/access/http/file.h
=====================================
@@ -29,7 +29,6 @@
 
 struct vlc_http_mgr;
 struct vlc_http_resource;
-struct block_t;
 
 /**
  * Creates an HTTP file.
@@ -77,7 +76,7 @@ int vlc_http_file_seek(struct vlc_http_resource *, uintmax_t offset);
  *
  * Reads data from a file and update the file offset.
  */
-struct block_t *vlc_http_file_read(struct vlc_http_resource *);
+block_t *vlc_http_file_read(struct vlc_http_resource *);
 
 #define vlc_http_file_get_status vlc_http_res_get_status
 #define vlc_http_file_get_redirect vlc_http_res_get_redirect


=====================================
modules/access/http/file_test.c
=====================================
@@ -312,7 +312,7 @@ static struct vlc_http_msg *stream_read_headers(struct vlc_http_stream *s)
     return m;
 }
 
-static struct block_t *stream_read(struct vlc_http_stream *s)
+static block_t *stream_read(struct vlc_http_stream *s)
 {
     assert(s == &stream);
     return NULL;


=====================================
modules/access/http/h1conn_test.c
=====================================
@@ -100,7 +100,7 @@ int main(void)
 {
     struct vlc_http_stream *s;
     struct vlc_http_msg *m;
-    struct block_t *b;
+    block_t *b;
 
     /* Dummy */
     conn_create();


=====================================
modules/access/http/h2conn_test.c
=====================================
@@ -163,7 +163,7 @@ int main(void)
 {
     struct vlc_http_stream *s, *s2;
     struct vlc_http_msg *m;
-    struct block_t *b;
+    block_t *b;
     uint_fast32_t sid = -1; /* Second guessed stream IDs :-/ */
 
     conn_create();


=====================================
modules/access/http/live.c
=====================================
@@ -74,7 +74,7 @@ struct vlc_http_resource *vlc_http_live_create(struct vlc_http_mgr *mgr,
 
 block_t *vlc_http_live_read(struct vlc_http_resource *res)
 {
-    struct block_t *block = vlc_http_res_read(res);
+    block_t *block = vlc_http_res_read(res);
     if (block != NULL && block != vlc_http_error)
         return block;
 


=====================================
modules/access/http/live.h
=====================================
@@ -26,12 +26,11 @@
  */
 
 struct vlc_http_resource;
-struct block_t;
 
 struct vlc_http_resource *vlc_http_live_create(struct vlc_http_mgr *mgr,
                                                const char *uri, const char *ua,
                                                const char *ref);
-struct block_t *vlc_http_live_read(struct vlc_http_resource *);
+block_t *vlc_http_live_read(struct vlc_http_resource *);
 
 #define vlc_http_live_get_status vlc_http_res_get_status
 #define vlc_http_live_get_redirect vlc_http_res_get_redirect


=====================================
modules/access/http/message.h
=====================================
@@ -29,7 +29,6 @@
  */
 
 struct vlc_http_msg;
-struct block_t;
 struct vlc_http_cookie_jar_t;
 
 /**
@@ -296,7 +295,7 @@ struct vlc_http_msg *vlc_http_msg_get_final(struct vlc_http_msg *) VLC_USED;
  * @retval NULL on end-of-stream
  * @retval vlc_http_error on fatal error
  */
-struct block_t *vlc_http_msg_read(struct vlc_http_msg *) VLC_USED;
+block_t *vlc_http_msg_read(struct vlc_http_msg *) VLC_USED;
 
 /**
  * Sends HTTP data.
@@ -358,7 +357,7 @@ struct vlc_http_stream_cbs
 {
     struct vlc_http_msg *(*read_headers)(struct vlc_http_stream *);
     ssize_t (*write)(struct vlc_http_stream *, const void *, size_t, bool eos);
-    struct block_t *(*read)(struct vlc_http_stream *);
+    block_t *(*read)(struct vlc_http_stream *);
     void (*close)(struct vlc_http_stream *, bool abort);
 };
 
@@ -414,7 +413,7 @@ static inline ssize_t vlc_http_stream_write(struct vlc_http_stream *s,
  * @retval NULL The end of the stream was reached.
  * @retval vlc_http_error The stream encountered a fatal error.
  */
-static inline struct block_t *vlc_http_stream_read(struct vlc_http_stream *s)
+static inline block_t *vlc_http_stream_read(struct vlc_http_stream *s)
 {
     return s->cbs->read(s);
 }


=====================================
modules/access/http/outfile.h
=====================================
@@ -29,7 +29,6 @@
 
 struct vlc_http_mgr;
 struct vlc_http_outfile;
-struct block_t;
 
 /**
  * Creates an HTTP output file.


=====================================
modules/access/http/resource.c
=====================================
@@ -307,7 +307,7 @@ char *vlc_http_res_get_type(struct vlc_http_resource *res)
     return (type != NULL) ? strdup(type) : NULL;
 }
 
-struct block_t *vlc_http_res_read(struct vlc_http_resource *res)
+block_t *vlc_http_res_read(struct vlc_http_resource *res)
 {
     int status = vlc_http_res_get_status(res);
     if (status < 200 || status >= 300)


=====================================
modules/access/http/resource.h
=====================================
@@ -94,7 +94,7 @@ char *vlc_http_res_get_type(struct vlc_http_resource *);
 /**
  * Reads data.
  */
-struct block_t *vlc_http_res_read(struct vlc_http_resource *);
+block_t *vlc_http_res_read(struct vlc_http_resource *);
 
 int vlc_http_res_set_login(struct vlc_http_resource *res,
                            const char *username, const char *password);


=====================================
modules/demux/adaptive/http/Chunk.h
=====================================
@@ -33,7 +33,7 @@
 #include <stdint.h>
 #include <vlc_cxx_helpers.hpp>
 
-typedef struct block_t block_t;
+typedef struct vlc_frame_t block_t;
 
 namespace adaptive
 {


=====================================
po/POTFILES.in
=====================================
@@ -21,6 +21,7 @@ include/vlc_es_out.h
 include/vlc_events.h
 include/vlc_filter.h
 include/vlc_fixups.h
+include/vlc_frame.h
 include/vlc_gcrypt.h
 include/vlc_httpd.h
 include/vlc_image.h
@@ -88,11 +89,11 @@ src/libvlc.c
 src/libvlc.h
 src/libvlc-module.c
 src/misc/actions.c
-src/misc/block.c
 src/misc/cpu.c
 src/misc/es_format.c
 src/misc/events.c
 src/misc/filter_chain.c
+src/misc/frame.c
 src/misc/image.c
 src/misc/md5.c
 src/misc/messages.c


=====================================
src/Makefile.am
=====================================
@@ -53,6 +53,7 @@ pluginsinclude_HEADERS = \
 	../include/vlc_filter.h \
 	../include/vlc_fingerprinter.h \
 	../include/vlc_fourcc.h \
+	../include/vlc_frame.h \
 	../include/vlc_fs.h \
 	../include/vlc_gcrypt.h \
 	../include/vlc_hash.h \
@@ -363,7 +364,7 @@ libvlccore_la_SOURCES = \
 	misc/probe.c \
 	misc/rand.c \
 	misc/mtime.c \
-	misc/block.c \
+	misc/frame.c \
 	misc/fifo.c \
 	misc/fourcc.c \
 	misc/fourcc_list.h \


=====================================
src/input/decoder.c
=====================================
@@ -799,20 +799,20 @@ static float ModuleThread_GetDisplayRate( decoder_t *p_dec )
 /*****************************************************************************
  * Public functions
  *****************************************************************************/
-block_t *decoder_NewAudioBuffer( decoder_t *dec, int samples )
+vlc_frame_t *decoder_NewAudioBuffer( decoder_t *dec, int samples )
 {
     assert( dec->fmt_out.audio.i_frame_length > 0
          && dec->fmt_out.audio.i_bytes_per_frame  > 0 );
 
     size_t length = samples * dec->fmt_out.audio.i_bytes_per_frame
                             / dec->fmt_out.audio.i_frame_length;
-    block_t *block = block_Alloc( length );
-    if( likely(block != NULL) )
+    vlc_frame_t *frame = block_Alloc( length );
+    if( likely(frame != NULL) )
     {
-        block->i_nb_samples = samples;
-        block->i_pts = block->i_length = 0;
+        frame->i_nb_samples = samples;
+        frame->i_pts = frame->i_length = 0;
     }
-    return block;
+    return frame;
 }
 
 static void RequestReload( vlc_input_decoder_t *p_owner )
@@ -836,7 +836,7 @@ static void DecoderWaitUnblock( vlc_input_decoder_t *p_owner )
         vlc_cond_wait( &p_owner->wait_request, &p_owner->lock );
 }
 
-static inline void DecoderUpdatePreroll( vlc_tick_t *pi_preroll, const block_t *p )
+static inline void DecoderUpdatePreroll( vlc_tick_t *pi_preroll, const vlc_frame_t *p )
 {
     if( p->i_flags & BLOCK_FLAG_PREROLL )
         *pi_preroll = PREROLL_FORCED;
@@ -851,9 +851,9 @@ static inline void DecoderUpdatePreroll( vlc_tick_t *pi_preroll, const block_t *
 }
 
 #ifdef ENABLE_SOUT
-static int DecoderThread_PlaySout( vlc_input_decoder_t *p_owner, block_t *p_sout_block )
+static int DecoderThread_PlaySout( vlc_input_decoder_t *p_owner, vlc_frame_t *sout_frame )
 {
-    assert( !p_sout_block->p_next );
+    assert( !sout_frame->p_next );
 
     vlc_mutex_lock( &p_owner->lock );
 
@@ -863,19 +863,19 @@ static int DecoderThread_PlaySout( vlc_input_decoder_t *p_owner, block_t *p_sout
 
     /* FIXME --VLC_TICK_INVALID inspect stream_output*/
     return sout_InputSendBuffer( p_owner->p_sout, p_owner->p_sout_input,
-                                 p_sout_block );
+                                 sout_frame );
 }
 
-/* This function process a block for sout
+/* This function process a frame for sout
  */
-static void DecoderThread_ProcessSout( vlc_input_decoder_t *p_owner, block_t *p_block )
+static void DecoderThread_ProcessSout( vlc_input_decoder_t *p_owner, vlc_frame_t *frame )
 {
     decoder_t *p_dec = &p_owner->dec;
-    block_t *p_sout_block;
-    block_t **pp_block = p_block ? &p_block : NULL;
+    vlc_frame_t *sout_frame;
+    vlc_frame_t **ppframe = frame ? &frame : NULL;
 
-    while( ( p_sout_block =
-                 p_dec->pf_packetize( p_dec, pp_block ) ) )
+    while( ( sout_frame =
+                 p_dec->pf_packetize( p_dec, ppframe ) ) )
     {
         if( p_owner->p_sout_input == NULL )
         {
@@ -901,20 +901,20 @@ static void DecoderThread_ProcessSout( vlc_input_decoder_t *p_owner, block_t *p_
                          (char *)&p_owner->fmt.i_codec );
                 p_owner->error = true;
 
-                if(p_block)
-                    block_Release(p_block);
+                if(frame)
+                    block_Release(frame);
 
-                block_ChainRelease(p_sout_block);
+                block_ChainRelease(sout_frame);
                 break;
             }
         }
 
-        while( p_sout_block )
+        while( sout_frame )
         {
-            block_t *p_next = p_sout_block->p_next;
+            vlc_frame_t *p_next = sout_frame->p_next;
             bool b_wants_substreams;
 
-            p_sout_block->p_next = NULL;
+            sout_frame->p_next = NULL;
 
             if( p_dec->pf_get_cc
              && sout_StreamControl( p_owner->p_sout,
@@ -926,7 +926,7 @@ static void DecoderThread_ProcessSout( vlc_input_decoder_t *p_owner, block_t *p_
                     !p_owner->cc.b_sout_created )
                 {
                     decoder_cc_desc_t desc;
-                    block_t *p_cc = p_dec->pf_get_cc( p_dec, &desc );
+                    vlc_frame_t *p_cc = p_dec->pf_get_cc( p_dec, &desc );
                     if( p_cc )
                     {
                         if(!p_owner->cc.b_sout_created)
@@ -949,7 +949,7 @@ static void DecoderThread_ProcessSout( vlc_input_decoder_t *p_owner, block_t *p_
                 }
             }
 
-            if( DecoderThread_PlaySout( p_owner, p_sout_block ) == VLC_EGENERIC )
+            if( DecoderThread_PlaySout( p_owner, sout_frame ) == VLC_EGENERIC )
             {
                 msg_Err( p_dec, "cannot continue streaming due to errors with codec %4.4s",
                                 (char *)&p_owner->fmt.i_codec );
@@ -958,20 +958,20 @@ static void DecoderThread_ProcessSout( vlc_input_decoder_t *p_owner, block_t *p_
 
                 /* Cleanup */
 
-                if( p_block )
-                    block_Release( p_block );
+                if( frame )
+                    block_Release( frame );
 
                 block_ChainRelease( p_next );
                 return;
             }
 
-            p_sout_block = p_next;
+            sout_frame = p_next;
         }
     }
 }
 #endif
 
-static void DecoderPlayCc( vlc_input_decoder_t *p_owner, block_t *p_cc,
+static void DecoderPlayCc( vlc_input_decoder_t *p_owner, vlc_frame_t *p_cc,
                            const decoder_cc_desc_t *p_desc )
 {
     vlc_mutex_lock( &p_owner->lock );
@@ -1008,7 +1008,7 @@ static void DecoderPlayCc( vlc_input_decoder_t *p_owner, block_t *p_cc,
 
 static void PacketizerGetCc( vlc_input_decoder_t *p_owner, decoder_t *p_dec_cc )
 {
-    block_t *p_cc;
+    vlc_frame_t *p_cc;
     decoder_cc_desc_t desc;
 
     /* Do not try retreiving CC if not wanted (sout) or cannot be retreived */
@@ -1023,7 +1023,7 @@ static void PacketizerGetCc( vlc_input_decoder_t *p_owner, decoder_t *p_dec_cc )
     DecoderPlayCc( p_owner, p_cc, &desc );
 }
 
-static void ModuleThread_QueueCc( decoder_t *p_videodec, block_t *p_cc,
+static void ModuleThread_QueueCc( decoder_t *p_videodec, vlc_frame_t *p_cc,
                                   const decoder_cc_desc_t *p_desc )
 {
     vlc_input_decoder_t *p_owner = dec_get_owner( p_videodec );
@@ -1178,7 +1178,7 @@ static void ModuleThread_QueueThumbnail( decoder_t *p_dec, picture_t *p_pic )
 
 }
 
-static int ModuleThread_PlayAudio( vlc_input_decoder_t *p_owner, block_t *p_audio )
+static int ModuleThread_PlayAudio( vlc_input_decoder_t *p_owner, vlc_frame_t *p_audio )
 {
     decoder_t *p_dec = &p_owner->dec;
 
@@ -1258,7 +1258,7 @@ static void ModuleThread_UpdateStatAudio( vlc_input_decoder_t *p_owner,
     decoder_Notify(p_owner, on_new_audio_stats, 1, aout_lost, played);
 }
 
-static void ModuleThread_QueueAudio( decoder_t *p_dec, block_t *p_aout_buf )
+static void ModuleThread_QueueAudio( decoder_t *p_dec, vlc_frame_t *p_aout_buf )
 {
     vlc_input_decoder_t *p_owner = dec_get_owner( p_dec );
     struct vlc_tracer *tracer = vlc_object_get_tracer( &p_dec->obj );
@@ -1332,19 +1332,19 @@ static void ModuleThread_QueueSpu( decoder_t *p_dec, subpicture_t *p_spu )
     }
 }
 
-static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, block_t *p_block );
-static void DecoderThread_DecodeBlock( vlc_input_decoder_t *p_owner, block_t *p_block )
+static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, vlc_frame_t *frame );
+static void DecoderThread_DecodeBlock( vlc_input_decoder_t *p_owner, vlc_frame_t *frame )
 {
     decoder_t *p_dec = &p_owner->dec;
     struct vlc_tracer *tracer = vlc_object_get_tracer( &p_dec->obj );
 
-    if ( tracer != NULL && p_block != NULL )
+    if ( tracer != NULL && frame != NULL )
     {
         vlc_tracer_TraceStreamDTS( tracer, "DEC", p_owner->psz_id, "IN",
-                            p_block->i_pts, p_block->i_dts );
+                            frame->i_pts, frame->i_dts );
     }
 
-    int ret = p_dec->pf_decode( p_dec, p_block );
+    int ret = p_dec->pf_decode( p_dec, frame );
     switch( ret )
     {
         case VLCDEC_SUCCESS:
@@ -1354,15 +1354,15 @@ static void DecoderThread_DecodeBlock( vlc_input_decoder_t *p_owner, block_t *p_
             break;
         case VLCDEC_RELOAD:
             RequestReload( p_owner );
-            if( unlikely( p_block == NULL ) )
+            if( unlikely( frame == NULL ) )
                 break;
-            if( !( p_block->i_flags & BLOCK_FLAG_CORE_PRIVATE_RELOADED ) )
+            if( !( frame->i_flags & BLOCK_FLAG_CORE_PRIVATE_RELOADED ) )
             {
-                p_block->i_flags |= BLOCK_FLAG_CORE_PRIVATE_RELOADED;
-                DecoderThread_ProcessInput( p_owner, p_block );
+                frame->i_flags |= BLOCK_FLAG_CORE_PRIVATE_RELOADED;
+                DecoderThread_ProcessInput( p_owner, frame );
             }
-            else /* We prefer loosing this block than an infinite recursion */
-                block_Release( p_block );
+            else /* We prefer loosing this frame than an infinite recursion */
+                block_Release( frame );
             break;
         default:
             vlc_assert_unreachable();
@@ -1370,12 +1370,12 @@ static void DecoderThread_DecodeBlock( vlc_input_decoder_t *p_owner, block_t *p_
 }
 
 /**
- * Decode a block
+ * Decode a frame
  *
  * \param p_dec the decoder object
- * \param p_block the block to decode
+ * \param frame the block to decode
  */
-static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, block_t *p_block )
+static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, vlc_frame_t *frame )
 {
     decoder_t *p_dec = &p_owner->dec;
 
@@ -1385,7 +1385,7 @@ static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, block_t *p
     /* Here, the atomic doesn't prevent to miss a reload request.
      * DecoderThread_ProcessInput() can still be called after the decoder module or the
      * audio output requested a reload. This will only result in a drop of an
-     * input block or an output buffer. */
+     * input frame or an output buffer. */
     enum reload reload;
     if( ( reload = atomic_exchange( &p_owner->reload, RELOAD_NO_REQUEST ) ) )
     {
@@ -1397,17 +1397,17 @@ static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, block_t *p
     }
 
     bool packetize = p_owner->p_packetizer != NULL;
-    if( p_block )
+    if( frame )
     {
-        if( p_block->i_buffer <= 0 )
+        if( frame->i_buffer <= 0 )
             goto error;
 
         vlc_mutex_lock( &p_owner->lock );
-        DecoderUpdatePreroll( &p_owner->i_preroll_end, p_block );
+        DecoderUpdatePreroll( &p_owner->i_preroll_end, frame );
         vlc_mutex_unlock( &p_owner->lock );
-        if( unlikely( p_block->i_flags & BLOCK_FLAG_CORE_PRIVATE_RELOADED ) )
+        if( unlikely( frame->i_flags & BLOCK_FLAG_CORE_PRIVATE_RELOADED ) )
         {
-            /* This block has already been packetized */
+            /* This frame has already been packetized */
             packetize = false;
         }
     }
@@ -1415,18 +1415,18 @@ static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, block_t *p
 #ifdef ENABLE_SOUT
     if( p_owner->p_sout != NULL )
     {
-        DecoderThread_ProcessSout( p_owner, p_block );
+        DecoderThread_ProcessSout( p_owner, frame );
         return;
     }
 #endif
     if( packetize )
     {
-        block_t *p_packetized_block;
-        block_t **pp_block = p_block ? &p_block : NULL;
+        vlc_frame_t *packetized_frame;
+        vlc_frame_t **ppframe = frame ? &frame : NULL;
         decoder_t *p_packetizer = p_owner->p_packetizer;
 
-        while( (p_packetized_block =
-                p_packetizer->pf_packetize( p_packetizer, pp_block ) ) )
+        while( (packetized_frame =
+                p_packetizer->pf_packetize( p_packetizer, ppframe ) ) )
         {
             if( !es_format_IsSimilar( &p_dec->fmt_in, &p_packetizer->fmt_out ) )
             {
@@ -1438,7 +1438,7 @@ static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, block_t *p
                 if( DecoderThread_Reload( p_owner, &p_packetizer->fmt_out,
                                           RELOAD_DECODER ) != VLC_SUCCESS )
                 {
-                    block_ChainRelease( p_packetized_block );
+                    block_ChainRelease( packetized_frame );
                     return;
                 }
             }
@@ -1446,32 +1446,32 @@ static void DecoderThread_ProcessInput( vlc_input_decoder_t *p_owner, block_t *p
             if( p_packetizer->pf_get_cc )
                 PacketizerGetCc( p_owner, p_packetizer );
 
-            while( p_packetized_block )
+            while( packetized_frame )
             {
-                block_t *p_next = p_packetized_block->p_next;
-                p_packetized_block->p_next = NULL;
+                vlc_frame_t *p_next = packetized_frame->p_next;
+                packetized_frame->p_next = NULL;
 
-                DecoderThread_DecodeBlock( p_owner, p_packetized_block );
+                DecoderThread_DecodeBlock( p_owner, packetized_frame );
                 if( p_owner->error )
                 {
                     block_ChainRelease( p_next );
                     return;
                 }
 
-                p_packetized_block = p_next;
+                packetized_frame = p_next;
             }
         }
         /* Drain the decoder after the packetizer is drained */
-        if( !pp_block )
+        if( !ppframe )
             DecoderThread_DecodeBlock( p_owner, NULL );
     }
     else
-        DecoderThread_DecodeBlock( p_owner, p_block );
+        DecoderThread_DecodeBlock( p_owner, frame );
     return;
 
 error:
-    if( p_block )
-        block_Release( p_block );
+    if( frame )
+        block_Release( frame );
 }
 
 static void DecoderThread_Flush( vlc_input_decoder_t *p_owner )
@@ -1718,8 +1718,8 @@ static void *DecoderThread( void *p_data )
 
         vlc_cond_signal( &p_owner->wait_fifo );
 
-        block_t *p_block = vlc_fifo_DequeueUnlocked( p_owner->p_fifo );
-        if( p_block == NULL )
+        vlc_frame_t *frame = vlc_fifo_DequeueUnlocked( p_owner->p_fifo );
+        if( frame == NULL )
         {
             if( likely(!p_owner->b_draining) )
             {   /* Wait for a block to decode (or a request to drain) */
@@ -1730,14 +1730,14 @@ static void *DecoderThread( void *p_data )
                 continue;
             }
             /* We have emptied the FIFO and there is a pending request to
-             * drain. Pass p_block = NULL to decoder just once. */
+             * drain. Pass frame = NULL to decoder just once. */
         }
 
         vlc_fifo_Unlock( p_owner->p_fifo );
 
-        DecoderThread_ProcessInput( p_owner, p_block );
+        DecoderThread_ProcessInput( p_owner, frame );
 
-        if( p_block == NULL && p_owner->dec.fmt_in.i_cat == AUDIO_ES )
+        if( frame == NULL && p_owner->dec.fmt_in.i_cat == AUDIO_ES )
         {   /* Draining: the decoder is drained and all decoded buffers are
              * queued to the output at this point. Now drain the output. */
             if( p_owner->p_aout != NULL )
@@ -1747,7 +1747,7 @@ static void *DecoderThread( void *p_data )
         /* TODO? Wait for draining instead of polling. */
         vlc_mutex_lock( &p_owner->lock );
         vlc_fifo_Lock( p_owner->p_fifo );
-        if( p_owner->b_draining && (p_block == NULL) )
+        if( p_owner->b_draining && (frame == NULL) )
         {
             p_owner->b_draining = false;
             p_owner->drained = true;
@@ -2231,13 +2231,13 @@ void vlc_input_decoder_Delete( vlc_input_decoder_t *p_owner )
 }
 
 /**
- * Put a block_t in the decoder's fifo.
+ * Put a vlc_frame_t in the decoder's fifo.
  * Thread-safe w.r.t. the decoder. May be a cancellation point.
  *
  * \param p_dec the decoder object
- * \param p_block the data block
+ * \param frame the data frame
  */
-void vlc_input_decoder_Decode( vlc_input_decoder_t *p_owner, block_t *p_block,
+void vlc_input_decoder_Decode( vlc_input_decoder_t *p_owner, vlc_frame_t *frame,
                                bool b_do_pace )
 {
     vlc_fifo_Lock( p_owner->p_fifo );
@@ -2251,7 +2251,7 @@ void vlc_input_decoder_Decode( vlc_input_decoder_t *p_owner, block_t *p_block,
             msg_Warn( &p_owner->dec, "decoder/packetizer fifo full (data not "
                       "consumed quickly enough), resetting fifo!" );
             block_ChainRelease( vlc_fifo_DequeueAllUnlocked( p_owner->p_fifo ) );
-            p_block->i_flags |= BLOCK_FLAG_DISCONTINUITY;
+            frame->i_flags |= BLOCK_FLAG_DISCONTINUITY;
         }
     }
     else
@@ -2263,7 +2263,7 @@ void vlc_input_decoder_Decode( vlc_input_decoder_t *p_owner, block_t *p_block,
             vlc_fifo_WaitCond( p_owner->p_fifo, &p_owner->wait_fifo );
     }
 
-    vlc_fifo_QueueUnlocked( p_owner->p_fifo, p_block );
+    vlc_fifo_QueueUnlocked( p_owner->p_fifo, frame );
     vlc_fifo_Unlock( p_owner->p_fifo );
 }
 
@@ -2299,7 +2299,7 @@ bool vlc_input_decoder_IsEmpty( vlc_input_decoder_t * p_owner )
 }
 
 /**
- * Signals that there are no further blocks to decode, and requests that the
+ * Signals that there are no further frames to decode, and requests that the
  * decoder drain all pending buffers. This is used to ensure that all
  * intermediate buffers empty and no samples get lost at the end of the stream.
  *


=====================================
src/libvlccore.sym
=====================================
@@ -36,20 +36,20 @@ vlc_audio_meter_AddPlugin
 vlc_audio_meter_RemovePlugin
 vlc_audio_meter_Process
 vlc_audio_meter_Flush
-block_Alloc
-block_FifoGet
-block_FifoNew
-block_FifoRelease
-block_FifoShow
-block_File
-block_FilePath
-block_heap_Alloc
-block_Init
-block_mmap_Alloc
-block_shm_Alloc
-block_Realloc
-block_Release
-block_TryRealloc
+vlc_fifo_Get
+vlc_fifo_New
+vlc_fifo_Release
+vlc_fifo_Show
+vlc_frame_Alloc
+vlc_frame_File
+vlc_frame_FilePath
+vlc_frame_heap_Alloc
+vlc_frame_Init
+vlc_frame_mmap_Alloc
+vlc_frame_shm_Alloc
+vlc_frame_Realloc
+vlc_frame_Release
+vlc_frame_TryRealloc
 config_AddIntf
 config_ChainCreate
 config_ChainDestroy


=====================================
src/misc/fifo.c
=====================================
@@ -35,7 +35,7 @@
 /**
  * Internal state for block queues
  */
-struct block_fifo_t
+struct vlc_fifo_t
 {
     vlc_queue_t         q;
     size_t              i_depth;
@@ -44,13 +44,13 @@ struct block_fifo_t
 
 static_assert (offsetof (block_fifo_t, q) == 0, "Problems in <vlc_block.h>");
 
-size_t vlc_fifo_GetCount(const vlc_fifo_t *fifo)
+size_t vlc_fifo_GetCount(const block_fifo_t *fifo)
 {
     vlc_mutex_assert(&fifo->q.lock);
     return fifo->i_depth;
 }
 
-size_t vlc_fifo_GetBytes(const vlc_fifo_t *fifo)
+size_t vlc_fifo_GetBytes(const block_fifo_t *fifo)
 {
     vlc_mutex_assert(&fifo->q.lock);
     return fifo->i_size;
@@ -87,7 +87,7 @@ block_t *vlc_fifo_DequeueAllUnlocked(block_fifo_t *fifo)
     return vlc_queue_DequeueAllUnlocked(&fifo->q);
 }
 
-block_fifo_t *block_FifoNew( void )
+block_fifo_t *vlc_fifo_New( void )
 {
     block_fifo_t *p_fifo = malloc( sizeof( block_fifo_t ) );
 
@@ -100,13 +100,13 @@ block_fifo_t *block_FifoNew( void )
     return p_fifo;
 }
 
-void block_FifoRelease( block_fifo_t *p_fifo )
+void vlc_fifo_Release( block_fifo_t *p_fifo )
 {
-    block_FifoEmpty(p_fifo);
+    vlc_fifo_Empty(p_fifo);
     free( p_fifo );
 }
 
-block_t *block_FifoGet(block_fifo_t *fifo)
+block_t *vlc_fifo_Get(block_fifo_t *fifo)
 {
     block_t *block;
 
@@ -125,7 +125,7 @@ block_t *block_FifoGet(block_fifo_t *fifo)
     return block;
 }
 
-block_t *block_FifoShow( block_fifo_t *p_fifo )
+block_t *vlc_fifo_Show( block_fifo_t *p_fifo )
 {
     block_t *b;
 


=====================================
src/misc/block.c → src/misc/frame.c
=====================================
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * block.c: Data blocks management functions
+ * frame.c: frames management functions
  *****************************************************************************
  * Copyright (C) 2003-2004 VLC authors and VideoLAN
  * Copyright (C) 2007-2009 Rémi Denis-Courmont
@@ -32,62 +32,62 @@
 #include <fcntl.h>
 
 #include <vlc_common.h>
-#include <vlc_block.h>
+#include <vlc_frame.h>
 #include <vlc_fs.h>
 
 #ifndef NDEBUG
-static void block_Check (block_t *block)
+static void vlc_frame_Check (vlc_frame_t *frame)
 {
-    while (block != NULL)
+    while (frame != NULL)
     {
-        unsigned char *start = block->p_start;
-        unsigned char *end = block->p_start + block->i_size;
-        unsigned char *bufstart = block->p_buffer;
-        unsigned char *bufend = block->p_buffer + block->i_buffer;
+        unsigned char *start = frame->p_start;
+        unsigned char *end = frame->p_start + frame->i_size;
+        unsigned char *bufstart = frame->p_buffer;
+        unsigned char *bufend = frame->p_buffer + frame->i_buffer;
 
         assert (start <= end);
         assert (bufstart <= bufend);
         assert (bufstart >= start);
         assert (bufend <= end);
 
-        block = block->p_next;
+        frame = frame->p_next;
     }
 }
 #else
-# define block_Check(b) ((void)(b))
+# define vlc_frame_Check(b) ((void)(b))
 #endif
 
-block_t *block_Init(block_t *restrict b, const struct vlc_block_callbacks *cbs,
-                    void *buf, size_t size)
+vlc_frame_t *vlc_frame_Init(vlc_frame_t *restrict f, const struct vlc_frame_callbacks *cbs,
+                            void *buf, size_t size)
 {
     /* Fill all fields to their default */
-    b->p_next = NULL;
-    b->p_buffer = buf;
-    b->i_buffer = size;
-    b->p_start = buf;
-    b->i_size = size;
-    b->i_flags = 0;
-    b->i_nb_samples = 0;
-    b->i_pts =
-    b->i_dts = VLC_TICK_INVALID;
-    b->i_length = 0;
-    b->cbs = cbs;
-    return b;
+    f->p_next = NULL;
+    f->p_buffer = buf;
+    f->i_buffer = size;
+    f->p_start = buf;
+    f->i_size = size;
+    f->i_flags = 0;
+    f->i_nb_samples = 0;
+    f->i_pts =
+    f->i_dts = VLC_TICK_INVALID;
+    f->i_length = 0;
+    f->cbs = cbs;
+    return f;
 }
 
-static void block_generic_Release (block_t *block)
+static void vlc_frame_generic_Release (vlc_frame_t *frame)
 {
-    /* That is always true for blocks allocated with block_Alloc(). */
-    assert (block->p_start == (unsigned char *)(block + 1));
-    free (block);
+    /* That is always true for frames allocated with vlc_frame_Alloc(). */
+    assert (frame->p_start == (unsigned char *)(frame + 1));
+    free (frame);
 }
 
-static const struct vlc_block_callbacks block_generic_cbs =
+static const struct vlc_frame_callbacks vlc_frame_generic_cbs =
 {
-    block_generic_Release,
+    vlc_frame_generic_Release,
 };
 
-static void BlockMetaCopy( block_t *restrict out, const block_t *in )
+static void BlockMetaCopy( vlc_frame_t *restrict out, const vlc_frame_t *in )
 {
     out->p_next    = in->p_next;
     out->i_nb_samples = in->i_nb_samples;
@@ -97,15 +97,15 @@ static void BlockMetaCopy( block_t *restrict out, const block_t *in )
     out->i_length  = in->i_length;
 }
 
-/** Initial memory alignment of data block.
+/** Initial memory alignment of data frame.
  * @note This must be a multiple of sizeof(void*) and a power of two.
  * libavcodec AVX optimizations require at least 32-bytes. */
-#define BLOCK_ALIGN        32
+#define VLC_FRAME_ALIGN        32
 
 /** Initial reserved header and footer size. */
-#define BLOCK_PADDING      32
+#define VLC_FRAME_PADDING      32
 
-block_t *block_Alloc (size_t size)
+vlc_frame_t *vlc_frame_Alloc (size_t size)
 {
     if (unlikely(size >> 28))
     {
@@ -113,171 +113,168 @@ block_t *block_Alloc (size_t size)
         return NULL;
     }
 
-    /* 2 * BLOCK_PADDING: pre + post padding */
-    const size_t alloc = sizeof (block_t) + BLOCK_ALIGN + (2 * BLOCK_PADDING)
+    /* 2 * VLC_FRAME_PADDING: pre + post padding */
+    const size_t alloc = sizeof (vlc_frame_t) + VLC_FRAME_ALIGN + (2 * VLC_FRAME_PADDING)
                        + size;
     if (unlikely(alloc <= size))
         return NULL;
 
-    block_t *b = malloc (alloc);
-    if (unlikely(b == NULL))
+    vlc_frame_t *f = malloc (alloc);
+    if (unlikely(f == NULL))
         return NULL;
 
-    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;
-    return b;
+    vlc_frame_Init(f, &vlc_frame_generic_cbs, f + 1, alloc - sizeof (*f));
+    static_assert ((VLC_FRAME_PADDING % VLC_FRAME_ALIGN) == 0,
+                   "VLC_FRAME_PADDING must be a multiple of VLC_FRAME_ALIGN");
+    f->p_buffer += VLC_FRAME_PADDING + VLC_FRAME_ALIGN - 1;
+    f->p_buffer = (void *)(((uintptr_t)f->p_buffer) & ~(VLC_FRAME_ALIGN - 1));
+    f->i_buffer = size;
+    return f;
 }
 
-void block_Release(block_t *block)
+void vlc_frame_Release(vlc_frame_t *frame)
 {
 #ifndef NDEBUG
-    block->p_next = NULL;
-    block_Check (block);
+    frame->p_next = NULL;
+    vlc_frame_Check (frame);
 #endif
-    block->cbs->free(block);
+    frame->cbs->free(frame);
 }
 
-block_t *block_TryRealloc (block_t *p_block, ssize_t i_prebody, size_t i_body)
+static vlc_frame_t *vlc_frame_ReallocDup( vlc_frame_t *frame, ssize_t i_prebody, size_t requested )
 {
-    block_Check( p_block );
+    vlc_frame_t *p_rea = vlc_frame_Alloc( requested );
+    if( p_rea == NULL )
+        return NULL;
+
+    if( frame->i_buffer > 0 )
+        memcpy( p_rea->p_buffer + i_prebody, frame->p_buffer, frame->i_buffer );
+    BlockMetaCopy( p_rea, frame );
+    vlc_frame_Release( frame );
+    return p_rea;
+}
+
+vlc_frame_t *vlc_frame_TryRealloc (vlc_frame_t *frame, ssize_t i_prebody, size_t i_body)
+{
+    vlc_frame_Check( frame );
 
-    /* Corner case: empty block requested */
+    /* Corner case: empty frame requested */
     if( i_prebody <= 0 && i_body <= (size_t)(-i_prebody) )
         i_prebody = i_body = 0;
 
-    assert( p_block->p_start <= p_block->p_buffer );
-    assert( p_block->p_start + p_block->i_size
-                                    >= p_block->p_buffer + p_block->i_buffer );
+    assert( frame->p_start <= frame->p_buffer );
+    assert( frame->p_start + frame->i_size
+                                    >= frame->p_buffer + frame->i_buffer );
 
     /* First, shrink payload */
 
     /* Pull payload start */
     if( i_prebody < 0 )
     {
-        if( p_block->i_buffer >= (size_t)-i_prebody )
+        if( frame->i_buffer >= (size_t)-i_prebody )
         {
-            p_block->p_buffer -= i_prebody;
-            p_block->i_buffer += i_prebody;
+            frame->p_buffer -= i_prebody;
+            frame->i_buffer += i_prebody;
         }
         else /* Discard current payload entirely */
-            p_block->i_buffer = 0;
+            frame->i_buffer = 0;
         i_body += i_prebody;
         i_prebody = 0;
     }
 
     /* Trim payload end */
-    if( p_block->i_buffer > i_body )
-        p_block->i_buffer = i_body;
+    if( frame->i_buffer > i_body )
+        frame->i_buffer = i_body;
 
     size_t requested = i_prebody + i_body;
 
-    if( p_block->i_buffer == 0 )
+    if( frame->i_buffer == 0 )
     {   /* Corner case: nothing to preserve */
-        if( requested <= p_block->i_size )
+        if( requested <= frame->i_size )
         {   /* Enough room: recycle buffer */
-            size_t extra = p_block->i_size - requested;
+            size_t extra = frame->i_size - requested;
 
-            p_block->p_buffer = p_block->p_start + (extra / 2);
-            p_block->i_buffer = requested;
-            return p_block;
+            frame->p_buffer = frame->p_start + (extra / 2);
+            frame->i_buffer = requested;
+            return frame;
         }
 
         /* Not enough room: allocate a new buffer */
-        block_t *p_rea = block_Alloc( requested );
-        if( p_rea == NULL )
-            return NULL;
-
-        BlockMetaCopy( p_rea, p_block );
-        block_Release( p_block );
-        return p_rea;
+        return vlc_frame_ReallocDup( frame, i_prebody, requested );
     }
 
-    uint8_t *p_start = p_block->p_start;
-    uint8_t *p_end = p_start + p_block->i_size;
+    uint8_t *p_start = frame->p_start;
+    uint8_t *p_end = p_start + frame->i_size;
 
     /* Second, reallocate the buffer if we lack space. */
     assert( i_prebody >= 0 );
-    if( (size_t)(p_block->p_buffer - p_start) < (size_t)i_prebody
-     || (size_t)(p_end - p_block->p_buffer) < i_body )
-    {
-        block_t *p_rea = block_Alloc( requested );
-        if( p_rea == NULL )
-            return NULL;
-
-        memcpy( p_rea->p_buffer + i_prebody, p_block->p_buffer,
-                p_block->i_buffer );
-        BlockMetaCopy( p_rea, p_block );
-        block_Release( p_block );
-        return p_rea;
-    }
+    if( (size_t)(frame->p_buffer - p_start) < (size_t)i_prebody
+     || (size_t)(p_end - frame->p_buffer) < i_body )
+        return vlc_frame_ReallocDup( frame, i_prebody, requested );
 
     /* Third, expand payload */
 
     /* Push payload start */
     if( i_prebody > 0 )
     {
-        p_block->p_buffer -= i_prebody;
-        p_block->i_buffer += i_prebody;
+        frame->p_buffer -= i_prebody;
+        frame->i_buffer += i_prebody;
         i_body += i_prebody;
         i_prebody = 0;
     }
 
     /* Expand payload to requested size */
-    p_block->i_buffer = i_body;
+    frame->i_buffer = i_body;
 
-    return p_block;
+    return frame;
 }
 
-block_t *block_Realloc (block_t *block, ssize_t prebody, size_t body)
+vlc_frame_t *vlc_frame_Realloc (vlc_frame_t *frame, ssize_t prebody, size_t body)
 {
-    block_t *rea = block_TryRealloc (block, prebody, body);
+    vlc_frame_t *rea = vlc_frame_TryRealloc (frame, prebody, body);
     if (rea == NULL)
-        block_Release(block);
+        vlc_frame_Release(frame);
     return rea;
 }
 
-static void block_heap_Release (block_t *block)
+static void vlc_frame_heap_Release (vlc_frame_t *frame)
 {
-    free (block->p_start);
-    free (block);
+    free (frame->p_start);
+    free (frame);
 }
 
-static const struct vlc_block_callbacks block_heap_cbs =
+static const struct vlc_frame_callbacks vlc_frame_heap_cbs =
 {
-    block_heap_Release,
+    vlc_frame_heap_Release,
 };
 
-block_t *block_heap_Alloc (void *addr, size_t length)
+vlc_frame_t *vlc_frame_heap_Alloc (void *addr, size_t length)
 {
-    block_t *block = malloc (sizeof (*block));
-    if (block == NULL)
+    vlc_frame_t *frame = malloc (sizeof (*frame));
+    if (frame == NULL)
     {
         free (addr);
         return NULL;
     }
 
-    return block_Init(block, &block_heap_cbs, addr, length);
+    return vlc_frame_Init(frame, &vlc_frame_heap_cbs, addr, length);
 }
 
 #ifdef HAVE_MMAP
 # include <sys/mman.h>
 
-static void block_mmap_Release (block_t *block)
+static void vlc_frame_mmap_Release (vlc_frame_t *frame)
 {
-    munmap (block->p_start, block->i_size);
-    free (block);
+    munmap (frame->p_start, frame->i_size);
+    free (frame);
 }
 
-static const struct vlc_block_callbacks block_mmap_cbs =
+static const struct vlc_frame_callbacks vlc_frame_mmap_cbs =
 {
-    block_mmap_Release,
+    vlc_frame_mmap_Release,
 };
 
-block_t *block_mmap_Alloc (void *addr, size_t length)
+vlc_frame_t *vlc_frame_mmap_Alloc (void *addr, size_t length)
 {
     if (addr == MAP_FAILED)
         return NULL;
@@ -286,90 +283,90 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
     size_t left = ((uintptr_t)addr) & page_mask;
     size_t right = (-length) & page_mask;
 
-    block_t *block = malloc (sizeof (*block));
-    if (block == NULL)
+    vlc_frame_t *frame = malloc (sizeof (*frame));
+    if (frame == NULL)
     {
         munmap (addr, length);
         return NULL;
     }
 
-    block_Init(block, &block_mmap_cbs,
+    vlc_frame_Init(frame, &vlc_frame_mmap_cbs,
                ((char *)addr) - left, left + length + right);
-    block->p_buffer = addr;
-    block->i_buffer = length;
-    return block;
+    frame->p_buffer = addr;
+    frame->i_buffer = length;
+    return frame;
 }
 #else
-block_t *block_mmap_Alloc (void *addr, size_t length)
+vlc_frame_t *vlc_frame_mmap_Alloc (void *addr, size_t length)
 {
     (void)addr; (void)length; return NULL;
 }
 #endif
 #if defined(_WIN32)
-struct block_mv
+struct vlc_frame_mv
 {
-    block_t b;
+    vlc_frame_t b;
     HANDLE  hMap;
 };
 
-static void block_mapview_Release (block_t *block)
+static void vlc_frame_mapview_Release (vlc_frame_t *frame)
 {
-    struct block_mv *mvblock = container_of(block, struct block_mv, b);
+    struct vlc_frame_mv *mvframe = container_of(frame, struct vlc_frame_mv, b);
 
-    UnmapViewOfFile(block->p_start);
-    CloseHandle(mvblock->hMap);
-    free(mvblock);
+    UnmapViewOfFile(frame->p_start);
+    CloseHandle(mvframe->hMap);
+    free(mvframe);
 }
 
-static const struct vlc_block_callbacks block_mapview_cbs =
+static const struct vlc_frame_callbacks vlc_frame_mapview_cbs =
 {
-    block_mapview_Release,
+    vlc_frame_mapview_Release,
 };
 
-static block_t *block_mapview_Alloc(HANDLE hMap, void *addr, size_t length)
+static vlc_frame_t *vlc_frame_mapview_Alloc(HANDLE hMap, void *addr, size_t length)
 {
-    struct block_mv *mvblock = malloc (sizeof (*mvblock));
-    if (unlikely(mvblock == NULL))
+    struct vlc_frame_mv *mvframe = malloc (sizeof (*mvframe));
+    if (unlikely(mvframe == NULL))
     {
         UnmapViewOfFile(addr);
         CloseHandle(hMap);
         return NULL;
     }
-    mvblock->hMap = hMap;
+    mvframe->hMap = hMap;
 
-    block_t *block = &mvblock->b;
-    block_Init(block, &block_mapview_cbs, addr, length);
-    return block;
+    vlc_frame_t *frame = &mvframe->b;
+    vlc_frame_Init(frame, &vlc_frame_mapview_cbs, addr, length);
+    return frame;
 }
 #endif
 
 #ifdef HAVE_SYS_SHM_H
 # include <sys/shm.h>
 
-static void block_shm_Release (block_t *block)
+static void vlc_frame_shm_Release (vlc_frame_t *frame)
 {
-    shmdt(block->p_start);
-    free(block);
+    shmdt(frame->p_start);
+    free(frame);
 }
 
-static const struct vlc_block_callbacks block_shm_cbs =
+static const struct vlc_frame_callbacks vlc_frame_shm_cbs =
 {
-    block_shm_Release,
+    vlc_frame_shm_Release,
 };
 
-block_t *block_shm_Alloc (void *addr, size_t length)
+vlc_frame_t *vlc_frame_shm_Alloc (void *addr, size_t length)
 {
-    block_t *block = malloc (sizeof (*block));
-    if (unlikely(block == NULL))
+    vlc_frame_t *frame = malloc (sizeof (*frame));
+    if (unlikely(frame == NULL))
     {
         shmdt (addr);
         return NULL;
     }
 
-    return block_Init(block, &block_shm_cbs, (uint8_t *)addr, length);
+    return vlc_frame_Init(frame, &vlc_frame_shm_cbs, (uint8_t *)addr, length);
 }
 #else
-block_t *block_shm_Alloc (void *addr, size_t length)
+vlc_frame_t *vlc_frame_shm_Alloc (void *addr, size_t length)
 {
     (void) addr; (void) length;
     abort ();
@@ -398,7 +395,7 @@ ssize_t pread (int fd, void *buf, size_t count, off_t offset)
 }
 #endif
 
-block_t *block_File(int fd, bool write)
+vlc_frame_t *vlc_frame_File(int fd, bool write)
 {
     size_t length;
     struct stat st;
@@ -440,7 +437,7 @@ block_t *block_File(int fd, bool write)
         void *addr = mmap(NULL, length, prot, flags, fd, 0);
 
         if (addr != MAP_FAILED)
-            return block_mmap_Alloc (addr, length);
+            return vlc_frame_mmap_Alloc (addr, length);
     }
 #elif defined(_WIN32)
     if (length > 0)
@@ -463,7 +460,7 @@ block_t *block_File(int fd, bool write)
 #endif
 
             if (addr != NULL)
-                return block_mapview_Alloc(hMap, addr, length);
+                return vlc_frame_mapview_Alloc(hMap, addr, length);
 
             CloseHandle(hMap);
         }
@@ -473,27 +470,27 @@ block_t *block_File(int fd, bool write)
 #endif
 
     /* If mmap() is not implemented by the OS _or_ the filesystem... */
-    block_t *block = block_Alloc (length);
-    if (block == NULL)
+    vlc_frame_t *frame = vlc_frame_Alloc (length);
+    if (frame == NULL)
         return NULL;
-    block_cleanup_push (block);
+    vlc_frame_cleanup_push (frame);
 
     for (size_t i = 0; i < length;)
     {
-        ssize_t len = pread (fd, block->p_buffer + i, length - i, i);
+        ssize_t len = pread (fd, frame->p_buffer + i, length - i, i);
         if (len == -1)
         {
-            block_Release (block);
-            block = NULL;
+            vlc_frame_Release (frame);
+            frame = NULL;
             break;
         }
         i += len;
     }
     vlc_cleanup_pop ();
-    return block;
+    return frame;
 }
 
-block_t *block_FilePath(const char *path, bool write)
+vlc_frame_t *vlc_frame_FilePath(const char *path, bool write)
 {
     /* NOTE: Writeable shared mappings are not supported here. So there are no
      * needs to open the file for writing (even if the mapping is writable). */
@@ -501,7 +498,7 @@ block_t *block_FilePath(const char *path, bool write)
     if (fd == -1)
         return NULL;
 
-    block_t *block = block_File(fd, write);
+    vlc_frame_t *frame = vlc_frame_File(fd, write);
     vlc_close (fd);
-    return block;
+    return frame;
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9958d3dbda2977b85dd3504851d0cb429035b0ea...543d402ecbf078f3cdd5293ef80b5f14a6c9665c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9958d3dbda2977b85dd3504851d0cb429035b0ea...543d402ecbf078f3cdd5293ef80b5f14a6c9665c
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list