diff options
author | Ron Economos <w6rz@comcast.net> | 2016-08-19 11:55:11 -0700 |
---|---|---|
committer | Ron Economos <w6rz@comcast.net> | 2016-08-19 11:55:11 -0700 |
commit | 1866270951ba0efa556a35accbf5dfdffb19d463 (patch) | |
tree | fa2968eeca73b39a02be2bd80e55bd94ae2230dd /gr-dtv | |
parent | fac58ba790528a692ce4df0c4f5b1e77f1992075 (diff) |
gr-dtv: Remove all exit(1) calls and replace with exception.
Diffstat (limited to 'gr-dtv')
23 files changed, 283 insertions, 195 deletions
diff --git a/gr-dtv/lib/atsc/atsc_interleaver_impl.cc b/gr-dtv/lib/atsc/atsc_interleaver_impl.cc index e628fbf30d..cfc9e2996c 100644 --- a/gr-dtv/lib/atsc/atsc_interleaver_impl.cc +++ b/gr-dtv/lib/atsc/atsc_interleaver_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include "atsc_interleaver_impl.h" #include "gnuradio/dtv/atsc_consts.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -45,14 +44,15 @@ namespace gr { J = 4; registers = (unsigned char *) malloc(sizeof(unsigned char) * I * ((I - 1) * J)); if (registers == NULL) { - fprintf(stderr, "Out of memory.\n"); - exit(1); + GR_LOG_FATAL(d_logger, "ATSC Interleaver, cannot allocate memory for registers."); + throw std::bad_alloc(); } pointers = (int *) malloc(sizeof(int) * I); if (pointers == NULL) { - fprintf(stderr, "Out of memory.\n"); - exit(1); + free(registers); + GR_LOG_FATAL(d_logger, "ATSC Interleaver, cannot allocate memory for pointers"); + throw std::bad_alloc(); } memset(registers, 0, sizeof(unsigned char) * I * ((I - 1) * J)); diff --git a/gr-dtv/lib/dvb/dvb_bbheader_bb_impl.cc b/gr-dtv/lib/dvb/dvb_bbheader_bb_impl.cc index 6961c2265c..d14b46a0e1 100644 --- a/gr-dtv/lib/dvb/dvb_bbheader_bb_impl.cc +++ b/gr-dtv/lib/dvb/dvb_bbheader_bb_impl.cc @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvb_bbheader_bb_impl.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -504,7 +503,7 @@ namespace gr { for (int j = 0; j < (int)((kbch - 80 - padding) / 8); j++) { if (count == 0) { if (*in != 0x47) { - printf("Transport Stream sync error!\n"); + GR_LOG_WARN(d_logger, "Transport Stream sync error!"); } j--; in++; @@ -527,7 +526,7 @@ namespace gr { for (int j = 0; j < (int)((kbch - 80 - padding) / 8); j++) { if (count == 0) { if (*in != 0x47) { - printf("Transport Stream sync error!\n"); + GR_LOG_WARN(d_logger, "Transport Stream sync error!"); } in++; b = crc; @@ -560,7 +559,7 @@ namespace gr { if (nibble == TRUE) { if (count == 0) { if (*in != 0x47) { - printf("Transport Stream sync error!\n"); + GR_LOG_WARN(d_logger, "Transport Stream sync error!"); } in++; b = crc; diff --git a/gr-dtv/lib/dvbs2/dvbs2_physical_cc_impl.cc b/gr-dtv/lib/dvbs2/dvbs2_physical_cc_impl.cc index d6c338695a..688ad7a40c 100644 --- a/gr-dtv/lib/dvbs2/dvbs2_physical_cc_impl.cc +++ b/gr-dtv/lib/dvbs2/dvbs2_physical_cc_impl.cc @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbs2_physical_cc_impl.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -80,8 +79,8 @@ namespace gr { type |= 1; } if (goldcode < 0 || goldcode > 262141) { - fprintf(stderr, "Gold Code must be between 0 and 262141 inclusive.\n"); - fprintf(stderr, "Gold Code set to 0.\n"); + GR_LOG_WARN(d_logger, "Gold Code must be between 0 and 262141 inclusive."); + GR_LOG_WARN(d_logger, "Gold Code set to 0."); goldcode = 0; } gold_code = goldcode; diff --git a/gr-dtv/lib/dvbt/dvbt_bit_inner_deinterleaver_impl.cc b/gr-dtv/lib/dvbt/dvbt_bit_inner_deinterleaver_impl.cc index c10a77c98a..4c67f62a60 100644 --- a/gr-dtv/lib/dvbt/dvbt_bit_inner_deinterleaver_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_bit_inner_deinterleaver_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_bit_inner_deinterleaver_impl.h" -#include <stdio.h> #define MAX_MODULATION_ORDER 6 #define INTERLEAVER_BLOCK_SIZE 126 @@ -34,37 +33,6 @@ namespace gr { const int dvbt_bit_inner_deinterleaver_impl::d_bsize = INTERLEAVER_BLOCK_SIZE; - int - dvbt_bit_inner_deinterleaver_impl::H(int e, int w) - { - int rez = 0; - - switch (e) { - case 0: - rez = w; - break; - case 1: - rez = (w + 63) % d_bsize; - break; - case 2: - rez = (w + 105) % d_bsize; - break; - case 3: - rez = (w + 42) % d_bsize; - break; - case 4: - rez = (w + 21) % d_bsize; - break; - case 5: - rez = (w + 84) % d_bsize; - break; - default: - break; - } - - return rez; - } - dvbt_bit_inner_deinterleaver::sptr dvbt_bit_inner_deinterleaver::make(int nsize, \ dvb_constellation_t constellation, dvbt_hierarchy_t hierarchy, dvbt_transmission_mode_t transmission) @@ -88,10 +56,10 @@ namespace gr { d_v = config.d_m; d_hierarchy = config.d_hierarchy; - d_perm = (unsigned char *)new unsigned char[d_v * d_bsize]; + d_perm = (unsigned char *)new (std::nothrow) unsigned char[d_v * d_bsize]; if (d_perm == NULL) { - std::cout << "Cannot allocate memory for d_perm" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "Bit Inner Deinterleaver, cannot allocate memory for d_perm."); + throw std::bad_alloc(); } //Init permutation table (used for b[e][do]) @@ -105,8 +73,8 @@ namespace gr { } if (d_nsize % d_bsize) { - std::cout << "Error: Input size must be multiple of block size: " \ - << "nsize: " << d_nsize << "bsize: " << d_bsize << std::endl; + GR_LOG_ERROR(d_logger, boost::format("Input size must be multiple of block size: nsize: %1% bsize: %2%") \ + % d_nsize % d_bsize); } } @@ -145,7 +113,7 @@ namespace gr { int c = in[(bcount * d_bsize) + w]; for (int e = 0; e < d_v; e++) { - d_b[e][H(e, w)] = (c >> (d_v - e - 1)) & 1; + d_b[e][d_lookup_H[w][e]] = (c >> (d_v - e - 1)) & 1; } } @@ -189,6 +157,136 @@ namespace gr { return noutput_items; } + const int dvbt_bit_inner_deinterleaver_impl::d_lookup_H[INTERLEAVER_BLOCK_SIZE][MAX_MODULATION_ORDER] = + { + {0, 63, 105, 42, 21, 84}, + {1, 64, 106, 43, 22, 85}, + {2, 65, 107, 44, 23, 86}, + {3, 66, 108, 45, 24, 87}, + {4, 67, 109, 46, 25, 88}, + {5, 68, 110, 47, 26, 89}, + {6, 69, 111, 48, 27, 90}, + {7, 70, 112, 49, 28, 91}, + {8, 71, 113, 50, 29, 92}, + {9, 72, 114, 51, 30, 93}, + {10, 73, 115, 52, 31, 94}, + {11, 74, 116, 53, 32, 95}, + {12, 75, 117, 54, 33, 96}, + {13, 76, 118, 55, 34, 97}, + {14, 77, 119, 56, 35, 98}, + {15, 78, 120, 57, 36, 99}, + {16, 79, 121, 58, 37, 100}, + {17, 80, 122, 59, 38, 101}, + {18, 81, 123, 60, 39, 102}, + {19, 82, 124, 61, 40, 103}, + {20, 83, 125, 62, 41, 104}, + {21, 84, 0, 63, 42, 105}, + {22, 85, 1, 64, 43, 106}, + {23, 86, 2, 65, 44, 107}, + {24, 87, 3, 66, 45, 108}, + {25, 88, 4, 67, 46, 109}, + {26, 89, 5, 68, 47, 110}, + {27, 90, 6, 69, 48, 111}, + {28, 91, 7, 70, 49, 112}, + {29, 92, 8, 71, 50, 113}, + {30, 93, 9, 72, 51, 114}, + {31, 94, 10, 73, 52, 115}, + {32, 95, 11, 74, 53, 116}, + {33, 96, 12, 75, 54, 117}, + {34, 97, 13, 76, 55, 118}, + {35, 98, 14, 77, 56, 119}, + {36, 99, 15, 78, 57, 120}, + {37, 100, 16, 79, 58, 121}, + {38, 101, 17, 80, 59, 122}, + {39, 102, 18, 81, 60, 123}, + {40, 103, 19, 82, 61, 124}, + {41, 104, 20, 83, 62, 125}, + {42, 105, 21, 84, 63, 0}, + {43, 106, 22, 85, 64, 1}, + {44, 107, 23, 86, 65, 2}, + {45, 108, 24, 87, 66, 3}, + {46, 109, 25, 88, 67, 4}, + {47, 110, 26, 89, 68, 5}, + {48, 111, 27, 90, 69, 6}, + {49, 112, 28, 91, 70, 7}, + {50, 113, 29, 92, 71, 8}, + {51, 114, 30, 93, 72, 9}, + {52, 115, 31, 94, 73, 10}, + {53, 116, 32, 95, 74, 11}, + {54, 117, 33, 96, 75, 12}, + {55, 118, 34, 97, 76, 13}, + {56, 119, 35, 98, 77, 14}, + {57, 120, 36, 99, 78, 15}, + {58, 121, 37, 100, 79, 16}, + {59, 122, 38, 101, 80, 17}, + {60, 123, 39, 102, 81, 18}, + {61, 124, 40, 103, 82, 19}, + {62, 125, 41, 104, 83, 20}, + {63, 0, 42, 105, 84, 21}, + {64, 1, 43, 106, 85, 22}, + {65, 2, 44, 107, 86, 23}, + {66, 3, 45, 108, 87, 24}, + {67, 4, 46, 109, 88, 25}, + {68, 5, 47, 110, 89, 26}, + {69, 6, 48, 111, 90, 27}, + {70, 7, 49, 112, 91, 28}, + {71, 8, 50, 113, 92, 29}, + {72, 9, 51, 114, 93, 30}, + {73, 10, 52, 115, 94, 31}, + {74, 11, 53, 116, 95, 32}, + {75, 12, 54, 117, 96, 33}, + {76, 13, 55, 118, 97, 34}, + {77, 14, 56, 119, 98, 35}, + {78, 15, 57, 120, 99, 36}, + {79, 16, 58, 121, 100, 37}, + {80, 17, 59, 122, 101, 38}, + {81, 18, 60, 123, 102, 39}, + {82, 19, 61, 124, 103, 40}, + {83, 20, 62, 125, 104, 41}, + {84, 21, 63, 0, 105, 42}, + {85, 22, 64, 1, 106, 43}, + {86, 23, 65, 2, 107, 44}, + {87, 24, 66, 3, 108, 45}, + {88, 25, 67, 4, 109, 46}, + {89, 26, 68, 5, 110, 47}, + {90, 27, 69, 6, 111, 48}, + {91, 28, 70, 7, 112, 49}, + {92, 29, 71, 8, 113, 50}, + {93, 30, 72, 9, 114, 51}, + {94, 31, 73, 10, 115, 52}, + {95, 32, 74, 11, 116, 53}, + {96, 33, 75, 12, 117, 54}, + {97, 34, 76, 13, 118, 55}, + {98, 35, 77, 14, 119, 56}, + {99, 36, 78, 15, 120, 57}, + {100, 37, 79, 16, 121, 58}, + {101, 38, 80, 17, 122, 59}, + {102, 39, 81, 18, 123, 60}, + {103, 40, 82, 19, 124, 61}, + {104, 41, 83, 20, 125, 62}, + {105, 42, 84, 21, 0, 63}, + {106, 43, 85, 22, 1, 64}, + {107, 44, 86, 23, 2, 65}, + {108, 45, 87, 24, 3, 66}, + {109, 46, 88, 25, 4, 67}, + {110, 47, 89, 26, 5, 68}, + {111, 48, 90, 27, 6, 69}, + {112, 49, 91, 28, 7, 70}, + {113, 50, 92, 29, 8, 71}, + {114, 51, 93, 30, 9, 72}, + {115, 52, 94, 31, 10, 73}, + {116, 53, 95, 32, 11, 74}, + {117, 54, 96, 33, 12, 75}, + {118, 55, 97, 34, 13, 76}, + {119, 56, 98, 35, 14, 77}, + {120, 57, 99, 36, 15, 78}, + {121, 58, 100, 37, 16, 79}, + {122, 59, 101, 38, 17, 80}, + {123, 60, 102, 39, 18, 81}, + {124, 61, 103, 40, 19, 82}, + {125, 62, 104, 41, 20, 83} + }; + } /* namespace dtv */ } /* namespace gr */ diff --git a/gr-dtv/lib/dvbt/dvbt_bit_inner_deinterleaver_impl.h b/gr-dtv/lib/dvbt/dvbt_bit_inner_deinterleaver_impl.h index 9f3811301d..9d33f6124b 100644 --- a/gr-dtv/lib/dvbt/dvbt_bit_inner_deinterleaver_impl.h +++ b/gr-dtv/lib/dvbt/dvbt_bit_inner_deinterleaver_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,8 @@ namespace gr { private: const dvbt_configure config; + static const int d_lookup_H[126][6]; + int d_nsize; dvbt_hierarchy_t d_hierarchy; @@ -43,9 +45,6 @@ namespace gr { // Table to keep interleaved indices unsigned char * d_perm; - // Permutation function - int H(int e, int w); - public: dvbt_bit_inner_deinterleaver_impl(int nsize, dvb_constellation_t constellation, dvbt_hierarchy_t hierarchy, dvbt_transmission_mode_t transmission); ~dvbt_bit_inner_deinterleaver_impl(); diff --git a/gr-dtv/lib/dvbt/dvbt_bit_inner_interleaver_impl.cc b/gr-dtv/lib/dvbt/dvbt_bit_inner_interleaver_impl.cc index bfd9bde0ad..07ba588f3e 100644 --- a/gr-dtv/lib/dvbt/dvbt_bit_inner_interleaver_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_bit_inner_interleaver_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_bit_inner_interleaver_impl.h" -#include <stdio.h> #define MAX_MODULATION_ORDER 6 #define INTERLEAVER_BLOCK_SIZE 126 @@ -58,10 +57,10 @@ namespace gr { d_v = config.d_m; d_hierarchy = config.d_hierarchy; - d_perm = (unsigned char *)new unsigned char[d_v * d_bsize]; + d_perm = (unsigned char *)new (std::nothrow) unsigned char[d_v * d_bsize]; if (d_perm == NULL) { - std::cout << "Cannot allocate memory for d_perm" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "Bit Inner Interleaver, cannot allocate memory for d_perm."); + throw std::bad_alloc(); } //Init permutation table (used for b[e][do]) @@ -75,8 +74,8 @@ namespace gr { } if (d_nsize % d_bsize) { - std::cout << "Error: Input size must be multiple of block size: " \ - << "nsize: " << d_nsize << "bsize: " << d_bsize << std::endl; + GR_LOG_ERROR(d_logger, boost::format("Input size must be multiple of block size: nsize: %1% bsize: %2%") \ + % d_nsize % d_bsize); } } diff --git a/gr-dtv/lib/dvbt/dvbt_bit_inner_interleaver_impl.h b/gr-dtv/lib/dvbt/dvbt_bit_inner_interleaver_impl.h index 824fdb5016..5fc5e109f8 100644 --- a/gr-dtv/lib/dvbt/dvbt_bit_inner_interleaver_impl.h +++ b/gr-dtv/lib/dvbt/dvbt_bit_inner_interleaver_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/gr-dtv/lib/dvbt/dvbt_configure.cc b/gr-dtv/lib/dvbt/dvbt_configure.cc index acf9862e74..33f5cc838b 100644 --- a/gr-dtv/lib/dvbt/dvbt_configure.cc +++ b/gr-dtv/lib/dvbt/dvbt_configure.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_configure.h" #include <iostream> -#include <stdio.h> namespace gr { namespace dtv { diff --git a/gr-dtv/lib/dvbt/dvbt_demap_impl.cc b/gr-dtv/lib/dvbt/dvbt_demap_impl.cc index 4bdec1dc96..65d659226c 100644 --- a/gr-dtv/lib/dvbt/dvbt_demap_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_demap_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_demap_impl.h" #include <volk/volk.h> -#include <stdio.h> namespace gr { namespace dtv { @@ -62,15 +61,15 @@ namespace gr { d_constellation_points = (gr_complex*) volk_malloc(sizeof(gr_complex) * d_constellation_size, volk_get_alignment()); if (d_constellation_points == NULL) { - std::cout << "cannot allocate memory for d_constellation_points" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "DVB-T Demap, cannot allocate memory for d_constellation_points."); + throw std::bad_alloc(); } d_sq_dist = (float*) volk_malloc(sizeof(float) * d_constellation_size, volk_get_alignment()); if (d_sq_dist == NULL) { - std::cout << "cannot allocate memory for d_sq_dist" << std::endl; + GR_LOG_FATAL(d_logger, "DVB-T Demap, cannot allocate memory for d_sq_dist."); volk_free(d_constellation_points); - exit(1); + throw std::bad_alloc(); } make_constellation_points(d_constellation_size, d_step, d_alpha); diff --git a/gr-dtv/lib/dvbt/dvbt_energy_dispersal_impl.cc b/gr-dtv/lib/dvbt/dvbt_energy_dispersal_impl.cc index 03dd0ffec5..ff8042f2c8 100644 --- a/gr-dtv/lib/dvbt/dvbt_energy_dispersal_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_energy_dispersal_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_energy_dispersal_impl.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -121,7 +120,7 @@ namespace gr { for (int j = 0; j < d_npacks; j++) { if (in[index + count] != d_SYNC) { - printf("error: Malformed MPEG-TS!\n"); + GR_LOG_WARN(d_logger, "Malformed MPEG-TS!"); } out[count++] = sync; diff --git a/gr-dtv/lib/dvbt/dvbt_inner_coder_impl.cc b/gr-dtv/lib/dvbt/dvbt_inner_coder_impl.cc index 9d0c93c35c..0787464aa2 100644 --- a/gr-dtv/lib/dvbt/dvbt_inner_coder_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_inner_coder_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_inner_coder_impl.h" -#include <stdio.h> #include <assert.h> namespace gr { @@ -170,17 +169,17 @@ namespace gr { d_out_bs = 4 * d_n; // allocate bit buffers - d_in_buff = new unsigned char[8 * d_in_bs]; + d_in_buff = new (std::nothrow) unsigned char[8 * d_in_bs]; if (d_in_buff == NULL) { - std::cout << "Cannot allocate memory for d_in_buff" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "Inner Coder, cannot allocate memory for d_in_buff."); + throw std::bad_alloc(); } - d_out_buff = new unsigned char[8 * d_in_bs * d_n / d_k]; + d_out_buff = new (std::nothrow) unsigned char[8 * d_in_bs * d_n / d_k]; if (d_out_buff == NULL) { - std::cout << "Cannot allocate memory for d_out_buff" << std::endl; + GR_LOG_FATAL(d_logger, "Inner Coder, cannot allocate memory for d_out_buff."); delete [] d_in_buff; - exit(1); + throw std::bad_alloc(); } } diff --git a/gr-dtv/lib/dvbt/dvbt_inner_coder_impl.h b/gr-dtv/lib/dvbt/dvbt_inner_coder_impl.h index 56ce828be1..d472b1f60c 100644 --- a/gr-dtv/lib/dvbt/dvbt_inner_coder_impl.h +++ b/gr-dtv/lib/dvbt/dvbt_inner_coder_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/gr-dtv/lib/dvbt/dvbt_map_impl.cc b/gr-dtv/lib/dvbt/dvbt_map_impl.cc index 05f6e7f69b..b2c21da525 100644 --- a/gr-dtv/lib/dvbt/dvbt_map_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_map_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include <gnuradio/io_signature.h> #include <complex> #include "dvbt_map_impl.h" -#include <stdio.h> #include <math.h> namespace gr { @@ -59,10 +58,10 @@ namespace gr { d_alpha = config.d_alpha; d_gain = gain * config.d_norm; - d_constellation_points = new gr_complex[d_constellation_size]; + d_constellation_points = new (std::nothrow) gr_complex[d_constellation_size]; if (d_constellation_points == NULL) { - std::cout << "Cannot allocate memory for d_constellation_points" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "DVB-T Map, cannot allocate memory for d_constellation_points."); + throw std::bad_alloc(); } make_constellation_points(d_constellation_size, d_step, d_alpha); diff --git a/gr-dtv/lib/dvbt/dvbt_ofdm_sym_acquisition_impl.cc b/gr-dtv/lib/dvbt/dvbt_ofdm_sym_acquisition_impl.cc index ee8dce0f15..135d622eef 100644 --- a/gr-dtv/lib/dvbt/dvbt_ofdm_sym_acquisition_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_ofdm_sym_acquisition_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,7 +27,6 @@ #include <complex> #include <gnuradio/math.h> #include <gnuradio/expj.h> -#include <stdio.h> #include <volk/volk.h> namespace gr { @@ -247,53 +246,53 @@ namespace gr { d_gamma = (gr_complex*) volk_malloc(sizeof(gr_complex) * d_fft_length, volk_get_alignment()); if (d_gamma == NULL) { - std::cout << "cannot allocate memory for d_gamma" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "OFDM Symbol Acquisition, cannot allocate memory for d_gamma."); + throw std::bad_alloc(); } d_lambda = (float*) volk_malloc(sizeof(float) * d_fft_length, volk_get_alignment()); if (d_lambda == NULL) { - std::cout << "cannot allocate memory for d_lambda" << std::endl; + GR_LOG_FATAL(d_logger, "OFDM Symbol Acquisition, cannot allocate memory for d_lambda."); volk_free(d_gamma); - exit(1); + throw std::bad_alloc(); } d_derot = (gr_complex*) volk_malloc(sizeof(gr_complex) * (d_fft_length + d_cp_length), volk_get_alignment()); if (d_derot == NULL) { - std::cout << "cannot allocate memory for d_derot" << std::endl; + GR_LOG_FATAL(d_logger, "OFDM Symbol Acquisition, cannot allocate memory for d_derot."); volk_free(d_lambda); volk_free(d_gamma); - exit(1); + throw std::bad_alloc(); } d_conj = (gr_complex*) volk_malloc(sizeof(gr_complex) * (2 * d_fft_length + d_cp_length), volk_get_alignment()); if (d_conj == NULL) { - std::cout << "cannot allocate memory for d_conj" << std::endl; + GR_LOG_FATAL(d_logger, "OFDM Symbol Acquisition, cannot allocate memory for d_conj."); volk_free(d_derot); volk_free(d_lambda); volk_free(d_gamma); - exit(1); + throw std::bad_alloc(); } d_norm = (float*) volk_malloc(sizeof(float) * (2 * d_fft_length + d_cp_length), volk_get_alignment()); if (d_norm == NULL) { - std::cout << "cannot allocate memory for d_norm" << std::endl; + GR_LOG_FATAL(d_logger, "OFDM Symbol Acquisition, cannot allocate memory for d_norm."); volk_free(d_conj); volk_free(d_derot); volk_free(d_lambda); volk_free(d_gamma); - exit(1); + throw std::bad_alloc(); } d_corr = (gr_complex*) volk_malloc(sizeof(gr_complex) * (2 * d_fft_length + d_cp_length), volk_get_alignment()); if (d_corr == NULL) { - std::cout << "cannot allocate memory for d_corr" << std::endl; + GR_LOG_FATAL(d_logger, "OFDM Symbol Acquisition, cannot allocate memory for d_corr."); volk_free(d_norm); volk_free(d_conj); volk_free(d_derot); volk_free(d_lambda); volk_free(d_gamma); - exit(1); + throw std::bad_alloc(); } peak_detect_init(0.3, 0.9); diff --git a/gr-dtv/lib/dvbt/dvbt_reed_solomon_dec_impl.cc b/gr-dtv/lib/dvbt/dvbt_reed_solomon_dec_impl.cc index f2e370a51f..fd6fedcf8d 100644 --- a/gr-dtv/lib/dvbt/dvbt_reed_solomon_dec_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_reed_solomon_dec_impl.cc @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_reed_solomon_dec_impl.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -52,8 +51,8 @@ namespace gr { { d_rs = init_rs_char(rs_init_symsize, gfpoly, rs_init_fcr, rs_init_prim, (n - k)); if (d_rs == NULL) { - fprintf(stderr, "Reed-Solomon decoder, Out of memory.\n"); - exit(1); + GR_LOG_FATAL(d_logger, "Reed-Solomon Decoder, cannot allocate memory for d_rs."); + throw std::bad_alloc(); } d_nerrors_corrected_count = 0; d_bad_packet_count = 0; diff --git a/gr-dtv/lib/dvbt/dvbt_reed_solomon_enc_impl.cc b/gr-dtv/lib/dvbt/dvbt_reed_solomon_enc_impl.cc index 3bc186055d..663301d614 100644 --- a/gr-dtv/lib/dvbt/dvbt_reed_solomon_enc_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_reed_solomon_enc_impl.cc @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_reed_solomon_enc_impl.h" -#include <stdio.h> #define MPEG_TS_PKT_LENGTH 188 @@ -53,14 +52,14 @@ namespace gr { { d_rs = init_rs_char(rs_init_symsize, gfpoly, rs_init_fcr, rs_init_prim, (n - k)); if (d_rs == NULL) { - fprintf(stderr, "Reed-Solomon encoder, Out of memory.\n"); - exit(1); + GR_LOG_FATAL(d_logger, "Reed-Solomon Encoder, cannot allocate memory for d_rs."); + throw std::bad_alloc(); } d_data = (unsigned char *) malloc(sizeof(unsigned char) * (d_s + MPEG_TS_PKT_LENGTH)); if (d_data == NULL) { - fprintf(stderr, "Reed-Solomon encoder, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Reed-Solomon Encoder, cannot allocate memory for d_data."); free_rs_char(d_rs); - exit(1); + throw std::bad_alloc(); } } diff --git a/gr-dtv/lib/dvbt/dvbt_reference_signals_impl.cc b/gr-dtv/lib/dvbt/dvbt_reference_signals_impl.cc index b3c7046ae2..ba2521404a 100644 --- a/gr-dtv/lib/dvbt/dvbt_reference_signals_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_reference_signals_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_reference_signals_impl.h" #include <complex> -#include <stdio.h> #include <gnuradio/expj.h> #include <gnuradio/math.h> @@ -173,37 +172,37 @@ namespace gr { //allocate PRBS buffer d_wk = new char[d_Kmax - d_Kmin + 1]; if (d_wk == NULL) { - std::cout << "Cannot allocate memory for d_wk" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_wk."); + throw std::bad_alloc(); } // Generate wk sequence generate_prbs(); // allocate buffer for scattered pilots - d_spilot_carriers_val = new gr_complex[d_Kmax - d_Kmin + 1]; + d_spilot_carriers_val = new (std::nothrow) gr_complex[d_Kmax - d_Kmin + 1]; if (d_spilot_carriers_val == NULL) { - std::cout << "Cannot allocate memory for d_spilot_carriers_val" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_spilot_carriers_val."); delete [] d_wk; - exit(1); + throw std::bad_alloc(); } // allocate buffer for channel gains (for each useful carrier) - d_channel_gain = new gr_complex[d_Kmax - d_Kmin + 1]; + d_channel_gain = new (std::nothrow) gr_complex[d_Kmax - d_Kmin + 1]; if (d_channel_gain == NULL) { - std::cout << "Cannot allocate memory for d_channel_gain" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_channel_gain."); delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } // Allocate buffer for continual pilots phase diffs - d_known_phase_diff = new float[d_cpilot_carriers_size - 1]; + d_known_phase_diff = new (std::nothrow) float[d_cpilot_carriers_size - 1]; if (d_known_phase_diff == NULL) { - std::cout << "Cannot allocate memory for d_known_phase_diff" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_known_phase_diff."); delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } // Obtain phase diff for all continual pilots @@ -212,45 +211,45 @@ namespace gr { norm(get_cpilot_value(d_cpilot_carriers[i + 1]) - get_cpilot_value(d_cpilot_carriers[i])); } - d_cpilot_phase_diff = new float[d_cpilot_carriers_size - 1]; + d_cpilot_phase_diff = new (std::nothrow) float[d_cpilot_carriers_size - 1]; if (d_cpilot_phase_diff == NULL) { - std::cout << "Cannot allocate memory for d_cpilot_phase_diff" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_cpilot_phase_diff."); delete [] d_known_phase_diff; delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } // Allocate buffer for derotated input symbol - d_derot_in = new gr_complex[d_fft_length]; + d_derot_in = new (std::nothrow) gr_complex[d_fft_length]; if (d_derot_in == NULL) { - std::cout << "Cannot allocate memory for d_derot_in" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_derot_in."); delete [] d_cpilot_phase_diff; delete [] d_known_phase_diff; delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } // allocate buffer for first tps symbol constellation - d_tps_carriers_val = new gr_complex[d_tps_carriers_size]; + d_tps_carriers_val = new (std::nothrow) gr_complex[d_tps_carriers_size]; if (d_tps_carriers_val == NULL) { - std::cout << "Cannot allocate memory for d_tps_carriers_val" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_tps_carriers_val."); delete [] d_derot_in; delete [] d_cpilot_phase_diff; delete [] d_known_phase_diff; delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } // allocate tps data buffer - d_tps_data = new unsigned char[d_symbols_per_frame]; + d_tps_data = new (std::nothrow) unsigned char[d_symbols_per_frame]; if (d_tps_data == NULL) { - std::cout << "Cannot allocate memory for d_tps_data" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_tps_data."); delete [] d_tps_carriers_val; delete [] d_derot_in; delete [] d_cpilot_phase_diff; @@ -258,12 +257,12 @@ namespace gr { delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } - d_prev_tps_symbol = new gr_complex[d_tps_carriers_size]; + d_prev_tps_symbol = new (std::nothrow) gr_complex[d_tps_carriers_size]; if (d_prev_tps_symbol == NULL) { - std::cout << "Cannot allocate memory for d_prev_tps_symbol" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_prev_tps_symbol."); delete [] d_tps_data; delete [] d_tps_carriers_val; delete [] d_derot_in; @@ -272,13 +271,13 @@ namespace gr { delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } memset(d_prev_tps_symbol, 0, d_tps_carriers_size * sizeof(gr_complex)); - d_tps_symbol = new gr_complex[d_tps_carriers_size]; + d_tps_symbol = new (std::nothrow) gr_complex[d_tps_carriers_size]; if (d_tps_symbol == NULL) { - std::cout << "Cannot allocate memory for d_tps_symbol" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_tps_symbol."); delete [] d_prev_tps_symbol; delete [] d_tps_data; delete [] d_tps_carriers_val; @@ -288,7 +287,7 @@ namespace gr { delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } memset(d_tps_symbol, 0, d_tps_carriers_size * sizeof(gr_complex)); @@ -304,9 +303,9 @@ namespace gr { } // Allocate buffer for channel estimation carriers - d_chanestim_carriers = new int[d_Kmax - d_Kmin + 1]; + d_chanestim_carriers = new (std::nothrow) int[d_Kmax - d_Kmin + 1]; if (d_chanestim_carriers == NULL) { - std::cout << "Cannot allocate memory for d_chanestim_carriers" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_chanestim_carriers."); delete [] d_tps_symbol; delete [] d_prev_tps_symbol; delete [] d_tps_data; @@ -317,13 +316,13 @@ namespace gr { delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } // Allocate buffer for payload carriers - d_payload_carriers = new int[d_Kmax - d_Kmin + 1]; + d_payload_carriers = new (std::nothrow) int[d_Kmax - d_Kmin + 1]; if (d_payload_carriers == NULL) { - std::cout << "Cannot allocate memory for d_payload_carriers" << std::endl; + GR_LOG_FATAL(d_logger, "Reference Signals, cannot allocate memory for d_payload_carriers."); delete [] d_chanestim_carriers; delete [] d_tps_symbol; delete [] d_prev_tps_symbol; @@ -335,7 +334,7 @@ namespace gr { delete [] d_channel_gain; delete [] d_spilot_carriers_val; delete [] d_wk; - exit(1); + throw std::bad_alloc(); } // Reset the pilot generator diff --git a/gr-dtv/lib/dvbt/dvbt_symbol_inner_interleaver_impl.cc b/gr-dtv/lib/dvbt/dvbt_symbol_inner_interleaver_impl.cc index 8bdfbf9776..1edd15a109 100644 --- a/gr-dtv/lib/dvbt/dvbt_symbol_inner_interleaver_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_symbol_inner_interleaver_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_symbol_inner_interleaver_impl.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -125,10 +124,10 @@ namespace gr { assert(d_payload_length == d_nsize); // Allocate memory for h vector - d_h = new int[d_fft_length]; + d_h = new (std::nothrow) int[d_fft_length]; if (d_h == NULL) { - std::cout << "Cannot allocate memory for d_h" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "Symbol Inner Interleaver, cannot allocate memory for d_h."); + throw std::bad_alloc(); } // Setup bit permutation vectors diff --git a/gr-dtv/lib/dvbt/dvbt_viterbi_decoder_impl.cc b/gr-dtv/lib/dvbt/dvbt_viterbi_decoder_impl.cc index 05554c55fa..d76016d41c 100644 --- a/gr-dtv/lib/dvbt/dvbt_viterbi_decoder_impl.cc +++ b/gr-dtv/lib/dvbt/dvbt_viterbi_decoder_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt_viterbi_decoder_impl.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -597,10 +596,10 @@ namespace gr { d_nout = d_nbits / 2 / 8; // Allocate the buffer for the bits - d_inbits = new unsigned char [d_nbits]; + d_inbits = new (std::nothrow) unsigned char [d_nbits]; if (d_inbits == NULL) { - std::cout << "Cannot allocate memory for d_inbits" << std::endl; - exit(1); + GR_LOG_FATAL(d_logger, "Viterbi Decoder, cannot allocate memory for d_inbits."); + throw std::bad_alloc(); } mettab[0][0] = 1; diff --git a/gr-dtv/lib/dvbt2/dvbt2_cellinterleaver_cc_impl.cc b/gr-dtv/lib/dvbt2/dvbt2_cellinterleaver_cc_impl.cc index feaf3e29f4..ad401feed3 100644 --- a/gr-dtv/lib/dvbt2/dvbt2_cellinterleaver_cc_impl.cc +++ b/gr-dtv/lib/dvbt2/dvbt2_cellinterleaver_cc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt2_cellinterleaver_cc_impl.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -175,14 +174,14 @@ namespace gr { } time_interleave = (gr_complex *) malloc(sizeof(gr_complex) * cell_size * fecblocks); if (time_interleave == NULL) { - fprintf(stderr, "Cell interleaver 1st malloc, Out of memory.\n"); - exit(1); + GR_LOG_FATAL(d_logger, "Cell/Time Interleaver, cannot allocate memory for time_interleave."); + throw std::bad_alloc(); } cols = (gr_complex **) malloc(sizeof(gr_complex *) * FECBlocksPerBigTIBlock * 5); if (cols == NULL) { free(time_interleave); - fprintf(stderr, "Cell interleaver 2nd malloc, Out of memory.\n"); - exit(1); + GR_LOG_FATAL(d_logger, "Cell/Time Interleaver, cannot allocate memory for cols."); + throw std::bad_alloc(); } ti_blocks = tiblocks; fec_blocks = fecblocks; diff --git a/gr-dtv/lib/dvbt2/dvbt2_framemapper_cc_impl.cc b/gr-dtv/lib/dvbt2/dvbt2_framemapper_cc_impl.cc index 5e47faca10..1755fc82ca 100644 --- a/gr-dtv/lib/dvbt2/dvbt2_framemapper_cc_impl.cc +++ b/gr-dtv/lib/dvbt2/dvbt2_framemapper_cc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include <gnuradio/io_signature.h> #include "dvbt2_framemapper_cc_impl.h" -#include <stdio.h> namespace gr { namespace dtv { @@ -910,33 +909,33 @@ namespace gr { set_output_multiple((N_P2 * C_P2) + (numdatasyms * C_DATA)); mapped_items = (N_P2 * C_P2) + (numdatasyms * C_DATA); if (mapped_items < (stream_items + 1840 + (N_post / eta_mod) + (N_FC - C_FC))) { - fprintf(stderr, "Too many FEC blocks in T2 frame.\n"); + GR_LOG_WARN(d_logger, "Frame Mapper, too many FEC blocks in T2 frame."); mapped_items = stream_items + 1840 + (N_post / eta_mod) + (N_FC - C_FC); /* avoid segfault */ } zigzag_interleave = (gr_complex *) malloc(sizeof(gr_complex) * mapped_items); if (zigzag_interleave == NULL) { - fprintf(stderr, "Frame mapper 1st malloc, Out of memory.\n"); - exit(1); + GR_LOG_FATAL(d_logger, "Frame Mapper, cannot allocate memory for zigzag_interleave."); + throw std::bad_alloc(); } } else { set_output_multiple((N_P2 * C_P2) + ((numdatasyms - 1) * C_DATA) + N_FC); mapped_items = (N_P2 * C_P2) + ((numdatasyms - 1) * C_DATA) + N_FC; if (mapped_items < (stream_items + 1840 + (N_post / eta_mod) + (N_FC - C_FC))) { - fprintf(stderr, "Too many FEC blocks in T2 frame.\n"); + GR_LOG_WARN(d_logger, "Frame Mapper, too many FEC blocks in T2 frame."); mapped_items = stream_items + 1840 + (N_post / eta_mod) + (N_FC - C_FC); /* avoid segfault */ } zigzag_interleave = (gr_complex *) malloc(sizeof(gr_complex) * mapped_items); if (zigzag_interleave == NULL) { - fprintf(stderr, "Frame mapper 1st malloc, Out of memory.\n"); - exit(1); + GR_LOG_FATAL(d_logger, "Frame Mapper, cannot allocate memory for zigzag_interleave."); + throw std::bad_alloc(); } } dummy_randomize = (gr_complex *) malloc(sizeof(gr_complex) * mapped_items - stream_items - 1840 - (N_post / eta_mod) - (N_FC - C_FC)); if (dummy_randomize == NULL) { free(zigzag_interleave); - fprintf(stderr, "Frame mapper 2nd malloc, Out of memory.\n"); - exit(1); + GR_LOG_FATAL(d_logger, "Frame Mapper, cannot allocate memory for dummy_randomize."); + throw std::bad_alloc(); } init_dummy_randomizer(); init_l1_randomizer(); diff --git a/gr-dtv/lib/dvbt2/dvbt2_paprtr_cc_impl.cc b/gr-dtv/lib/dvbt2/dvbt2_paprtr_cc_impl.cc index fc091bd70d..cec39a7041 100644 --- a/gr-dtv/lib/dvbt2/dvbt2_paprtr_cc_impl.cc +++ b/gr-dtv/lib/dvbt2/dvbt2_paprtr_cc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include <gnuradio/io_signature.h> #include "dvbt2_paprtr_cc_impl.h" #include <volk/volk.h> -#include <stdio.h> namespace gr { namespace dtv { @@ -518,61 +517,65 @@ namespace gr { left_nulls = ((vlength - C_PS) / 2) + 1; right_nulls = (vlength - C_PS) / 2; papr_fft_size = vlength; - papr_fft = new fft::fft_complex(papr_fft_size, false, 1); + papr_fft = new (std::nothrow) fft::fft_complex(papr_fft_size, false, 1); + if (papr_fft == NULL) { + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for papr_fft."); + throw std::bad_alloc(); + } ones_freq = (gr_complex*) volk_malloc(sizeof(gr_complex) * papr_fft_size, volk_get_alignment()); if (ones_freq == NULL) { - fprintf(stderr, "Tone reservation PAPR 1st volk_malloc, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for ones_freq."); delete papr_fft; - exit(1); + throw std::bad_alloc(); } ones_time = (gr_complex*) volk_malloc(sizeof(gr_complex) * papr_fft_size, volk_get_alignment()); if (ones_time == NULL) { - fprintf(stderr, "Tone reservation PAPR 2nd volk_malloc, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for ones_time."); volk_free(ones_freq); delete papr_fft; - exit(1); + throw std::bad_alloc(); } c = (gr_complex*) volk_malloc(sizeof(gr_complex) * papr_fft_size, volk_get_alignment()); if (c == NULL) { - fprintf(stderr, "Tone reservation PAPR 3rd volk_malloc, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for c."); volk_free(ones_time); volk_free(ones_freq); delete papr_fft; - exit(1); + throw std::bad_alloc(); } ctemp = (gr_complex*) volk_malloc(sizeof(gr_complex) * papr_fft_size, volk_get_alignment()); if (ctemp == NULL) { - fprintf(stderr, "Tone reservation PAPR 4th volk_malloc, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for ctemp."); volk_free(c); volk_free(ones_time); volk_free(ones_freq); delete papr_fft; - exit(1); + throw std::bad_alloc(); } magnitude = (float*) volk_malloc(sizeof(float) * papr_fft_size, volk_get_alignment()); if (magnitude == NULL) { - fprintf(stderr, "Tone reservation PAPR 5th volk_malloc, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for magnitude."); volk_free(ctemp); volk_free(c); volk_free(ones_time); volk_free(ones_freq); delete papr_fft; - exit(1); + throw std::bad_alloc(); } r = (gr_complex*) volk_malloc(sizeof(gr_complex) * N_TR, volk_get_alignment()); if (r == NULL) { - fprintf(stderr, "Tone reservation PAPR 6th volk_malloc, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for r."); volk_free(magnitude); volk_free(ctemp); volk_free(c); volk_free(ones_time); volk_free(ones_freq); delete papr_fft; - exit(1); + throw std::bad_alloc(); } rNew = (gr_complex*) volk_malloc(sizeof(gr_complex) * N_TR, volk_get_alignment()); if (rNew == NULL) { - fprintf(stderr, "Tone reservation PAPR 7th volk_malloc, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for rNew."); volk_free(r); volk_free(magnitude); volk_free(ctemp); @@ -580,11 +583,11 @@ namespace gr { volk_free(ones_time); volk_free(ones_freq); delete papr_fft; - exit(1); + throw std::bad_alloc(); } v = (gr_complex*) volk_malloc(sizeof(gr_complex) * N_TR, volk_get_alignment()); if (v == NULL) { - fprintf(stderr, "Tone reservation PAPR 8th volk_malloc, Out of memory.\n"); + GR_LOG_FATAL(d_logger, "Tone Reservation PAPR, cannot allocate memory for v."); volk_free(rNew); volk_free(r); volk_free(magnitude); @@ -593,7 +596,7 @@ namespace gr { volk_free(ones_time); volk_free(ones_freq); delete papr_fft; - exit(1); + throw std::bad_alloc(); } num_symbols = numdatasyms + N_P2; set_output_multiple(num_symbols); diff --git a/gr-dtv/lib/dvbt2/dvbt2_pilotgenerator_cc_impl.cc b/gr-dtv/lib/dvbt2/dvbt2_pilotgenerator_cc_impl.cc index 26c83492b9..2bb19f5189 100644 --- a/gr-dtv/lib/dvbt2/dvbt2_pilotgenerator_cc_impl.cc +++ b/gr-dtv/lib/dvbt2/dvbt2_pilotgenerator_cc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2016 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1131,7 +1131,11 @@ namespace gr { } equalization_enable = equalization; ofdm_fft_size = vlength; - ofdm_fft = new fft::fft_complex(ofdm_fft_size, false, 1); + ofdm_fft = new (std::nothrow) fft::fft_complex(ofdm_fft_size, false, 1); + if (ofdm_fft == NULL) { + GR_LOG_FATAL(d_logger, "Pilot Generator and IFFT, cannot allocate memory for ofdm_fft."); + throw std::bad_alloc(); + } num_symbols = numdatasyms + N_P2; set_output_multiple(num_symbols); } |