source: svn/branches/kctv/zas_dstar/pdrivers/pd_dmx_priv.h

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
File size: 5.5 KB
Line 
1/******************************************************************************
2 *_Copyright (c) 2009 Digital Stream Technology Inc. All Rights Reserved.
3 *
4 * Module:      pd_dmx_priv.h
5 *
6 * Description
7 *      Private header for Demux Pseudo Driver
8 *
9 * @author Junku Park (hwatk@dstreamtech.com)
10 * @version $Revision: 1.1 $
11 *
12 ******************************************************************************/
13
14#ifndef __PD_DMX_PRIV_H__
15#define __PD_DMX_PRIV_H__
16
17#include <string.h>
18
19#if 0
20___Block_APIs___()
21#endif
22enum {
23    BLOCK_FLAG_CORRUPTED = 0x8000,
24};
25
26typedef struct block_t block_t;
27typedef void (*block_free_t) (block_t *);
28
29typedef struct block_fifo_t block_fifo_t;
30
31struct block_t
32{
33    block_t     *p_next;
34    block_t     *p_prev;
35
36    DS_U32      i_flags;
37
38    DS_S64      i_pts;
39    DS_S64      i_dts;
40    DS_S64      i_length;
41
42    int         i_samples; /* Used for audio */
43    int         i_rate;
44
45    DS_U64      i_buffer;
46    DS_U8      *p_buffer;
47
48    DS_U64      i_osize;    /* Origianl size */
49    /* Rudimentary support for overloading block (de)allocation. */
50    block_free_t pf_release;
51};
52
53void block_Init( block_t *, void *, int );
54block_t *block_Alloc( int );
55block_t *block_Realloc( block_t *, int i_pre, int i_body );
56
57static inline void block_Release( block_t *p_block )
58{
59    p_block->pf_release( p_block );
60}
61
62static inline block_t *block_Duplicate( block_t *p_block )
63{
64    block_t *p_dup = block_Alloc( p_block->i_buffer );
65    if( p_dup == NULL )
66        return NULL;
67
68    p_dup->i_dts     = p_block->i_dts;
69    p_dup->i_pts     = p_block->i_pts;
70    p_dup->i_flags   = p_block->i_flags;
71    p_dup->i_length  = p_block->i_length;
72    p_dup->i_rate    = p_block->i_rate;
73    p_dup->i_samples = p_block->i_samples;
74    memcpy( p_dup->p_buffer, p_block->p_buffer, p_block->i_buffer );
75
76    return p_dup;
77}
78
79static inline void block_ChainAppend( block_t **pp_list, block_t *p_block )
80{
81    if( *pp_list == NULL )
82    {
83        *pp_list = p_block;
84    }
85    else
86    {
87        block_t *p = *pp_list;
88
89        while( p->p_next ) p = p->p_next;
90        p->p_next = p_block;
91    }
92}
93
94static inline void block_ChainLastAppend( block_t ***ppp_last, block_t *p_block )
95{
96    block_t *p_last = p_block;
97
98    **ppp_last = p_block;
99
100    while( p_last->p_next ) p_last = p_last->p_next;
101    *ppp_last = &p_last->p_next;
102}
103
104static inline void block_ChainRelease( block_t *p_block )
105{
106    while( p_block )
107    {
108        block_t *p_next = p_block->p_next;
109        block_Release( p_block );
110        p_block = p_next;
111    }
112}
113
114#ifndef __MIN
115#define __MIN(x,y)  ((x)>(y) ? (y) : (x))
116#endif
117
118static int block_ChainExtract( block_t *p_list, void *p_data, int i_max )
119{
120    int  i_total = 0;
121    DS_U8 *p = (DS_U8 *)p_data;
122
123    while( p_list && i_max )
124    {
125        int i_copy = __MIN( i_max, p_list->i_buffer );
126        memcpy( p, p_list->p_buffer, i_copy );
127        i_max   -= i_copy;
128        i_total += i_copy;
129        p       += i_copy;
130
131        p_list = p_list->p_next;
132    }
133    return i_total;
134}
135
136static inline block_t *block_ChainGather( block_t *p_list )
137{
138    int  i_total = 0;
139    DS_S64 i_length = 0;
140    block_t *b, *g;
141
142    if( p_list->p_next == NULL )
143        return p_list;  /* Already gathered */
144
145    for( b = p_list; b != NULL; b = b->p_next )
146    {
147        i_total += b->i_buffer;
148        i_length += b->i_length;
149    }
150
151    g = block_Alloc( i_total );
152    block_ChainExtract( p_list, g->p_buffer, g->i_buffer );
153
154    g->i_flags = p_list->i_flags;
155    g->i_pts   = p_list->i_pts;
156    g->i_dts   = p_list->i_dts;
157    g->i_length = i_length;
158
159    /* free p_list */
160    block_ChainRelease( p_list );
161    return g;
162}
163
164#define block_New( dummy, size ) block_Alloc(size)
165
166#if 0
167___FIFO_APIs___()
168#endif
169
170block_fifo_t *block_FifoNew( void );
171void block_FifoRelease( block_fifo_t *p_fifo );
172void block_FifoEmpty( block_fifo_t *p_fifo );
173int block_FifoPut( block_fifo_t *p_fifo, block_t *p_block );
174void block_FifoWake( block_fifo_t *p_fifo );
175block_t *block_FifoGet( block_fifo_t *p_fifo );
176block_t *block_FifoShow( block_fifo_t *p_fifo );
177int block_FifoSize( const block_fifo_t *p_fifo );
178int block_FifoCount( const block_fifo_t *p_fifo );
179
180#if 0
181___Utility_APIs___()
182#endif
183static inline DS_U16 U16_AT( const void * _p )
184{
185    const DS_U8 * p = (const DS_U8 *)_p;
186    return ( ((DS_U16)p[0] << 8) | p[1] );
187}
188
189static inline DS_U32 U32_AT( const void * _p )
190{
191    const DS_U8 * p = (const DS_U8 *)_p;
192    return ( ((DS_U32)p[0] << 24) | ((DS_U32)p[1] << 16) | ((DS_U32)p[2] << 8) | p[3] );
193}
194
195static inline DS_U64 U64_AT( const void * _p )
196{
197    const DS_U8 * p = (const DS_U8 *)_p;
198    return ( ((DS_U64)p[0] << 56) | ((DS_U64)p[1] << 48)
199              | ((DS_U64)p[2] << 40) | ((DS_U64)p[3] << 32)
200              | ((DS_U64)p[4] << 24) | ((DS_U64)p[5] << 16)
201              | ((DS_U64)p[6] << 8) | p[7] );
202}
203
204static inline DS_U16 GetWLE( const void * _p )
205{
206    const DS_U8 * p = (const DS_U8 *)_p;
207    return ( ((DS_U16)p[1] << 8) | p[0] );
208}
209
210static inline DS_U32 GetDWLE( const void * _p )
211{
212    const DS_U8 * p = (const DS_U8 *)_p;
213    return ( ((DS_U32)p[3] << 24) | ((DS_U32)p[2] << 16)
214              | ((DS_U32)p[1] << 8) | p[0] );
215}
216
217static inline DS_U64 GetQWLE( const void * _p )
218{
219    const DS_U8 * p = (const DS_U8 *)_p;
220    return ( ((DS_U64)p[7] << 56) | ((DS_U64)p[6] << 48)
221              | ((DS_U64)p[5] << 40) | ((DS_U64)p[4] << 32)
222              | ((DS_U64)p[3] << 24) | ((DS_U64)p[2] << 16)
223              | ((DS_U64)p[1] << 8) | p[0] );
224}
225
226#define GetWBE( p )     U16_AT( p )
227#define GetDWBE( p )    U32_AT( p )
228#define GetQWBE( p )    U64_AT( p )
229
230
231#endif /* __PD_DMX_PRIV_H__ */
Note: See TracBrowser for help on using the repository browser.