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..
6 * See the README.txt file for copyright information and how to reach the author(s).
15 #define __STDC_FORMAT_MACROS 1
18 #include "AtmoLiveView.h"
19 #include "AtmoOutputFilter.h"
20 #include "AtmoTools.h"
22 #if defined(_ATMO_VLC_PLUGIN_)
23 # include <vlc_common.h>
25 # include "AtmoGdiDisplayCaptureInput.h"
28 #include "AtmoExternalCaptureInput.h"
30 #if defined(_ATMO_VLC_PLUGIN_)
32 CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData) :
33 CThread(pAtmoDynData->getAtmoFilter())
35 this->m_pAtmoDynData = pAtmoDynData;
40 CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData)
42 this->m_pAtmoDynData = pAtmoDynData;
48 CAtmoLiveView::~CAtmoLiveView(void)
53 DWORD CAtmoLiveView::Execute(void)
55 #if defined(_ATMO_VLC_PLUGIN_)
56 vlc_object_t *m_pLog = m_pAtmoDynData->getAtmoFilter();
65 int i_frame_counter = -1;
67 pColorPacket ColorPacket;
68 pColorPacket PreviousPacket = NULL;
70 CAtmoConnection *pAtmoConnection = this->m_pAtmoDynData->getAtmoConnection();
71 if((pAtmoConnection == NULL) || (pAtmoConnection->isOpen() == ATMO_FALSE)) return 0;
73 CAtmoConfig *pAtmoConfig = this->m_pAtmoDynData->getAtmoConfig();
76 this object does post processing of the pixel data
77 like jump /scenechange detection fading over the colors
79 CAtmoOutputFilter *filter = new CAtmoOutputFilter( this->m_pAtmoDynData->getAtmoConfig() );
80 CAtmoPacketQueue *pPacketQueue = this->m_pAtmoDynData->getLivePacketQueue();
82 int frameDelay = pAtmoConfig->getLiveView_FrameDelay();
84 #if defined(_ATMO_VLC_PLUGIN_)
86 because time function of vlc are working with us values instead of ms
88 frameDelay = frameDelay * 1000;
92 wait for the first frame to go in sync with the other thread
96 if( pPacketQueue->WaitForNextPacket(3000) )
99 do_sleep( frameDelay );
100 #if defined(_ATMO_VLC_PLUGIN_)
101 msg_Dbg( m_pLog, "First Packet got %"PRId64" ms", (get_time - t) / 1000 );
105 while(this->m_bTerminated == ATMO_FALSE)
108 if(i_frame_counter == 50) i_frame_counter = 0;
110 /* grab current Packet from InputQueue (working as FIFO)! */
111 #if defined(_ATMO_VLC_PLUGIN_)
112 ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), m_pLog, packet_time);
114 ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), packet_time);
119 create a packet copy - for later reuse if the input is slower than 25fps
121 if(PreviousPacket && (PreviousPacket->numColors == ColorPacket->numColors))
122 CopyColorPacket(ColorPacket, PreviousPacket)
124 delete (char *)PreviousPacket;
125 DupColorPacket(PreviousPacket, ColorPacket )
129 packet queue was empty for the given point of time
131 if(i_frame_counter == 0)
133 #if defined(_ATMO_VLC_PLUGIN_)
134 msg_Dbg( m_pLog, "wait for delayed packet..." );
137 if( pPacketQueue->WaitForNextPacket(200) )
140 do_sleep( frameDelay );
141 #if defined(_ATMO_VLC_PLUGIN_)
142 msg_Dbg( m_pLog, "got delayed packet %"PRId64" ms", (mdate() - t) / 1000 );
148 reuse previous color packet
150 DupColorPacket(ColorPacket, PreviousPacket)
157 /* pass it through the outputfilters! */
158 // Info Filtering will possible free the colorpacket and alloc a new one!
159 ColorPacket = filter->Filtering(ColorPacket);
161 /* apply gamma correction - only if the hardware isnt capable doing this */
162 ColorPacket = CAtmoTools::ApplyGamma(pAtmoConfig, ColorPacket);
165 apply white calibration - only if it is not
168 if(pAtmoConfig->isUseSoftwareWhiteAdj())
169 ColorPacket = CAtmoTools::WhiteCalibration(pAtmoConfig, ColorPacket);
171 /* send color data to the the hardware... */
172 pAtmoConnection->SendData(ColorPacket);
174 delete (char *)ColorPacket;
178 calculate RunTime of thread abbove (doesn't work well - so
179 this threads comes out of sync with Image producer and the
180 framerate (25fps) drifts away
182 #if defined(_ATMO_VLC_PLUGIN_)
183 ticks = ((mdate() - ticks) + 999)/1000;
185 ticks = GetTickCount() - ticks;
189 if( ThreadSleep( 40 - ticks ) == ATMO_FALSE )
194 #if defined(_ATMO_VLC_PLUGIN_)
195 msg_Dbg( m_pLog, "DWORD CAtmoLiveView::Execute(void) terminates");
196 pPacketQueue->ShowQueueStatus( m_pLog );
199 delete (char *)PreviousPacket;