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

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "videoWidget.h"
  2. videoWidget::videoWidget(CSTR path, int x, int y, int width, int height, bool decor, sdlCoreWidget* pParent) :sdlYUV420PWidget(x,y,width,height,decor,pParent), basicMediaDestination(){
  3. m_pTextureProtector = SDL_CreateMutex();
  4. m_pSource = new videoAVLIBSource();
  5. m_pCurrentFrame = NULL;
  6. m_pFrame_buffer = NULL;
  7. if (m_pSource != NULL) {
  8. if (decor) {
  9. SDL_Rect tR = m_pDecoration->getClipRect(m_sGeometry);
  10. m_pSource->_open(path, false, -1., -1, -1, -1, true, tR.w, tR.h);
  11. } else {
  12. m_pSource->_open(path, false, -1., -1, -1, -1, true, width, height);
  13. };
  14. m_pSource->attachDestination(this);
  15. };
  16. sdlGraphicElement::setType(GEL_PANEL);
  17. m_pGUI->registerGEL(this);
  18. };
  19. videoWidget::~videoWidget() {
  20. if (m_pTextureProtector != NULL)SDL_DestroyMutex(m_pTextureProtector);
  21. if (m_pCurrentFrame != NULL) {
  22. av_frame_free(&m_pCurrentFrame);
  23. };
  24. };
  25. void videoWidget::pushFrame(AVFrame* Frame, void* src ) {
  26. if (m_pTextureProtector == NULL) return;
  27. if (SDL_TryLockMutex(m_pTextureProtector) == 0) {
  28. if (m_pCurrentFrame == NULL) {
  29. m_pCurrentFrame = av_frame_alloc();
  30. if (m_pCurrentFrame != NULL) {
  31. m_pFrame_buffer = (uint8_t*)av_malloc(av_image_get_buffer_size(AV_PIX_FMT_YUV420P, Frame->width, Frame->height, BUFFER_ALIGN));
  32. if (m_pFrame_buffer != NULL) {
  33. //avpicture_fill((AVPicture *) m_pFrameYUV, m_pOut_buffer, AV_PIX_FMT_YUV420P, m_nWidth, m_nHeight );
  34. av_image_fill_arrays(m_pCurrentFrame->data, m_pCurrentFrame->linesize, m_pFrame_buffer, AV_PIX_FMT_YUV420P, Frame->width, Frame->height, 1);
  35. };
  36. };
  37. };
  38. if (m_pCurrentFrame!= NULL && m_pFrame_buffer != NULL) {
  39. av_image_copy(
  40. m_pCurrentFrame->data,
  41. m_pCurrentFrame->linesize,
  42. (const uint8_t**)(Frame->data), Frame->linesize,
  43. AV_PIX_FMT_YUV420P,
  44. Frame->width,
  45. Frame->height
  46. );
  47. };
  48. /* Moved to Render Function
  49. if (m_pFrame_buffer != NULL) {
  50. if (m_bNoDecoration) {
  51. 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]);
  52. } else {
  53. 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]);
  54. };
  55. };
  56. //*/
  57. SDL_UnlockMutex(m_pTextureProtector);
  58. m_bUpdateReq = true;
  59. };
  60. };
  61. void videoWidget::render(SDL_Renderer* pRenderer) {
  62. if (!m_bInitComplete) return;
  63. if (pRenderer == NULL) return;
  64. if (m_bHidden) return;
  65. if (m_pTexItem == NULL) {
  66. m_bInitComplete = false;
  67. return;
  68. };
  69. if (m_pTexItem->texture == NULL) return;
  70. SDL_Texture* backup;
  71. backup = SDL_GetRenderTarget(pRenderer);
  72. if (m_bUpdateReq) {
  73. SDL_LockMutex(m_pTextureProtector);
  74. SDL_SetRenderDrawBlendMode(pRenderer, SDL_BLENDMODE_BLEND);
  75. if (m_pFrame_buffer != NULL) {
  76. if (m_bNoDecoration) {
  77. 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]);
  78. } else {
  79. 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]);
  80. };
  81. };
  82. SDL_SetTextureBlendMode(m_pTexItem->texture, SDL_BLENDMODE_BLEND);
  83. SDL_SetRenderTarget(pRenderer, m_pTexItem->texture);
  84. SDL_Rect VPRect;
  85. if (m_bNoDecoration) {
  86. SDL_SetRenderDrawColor(pRenderer, m_sBgColor.r, m_sBgColor.g, m_sBgColor.b, m_sBgColor.a);
  87. SDL_RenderClear(pRenderer);
  88. } else {
  89. SDL_SetRenderDrawColor(pRenderer, 0, 0, 0, 0);
  90. SDL_RenderClear(pRenderer);
  91. VPRect = m_pDecoration->getClipRect(m_sGeometry);
  92. if (m_pContentTexture != NULL) {
  93. SDL_SetRenderTarget(pRenderer, m_pContentTexture->texture);
  94. };
  95. };
  96. if (!m_bNoDecoration) {
  97. if (m_pContentTexture != NULL) {
  98. SDL_SetRenderTarget(pRenderer, m_pTexItem->texture);
  99. SDL_RenderCopy(pRenderer, m_pContentTexture->texture, NULL, &VPRect);
  100. };
  101. drawAfter(pRenderer);
  102. m_pDecoration->decorate(this, pRenderer);
  103. } else {
  104. drawAfter(pRenderer);
  105. };
  106. SDL_UnlockMutex(m_pTextureProtector);
  107. };
  108. SDL_SetRenderTarget(pRenderer, backup);
  109. SDL_RenderCopy(pRenderer, m_pTexItem->texture, NULL, &m_sGeometry);
  110. };