diff options
-rw-r--r-- | src/dabplussnoop.cpp | 8 | ||||
-rw-r--r-- | src/dabplussnoop.hpp | 12 | ||||
-rw-r--r-- | src/etisnoop.cpp | 23 | ||||
-rw-r--r-- | src/faad_decoder.cpp | 10 |
4 files changed, 33 insertions, 20 deletions
diff --git a/src/dabplussnoop.cpp b/src/dabplussnoop.cpp index d7bc21a..f0badaf 100644 --- a/src/dabplussnoop.cpp +++ b/src/dabplussnoop.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Matthias P. Braendli (http://www.opendigitalradio.org) + Copyright (C) 2017 Matthias P. Braendli (http://www.opendigitalradio.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -305,18 +305,16 @@ bool DabPlusSnoop::analyse_au(vector<vector<uint8_t> >& aus) return m_faad_decoder.decode(aus); } -void DabPlusSnoop::close() +DabPlusSnoop::~DabPlusSnoop() { m_faad_decoder.close(); } -void StreamSnoop::close() +StreamSnoop::~StreamSnoop() { if (m_raw_data_stream_fd) { fclose(m_raw_data_stream_fd); } - - dps.close(); } void StreamSnoop::push(uint8_t* streamdata, size_t streamsize) diff --git a/src/dabplussnoop.hpp b/src/dabplussnoop.hpp index 8efc481..8ba35d5 100644 --- a/src/dabplussnoop.hpp +++ b/src/dabplussnoop.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Matthias P. Braendli (http://www.opendigitalradio.org) + Copyright (C) 2017 Matthias P. Braendli (http://www.opendigitalradio.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -89,6 +89,9 @@ class DabPlusSnoop m_index(0), m_subchannel_index(0), m_data(0) {} + ~DabPlusSnoop(); + DabPlusSnoop(const DabPlusSnoop& other) = delete; + DabPlusSnoop& operator=(const DabPlusSnoop& other) = delete; void set_subchannel_index(unsigned subchannel_index) { @@ -102,8 +105,6 @@ class DabPlusSnoop void push(uint8_t* streamdata, size_t streamsize); - void close(void); - private: /* Data needed for FAAD */ FaadDecoder m_faad_decoder; @@ -135,6 +136,9 @@ class StreamSnoop dps(), m_index(-1), m_raw_data_stream_fd(NULL) {} + ~StreamSnoop(); + StreamSnoop(const StreamSnoop& other) = delete; + StreamSnoop& operator=(const StreamSnoop& other) = delete; void set_subchannel_index(unsigned subchannel_index) { @@ -149,8 +153,6 @@ class StreamSnoop void push(uint8_t* streamdata, size_t streamsize); - void close(void); - private: DabPlusSnoop dps; int m_index; diff --git a/src/etisnoop.cpp b/src/etisnoop.cpp index ef0de16..23a26e0 100644 --- a/src/etisnoop.cpp +++ b/src/etisnoop.cpp @@ -44,9 +44,11 @@ #include <boost/regex.hpp> #include <vector> #include <map> +#include <atomic> #include <list> #include <sstream> #include <time.h> +#include <signal.h> extern "C" { #include "lib_crc.h" } @@ -117,6 +119,14 @@ int eti_analyse(eti_analyse_config_t &config); const char *get_programme_type_str(size_t int_table_Id, size_t pty); int sprintfMJD(char *dst, int mjd); +// Signal handler flag +static std::atomic<bool> quit(false); + +static void handle_signal(int) +{ + quit.store(true); +} + static void print_fig_result(const fig_result_t& fig_result, const display_settings_t& disp) { if (disp.print) { @@ -188,6 +198,12 @@ void usage(void) int main(int argc, char *argv[]) { + struct sigaction sa; + memset( &sa, 0, sizeof(sa) ); + sa.sa_handler = handle_signal; + sigfillset(&sa.sa_mask); + sigaction(SIGINT, &sa, NULL); + int index; int ch = 0; string file_name("-"); @@ -200,8 +216,7 @@ int main(int argc, char *argv[]) case 'd': { int subchix = atoi(optarg); - StreamSnoop snoop; - config.streams_to_decode[subchix] = snoop; + config.streams_to_decode.emplace(std::piecewise_construct, std::make_tuple(subchix), std::make_tuple()); } break; case 'e': @@ -680,10 +695,8 @@ int eti_analyse(eti_analyse_config_t &config) if (config.analyse_fig_rates and (fct % 250) == 0) { rate_display_analysis(false, config.analyse_fig_rates_per_second); } - } - for (auto& snoop : config.streams_to_decode) { - snoop.second.close(); + if (quit.load()) running = false; } if (config.decode_watermark) { diff --git a/src/faad_decoder.cpp b/src/faad_decoder.cpp index 73ea374..24c951a 100644 --- a/src/faad_decoder.cpp +++ b/src/faad_decoder.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Matthias P. Braendli (http://www.opendigitalradio.org) + Copyright (C) 2017 Matthias P. Braendli (http://www.opendigitalradio.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,7 +38,7 @@ using namespace std; FaadDecoder::FaadDecoder() : m_data_len(0), - m_fd(NULL), + m_fd(nullptr), m_initialised(false) { } @@ -105,7 +105,7 @@ bool FaadDecoder::decode(vector<vector<uint8_t> > aus) } outBuffer = (int16_t *)NeAACDecDecode(m_faad_handle.decoder, &hInfo, &au[0], au.size()); - assert(outBuffer != NULL); + assert(outBuffer != nullptr); m_sample_rate = hInfo.samplerate; m_channels = hInfo.channels; @@ -125,7 +125,7 @@ bool FaadDecoder::decode(vector<vector<uint8_t> > aus) return false; } - if (m_fd == NULL) { + if (m_fd == nullptr) { stringstream ss; ss << m_filename << ".wav"; m_fd = wavfile_open(ss.str().c_str(), m_sample_rate); @@ -155,7 +155,7 @@ bool FaadDecoder::decode(vector<vector<uint8_t> > aus) void FaadDecoder::close() { - if (m_initialised) { + if (m_fd) { wavfile_close(m_fd); } } |