]> git.sesse.net Git - vlc/blob - include/vlc_block.h
* stream_output.h: removed sout_buffer_t and use block_t instead.
[vlc] / include / vlc_block.h
1 /*****************************************************************************
2  * vlc_block.h: Data blocks management functions
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #ifndef _VLC_BLOCK_H
25 #define _VLC_BLOCK_H 1
26
27 /*
28  * block
29  */
30 typedef struct block_sys_t block_sys_t;
31
32 /* BLOCK_FLAG_DISCONTINUITY: the content doesn't follow the last block, or is probably broken */
33 #define BLOCK_FLAG_DISCONTINUITY 0x0001
34 /* BLOCK_FLAG_TYPE_I: Intra frame */
35 #define BLOCK_FLAG_TYPE_I        0x0002
36 /* BLOCK_FLAG_TYPE_P: inter frame with backward reference only */
37 #define BLOCK_FLAG_TYPE_P        0x0004
38 /* BLOCK_FLAG_TYPE_B: inter frame with backward and forward reference */
39 #define BLOCK_FLAG_TYPE_B        0x0008
40 /* BLOCK_FLAG_TYPE_PB: for inter frame when you don't know the real type */
41 #define BLOCK_FLAG_TYPE_PB       0x0010
42 /* BLOCK_FLAG_HEADER: warm that this block is a header one */
43 #define BLOCK_FLAG_HEADER        0x0020
44
45 #define BLOCK_FLAG_PRIVATE_MASK  0xffff0000
46 #define BLOCK_FLAG_PRIVATE_SHIFT 16
47
48 struct block_t
49 {
50     block_t     *p_next;
51
52     uint32_t    i_flags;
53
54     mtime_t     i_pts;
55     mtime_t     i_dts;
56     mtime_t     i_length;
57
58     int         i_rate;
59
60     int         i_buffer;
61     uint8_t     *p_buffer;
62
63     void        (*pf_release)   ( block_t * );
64
65     block_t    *(*pf_modify)    ( block_t *, vlc_bool_t );
66     block_t    *(*pf_duplicate) ( block_t * );
67     block_t    *(*pf_realloc)   ( block_t *, int i_prebody, int i_body );
68
69     /* Following fields are private, user should never touch it */
70     /* XXX never touch that OK !!! the first that access that will
71      * have cvs account removed ;) XXX */
72
73     /* It's an object that should be valid as long as the block_t is valid */
74     /* It should become a true block manager to reduce malloc/free */
75     vlc_object_t    *p_manager;
76
77     /* private member for block_New, .... manager */
78     block_sys_t *p_sys;
79 };
80
81 struct block_fifo_t
82 {
83     vlc_mutex_t         lock;                         /* fifo data lock */
84     vlc_cond_t          wait;         /* fifo data conditional variable */
85
86     int                 i_depth;
87     block_t             *p_first;
88     block_t             **pp_last;
89 };
90
91 /*
92  * block
93  */
94 #define block_New( a, b ) __block_New( VLC_OBJECT(a), b )
95 VLC_EXPORT( block_t *,  __block_New,        ( vlc_object_t *, int ) );
96 static inline void block_Release( block_t *p_block )
97 {
98     p_block->pf_release( p_block );
99 }
100 static inline block_t *block_Modify( block_t *p_block, vlc_bool_t b_willmodify )
101 {
102     return p_block->pf_modify( p_block, b_willmodify );
103 }
104 static inline block_t *block_Duplicate( block_t *p_block )
105 {
106     return p_block->pf_duplicate( p_block );
107 }
108 static inline block_t *block_Realloc( block_t *p_block, int i_pre, int i_body )
109 {
110     return p_block->pf_realloc( p_block, i_pre, i_body );
111 }
112 VLC_EXPORT( void,       block_ChainAppend,  ( block_t **, block_t * ) );
113 VLC_EXPORT( void,       block_ChainRelease, ( block_t * ) );
114 VLC_EXPORT( int,        block_ChainExtract, ( block_t *, void *, int ) );
115 VLC_EXPORT( block_t *,  block_ChainGather,  ( block_t * ) );
116
117 /* a bit special, only for new/other block manager */
118 VLC_EXPORT( block_t *,  block_NewEmpty,     ( void ) );
119
120 #define block_FifoNew( a ) __block_FifoNew( VLC_OBJECT(a) )
121 VLC_EXPORT( block_fifo_t *, __block_FifoNew,    ( vlc_object_t * ) );
122 VLC_EXPORT( void,           block_FifoRelease,  ( block_fifo_t * ) );
123 VLC_EXPORT( void,           block_FifoEmpty,    ( block_fifo_t * ) );
124 VLC_EXPORT( int,            block_FifoPut,      ( block_fifo_t *, block_t * ) );
125 VLC_EXPORT( block_t *,      block_FifoGet,      ( block_fifo_t * ) );
126 VLC_EXPORT( block_t *,      block_FifoShow,     ( block_fifo_t * ) );
127
128 #endif /* VLC_BLOCK_H */