annotate src/mediastreamer/msread.c @ 12389:e024601d45c7

[gaim-migrate @ 14695] How about we allow callers to pass in the entity body, rather than forcing them to hash it themselves? committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Wed, 07 Dec 2005 11:01:49 +0000
parents 1c771536a032
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12024
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 The mediastreamer library aims at providing modular media processing and I/O
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 for linphone, but also for any telephony application.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 This library is free software; you can redistribute it and/or
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 modify it under the terms of the GNU Lesser General Public
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 License as published by the Free Software Foundation; either
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 version 2.1 of the License, or (at your option) any later version.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 This library is distributed in the hope that it will be useful,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 Lesser General Public License for more details.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 You should have received a copy of the GNU Lesser General Public
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 License along with this library; if not, write to the Free Software
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 #include "msread.h"
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 #include "mssync.h"
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 #include <unistd.h>
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include <fcntl.h>
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 #include <sys/types.h>
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 #include <string.h>
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include <errno.h>
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 static MSReadClass *ms_read_class=NULL;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 MSFilter * ms_read_new(char *name)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 MSRead *r;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 r=g_new(MSRead,1);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 ms_read_init(r);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 if (ms_read_class==NULL)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 ms_read_class=g_new(MSReadClass,1);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 ms_read_class_init(ms_read_class);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_read_class);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 r->fd=-1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 if (name!=NULL) ms_read_open(r,name);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 return(MS_FILTER(r));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 gint ms_read_open(MSRead *r, gchar *name)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 gint fd;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 fd=open(name,O_RDONLY);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 if (fd<0) {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 r->fd=-1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 g_warning("ms_read_new: cannot open %s : %s",name,strerror(errno));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 return -1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 r->fd=fd;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 if (strstr(name,".wav")!=NULL){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 /* skip the header */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 lseek(fd,20,SEEK_SET);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 #ifdef WORDS_BIGENDIAN
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 r->need_swap=1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 #else
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 r->need_swap=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 #endif
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 r->state=MS_READ_STATE_STARTED;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 return 0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 /* FOR INTERNAL USE*/
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 void ms_read_init(MSRead *r)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 ms_filter_init(MS_FILTER(r));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 MS_FILTER(r)->outfifos=r->foutputs;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 MS_FILTER(r)->outqueues=r->qoutputs;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 memset(r->foutputs,0,sizeof(MSFifo*)*MSREAD_MAX_OUTPUTS);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 memset(r->qoutputs,0,sizeof(MSQueue*)*MSREAD_MAX_OUTPUTS);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 r->fd=-1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 r->gran=320;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 r->state=MS_READ_STATE_STOPPED;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 r->need_swap=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 r->rate=8000;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 gint ms_read_set_property(MSRead *f,MSFilterProperty prop, void *value)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 switch(prop){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 case MS_FILTER_PROPERTY_FREQ:
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 f->rate=((gint*)value)[0];
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 break;
12029
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
94 case MS_FILTER_PROPERTY_BITRATE:
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
95 case MS_FILTER_PROPERTY_CHANNELS:
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
96 case MS_FILTER_PROPERTY_FMTP:
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
97 default:
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
98 break;
12024
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 return 0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 void ms_read_class_init(MSReadClass *klass)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 ms_filter_class_init(MS_FILTER_CLASS(klass));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 ms_filter_class_set_name(MS_FILTER_CLASS(klass),"dskreader");
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 ms_filter_class_set_attr(MS_FILTER_CLASS(klass),FILTER_IS_SOURCE);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 MS_FILTER_CLASS(klass)->max_foutputs=MSREAD_MAX_OUTPUTS;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 MS_FILTER_CLASS(klass)->max_qoutputs=MSREAD_MAX_OUTPUTS;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 MS_FILTER_CLASS(klass)->w_maxgran=MSREAD_DEF_GRAN;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_read_destroy;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 MS_FILTER_CLASS(klass)->setup=(MSFilterSetupFunc)ms_read_setup;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_read_process;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 MS_FILTER_CLASS(klass)->set_property=(MSFilterPropertyFunc)ms_read_set_property;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 void ms_read_process(MSRead *r)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 MSFifo *f;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 MSQueue *q;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 MSMessage *msg=NULL;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 int err;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 gint gran=r->gran;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 void *p;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 f=r->foutputs[0];
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 if ((f!=NULL) && (r->state==MS_READ_STATE_STARTED))
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 ms_fifo_get_write_ptr(f,gran,&p);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 if (p!=NULL)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 err=read(r->fd,p,gran);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 if (err<0)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 /* temp: */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 g_warning("ms_read_process: failed to read: %s.\n",strerror(errno));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 else if (err<gran){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 ms_trace("ms_read_process: end of file.");
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 ms_filter_notify_event(MS_FILTER(r),MS_READ_EVENT_EOF,NULL);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 r->state=MS_READ_STATE_STOPPED;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 close(r->fd);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 r->fd=-1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 if (r->need_swap) swap_buffer(p,gran);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 /* process output queues*/
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 q=r->qoutputs[0];
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 if ((q!=NULL) && (r->fd>0))
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 msg=ms_message_new(r->gran);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 err=read(r->fd,msg->data,r->gran);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 if (err>0){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 msg->size=err;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 ms_queue_put(q,msg);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 if (r->need_swap) swap_buffer(msg->data,r->gran);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 }else{
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 ms_filter_notify_event(MS_FILTER(r),MS_READ_EVENT_EOF,NULL);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 ms_trace("End of file reached.");
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 r->state=MS_READ_STATE_STOPPED;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 void ms_read_destroy( MSRead *obj)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 if (obj->fd!=0) close(obj->fd);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 g_free(obj);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 gint ms_read_close(MSRead *obj)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 if (obj->fd!=0) {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 close(obj->fd);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 obj->fd=-1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 obj->state=MS_READ_STATE_STOPPED;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 }
12029
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
179
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
180 /* No idea if this is correct, but again nothing is calling it and it's not
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
181 * even declared in the header file so this should be fine. -- Gary
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
182 */
1c771536a032 [gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents: 12024
diff changeset
183 return 0;
12024
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 void ms_read_setup(MSRead *r, MSSync *sync)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 r->sync=sync;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 r->gran=(r->rate*sync->interval/1000)*2;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 }