VLC  3.0.15
Modules | Files | Data Structures | Macros | Typedefs | Functions
Data blocks
Collaboration diagram for Data blocks:

Modules

 Block chain
 
 Block FIFO
 Thread-safe block queue functions.
 

Files

file  vlc_block.h
 

Data Structures

struct  block_t
 

Macros

#define BLOCK_FLAG_DISCONTINUITY   0x0001
 The content doesn't follow the last block, possible some blocks in between have been lost. More...
 
#define BLOCK_FLAG_TYPE_I   0x0002
 Intra frame. More...
 
#define BLOCK_FLAG_TYPE_P   0x0004
 Inter frame with backward reference only. More...
 
#define BLOCK_FLAG_TYPE_B   0x0008
 Inter frame with backward and forward reference. More...
 
#define BLOCK_FLAG_TYPE_PB   0x0010
 For inter frame when you don't know the real type. More...
 
#define BLOCK_FLAG_HEADER   0x0020
 Warn that this block is a header one. More...
 
#define BLOCK_FLAG_END_OF_SEQUENCE   0x0040
 This block contains the last part of a sequence
More...
 
#define BLOCK_FLAG_CLOCK   0x0080
 This block contains a clock reference. More...
 
#define BLOCK_FLAG_SCRAMBLED   0x0100
 This block is scrambled. More...
 
#define BLOCK_FLAG_PREROLL   0x0200
 This block has to be decoded but not be displayed. More...
 
#define BLOCK_FLAG_CORRUPTED   0x0400
 This block is corrupted and/or there is data loss
More...
 
#define BLOCK_FLAG_TOP_FIELD_FIRST   0x0800
 This block contains an interlaced picture with top field stored first. More...
 
#define BLOCK_FLAG_BOTTOM_FIELD_FIRST   0x1000
 This block contains an interlaced picture with bottom field stored first. More...
 
#define BLOCK_FLAG_SINGLE_FIELD   0x2000
 This block contains a single field from interlaced picture. More...
 
#define BLOCK_FLAG_INTERLACED_MASK   (BLOCK_FLAG_TOP_FIELD_FIRST|BLOCK_FLAG_BOTTOM_FIELD_FIRST|BLOCK_FLAG_SINGLE_FIELD)
 This block contains an interlaced picture. More...
 
#define BLOCK_FLAG_TYPE_MASK   (BLOCK_FLAG_TYPE_I|BLOCK_FLAG_TYPE_P|BLOCK_FLAG_TYPE_B|BLOCK_FLAG_TYPE_PB)
 
#define BLOCK_FLAG_CORE_PRIVATE_MASK   0x00ff0000
 
#define BLOCK_FLAG_CORE_PRIVATE_SHIFT   16
 
#define BLOCK_FLAG_PRIVATE_MASK   0xff000000
 
#define BLOCK_FLAG_PRIVATE_SHIFT   24
 
#define block_cleanup_push(block)   vlc_cleanup_push (block_Cleanup, block)
 

Typedefs

typedef void(* block_free_t) (block_t *)
 

Functions

void block_Init (block_t *, void *, size_t)
 
block_tblock_Alloc (size_t size)
 Allocates a block. More...
 
block_tblock_TryRealloc (block_t *, ssize_t pre, size_t body)
 
block_tblock_Realloc (block_t *, ssize_t pre, size_t body)
 Reallocates a block. More...
 
static void block_Release (block_t *block)
 Releases a block. More...
 
static void block_CopyProperties (block_t *dst, block_t *src)
 
static block_tblock_Duplicate (block_t *p_block)
 Duplicates a block. More...
 
block_tblock_heap_Alloc (void *, size_t)
 Wraps heap in a block. More...
 
block_tblock_mmap_Alloc (void *addr, size_t length)
 Wraps a memory mapping in a block. More...
 
block_tblock_shm_Alloc (void *addr, size_t length)
 Wraps a System V memory segment in a block. More...
 
block_tblock_File (int fd, bool write)
 Maps a file handle in memory. More...
 
block_tblock_FilePath (const char *, bool write)
 Maps a file in memory. More...
 
static void block_Cleanup (void *block)
 

Detailed Description

Blocks of binary data.

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 Demultiplexer, the packetizer (if present) and the Decoder, and for audio, between the Decoder, the audio filters, and the Audio output.

Macro Definition Documentation

◆ block_cleanup_push

#define block_cleanup_push (   block)    vlc_cleanup_push (block_Cleanup, block)

◆ BLOCK_FLAG_BOTTOM_FIELD_FIRST

#define BLOCK_FLAG_BOTTOM_FIELD_FIRST   0x1000

This block contains an interlaced picture with bottom field stored first.

◆ BLOCK_FLAG_CLOCK

#define BLOCK_FLAG_CLOCK   0x0080

This block contains a clock reference.

◆ BLOCK_FLAG_CORE_PRIVATE_MASK

#define BLOCK_FLAG_CORE_PRIVATE_MASK   0x00ff0000

◆ BLOCK_FLAG_CORE_PRIVATE_SHIFT

#define BLOCK_FLAG_CORE_PRIVATE_SHIFT   16

◆ BLOCK_FLAG_CORRUPTED

#define BLOCK_FLAG_CORRUPTED   0x0400

This block is corrupted and/or there is data loss

◆ BLOCK_FLAG_DISCONTINUITY

#define BLOCK_FLAG_DISCONTINUITY   0x0001

The content doesn't follow the last block, possible some blocks in between have been lost.

◆ BLOCK_FLAG_END_OF_SEQUENCE

#define BLOCK_FLAG_END_OF_SEQUENCE   0x0040

This block contains the last part of a sequence

◆ BLOCK_FLAG_HEADER

#define BLOCK_FLAG_HEADER   0x0020

Warn that this block is a header one.

◆ BLOCK_FLAG_INTERLACED_MASK

This block contains an interlaced picture.

◆ BLOCK_FLAG_PREROLL

#define BLOCK_FLAG_PREROLL   0x0200

This block has to be decoded but not be displayed.

◆ BLOCK_FLAG_PRIVATE_MASK

#define BLOCK_FLAG_PRIVATE_MASK   0xff000000

◆ BLOCK_FLAG_PRIVATE_SHIFT

#define BLOCK_FLAG_PRIVATE_SHIFT   24

◆ BLOCK_FLAG_SCRAMBLED

#define BLOCK_FLAG_SCRAMBLED   0x0100

This block is scrambled.

◆ BLOCK_FLAG_SINGLE_FIELD

#define BLOCK_FLAG_SINGLE_FIELD   0x2000

This block contains a single field from interlaced picture.

◆ BLOCK_FLAG_TOP_FIELD_FIRST

#define BLOCK_FLAG_TOP_FIELD_FIRST   0x0800

This block contains an interlaced picture with top field stored first.

◆ BLOCK_FLAG_TYPE_B

#define BLOCK_FLAG_TYPE_B   0x0008

Inter frame with backward and forward reference.

◆ BLOCK_FLAG_TYPE_I

#define BLOCK_FLAG_TYPE_I   0x0002

Intra frame.

◆ BLOCK_FLAG_TYPE_MASK

◆ BLOCK_FLAG_TYPE_P

#define BLOCK_FLAG_TYPE_P   0x0004

Inter frame with backward reference only.

◆ BLOCK_FLAG_TYPE_PB

#define BLOCK_FLAG_TYPE_PB   0x0010

For inter frame when you don't know the real type.

Typedef Documentation

◆ block_free_t

typedef void(* block_free_t) (block_t *)

Function Documentation

◆ block_Alloc()

block_t* block_Alloc ( size_t  size)

Allocates a block.

Creates a new block with the requested size. The block must be released with block_Release().

Parameters
sizesize in bytes (possibly zero)
Returns
the created block, or NULL on memory error.

References BLOCK_ALIGN, block_generic_Release(), block_Init(), BLOCK_PADDING, block_t::i_buffer, block_t::p_buffer, block_t::pf_release, static_assert, and unlikely.

Referenced by aout_DecSilence(), block_Duplicate(), block_File(), block_TryRealloc(), bo_init(), decoder_NewAudioBuffer(), vlc_chunked_read(), vlc_h1_stream_read(), vlc_stream_Block(), vlc_stream_fifo_Write(), vlc_stream_Peek(), and vlc_stream_ReadBlock().

◆ block_Cleanup()

static void block_Cleanup ( void *  block)
inlinestatic

◆ block_CopyProperties()

static void block_CopyProperties ( block_t dst,
block_t src 
)
inlinestatic

Referenced by block_Duplicate().

◆ block_Duplicate()

static block_t* block_Duplicate ( block_t p_block)
inlinestatic

Duplicates a block.

Creates a writeable duplicate of a block.

Returns
the duplicate on success, NULL on error.

References block_Alloc(), block_CopyProperties(), block_t::i_buffer, and block_t::p_buffer.

Referenced by DecoderPlayCc(), and EsOutSend().

◆ block_File()

block_t* block_File ( int  fd,
bool  write 
)

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.
Parameters
fdfile descriptor to load from
writeIf true, request a read/write private mapping. If false, request a read-only potentially shared mapping.
Returns
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).

References block_Alloc(), block_cleanup_push, block_mmap_Alloc(), block_Release(), block_t::p_buffer, S_TYPEISSHM, and vlc_cleanup_pop.

Referenced by block_FilePath().

◆ block_FilePath()

block_t* block_FilePath ( const char *  ,
bool  write 
)

Maps a file in memory.

Loads a file into a block of memory from a path to the file. See also block_File().

Parameters
writeIf true, request a read/write private mapping. If false, request a read-only potentially shared mapping.

References block_File(), vlc_close(), and vlc_open().

◆ block_heap_Alloc()

block_t* block_heap_Alloc ( void *  ,
size_t   
)

Wraps heap in a block.

Creates a 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.

Parameters
addrbase address of the heap allocation (will be free()'d)
lengthbytes length of the heap allocation
Returns
NULL in case of error (ptr free()'d in that case), or a valid block_t pointer.

References block_heap_Release(), block_Init(), and block_t::pf_release.

Referenced by vlc_h2_stream_read().

◆ block_Init()

void block_Init ( block_t ,
void *  ,
size_t   
)

◆ block_mmap_Alloc()

block_t* block_mmap_Alloc ( void *  addr,
size_t  length 
)

Wraps a memory mapping in a block.

Creates a 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.

Parameters
addrbase address of the mapping (as returned by mmap)
lengthlength (bytes) of the mapping (as passed to mmap)
Returns
NULL if addr is MAP_FAILED, or an error occurred (in the later case, munmap(addr, length) is invoked before returning).

Referenced by block_File().

◆ block_Realloc()

block_t* block_Realloc ( block_t ,
ssize_t  pre,
size_t  body 
)

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.

Parameters
precount of bytes to prepend if positive, count of leading bytes to discard if negative
bodynew bytes size of the block
Returns
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.
Discard trailing bytes can be achieved directly by subtracting from block_t.i_buffer.
On error, the block is discarded. To avoid that, use block_TryRealloc() instead.

References block_Release(), and block_TryRealloc().

Referenced by bo_extend().

◆ block_Release()

static void block_Release ( block_t block)
inlinestatic

Releases a block.

This function works for any block_t block, regardless of the way it was allocated.

Note
If the block is in a chain, this function does not release any subsequent block in the chain. Use block_ChainRelease() for that purpose.
Parameters
blockblock to release (cannot be NULL)

References block_t::pf_release.

Referenced by aout_DecPlay(), aout_FiltersPlay(), block_BytestreamFlush(), block_File(), block_Realloc(), block_TryRealloc(), bo_deinit(), CmdInitDel(), decoder_QueueCc(), DecoderPlayCc(), DecoderProcess(), EsOutSend(), ImageRead(), ImageWriteUrl(), stream_CommonDelete(), vlc_chunked_read(), vlc_h1_stream_read(), vlc_stream_Block(), vlc_stream_CopyBlock(), vlc_stream_fifo_Queue(), vlc_stream_ReadBlock(), vlc_stream_Seek(), and vlc_stream_vaControl().

◆ block_shm_Alloc()

block_t* block_shm_Alloc ( void *  addr,
size_t  length 
)

Wraps a System V memory segment in a block.

Creates a 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.

Parameters
addrbase address of the segment (as returned by shmat())
lengthlength (bytes) of the segment (as passed to shmget())
Returns
NULL if an error occurred (in that case, shmdt(addr) is invoked before returning NULL).

◆ block_TryRealloc()

block_t* block_TryRealloc ( block_t ,
ssize_t  pre,
size_t  body 
)