-
Notifications
You must be signed in to change notification settings - Fork 3
/
AtmoLiveView.cpp
226 lines (187 loc) · 5.5 KB
/
AtmoLiveView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* AtmoLiveView.cpp: this effect outputs colors as result of a picture
* content (most complex effect) see thread.c of the linux VDR version -
* to fully understand what happens here..
*
* See the README.txt file for copyright information and how to reach the author(s).
*
* $Id: 2f8d0167a302fa343d16730e46bd362259a56744 $
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#define __STDC_FORMAT_MACROS 1
#include "AtmoDefs.h"
#include "AtmoLiveView.h"
#include "AtmoOutputFilter.h"
#include "AtmoTools.h"
#if defined(_ATMO_VLC_PLUGIN_)
# include <vlc_common.h>
#else
# include "AtmoGdiDisplayCaptureInput.h"
#endif
#include "AtmoExternalCaptureInput.h"
#if defined(_ATMO_VLC_PLUGIN_)
CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData) :
CThread(pAtmoDynData->getAtmoFilter())
{
this->m_pAtmoDynData = pAtmoDynData;
}
#else
CAtmoLiveView::CAtmoLiveView(CAtmoDynData *pAtmoDynData)
{
this->m_pAtmoDynData = pAtmoDynData;
}
#endif
CAtmoLiveView::~CAtmoLiveView(void)
{
}
DWORD CAtmoLiveView::Execute(void)
{
#if defined(_ATMO_VLC_PLUGIN_)
vlc_object_t *m_pLog = m_pAtmoDynData->getAtmoFilter();
mtime_t ticks;
mtime_t t;
mtime_t packet_time;
#else
DWORD ticks;
DWORD t;
DWORD packet_time;
#endif
int i_frame_counter = -1;
pColorPacket ColorPacket;
pColorPacket PreviousPacket = NULL;
CAtmoConnection *pAtmoConnection = this->m_pAtmoDynData->getAtmoConnection();
if((pAtmoConnection == NULL) || (pAtmoConnection->isOpen() == ATMO_FALSE)) return 0;
CAtmoConfig *pAtmoConfig = this->m_pAtmoDynData->getAtmoConfig();
/*
this object does post processing of the pixel data
like jump /scenechange detection fading over the colors
*/
CAtmoOutputFilter *filter = new CAtmoOutputFilter( this->m_pAtmoDynData->getAtmoConfig() );
CAtmoPacketQueue *pPacketQueue = this->m_pAtmoDynData->getLivePacketQueue();
int frameDelay = pAtmoConfig->getLiveView_FrameDelay();
#if defined(_ATMO_VLC_PLUGIN_)
/*
because time function of vlc are working with us values instead of ms
*/
frameDelay = frameDelay * 1000;
#endif
/*
wait for the first frame to go in sync with the other thread
*/
t = get_time1;
if( pPacketQueue->WaitForNextPacket(3000) )
{
if( frameDelay > 0 )
do_sleep( frameDelay );
#if defined(_ATMO_VLC_PLUGIN_)
msg_Dbg( m_pLog, "First Packet got %"PRId64" ms", (get_time1 - t) / 1000 );
#endif
}
while(this->m_bTerminated == ATMO_FALSE)
{
i_frame_counter++;
if(i_frame_counter == 50) i_frame_counter = 0;
/* grab current Packet from InputQueue (working as FIFO)! */
#if defined(_ATMO_VLC_PLUGIN_)
ColorPacket = pPacketQueue->GetNextPacket(get_time1 - frameDelay, (i_frame_counter == 0), m_pLog, packet_time);
#else
ColorPacket = pPacketQueue->GetNextPacket(get_time1 - frameDelay, (i_frame_counter == 0), packet_time);
#endif
if(ColorPacket)
{
/*
create a packet copy - for later reuse if the input is slower than 25fps
*/
if(PreviousPacket && (PreviousPacket->numColors == ColorPacket->numColors))
CopyColorPacket(ColorPacket, PreviousPacket)
else
{
delete (char *)PreviousPacket;
DupColorPacket(PreviousPacket, ColorPacket )
}
}
else
{
/*
packet queue was empty for the given point of time
*/
if(i_frame_counter == 0)
{
#if defined(_ATMO_VLC_PLUGIN_)
msg_Dbg( m_pLog, "wait for delayed packet..." );
#endif
t = get_time1;
if( pPacketQueue->WaitForNextPacket(200) )
{
if( frameDelay > 0 )
do_sleep( frameDelay );
#if defined(_ATMO_VLC_PLUGIN_)
msg_Dbg( m_pLog, "got delayed packet %"PRId64" ms", (mdate() - t) / 1000 );
#endif
continue;
}
}
/*
reuse previous color packet
*/
DupColorPacket(ColorPacket, PreviousPacket)
}
ticks = get_time1;
if(ColorPacket)
{
/* pass it through the outputfilters! */
// Info Filtering will possible free the colorpacket and alloc a new one!
ColorPacket = filter->Filtering(ColorPacket);
// invert colors
if(pAtmoConfig->isUseinvert())
ColorPacket = CAtmoTools::Applyinvert(pAtmoConfig, ColorPacket);
/* apply gamma correction - only if the hardware isnt capable doing this */
ColorPacket = CAtmoTools::ApplyGamma(pAtmoConfig, ColorPacket);
// load color correction from Kodak 3D-Lut file
if(pAtmoConfig->isUse3dlut() && pAtmoConfig->m_3dlut)
ColorPacket = CAtmoTools::Apply3dlut(pAtmoConfig, ColorPacket);
// our own trilinear CMS
if(pAtmoConfig->isUseColorKWhiteAdj())
ColorPacket = CAtmoTools::ApplyColorK(pAtmoConfig, ColorPacket);
// apply white calibration - only if it is not done by the hardware
if((pAtmoConfig->isUseSoftwareWhiteAdj()))//&&(!pAtmoConfig->isUseColorKWhiteAdj()))
ColorPacket = CAtmoTools::WhiteCalibration(pAtmoConfig, ColorPacket);
//Sensitivity
ColorPacket = CAtmoTools::ApplySens(pAtmoConfig, ColorPacket);
/* send color data to the the hardware... */
try
{
pAtmoConnection->SendData(ColorPacket);
delete (char *)ColorPacket;
}
catch(...)
{
delete (char *)ColorPacket;
}
}
/*
calculate RunTime of thread abbove (doesn't work well - so
this threads comes out of sync with Image producer and the
framerate (25fps) drifts away
*/
#if defined(_ATMO_VLC_PLUGIN_)
ticks = ((mdate() - ticks) + 999)/1000;
#else
ticks = GetTickCount() - ticks;
#endif
if(ticks < 40)
{
if( ThreadSleep( 40 - ticks ) == ATMO_FALSE )
break;
}
}
#if defined(_ATMO_VLC_PLUGIN_)
msg_Dbg( m_pLog, "DWORD CAtmoLiveView::Execute(void) terminates");
pPacketQueue->ShowQueueStatus( m_pLog );
#endif
delete (char *)PreviousPacket;
delete filter;
return 0;
}