[polypaudio-commits] r901 - /trunk/src/polypcore/sound-file-stream.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed May 17 07:55:55 PDT 2006


Author: lennart
Date: Wed May 17 16:55:54 2006
New Revision: 901

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=901&root=polypaudio&view=rev
Log:
* support native ULAW/ALAW file streams
* fix shutdown of file streams

Modified:
    trunk/src/polypcore/sound-file-stream.c

Modified: trunk/src/polypcore/sound-file-stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sound-file-stream.c?rev=901&root=polypaudio&r1=900&r2=901&view=diff
==============================================================================
--- trunk/src/polypcore/sound-file-stream.c (original)
+++ trunk/src/polypcore/sound-file-stream.c Wed May 17 16:55:54 2006
@@ -65,10 +65,6 @@
     free_userdata(i->userdata);
 }
 
-static void si_kill(PA_GCC_UNUSED pa_mainloop_api *m, void *i) {
-    sink_input_kill(i);
-}
-
 static int sink_input_peek(pa_sink_input *i, pa_memchunk *chunk) {
     struct userdata *u;
     assert(i && chunk && i->userdata);
@@ -76,18 +72,25 @@
 
     if (!u->memchunk.memblock) {
         uint32_t fs = pa_frame_size(&i->sample_spec);
-        sf_count_t samples = BUF_SIZE/fs;
+        sf_count_t n;
 
         u->memchunk.memblock = pa_memblock_new(BUF_SIZE, i->sink->core->memblock_stat);
         u->memchunk.index = 0;
-        samples = u->readf_function(u->sndfile, u->memchunk.memblock->data, samples);
-        u->memchunk.length = samples*fs;
+
+        if (u->readf_function) {
+            if ((n = u->readf_function(u->sndfile, u->memchunk.memblock->data, BUF_SIZE/fs)) <= 0)
+                n = 0;
+
+            u->memchunk.length = n * fs;
+        } else {
+            if ((n = sf_read_raw(u->sndfile, u->memchunk.memblock->data, BUF_SIZE)) <= 0)
+                n = 0;
+            
+            u->memchunk.length = n;
+        }
         
         if (!u->memchunk.length) {
-            pa_memblock_unref(u->memchunk.memblock);
-            u->memchunk.memblock = NULL;
-            u->memchunk.index = u->memchunk.length = 0;
-            pa_mainloop_api_once(i->sink->core->mainloop, si_kill, i);
+            free_userdata(u);
             return -1;
         }
     }
@@ -135,14 +138,24 @@
         goto fail;
     }
 
+    u->readf_function = NULL;
+    
     switch (sfinfo.format & 0xFF) {
         case SF_FORMAT_PCM_16:
         case SF_FORMAT_PCM_U8:
-        case SF_FORMAT_ULAW:
-        case SF_FORMAT_ALAW:
+        case SF_FORMAT_PCM_S8:
             ss.format = PA_SAMPLE_S16NE;
             u->readf_function = (sf_count_t (*)(SNDFILE *sndfile, void *ptr, sf_count_t frames)) sf_readf_short;
             break;
+
+        case SF_FORMAT_ULAW:
+            ss.format = PA_SAMPLE_ULAW;
+            break;
+            
+        case SF_FORMAT_ALAW:
+            ss.format = PA_SAMPLE_ALAW;
+            break;
+
         case SF_FORMAT_FLOAT:
         default:
             ss.format = PA_SAMPLE_FLOAT32NE;




More information about the pulseaudio-commits mailing list