Commit f6245e2e authored by DreamSourceLab's avatar DreamSourceLab
Browse files

Improve memory alloc and free for capture session

parent 1b6f16bf
......@@ -369,7 +369,7 @@ QScrollBar:horizontal
QScrollBar::handle:horizontal
{
background-color: #605F5F;
min-width: 5px;
min-width: 15px;
border-radius: 4px;
}
......@@ -435,7 +435,7 @@ QScrollBar:vertical
QScrollBar::handle:vertical
{
background-color: #605F5F;
min-height: 5px;
min-height: 15px;
border-radius: 4px;
}
......
......@@ -24,6 +24,8 @@
#include "analog.h"
#include "analogsnapshot.h"
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
......@@ -47,7 +49,9 @@ deque< boost::shared_ptr<AnalogSnapshot> >& Analog::get_snapshots()
void Analog::clear()
{
_snapshots.clear();
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<AnalogSnapshot> s, _snapshots)
s->clear();
}
} // namespace data
......
......@@ -46,13 +46,10 @@ const float AnalogSnapshot::LogEnvelopeScaleFactor =
logf(EnvelopeScaleFactor);
const uint64_t AnalogSnapshot::EnvelopeDataUnit = 64*1024; // bytes
AnalogSnapshot::AnalogSnapshot(const sr_datafeed_analog &analog, uint64_t _total_sample_len, unsigned int channel_num) :
Snapshot(sizeof(uint16_t)*channel_num, _total_sample_len, channel_num)
AnalogSnapshot::AnalogSnapshot() :
Snapshot(sizeof(uint16_t), 1, 1)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
memset(_envelope_levels, 0, sizeof(_envelope_levels));
init(_total_sample_len * channel_num);
append_payload(analog);
}
AnalogSnapshot::~AnalogSnapshot()
......@@ -62,6 +59,24 @@ AnalogSnapshot::~AnalogSnapshot()
free(e.samples);
}
void AnalogSnapshot::clear()
{
_sample_count = 0;
_ring_sample_count = 0;
}
void AnalogSnapshot::first_payload(const sr_datafeed_analog &analog, uint64_t total_sample_count, unsigned int channel_num)
{
_total_sample_count = total_sample_count;
_channel_num = channel_num;
_unit_size = sizeof(uint16_t)*channel_num;
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
if (init(_total_sample_count*_channel_num) == SR_OK) {
append_payload(analog);
_last_ended = false;
}
}
void AnalogSnapshot::append_payload(
const sr_datafeed_analog &analog)
{
......@@ -89,7 +104,7 @@ const uint16_t* AnalogSnapshot::get_samples(
// memcpy(data, (uint16_t*)_data + start_sample, sizeof(uint16_t) *
// (end_sample - start_sample));
// return data;
return (uint16_t*)_data + start_sample * _channel_num;
return (uint16_t*)_data.data() + start_sample * _channel_num;
}
void AnalogSnapshot::get_envelope_section(EnvelopeSection &s,
......@@ -154,7 +169,7 @@ void AnalogSnapshot::append_payload_to_envelope_levels()
dest_ptr = e0.samples + prev_length;
// Iterate through the samples to populate the first level mipmap
const uint16_t *const stop_src_ptr = (uint16_t*)_data +
const uint16_t *const stop_src_ptr = (uint16_t*)_data.data() +
e0.length * EnvelopeScaleFactor * _channel_num;
// for (const uint16_t *src_ptr = (uint16_t*)_data +
// prev_length * EnvelopeScaleFactor;
......@@ -167,7 +182,7 @@ void AnalogSnapshot::append_payload_to_envelope_levels()
// *dest_ptr++ = sub_sample;
// }
for (const uint16_t *src_ptr = (uint16_t*)_data +
for (const uint16_t *src_ptr = (uint16_t*)_data.data() +
prev_length * EnvelopeScaleFactor * _channel_num + i;
src_ptr < stop_src_ptr; src_ptr += EnvelopeScaleFactor * _channel_num)
{
......
......@@ -69,10 +69,14 @@ private:
static const uint64_t EnvelopeDataUnit;
public:
AnalogSnapshot(const sr_datafeed_analog &analog, uint64_t _total_sample_len, unsigned int channel_num);
AnalogSnapshot();
virtual ~AnalogSnapshot();
void clear();
void first_payload(const sr_datafeed_analog &analog, uint64_t total_sample_count, unsigned int channel_num);
void append_payload(const sr_datafeed_analog &analog);
const uint16_t* get_samples(int64_t start_sample,
......
......@@ -56,8 +56,8 @@ namespace data {
const double DecoderStack::DecodeMargin = 1.0;
const double DecoderStack::DecodeThreshold = 0.2;
const int64_t DecoderStack::DecodeChunkLength = 1024 * 1024;
const unsigned int DecoderStack::DecodeNotifyPeriod = 1;
const int64_t DecoderStack::DecodeChunkLength = 4 * 1024;
const unsigned int DecoderStack::DecodeNotifyPeriod = 1024;
mutex DecoderStack::_global_decode_mutex;
......@@ -332,7 +332,7 @@ void DecoderStack::clear()
_sample_count = 0;
_frame_complete = false;
_samples_decoded = 0;
//new_decode_data();
new_decode_data();
_error_message = QString();
for (map<const Row, RowData>::const_iterator i = _rows.begin();
i != _rows.end(); i++)
......@@ -342,7 +342,7 @@ void DecoderStack::clear()
void DecoderStack::stop_decode()
{
_snapshot.reset();
//_snapshot.reset();
if(_decode_state == Stopped) {
clear();
......@@ -397,12 +397,14 @@ void DecoderStack::begin_decode()
if (snapshots.empty())
return;
_snapshot = snapshots.front();
if (_snapshot->empty())
return;
// Get the samplerate and start time
_start_time = data->get_start_time();
_samplerate = data->samplerate();
if (_samplerate == 0.0)
_samplerate = 1.0;
if (_samplerate == 0.0)
return;
//_decode_thread = boost::thread(&DecoderStack::decode_proc, this);
_decode_thread.reset(new boost::thread(&DecoderStack::decode_proc, this));
......@@ -437,7 +439,8 @@ void DecoderStack::decode_data(
const unsigned int unit_size, srd_session *const session)
{
uint8_t *chunk = NULL;
uint64_t last_cnt = 0;
uint64_t notify_cnt = (decode_end - decode_start + 1)/100;
const uint64_t chunk_sample_count =
DecodeChunkLength / _snapshot->unit_size();
......@@ -463,8 +466,10 @@ void DecoderStack::decode_data(
_samples_decoded = chunk_end - decode_start + 1;
}
if (i % DecodeNotifyPeriod == 0)
if ((i - last_cnt) > notify_cnt) {
last_cnt = i;
new_decode_data();
}
}
_options_changed = false;
......@@ -492,6 +497,12 @@ void DecoderStack::decode_proc()
// Create the decoders
const unsigned int unit_size = _snapshot->unit_size();
// Get the intial sample count
{
unique_lock<mutex> input_lock(_input_mutex);
sample_count = _sample_count = _snapshot->get_sample_count();
}
BOOST_FOREACH(const shared_ptr<decode::Decoder> &dec, _stack)
{
srd_decoder_inst *const di = dec->create_decoder_inst(session, unit_size);
......@@ -508,13 +519,7 @@ void DecoderStack::decode_proc()
prev_di = di;
decode_start = dec->decode_start();
decode_end = min(dec->decode_end(), _snapshot->get_sample_count());
}
// Get the intial sample count
{
unique_lock<mutex> input_lock(_input_mutex);
sample_count = _sample_count = _snapshot->get_sample_count();
decode_end = min(dec->decode_end(), _sample_count-1);
}
// Start the session
......
......@@ -23,6 +23,8 @@
#include "dso.h"
#include "dsosnapshot.h"
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
......@@ -46,7 +48,9 @@ deque< boost::shared_ptr<DsoSnapshot> >& Dso::get_snapshots()
void Dso::clear()
{
_snapshots.clear();
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<DsoSnapshot> s, _snapshots)
s->clear();
}
} // namespace data
......
......@@ -47,16 +47,13 @@ const uint64_t DsoSnapshot::EnvelopeDataUnit = 4*1024; // bytes
const int DsoSnapshot::VrmsScaleFactor = 1 << 8;
DsoSnapshot::DsoSnapshot(const sr_datafeed_dso &dso, uint64_t _total_sample_len, unsigned int channel_num, bool instant) :
Snapshot(sizeof(uint16_t), _total_sample_len, channel_num),
DsoSnapshot::DsoSnapshot() :
Snapshot(sizeof(uint16_t), 1, 1),
_envelope_en(false),
_envelope_done(false),
_instant(instant)
_instant(false)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
memset(_envelope_levels, 0, sizeof(_envelope_levels));
init(_total_sample_len);
append_payload(dso);
}
DsoSnapshot::~DsoSnapshot()
......@@ -66,6 +63,24 @@ DsoSnapshot::~DsoSnapshot()
free(e.samples);
}
void DsoSnapshot::clear()
{
_sample_count = 0;
_ring_sample_count = 0;
}
void DsoSnapshot::first_payload(const sr_datafeed_dso &dso, uint64_t total_sample_count, unsigned int channel_num, bool instant)
{
_total_sample_count = total_sample_count;
_channel_num = channel_num;
_instant = instant;
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
if (init(_total_sample_count) == SR_OK) {
append_payload(dso);
_last_ended = false;
}
}
void DsoSnapshot::append_payload(const sr_datafeed_dso &dso)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
......@@ -103,7 +118,7 @@ const uint8_t *DsoSnapshot::get_samples(
// memcpy(data, (uint16_t*)_data + start_sample, sizeof(uint16_t) *
// (end_sample - start_sample));
// return data;
return (uint8_t*)_data + start_sample * _channel_num + index * (_channel_num != 1);
return (uint8_t*)_data.data() + start_sample * _channel_num + index * (_channel_num != 1);
}
void DsoSnapshot::get_envelope_section(EnvelopeSection &s,
......@@ -170,9 +185,9 @@ void DsoSnapshot::append_payload_to_envelope_levels(bool header)
dest_ptr = e0.samples + prev_length;
// Iterate through the samples to populate the first level mipmap
const uint8_t *const stop_src_ptr = (uint8_t*)_data +
const uint8_t *const stop_src_ptr = (uint8_t*)_data.data() +
e0.length * EnvelopeScaleFactor * _channel_num;
for (const uint8_t *src_ptr = (uint8_t*)_data +
for (const uint8_t *src_ptr = (uint8_t*)_data.data() +
prev_length * EnvelopeScaleFactor * _channel_num + i;
src_ptr < stop_src_ptr; src_ptr += EnvelopeScaleFactor * _channel_num)
{
......@@ -248,9 +263,9 @@ double DsoSnapshot::cal_vrms(double zero_off, int index) const
double tmp;
// Iterate through the samples to populate the first level mipmap
const uint8_t *const stop_src_ptr = (uint8_t*)_data +
const uint8_t *const stop_src_ptr = (uint8_t*)_data.data() +
_sample_count * _channel_num;
for (const uint8_t *src_ptr = (uint8_t*)_data + index;
for (const uint8_t *src_ptr = (uint8_t*)_data.data() + index;
src_ptr < stop_src_ptr; src_ptr += VrmsScaleFactor * _channel_num)
{
const uint8_t * begin_src_ptr =
......@@ -282,9 +297,9 @@ double DsoSnapshot::cal_vmean(int index) const
double vmean = 0;
// Iterate through the samples to populate the first level mipmap
const uint8_t *const stop_src_ptr = (uint8_t*)_data +
const uint8_t *const stop_src_ptr = (uint8_t*)_data.data() +
_sample_count * _channel_num;
for (const uint8_t *src_ptr = (uint8_t*)_data + index;
for (const uint8_t *src_ptr = (uint8_t*)_data.data() + index;
src_ptr < stop_src_ptr; src_ptr += VrmsScaleFactor * _channel_num)
{
const uint8_t * begin_src_ptr =
......
......@@ -70,10 +70,14 @@ private:
static const int VrmsScaleFactor;
public:
DsoSnapshot(const sr_datafeed_dso &dso, uint64_t _total_sample_len, unsigned int channel_num, bool instant);
DsoSnapshot();
virtual ~DsoSnapshot();
void clear();
void first_payload(const sr_datafeed_dso &dso, uint64_t total_sample_count, unsigned int channel_num, bool instant);
void append_payload(const sr_datafeed_dso &dso);
const uint8_t* get_samples(int64_t start_sample,
......
......@@ -98,7 +98,7 @@ private:
private:
struct Envelope _envelope_levels[ScaleStepCount];
mutable boost::recursive_mutex _mutex;
void *_data;
const void *_data;
uint64_t _sample_count;
int _unit_size;
boost::shared_ptr<view::Signal> _signal;
......
......@@ -24,6 +24,8 @@
#include "logic.h"
#include "logicsnapshot.h"
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
......@@ -48,7 +50,9 @@ deque< boost::shared_ptr<LogicSnapshot> >& Logic::get_snapshots()
void Logic::clear()
{
_snapshots.clear();
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<LogicSnapshot> s, _snapshots)
s->clear();
}
} // namespace data
......
......@@ -43,21 +43,37 @@ const int LogicSnapshot::MipMapScaleFactor = 1 << MipMapScalePower;
const float LogicSnapshot::LogMipMapScaleFactor = logf(MipMapScaleFactor);
const uint64_t LogicSnapshot::MipMapDataUnit = 64*1024; // bytes
LogicSnapshot::LogicSnapshot(const sr_datafeed_logic &logic, uint64_t _total_sample_len, unsigned int channel_num) :
Snapshot(logic.unitsize, _total_sample_len, channel_num),
_last_append_sample(0)
LogicSnapshot::LogicSnapshot() :
Snapshot(1, 1, 1),
_last_append_sample(0)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
memset(_mip_map, 0, sizeof(_mip_map));
if (init(_total_sample_len * channel_num) == SR_OK)
append_payload(logic);
memset(_mip_map, 0, sizeof(_mip_map));
}
LogicSnapshot::~LogicSnapshot()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
BOOST_FOREACH(MipMapLevel &l, _mip_map)
free(l.data);
BOOST_FOREACH(MipMapLevel &l, _mip_map)
free(l.data);
}
void LogicSnapshot::clear()
{
_sample_count = 0;
_ring_sample_count = 0;
memset(_mip_map, 0, sizeof(_mip_map));
}
void LogicSnapshot::first_payload(const sr_datafeed_logic &logic, uint64_t total_sample_count, unsigned int channel_num)
{
_total_sample_count = total_sample_count;
_channel_num = channel_num;
_unit_size = logic.unitsize;
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
if (init(_total_sample_count * _channel_num) == SR_OK) {
append_payload(logic);
_last_ended = false;
}
}
void LogicSnapshot::append_payload(
......@@ -88,7 +104,7 @@ uint8_t * LogicSnapshot::get_samples(int64_t start_sample, int64_t end_sample) c
//const size_t size = (end_sample - start_sample) * _unit_size;
//memcpy(data, (const uint8_t*)_data + start_sample * _unit_size, size);
return (uint8_t*)_data + start_sample * _unit_size;
return (uint8_t*)_data.data() + start_sample * _unit_size;
}
void LogicSnapshot::reallocate_mipmap_level(MipMapLevel &m)
......@@ -127,9 +143,9 @@ void LogicSnapshot::append_payload_to_mipmap()
dest_ptr = (uint8_t*)m0.data + prev_length * _unit_size;
// Iterate through the samples to populate the first level mipmap
const uint8_t *const end_src_ptr = (uint8_t*)_data +
const uint8_t *const end_src_ptr = (uint8_t*)_data.data() +
m0.length * _unit_size * MipMapScaleFactor;
for (src_ptr = (uint8_t*)_data +
for (src_ptr = (uint8_t*)_data.data() +
prev_length * _unit_size * MipMapScaleFactor;
src_ptr < end_src_ptr;)
{
......@@ -201,7 +217,7 @@ void LogicSnapshot::get_subsampled_edges(
assert(sig_index >= 0);
assert(sig_index < 64);
if (!_data)
if (_data.size() == 0)
return;
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
......
......@@ -61,10 +61,14 @@ public:
typedef std::pair<uint64_t, bool> EdgePair;
public:
LogicSnapshot(const sr_datafeed_logic &logic, uint64_t _total_sample_len, unsigned int channel_num);
LogicSnapshot();
virtual ~LogicSnapshot();
void clear();
void first_payload(const sr_datafeed_logic &logic, uint64_t total_sample_count, unsigned int channel_num);
void append_payload(const sr_datafeed_logic &logic);
uint8_t * get_samples(int64_t start_sample, int64_t end_sample) const;
......
......@@ -56,7 +56,8 @@ MathStack::MathStack(pv::SigSession &session, int index) :
_index(index),
_dc_ignore(true),
_sample_interval(1),
_math_state(Init)
_math_state(Init),
_fft_plan(NULL)
{
}
......@@ -65,7 +66,8 @@ MathStack::~MathStack()
_xn.clear();
_xk.clear();
_power_spectrum.clear();
fftw_destroy_plan(_fft_plan);
if (_fft_plan)
fftw_destroy_plan(_fft_plan);
}
void MathStack::clear()
......
......@@ -33,12 +33,13 @@ namespace pv {
namespace data {
Snapshot::Snapshot(int unit_size, uint64_t total_sample_count, unsigned int channel_num) :
_data(NULL),
_channel_num(channel_num),
_sample_count(0),
_total_sample_count(total_sample_count),
_ring_sample_count(0),
_unit_size(unit_size)
_unit_size(unit_size),
_memory_failed(true),
_last_ended(true)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
assert(_unit_size > 0);
......@@ -47,41 +48,65 @@ Snapshot::Snapshot(int unit_size, uint64_t total_sample_count, unsigned int chan
Snapshot::~Snapshot()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
if (_data != NULL)
free(_data);
_data = NULL;
_data.clear();
}
int Snapshot::init(uint64_t _total_sample_len)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
_data = malloc(_total_sample_len * _unit_size +
sizeof(uint64_t));
// boost::lock_guard<boost::recursive_mutex> lock(_mutex);
// _data = malloc(_total_sample_len * _unit_size +
// sizeof(uint64_t));
// if (_data == NULL)
// return SR_ERR_MALLOC;
// else
// return SR_OK;
if (_data == NULL)
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
uint64_t size = _total_sample_len * _unit_size + sizeof(uint64_t);
try{
_data.resize(size);
} catch(...) {
_memory_failed = true;
return SR_ERR_MALLOC;
else
return SR_OK;
}
_memory_failed = false;
return SR_OK;
}
bool Snapshot::memory_failed() const
{
return _memory_failed;
}
bool Snapshot::buf_null() const
bool Snapshot::empty() const
{
if (_data == NULL)
if (_sample_count == 0 || _memory_failed)
return true;
else
return false;
}
bool Snapshot::last_ended() const
{
return _last_ended;
}
void Snapshot::set_last_ended(bool ended)
{
_last_ended = ended;
}
uint64_t Snapshot::get_sample_count() const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
return _sample_count;
}
void* Snapshot::get_data() const
const void* Snapshot::get_data() const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
return _data;
return _data.data();
}
int Snapshot::unit_size() const
......@@ -100,10 +125,10 @@ uint64_t Snapshot::get_sample(uint64_t index) const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
assert(_data);
assert(_data.data());
assert(index < _sample_count);
return *(uint64_t*)((uint8_t*)_data + index * _unit_size);
return *(uint64_t*)((uint8_t*)_data.data() + index * _unit_size);
}
void Snapshot::append_data(void *data, uint64_t samples)
......@@ -117,13 +142,13 @@ void Snapshot::append_data(void *data, uint64_t samples)
_sample_count = _total_sample_count;
if (_ring_sample_count + samples > _total_sample_count) {
memcpy((uint8_t*)_data + _ring_sample_count * _unit_size,
memcpy((uint8_t*)_data.data() + _ring_sample_count * _unit_size,
data, (_total_sample_count - _ring_sample_count) * _unit_size);
_ring_sample_count = (samples + _ring_sample_count - _total_sample_count) % _total_sample_count;
memcpy((uint8_t*)_data,
memcpy((uint8_t*)_data.data(),
data, _ring_sample_count * _unit_size);
} else {
memcpy((uint8_t*)_data + _ring_sample_count * _unit_size,
memcpy((uint8_t*)_data.data() + _ring_sample_count * _unit_size,
data, samples * _unit_size);
_ring_sample_count += samples;
}
......@@ -134,10 +159,10 @@ void Snapshot::refill_data(void *data, uint64_t samples, bool instant)
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
if (instant) {
memcpy((uint8_t*)_data + _sample_count * _channel_num, data, samples*_channel_num);
memcpy((uint8_t*)_data.data() + _sample_count * _channel_num, data, samples*_channel_num);
_sample_count = (_sample_count + samples) % (_total_sample_count + 1);
} else {
memcpy((uint8_t*)_data, data, samples*_channel_num);
memcpy((uint8_t*)_data.data(), data, samples*_channel_num);
_sample_count = samples;
}
......
......@@ -42,11 +42,15 @@ public:
uint64_t get_sample_count() const;
void * get_data() const;
const void * get_data() const;
int unit_size() const;
bool buf_null() const;
bool memory_failed() const;
bool empty() const;
bool last_ended() const;
void set_last_ended(bool ended);
unsigned int get_channel_num() const;
......@@ -58,12 +62,14 @@ protected:
protected:
mutable boost::recursive_mutex _mutex;
void *_data;
std::vector<uint8_t> _data;
unsigned int _channel_num;
uint64_t _sample_count;
uint64_t _total_sample_count;
uint64_t _ring_sample_count;
int _unit_size;
bool _memory_failed;
bool _last_ended;
};
} // namespace data
......
......@@ -166,14 +166,6 @@ int ProtocolDock::decoder_name_cmp(const void *a, const void *b)
((const srd_decoder*)b)->name);
}
void ProtocolDock::paintEvent(QPaintEvent *)
{
//QStyleOption opt;
//opt.init(this);
//QPainter p(this);
//style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
void ProtocolDock::add_protocol()
{
if (_session.get_device()->dev_inst()->mode != LOGIC) {
......@@ -228,7 +220,7 @@ void ProtocolDock::add_protocol()
// progress connection
const std::vector< boost::shared_ptr<pv::view::DecodeTrace> > decode_sigs(
_session.get_decode_signals());
//connect(decode_sigs.back().get(), SIGNAL(decoded_progress(int)), this, SLOT(decoded_progess(int)));
connect(decode_sigs.back().get(), SIGNAL(decoded_progress(int)), this, SLOT(decoded_progess(int)));
protocol_updated();
}
......@@ -363,6 +355,7 @@ void ProtocolDock::decoded_progess(int progress)
_progress_label_list.at(index)->setText(progress_str);
index++;
}
update_model();
}
void ProtocolDock::set_model()
......
......@@ -61,8 +61,6 @@ public:
ProtocolDock(QWidget *parent, SigSession &session);
~ProtocolDock();
void paintEvent(QPaintEvent *);
void del_all_protocol();
signals:
......
......@@ -487,6 +487,13 @@ void SigSession::start_capture(bool instant,
void SigSession::stop_capture()
{
_instant = false;
#ifdef ENABLE_DECODE
for (vector< boost::shared_ptr<view::DecodeTrace> >::iterator i =
_decode_traces.begin();
i != _decode_traces.end();
i++)
(*i)->decoder()->stop_decode();
#endif
if (get_capture_state() != Running)
return;
sr_session_stop();
......@@ -527,7 +534,7 @@ bool SigSession::get_instant()
return _instant;
}
void* SigSession::get_buf(int& unit_size, uint64_t &length)
const void* SigSession::get_buf(int& unit_size, uint64_t &length)
{
if (_dev_inst->dev_inst()->mode == LOGIC) {
const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots =
......@@ -597,12 +604,12 @@ void SigSession::sample_thread_proc(boost::shared_ptr<device::DevInst> dev_inst,
set_capture_state(Stopped);
// Confirm that SR_DF_END was received
assert(!_cur_logic_snapshot);
assert(!_cur_dso_snapshot);
assert(!_cur_analog_snapshot);
assert(_cur_logic_snapshot->last_ended());
assert(_cur_dso_snapshot->last_ended());
assert(_cur_analog_snapshot->last_ended());
}
void SigSession::update_data_header(const sr_dev_inst *const sdi)
void SigSession::feed_in_header(const sr_dev_inst *sdi)
{
GVariant *gvar;
int ret;
......@@ -631,15 +638,12 @@ void SigSession::update_data_header(const sr_dev_inst *const sdi)
// Set the sample rate of all SignalData
// Logic/Analog/Dso
set< boost::shared_ptr<data::SignalData> > data_set;
BOOST_FOREACH(const boost::shared_ptr<view::Signal> sig, _signals) {
assert(sig);
data_set.insert(sig->data());
}
BOOST_FOREACH(boost::shared_ptr<data::SignalData> data, data_set) {
assert(data);
data->set_samplerate(_cur_samplerate);
}
if (_logic_data)
_logic_data->set_samplerate(_cur_samplerate);
if (_analog_data)
_analog_data->set_samplerate(_cur_samplerate);
if (_dso_data)
_dso_data->set_samplerate(_cur_samplerate);
#ifdef ENABLE_DECODE
// DecoderStack
BOOST_FOREACH(const boost::shared_ptr<view::DecodeTrace> d, _decode_traces)
......@@ -658,19 +662,6 @@ void SigSession::update_data_header(const sr_dev_inst *const sdi)
_group_data->set_samplerate(_cur_samplerate);
}
void SigSession::feed_in_header(const sr_dev_inst *sdi)
{
#ifdef ENABLE_DECODE
for (vector< boost::shared_ptr<view::DecodeTrace> >::iterator i =
_decode_traces.begin();
i != _decode_traces.end();
i++)
(*i)->decoder()->stop_decode();
#endif
update_data_header(sdi);
//receive_data(0);
}
void SigSession::add_group()
{
std::list<int> probe_index_list;
......@@ -786,21 +777,36 @@ void SigSession::init_signals()
}
}
// Create snapshots
{
_cur_logic_snapshot.reset(new data::LogicSnapshot());
assert(_cur_logic_snapshot);
_cur_dso_snapshot.reset(new data::DsoSnapshot());
assert(_cur_dso_snapshot);
_cur_analog_snapshot.reset(new data::AnalogSnapshot());
assert(_cur_analog_snapshot);
}
// Create data containers for the coming data snapshots
{
if (logic_probe_count != 0) {
_logic_data.reset(new data::Logic());
assert(_logic_data);
_logic_data->push_snapshot(_cur_logic_snapshot);
}
if (dso_probe_count != 0) {
_dso_data.reset(new data::Dso());
assert(_dso_data);
_dso_data->push_snapshot(_cur_dso_snapshot);
}
if (analog_probe_count != 0) {
_analog_data.reset(new data::Analog());
assert(_analog_data);
_analog_data->push_snapshot(_cur_analog_snapshot);
}
_group_data.reset(new data::Group());
......@@ -914,7 +920,7 @@ void SigSession::refresh(int holdtime)
{
if (_logic_data) {
_logic_data->clear();
_cur_logic_snapshot.reset();
//_cur_logic_snapshot.reset();
#ifdef ENABLE_DECODE
BOOST_FOREACH(const boost::shared_ptr<view::DecodeTrace> d, _decode_traces)
{
......@@ -925,7 +931,8 @@ void SigSession::refresh(int holdtime)
}
if (_dso_data) {
_dso_data->clear();
_cur_dso_snapshot.reset();
//_cur_dso_snapshot.reset();
_cur_dso_snapshot->set_last_ended(true);
// MathStack
BOOST_FOREACH(const boost::shared_ptr<view::MathTrace> m, _math_traces)
{
......@@ -935,7 +942,7 @@ void SigSession::refresh(int holdtime)
}
if (_analog_data) {
_analog_data->clear();
_cur_analog_snapshot.reset();
//_cur_analog_snapshot.reset();
}
if (strncmp(_dev_inst->dev_inst()->driver->name, "virtual", 7)) {
_data_lock = true;
......@@ -997,8 +1004,7 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic)
{
boost::lock_guard<boost::mutex> lock(_data_mutex);
if (!_logic_data)
{
if (!_logic_data || !_cur_logic_snapshot) {
qDebug() << "Unexpected logic packet";
return;
}
......@@ -1007,29 +1013,20 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic)
test_data_error();
}
if (!_cur_logic_snapshot)
{
// Create a new data snapshot
_cur_logic_snapshot = boost::shared_ptr<data::LogicSnapshot>(
new data::LogicSnapshot(logic, _dev_inst->get_sample_limit(), 1));
if (_cur_logic_snapshot->buf_null())
{
if (_cur_logic_snapshot->last_ended()) {
_cur_logic_snapshot->first_payload(logic, _dev_inst->get_sample_limit(), 1);
if (_cur_logic_snapshot->memory_failed()) {
malloc_error();
return;
} else {
_logic_data->push_snapshot(_cur_logic_snapshot);
}
// @todo Putting this here means that only listeners querying
// for logic will be notified. Currently the only user of
// frame_began is DecoderStack, but in future we need to signal
// this after both analog and logic sweeps have begun.
frame_began();
} else if(!_cur_logic_snapshot->buf_null()) {
} else {
// Append to the existing data snapshot
_cur_logic_snapshot->append_payload(logic);
} else {
return;
}
emit receive_data(logic.length/logic.unitsize);
......@@ -1041,13 +1038,13 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso)
{
boost::lock_guard<boost::mutex> lock(_data_mutex);
if(!_dso_data)
if(!_dso_data || !_cur_dso_snapshot)
{
qDebug() << "Unexpected dso packet";
return; // This dso packet was not expected.
}
if (!_cur_dso_snapshot)
if (_cur_dso_snapshot->last_ended())
{
// reset scale of dso signal
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals)
......@@ -1058,24 +1055,17 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso)
dsoSig->set_scale(dsoSig->get_view_rect().height() / 256.0f);
}
// Create a new data snapshot
_cur_dso_snapshot = boost::shared_ptr<data::DsoSnapshot>(
new data::DsoSnapshot(dso, _dev_inst->get_sample_limit(), get_ch_num(SR_CHANNEL_DSO), _instant));
if (_cur_dso_snapshot->buf_null())
{
// first payload
_cur_dso_snapshot->first_payload(dso, _dev_inst->get_sample_limit(), get_ch_num(SR_CHANNEL_DSO), _instant);
if (_cur_dso_snapshot->memory_failed()) {
malloc_error();
return;
} else {
_dso_data->push_snapshot(_cur_dso_snapshot);
}
} else if(!_cur_dso_snapshot->buf_null()) {
} else {
// Append to the existing data snapshot
_cur_dso_snapshot->append_payload(dso);
} else {
return;
}
// reset scale of dso signal
// calculate related math results
BOOST_FOREACH(const boost::shared_ptr<view::MathTrace> m, _math_traces)
{
assert(m);
......@@ -1085,36 +1075,29 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso)
receive_data(dso.num_samples);
data_updated();
//if (!_instant)
// start_timer(ViewTime);
}
void SigSession::feed_in_analog(const sr_datafeed_analog &analog)
{
boost::lock_guard<boost::mutex> lock(_data_mutex);
if(!_analog_data)
if(!_analog_data || !_cur_analog_snapshot)
{
qDebug() << "Unexpected analog packet";
return; // This analog packet was not expected.
}
if (!_cur_analog_snapshot)
if (_cur_analog_snapshot->last_ended())
{
// Create a new data snapshot
_cur_analog_snapshot = boost::shared_ptr<data::AnalogSnapshot>(
new data::AnalogSnapshot(analog, _dev_inst->get_sample_limit(), get_ch_num(SR_CHANNEL_ANALOG)));
if (_cur_analog_snapshot->buf_null())
{
// first payload
_cur_analog_snapshot->first_payload(analog, _dev_inst->get_sample_limit(), get_ch_num(SR_CHANNEL_ANALOG));
if (_cur_analog_snapshot->memory_failed()) {
malloc_error();
return;
} else if(!_cur_analog_snapshot->buf_null()) {
_analog_data->push_snapshot(_cur_analog_snapshot);
}
} else if(!_cur_analog_snapshot->buf_null()) {
} else {
// Append to the existing data snapshot
_cur_analog_snapshot->append_payload(analog);
} else {
return;
}
receive_data(analog.num_samples);
......@@ -1165,7 +1148,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
{
{
boost::lock_guard<boost::mutex> lock(_data_mutex);
if (_cur_logic_snapshot) {
if (!_cur_logic_snapshot->empty()) {
BOOST_FOREACH(const boost::shared_ptr<view::GroupSignal> g, _group_traces)
{
assert(g);
......@@ -1176,9 +1159,9 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
_cur_group_snapshot.reset();
}
}
_cur_logic_snapshot.reset();
_cur_dso_snapshot.reset();
_cur_analog_snapshot.reset();
_cur_logic_snapshot->set_last_ended(true);
_cur_dso_snapshot->set_last_ended(true);
_cur_analog_snapshot->set_last_ended(true);
#ifdef ENABLE_DECODE
BOOST_FOREACH(const boost::shared_ptr<view::DecodeTrace> d, _decode_traces)
d->frame_ended();
......
......@@ -173,7 +173,7 @@ public:
void del_group();
void* get_buf(int& unit_size, uint64_t& length);
const void* get_buf(int& unit_size, uint64_t& length);
void start_hotplug_proc(boost::function<void (const QString)> error_handler);
void stop_hotplug_proc();
......@@ -191,8 +191,6 @@ public:
private:
void set_capture_state(capture_state state);
void update_data_header(const sr_dev_inst *const sdi);
private:
/**
* Attempts to autodetect the format. Failing that
......
......@@ -158,7 +158,7 @@ void FileBar::show_session_error(
void FileBar::on_actionExport_triggered(){
int unit_size;
uint64_t length;
void* buf = _session.get_buf(unit_size, length);
const void* buf = _session.get_buf(unit_size, length);
if (!buf) {
QMessageBox msg(this);
msg.setText(tr("Data Export"));
......@@ -192,7 +192,7 @@ void FileBar::on_actionSave_triggered()
//save();
int unit_size;
uint64_t length;
void* buf = _session.get_buf(unit_size, length);
const void* buf = _session.get_buf(unit_size, length);
if (!buf) {
QMessageBox msg(this);
msg.setText(tr("File Save"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment