]> code.delx.au - pulseaudio/blobdiff - polyp/sink-input.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / sink-input.c
index 486a204439689ad848b9dd36a77f04e431b070f1..23b4a136487ee63bc4377dee9beedcb4753df23e 100644 (file)
@@ -4,7 +4,7 @@
   This file is part of polypaudio.
  
   polypaudio is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published
+  it under the terms of the GNU Lesser General Public License as published
   by the Free Software Foundation; either version 2 of the License,
   or (at your option) any later version.
  
@@ -13,7 +13,7 @@
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.
  
-  You should have received a copy of the GNU General Public License
+  You should have received a copy of the GNU Lesser General Public License
   along with polypaudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
@@ -36,7 +36,7 @@
 
 #define CONVERT_BUFFER_LENGTH 4096
 
-struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec, int variable_rate) {
+struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec, int variable_rate, int resample_method) {
     struct pa_sink_input *i;
     struct pa_resampler *resampler = NULL;
     int r;
@@ -47,9 +47,12 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con
         pa_log(__FILE__": Failed to create sink input: too many inputs per sink.\n");
         return NULL;
     }
+
+    if (resample_method < 0)
+        resample_method = s->core->resample_method;
     
     if (variable_rate || !pa_sample_spec_equal(spec, &s->sample_spec))
-        if (!(resampler = pa_resampler_new(spec, &s->sample_spec, s->core->memblock_stat, s->core->resample_method)))
+        if (!(resampler = pa_resampler_new(spec, &s->sample_spec, s->core->memblock_stat, resample_method)))
             return NULL;
     
     i = pa_xmalloc(sizeof(struct pa_sink_input));
@@ -66,9 +69,10 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con
     i->kill = NULL;
     i->get_latency = NULL;
     i->userdata = NULL;
+    i->underrun = NULL;
 
-    i->corked = 0;
     i->volume = PA_VOLUME_NORM;
+    i->playing = 0;
 
     i->resampled_chunk.memblock = NULL;
     i->resampled_chunk.index = i->resampled_chunk.length = 0;
@@ -89,7 +93,7 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con
 }
 
 void pa_sink_input_disconnect(struct pa_sink_input *i) {
-    assert(i && i->state == PA_SINK_INPUT_RUNNING && i->sink && i->sink->core);
+    assert(i && i->state != PA_SINK_INPUT_DISCONNECTED && i->sink && i->sink->core);
 
     pa_idxset_remove_by_data(i->sink->core->sink_inputs, i, NULL);
     pa_idxset_remove_by_data(i->sink->inputs, i, NULL);
@@ -154,20 +158,19 @@ pa_usec_t pa_sink_input_get_latency(struct pa_sink_input *i) {
 }
 
 int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk) {
-    int ret = 0;
+    int ret = -1;
     assert(i && chunk && i->ref >= 1);
 
-    if (!i->peek || !i->drop)
-        return -1;
-
-    if (i->corked)
-        return -1;
-    
-    if (!i->resampler)
-        return i->peek(i, chunk);
-
     pa_sink_input_ref(i);
 
+    if (!i->peek || !i->drop || i->state == PA_SINK_INPUT_CORKED)
+        goto finish;
+        
+    if (!i->resampler) {
+        ret = i->peek(i, chunk);
+        goto finish;
+    }
+
     while (!i->resampled_chunk.memblock) {
         struct pa_memchunk tchunk;
         size_t l;
@@ -197,6 +200,11 @@ int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk) {
 
 finish:
 
+    if (ret < 0 && i->playing && i->underrun)
+        i->underrun(i);
+
+    i->playing = ret >= 0;
+    
     pa_sink_input_unref(i);
     
     return ret;
@@ -235,9 +243,12 @@ void pa_sink_input_set_volume(struct pa_sink_input *i, pa_volume_t volume) {
 void pa_sink_input_cork(struct pa_sink_input *i, int b) {
     int n;
     assert(i && i->ref >= 1);
-    
-    n = i->corked && !b;
-    i->corked = b;
+
+    if (i->state == PA_SINK_INPUT_DISCONNECTED)
+        return;
+
+    n = i->state == PA_SINK_INPUT_CORKED && !b;
+    i->state = b ? PA_SINK_INPUT_CORKED : PA_SINK_INPUT_RUNNING;
 
     if (n)
         pa_sink_notify(i->sink);