source: mediastreamer2/src/msqueue.c @ 856:3d8054c9c0b4

Last change on this file since 856:3d8054c9c0b4 was 856:3d8054c9c0b4, checked in by Simon Morlat <simon.morlat@…>, 3 years ago

expurge everything but mediastreamer2

File size: 2.7 KB
Line 
1/*
2mediastreamer2 library - modular sound and video processing and streaming
3Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18*/
19
20#include "mediastreamer2/msqueue.h"
21#include "mediastreamer2/mscommon.h"
22#include "mediastreamer2/msvideo.h"
23#include <string.h>
24
25MSQueue * ms_queue_new(struct _MSFilter *f1, int pin1, struct _MSFilter *f2, int pin2 ){
26        MSQueue *q=(MSQueue*)ms_new(MSQueue,1);
27        qinit(&q->q);
28        q->prev.filter=f1;
29        q->prev.pin=pin1;
30        q->next.filter=f2;
31        q->next.pin=pin2;
32        return q;
33}
34
35void ms_queue_init(MSQueue *q){
36        q->prev.filter=0;
37        q->prev.pin=0;
38        q->next.filter=0;
39        q->next.pin=0;
40        qinit(&q->q);
41}
42
43void ms_queue_destroy(MSQueue *q){
44        flushq(&q->q,0);
45        ms_free(q);
46}
47
48void ms_queue_flush(MSQueue *q){
49        flushq(&q->q,0);
50}
51
52
53void ms_bufferizer_init(MSBufferizer *obj){
54        qinit(&obj->q);
55        obj->size=0;
56}
57
58MSBufferizer * ms_bufferizer_new(){
59        MSBufferizer *obj=(MSBufferizer *)ms_new(MSBufferizer,1);
60        ms_bufferizer_init(obj);
61        return obj;
62}
63
64void ms_bufferizer_put(MSBufferizer *obj, mblk_t *m){
65        obj->size+=msgdsize(m);
66        putq(&obj->q,m);
67}
68
69void ms_bufferizer_put_from_queue(MSBufferizer *obj, MSQueue *q){
70        mblk_t *m;
71        while((m=ms_queue_get(q))!=NULL){
72                ms_bufferizer_put(obj,m);
73        }
74}
75
76int ms_bufferizer_read(MSBufferizer *obj, uint8_t *data, int datalen){
77        if (obj->size>=datalen){
78                int sz=0;
79                int cplen;
80                mblk_t *m=peekq(&obj->q);
81                /*we can return something */
82                while(sz<datalen){
83                        cplen=MIN(m->b_wptr-m->b_rptr,datalen-sz);
84                        memcpy(data+sz,m->b_rptr,cplen);
85                        sz+=cplen;
86                        m->b_rptr+=cplen;
87                        if (m->b_rptr==m->b_wptr){
88                                /* check cont */
89                                if (m->b_cont!=NULL) {
90                                        m=m->b_cont;
91                                }
92                                else{
93                                        mblk_t *remove=getq(&obj->q);
94                                        freemsg(remove);
95                                        m=peekq(&obj->q);
96                                }
97                        }
98                }
99                obj->size-=datalen;
100                return datalen;
101        }
102        return 0;
103}
104
105void ms_bufferizer_flush(MSBufferizer *obj){
106        obj->size=0;
107        flushq(&obj->q,0);
108}
109
110void ms_bufferizer_uninit(MSBufferizer *obj){
111        flushq(&obj->q,0);
112}
113
114void ms_bufferizer_destroy(MSBufferizer *obj){
115        ms_bufferizer_uninit(obj);
116        ms_free(obj);
117}
Note: See TracBrowser for help on using the repository browser.