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).
11 #define __STDC_FORMAT_MACROS 1
14 #include "AtmoLiveView.h"
15 #include "AtmoOutputFilter.h"
16 #include "AtmoTools.h"
18 #if defined(_ATMO_VLC_PLUGIN_)
19 # include <vlc_common.h>
21 # include "AtmoGdiDisplayCaptureInput.h"
24 #include "AtmoExternalCaptureInput.h"
26 #if defined(_ATMO_VLC_PLUGIN_)
28 CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData) :
29 CThread(pAtmoDynData->getAtmoFilter())
31 this->m_pAtmoDynData = pAtmoDynData;
36 CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData)
38 this->m_pAtmoDynData = pAtmoDynData;
44 CAtmoLiveView::~CAtmoLiveView(void)
49 DWORD CAtmoLiveView::Execute(void)
51 #if defined(_ATMO_VLC_PLUGIN_)
60 int i_frame_counter = -1;
62 pColorPacket ColorPacket;
63 pColorPacket PreviousPacket = NULL;
65 CAtmoConnection *pAtmoConnection = this->m_pAtmoDynData->getAtmoConnection();
66 if((pAtmoConnection == NULL) || (pAtmoConnection->isOpen() == ATMO_FALSE)) return 0;
68 CAtmoConfig *pAtmoConfig = this->m_pAtmoDynData->getAtmoConfig();
71 this object does post processing of the pixel data
72 like jump /scenechange detection fading over the colors
74 CAtmoOutputFilter *filter = new CAtmoOutputFilter( this->m_pAtmoDynData->getAtmoConfig() );
75 CAtmoPacketQueue *pPacketQueue = this->m_pAtmoDynData->getLivePacketQueue();
77 int frameDelay = pAtmoConfig->getLiveView_FrameDelay();
79 #if defined(_ATMO_VLC_PLUGIN_)
81 because time function of vlc are working with us values instead of ms
83 frameDelay = frameDelay * 1000;
87 wait for the first frame to go in sync with the other thread
91 if( pPacketQueue->WaitForNextPacket(3000) )
94 do_sleep( frameDelay );
95 #if defined(_ATMO_VLC_PLUGIN_)
96 msg_Dbg( m_pAtmoThread, "First Packet got %"PRId64" ms", (get_time - t) / 1000 );
100 while(this->m_bTerminated == ATMO_FALSE)
103 if(i_frame_counter == 50) i_frame_counter = 0;
105 /* grab current Packet from InputQueue (working as FIFO)! */
106 #if defined(_ATMO_VLC_PLUGIN_)
107 ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), m_pAtmoThread, packet_time);
109 ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), packet_time);
114 create a packet copy - for later reuse if the input is slower than 25fps
116 if(PreviousPacket && (PreviousPacket->numColors == ColorPacket->numColors))
117 CopyColorPacket(ColorPacket, PreviousPacket)
119 delete (char *)PreviousPacket;
120 DupColorPacket(PreviousPacket, ColorPacket )
124 packet queue was empty for the given point of time
126 if(i_frame_counter == 0)
128 #if defined(_ATMO_VLC_PLUGIN_)
129 msg_Dbg( m_pAtmoThread, "wait for delayed packet..." );
132 if( pPacketQueue->WaitForNextPacket(200) )
135 do_sleep( frameDelay );
136 #if defined(_ATMO_VLC_PLUGIN_)
137 msg_Dbg( m_pAtmoThread, "got delayed packet %"PRId64" ms", (mdate() - t) / 1000 );
143 reuse previous color packet
145 DupColorPacket(ColorPacket, PreviousPacket)
152 /* pass it through the outputfilters! */
153 // Info Filtering will possible free the colorpacket and alloc a new one!
154 ColorPacket = filter->Filtering(ColorPacket);
156 /* apply gamma correction - only if the hardware isnt capable doing this */
157 ColorPacket = CAtmoTools::ApplyGamma(pAtmoConfig, ColorPacket);
160 apply white calibration - only if it is not
163 if(pAtmoConfig->isUseSoftwareWhiteAdj())
164 ColorPacket = CAtmoTools::WhiteCalibration(pAtmoConfig, ColorPacket);
166 /* send color data to the the hardware... */
167 pAtmoConnection->SendData(ColorPacket);
169 delete (char *)ColorPacket;
173 calculate RunTime of thread abbove (doesn't work well - so
174 this threads comes out of sync with Image producer and the
175 framerate (25fps) drifts away
177 #if defined(_ATMO_VLC_PLUGIN_)
178 ticks = ((mdate() - ticks) + 999)/1000;
180 ticks = GetTickCount() - ticks;
184 if( ThreadSleep( 40 - ticks ) == ATMO_FALSE )
189 #if defined(_ATMO_VLC_PLUGIN_)
190 msg_Dbg( m_pAtmoThread, "DWORD CAtmoLiveView::Execute(void) terminates");
191 pPacketQueue->ShowQueueStatus( m_pAtmoThread );
194 delete (char *)PreviousPacket;