QAbstractVideoSurface present silent crash on image copy
-
Hi,
I try to copy the frame passed to the function present of my QAbstractVideoSurface class. When I place a breakpoint at the start of the function, and hit play manually to pause the application flow at each present calls, there is no crash. If I remove the breakpoint and let the application run normally, the application will crash at the second call to the function.
Here is my function
@
bool VideoSurface::present(const QVideoFrame &frame)
{
if (frame.isValid())
{
QVideoFrame videoFrame(frame);
if( videoFrame.map(QAbstractVideoBuffer::ReadOnly) )
{
m_lastFrame = QImage(videoFrame.width(), videoFrame.height(), QImage::Format_ARGB32);
memcpy(m_lastFrame.bits(), videoFrame.bits(), videoFrame.mappedBytes());videoFrame.unmap(); return true; } } return true;
}
@Does any one have an idea why?
Thank you!
-
Hi,
Are you sure that frame is mapped ?
-
Well that was a good observation, but I beleive it is not mapped. I changed
@if( videoFrame.map(QAbstractVideoBuffer::ReadOnly) )@
for
@if( videoFrame.isMapped() && videoFrame.map(QAbstractVideoBuffer::ReadOnly) )@
And the application still crash.
I added a qDebug() call before the memcpy and just after it, and it seems the application crashes on the first call of memcpy, not at the second as I thought.
If I add a breakpoint at the start of the function, start debugging and hit play as soon as the breakpoint is reached, I got the second qDebug() call and the memcpy succeed.
I also add a videoFrame.isMapped() condition just before the memcpy, to be safe. And the application still crashed at the first call of memcpy.
-
Well my QImage bytes space is lower than the frame...Here is my debug :
@qDebug() << "frame buffer bits address is " << videoFrame.bits() << " and is composed of " << videoFrame.mappedBytes() << "bytes with format " << videoFrame.pixelFormat();@
frame buffer bits address is 0x112000000 and is composed of 3686432 bytes with format Format_RGB32@qDebug() << "image buffer bits address is " << m_lastFrame.bits() << " and is composed of " << m_lastFrame.byteCount() << "bytes with color model " << m_lastFrame.pixelFormat().colorModel() << " and TypeInterpretation " << m_lastFrame.pixelFormat().typeInterpretation();@
image buffer bits address is 0x112385000 and is composed of 3686400 bytes with color model 0 and TypeInterpretation 0So this is why the memcpy failed. But I do not understand why they do not have the same size in bytes...
The color model 0 is QPixelFormat::RGB and the typeInterpretation 0 is QPixelFormat::UnsignedInteger
-
Is it me or does it looks like there's one pixel messing around ?
-
Isn't 32 bytes missing? With 32 bits per pixels, there are likely 4 pixels messing around.
Still, this is strange !
For now, I used m_lastFrame.byteCount() for the memcpy and it is working fine. Do you think this could be a bug from the Qt side?
Thanks !
-
Yes, you're right, that makes it 4, late night math :D
Pretty good question, I'd recommend asking on the interest mailing list and you should also check the "bug report system":http://bugreports.qt.io