msqueue.h 6.78 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
aymeric's avatar
aymeric committed
18 19 20 21
*/
#ifndef MSQUEUE_H
#define MSQUEUE_H

Simon Morlat's avatar
Simon Morlat committed
22 23
#include <ortp/str_utils.h>
#include <mediastreamer2/mscommon.h>
aymeric's avatar
aymeric committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38


typedef struct _MSCPoint{
	struct _MSFilter *filter;
	int pin;
} MSCPoint;

typedef struct _MSQueue
{
	queue_t q;
	MSCPoint prev;
	MSCPoint next;
}MSQueue;


Ghislain MARY's avatar
Ghislain MARY committed
39
MS2_PUBLIC MSQueue * ms_queue_new(struct _MSFilter *f1, int pin1, struct _MSFilter *f2, int pin2 );
aymeric's avatar
aymeric committed
40

41
static MS2_INLINE mblk_t *ms_queue_get(MSQueue *q){
aymeric's avatar
aymeric committed
42 43 44
	return getq(&q->q);
}

45
static MS2_INLINE void ms_queue_put(MSQueue *q, mblk_t *m){
aymeric's avatar
aymeric committed
46 47 48 49
	putq(&q->q,m);
	return;
}

Simon Morlat's avatar
Simon Morlat committed
50 51 52 53
/**
 * Insert mblk_t 'm' in queue 'q' just before mblk_t 'em'.
 * If em is NULL, m is inserted at the end and becomes the last element.
 */
54 55 56 57 58
static MS2_INLINE void ms_queue_insert(MSQueue *q, mblk_t *em, mblk_t *m) {
    insq(&q->q, em, m);
    return;
}

59
static MS2_INLINE mblk_t * ms_queue_peek_last(MSQueue *q){
aymeric's avatar
aymeric committed
60 61 62
	return qlast(&q->q);
}

63 64 65 66
static MS2_INLINE mblk_t *ms_queue_peek_first(MSQueue *q){
	return qbegin(&q->q);
}

67
#define ms_queue_next(q, m) (m)->b_next
68 69 70 71 72

static MS2_INLINE bool_t ms_queue_end(MSQueue *q, mblk_t *m){
	return qend(&q->q,m);
}

73
static MS2_INLINE void ms_queue_remove(MSQueue *q, mblk_t *m){
74 75 76
	remq(&q->q,m);
}

77
static MS2_INLINE bool_t ms_queue_empty(MSQueue *q){
aymeric's avatar
aymeric committed
78 79 80 81 82 83 84 85
	return qempty(&q->q);
}

#ifdef __cplusplus
extern "C"
{
#endif

86 87
/*yes these functions need to be public for plugins to work*/

aymeric's avatar
aymeric committed
88
/*init a queue on stack*/
89
MS2_PUBLIC void ms_queue_init(MSQueue *q);
aymeric's avatar
aymeric committed
90

91
MS2_PUBLIC void ms_queue_flush(MSQueue *q);
aymeric's avatar
aymeric committed
92

93
MS2_PUBLIC void ms_queue_destroy(MSQueue *q);
aymeric's avatar
aymeric committed
94

95

96 97 98
#define __mblk_set_flag(m,pos,bitval) \
	(m)->reserved2=(m->reserved2 & ~(1<<pos)) | ((!!bitval)<<pos) 
	
aymeric's avatar
aymeric committed
99 100
#define mblk_set_timestamp_info(m,ts) (m)->reserved1=(ts);
#define mblk_get_timestamp_info(m)    ((m)->reserved1)
101
#define mblk_set_marker_info(m,bit)   __mblk_set_flag(m,0,bit)
102 103 104 105 106
#define mblk_get_marker_info(m)	      ((m)->reserved2 & 0x1) /*bit 1*/

#define mblk_set_precious_flag(m,bit)    __mblk_set_flag(m,1,bit)  /*use to prevent mirroring for video*/
#define mblk_get_precious_flag(m)    (((m)->reserved2)>>1 & 0x1) /*bit 2 */

107
#define mblk_set_plc_flag(m,bit)    __mblk_set_flag(m,2,bit)  /*use to mark a plc generated block*/
108 109
#define mblk_get_plc_flag(m)    (((m)->reserved2)>>2 & 0x1) /*bit 3*/

110
#define mblk_set_cng_flag(m,bit)    __mblk_set_flag(m,3,bit)  /*use to mark a cng generated block*/
111 112 113 114 115
#define mblk_get_cng_flag(m)    (((m)->reserved2)>>3 & 0x1) /*bit 4*/

#define mblk_set_user_flag(m,bit)    __mblk_set_flag(m,7,bit)  /* to be used by extensions to mediastreamer2*/
#define mblk_get_user_flag(m)    (((m)->reserved2)>>7 & 0x1) /*bit 8*/

jehan's avatar
jehan committed
116 117
#define mblk_set_cseq(m,value) (m)->reserved2=(m)->reserved2| ((value&0xFFFF)<<16);	
#define mblk_get_cseq(m) ((m)->reserved2>>16)
118 119

#define HAVE_ms_bufferizer_fill_current_metas
jehan's avatar
jehan committed
120
	
aymeric's avatar
aymeric committed
121 122
struct _MSBufferizer{
	queue_t q;
123
	size_t size;
aymeric's avatar
aymeric committed
124 125 126 127 128
};

typedef struct _MSBufferizer MSBufferizer;

/*allocates and initialize */
129
MS2_PUBLIC MSBufferizer * ms_bufferizer_new(void);
aymeric's avatar
aymeric committed
130 131

/*initialize in memory */
Ghislain MARY's avatar
Ghislain MARY committed
132
MS2_PUBLIC void ms_bufferizer_init(MSBufferizer *obj);
aymeric's avatar
aymeric committed
133

134
MS2_PUBLIC void ms_bufferizer_put(MSBufferizer *obj, mblk_t *m);
aymeric's avatar
aymeric committed
135 136

/* put every mblk_t from q, into the bufferizer */
137
MS2_PUBLIC void ms_bufferizer_put_from_queue(MSBufferizer *obj, MSQueue *q);
aymeric's avatar
aymeric committed
138

139
/*read bytes from bufferizer object*/
140
MS2_PUBLIC size_t ms_bufferizer_read(MSBufferizer *obj, uint8_t *data, size_t datalen);
aymeric's avatar
aymeric committed
141

142 143 144
/*obtain current meta-information of the last read bytes (if any) and copy them into 'm'*/
MS2_PUBLIC void ms_bufferizer_fill_current_metas(MSBufferizer *obj, mblk_t *m);

aymeric's avatar
aymeric committed
145
/* returns the number of bytes available in the bufferizer*/
146
static MS2_INLINE size_t ms_bufferizer_get_avail(MSBufferizer *obj){
aymeric's avatar
aymeric committed
147 148 149
	return obj->size;
}

150
MS2_PUBLIC void ms_bufferizer_skip_bytes(MSBufferizer *obj, int bytes);
151

smorlat's avatar
smorlat committed
152
/* purge all data pending in the bufferizer */
153
MS2_PUBLIC void ms_bufferizer_flush(MSBufferizer *obj);
smorlat's avatar
smorlat committed
154

Ghislain MARY's avatar
Ghislain MARY committed
155
MS2_PUBLIC void ms_bufferizer_uninit(MSBufferizer *obj);
aymeric's avatar
aymeric committed
156

157
MS2_PUBLIC void ms_bufferizer_destroy(MSBufferizer *obj);
aymeric's avatar
aymeric committed
158

159 160 161 162 163 164 165

struct _MSFlowControlledBufferizer {
	MSBufferizer base;
	struct _MSFilter *filter;
	uint64_t flow_control_time;
	uint32_t flow_control_interval_ms;
	uint32_t max_size_ms;
166 167
	uint32_t granularity_ms;
	uint32_t min_size_ms_during_interval;
168 169 170 171 172 173 174 175 176 177 178 179
	int samplerate;
	int nchannels;
};

typedef struct _MSFlowControlledBufferizer MSFlowControlledBufferizer;

MS2_PUBLIC MSFlowControlledBufferizer * ms_flow_controlled_bufferizer_new(struct _MSFilter *f, int samplerate, int nchannels);

MS2_PUBLIC void ms_flow_controlled_bufferizer_init(MSFlowControlledBufferizer *obj, struct _MSFilter *f, int samplerate, int nchannels);

MS2_PUBLIC void ms_flow_controlled_bufferizer_set_max_size_ms(MSFlowControlledBufferizer *obj, uint32_t ms);

180 181
MS2_PUBLIC void ms_flow_controlled_bufferizer_set_granularity_ms(MSFlowControlledBufferizer *obj, uint32_t ms);

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
MS2_PUBLIC void ms_flow_controlled_bufferizer_set_flow_control_interval_ms(MSFlowControlledBufferizer *obj, uint32_t ms);

MS2_PUBLIC void ms_flow_controlled_bufferizer_set_samplerate(MSFlowControlledBufferizer *obj, int samplerate);

MS2_PUBLIC void ms_flow_controlled_bufferizer_set_nchannels(MSFlowControlledBufferizer *obj, int nchannels);

MS2_PUBLIC void ms_flow_controlled_bufferizer_put(MSFlowControlledBufferizer *obj, mblk_t *m);

MS2_PUBLIC void ms_flow_controlled_bufferizer_put_from_queue(MSFlowControlledBufferizer *obj, MSQueue *q);

#define ms_flow_controlled_bufferizer_read(obj, data, datalen) ms_bufferizer_read((MSBufferizer *)(obj), data, datalen)

#define ms_flow_controlled_bufferizer_fill_current_metas(obj, m) ms_bufferizer_fill_current_metas((MSBufferizer *)(obj), m)

#define ms_flow_controlled_bufferizer_get_avail(obj) ms_bufferizer_get_avail((MSBufferizer *)(obj))

#define ms_flow_controlled_bufferizer_skip_bytes(obj, bytes) ms_bufferizer_skip_bytes((MSBufferizer *)(obj), bytes)

#define ms_flow_controlled_bufferizer_flush(obj) ms_bufferizer_flush((MSBufferizer *)(obj))

#define ms_flow_controlled_bufferizer_uninit(obj) ms_bufferizer_uninit((MSBufferizer *)(obj))

#define ms_flow_controlled_bufferizer_destroy(obj) ms_bufferizer_destroy((MSBufferizer *)(obj))

aymeric's avatar
aymeric committed
206 207 208 209 210
#ifdef __cplusplus
}
#endif

#endif