Commit f83e0c96 authored by Laurent Aimar's avatar Laurent Aimar

Converted atmo filter to vlc_clone().

I have just modified it to remove the use of vlc_thread_create(). There is
a lot of improvement that can be done to the way the thread are handled.

I have not tested it for regressions.
parent 03718ff8
......@@ -29,6 +29,7 @@ CAtmoExternalCaptureInput::CAtmoExternalCaptureInput(CAtmoDynData *pAtmoDynData)
vlc_cond_init( &m_WakeupCond );
vlc_mutex_init( &m_WakeupLock );
m_pCurrentFramePixels = NULL;
m_pLog = pAtmoDynData->getAtmoFilter();
}
#else
......@@ -97,7 +98,7 @@ void CAtmoExternalCaptureInput::DeliverNewSourceDataPaket(BITMAPINFOHEADER *bmpI
the test needs and malloc needs...
*/
#if defined(_ATMO_VLC_PLUGIN_)
// msg_Dbg( m_pAtmoThread, "DeliverNewSourceDataPaket start...");
// msg_Dbg( m_pLog, "DeliverNewSourceDataPaket start...");
vlc_mutex_lock( &m_WakeupLock );
#else
EnterCriticalSection( &m_BufferLock );
......@@ -119,7 +120,7 @@ void CAtmoExternalCaptureInput::DeliverNewSourceDataPaket(BITMAPINFOHEADER *bmpI
#if defined(_ATMO_VLC_PLUGIN_)
vlc_cond_signal( &m_WakeupCond );
vlc_mutex_unlock( &m_WakeupLock );
// msg_Dbg( m_pAtmoThread, "DeliverNewSourceDataPaket done.");
// msg_Dbg( m_pLog, "DeliverNewSourceDataPaket done.");
#else
SetEvent(m_hWakeupEvent);
LeaveCriticalSection( &m_BufferLock );
......@@ -136,7 +137,7 @@ void CAtmoExternalCaptureInput::DeliverNewSourceDataPaket(BITMAPINFOHEADER *bmpI
DWORD CAtmoExternalCaptureInput::Execute(void)
{
while ((this->m_bTerminated == ATMO_FALSE) && !this->m_pAtmoThread->b_die) {
while ((this->m_bTerminated == ATMO_FALSE)) {
vlc_mutex_lock( &m_WakeupLock );
vlc_cond_timedwait(&m_WakeupCond, &m_WakeupLock, mdate() + 75000 );
......@@ -146,7 +147,7 @@ DWORD CAtmoExternalCaptureInput::Execute(void)
vlc_mutex_unlock( &m_WakeupLock );
}
msg_Dbg( m_pAtmoThread, "DWORD CAtmoExternalCaptureInput::Execute(void) bailed out?");
msg_Dbg( m_pLog, "DWORD CAtmoExternalCaptureInput::Execute(void) bailed out?");
return 0;
}
......@@ -185,7 +186,7 @@ void CAtmoExternalCaptureInput::CalcColors()
int srcIndex,index = 0;
memset(&HSV_Img,0,sizeof(HSV_Img));
// msg_Dbg( m_pAtmoThread, "CalcColors start...");
// msg_Dbg( m_pLog, "CalcColors start...");
if((m_CurrentFrameHeader.biWidth == CAP_WIDTH) && (m_CurrentFrameHeader.biHeight == CAP_HEIGHT))
{
......@@ -271,8 +272,8 @@ void CAtmoExternalCaptureInput::CalcColors()
(sorry I don't know how it exactly works because the formulas
are done by some one else...)
*/
//msg_Dbg( m_pAtmoThread, "CalcColors ende AddPacket...");
//msg_Dbg( m_pLog, "CalcColors ende AddPacket...");
m_pAtmoDynData->getLivePacketQueue()->AddPacket( m_pAtmoColorCalculator->AnalyzeHSV( HSV_Img ) );
//msg_Dbg( m_pAtmoThread, "CalcColors ende AddPacket...done.");
//msg_Dbg( m_pLog, "CalcColors ende AddPacket...done.");
}
......@@ -30,6 +30,7 @@ protected:
#if defined(_ATMO_VLC_PLUGIN_)
vlc_cond_t m_WakeupCond;
vlc_mutex_t m_WakeupLock;
vlc_object_t *m_pLog;
#else
HANDLE m_hWakeupEvent;
CRITICAL_SECTION m_BufferLock;
......
......@@ -53,6 +53,7 @@ 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;
......@@ -97,7 +98,7 @@ DWORD CAtmoLiveView::Execute(void)
if( frameDelay > 0 )
do_sleep( frameDelay );
#if defined(_ATMO_VLC_PLUGIN_)
msg_Dbg( m_pAtmoThread, "First Packet got %"PRId64" ms", (get_time - t) / 1000 );
msg_Dbg( m_pLog, "First Packet got %"PRId64" ms", (get_time - t) / 1000 );
#endif
}
......@@ -108,7 +109,7 @@ DWORD CAtmoLiveView::Execute(void)
/* grab current Packet from InputQueue (working as FIFO)! */
#if defined(_ATMO_VLC_PLUGIN_)
ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), m_pAtmoThread, packet_time);
ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), m_pLog, packet_time);
#else
ColorPacket = pPacketQueue->GetNextPacket(get_time - frameDelay, (i_frame_counter == 0), packet_time);
#endif
......@@ -130,7 +131,7 @@ DWORD CAtmoLiveView::Execute(void)
if(i_frame_counter == 0)
{
#if defined(_ATMO_VLC_PLUGIN_)
msg_Dbg( m_pAtmoThread, "wait for delayed packet..." );
msg_Dbg( m_pLog, "wait for delayed packet..." );
#endif
t = get_time;
if( pPacketQueue->WaitForNextPacket(200) )
......@@ -138,7 +139,7 @@ DWORD CAtmoLiveView::Execute(void)
if( frameDelay > 0 )
do_sleep( frameDelay );
#if defined(_ATMO_VLC_PLUGIN_)
msg_Dbg( m_pAtmoThread, "got delayed packet %"PRId64" ms", (mdate() - t) / 1000 );
msg_Dbg( m_pLog, "got delayed packet %"PRId64" ms", (mdate() - t) / 1000 );
#endif
continue;
}
......@@ -191,8 +192,8 @@ DWORD CAtmoLiveView::Execute(void)
}
#if defined(_ATMO_VLC_PLUGIN_)
msg_Dbg( m_pAtmoThread, "DWORD CAtmoLiveView::Execute(void) terminates");
pPacketQueue->ShowQueueStatus( m_pAtmoThread );
msg_Dbg( m_pLog, "DWORD CAtmoLiveView::Execute(void) terminates");
pPacketQueue->ShowQueueStatus( m_pLog );
#endif
delete (char *)PreviousPacket;
......
......@@ -181,7 +181,7 @@ pColorPacket CAtmoPacketQueue::GetNextPacket()
}
#if defined(_ATMO_VLC_PLUGIN_)
void CAtmoPacketQueue::ShowQueueStatus(atmo_thread_t *p_this)
void CAtmoPacketQueue::ShowQueueStatus(vlc_object_t *p_this)
{
/*
show some statistics for the whole time...
......@@ -198,7 +198,7 @@ void CAtmoPacketQueue::ShowQueueStatus(atmo_thread_t *p_this)
#endif
#if defined(_ATMO_VLC_PLUGIN_)
pColorPacket CAtmoPacketQueue::GetNextPacket(mtime_t timecode, ATMO_BOOL withWait, atmo_thread_t *p_this, mtime_t &packet_time)
pColorPacket CAtmoPacketQueue::GetNextPacket(mtime_t timecode, ATMO_BOOL withWait, vlc_object_t *p_this, mtime_t &packet_time)
#else
pColorPacket CAtmoPacketQueue::GetNextPacket(DWORD timecode, ATMO_BOOL withWait, DWORD &packet_time)
#endif
......
......@@ -87,8 +87,8 @@ public:
// timecode = GetTickCount() - framedelay;
#if defined(_ATMO_VLC_PLUGIN_)
void ShowQueueStatus(atmo_thread_t *p_this);
pColorPacket GetNextPacket(mtime_t timecode, ATMO_BOOL withWait, atmo_thread_t *p_this, mtime_t &packet_time );
void ShowQueueStatus(vlc_object_t *p_this);
pColorPacket GetNextPacket(mtime_t timecode, ATMO_BOOL withWait, vlc_object_t *p_this, mtime_t &packet_time );
#else
pColorPacket GetNextPacket(DWORD timecode, ATMO_BOOL withWait, DWORD &packet_time );
#endif
......
......@@ -9,6 +9,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include "AtmoThread.h"
......@@ -17,18 +18,10 @@
CThread::CThread(vlc_object_t *pOwner)
{
m_bTerminated = ATMO_FALSE;
m_pAtmoThread = (atmo_thread_t *)vlc_object_create( pOwner,
sizeof(atmo_thread_t) );
if(m_pAtmoThread)
{
m_pAtmoThread->p_thread = this;
this->m_pOwner = pOwner;
vlc_object_attach( m_pAtmoThread, m_pOwner);
vlc_mutex_init( &m_TerminateLock );
vlc_cond_init( &m_TerminateCond );
}
vlc_mutex_init( &m_TerminateLock );
vlc_cond_init( &m_TerminateCond );
m_pOwner = pOwner;
m_HasThread = ATMO_FALSE;
}
#else
......@@ -51,12 +44,9 @@ CThread::CThread(void)
CThread::~CThread(void)
{
if(m_pAtmoThread)
{
vlc_mutex_destroy( &m_TerminateLock );
vlc_cond_destroy( &m_TerminateCond );
vlc_object_release(m_pAtmoThread);
}
assert(m_HasThread == ATMO_FALSE);
vlc_mutex_destroy( &m_TerminateLock );
vlc_cond_destroy( &m_TerminateCond );
}
#else
......@@ -71,17 +61,14 @@ CThread::~CThread(void)
#if defined(_ATMO_VLC_PLUGIN_)
void *CThread::ThreadProc(vlc_object_t *obj)
void *CThread::ThreadProc(void *obj)
{
atmo_thread_t *pAtmoThread = (atmo_thread_t *)obj;
CThread *pThread = (CThread *)pAtmoThread->p_thread;
if(pThread) {
int canc;
canc = vlc_savecancel ();
pThread->Execute();
vlc_restorecancel (canc);
}
CThread *pThread = static_cast<CThread*>(obj);
int canc = vlc_savecancel ();
pThread->Execute();
vlc_restorecancel (canc);
return NULL;
}
......@@ -117,15 +104,15 @@ void CThread::Terminate(void)
// and wait for Termination
#if defined(_ATMO_VLC_PLUGIN_)
if(m_pAtmoThread)
if(m_HasThread != ATMO_FALSE)
{
vlc_mutex_lock( &m_TerminateLock );
m_bTerminated = ATMO_TRUE;
vlc_cond_signal( &m_TerminateCond );
vlc_mutex_unlock( &m_TerminateLock );
vlc_object_kill( m_pAtmoThread );
vlc_thread_join( m_pAtmoThread );
vlc_cancel( m_Thread );
vlc_join( m_Thread, NULL );
}
#else
m_bTerminated = ATMO_TRUE;
......@@ -139,12 +126,14 @@ void CThread::Run()
m_bTerminated = ATMO_FALSE;
#if defined(_ATMO_VLC_PLUGIN_)
m_pAtmoThread->b_die = false;
if(vlc_thread_create( m_pAtmoThread,
CThread::ThreadProc,
VLC_THREAD_PRIORITY_LOW ))
if (vlc_clone( &m_Thread, CThread::ThreadProc, this, VLC_THREAD_PRIORITY_LOW))
{
m_HasThread = ATMO_FALSE;
msg_Err( m_pOwner, "cannot launch one of the AtmoLight threads");
}
else
{
msg_Err( m_pOwner, "cannot launch one of the AtmoLight threads");
m_HasThread = ATMO_TRUE;;
}
#else
......
......@@ -15,13 +15,6 @@
// use threading stuff from videolan!
# include <vlc_common.h>
# include <vlc_threads.h>
typedef struct
{
VLC_COMMON_MEMBERS
void *p_thread; /* cast to CThread * */
} atmo_thread_t;
#else
# include <windows.h>
#endif
......@@ -32,10 +25,11 @@ protected:
#if defined(_ATMO_VLC_PLUGIN_)
atmo_thread_t *m_pAtmoThread;
vlc_mutex_t m_TerminateLock;
vlc_cond_t m_TerminateCond;
vlc_object_t *m_pOwner;
ATMO_BOOL m_HasThread;
vlc_thread_t m_Thread;
#else
......@@ -50,7 +44,7 @@ protected:
private:
#if defined(_ATMO_VLC_PLUGIN_)
static void *ThreadProc(vlc_object_t *);
static void *ThreadProc(void *);
#else
static DWORD WINAPI ThreadProc(LPVOID lpParameter);
#endif
......
......@@ -43,6 +43,7 @@
#include <vlc_playlist.h>
#include <vlc_filter.h>
#include <vlc_atomic.h>
#include "filter_picture.h"
......@@ -699,8 +700,10 @@ static const char *const ppsz_filter_options[] = {
*/
typedef struct
{
VLC_COMMON_MEMBERS
filter_t *p_filter;
filter_t *p_filter;
vlc_thread_t thread;
vlc_atomic_t abort;
/* tell the thread which color should be the target of fading */
uint8_t ui_red;
uint8_t ui_green;
......@@ -710,7 +713,7 @@ typedef struct
} fadethread_t;
static void *FadeToColorThread(vlc_object_t *);
static void *FadeToColorThread(void *);
/*****************************************************************************
......@@ -1105,9 +1108,7 @@ static void Atmo_Shutdown(filter_t *p_filter)
p_sys->b_pause_live = true;
p_sys->p_fadethread = (fadethread_t *)vlc_object_create( p_filter,
sizeof(fadethread_t) );
p_sys->p_fadethread = (fadethread_t *)calloc( 1, sizeof(fadethread_t) );
p_sys->p_fadethread->p_filter = p_filter;
p_sys->p_fadethread->ui_red = p_sys->ui_endcolor_red;
p_sys->p_fadethread->ui_green = p_sys->ui_endcolor_green;
......@@ -1116,13 +1117,15 @@ static void Atmo_Shutdown(filter_t *p_filter)
p_sys->p_fadethread->i_steps = 1;
else
p_sys->p_fadethread->i_steps = p_sys->i_endfadesteps;
vlc_atomic_set(&p_sys->p_fadethread->abort, 0);
if( vlc_thread_create( p_sys->p_fadethread,
FadeToColorThread,
VLC_THREAD_PRIORITY_LOW ) )
if( vlc_clone( &p_sys->p_fadethread->thread,
FadeToColorThread,
p_sys->p_fadethread,
VLC_THREAD_PRIORITY_LOW ) )
{
msg_Err( p_filter, "cannot create FadeToColorThread" );
vlc_object_release( p_sys->p_fadethread );
free( p_sys->p_fadethread );
p_sys->p_fadethread = NULL;
vlc_mutex_unlock( &p_sys->filter_lock );
......@@ -1131,9 +1134,9 @@ static void Atmo_Shutdown(filter_t *p_filter)
vlc_mutex_unlock( &p_sys->filter_lock );
/* wait for the thread... */
vlc_thread_join(p_sys->p_fadethread);
vlc_join(p_sys->p_fadethread->thread, NULL);
vlc_object_release(p_sys->p_fadethread);
free(p_sys->p_fadethread);
p_sys->p_fadethread = NULL;
}
......@@ -2323,7 +2326,7 @@ static picture_t * Filter( filter_t *p_filter, picture_t *p_pic )
* to a target color defined in p_fadethread struct
* use for: Fade to Pause Color, and Fade to End Color
*****************************************************************************/
static void *FadeToColorThread(vlc_object_t *obj)
static void *FadeToColorThread(void *obj)
{
fadethread_t *p_fadethread = (fadethread_t *)obj;
filter_sys_t *p_sys = (filter_sys_t *)p_fadethread->p_filter->p_sys;
......@@ -2366,7 +2369,7 @@ static void *FadeToColorThread(vlc_object_t *obj)
/* send the same pixel data again... to unlock the buffer! */
AtmoSendPixelData( p_fadethread->p_filter );
while( (vlc_object_alive (p_fadethread)) &&
while( (!vlc_atomic_get (&p_fadethread->abort)) &&
(i_steps_done < p_fadethread->i_steps))
{
p_transfer = AtmoLockTransferBuffer( p_fadethread->p_filter );
......@@ -2379,7 +2382,7 @@ static void *FadeToColorThread(vlc_object_t *obj)
thread improvements wellcome!
*/
for(i_index = 0;
(i_index < i_size) && (vlc_object_alive (p_fadethread));
(i_index < i_size) && (!vlc_atomic_get (&p_fadethread->abort));
i_index+=4)
{
i_src_blue = p_source[i_index+0];
......@@ -2435,11 +2438,10 @@ static void CheckAndStopFadeThread(filter_t *p_filter)
{
msg_Dbg(p_filter, "kill still running fadeing thread...");
p_sys->p_fadethread->b_die = true;
vlc_atomic_set(&p_sys->p_fadethread->abort, 1);
vlc_thread_join(p_sys->p_fadethread);
vlc_object_release(p_sys->p_fadethread);
vlc_join(p_sys->p_fadethread->thread, NULL);
free(p_sys->p_fadethread);
p_sys->p_fadethread = NULL;
}
vlc_mutex_unlock( &p_sys->filter_lock );
......@@ -2478,22 +2480,21 @@ static int StateCallback( vlc_object_t *, char const *,
*/
if(p_sys->p_fadethread == NULL)
{
p_sys->p_fadethread = (fadethread_t *)vlc_object_create(
p_filter,
sizeof(fadethread_t) );
p_sys->p_fadethread = (fadethread_t *)calloc( 1, sizeof(fadethread_t) );
p_sys->p_fadethread->p_filter = p_filter;
p_sys->p_fadethread->ui_red = p_sys->ui_pausecolor_red;
p_sys->p_fadethread->ui_green = p_sys->ui_pausecolor_green;
p_sys->p_fadethread->ui_blue = p_sys->ui_pausecolor_blue;
p_sys->p_fadethread->i_steps = p_sys->i_fadesteps;
vlc_atomic_set(&p_sys->p_fadethread->abort, 0);
if( vlc_thread_create( p_sys->p_fadethread,
FadeToColorThread,
VLC_THREAD_PRIORITY_LOW ) )
if( vlc_clone( &p_sys->p_fadethread->thread,
FadeToColorThread,
p_sys->p_fadethread,
VLC_THREAD_PRIORITY_LOW ) )
{
msg_Err( p_filter, "cannot create FadeToColorThread" );
vlc_object_release( p_sys->p_fadethread );
free( p_sys->p_fadethread );
p_sys->p_fadethread = NULL;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment