livoxGen1:PcloudStimProd: move qualeApi param parsing here
This commit is contained in:
@@ -73,8 +73,8 @@ public:
|
|||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& spec) const;
|
const std::shared_ptr<device::DeviceAttachmentSpec>& spec) const;
|
||||||
|
|
||||||
virtual std::shared_ptr<StimulusBuffer> getOrCreateAttachedStimulusBuffer(
|
virtual std::shared_ptr<StimulusBuffer> getOrCreateAttachedStimulusBuffer(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec,
|
const std::shared_ptr<device::DeviceAttachmentSpec>
|
||||||
int histbuffMs) = 0;
|
&deviceAttachmentSpec) = 0;
|
||||||
|
|
||||||
// Check if any attached buffer has the specified qualeIfaceApi
|
// Check if any attached buffer has the specified qualeIfaceApi
|
||||||
bool hasBufferWithQualeIfaceApi(const std::string& qualeIfaceApi) const;
|
bool hasBufferWithQualeIfaceApi(const std::string& qualeIfaceApi) const;
|
||||||
|
|||||||
@@ -80,37 +80,6 @@ getStimulusProducer(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to parse histbuffMs from device attachment spec
|
|
||||||
static int parseHistbuffMs(
|
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec)
|
|
||||||
{
|
|
||||||
int histbuffMs = 30000; // Default: 30000ms (30 seconds)
|
|
||||||
const std::vector<std::string> histbuffParamNames = {
|
|
||||||
"history-buffer-duration-ms",
|
|
||||||
"hist-buff-duration-ms",
|
|
||||||
"histbuff-duration-ms",
|
|
||||||
"histbuff-ms"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Loop through synonyms in reverse order; lattermost synonym wins.
|
|
||||||
for (auto synIt = histbuffParamNames.rbegin();
|
|
||||||
synIt != histbuffParamNames.rend(); ++synIt)
|
|
||||||
{
|
|
||||||
const auto& paramName = *synIt;
|
|
||||||
try {
|
|
||||||
histbuffMs = smo::device::DeviceAttachmentSpec
|
|
||||||
::parseRequiredParamAsInt(
|
|
||||||
spec->qualeIfaceApiParams, paramName);
|
|
||||||
break; // Found and parsed successfully
|
|
||||||
} catch (const std::exception&) {
|
|
||||||
// Parameter not found or parse error, continue to next synonym
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return histbuffMs;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to parse n-dgrams-per-frame from stim-buff-api params
|
// Helper function to parse n-dgrams-per-frame from stim-buff-api params
|
||||||
static size_t parseNDgramsPerFrame(
|
static size_t parseNDgramsPerFrame(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec)
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec)
|
||||||
@@ -205,13 +174,10 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse histbuffMs
|
|
||||||
int histbuffMs = parseHistbuffMs(context->spec);
|
|
||||||
|
|
||||||
// Call getOrCreateAttachedStimulusBuffer (may throw, catch and return failure)
|
// Call getOrCreateAttachedStimulusBuffer (may throw, catch and return failure)
|
||||||
try {
|
try {
|
||||||
context->stimProducer->getOrCreateAttachedStimulusBuffer(
|
context->stimProducer->getOrCreateAttachedStimulusBuffer(
|
||||||
context->spec, histbuffMs);
|
context->spec);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << __func__ << ": Failed to create StimBuffer: "
|
std::cerr << __func__ << ": Failed to create StimBuffer: "
|
||||||
<< e.what() << ". Producer is committed, DeviceReattacher will retry."
|
<< e.what() << ". Producer is committed, DeviceReattacher will retry."
|
||||||
|
|||||||
@@ -106,6 +106,37 @@ void produceStimFrameAck(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to parse histbuffMs from device attachment spec
|
||||||
|
static int parseHistbuffMs(
|
||||||
|
const std::shared_ptr<device::DeviceAttachmentSpec>& spec)
|
||||||
|
{
|
||||||
|
int histbuffMs = 30000; // Default: 30000ms (30 seconds)
|
||||||
|
const std::vector<std::string> histbuffParamNames = {
|
||||||
|
"history-buffer-duration-ms",
|
||||||
|
"hist-buff-duration-ms",
|
||||||
|
"histbuff-duration-ms",
|
||||||
|
"histbuff-ms"
|
||||||
|
};
|
||||||
|
|
||||||
|
// Loop through synonyms in reverse order; lattermost synonym wins.
|
||||||
|
for (auto synIt = histbuffParamNames.rbegin();
|
||||||
|
synIt != histbuffParamNames.rend(); ++synIt)
|
||||||
|
{
|
||||||
|
const auto& paramName = *synIt;
|
||||||
|
try {
|
||||||
|
histbuffMs = device::DeviceAttachmentSpec
|
||||||
|
::parseRequiredParamAsInt(
|
||||||
|
spec->qualeIfaceApiParams, paramName);
|
||||||
|
break; // Found and parsed successfully
|
||||||
|
} catch (const std::exception&) {
|
||||||
|
// Parameter not found or parse error, continue to next synonym
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return histbuffMs;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<StimulusBuffer>
|
std::shared_ptr<StimulusBuffer>
|
||||||
PcloudStimulusProducer::getAttachedStimulusBuffer(
|
PcloudStimulusProducer::getAttachedStimulusBuffer(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& spec) const
|
const std::shared_ptr<device::DeviceAttachmentSpec>& spec) const
|
||||||
@@ -142,8 +173,7 @@ PcloudStimulusProducer::getAttachedStimulusBuffer(
|
|||||||
|
|
||||||
std::shared_ptr<StimulusBuffer>
|
std::shared_ptr<StimulusBuffer>
|
||||||
PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer(
|
PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec,
|
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec
|
||||||
int histbuffMs
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Check if buffer already exists (idempotent)
|
// Check if buffer already exists (idempotent)
|
||||||
@@ -151,6 +181,9 @@ PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer(
|
|||||||
if (existingBuffer)
|
if (existingBuffer)
|
||||||
{ return existingBuffer; }
|
{ return existingBuffer; }
|
||||||
|
|
||||||
|
// Parse histbuffMs from device attachment spec
|
||||||
|
int histbuffMs = parseHistbuffMs(deviceAttachmentSpec);
|
||||||
|
|
||||||
// Parse qualeIfaceApi to determine buffer type
|
// Parse qualeIfaceApi to determine buffer type
|
||||||
const std::string& qualeIfaceApi = deviceAttachmentSpec->qualeIfaceApi;
|
const std::string& qualeIfaceApi = deviceAttachmentSpec->qualeIfaceApi;
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ public:
|
|||||||
|
|
||||||
std::shared_ptr<StimulusBuffer> getOrCreateAttachedStimulusBuffer(
|
std::shared_ptr<StimulusBuffer> getOrCreateAttachedStimulusBuffer(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>
|
const std::shared_ptr<device::DeviceAttachmentSpec>
|
||||||
&deviceAttachmentSpec,
|
&deviceAttachmentSpec) override;
|
||||||
int histbuffMs) override;
|
|
||||||
|
|
||||||
std::shared_ptr<StimulusBuffer> getAttachedStimulusBuffer(
|
std::shared_ptr<StimulusBuffer> getAttachedStimulusBuffer(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& spec)
|
const std::shared_ptr<device::DeviceAttachmentSpec>& spec)
|
||||||
|
|||||||
Reference in New Issue
Block a user