]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/sound-file-stream.c
move flat volume logic into the core. while doing so add n_volume_steps field to...
[pulseaudio] / src / pulsecore / sound-file-stream.c
index e209676f63ab5bb8e1a528a37d4e27dbb6bf2788..1be421f178c6f61482a42d4b213729cdc87c9dfc 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -35,6 +33,7 @@
 #include <sndfile.h>
 
 #include <pulse/xmalloc.h>
+#include <pulse/util.h>
 
 #include <pulsecore/core-error.h>
 #include <pulsecore/sink-input.h>
@@ -134,7 +133,7 @@ static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t s
      * we are heard right-away. */
     if (PA_SINK_INPUT_IS_LINKED(state) &&
         i->thread_info.state == PA_SINK_INPUT_INIT)
-        pa_sink_input_request_rewind(i, 0, FALSE, TRUE);
+        pa_sink_input_request_rewind(i, 0, FALSE, TRUE, TRUE);
 }
 
 /* Called from IO thread context */
@@ -149,8 +148,6 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk
     if (!u->memblockq)
         return -1;
 
-    pa_log_debug("pop: %lu", (unsigned long) length);
-
     for (;;) {
         pa_memchunk tchunk;
         size_t fs;
@@ -158,6 +155,7 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk
         sf_count_t n;
 
         if (pa_memblockq_peek(u->memblockq, chunk) >= 0) {
+            chunk->length = PA_MIN(chunk->length, length);
             pa_memblockq_drop(u->memblockq, chunk->length);
             return 0;
         }
@@ -172,10 +170,10 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk
 
         if (u->readf_function) {
             fs = pa_frame_size(&i->sample_spec);
-            n = u->readf_function(u->sndfile, p, length/fs);
+            n = u->readf_function(u->sndfile, p, (sf_count_t) (length/fs));
         } else {
             fs = 1;
-            n = sf_read_raw(u->sndfile, p, length);
+            n = sf_read_raw(u->sndfile, p, (sf_count_t) length);
         }
 
         pa_memblock_release(tchunk.memblock);
@@ -188,17 +186,13 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk
             break;
         }
 
-        tchunk.length = n * fs;
+        tchunk.length = (size_t) n * fs;
 
         pa_memblockq_push(u->memblockq, &tchunk);
         pa_memblock_unref(tchunk.memblock);
     }
 
-    pa_log_debug("peek fail");
-
     if (pa_sink_input_safe_to_remove(i)) {
-        pa_log_debug("completed to play");
-
         pa_memblockq_free(u->memblockq);
         u->memblockq = NULL;
 
@@ -212,7 +206,6 @@ static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
     file_stream *u;
 
     pa_sink_input_assert_ref(i);
-    pa_assert(nbytes > 0);
     u = FILE_STREAM(i->userdata);
     file_stream_assert_ref(u);
 
@@ -317,8 +310,8 @@ int pa_play_file(
             break;
     }
 
-    ss.rate = sfinfo.samplerate;
-    ss.channels = sfinfo.channels;
+    ss.rate = (uint32_t) sfinfo.samplerate;
+    ss.channels = (uint8_t) sfinfo.channels;
 
     if (!pa_sample_spec_valid(&ss)) {
         pa_log("Unsupported sample format in file %s", fname);
@@ -329,8 +322,8 @@ int pa_play_file(
     data.sink = sink;
     data.driver = __FILE__;
     pa_sink_input_new_data_set_sample_spec(&data, &ss);
-    pa_sink_input_new_data_set_volume(&data, volume);
-    pa_proplist_sets(data.proplist, PA_PROP_MEDIA_NAME, fname);
+    pa_sink_input_new_data_set_virtual_volume(&data, volume);
+    pa_proplist_sets(data.proplist, PA_PROP_MEDIA_NAME, pa_path_get_filename(fname));
     pa_proplist_sets(data.proplist, PA_PROP_MEDIA_FILENAME, fname);
 
     u->sink_input = pa_sink_input_new(sink->core, &data, 0);