2
0
forked from Ivasoft/DSView

fix: got an error data to decode on loop mode, the data offset is error

This commit is contained in:
dreamsourcelabTAI
2024-05-22 16:27:49 +08:00
parent 3358e89948
commit 7251789916
3 changed files with 100 additions and 55 deletions

View File

@@ -521,12 +521,10 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
assert(logic_di);
uint64_t entry_cnt = 0;
uint64_t i = decode_start;
char *error = NULL;
bool bError = false;
bool bEndTime = false;
//struct srd_push_param push_param;
if( i >= decode_end){
dsv_info("decode data index have been to end");
@@ -534,12 +532,11 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
std::vector<const uint8_t *> chunk;
std::vector<uint8_t> chunk_const;
bool bCheckEnd = false;
uint64_t end_index = decode_end;
uint64_t decoded_sample_count = 0;
_progress = 0;
uint64_t sended_len = 0;
_is_decoding = true;
void* lbp_array[35];
@@ -547,8 +544,8 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
for (int j =0 ; j < logic_di->dec_num_channels; j++){
lbp_array[j] = NULL;
}
while(i < end_index && !_no_memory && !status->_bStop)
while(i <= end_index && !_no_memory && !status->_bStop)
{
chunk.clear();
chunk_const.clear();
@@ -567,7 +564,7 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
if (end_index >= align_sample_count){
end_index = align_sample_count - 1;
dsv_info("Reset the decode end sample, new:%llu, old:%llu",
dsv_info("Reset the decode end sample index, new:%llu, old:%llu",
(u64_t)end_index, (u64_t)decode_end);
}
@@ -580,14 +577,10 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
else if (i >= _snapshot->get_ring_sample_count())
{
// Wait the data is ready.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(200));
continue;
}
if (_is_capture_end && i == _snapshot->get_ring_sample_count()){
break;
}
uint64_t chunk_end = end_index;
for (int j =0 ; j < logic_di->dec_num_channels; j++) {
@@ -601,8 +594,9 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
else {
if (_snapshot->has_data(sig_index)) {
const uint8_t *data_ptr = _snapshot->get_samples(i, chunk_end, sig_index, &lbp);
bool flag = _snapshot->get_sample(i, sig_index);
chunk.push_back(data_ptr);
chunk_const.push_back(_snapshot->get_sample(i, sig_index));
chunk_const.push_back(flag);
if (_snapshot->is_able_free() == false)
{
@@ -621,12 +615,18 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
}
}
if (chunk_end > end_index)
chunk_end = end_index;
if (i > end_index){
bEndTime = true;
dsv_info("Decoding data to end.");
break;
}
if (chunk_end >= end_index)
chunk_end = end_index + 1;
if (chunk_end - i > MaxChunkSize)
chunk_end = i + MaxChunkSize;
bEndTime = (chunk_end == end_index);
bEndTime = (chunk_end > end_index);
if (srd_session_send(
session,
@@ -639,7 +639,7 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
if (error){
_error_message = QString::fromLocal8Bit(error);
dsv_err("Failed to call srd_session_send:%s", error);
dsv_err("ERROR: Failed to call srd_session_send:%s", error);
g_free(error);
error = NULL;
}
@@ -648,11 +648,10 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
break;
}
sended_len += chunk_end - i;
_progress = (int)(sended_len * 100 / end_index);
i = chunk_end;
decoded_sample_count += chunk_end - i;
_progress = (int)(decoded_sample_count * 100 / end_index);
i = chunk_end;
//use mutex
{
std::lock_guard<std::mutex> lock(_output_mutex);
@@ -663,8 +662,6 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
last_cnt = i;
new_decode_data();
}
entry_cnt++;
}
_progress = 100;
@@ -681,14 +678,16 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod
dsv_err("Failed to call srd_session_end:%s", error);
}
}
dsv_info("%s%llu", "send to decoder times: ", (u64_t)entry_cnt);
if (error != NULL)
if (error != NULL){
g_free(error);
}
if (!_session->is_closed())
if (!_session->is_closed()){
decode_done();
}
dsv_info("Decoded sample count:%llu", decoded_sample_count);
}
void DecoderStack::execute_decode_stack()
@@ -738,7 +737,7 @@ void DecoderStack::execute_decode_stack()
decode_end = max(dec->decode_end(), decode_end);
}
dsv_info("decoder start sample:%llu, end sample:%llu, count:%llu",
dsv_info("Decode start sample index:%llu, end sample index:%llu, count:%llu",
(u64_t)decode_start, (u64_t)decode_end, (u64_t)(decode_end - decode_start + 1));
// Start the session

View File

@@ -600,45 +600,70 @@ void LogicSnapshot::calc_mipmap(unsigned int order, uint8_t index0, uint8_t inde
}
const uint8_t *LogicSnapshot::get_samples(uint64_t start_sample, uint64_t &end_sample, int sig_index, void **lbp)
{
{
std::lock_guard<std::mutex> lock(_mutex);
uint64_t sample_count = _ring_sample_count;
assert(start_sample < sample_count);
if (end_sample >= sample_count)
end_sample = sample_count - 1;
assert(end_sample <= sample_count);
assert(start_sample <= end_sample);
start_sample += _loop_offset;
_ring_sample_count += _loop_offset;
uint64_t logic_sample_index = start_sample + _loop_offset;
int order = get_ch_order(sig_index);
uint64_t index0 = start_sample >> (LeafBlockPower + RootScalePower);
uint64_t index1 = (start_sample & RootMask) >> LeafBlockPower;
uint64_t offset = (start_sample & LeafMask) / 8;
// uint64_t index0 = logic_sample_index >> (LeafBlockPower + RootScalePower);
// uint64_t index1 = (logic_sample_index & RootMask) >> LeafBlockPower;
// uint64_t offset = (start_sample & LeafMask) / 8;
end_sample = (index0 << (LeafBlockPower + RootScalePower)) +
uint64_t index0 = logic_sample_index / LeafBlockSamples / RootScale;
uint64_t index1 = (logic_sample_index / LeafBlockSamples) % RootScale;
uint64_t offset = (start_sample % LeafBlockSamples) / 8;
uint8_t *block_buffer = (uint8_t*)_ch_data[order][index0].lbp[index1];
int block_num = get_block_num_unlock();
if (_is_loop && _loop_offset > 0)
{
uint64_t block0_sample = get_block_size_unlock(0) * 8;
bool flag = false;
if (start_sample < block0_sample){
block_buffer = get_block_buf_unlock(0, sig_index, flag);
end_sample = block0_sample;
offset = start_sample / 8;
}
else{
uint64_t last_block_sample = get_block_size_unlock(block_num - 1) * 8;
offset = ((start_sample - block0_sample) % LeafBlockSamples) / 8;
if (start_sample >= sample_count - last_block_sample){
end_sample = sample_count;
}
else{
int mid_block_num = (start_sample - block0_sample) / LeafBlockSamples + 1;
end_sample = mid_block_num * LeafBlockSamples + block0_sample;
}
}
}
else{
end_sample = (index0 << (LeafBlockPower + RootScalePower)) +
(index1 << LeafBlockPower) +
~(~0ULL << LeafBlockPower);
end_sample = min(end_sample + 1, sample_count);
end_sample = min(end_sample + 1, sample_count);
}
_ring_sample_count -= _loop_offset;
if (order == -1 || _ch_data[order][index0].lbp[index1] == NULL)
if (order == -1 || block_buffer == NULL){
return NULL;
}
else{
if (lbp != NULL)
if (lbp != NULL){
*lbp = _ch_data[order][index0].lbp[index1];
}
_cur_ref_block_indexs[order].root_index = index0;
_cur_ref_block_indexs[order].lbp_index = index1;
return (uint8_t*)_ch_data[order][index0].lbp[index1] + offset;
return block_buffer + offset;
}
}
@@ -1361,8 +1386,14 @@ bool LogicSnapshot::has_data(int sig_index)
}
int LogicSnapshot::get_block_num()
{
std::lock_guard<std::mutex> lock(_mutex);
return get_block_num_unlock();
}
int LogicSnapshot::get_block_num_unlock()
{
auto align_sample_count = get_ring_sample_count();
auto align_sample_count = _ring_sample_count;
int block = align_sample_count / LeafBlockSamples;
if (align_sample_count % LeafBlockSamples != 0){
@@ -1375,7 +1406,7 @@ int LogicSnapshot::get_block_num()
if ((diff1 == 0 && diff2 != 0) ||
(diff1 != 0 && diff1 + diff2 > LeafBlockSamples)){
block++;
block++;
}
}
@@ -1384,10 +1415,16 @@ int LogicSnapshot::get_block_num()
uint64_t LogicSnapshot::get_block_size(int block_index)
{
int block_num = get_block_num();
std::lock_guard<std::mutex> lock(_mutex);
return get_block_size_unlock(block_index);
}
uint64_t LogicSnapshot::get_block_size_unlock(int block_index)
{
int block_num = get_block_num_unlock();
assert(block_index < block_num);
auto align_sample_count = get_ring_sample_count();
auto align_sample_count = _ring_sample_count;
if (_loop_offset > 0)
{
@@ -1426,7 +1463,13 @@ uint64_t LogicSnapshot::get_block_size(int block_index)
uint8_t *LogicSnapshot::get_block_buf(int block_index, int sig_index, bool &sample)
{
int block_num = get_block_num();
std::lock_guard<std::mutex> lock(_mutex);
return get_block_buf_unlock(block_index, sig_index, sample);
}
uint8_t *LogicSnapshot::get_block_buf_unlock(int block_index, int sig_index, bool &sample)
{
int block_num = get_block_num_unlock();
assert(block_index < block_num);
int order = get_ch_order(sig_index);

View File

@@ -124,8 +124,11 @@ public:
bool has_data(int sig_index);
int get_block_num();
int get_block_num_unlock();
uint64_t get_block_size(int block_index);
uint64_t get_block_size_unlock(int block_index);
uint8_t *get_block_buf(int block_index, int sig_index, bool &sample);
uint8_t *get_block_buf_unlock(int block_index, int sig_index, bool &sample);
bool pattern_search(int64_t start, int64_t end, int64_t& index,
std::map<uint16_t, QString> &pattern, bool isNext);