Skip to content

Commit

Permalink
Merge branch 'trxlooper-lifespan-refactor' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rjonaitis committed Jun 24, 2024
2 parents c4326f2 + e1fd773 commit 8dff6c4
Show file tree
Hide file tree
Showing 25 changed files with 1,196 additions and 833 deletions.
1 change: 1 addition & 0 deletions GUI/fftviewer_wxgui/fftviewer_frFFTviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ void fftviewer_frFFTviewer::StreamingLoop(
kiss_fft_free(m_fftCalcPlan);
pthis->stopProcessing.store(true);
pthis->device->StreamStop(chipIndex);
pthis->device->StreamDestroy(chipIndex);

for (int i = 0; i < channelsCount; ++i)
delete[] buffers[i];
Expand Down
23 changes: 11 additions & 12 deletions src/API/LMS_APIWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ struct StreamHandle {
static constexpr std::size_t MAX_ELEMENTS_IN_BUFFER = 4096;

LMS_APIDevice* parent;
bool isStreamStartedFromAPI;
bool isStreamActuallyStarted;
lime::MemoryPool memoryPool;

StreamHandle() = delete;
StreamHandle(LMS_APIDevice* parent)
: parent(parent)
, isStreamStartedFromAPI(false)
, isStreamActuallyStarted(false)
, memoryPool(1, sizeof(lime::complex32f_t) * MAX_ELEMENTS_IN_BUFFER, 4096, "StreamHandleMemoryPool"s)
{
Expand All @@ -115,7 +113,7 @@ static inline int OpStatusToReturnCode(OpStatus value)
return value == OpStatus::Success ? 0 : -1;
}

inline LMS_APIDevice* CheckDevice(lms_device_t* device)
static inline LMS_APIDevice* CheckDevice(lms_device_t* device)
{
if (device == nullptr)
{
Expand All @@ -126,7 +124,7 @@ inline LMS_APIDevice* CheckDevice(lms_device_t* device)
return static_cast<LMS_APIDevice*>(device);
}

inline LMS_APIDevice* CheckDevice(lms_device_t* device, unsigned chan)
static inline LMS_APIDevice* CheckDevice(lms_device_t* device, unsigned chan)
{
LMS_APIDevice* apiDevice = CheckDevice(device);
if (apiDevice == nullptr || apiDevice->device == nullptr)
Expand All @@ -143,7 +141,7 @@ inline LMS_APIDevice* CheckDevice(lms_device_t* device, unsigned chan)
return apiDevice;
}

inline std::size_t GetStreamHandle(LMS_APIDevice* parent)
static inline std::size_t GetStreamHandle(LMS_APIDevice* parent)
{
for (std::size_t i = 0; i < streamHandles.size(); i++)
{
Expand All @@ -158,14 +156,14 @@ inline std::size_t GetStreamHandle(LMS_APIDevice* parent)
return streamHandles.size() - 1;
}

inline void CopyString(const std::string_view source, char* destination, std::size_t destinationLength)
static inline void CopyString(const std::string_view source, char* destination, std::size_t destinationLength)
{
std::size_t charsToCopy = std::min(destinationLength - 1, source.size());
std::strncpy(destination, source.data(), charsToCopy);
destination[charsToCopy] = 0;
}

inline lms_range_t RangeToLMS_Range(const lime::Range& range)
static inline lms_range_t RangeToLMS_Range(const lime::Range& range)
{
return { range.min, range.max, range.step };
}
Expand Down Expand Up @@ -819,13 +817,19 @@ API_EXPORT int CALL_CONV LMS_DestroyStream(lms_device_t* device, lms_stream_t* s
return -1;
}

apiDevice->device->StreamDestroy(apiDevice->moduleIndex);
auto& streamHandle = streamHandles.at(stream->handle);
if (streamHandle != nullptr)
{
delete streamHandle;
streamHandle = nullptr;
}

auto& channels = apiDevice->lastSavedStreamConfig.channels.at(stream->isTx ? lime::TRXDir::Tx : lime::TRXDir::Rx);
auto iter = std::find(channels.begin(), channels.end(), stream->channel);
if (iter != std::end(channels))
channels.erase(iter);

return 0;
}

Expand All @@ -842,8 +846,6 @@ API_EXPORT int CALL_CONV LMS_StartStream(lms_stream_t* stream)
return -1;
}

handle->isStreamStartedFromAPI = true;

if (!handle->isStreamActuallyStarted)
{
handle->parent->device->StreamStart(handle->parent->moduleIndex);
Expand Down Expand Up @@ -875,8 +877,6 @@ API_EXPORT int CALL_CONV LMS_StopStream(lms_stream_t* stream)
return -1;
}

handle->isStreamStartedFromAPI = false;

if (handle->isStreamActuallyStarted)
{
handle->parent->device->StreamStop(handle->parent->moduleIndex);
Expand Down Expand Up @@ -1151,7 +1151,6 @@ API_EXPORT int CALL_CONV LMS_GetStreamStatus(lms_stream_t* stream, lms_stream_st
break;
}

status->active = handle->isStreamStartedFromAPI;
status->fifoFilledCount = stats.FIFO.usedCount;
status->fifoSize = stats.FIFO.totalCount;

Expand Down
Loading

0 comments on commit 8dff6c4

Please sign in to comment.