msqueue.h 3.25 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/*
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

#include "ortp/str_utils.h"

/* for the moment these are stupid queues limited to one element*/

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

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


MSQueue * ms_queue_new(struct _MSFilter *f1, int pin1, struct _MSFilter *f2, int pin2 );

static inline mblk_t *ms_queue_get(MSQueue *q){
	return getq(&q->q);
}

static inline void ms_queue_put(MSQueue *q, mblk_t *m){
	putq(&q->q,m);
	return;
}

static inline mblk_t * ms_queue_peek_last(MSQueue *q){
	return qlast(&q->q);
}

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

aymeric's avatar
aymeric committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
static inline bool_t ms_queue_empty(MSQueue *q){
	return qempty(&q->q);
}

#ifdef __cplusplus
extern "C"
{
#endif

/*init a queue on stack*/
void ms_queue_init(MSQueue *q);

void ms_queue_flush(MSQueue *q);

void ms_queue_destroy(MSQueue *q);

#define mblk_set_timestamp_info(m,ts) (m)->reserved1=(ts);
#define mblk_get_timestamp_info(m)    ((m)->reserved1)
#define mblk_set_marker_info(m,bit)   (m)->reserved2=((m)->reserved2|bit)
#define mblk_get_marker_info(m)	      ((m)->reserved2&0x1)
#define mblk_set_rate(m,bits)         (m)->reserved2=((m)->reserved2|(bits)<<1)
#define mblk_get_rate(m)              (((m)->reserved2>>1)&0x3)
#define mblk_set_payload_type(m,bits) (m)->reserved2=((m)->reserved2|(bits<<3))
81 82 83
#define mblk_get_payload_type(m)      (((m)->reserved2>>3)&0x7F)
#define mblk_set_precious_flag(m,bit)    (m)->reserved2=(m)->reserved2|((bit & 0x1)<<10) /*use to prevent mirroring*/
#define mblk_get_precious_flag(m)    (((m)->reserved2)>>10 & 0x1)
aymeric's avatar
aymeric committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

struct _MSBufferizer{
	queue_t q;
	int size;
};

typedef struct _MSBufferizer MSBufferizer;

/*allocates and initialize */
MSBufferizer * ms_bufferizer_new(void);

/*initialize in memory */
void ms_bufferizer_init(MSBufferizer *obj);

void ms_bufferizer_put(MSBufferizer *obj, mblk_t *m);

/* put every mblk_t from q, into the bufferizer */
void ms_bufferizer_put_from_queue(MSBufferizer *obj, MSQueue *q);

int ms_bufferizer_read(MSBufferizer *obj, uint8_t *data, int datalen);

/* returns the number of bytes available in the bufferizer*/
static inline int ms_bufferizer_get_avail(MSBufferizer *obj){
	return obj->size;
}

smorlat's avatar
smorlat committed
110 111 112
/* purge all data pending in the bufferizer */
void ms_bufferizer_flush(MSBufferizer *obj);

aymeric's avatar
aymeric committed
113 114 115 116 117 118 119 120 121
void ms_bufferizer_uninit(MSBufferizer *obj);

void ms_bufferizer_destroy(MSBufferizer *obj);

#ifdef __cplusplus
}
#endif

#endif