PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/VLC-1.1.0-iOS/modules/video_filter/atmo/AtmoLiveView.cpp

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