Avoid steady-state v210 double copy

This commit is contained in:
Johanness
2026-05-19 00:43:04 +03:00
parent 3df545e95c
commit 32f5b70f59
4 changed files with 227 additions and 37 deletions
+111
View File
@@ -518,6 +518,105 @@ const VideoFrame& MxlSdkFeed::getFrame(uint32_t frameCounter)
return mFrame;
}
bool MxlSdkFeed::readV210FrameInto(
uint32_t frameCounter,
void* destination,
size_t destinationSize)
{
(void)frameCounter;
if (!mFlowOpened && !openFlow())
{
return false;
}
uint64_t index = mLastDisplayedIndex + 1;
const uint64_t currentIndex = mxlGetCurrentIndex(&mGrainRate);
if (index > currentIndex)
{
return false;
}
mxlGrainInfo grain{};
grain.version = 2;
grain.size = sizeof(mxlGrainInfo);
uint8_t* payload = nullptr;
while (true)
{
mxlStatus status = mxlFlowReaderGetGrainNonBlocking(
mReader,
index,
&grain,
&payload);
if (status == MXL_STATUS_OK)
{
break;
}
if (status == MXL_ERR_OUT_OF_RANGE_TOO_EARLY)
{
return false;
}
if (status == MXL_ERR_OUT_OF_RANGE_TOO_LATE)
{
mxlFlowRuntimeInfo runtimeInfo{};
if (mxlFlowReaderGetRuntimeInfo(mReader, &runtimeInfo) !=
MXL_STATUS_OK)
{
return false;
}
if (runtimeInfo.headIndex == 0)
{
return false;
}
index = runtimeInfo.headIndex - 1;
if (index <= mLastDisplayedIndex)
{
return false;
}
continue;
}
if (status == MXL_ERR_FLOW_INVALID)
{
std::cerr << "MxlSdkFeed: flow invalidated, reconnecting"
<< std::endl;
closeFlow();
return false;
}
std::cerr << "MxlSdkFeed: grain read error status="
<< static_cast<int>(status) << std::endl;
return false;
}
const size_t payloadSize =
static_cast<size_t>(mSourceStride) *
static_cast<size_t>(mSourceHeight);
if (payload == nullptr ||
destination == nullptr ||
payloadSize == 0 ||
destinationSize < payloadSize)
{
return false;
}
std::memcpy(destination, payload, payloadSize);
mLastDisplayedIndex = index;
++mFrameVersion;
return true;
}
FeedRuntimeStatus MxlSdkFeed::status() const
{
if (mFlowOpened && !mV210Payload.empty())
@@ -616,6 +715,7 @@ float MxlSdkFeed::srcAspectRatio() const
bool MxlSdkFeed::hasV210() const { return mFlowOpened && !mV210Payload.empty(); }
const uint8_t* MxlSdkFeed::v210Data() const { return mV210Payload.data(); }
bool MxlSdkFeed::supportsDirectV210Read() const { return mFlowOpened; }
uint32_t MxlSdkFeed::v210Width() const { return mSourceWidth; }
uint32_t MxlSdkFeed::v210Height() const { return mSourceHeight; }
uint32_t MxlSdkFeed::v210Stride() const { return mSourceStride; }
@@ -635,6 +735,17 @@ double MxlSdkFeed::frameRate() const { return 0.0; }
float MxlSdkFeed::srcAspectRatio() const { return 16.0f / 9.0f; }
bool MxlSdkFeed::hasV210() const { return false; }
const uint8_t* MxlSdkFeed::v210Data() const { return nullptr; }
bool MxlSdkFeed::supportsDirectV210Read() const { return false; }
bool MxlSdkFeed::readV210FrameInto(
uint32_t frameCounter,
void* destination,
size_t destinationSize)
{
(void)frameCounter;
(void)destination;
(void)destinationSize;
return false;
}
uint32_t MxlSdkFeed::v210Width() const { return 0; }
uint32_t MxlSdkFeed::v210Height() const { return 0; }
uint32_t MxlSdkFeed::v210Stride() const { return 0; }