msqueue.h 3.61 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
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
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
#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;
}

50
static MS2_INLINE mblk_t * ms_queue_peek_last(MSQueue *q){
aymeric's avatar
aymeric committed
51 52 53
	return qlast(&q->q);
}

54
static MS2_INLINE void ms_queue_remove(MSQueue *q, mblk_t *m){
55 56 57
	remq(&q->q,m);
}

58
static MS2_INLINE bool_t ms_queue_empty(MSQueue *q){
aymeric's avatar
aymeric committed
59 60 61 62 63 64 65 66
	return qempty(&q->q);
}

#ifdef __cplusplus
extern "C"
{
#endif

67 68
/*yes these functions need to be public for plugins to work*/

aymeric's avatar
aymeric committed
69
/*init a queue on stack*/
70
MS2_PUBLIC void ms_queue_init(MSQueue *q);
aymeric's avatar
aymeric committed
71

72
MS2_PUBLIC void ms_queue_flush(MSQueue *q);
aymeric's avatar
aymeric committed
73

74
MS2_PUBLIC void ms_queue_destroy(MSQueue *q);
aymeric's avatar
aymeric committed
75

76

77 78 79
#define __mblk_set_flag(m,pos,bitval) \
	(m)->reserved2=(m->reserved2 & ~(1<<pos)) | ((!!bitval)<<pos) 
	
aymeric's avatar
aymeric committed
80 81
#define mblk_set_timestamp_info(m,ts) (m)->reserved1=(ts);
#define mblk_get_timestamp_info(m)    ((m)->reserved1)
82
#define mblk_set_marker_info(m,bit)   __mblk_set_flag(m,0,bit)
jehan's avatar
jehan committed
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*/
jehan's avatar
jehan committed
85
#define mblk_get_precious_flag(m)    (((m)->reserved2)>>1 & 0x1) /*bit 2*/
86 87
#define mblk_set_plc_flag(m,bit)    __mblk_set_flag(m,2,bit)  /*use to mark a plc generated block*/
#define mblk_get_plc_flag(m)    (((m)->reserved2)>>1 & 0x2) /*bit 2*/
jehan's avatar
jehan committed
88 89 90
#define mblk_set_cseq(m,value) (m)->reserved2=(m)->reserved2| ((value&0xFFFF)<<16);	
#define mblk_get_cseq(m) ((m)->reserved2>>16)
	
aymeric's avatar
aymeric committed
91 92 93 94 95 96 97 98
struct _MSBufferizer{
	queue_t q;
	int size;
};

typedef struct _MSBufferizer MSBufferizer;

/*allocates and initialize */
99
MS2_PUBLIC MSBufferizer * ms_bufferizer_new(void);
aymeric's avatar
aymeric committed
100 101

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

104
MS2_PUBLIC void ms_bufferizer_put(MSBufferizer *obj, mblk_t *m);
aymeric's avatar
aymeric committed
105 106

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

109
MS2_PUBLIC int ms_bufferizer_read(MSBufferizer *obj, uint8_t *data, int datalen);
aymeric's avatar
aymeric committed
110 111

/* returns the number of bytes available in the bufferizer*/
112
static MS2_INLINE int ms_bufferizer_get_avail(MSBufferizer *obj){
aymeric's avatar
aymeric committed
113 114 115
	return obj->size;
}

116
MS2_PUBLIC void ms_bufferizer_skip_bytes(MSBufferizer *obj, int bytes);
117

smorlat's avatar
smorlat committed
118
/* purge all data pending in the bufferizer */
119
MS2_PUBLIC void ms_bufferizer_flush(MSBufferizer *obj);
smorlat's avatar
smorlat committed
120

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

123
MS2_PUBLIC void ms_bufferizer_destroy(MSBufferizer *obj);
aymeric's avatar
aymeric committed
124 125 126 127 128 129

#ifdef __cplusplus
}
#endif

#endif