You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
4.4 KiB
116 lines
4.4 KiB
#include "videoWidget.h"
|
|
videoWidget::videoWidget(CSTR path, int x, int y, int width, int height, bool decor, sdlCoreWidget* pParent) :sdlYUV420PWidget(x,y,width,height,decor,pParent), basicMediaDestination(){
|
|
m_pTextureProtector = SDL_CreateMutex();
|
|
m_pSource = new videoAVLIBSource();
|
|
m_pCurrentFrame = NULL;
|
|
m_pFrame_buffer = NULL;
|
|
if (m_pSource != NULL) {
|
|
if (decor) {
|
|
SDL_Rect tR = m_pDecoration->getClipRect(m_sGeometry);
|
|
m_pSource->_open(path, false, -1., -1, -1, -1, true, tR.w, tR.h);
|
|
} else {
|
|
m_pSource->_open(path, false, -1., -1, -1, -1, true, width, height);
|
|
};
|
|
m_pSource->attachDestination(this);
|
|
};
|
|
sdlGraphicElement::setType(GEL_PANEL);
|
|
m_pGUI->registerGEL(this);
|
|
};
|
|
|
|
videoWidget::~videoWidget() {
|
|
if (m_pTextureProtector != NULL)SDL_DestroyMutex(m_pTextureProtector);
|
|
if (m_pCurrentFrame != NULL) {
|
|
av_frame_free(&m_pCurrentFrame);
|
|
};
|
|
};
|
|
|
|
void videoWidget::pushFrame(AVFrame* Frame, void* src ) {
|
|
if (m_pTextureProtector == NULL) return;
|
|
if (SDL_TryLockMutex(m_pTextureProtector) == 0) {
|
|
if (m_pCurrentFrame == NULL) {
|
|
m_pCurrentFrame = av_frame_alloc();
|
|
if (m_pCurrentFrame != NULL) {
|
|
m_pFrame_buffer = (uint8_t*)av_malloc(av_image_get_buffer_size(AV_PIX_FMT_YUV420P, Frame->width, Frame->height, BUFFER_ALIGN));
|
|
if (m_pFrame_buffer != NULL) {
|
|
//avpicture_fill((AVPicture *) m_pFrameYUV, m_pOut_buffer, AV_PIX_FMT_YUV420P, m_nWidth, m_nHeight );
|
|
av_image_fill_arrays(m_pCurrentFrame->data, m_pCurrentFrame->linesize, m_pFrame_buffer, AV_PIX_FMT_YUV420P, Frame->width, Frame->height, 1);
|
|
};
|
|
};
|
|
};
|
|
if (m_pCurrentFrame!= NULL && m_pFrame_buffer != NULL) {
|
|
av_image_copy(
|
|
m_pCurrentFrame->data,
|
|
m_pCurrentFrame->linesize,
|
|
(const uint8_t**)(Frame->data), Frame->linesize,
|
|
AV_PIX_FMT_YUV420P,
|
|
Frame->width,
|
|
Frame->height
|
|
);
|
|
};
|
|
/* Moved to Render Function
|
|
if (m_pFrame_buffer != NULL) {
|
|
if (m_bNoDecoration) {
|
|
if (m_pTexItem != NULL) SDL_UpdateYUVTexture(m_pTexItem->texture, &m_pTexItem->geopmetry, Frame->data[0], Frame->linesize[0], Frame->data[1], Frame->linesize[1], Frame->data[2], Frame->linesize[2]);
|
|
} else {
|
|
if (m_pContentTexture != NULL) SDL_UpdateYUVTexture(m_pContentTexture->texture, &m_pContentTexture->geopmetry, Frame->data[0], Frame->linesize[0], Frame->data[1], Frame->linesize[1], Frame->data[2], Frame->linesize[2]);
|
|
};
|
|
};
|
|
//*/
|
|
SDL_UnlockMutex(m_pTextureProtector);
|
|
m_bUpdateReq = true;
|
|
};
|
|
};
|
|
|
|
void videoWidget::render(SDL_Renderer* pRenderer) {
|
|
if (!m_bInitComplete) return;
|
|
if (pRenderer == NULL) return;
|
|
if (m_bHidden) return;
|
|
if (m_pTexItem == NULL) {
|
|
m_bInitComplete = false;
|
|
return;
|
|
};
|
|
if (m_pTexItem->texture == NULL) return;
|
|
SDL_Texture* backup;
|
|
backup = SDL_GetRenderTarget(pRenderer);
|
|
if (m_bUpdateReq) {
|
|
SDL_LockMutex(m_pTextureProtector);
|
|
SDL_SetRenderDrawBlendMode(pRenderer, SDL_BLENDMODE_BLEND);
|
|
|
|
if (m_pFrame_buffer != NULL) {
|
|
if (m_bNoDecoration) {
|
|
if (m_pTexItem != NULL) SDL_UpdateYUVTexture(m_pTexItem->texture, &m_pTexItem->geopmetry, m_pCurrentFrame->data[0], m_pCurrentFrame->linesize[0], m_pCurrentFrame->data[1], m_pCurrentFrame->linesize[1], m_pCurrentFrame->data[2], m_pCurrentFrame->linesize[2]);
|
|
} else {
|
|
if (m_pContentTexture != NULL) SDL_UpdateYUVTexture(m_pContentTexture->texture, &m_pContentTexture->geopmetry, m_pCurrentFrame->data[0], m_pCurrentFrame->linesize[0], m_pCurrentFrame->data[1], m_pCurrentFrame->linesize[1], m_pCurrentFrame->data[2], m_pCurrentFrame->linesize[2]);
|
|
};
|
|
};
|
|
|
|
SDL_SetTextureBlendMode(m_pTexItem->texture, SDL_BLENDMODE_BLEND);
|
|
SDL_SetRenderTarget(pRenderer, m_pTexItem->texture);
|
|
SDL_Rect VPRect;
|
|
if (m_bNoDecoration) {
|
|
SDL_SetRenderDrawColor(pRenderer, m_sBgColor.r, m_sBgColor.g, m_sBgColor.b, m_sBgColor.a);
|
|
SDL_RenderClear(pRenderer);
|
|
} else {
|
|
SDL_SetRenderDrawColor(pRenderer, 0, 0, 0, 0);
|
|
SDL_RenderClear(pRenderer);
|
|
VPRect = m_pDecoration->getClipRect(m_sGeometry);
|
|
if (m_pContentTexture != NULL) {
|
|
SDL_SetRenderTarget(pRenderer, m_pContentTexture->texture);
|
|
};
|
|
};
|
|
|
|
if (!m_bNoDecoration) {
|
|
if (m_pContentTexture != NULL) {
|
|
SDL_SetRenderTarget(pRenderer, m_pTexItem->texture);
|
|
SDL_RenderCopy(pRenderer, m_pContentTexture->texture, NULL, &VPRect);
|
|
};
|
|
drawAfter(pRenderer);
|
|
m_pDecoration->decorate(this, pRenderer);
|
|
} else {
|
|
drawAfter(pRenderer);
|
|
};
|
|
SDL_UnlockMutex(m_pTextureProtector);
|
|
};
|
|
SDL_SetRenderTarget(pRenderer, backup);
|
|
SDL_RenderCopy(pRenderer, m_pTexItem->texture, NULL, &m_sGeometry);
|
|
};
|