1 | /* |
2 | mediastreamer2 library - modular sound and video processing and streaming |
3 | Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org) |
4 | |
5 | This program is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU General Public License |
7 | as published by the Free Software Foundation; either version 2 |
8 | of the License, or (at your option) any later version. |
9 | |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | */ |
19 | #ifndef MSQUEUE_H |
20 | #define MSQUEUE_H |
21 | |
22 | #include <ortp/str_utils.h> |
23 | #include <mediastreamer2/mscommon.h> |
24 | |
25 | |
26 | typedef struct _MSCPoint{ |
27 | struct _MSFilter *filter; |
28 | int pin; |
29 | } MSCPoint; |
30 | |
31 | typedef struct _MSQueue |
32 | { |
33 | queue_t q; |
34 | MSCPoint prev; |
35 | MSCPoint next; |
36 | }MSQueue; |
37 | |
38 | |
39 | MS2_PUBLIC MSQueue * ms_queue_new(struct _MSFilter *f1, int pin1, struct _MSFilter *f2, int pin2 ); |
40 | |
41 | static inline mblk_t *ms_queue_get(MSQueue *q){ |
42 | return getq(&q->q); |
43 | } |
44 | |
45 | static inline void ms_queue_put(MSQueue *q, mblk_t *m){ |
46 | putq(&q->q,m); |
47 | return; |
48 | } |
49 | |
50 | static inline mblk_t * ms_queue_peek_last(MSQueue *q){ |
51 | return qlast(&q->q); |
52 | } |
53 | |
54 | static inline void ms_queue_remove(MSQueue *q, mblk_t *m){ |
55 | remq(&q->q,m); |
56 | } |
57 | |
58 | static inline bool_t ms_queue_empty(MSQueue *q){ |
59 | return qempty(&q->q); |
60 | } |
61 | |
62 | #ifdef __cplusplus |
63 | extern "C" |
64 | { |
65 | #endif |
66 | |
67 | /*yes these functions need to be public for plugins to work*/ |
68 | |
69 | /*init a queue on stack*/ |
70 | MS2_PUBLIC void ms_queue_init(MSQueue *q); |
71 | |
72 | MS2_PUBLIC void ms_queue_flush(MSQueue *q); |
73 | |
74 | MS2_PUBLIC void ms_queue_destroy(MSQueue *q); |
75 | |
76 | |
77 | #define __mblk_set_flag(m,pos,bitval) \ |
78 | (m)->reserved2=(m->reserved2 & ~(1<<pos)) | ((!!bitval)<<pos) |
79 | |
80 | #define mblk_set_timestamp_info(m,ts) (m)->reserved1=(ts); |
81 | #define mblk_get_timestamp_info(m) ((m)->reserved1) |
82 | #define mblk_set_marker_info(m,bit) __mblk_set_flag(m,0,bit) |
83 | #define mblk_get_marker_info(m) ((m)->reserved2&0x1) /*bit 1*/ |
84 | #define mblk_set_precious_flag(m,bit) __mblk_set_flag(m,1,bit) /*use to prevent mirroring*/ |
85 | #define mblk_get_precious_flag(m) (((m)->reserved2)>>1 & 0x1) /*bit 2*/ |
86 | #define mblk_set_plc_flag(m,bit) __mblk_set_flag(m,2,bit) /*use to mark a plc generated block*/ |
87 | #define mblk_get_plc_flag(m) (((m)->reserved2)>>1 & 0x2) /*bit 2*/ |
88 | #define mblk_set_cseq(m,value) (m)->reserved2=(m)->reserved2| ((value&0xFFFF)<<16); |
89 | #define mblk_get_cseq(m) ((m)->reserved2>>16) |
90 | |
91 | struct _MSBufferizer{ |
92 | queue_t q; |
93 | int size; |
94 | }; |
95 | |
96 | typedef struct _MSBufferizer MSBufferizer; |
97 | |
98 | /*allocates and initialize */ |
99 | MS2_PUBLIC MSBufferizer * ms_bufferizer_new(void); |
100 | |
101 | /*initialize in memory */ |
102 | MS2_PUBLIC void ms_bufferizer_init(MSBufferizer *obj); |
103 | |
104 | MS2_PUBLIC void ms_bufferizer_put(MSBufferizer *obj, mblk_t *m); |
105 | |
106 | /* put every mblk_t from q, into the bufferizer */ |
107 | MS2_PUBLIC void ms_bufferizer_put_from_queue(MSBufferizer *obj, MSQueue *q); |
108 | |
109 | MS2_PUBLIC int ms_bufferizer_read(MSBufferizer *obj, uint8_t *data, int datalen); |
110 | |
111 | /* returns the number of bytes available in the bufferizer*/ |
112 | static inline int ms_bufferizer_get_avail(MSBufferizer *obj){ |
113 | return obj->size; |
114 | } |
115 | |
116 | MS2_PUBLIC void ms_bufferizer_skip_bytes(MSBufferizer *obj, int bytes); |
117 | |
118 | /* purge all data pending in the bufferizer */ |
119 | MS2_PUBLIC void ms_bufferizer_flush(MSBufferizer *obj); |
120 | |
121 | MS2_PUBLIC void ms_bufferizer_uninit(MSBufferizer *obj); |
122 | |
123 | MS2_PUBLIC void ms_bufferizer_destroy(MSBufferizer *obj); |
124 | |
125 | #ifdef __cplusplus |
126 | } |
127 | #endif |
128 | |
129 | #endif |
130 | |