]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/sound-file.c
add byte-to-usec and usec-to-byte converters that round up, not down
[pulseaudio] / src / pulsecore / sound-file.c
index b1c509f25474d2133a4566004c88399e4b027fdb..74338f9a01412ef7d4c81ae02874613b468ad9df 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -47,7 +45,7 @@ int pa_sound_file_load(
         pa_sample_spec *ss,
         pa_channel_map *map,
         pa_memchunk *chunk) {
-    
+
     SNDFILE *sf = NULL;
     SF_INFO sfinfo;
     int ret = -1;
@@ -63,7 +61,11 @@ int pa_sound_file_load(
     pa_memchunk_reset(chunk);
     memset(&sfinfo, 0, sizeof(sfinfo));
 
-    if ((fd = open(fname, O_RDONLY|O_NOCTTY)) < 0) {
+    if ((fd = open(fname, O_RDONLY
+#ifdef O_NOCTTY
+                   |O_NOCTTY
+#endif
+                   )) < 0) {
         pa_log("Failed to open file %s: %s", fname, pa_cstrerror(errno));
         goto finish;
     }
@@ -75,7 +77,7 @@ int pa_sound_file_load(
     } else
         pa_log_debug("POSIX_FADV_SEQUENTIAL succeeded.");
 #endif
-    
+
     if (!(sf = sf_open_fd(fd, SFM_READ, &sfinfo, 1))) {
         pa_log("Failed to open file %s", fname);
         pa_close(fd);
@@ -106,8 +108,8 @@ int pa_sound_file_load(
             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);
@@ -115,9 +117,9 @@ int pa_sound_file_load(
     }
 
     if (map)
-        pa_channel_map_init_auto(map, ss->channels, PA_CHANNEL_MAP_DEFAULT);
+        pa_channel_map_init_extend(map, ss->channels, PA_CHANNEL_MAP_DEFAULT);
 
-    if ((l = pa_frame_size(ss) * sfinfo.frames) > PA_SCACHE_ENTRY_SIZE_MAX) {
+    if ((l = pa_frame_size(ss) * (size_t) sfinfo.frames) > PA_SCACHE_ENTRY_SIZE_MAX) {
         pa_log("File too large");
         goto finish;
     }
@@ -129,7 +131,7 @@ int pa_sound_file_load(
     ptr = pa_memblock_acquire(chunk->memblock);
 
     if ((readf_function && readf_function(sf, ptr, sfinfo.frames) != sfinfo.frames) ||
-        (!readf_function && sf_read_raw(sf, ptr, l) != (sf_count_t) l)) {
+        (!readf_function && sf_read_raw(sf, ptr, (sf_count_t) l) != (sf_count_t) l)) {
         pa_log("Premature file end");
         goto finish;
     }
@@ -151,13 +153,13 @@ finish:
 }
 
 int pa_sound_file_too_big_to_cache(const char *fname) {
-    
+
     SNDFILE*sf = NULL;
     SF_INFO sfinfo;
     pa_sample_spec ss;
 
     pa_assert(fname);
-    
+
     if (!(sf = sf_open(fname, SFM_READ, &sfinfo))) {
         pa_log("Failed to open file %s", fname);
         return -1;
@@ -187,15 +189,15 @@ int pa_sound_file_too_big_to_cache(const char *fname) {
             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);
         return -1;
     }
-    
-    if ((pa_frame_size(&ss) * sfinfo.frames) > PA_SCACHE_ENTRY_SIZE_MAX) {
+
+    if ((pa_frame_size(&ss) * (size_t) sfinfo.frames) > PA_SCACHE_ENTRY_SIZE_MAX) {
         pa_log("File too large: %s", fname);
         return 1;
     }