I need to render decoded frames on a QPixmap and draw it on a QWidget (I actually need to render each frame on several QWidgets, that's why i need to render on a custom area).
I've studied the libvlc and Qt documentation and googled around a lot... but I still get nothing!
This is what I've done:
FIRST, I've set callbacks and private data to render decoded video to a custom area in memory
Code: Select all
// these are class properties of type uchar*; the second pointer should be 32-byte aligned
_nativeBufferNotAligned = (uchar*)malloc((_nativeWidth * _nativeHeight * 4) + 31);
_nativeBuffer = (uchar*)((size_t(_nativeBufferNotAligned)+31) & (~31));
libvlc_video_set_format(_vlcmp, "RV32", _nativeWidth, _nativeHeight, _nativeWidth*4);
libvlc_video_set_callbacks(_vlcmp, libvlc_media_player_lock, libvlc_media_player_unlock, libvlc_media_player_display, this);
Code: Select all
void* VlcMediaPlayer::libvlc_media_player_lock(void *opaque, void **plane)
{
VlcMediaPlayer* vlcmp = (VlcMediaPlayer*) opaque;
*plane = vlcmp->_nativeBuffer;
return NULL;
}
void VlcMediaPlayer::libvlc_media_player_unlock(void *opaque, void *picture, void *const *plane)
{
}
void VlcMediaPlayer::libvlc_media_player_display(void *opaque, void *picture)
{
VlcMediaPlayer* vlcmp = (VlcMediaPlayer*) opaque;
// I keep a pointer to a QWidget that will render the buffer on video
vlcmp->_renderSurface->bufferReady(vlcmp->_nativeBuffer, vlcmp->_nativeWidth, vlcmp->_nativeHeight);
}
Code: Select all
void RenderSurface::bufferReady(uchar* nativeBuffer, uint nativeWidth, uint nativeHeight)
{
// _nativePixmap is a class property of type QPixmap*
if (_nativePixmap == NULL)
_nativePixmap = new QPixmap(nativeWidth, nativeHeight);
_nativePixmap->loadFromData(nativeBuffer, nativeWidth*nativeHeight*4);
update();
}
void RenderSurface::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.drawPixmap(0, 0, _surfaceWidth, _surfaceHeight, *_nativePixmap);
}
Has anybody any suggestion?
Thanks!!