diff options
author | XANTRONIX Development | 2022-03-19 12:10:58 -0400 |
---|---|---|
committer | XANTRONIX Development | 2022-03-19 12:10:58 -0400 |
commit | c48eabffbe6dc192dedad73c86616ba26f7ed6d3 (patch) | |
tree | 8f4d01f7680297e46dfd066bd7ea3eb26a70a59a | |
parent | fffe9ba41da0cd99402178edf3c21dea64a57873 (diff) | |
download | xas-c48eabffbe6dc192dedad73c86616ba26f7ed6d3.tar.gz xas-c48eabffbe6dc192dedad73c86616ba26f7ed6d3.tar.bz2 xas-c48eabffbe6dc192dedad73c86616ba26f7ed6d3.zip |
Use filesystem I/O block size in src/riff.c
-rw-r--r-- | src/riff.c | 50 |
1 files changed, 37 insertions, 13 deletions
@@ -2,6 +2,7 @@ #include <string.h> #include <fcntl.h> #include <unistd.h> +#include <sys/stat.h> #include <errno.h> #include <xas/audio.h> @@ -10,7 +11,9 @@ struct _xas_riff { const char *file; int fd; - size_t size; + + size_t size, + blksize; xas_audio_format format; }; @@ -73,6 +76,7 @@ static xas_riff *new_file(const char *path, xas_audio_format format, int flags) { xas_riff *riff; + struct stat st; if ((riff = malloc(sizeof(*riff))) == NULL) { goto error_malloc_riff; @@ -84,8 +88,13 @@ static xas_riff *new_file(const char *path, goto error_open; } - riff->file = path; - riff->size = 0; + if (fstat(riff->fd, &st) < 0) { + goto error_fstat; + } + + riff->file = path; + riff->size = 0; + riff->blksize = st.st_blksize; riff->format.channels = format.channels; riff->format.sample_size = format.sample_size; @@ -98,6 +107,7 @@ static xas_riff *new_file(const char *path, return riff; error_header_write: +error_fstat: close(riff->fd); error_open: @@ -189,15 +199,21 @@ static xas_riff *open_fd(int fd) { xas_riff *riff; xas_riff_wave_header header; + struct stat st; ssize_t readlen; + if (fstat(fd, &st) < 0) { + goto error_fstat; + } + if ((riff = malloc(sizeof(*riff))) == NULL) { goto error_malloc_riff; } - riff->file = NULL; - riff->fd = fd; - riff->size = 0; + riff->file = NULL; + riff->fd = fd; + riff->size = 0; + riff->blksize = st.st_blksize; riff->format.channels = 0; riff->format.sample_size = 0; @@ -225,6 +241,7 @@ error_read: free(riff); error_malloc_riff: +error_fstat: return NULL; } @@ -232,6 +249,7 @@ static xas_riff *open_file(const char *path, int flags) { xas_riff *riff; xas_riff_wave_header header; + struct stat st; ssize_t readlen; if ((riff = malloc(sizeof(*riff))) == NULL) { @@ -244,8 +262,13 @@ static xas_riff *open_file(const char *path, int flags) { goto error_open; } - riff->file = path; - riff->size = 0; + if (fstat(riff->fd, &st) < 0) { + goto error_fstat; + } + + riff->file = path; + riff->size = 0; + riff->blksize = st.st_blksize; riff->format.channels = 0; riff->format.sample_size = 0; @@ -275,6 +298,7 @@ error_wave_header_parse: error_wave_header_short: error_read: error_lseek: +error_fstat: close(riff->fd); error_open: @@ -348,7 +372,7 @@ xas_audio_stream *xas_riff_new_file(const char *path, if ((stream = xas_audio_stream_new_sink((xas_audio_drain)audio_drain, (xas_audio_cleanup)close_file, format, - 4096, + riff->blksize, riff)) == NULL) { goto error_audio_stream_new_sink; } @@ -356,7 +380,7 @@ xas_audio_stream *xas_riff_new_file(const char *path, if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill, (xas_audio_cleanup)close_file, format, - 4096, + riff->blksize, riff)) == NULL) { goto error_audio_stream_new_sink; } @@ -383,7 +407,7 @@ xas_audio_stream *xas_riff_open_file(const char *path, int flags) { if ((stream = xas_audio_stream_new_sink((xas_audio_drain)audio_drain, (xas_audio_cleanup)close_file, riff->format, - 4096, + riff->blksize, riff)) == NULL) { goto error_audio_stream_new_sink; } @@ -391,7 +415,7 @@ xas_audio_stream *xas_riff_open_file(const char *path, int flags) { if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill, (xas_audio_cleanup)close_file, riff->format, - 4096, + riff->blksize, riff)) == NULL) { goto error_audio_stream_new_sink; } @@ -417,7 +441,7 @@ xas_audio_stream *xas_riff_open_fd(int fd) { if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill, (xas_audio_cleanup)close_file, riff->format, - 4096, + riff->blksize, riff)) == NULL) { goto error_audio_stream_new_sink; } |