diff --git a/CMakeLists.txt b/CMakeLists.txt index 723d235..f9b5cba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,24 +9,12 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) # For OSX - don't clear RPATH on install set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -if (WIN32) - find_library (MMAN mman) - if(NOT(MMAN)) - message(FATAL_ERROR "please install mman-win32") - else(NOT(MMAN)) - set (extraLibs ${extraLibs} ${MMAN}) - endif(NOT(MMAN)) -ENDIF (WIN32) - if (MSVC) - find_path(MMAN_INCLUDE_DIR sys/mman.h) - #force std::complex<> typedefs in liquiddsp add_definitions(-D_LIBCPP_COMPLEX) #enable math definitions in math.h add_definitions(-D_USE_MATH_DEFINES) - endif (MSVC) if (NOT CMAKE_CXX_FLAGS) @@ -68,7 +56,6 @@ find_package(FFTW REQUIRED) find_package(Liquid REQUIRED) include_directories( - ${MMAN_INCLUDE_DIR} ${QT_INCLUDES} ${FFTW_INCLUDES} ${LIQUID_INCLUDES} @@ -81,7 +68,6 @@ target_link_libraries(inspectrum ${QT_LIBRARIES} ${FFTW_LIBRARIES} ${LIQUID_LIBRARIES} - ${extraLibs} ) set(INSTALL_DEFAULT_BINDIR "bin" CACHE STRING "Appended to CMAKE_INSTALL_PREFIX") diff --git a/inputsource.cpp b/inputsource.cpp index b5f2721..7568fc0 100644 --- a/inputsource.cpp +++ b/inputsource.cpp @@ -20,12 +20,9 @@ #include "inputsource.h" -#include #include #include #include -#include -#include #include #include @@ -107,13 +104,12 @@ InputSource::~InputSource() void InputSource::cleanup() { if (mmapData != nullptr) { - munmap(mmapData, fileSize); + inputFile->unmap(mmapData); mmapData = nullptr; - fileSize = 0; } if (inputFile != nullptr) { - fclose(inputFile); + delete inputFile; inputFile = nullptr; } } @@ -138,28 +134,21 @@ void InputSource::openFile(const char *filename) sampleAdapter = std::unique_ptr(new ComplexF32SampleAdapter()); } - errno = 0; - FILE *file = fopen(filename, "rb"); - if (file == nullptr) { - std::stringstream ss; - ss << "Error opening file: " << strerror(errno) << " (" << errno << ")"; - throw std::runtime_error(ss.str()); + std::unique_ptr file(new QFile(filename)); + if (!file->open(QFile::ReadOnly)) { + throw std::runtime_error(file->errorString().toStdString()); } - struct stat sb; - if (fstat(fileno(file), &sb) != 0) - throw std::runtime_error("Error fstating file"); - off_t size = sb.st_size; + auto size = file->size(); sampleCount = size / sampleAdapter->sampleSize(); - auto data = mmap(NULL, size, PROT_READ, MAP_SHARED, fileno(file), 0); + auto data = file->map(0, size); if (data == nullptr) throw std::runtime_error("Error mmapping file"); cleanup(); - inputFile = file; - fileSize = size; + inputFile = file.release(); mmapData = data; invalidate(); diff --git a/inputsource.h b/inputsource.h index ff7ea76..ac94dda 100644 --- a/inputsource.h +++ b/inputsource.h @@ -21,6 +21,7 @@ #pragma once #include +#include #include "samplesource.h" class SampleAdapter { @@ -32,11 +33,10 @@ public: class InputSource : public SampleSource> { private: - FILE *inputFile = nullptr; - off_t fileSize = 0; + QFile *inputFile = nullptr; off_t sampleCount = 0; off_t sampleRate = 0; - void *mmapData = nullptr; + uchar *mmapData = nullptr; std::unique_ptr sampleAdapter; public: