PageRenderTime 22ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/video_filter/atmo/AtmoLiveView.cpp

https://github.com/ccf19881030/vlc
C++ | 204 lines | 127 code | 35 blank | 42 comment | 26 complexity | da5dc545df9cb2e6f90e061aa84f73d6 MD5 | raw file
Possible License(s): GPL-2.0, WTFPL
  1. /*
  2. * AtmoLiveView.cpp: this effect outputs colors as result of a picture
  3. * content (most complex effect) see thread.c of the linux VDR version -
  4. * to fully understand what happens here..
  5. *
  6. * See the README.txt file for copyright information and how to reach the author(s).
  7. *
  8. * $Id: 987bb6115ad6da3016a852fab5c62a0aeb67505b $
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #define __STDC_FORMAT_MACROS 1
  14. #include "AtmoDefs.h"
  15. #include "AtmoLiveView.h"
  16. #include "AtmoOutputFilter.h"
  17. #include "AtmoTools.h"
  18. #if defined(_ATMO_VLC_PLUGIN_)
  19. # include <vlc_common.h>
  20. #else
  21. # include "AtmoGdiDisplayCaptureInput.h"
  22. #endif
  23. #include "AtmoExternalCaptureInput.h"
  24. #if defined(_ATMO_VLC_PLUGIN_)
  25. CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData) :
  26. CThread(pAtmoDynData->getAtmoFilter())
  27. {
  28. this->m_pAtmoDynData = pAtmoDynData;
  29. }
  30. #else
  31. CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData)
  32. {
  33. this->m_pAtmoDynData = pAtmoDynData;
  34. }
  35. #endif
  36. CAtmoLiveView::~CAtmoLiveView(void)
  37. {
  38. }
  39. DWORD CAtmoLiveView::Execute(void)
  40. {
  41. #if defined(_ATMO_VLC_PLUGIN_)
  42. vlc_object_t *m_pLog = m_pAtmoDynData->getAtmoFilter();
  43. mtime_t ticks;
  44. mtime_t t;
  45. mtime_t packet_time;
  46. #else
  47. DWORD ticks;
  48. DWORD t;
  49. DWORD packet_time;
  50. #endif
  51. int i_frame_counter = -1;
  52. pColorPacket ColorPacket;
  53. pColorPacket PreviousPacket = NULL;
  54. CAtmoConnection *pAtmoConnection = this->m_pAtmoDynData->getAtmoConnection();
  55. if((pAtmoConnection == NULL) || (pAtmoConnection->isOpen() == ATMO_FALSE)) return 0;
  56. CAtmoConfig *pAtmoConfig = this->m_pAtmoDynData->getAtmoConfig();
  57. /*
  58. this object does post processing of the pixel data
  59. like jump /scenechange detection fading over the colors
  60. */
  61. CAtmoOutputFilter *filter = new CAtmoOutputFilter( this->m_pAtmoDynData->getAtmoConfig() );
  62. CAtmoPacketQueue *pPacketQueue = this->m_pAtmoDynData->getLivePacketQueue();
  63. int frameDelay = pAtmoConfig->getLiveView_FrameDelay();
  64. #if defined(_ATMO_VLC_PLUGIN_)
  65. /*
  66. because time function of vlc are working with us values instead of ms
  67. */
  68. frameDelay = frameDelay * 1000;
  69. #endif
  70. /*
  71. wait for the first frame to go in sync with the other thread
  72. */
  73. t = get_time;
  74. if( pPacketQueue->WaitForNextPacket(3000) )
  75. {
  76. if( frameDelay > 0 )
  77. do_sleep( frameDelay );
  78. #if defined(_ATMO_VLC_PLUGIN_)
  79. msg_Dbg( m_pLog, "First Packet got %"PRId64" ms", (get_time - t) / 1000 );
  80. #endif
  81. }
  82. while(this->m_bTerminated == ATMO_FALSE)
  83. {
  84. i_frame_counter++;
  85. if(i_frame_counter == 50) i_frame_counter = 0;
  86. /* grab current Packet from InputQueue (working as FIFO)! */
  87. #if defined(_ATMO_VLC_PLUGIN_)
  88. ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), m_pLog, packet_time);
  89. #else
  90. ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), packet_time);
  91. #endif
  92. if(ColorPacket)
  93. {
  94. /*
  95. create a packet copy - for later reuse if the input is slower than 25fps
  96. */
  97. if(PreviousPacket && (PreviousPacket->numColors == ColorPacket->numColors))
  98. CopyColorPacket(ColorPacket, PreviousPacket)
  99. else {
  100. delete [] PreviousPacket;
  101. DupColorPacket(PreviousPacket, ColorPacket )
  102. }
  103. } else {
  104. /*
  105. packet queue was empty for the given point of time
  106. */
  107. if(i_frame_counter == 0)
  108. {
  109. #if defined(_ATMO_VLC_PLUGIN_)
  110. msg_Dbg( m_pLog, "wait for delayed packet..." );
  111. #endif
  112. t = get_time;
  113. if( pPacketQueue->WaitForNextPacket(200) )
  114. {
  115. if( frameDelay > 0 )
  116. do_sleep( frameDelay );
  117. #if defined(_ATMO_VLC_PLUGIN_)
  118. msg_Dbg( m_pLog, "got delayed packet %"PRId64" ms", (mdate() - t) / 1000 );
  119. #endif
  120. continue;
  121. }
  122. }
  123. /*
  124. reuse previous color packet
  125. */
  126. DupColorPacket(ColorPacket, PreviousPacket)
  127. }
  128. ticks = get_time;
  129. if(ColorPacket)
  130. {
  131. /* pass it through the outputfilters! */
  132. // Info Filtering will possible free the colorpacket and alloc a new one!
  133. ColorPacket = filter->Filtering(ColorPacket);
  134. /* apply gamma correction - only if the hardware isnt capable doing this */
  135. ColorPacket = CAtmoTools::ApplyGamma(pAtmoConfig, ColorPacket);
  136. /*
  137. apply white calibration - only if it is not
  138. done by the hardware
  139. */
  140. if(pAtmoConfig->isUseSoftwareWhiteAdj())
  141. ColorPacket = CAtmoTools::WhiteCalibration(pAtmoConfig, ColorPacket);
  142. /* send color data to the the hardware... */
  143. pAtmoConnection->SendData(ColorPacket);
  144. delete (char *)ColorPacket;
  145. }
  146. /*
  147. calculate RunTime of thread abbove (doesn't work well - so
  148. this threads comes out of sync with Image producer and the
  149. framerate (25fps) drifts away
  150. */
  151. #if defined(_ATMO_VLC_PLUGIN_)
  152. ticks = ((mdate() - ticks) + 999)/1000;
  153. #else
  154. ticks = GetTickCount() - ticks;
  155. #endif
  156. if(ticks < 40)
  157. {
  158. if( ThreadSleep( 40 - ticks ) == ATMO_FALSE )
  159. break;
  160. }
  161. }
  162. #if defined(_ATMO_VLC_PLUGIN_)
  163. msg_Dbg( m_pLog, "DWORD CAtmoLiveView::Execute(void) terminates");
  164. pPacketQueue->ShowQueueStatus( m_pLog );
  165. #endif
  166. delete [] PreviousPacket;
  167. delete filter;
  168. return 0;
  169. }