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