Commit 6953f19e authored by Simon Morlat's avatar Simon Morlat

pulseaudio card works.

parent 21c9b377
......@@ -149,21 +149,21 @@ static void pulse_read_preprocess(MSFilter *f){
attr.tlength=-1;
attr.prebuf=-1;
attr.minreq=-1;
attr.fragsize=s->fragsize=latency_req*s->channels*s->rate*2;
attr.fragsize=s->fragsize=latency_req*(float)s->channels*(float)s->rate*2;
s->stream=pa_stream_new(context,"mediastreamer2 read filter",&pss,NULL);
if (s->stream==NULL){
ms_error("pa_stream_new() failed: %s",pa_strerror(pa_context_errno(context)));
return;
}
pa_threaded_mainloop_lock(pa_loop);
err=pa_stream_connect_record(s->stream,NULL,&attr, PA_STREAM_ADJUST_LATENCY);
pa_threaded_mainloop_unlock(pa_loop);
if (err!=0){
ms_error("pa_stream_connect_record() failed");
}
}
static void stub(void *p){
}
static void pulse_read_process(MSFilter *f){
PulseReadState *s=(PulseReadState *)f->data;
......@@ -171,13 +171,17 @@ static void pulse_read_process(MSFilter *f){
size_t nbytes=0;
if (s->stream!=NULL){
pa_stream_peek(s->stream,&buffer,&nbytes);
if (buffer!=NULL){
pa_stream_drop(s->stream);
mblk_t *om=esballoc((uint8_t*)buffer,nbytes,0,stub);
pa_threaded_mainloop_lock(pa_loop);
while (pa_stream_peek(s->stream,&buffer,&nbytes)==0 && nbytes>0){
mblk_t *om;
om=allocb(nbytes,0);
memcpy(om->b_wptr,buffer,nbytes);
om->b_wptr+=nbytes;
ms_queue_put(f->outputs[0],om);
nbytes=0;
pa_stream_drop(s->stream);
}
pa_threaded_mainloop_unlock(pa_loop);
}
}
......@@ -186,8 +190,10 @@ static void pulse_read_postprocess(MSFilter *f){
PulseReadState *s=(PulseReadState *)f->data;
if (s->stream) {
pa_threaded_mainloop_lock(pa_loop);
pa_stream_disconnect(s->stream);
pa_stream_unref(s->stream);
pa_threaded_mainloop_unlock(pa_loop);
}
}
......@@ -252,19 +258,23 @@ static void pulse_write_preprocess(MSFilter *f){
pss.format=PA_SAMPLE_S16LE;
pss.channels=s->channels;
pss.rate=s->rate;
s->fragsize=latency_req*(float)s->channels*(float)s->rate*2;
attr.maxlength=-1;
attr.tlength=-1;
attr.tlength=s->fragsize;
attr.prebuf=-1;
attr.minreq=-1;
attr.fragsize=s->fragsize=latency_req*s->channels*s->rate*2;
attr.fragsize=-1;
s->stream=pa_stream_new(context,"mediastreamer2",&pss,NULL);
if (s->stream==NULL){
ms_error("pa_stream_new() failed: %s",pa_strerror(pa_context_errno(context)));
return;
}
pa_threaded_mainloop_lock(pa_loop);
err=pa_stream_connect_playback(s->stream,NULL,&attr, PA_STREAM_ADJUST_LATENCY,NULL,NULL);
pa_threaded_mainloop_unlock(pa_loop);
if (err!=0){
ms_error("pa_stream_connect_playback() failed");
}
......@@ -276,10 +286,12 @@ static void pulse_write_process(MSFilter *f){
while((im=ms_queue_get(f->inputs[0]))!=NULL){
int bsize=msgdsize(im);
if (s->stream){
pa_threaded_mainloop_lock(pa_loop);
if (pa_stream_writable_size(s->stream)>=bsize){
//ms_message("Pushing data to pulseaudio");
pa_stream_write(s->stream,im->b_rptr,bsize,NULL,0,PA_SEEK_RELATIVE);
}
pa_threaded_mainloop_unlock(pa_loop);
}
freemsg(im);
}
......@@ -288,8 +300,10 @@ static void pulse_write_process(MSFilter *f){
static void pulse_write_postprocess(MSFilter *f){
PulseWriteState *s=(PulseWriteState*)f->data;
if (s->stream) {
pa_threaded_mainloop_lock(pa_loop);
pa_stream_disconnect(s->stream);
pa_stream_unref(s->stream);
pa_threaded_mainloop_unlock(pa_loop);
}
}
......
......@@ -42,6 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static int cond=1;
static const char * capture_card=NULL;
static const char * playback_card=NULL;
static float ng_threshold=-1;
static bool_t use_ng=FALSE;
......@@ -139,7 +140,8 @@ const char *usage="mediastream --local <port> --remote <ip:port> --payload <payl
"[ --agc (enable automatic gain control)]\n"
"[ --ng (enable noise gate)]\n"
"[ --ng-threshold <(float) [0-1]> (noise gate threshold)]\n"
"[ --capture-card <index>] \n";
"[ --capture-card <name>] \n"
"[ --playback-card <name>] \n";
static void run_media_streams(int localport, const char *remote_ip, int remoteport, int payload, const char *fmtp,
int jitter, int bitrate, MSVideoSize vs, bool_t ec, bool_t agc, bool_t eq);
......@@ -211,6 +213,9 @@ int main(int argc, char * argv[])
}else if (strcmp(argv[i],"--capture-card")==0){
i++;
capture_card=argv[i];
}else if (strcmp(argv[i],"--playback-card")==0){
i++;
playback_card=argv[i];
}else if (strcmp(argv[i],"--ec")==0){
ec=TRUE;
}else if (strcmp(argv[i],"--agc")==0){
......@@ -255,13 +260,15 @@ static void run_media_streams(int localport, const char *remote_ip, int remotepo
MSSndCardManager *manager=ms_snd_card_manager_get();
MSSndCard *capt= capture_card==NULL ? ms_snd_card_manager_get_default_capture_card(manager) :
ms_snd_card_manager_get_card(manager,capture_card);
MSSndCard *play= playback_card==NULL ? ms_snd_card_manager_get_default_playback_card(manager) :
ms_snd_card_manager_get_card(manager,playback_card);
audio=audio_stream_new(localport,ms_is_ipv6(remote_ip));
audio_stream_enable_automatic_gain_control(audio,agc);
audio_stream_enable_noise_gate(audio,use_ng);
audio_stream_set_echo_canceller_params(audio,ec_len_ms,ec_delay_ms,ec_framesize);
printf("Starting audio stream.\n");
audio_stream_set_echo_canceller_params(audio,ec_len_ms,ec_delay_ms,ec_framesize);
printf("Starting audio stream.\n");
audio_stream_start_now(audio,profile,remote_ip,remoteport,remoteport+1,payload,jitter,
ms_snd_card_manager_get_default_playback_card(manager),
play,
capt,
ec);
if (audio) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment