From f8b54ea9c01d80cd2c4fbb24f186090c6c925508 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 4 Dec 2013 12:09:06 +0100 Subject: [PATCH] Playback: use POSIX API --- Makefile.in | 6 +++--- src/video_capture/import.c | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Makefile.in b/Makefile.in index d86249b30..55e1a8f71 100644 --- a/Makefile.in +++ b/Makefile.in @@ -5,9 +5,9 @@ CXX = @CXX@ QMAKE = @QMAKE@ LINKER = @LINKER@ COMMON_FLAGS = -g @DEFS@ -DPATH_PREFIX=@prefix@ -DLIB_DIR=@libdir@ -Wall -Wextra -Wpointer-arith -msse2 -CFLAGS = @CFLAGS@ @X_CFLAGS@ $(COMMON_FLAGS) -CPPFLAGS = @CPPFLAGS@ -CXXFLAGS = @CXXFLAGS@ $(COMMON_FLAGS) +CFLAGS = @CFLAGS@ @X_CFLAGS@ $(COMMON_FLAGS) -D_GNU_SOURCE +CPPFLAGS = @CPPFLAGS@ -D_GNU_SOURCE +CXXFLAGS = @CXXFLAGS@ $(COMMON_FLAGS) -D_GNU_SOURCE NVCCFLAGS = @NVCCFLAGS@ LDFLAGS = @LDFLAGS@ LIBS += @LIBS@ @JACK_TRANS_LIB@ @MATHLIBS@ @COREAUDIO_LIB@ \ diff --git a/src/video_capture/import.c b/src/video_capture/import.c index 2a840135f..35b7e3dc9 100644 --- a/src/video_capture/import.c +++ b/src/video_capture/import.c @@ -967,24 +967,30 @@ static void * reading_thread(void *args) perror("stat"); goto next; } - FILE *file = fopen(name, "rb"); - if(!file) { - perror("fopen"); + int fd = open(name, O_RDONLY|O_DIRECT); + if(fd == -1) { + perror("open"); goto next; } new_entry = malloc(sizeof(struct processed_entry)); assert(new_entry != NULL); new_entry->data_len = sb.st_size; - new_entry->data = malloc(new_entry->data_len); + posix_memalign((void **) &new_entry->data, + 512, new_entry->data_len); new_entry->next = NULL; assert(new_entry->data != NULL); - size_t res = fread(new_entry->data, new_entry->data_len, 1, file); - fclose(file); - if(res != 1) { - perror("fread"); - goto next; - } + ssize_t bytes = 0; + do { + ssize_t res = read(fd, new_entry->data + bytes, + new_entry->data_len - bytes); + if (res <= 0) { + perror("read"); + break; + } + bytes += res; + } while (bytes < new_entry->data_len); + close(fd); pthread_mutex_lock(&s->lock); {