| 34 | } |
| 35 | |
| 36 | void Writer4SampleQueue::SaveQueue(std::unique_lock<std::mutex>& lock) { |
| 37 | if (writer_.CompressData()) { |
| 38 | SaveQueueCompressed(lock); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | // Save uncompressed data in last DG/DT block |
| 43 | auto* dg4 = dynamic_cast<Dg4Block*>(&data_group_); |
| 44 | if (dg4 == nullptr) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | lock.unlock(); |
| 49 | |
| 50 | writer_.Open( std::ios_base::in | std::ios_base::out | std::ios_base::binary); |
| 51 | if (!writer_.IsOpen()) { |
| 52 | lock.lock(); |
| 53 | return; |
| 54 | } |
| 55 | auto* dt4 = dg4->CreateOrGetDt4(*writer_.file_); |
| 56 | if (dt4 == nullptr) { |
| 57 | return; |
| 58 | } |
| 59 | const auto data_position = dt4->DataPosition(); |
| 60 | if (data_position <= 0) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | SetLastPosition(*writer_.file_); |
| 65 | |
| 66 | lock.lock(); |
| 67 | |
| 68 | TrimQueue(); |
| 69 | |
| 70 | const auto id_size = dg4->RecordIdSize(); |
| 71 | const auto stop_time = writer_.StopTime(); |
| 72 | while (!IsEmpty()) { |
| 73 | // Write a sample last to file |
| 74 | SampleRecord sample = GetSample(); |
| 75 | if (stop_time > 0 && sample.timestamp > stop_time) { |
| 76 | break; |
| 77 | } |
| 78 | auto* cg4 = dg4->FindCgRecordId(sample.record_id); |
| 79 | if (cg4 == nullptr) { |
| 80 | continue; |
| 81 | } |
| 82 | lock.unlock(); |
| 83 | |
| 84 | |
| 85 | auto* vlsd_group = sample.vlsd_data ? |
| 86 | dg4->FindCgRecordId(sample.record_id + 1) : nullptr; |
| 87 | // The next group must have the VLSD flag set otherwise it's not a VLSD group. |
| 88 | if (vlsd_group != nullptr && (vlsd_group->Flags() & CgFlag::VlsdChannel) == 0) { |
| 89 | vlsd_group = nullptr; |
| 90 | } |
| 91 | auto* cn4 = sample.vlsd_data && vlsd_group == nullptr ? |
| 92 | cg4->FindSdChannel() : nullptr; |
| 93 | // If the sample holds VLSD data, save this data first and then update |
nothing calls this directly
no test coverage detected