diff options
author | Marcus Müller <marcus.mueller@ettus.com> | 2015-08-09 21:50:58 +0200 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2016-03-28 14:33:37 -0700 |
commit | 9d559c1811f3e8272b978050a6c642e19325d137 (patch) | |
tree | 130abd7ed824b79496c606df5001194cbfbf2a21 /gr-uhd | |
parent | 7d2c8b16c3764207e9de1190bbfd7e051b8257e4 (diff) |
Backport UHD start/stop segfault fix
Check RX/TX streamers::sptr before flush/reset
Current code triggers a segfault when user uses the stream arg setter
before starting the flowgraph.
Another surprising use case that segfaults is
tb->start();
usrp_source->stop();
which is a clever way to allow streaming to start when the user calls
usrp_source->issue_stream_cmd(...) rather than as soon as GNU Radio runs
without using set_start_time (e.g. when the start time is unknown at FG
initialization).
Diffstat (limited to 'gr-uhd')
-rw-r--r-- | gr-uhd/lib/usrp_sink_impl.cc | 6 | ||||
-rw-r--r-- | gr-uhd/lib/usrp_source_impl.cc | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/gr-uhd/lib/usrp_sink_impl.cc b/gr-uhd/lib/usrp_sink_impl.cc index 64d25bde30..666f09cbf5 100644 --- a/gr-uhd/lib/usrp_sink_impl.cc +++ b/gr-uhd/lib/usrp_sink_impl.cc @@ -321,7 +321,8 @@ namespace gr { { _update_stream_args(stream_args); #ifdef GR_UHD_USE_STREAM_API - _tx_stream.reset(); + if(_tx_stream) + _tx_stream.reset(); #else throw std::runtime_error("not implemented in this version"); #endif @@ -609,7 +610,8 @@ namespace gr { _nitems_to_send = 0; #ifdef GR_UHD_USE_STREAM_API - _tx_stream->send(gr_vector_const_void_star(_nchan), 0, _metadata, 1.0); + if(_tx_stream) + _tx_stream->send(gr_vector_const_void_star(_nchan), 0, _metadata, 1.0); #else _dev->get_device()->send (gr_vector_const_void_star(_nchan), 0, _metadata, diff --git a/gr-uhd/lib/usrp_source_impl.cc b/gr-uhd/lib/usrp_source_impl.cc index e174e11334..eeb9521a5a 100644 --- a/gr-uhd/lib/usrp_source_impl.cc +++ b/gr-uhd/lib/usrp_source_impl.cc @@ -348,7 +348,8 @@ namespace gr { { _update_stream_args(stream_args); #ifdef GR_UHD_USE_STREAM_API - _rx_stream.reset(); + if(_rx_stream) + _rx_stream.reset(); #else throw std::runtime_error("not implemented in this version"); #endif @@ -409,7 +410,12 @@ namespace gr { while(true) { #ifdef GR_UHD_USE_STREAM_API const size_t bpi = ::uhd::convert::get_bytes_per_item(_stream_args.cpu_format); - _rx_stream->recv(outputs, nbytes/bpi, _metadata, 0.0); + if(_rx_stream) + // get the remaining samples out of the buffers + _rx_stream->recv(outputs, nbytes/bpi, _metadata, 0.0); + else + // no rx streamer -- nothing to flush + break; #else _dev->get_device()->recv (outputs, nbytes/_type->size, _metadata, *_type, |