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