~ubuntu-branches/ubuntu/quantal/linphone/quantal

« back to all changes in this revision

Viewing changes to mediastreamer/msossread.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "msossread.h"
22
 
#include "mssync.h"
23
 
#include <unistd.h>
24
 
#include <errno.h>
25
 
#include <sys/time.h>
26
 
#include <sys/types.h>
27
 
 
28
 
MSFilterInfo oss_read_info={
29
 
        "OSS read",
30
 
        0,
31
 
        MS_FILTER_AUDIO_IO,
32
 
        ms_oss_read_new,
33
 
        NULL
34
 
};
35
 
 
36
 
static MSOssReadClass *msossreadclass=NULL;
37
 
 
38
 
MSFilter * ms_oss_read_new()
39
 
{
40
 
        MSOssRead *w;
41
 
        
42
 
        if (msossreadclass==NULL)
43
 
        {
44
 
                msossreadclass=g_new(MSOssReadClass,1);
45
 
                ms_oss_read_class_init( msossreadclass );
46
 
        }
47
 
        
48
 
        w=g_new(MSOssRead,1);
49
 
        MS_FILTER(w)->klass=MS_FILTER_CLASS(msossreadclass);
50
 
        ms_oss_read_init(w);
51
 
        
52
 
        return(MS_FILTER(w));
53
 
}
54
 
 
55
 
/* FOR INTERNAL USE*/
56
 
void ms_oss_read_init(MSOssRead *w)
57
 
{
58
 
        ms_sound_read_init(MS_SOUND_READ(w));
59
 
        MS_FILTER(w)->outfifos=w->f_outputs;
60
 
        MS_FILTER(w)->outfifos[0]=NULL;
61
 
        w->devid=0;
62
 
        w->sndcard=NULL;
63
 
        w->freq=8000;
64
 
}
65
 
        
66
 
gint ms_oss_read_set_property(MSOssRead *f,MSFilterProperty prop, void *value)
67
 
{
68
 
        switch(prop){
69
 
                case MS_FILTER_PROPERTY_FREQ:
70
 
                        f->freq=((gint*)value)[0];
71
 
                break;
72
 
        }
73
 
        return 0;
74
 
}
75
 
void ms_oss_read_class_init(MSOssReadClass *klass)
76
 
{
77
 
        ms_sound_read_class_init(MS_SOUND_READ_CLASS(klass));
78
 
        MS_FILTER_CLASS(klass)->max_foutputs=1;  /* one fifo output only */
79
 
        MS_FILTER_CLASS(klass)->setup=(MSFilterSetupFunc)ms_oss_read_setup;
80
 
        MS_FILTER_CLASS(klass)->unsetup=(MSFilterSetupFunc)ms_oss_read_stop;
81
 
        MS_FILTER_CLASS(klass)->process= (MSFilterProcessFunc)ms_oss_read_process;
82
 
        MS_FILTER_CLASS(klass)->set_property=(MSFilterPropertyFunc)ms_oss_read_set_property;
83
 
        MS_FILTER_CLASS(klass)->destroy= (MSFilterDestroyFunc)ms_oss_read_destroy;
84
 
        MS_FILTER_CLASS(klass)->w_maxgran=MS_OSS_READ_MAX_GRAN;
85
 
        MS_FILTER_CLASS(klass)->info=&oss_read_info;
86
 
        MS_SOUND_READ_CLASS(klass)->set_device=(gint (*)(MSSoundRead*,gint))ms_oss_read_set_device;
87
 
        MS_SOUND_READ_CLASS(klass)->start=(void (*)(MSSoundRead*))ms_oss_read_start;
88
 
        MS_SOUND_READ_CLASS(klass)->stop=(void (*)(MSSoundRead*))ms_oss_read_stop;
89
 
        ms_filter_class_set_name(MS_FILTER_CLASS(klass),"OssRead");
90
 
        //ms_filter_class_set_attr( MS_FILTER_CLASS(klass),FILTER_CAN_SYNC|FILTER_IS_SOURCE);   
91
 
}
92
 
 
93
 
void ms_oss_read_destroy( MSOssRead *obj)
94
 
{
95
 
        g_free(obj);
96
 
}
97
 
 
98
 
void ms_oss_read_process(MSOssRead *f)
99
 
{
100
 
        MSFifo *fifo;
101
 
        char *p;
102
 
        fifo=f->f_outputs[0];
103
 
        
104
 
        g_return_if_fail(f->sndcard!=NULL);
105
 
        g_return_if_fail(f->gran>0);
106
 
        
107
 
        if (snd_card_can_read(f->sndcard)){
108
 
                ms_fifo_get_write_ptr(fifo,f->gran,(void**)&p);
109
 
                g_return_if_fail(p!=NULL);
110
 
                snd_card_read(f->sndcard,p,f->gran);
111
 
        }               
112
 
}
113
 
 
114
 
 
115
 
void ms_oss_read_start(MSOssRead *r)
116
 
{
117
 
        g_return_if_fail(r->devid!=-1);
118
 
        r->sndcard=snd_card_manager_get_card(snd_card_manager,r->devid);
119
 
        g_return_if_fail(r->sndcard!=NULL);
120
 
        /* open the device for an audio telephony signal with minimum latency */
121
 
        snd_card_open_r(r->sndcard,16,0,r->freq);
122
 
        r->gran=(512*r->freq)/8000;
123
 
        
124
 
}
125
 
 
126
 
void ms_oss_read_stop(MSOssRead *w)
127
 
{
128
 
        g_return_if_fail(w->devid!=-1);
129
 
        g_return_if_fail(w->sndcard!=NULL);
130
 
        snd_card_close_r(w->sndcard);
131
 
        w->sndcard=NULL;
132
 
}
133
 
 
134
 
 
135
 
void ms_oss_read_setup(MSOssRead *f, MSSync *sync)
136
 
{
137
 
        f->sync=sync;
138
 
        ms_oss_read_start(f);
139
 
}
140
 
 
141
 
 
142
 
gint ms_oss_read_set_device(MSOssRead *r,gint devid)
143
 
{
144
 
        r->devid=devid;
145
 
        return 0;
146
 
}