]> git.sesse.net Git - vlc/blob - modules/video_filter/atmo/AtmoLiveView.cpp
Change %d into %PRId64
[vlc] / modules / video_filter / atmo / AtmoLiveView.cpp
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$
9  */
10
11 #define __STDC_FORMAT_MACROS 1
12
13 #include "AtmoDefs.h"
14 #include "AtmoLiveView.h"
15 #include "AtmoOutputFilter.h"
16 #include "AtmoTools.h"
17
18 #if defined(_ATMO_VLC_PLUGIN_)
19 #  include <vlc_common.h>
20 #else
21 #  include "AtmoGdiDisplayCaptureInput.h"
22 #endif
23
24 #include "AtmoExternalCaptureInput.h"
25
26 #if defined(_ATMO_VLC_PLUGIN_)
27
28 CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData) :
29                CThread(pAtmoDynData->getAtmoFilter())
30 {
31     this->m_pAtmoDynData    = pAtmoDynData;
32 }
33
34 #else
35
36 CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData)
37 {
38     this->m_pAtmoDynData  = pAtmoDynData;
39 }
40
41 #endif
42
43
44 CAtmoLiveView::~CAtmoLiveView(void)
45 {
46 }
47
48
49 DWORD CAtmoLiveView::Execute(void)
50 {
51 #if defined(_ATMO_VLC_PLUGIN_)
52     mtime_t ticks;
53     mtime_t t;
54     mtime_t packet_time;
55 #else
56     DWORD ticks;
57     DWORD t;
58     DWORD packet_time;
59 #endif
60     int i_frame_counter = -1;
61
62     pColorPacket ColorPacket;
63     pColorPacket PreviousPacket = NULL;
64
65     CAtmoConnection *pAtmoConnection = this->m_pAtmoDynData->getAtmoConnection();
66     if((pAtmoConnection == NULL) || (pAtmoConnection->isOpen() == ATMO_FALSE)) return 0;
67
68     CAtmoConfig *pAtmoConfig = this->m_pAtmoDynData->getAtmoConfig();
69
70     /*
71        this object does post processing of the pixel data
72        like jump /scenechange detection fading over the colors
73     */
74     CAtmoOutputFilter *filter = new CAtmoOutputFilter( this->m_pAtmoDynData->getAtmoConfig() );
75     CAtmoPacketQueue *pPacketQueue = this->m_pAtmoDynData->getLivePacketQueue();
76
77     int frameDelay = pAtmoConfig->getLiveView_FrameDelay();
78
79 #if defined(_ATMO_VLC_PLUGIN_)
80     /*
81      because time function of vlc are working with us values instead of ms
82     */
83     frameDelay = frameDelay * 1000;
84 #endif
85
86     /*
87       wait for the first frame to go in sync with the other thread
88     */
89     t = get_time;
90
91     if( pPacketQueue->WaitForNextPacket(3000) )
92     {
93         if( frameDelay > 0 )
94             do_sleep( frameDelay );
95 #if defined(_ATMO_VLC_PLUGIN_)
96         msg_Dbg( m_pAtmoThread, "First Packet got %"PRId64" ms", (get_time - t) / 1000  );
97 #endif
98     }
99
100     while(this->m_bTerminated == ATMO_FALSE)
101     {
102         i_frame_counter++;
103         if(i_frame_counter == 50) i_frame_counter = 0;
104
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);
108 #else
109         ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), packet_time);
110 #endif
111         if(ColorPacket)
112         {
113             /*
114               create a packet copy - for later reuse if the input is slower than 25fps
115             */
116             if(PreviousPacket && (PreviousPacket->numColors == ColorPacket->numColors))
117                 CopyColorPacket(ColorPacket, PreviousPacket)
118             else {
119                 delete (char *)PreviousPacket;
120                 DupColorPacket(PreviousPacket, ColorPacket )
121             }
122         } else {
123             /*
124               packet queue was empty for the given point of time
125             */
126             if(i_frame_counter == 0)
127             {
128 #if defined(_ATMO_VLC_PLUGIN_)
129                 msg_Dbg( m_pAtmoThread, "wait for delayed packet..." );
130 #endif
131                 t = get_time;
132                 if( pPacketQueue->WaitForNextPacket(200) )
133                 {
134                     if( frameDelay > 0 )
135                         do_sleep( frameDelay );
136 #if defined(_ATMO_VLC_PLUGIN_)
137                     msg_Dbg( m_pAtmoThread, "got delayed packet %"PRId64" ms", (mdate() - t) / 1000  );
138 #endif
139                     continue;
140                 }
141             }
142             /*
143               reuse previous color packet
144             */
145             DupColorPacket(ColorPacket, PreviousPacket)
146         }
147
148         ticks = get_time;
149
150         if(ColorPacket)
151         {
152             /* pass it through the outputfilters! */
153             // Info Filtering will possible free the colorpacket and alloc a new one!
154             ColorPacket = filter->Filtering(ColorPacket);
155
156             /* apply gamma correction - only if the hardware isnt capable doing this */
157             ColorPacket = CAtmoTools::ApplyGamma(pAtmoConfig, ColorPacket);
158
159             /*
160             apply white calibration - only if it is not
161             done by the hardware
162             */
163             if(pAtmoConfig->isUseSoftwareWhiteAdj())
164                 ColorPacket = CAtmoTools::WhiteCalibration(pAtmoConfig, ColorPacket);
165
166             /* send color data to the the hardware... */
167             pAtmoConnection->SendData(ColorPacket);
168
169             delete (char *)ColorPacket;
170         }
171
172         /*
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
176         */
177 #if defined(_ATMO_VLC_PLUGIN_)
178         ticks = ((mdate() - ticks) + 999)/1000;
179 #else
180         ticks = GetTickCount() - ticks;
181 #endif
182         if(ticks < 40)
183         {
184             if( ThreadSleep( 40 - ticks ) == ATMO_FALSE )
185                 break;
186         }
187     }
188
189 #if defined(_ATMO_VLC_PLUGIN_)
190     msg_Dbg( m_pAtmoThread, "DWORD CAtmoLiveView::Execute(void) terminates");
191     pPacketQueue->ShowQueueStatus( m_pAtmoThread );
192 #endif
193
194     delete (char *)PreviousPacket;
195
196     delete filter;
197     return 0;
198 }
199