List Info

Thread: CR:Changes to fix the Xlib crash happening during the playback with UI for LitePl




CR:Changes to fix the Xlib crash happening during the playback with UI for LitePl
country flaguser name
India
2008-04-24 03:55:27
Synopsis:
Changes to fix the Xlib crash happening during the playback
with UI for 
LitePlayer.

Overview:
When we were playing a rm/wm file with UI, we were getting
*Xlib: 
unexpected async reply message* because we were blitting on
multiple 
threads. Now we have scheduled a callback before call to 
_MinimalBlt(baseroot.cpp) and _UpdateOverlay(basesurf.cpp)
if we detect 
that we are not on the main gtk thread. When the callback
occurs, the 
callback occurs on the main thread and we call
_MinimalBlt(baseroot.cpp) 
and _UpdateOverlay(basesurf.cpp). This does the blitting on
the main 
thread.

Files Added:
/video/sitelib/linux2.pcf

Files Modified:
/video/sitelib/baseroot.cpp
/video/sitelib/basesurf.cpp
/video/sitelib/pub/basesurf.h
/video/sitelib/pub/baseroot.h

Image Size and Heap Use impact (Client -Only):
None.

Platforms and Profiles Affected:
None

Distribution Libraries Affected:
None

Distribution library impact and planned action:
None

Platforms and Profiles Build Verified:
BIF branch    -> wombat
Target(s)      ->  LitePlayerWombat
Profile          -> helix-client-moblin
SYSTEM_ID -> linux-2.2-libc6-gcc32-i586

Branch:
hxclient_3_1_0_atlas, HEAD

Files Attached:
sitelib_diff.txt
linux2.pcf

Thanks,
Deepak Jain

_______________________________________________
Helix-client-dev mailing list
Helix-client-devhelixcommunity.org
http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev

  
  
Changes to fix the Xlib crash happening during the playback with U
country flaguser name
India
2008-04-24 06:22:08
Resending the updated diff.

Thanks,
Deepak Jain

Deepak Jain wrote:
> Synopsis:
> Changes to fix the Xlib crash happening during the
playback with UI 
> for LitePlayer.
>
> Overview:
> When we were playing a rm/wm file with UI, we were
getting *Xlib: 
> unexpected async reply message* because we were
blitting on multiple 
> threads. Now we have scheduled a callback before call
to 
> _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp) if we 
> detect that we are not on the main gtk thread. When the
callback 
> occurs, the callback occurs on the main thread and we
call 
> _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp). This does 
> the blitting on the main thread.
>
> Files Added:
> /video/sitelib/linux2.pcf
>
> Files Modified:
> /video/sitelib/baseroot.cpp
> /video/sitelib/basesurf.cpp
> /video/sitelib/pub/basesurf.h
> /video/sitelib/pub/baseroot.h
>
> Image Size and Heap Use impact (Client -Only):
> None.
>
> Platforms and Profiles Affected:
> None
>
> Distribution Libraries Affected:
> None
>
> Distribution library impact and planned action:
> None
>
> Platforms and Profiles Build Verified:
> BIF branch    -> wombat
> Target(s)      ->  LitePlayerWombat
> Profile          -> helix-client-moblin
> SYSTEM_ID -> linux-2.2-libc6-gcc32-i586
>
> Branch:
> hxclient_3_1_0_atlas, HEAD
>
> Files Attached:
> sitelib_diff.txt
> linux2.pcf
>
> Thanks,
> Deepak Jain
>
------------------------------------------------------------
------------
>
> # on gcc we want to turn on all warnings
> extra_cflags = ""
> using_gcc = 0
> if string.find(platform.cc.cmd, 'gcc') != -1:
>     using_gcc = 1
>     extra_cflags = "-Wall"
>
> # grab flags from pkgconfig
> import shell
> import string
>
> # see if we're using the target gtk version (triggers
setting of the
> # DISABLE_DEPRECATED flag)
>
> (exitstatus, gtk_mod_version) =
shell.run("pkg-config --modversion gtk+-2.0")
> if exitstatus != 0:
> 	e = err.Error()
> 	e.Set("pkg-config failed")
> 	raise err.error, e
>
> if string.find(gtk_mod_version, "2.0") == 0:
> 	project.AddDefines('G_DISABLE_DEPRECATED',
> 					   'GDK_DISABLE_DEPRECATED',
> 					   'GTK_DISABLE_DEPRECATED')
>
> pkg_modules = "gtk+-2.0"
>
> if project.IsDefined('HELIX_FEATURE_LIBGLADE'):
> 	pkg_modules = pkg_modules + " libglade-2.0
gmodule-2.0"
>
> (exitstatus, gtk_config_output_cflags) =
shell.run("pkg-config --cflags " + pkg_modules)
> (exitstatus, gtk_config_output_ldflags) =
shell.run("pkg-config --libs " + pkg_modules)
>
> gtk_cflags = string.split(gtk_config_output_cflags)
> gtk_ldflags = string.split(gtk_config_output_ldflags)
>
> gtk_ld_paths = []
> gtk_libs = []
> gtk_includes = []
> gtk_defines = []
> gtk_other_cflags = ""
> gtk_other_ldflags = ""
>
> for x in gtk_cflags:
> 		if x[0:2] == '-I':
> 				gtk_includes[-1:-1] = [ x[2:] ]
> 		elif x[0:2] == '-D':
> 				gtk_defines[-1:-1] = [ x[2:] ]
> 		else:
> 				gtk_other_cflags = gtk_other_cflags + " "
+ x
>
> for x in gtk_ldflags:
> 		if x[0:2] == '-l':
> 				gtk_libs[-1:-1] = [ x[2:] ]
> 		elif x[0:2] == '-L':
> 				gtk_ld_paths[-1:-1] = [ x ]
> 		else:
> 				gtk_other_ldflags = gtk_other_ldflags + "
" + x                
>
> # add the flags
> project.AddSystemLibraries(gtk_libs)
> project.AddIncludes(gtk_includes)
> project.AddSystemPaths(gtk_ld_paths)
> project.AddDefines(gtk_defines)
>
> platform.cc.args["default"] =
platform.cc.args["default"] + " " +
gtk_other_cflags + " " + extra_cflags
> platform.cxx.args["default"] =
platform.cxx.args["default"] + " " +
gtk_other_cflags + " " + extra_cflags
>
> # platform.link.args["default"] =
platform.link.args["default"] + " " +
gtk_other_ldflags
> project.AddDynamicLibraries(gtk_other_ldflags)
>   
>
------------------------------------------------------------
------------
>
> Index: sitelib/baseroot.cpp
>
============================================================
=======
> RCS file: /cvsroot/video/sitelib/baseroot.cpp,v
> retrieving revision 1.12
> diff -u -r1.12 baseroot.cpp
> --- sitelib/baseroot.cpp	6 Jul 2007 20:53:58
-0000	1.12
> +++ sitelib/baseroot.cpp	24 Apr 2008 07:47:11 -0000
>  -123,6 +123,10 
>      , m_bUseCardMemory(FALSE)
>      , m_pUnlockingSite(NULL)
>      , zm_pColorAcc(NULL)
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +    , m_MainThreadID(0)
> +    , m_pMutexMinimalBlt(NULL)
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>  {
>  #ifdef _BLT_IN_DEBUG
>     m_nBLTMode = HX_WINDOWLESS_DEBUG;
>  -134,7 +138,10 
>     HX_ASSERT( m_pSite );
>     m_pContext->AddRef();
>     m_pSite->AddRef();
> -
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +	m_MainThreadID = pthread_self();
> +	CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pMutexMinimalBlt, m_pContext);
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>     CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pMutex, m_pContext);
>     CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pCompMutex, m_pContext);
>  
>  -190,7 +197,14 
>  #ifdef _WINDOWS
>     HX_RELEASE(m_pPlayer);
>  #endif
> -
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +	while(!m_listTimeOutCallback.IsEmpty())
> +	{
> +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
> +		g_source_remove (id);
> +	}
> +	HX_RELEASE(m_pMutexMinimalBlt);
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>     HX_RELEASE(m_pMutex);
>     HX_RELEASE(m_pCompMutex);
>     HX_RELEASE(m_pContext);
>  -271,6 +285,25 
>      }
>  }
>  
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +struct GtkInfoMinimalBlt
> +{	
> +	CBaseRootSurface* 	pBase;	
> +	HXxRect         	rDestRect;	
> +};
> +gboolean
CBaseRootSurface::CallbackToMinimalBlt(gpointer data)
> +{
> +	GtkInfoMinimalBlt* pGtkInfoMinimalBlt =
(GtkInfoMinimalBlt*)data;	
>
+	pGtkInfoMinimalBlt->pBase->_MinimalBlt(pGtkInfoMinim
alBlt->rDestRect);
>
+	if(!pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback
.IsEmpty())
> +	{	
>
+		pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback.Re
moveHead();
> +	}
> +	HX_DELETE(pGtkInfoMinimalBlt);	
> +	return FALSE;
> +}
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> +
>  STDMETHODIMP CBaseRootSurface::Blt( UCHAR*            
  pImageData,
>                                     
HXBitmapInfoHeader* pBitmapInfo,
>                                      REF(HXxRect)      
  rDestRect,
>  -532,7 +565,26 
>                                           
rSrcRect.left, rSrcRect.top, dxSrc, dySrc);
>  
>              if( !m_pSite->IsCompositionLocked()
&& returnVal != -1)
> +            {
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +            	unsigned int cur_thread =
pthread_self();
> +				if (cur_thread != m_MainThreadID)
> +				{	
> +	            	GtkInfoMinimalBlt* ptr = new
GtkInfoMinimalBlt;
> +					guint id = 0;
> +	            	ptr->pBase = this;	
> +	            	ptr->rDestRect = rDestRect;	
> +	            	id = g_timeout_add(0,
CallbackToMinimalBlt, (gpointer*)ptr);
> +					m_listTimeOutCallback.AddTail((void*)id);
> +		    		return HXR_OK;
> +				}
> +				m_pMutexMinimalBlt->Lock();
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>                  _MinimalBlt(rDestRect);
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +				m_pMutexMinimalBlt->Unlock();
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> +            }
>           }
>        }
>        if (!returnVal)
> Index: sitelib/basesurf.cpp
>
============================================================
=======
> RCS file: /cvsroot/video/sitelib/basesurf.cpp,v
> retrieving revision 1.34
> diff -u -r1.34 basesurf.cpp
> --- sitelib/basesurf.cpp	1 Aug 2007 00:11:31
-0000	1.34
> +++ sitelib/basesurf.cpp	24 Apr 2008 07:47:15 -0000
>  -185,6 +185,9 
>      , m_bImageBlocksGood(FALSE)
>      , m_pOverlayManager(NULL)
>      , m_bAllowOverlayShrinking(FALSE)
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +    , m_IDMainThread(0)
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>  {
>      HX_ASSERT( m_pContext );
>      m_pContext->AddRef();
>  -201,6 +204,10 
>      m_TimeStamps.Init(m_pContext, this);
>  #endif
>  
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +    m_IDMainThread = pthread_self();
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> +
>      IHXPreferences* pPreferences = NULL;
>      IHXBuffer*      pBuffer      = NULL;
>      HXFLOAT         fTmp         =
(float)m_fScrollBarZoom;
>  -235,6 +242,13 
>      HX_DELETE(m_pHwMemObj);
>  
>      HX_RELEASE(m_pRootSurface);
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +    while(!m_listTimeOutCallback.IsEmpty())
> +    {
> +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
> +		g_source_remove (id);
> +    }
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>  
>      // CBaseSite:estroy
calls EndOptimizedBlt.  We can't call
>      // EndOptimizedBlt from the destructor since it
calls DestroySurfaces
>  -3811,6 +3825,27 
>      m_nUpdateOverlayByPassCount =
OVERLAY_BYPASS_THRESHOLD+1;
>  }
>  
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +struct GtkMainUpdateOverlay
> +{	
> +	CBaseSurface* 		pBase;	
> +	HXxRect         	rDestRect;
> +	HXxRect				rSrcRect;
> +	INT32				rflags;
> +};
> +gboolean
CBaseSurface::CallbackToUpdateOverlay(gpointer data)
> +{
> +	GtkMainUpdateOverlay* pGtkMainUpdateOverlay =
(GtkMainUpdateOverlay*)data;	
>
+	pGtkMainUpdateOverlay->pBase->_UpdateOverlay(&pG
tkMainUpdateOverlay->rDestRect,
&pGtkMainUpdateOverlay->rSrcRect,
pGtkMainUpdateOverlay->rflags);	
>
+	if(!pGtkMainUpdateOverlay->pBase->m_listTimeOutCallb
ack.IsEmpty())
> +	{	
>
+		pGtkMainUpdateOverlay->pBase->m_listTimeOutCallback
.RemoveHead();
> +	}
> +	HX_DELETE(pGtkMainUpdateOverlay);	
> +	return FALSE;
> +}
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> +
>  HX_RESULT CBaseSurface::UpdateOverlay(  REF(HXxRect)
/*IN*/  rDestRect,
>                                          REF(HXxRect)
/*IN*/  rSrcRect,
>                                          int x, int y)
>  -3993,6 +4028,21 
>              m_nUpdateOverlayByPassCount = 0;
>              memcpy(&m_lastUpdateDestRect,
&destRect, sizeof(HXxRect)); /* Flawfinder: ignore */
>              memcpy(&m_lastUpdateSrcRect, 
&srcRect,  sizeof(HXxRect)); /* Flawfinder: ignore */
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +			unsigned int cur_thread = pthread_self();
> +			if (cur_thread != m_IDMainThread)
> +			{
> +				GtkMainUpdateOverlay* ptr = new
GtkMainUpdateOverlay;	
> +				guint id = 0;
> +				ptr->pBase = this;	
> +				ptr->rDestRect = destRect;	
> +				ptr->rSrcRect = srcRect;
> +				ptr->rflags = flags;
> +				id = g_timeout_add(0, CallbackToUpdateOverlay,
(gpointer*)ptr);	
> +				m_listTimeOutCallback.AddTail((void*)id);				
> +				return HXR_OK;
> +			}
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>              _UpdateOverlay(&destRect,
&srcRect, flags);
>  #ifdef _CHECK_PERFORMANCE
>              NumOfUpdateOverlays++;       
> Index: sitelib/pub/baseroot.h
>
============================================================
=======
> RCS file: /cvsroot/video/sitelib/pub/baseroot.h,v
> retrieving revision 1.8
> diff -u -r1.8 baseroot.h
> --- sitelib/pub/baseroot.h	6 Jul 2007 20:54:02
-0000	1.8
> +++ sitelib/pub/baseroot.h	24 Apr 2008 07:47:17 -0000
>  -52,7 +52,12 
>  #include "hxengin.h"
>  #include "hxslist.h"
>  #include "baseobj.h"
> -
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +#include <glib/gtypes.h>
> +#include <gtk/gtk.h>
> +#include <glib.h>
> +#include <pthread.h>
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>  #ifndef _BASEROOT_H_
>  #define _BASEROOT_H_
>  
>  -148,7 +153,12 
>      void         UnlockCompMutex();
>  
>      ColorFuncAccess* GetColorAccess() {return
zm_pColorAcc;}
> -   
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +   unsigned int m_MainThreadID;
> +   static gboolean CallbackToMinimalBlt(gpointer
data);
> +   CHXSimpleList m_listTimeOutCallback;
> +   IHXMutex*    m_pMutexMinimalBlt;
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD 
>  protected:
>      IHXMutex*    m_pMutex;
>      IHXMutex*    m_pCompMutex;
> Index: sitelib/pub/basesurf.h
>
============================================================
=======
> RCS file: /cvsroot/video/sitelib/pub/basesurf.h,v
> retrieving revision 1.11
> diff -u -r1.11 basesurf.h
> --- sitelib/pub/basesurf.h	6 Jul 2007 20:54:03
-0000	1.11
> +++ sitelib/pub/basesurf.h	24 Apr 2008 07:47:18 -0000
>  -58,6 +58,12 
>  #include "hxwin.h"
>  #include "baseobj.h"
>  
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +#include <glib/gtypes.h>
> +#include <gtk/gtk.h>
> +#include <glib.h>
> +#include <pthread.h>
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>  #if !defined(_GOLD) && 0
>  #include "timestmp.h"    
>  #endif
>  -237,6 +243,12 
>  
>      HXxSize* GetSurfaceSize()   {return
&m_surfaceSize;}
>  
> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> +    unsigned int m_IDMainThread;
> +    static gboolean CallbackToUpdateOverlay(gpointer
data);
> +    CHXSimpleList m_listTimeOutCallback;
> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> +
>  private:
>     
>      CBaseSurface();
>   
>
------------------------------------------------------------
------------
>
> _______________________________________________
> Helix-client-dev mailing list
> Helix-client-devhelixcommunity.org
> http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev
>   


_______________________________________________
Helix-client-dev mailing list
Helix-client-devhelixcommunity.org
http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev

  
RE: Changes to fix the Xlib crash happening during the playback wi
country flaguser name
United States
2008-04-24 11:06:23
Deepak,

Here are my comments:

1) Did you try Milko and Rahul's suggestion? Here
   it is as I understand it:
     - Check the thread id right after we enter
       CBaseSurface::Blt() or CBaseSurface::BltSubRects()
     - If we are not on the thread we were created on,
       then save m_pSite into our callback struct
       and schedule the callback and then exit
       CBaseSurface::Blt() or CBaseSurface::BltSubRects().
     - When the callback fires, then call
m_pSite->ForceRedraw().
       This will synchronously call back into Blt() with
the
       most up-to-date frame, but now on the main thread.

   I seem to remember in your status email you said
something about
   frames being dropped. Why were frames being dropped?
Where
   were they being dropped? In CBaseSurface or in the base
video
   renderer? Also, I'd like to know a few other things:
     - how long (min, avg, max) is it between scheduling
       the callback with g_timeout_add(0,..) and the
callback
       actually executing?
     - how often does this happen: you get a blt on a
       non-main thread, so you schedule a callback. In
between
       the time the callback is scheduled and the time it
fires,
       you get a blt on the main thread (so that blt goes
through).

   Overall, I think we should try to make this suggestion
work.
   Or if it's not working, we need to understand why it
doesn't work.
   If we can make this work, then the fix becomes a lot
simpler:
   we don't have to worry about whether we are in overlay
mode
   or basic_blt mode, etc.

   The rest of my comments have to do with the fix as it
currently
   stands. But top priority is to try the suggestion above
and
   either get it work, or understand why it doesn't work.

2) If we stick with what you currently have (and for some
reason
   Milko and Rahul's suggestion above does not work), then 
   I think we won't need the mutexes after all. The reason
is
   that access to the CBaseRootSurface is mutex protected
   already. Note the code in CBaseSurface::Blt() here
   (just for the HX_BASIC_BLT mode):

        while( HXR_OK != pSurface->Lock(0))

   This is calling a Lock() on a mutex inside of
CBaseRootSurface().
   So at least for the HX_BASIC_BLT mode, we won't need
   to add a separate mutex inside of CBaseRootSurface().

   However, you will need to call pBase->Lock() and
   pBase->Unlock() on either side of your call to
   pBase->_MinimalBlt().
   
3) In your callbacks for UpdateOverlay(), the problem I
   see is that we have rotating buffers. From my looking
   at the code, it looks like the base surface calls
   _LockInternalSurface(), which chooses from a ring of
   buffers. (Usually it's 2, but it could be more than 2.)
   Then it writes into that buffer and then calls
UpdateOverlay(),
   which calls XvShmPutImage() or XvPutImage() on the
current
   buffer.

   The problem is that another blt on the main thread could
come
   in between the time that the callback is scheduled and 
   the callback executes. In that case, the "current
buffer"
   switches and so the srcRect, dstRect, and flags you
saved
   are no longer valid for the current image.

   So I think in your callback we should be using the
   saved m_lastUpdateDestRect and m_lastUpdateSrcRect. I
guess
   since flags are not currently saved, we'll have to save
   them as well.

4) Instead of HELIX_CONFIG_USE_GTKMAIN_THREAD,
   let's call it something more descriptive like 
   HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD

5) Instead of using pthread_self() to get the
   current thread ID, you can use the cross-platform
   HXGetCurrentThreadID() defined in
   commonsystempubthrdutil.h.

6) +    unsigned int m_IDMainThread;

   +   unsigned int m_MainThreadID;
  
   These should be UINT32, since HXGetCurrentThreadID()
   returns UINT32.


Thanks,

Eric

=============================================
Eric Hyche (ehychereal.com)
Technical Lead
RealNetworks, Inc.  

> -----Original Message-----
> From: helix-client-dev-bounceshelixcommunity.org 
> [mailto:helix-client-dev-bounceshelixcommunity.org] On 
> Behalf Of Deepak Jain
> Sent: Thursday, April 24, 2008 7:22 AM
> To: video-devhelixcommunity.org; helix-client-devhelixcommunity.org
> Subject: [Helix-client-dev] CR:[RESENDING] Changes to
fix the 
> Xlib crash happening during the playback with UI for
LitePlayer.
> 
> Resending the updated diff.
> 
> Thanks,
> Deepak Jain
> 
> Deepak Jain wrote:
> > Synopsis:
> > Changes to fix the Xlib crash happening during the
playback with UI 
> > for LitePlayer.
> >
> > Overview:
> > When we were playing a rm/wm file with UI, we were
getting *Xlib: 
> > unexpected async reply message* because we were
blitting on 
> multiple 
> > threads. Now we have scheduled a callback before
call to 
> > _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp) if we 
> > detect that we are not on the main gtk thread.
When the callback 
> > occurs, the callback occurs on the main thread and
we call 
> > _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp). 
> This does 
> > the blitting on the main thread.
> >
> > Files Added:
> > /video/sitelib/linux2.pcf
> >
> > Files Modified:
> > /video/sitelib/baseroot.cpp
> > /video/sitelib/basesurf.cpp
> > /video/sitelib/pub/basesurf.h
> > /video/sitelib/pub/baseroot.h
> >
> > Image Size and Heap Use impact (Client -Only):
> > None.
> >
> > Platforms and Profiles Affected:
> > None
> >
> > Distribution Libraries Affected:
> > None
> >
> > Distribution library impact and planned action:
> > None
> >
> > Platforms and Profiles Build Verified:
> > BIF branch    -> wombat
> > Target(s)      ->  LitePlayerWombat
> > Profile          -> helix-client-moblin
> > SYSTEM_ID -> linux-2.2-libc6-gcc32-i586
> >
> > Branch:
> > hxclient_3_1_0_atlas, HEAD
> >
> > Files Attached:
> > sitelib_diff.txt
> > linux2.pcf
> >
> > Thanks,
> > Deepak Jain
> > 
>
------------------------------------------------------------
--
> ----------
> >
> > # on gcc we want to turn on all warnings
> > extra_cflags = ""
> > using_gcc = 0
> > if string.find(platform.cc.cmd, 'gcc') != -1:
> >     using_gcc = 1
> >     extra_cflags = "-Wall"
> >
> > # grab flags from pkgconfig
> > import shell
> > import string
> >
> > # see if we're using the target gtk version
(triggers setting of the
> > # DISABLE_DEPRECATED flag)
> >
> > (exitstatus, gtk_mod_version) =
shell.run("pkg-config 
> --modversion gtk+-2.0")
> > if exitstatus != 0:
> > 	e = err.Error()
> > 	e.Set("pkg-config failed")
> > 	raise err.error, e
> >
> > if string.find(gtk_mod_version, "2.0")
== 0:
> > 	project.AddDefines('G_DISABLE_DEPRECATED',
> > 					   'GDK_DISABLE_DEPRECATED',
> > 					   'GTK_DISABLE_DEPRECATED')
> >
> > pkg_modules = "gtk+-2.0"
> >
> > if project.IsDefined('HELIX_FEATURE_LIBGLADE'):
> > 	pkg_modules = pkg_modules + " libglade-2.0
gmodule-2.0"
> >
> > (exitstatus, gtk_config_output_cflags) = 
> shell.run("pkg-config --cflags " +
pkg_modules)
> > (exitstatus, gtk_config_output_ldflags) = 
> shell.run("pkg-config --libs " +
pkg_modules)
> >
> > gtk_cflags =
string.split(gtk_config_output_cflags)
> > gtk_ldflags =
string.split(gtk_config_output_ldflags)
> >
> > gtk_ld_paths = []
> > gtk_libs = []
> > gtk_includes = []
> > gtk_defines = []
> > gtk_other_cflags = ""
> > gtk_other_ldflags = ""
> >
> > for x in gtk_cflags:
> > 		if x[0:2] == '-I':
> > 				gtk_includes[-1:-1] = [ x[2:] ]
> > 		elif x[0:2] == '-D':
> > 				gtk_defines[-1:-1] = [ x[2:] ]
> > 		else:
> > 				gtk_other_cflags = 
> gtk_other_cflags + " " + x
> >
> > for x in gtk_ldflags:
> > 		if x[0:2] == '-l':
> > 				gtk_libs[-1:-1] = [ x[2:] ]
> > 		elif x[0:2] == '-L':
> > 				gtk_ld_paths[-1:-1] = [ x ]
> > 		else:
> > 				gtk_other_ldflags = 
> gtk_other_ldflags + " " + x                
> >
> > # add the flags
> > project.AddSystemLibraries(gtk_libs)
> > project.AddIncludes(gtk_includes)
> > project.AddSystemPaths(gtk_ld_paths)
> > project.AddDefines(gtk_defines)
> >
> > platform.cc.args["default"] =
platform.cc.args["default"] + 
> " " + gtk_other_cflags + " " +
extra_cflags
> > platform.cxx.args["default"] =
platform.cxx.args["default"] 
> + " " + gtk_other_cflags + " " +
extra_cflags
> >
> > # platform.link.args["default"] = 
> platform.link.args["default"] + " "
+ gtk_other_ldflags
> > project.AddDynamicLibraries(gtk_other_ldflags)
> >   
> > 
>
------------------------------------------------------------
--
> ----------
> >
> > Index: sitelib/baseroot.cpp
> >
============================================================
=======
> > RCS file: /cvsroot/video/sitelib/baseroot.cpp,v
> > retrieving revision 1.12
> > diff -u -r1.12 baseroot.cpp
> > --- sitelib/baseroot.cpp	6 Jul 2007 20:53:58
-0000	1.12
> > +++ sitelib/baseroot.cpp	24 Apr 2008 07:47:11
-0000
> >  -123,6 +123,10 
> >      , m_bUseCardMemory(FALSE)
> >      , m_pUnlockingSite(NULL)
> >      , zm_pColorAcc(NULL)
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +    , m_MainThreadID(0)
> > +    , m_pMutexMinimalBlt(NULL)
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >  {
> >  #ifdef _BLT_IN_DEBUG
> >     m_nBLTMode = HX_WINDOWLESS_DEBUG;
> >  -134,7 +138,10 
> >     HX_ASSERT( m_pSite );
> >     m_pContext->AddRef();
> >     m_pSite->AddRef();
> > -
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +	m_MainThreadID = pthread_self();
> > +	CreateInstanceCCF(CLSID_IHXMutex, 
> (void**)&m_pMutexMinimalBlt, m_pContext);
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >     CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pMutex, 
> m_pContext);
> >     CreateInstanceCCF(CLSID_IHXMutex, 
> (void**)&m_pCompMutex, m_pContext);
> >  
> >  -190,7 +197,14 
> >  #ifdef _WINDOWS
> >     HX_RELEASE(m_pPlayer);
> >  #endif
> > -
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +	while(!m_listTimeOutCallback.IsEmpty())
> > +	{
> > +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
> > +		g_source_remove (id);
> > +	}
> > +	HX_RELEASE(m_pMutexMinimalBlt);
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >     HX_RELEASE(m_pMutex);
> >     HX_RELEASE(m_pCompMutex);
> >     HX_RELEASE(m_pContext);
> >  -271,6 +285,25 
> >      }
> >  }
> >  
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +struct GtkInfoMinimalBlt
> > +{	
> > +	CBaseRootSurface* 	pBase;	
> > +	HXxRect         	rDestRect;	
> > +};
> > +gboolean
CBaseRootSurface::CallbackToMinimalBlt(gpointer data)
> > +{
> > +	GtkInfoMinimalBlt* pGtkInfoMinimalBlt = 
> (GtkInfoMinimalBlt*)data;	
> > +	
>
pGtkInfoMinimalBlt->pBase->_MinimalBlt(pGtkInfoMinimal
Blt->rDestRect);
> >
+	if(!pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback
.IsEmpty())
> > +	{	
> > +		
>
pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback.Remov
eHead();
> > +	}
> > +	HX_DELETE(pGtkInfoMinimalBlt);	
> > +	return FALSE;
> > +}
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +
> >  STDMETHODIMP CBaseRootSurface::Blt( UCHAR*       
       
> pImageData,
> >                                     
HXBitmapInfoHeader* 
> pBitmapInfo,
> >                                      REF(HXxRect) 
       rDestRect,
> >  -532,7 +565,26 
> >                                           
rSrcRect.left, 
> rSrcRect.top, dxSrc, dySrc);
> >  
> >              if(
!m_pSite->IsCompositionLocked() && returnVal !=
-1)
> > +            {
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +            	unsigned int cur_thread =
pthread_self();
> > +				if (cur_thread != m_MainThreadID)
> > +				{	
> > +	            	GtkInfoMinimalBlt* ptr = new
GtkInfoMinimalBlt;
> > +					guint id = 0;
> > +	            	ptr->pBase = this;	
> > +	            	ptr->rDestRect = rDestRect;	
> > +	            	id = g_timeout_add(0, 
> CallbackToMinimalBlt, (gpointer*)ptr);
> > +					
> m_listTimeOutCallback.AddTail((void*)id);
> > +		    		return HXR_OK;
> > +				}
> > +				m_pMutexMinimalBlt->Lock();
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >                  _MinimalBlt(rDestRect);
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +				m_pMutexMinimalBlt->Unlock();
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +            }
> >           }
> >        }
> >        if (!returnVal)
> > Index: sitelib/basesurf.cpp
> >
============================================================
=======
> > RCS file: /cvsroot/video/sitelib/basesurf.cpp,v
> > retrieving revision 1.34
> > diff -u -r1.34 basesurf.cpp
> > --- sitelib/basesurf.cpp	1 Aug 2007 00:11:31
-0000	1.34
> > +++ sitelib/basesurf.cpp	24 Apr 2008 07:47:15
-0000
> >  -185,6 +185,9 
> >      , m_bImageBlocksGood(FALSE)
> >      , m_pOverlayManager(NULL)
> >      , m_bAllowOverlayShrinking(FALSE)
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +    , m_IDMainThread(0)
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >  {
> >      HX_ASSERT( m_pContext );
> >      m_pContext->AddRef();
> >  -201,6 +204,10 
> >      m_TimeStamps.Init(m_pContext, this);
> >  #endif
> >  
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +    m_IDMainThread = pthread_self();
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +
> >      IHXPreferences* pPreferences = NULL;
> >      IHXBuffer*      pBuffer      = NULL;
> >      HXFLOAT         fTmp         =
(float)m_fScrollBarZoom;
> >  -235,6 +242,13 
> >      HX_DELETE(m_pHwMemObj);
> >  
> >      HX_RELEASE(m_pRootSurface);
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +    while(!m_listTimeOutCallback.IsEmpty())
> > +    {
> > +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
> > +		g_source_remove (id);
> > +    }
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >  
> >      // CBaseSite:estroy
calls EndOptimizedBlt.  We can't call
> >      // EndOptimizedBlt from the destructor since
it calls 
> DestroySurfaces
> >  -3811,6 +3825,27 
> >      m_nUpdateOverlayByPassCount =
OVERLAY_BYPASS_THRESHOLD+1;
> >  }
> >  
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +struct GtkMainUpdateOverlay
> > +{	
> > +	CBaseSurface* 		pBase;	
> > +	HXxRect         	rDestRect;
> > +	HXxRect				rSrcRect;
> > +	INT32				rflags;
> > +};
> > +gboolean
CBaseSurface::CallbackToUpdateOverlay(gpointer data)
> > +{
> > +	GtkMainUpdateOverlay* pGtkMainUpdateOverlay = 
> (GtkMainUpdateOverlay*)data;	
> > +	
>
pGtkMainUpdateOverlay->pBase->_UpdateOverlay(&pGtk
MainUpdateOv
> erlay->rDestRect,
&pGtkMainUpdateOverlay->rSrcRect, 
> pGtkMainUpdateOverlay->rflags);	
> > +	
>
if(!pGtkMainUpdateOverlay->pBase->m_listTimeOutCallbac
k.IsEmpty())
> > +	{	
> > +		
>
pGtkMainUpdateOverlay->pBase->m_listTimeOutCallback.Re
moveHead();
> > +	}
> > +	HX_DELETE(pGtkMainUpdateOverlay);	
> > +	return FALSE;
> > +}
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +
> >  HX_RESULT CBaseSurface::UpdateOverlay( 
REF(HXxRect) 
> /*IN*/  rDestRect,
> >                                         
REF(HXxRect) 
> /*IN*/  rSrcRect,
> >                                          int x,
int y)
> >  -3993,6 +4028,21 
> >              m_nUpdateOverlayByPassCount = 0;
> >              memcpy(&m_lastUpdateDestRect,
&destRect, 
> sizeof(HXxRect)); /* Flawfinder: ignore */
> >              memcpy(&m_lastUpdateSrcRect, 
&srcRect,  
> sizeof(HXxRect)); /* Flawfinder: ignore */
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +			unsigned int cur_thread = pthread_self();
> > +			if (cur_thread != m_IDMainThread)
> > +			{
> > +				GtkMainUpdateOverlay* ptr = new 
> GtkMainUpdateOverlay;	
> > +				guint id = 0;
> > +				ptr->pBase = this;	
> > +				ptr->rDestRect = destRect;	
> > +				ptr->rSrcRect = srcRect;
> > +				ptr->rflags = flags;
> > +				id = g_timeout_add(0, 
> CallbackToUpdateOverlay, (gpointer*)ptr);	
> > +				
> m_listTimeOutCallback.AddTail((void*)id);				
> > +				return HXR_OK;
> > +			}
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >              _UpdateOverlay(&destRect,
&srcRect, flags);
> >  #ifdef _CHECK_PERFORMANCE
> >              NumOfUpdateOverlays++;       
> > Index: sitelib/pub/baseroot.h
> >
============================================================
=======
> > RCS file: /cvsroot/video/sitelib/pub/baseroot.h,v
> > retrieving revision 1.8
> > diff -u -r1.8 baseroot.h
> > --- sitelib/pub/baseroot.h	6 Jul 2007 20:54:02
-0000	1.8
> > +++ sitelib/pub/baseroot.h	24 Apr 2008 07:47:17
-0000
> >  -52,7 +52,12 
> >  #include "hxengin.h"
> >  #include "hxslist.h"
> >  #include "baseobj.h"
> > -
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +#include <glib/gtypes.h>
> > +#include <gtk/gtk.h>
> > +#include <glib.h>
> > +#include <pthread.h>
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >  #ifndef _BASEROOT_H_
> >  #define _BASEROOT_H_
> >  
> >  -148,7 +153,12 
> >      void         UnlockCompMutex();
> >  
> >      ColorFuncAccess* GetColorAccess() {return
zm_pColorAcc;}
> > -   
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +   unsigned int m_MainThreadID;
> > +   static gboolean CallbackToMinimalBlt(gpointer
data);
> > +   CHXSimpleList m_listTimeOutCallback;
> > +   IHXMutex*    m_pMutexMinimalBlt;
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD 
> >  protected:
> >      IHXMutex*    m_pMutex;
> >      IHXMutex*    m_pCompMutex;
> > Index: sitelib/pub/basesurf.h
> >
============================================================
=======
> > RCS file: /cvsroot/video/sitelib/pub/basesurf.h,v
> > retrieving revision 1.11
> > diff -u -r1.11 basesurf.h
> > --- sitelib/pub/basesurf.h	6 Jul 2007 20:54:03
-0000	1.11
> > +++ sitelib/pub/basesurf.h	24 Apr 2008 07:47:18
-0000
> >  -58,6 +58,12 
> >  #include "hxwin.h"
> >  #include "baseobj.h"
> >  
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +#include <glib/gtypes.h>
> > +#include <gtk/gtk.h>
> > +#include <glib.h>
> > +#include <pthread.h>
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >  #if !defined(_GOLD) && 0
> >  #include "timestmp.h"    
> >  #endif
> >  -237,6 +243,12 
> >  
> >      HXxSize* GetSurfaceSize()   {return
&m_surfaceSize;}
> >  
> > +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +    unsigned int m_IDMainThread;
> > +    static gboolean
CallbackToUpdateOverlay(gpointer data);
> > +    CHXSimpleList m_listTimeOutCallback;
> > +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> > +
> >  private:
> >     
> >      CBaseSurface();
> >   
> > 
>
------------------------------------------------------------
--
> ----------
> >
> > _______________________________________________
> > Helix-client-dev mailing list
> > Helix-client-devhelixcommunity.org
> > http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev
> >   
> 
> 


_______________________________________________
Helix-client-dev mailing list
Helix-client-devhelixcommunity.org
http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev

RE: Changes to fix the Xlib crash happening during the playback wi
user name
2008-04-24 20:14:16
  I haven't accessed the source code about Lite Player,
but from my experience, there are two points should take
care for the Xlib issue.
  1. You should have some thread initialization at the
begin of your main(). Refer to the code at
player/kit/dbus-server/src/helix-dbus-server-main.cpp. you
can also take a look at the patch I sent moment ago for
player_gtk_test.
  2. Where is your ClientEngineProcessXEvent() in top
level player?
  Helix-player create a new thread to do that, I don't
think that's a good way (I find that will lose lots of
frames on Atlas branch).
  I suggest to use g_timeout_add_full() to add scheduled
hxplayer_pump() in the main thread of GTK.
  You can also refer to helix-dbus-server, or
player_gtk_test.
  
  BR.
  
  
  >-----Original Message-----
  >From: helix-client-dev-bounceshelixcommunity.org
  >[mailto:helix-client-dev-bounceshelixcommunity.org] On Behalf Of Deepak
  >Jain
  >Sent: 2008定4埖24晩 19:22
  >To: video-devhelixcommunity.org; helix-client-devhelixcommunity.org
  >Subject: [Helix-client-dev] CR:[RESENDING] Changes
to fix the Xlib crash
  >happening during the playback with UI for
LitePlayer.
  >
  >Resending the updated diff.
  >
  >Thanks,
  >Deepak Jain
  >
  >Deepak Jain wrote:
  >> Synopsis:
  >> Changes to fix the Xlib crash happening during
the playback with UI
  >> for LitePlayer.
  >>
  >> Overview:
  >> When we were playing a rm/wm file with UI, we
were getting *Xlib:
  >> unexpected async reply message* because we were
blitting on multiple
  >> threads. Now we have scheduled a callback
before call to
  >> _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp) if we
  >> detect that we are not on the main gtk thread.
When the callback
  >> occurs, the callback occurs on the main thread
and we call
  >> _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp). This does
  >> the blitting on the main thread.
  >>
  >> Files Added:
  >> /video/sitelib/linux2.pcf
  >>
  >> Files Modified:
  >> /video/sitelib/baseroot.cpp
  >> /video/sitelib/basesurf.cpp
  >> /video/sitelib/pub/basesurf.h
  >> /video/sitelib/pub/baseroot.h
  >>
  >> Image Size and Heap Use impact (Client -Only):
  >> None.
  >>
  >> Platforms and Profiles Affected:
  >> None
  >>
  >> Distribution Libraries Affected:
  >> None
  >>
  >> Distribution library impact and planned
action:
  >> None
  >>
  >> Platforms and Profiles Build Verified:
  >> BIF branch    -> wombat
  >> Target(s)      ->  LitePlayerWombat
  >> Profile          -> helix-client-moblin
  >> SYSTEM_ID -> linux-2.2-libc6-gcc32-i586
  >>
  >> Branch:
  >> hxclient_3_1_0_atlas, HEAD
  >>
  >> Files Attached:
  >> sitelib_diff.txt
  >> linux2.pcf
  >>
  >> Thanks,
  >> Deepak Jain
  >>
  >----------------------------------------------------
-------------------
  >-
  >>
  >> # on gcc we want to turn on all warnings
  >> extra_cflags = ""
  >> using_gcc = 0
  >> if string.find(platform.cc.cmd, 'gcc') != -1:
  >>     using_gcc = 1
  >>     extra_cflags = "-Wall"
  >>
  >> # grab flags from pkgconfig
  >> import shell
  >> import string
  >>
  >> # see if we're using the target gtk version
(triggers setting of the
  >> # DISABLE_DEPRECATED flag)
  >>
  >> (exitstatus, gtk_mod_version) =
shell.run("pkg-config --modversion
  >gtk+-2.0")
  >> if exitstatus != 0:
  >> 	e = err.Error()
  >> 	e.Set("pkg-config failed")
  >> 	raise err.error, e
  >>
  >> if string.find(gtk_mod_version,
"2.0") == 0:
  >> 	project.AddDefines('G_DISABLE_DEPRECATED',
  >> 					   'GDK_DISABLE_DEPRECATED',
  >> 					   'GTK_DISABLE_DEPRECATED')
  >>
  >> pkg_modules = "gtk+-2.0"
  >>
  >> if
project.IsDefined('HELIX_FEATURE_LIBGLADE'):
  >> 	pkg_modules = pkg_modules + "
libglade-2.0 gmodule-2.0"
  >>
  >> (exitstatus, gtk_config_output_cflags) =
shell.run("pkg-config --cflags
  >" + pkg_modules)
  >> (exitstatus, gtk_config_output_ldflags) =
shell.run("pkg-config --libs
  >" + pkg_modules)
  >>
  >> gtk_cflags =
string.split(gtk_config_output_cflags)
  >> gtk_ldflags =
string.split(gtk_config_output_ldflags)
  >>
  >> gtk_ld_paths = []
  >> gtk_libs = []
  >> gtk_includes = []
  >> gtk_defines = []
  >> gtk_other_cflags = ""
  >> gtk_other_ldflags = ""
  >>
  >> for x in gtk_cflags:
  >> 		if x[0:2] == '-I':
  >> 				gtk_includes[-1:-1] = [ x[2:] ]
  >> 		elif x[0:2] == '-D':
  >> 				gtk_defines[-1:-1] = [ x[2:] ]
  >> 		else:
  >> 				gtk_other_cflags = gtk_other_cflags +
" " + x
  >>
  >> for x in gtk_ldflags:
  >> 		if x[0:2] == '-l':
  >> 				gtk_libs[-1:-1] = [ x[2:] ]
  >> 		elif x[0:2] == '-L':
  >> 				gtk_ld_paths[-1:-1] = [ x ]
  >> 		else:
  >> 				gtk_other_ldflags = gtk_other_ldflags +
" " + x
  >>
  >> # add the flags
  >> project.AddSystemLibraries(gtk_libs)
  >> project.AddIncludes(gtk_includes)
  >> project.AddSystemPaths(gtk_ld_paths)
  >> project.AddDefines(gtk_defines)
  >>
  >> platform.cc.args["default"] =
platform.cc.args["default"] + " " +
  >gtk_other_cflags + " " + extra_cflags
  >> platform.cxx.args["default"] =
platform.cxx.args["default"] + " " +
  >gtk_other_cflags + " " + extra_cflags
  >>
  >> # platform.link.args["default"] =
platform.link.args["default"] + " " +
  >gtk_other_ldflags
  >> project.AddDynamicLibraries(gtk_other_ldflags)
  >>
  >>
  >----------------------------------------------------
-------------------
  >-
  >>
  >> Index: sitelib/baseroot.cpp
  >>
============================================================
=======
  >> RCS file:
/cvsroot/video/sitelib/baseroot.cpp,v
  >> retrieving revision 1.12
  >> diff -u -r1.12 baseroot.cpp
  >> --- sitelib/baseroot.cpp	6 Jul 2007 20:53:58
-0000	1.12
  >> +++ sitelib/baseroot.cpp	24 Apr 2008 07:47:11
-0000
  >>  -123,6 +123,10 
  >>      , m_bUseCardMemory(FALSE)
  >>      , m_pUnlockingSite(NULL)
  >>      , zm_pColorAcc(NULL)
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +    , m_MainThreadID(0)
  >> +    , m_pMutexMinimalBlt(NULL)
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>  {
  >>  #ifdef _BLT_IN_DEBUG
  >>     m_nBLTMode = HX_WINDOWLESS_DEBUG;
  >>  -134,7 +138,10 
  >>     HX_ASSERT( m_pSite );
  >>     m_pContext->AddRef();
  >>     m_pSite->AddRef();
  >> -
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +	m_MainThreadID = pthread_self();
  >> +	CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pMutexMinimalBlt,
  >m_pContext);
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>     CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pMutex, m_pContext);
  >>     CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pCompMutex,
  >m_pContext);
  >>
  >>  -190,7 +197,14 
  >>  #ifdef _WINDOWS
  >>     HX_RELEASE(m_pPlayer);
  >>  #endif
  >> -
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +	while(!m_listTimeOutCallback.IsEmpty())
  >> +	{
  >> +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
  >> +		g_source_remove (id);
  >> +	}
  >> +	HX_RELEASE(m_pMutexMinimalBlt);
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>     HX_RELEASE(m_pMutex);
  >>     HX_RELEASE(m_pCompMutex);
  >>     HX_RELEASE(m_pContext);
  >>  -271,6 +285,25 
  >>      }
  >>  }
  >>
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +struct GtkInfoMinimalBlt
  >> +{
  >> +	CBaseRootSurface* 	pBase;
  >> +	HXxRect         	rDestRect;
  >> +};
  >> +gboolean
CBaseRootSurface::CallbackToMinimalBlt(gpointer data)
  >> +{
  >> +	GtkInfoMinimalBlt* pGtkInfoMinimalBlt =
(GtkInfoMinimalBlt*)data;
  >> +
  >	pGtkInfoMinimalBlt->pBase->_MinimalBlt(pGtkIn
foMinimalBlt->rDestRect);
  >>
+	if(!pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback
.IsEmpty())
  >> +	{
  >> +
  >	pGtkInfoMinimalBlt->pBase->m_listTimeOutCallb
ack.RemoveHead();
  >> +	}
  >> +	HX_DELETE(pGtkInfoMinimalBlt);
  >> +	return FALSE;
  >> +}
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +
  >>  STDMETHODIMP CBaseRootSurface::Blt( UCHAR*    
          pImageData,
  >>                                     
HXBitmapInfoHeader* pBitmapInfo,
  >>                                     
REF(HXxRect)         rDestRect,
  >>  -532,7 +565,26 
  >>                                           
rSrcRect.left,
  >rSrcRect.top, dxSrc, dySrc);
  >>
  >>              if(
!m_pSite->IsCompositionLocked() && returnVal !=
-1)
  >> +            {
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +            	unsigned int cur_thread =
pthread_self();
  >> +				if (cur_thread != m_MainThreadID)
  >> +				{
  >> +	            	GtkInfoMinimalBlt* ptr = new
GtkInfoMinimalBlt;
  >> +					guint id = 0;
  >> +	            	ptr->pBase = this;
  >> +	            	ptr->rDestRect = rDestRect;
  >> +	            	id = g_timeout_add(0,
CallbackToMinimalBlt,
  >(gpointer*)ptr);
  >>
+					m_listTimeOutCallback.AddTail((void*)id);
  >> +		    		return HXR_OK;
  >> +				}
  >> +				m_pMutexMinimalBlt->Lock();
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>                  _MinimalBlt(rDestRect);
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +				m_pMutexMinimalBlt->Unlock();
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +            }
  >>           }
  >>        }
  >>        if (!returnVal)
  >> Index: sitelib/basesurf.cpp
  >>
============================================================
=======
  >> RCS file:
/cvsroot/video/sitelib/basesurf.cpp,v
  >> retrieving revision 1.34
  >> diff -u -r1.34 basesurf.cpp
  >> --- sitelib/basesurf.cpp	1 Aug 2007 00:11:31
-0000	1.34
  >> +++ sitelib/basesurf.cpp	24 Apr 2008 07:47:15
-0000
  >>  -185,6 +185,9 
  >>      , m_bImageBlocksGood(FALSE)
  >>      , m_pOverlayManager(NULL)
  >>      , m_bAllowOverlayShrinking(FALSE)
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +    , m_IDMainThread(0)
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>  {
  >>      HX_ASSERT( m_pContext );
  >>      m_pContext->AddRef();
  >>  -201,6 +204,10 
  >>      m_TimeStamps.Init(m_pContext, this);
  >>  #endif
  >>
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +    m_IDMainThread = pthread_self();
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +
  >>      IHXPreferences* pPreferences = NULL;
  >>      IHXBuffer*      pBuffer      = NULL;
  >>      HXFLOAT         fTmp         =
(float)m_fScrollBarZoom;
  >>  -235,6 +242,13 
  >>      HX_DELETE(m_pHwMemObj);
  >>
  >>      HX_RELEASE(m_pRootSurface);
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +    while(!m_listTimeOutCallback.IsEmpty())
  >> +    {
  >> +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
  >> +		g_source_remove (id);
  >> +    }
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>
  >>      // CBaseSite:estroy
calls EndOptimizedBlt.  We can't call
  >>      // EndOptimizedBlt from the destructor
since it calls
  >DestroySurfaces
  >>  -3811,6 +3825,27 
  >>      m_nUpdateOverlayByPassCount =
OVERLAY_BYPASS_THRESHOLD+1;
  >>  }
  >>
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +struct GtkMainUpdateOverlay
  >> +{
  >> +	CBaseSurface* 		pBase;
  >> +	HXxRect         	rDestRect;
  >> +	HXxRect				rSrcRect;
  >> +	INT32				rflags;
  >> +};
  >> +gboolean
CBaseSurface::CallbackToUpdateOverlay(gpointer data)
  >> +{
  >> +	GtkMainUpdateOverlay* pGtkMainUpdateOverlay
=
  >(GtkMainUpdateOverlay*)data;
  >> +
  >	pGtkMainUpdateOverlay->pBase->_UpdateOverlay(
&pGtkMainUpdateOverlay->r
  >DestRect, &pGtkMainUpdateOverlay->rSrcRect,
  >pGtkMainUpdateOverlay->rflags);
  >> +
  >	if(!pGtkMainUpdateOverlay->pBase->m_listTimeO
utCallback.IsEmpty())
  >> +	{
  >> +
  >	pGtkMainUpdateOverlay->pBase->m_listTimeOutCa
llback.RemoveHead();
  >> +	}
  >> +	HX_DELETE(pGtkMainUpdateOverlay);
  >> +	return FALSE;
  >> +}
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +
  >>  HX_RESULT CBaseSurface::UpdateOverlay( 
REF(HXxRect) /*IN*/
  >rDestRect,
  >>                                         
REF(HXxRect) /*IN*/
  >rSrcRect,
  >>                                          int x,
int y)
  >>  -3993,6 +4028,21 
  >>              m_nUpdateOverlayByPassCount = 0;
  >>              memcpy(&m_lastUpdateDestRect,
&destRect, sizeof(HXxRect));
  >/* Flawfinder: ignore */
  >>              memcpy(&m_lastUpdateSrcRect, 
&srcRect,
  >sizeof(HXxRect)); /* Flawfinder: ignore */
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +			unsigned int cur_thread = pthread_self();
  >> +			if (cur_thread != m_IDMainThread)
  >> +			{
  >> +				GtkMainUpdateOverlay* ptr = new
GtkMainUpdateOverlay;
  >
  >> +				guint id = 0;
  >> +				ptr->pBase = this;
  >> +				ptr->rDestRect = destRect;
  >> +				ptr->rSrcRect = srcRect;
  >> +				ptr->rflags = flags;
  >> +				id = g_timeout_add(0,
CallbackToUpdateOverlay,
  >(gpointer*)ptr);
  >> +				m_listTimeOutCallback.AddTail((void*)id);
  >
  >> +				return HXR_OK;
  >> +			}
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>              _UpdateOverlay(&destRect,
&srcRect, flags);
  >>  #ifdef _CHECK_PERFORMANCE
  >>              NumOfUpdateOverlays++;
  >> Index: sitelib/pub/baseroot.h
  >>
============================================================
=======
  >> RCS file:
/cvsroot/video/sitelib/pub/baseroot.h,v
  >> retrieving revision 1.8
  >> diff -u -r1.8 baseroot.h
  >> --- sitelib/pub/baseroot.h	6 Jul 2007 20:54:02
-0000	1.8
  >> +++ sitelib/pub/baseroot.h	24 Apr 2008 07:47:17
-0000
  >>  -52,7 +52,12 
  >>  #include "hxengin.h"
  >>  #include "hxslist.h"
  >>  #include "baseobj.h"
  >> -
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +#include <glib/gtypes.h>
  >> +#include <gtk/gtk.h>
  >> +#include <glib.h>
  >> +#include <pthread.h>
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>  #ifndef _BASEROOT_H_
  >>  #define _BASEROOT_H_
  >>
  >>  -148,7 +153,12 
  >>      void         UnlockCompMutex();
  >>
  >>      ColorFuncAccess* GetColorAccess() {return
zm_pColorAcc;}
  >> -
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +   unsigned int m_MainThreadID;
  >> +   static gboolean
CallbackToMinimalBlt(gpointer data);
  >> +   CHXSimpleList m_listTimeOutCallback;
  >> +   IHXMutex*    m_pMutexMinimalBlt;
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>  protected:
  >>      IHXMutex*    m_pMutex;
  >>      IHXMutex*    m_pCompMutex;
  >> Index: sitelib/pub/basesurf.h
  >>
============================================================
=======
  >> RCS file:
/cvsroot/video/sitelib/pub/basesurf.h,v
  >> retrieving revision 1.11
  >> diff -u -r1.11 basesurf.h
  >> --- sitelib/pub/basesurf.h	6 Jul 2007 20:54:03
-0000	1.11
  >> +++ sitelib/pub/basesurf.h	24 Apr 2008 07:47:18
-0000
  >>  -58,6 +58,12 
  >>  #include "hxwin.h"
  >>  #include "baseobj.h"
  >>
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +#include <glib/gtypes.h>
  >> +#include <gtk/gtk.h>
  >> +#include <glib.h>
  >> +#include <pthread.h>
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >>  #if !defined(_GOLD) && 0
  >>  #include "timestmp.h"
  >>  #endif
  >>  -237,6 +243,12 
  >>
  >>      HXxSize* GetSurfaceSize()   {return
&m_surfaceSize;}
  >>
  >> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +    unsigned int m_IDMainThread;
  >> +    static gboolean
CallbackToUpdateOverlay(gpointer data);
  >> +    CHXSimpleList m_listTimeOutCallback;
  >> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
  >> +
  >>  private:
  >>
  >>      CBaseSurface();
  >>
  >>
  >----------------------------------------------------
-------------------
  >-
  >>
  >>
_______________________________________________
  >> Helix-client-dev mailing list
  >> Helix-client-devhelixcommunity.org
  >> http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev
  >>
  

_______________________________________________
Helix-client-dev mailing list
Helix-client-devhelixcommunity.org
http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev

Re: Changes to fix the Xlib crash happening during the playback wi
country flaguser name
India
2008-04-25 07:43:15
Hi Eric,

Good News!

Milko and Rahul's suggestion worked. Earlier, i was using
ForceRedraw() 
option in baseroot.cpp's callback function without saving
any site but 
using the existing member pointer of CBaseSite in
baseroot.cpp.

Now as you suggested to check the Thread ID's in Blt
function of 
basesurf.cpp and schedule a callback if we are not on the
main thread 
after saving the m_pSite in structure. From the callback, i
am calling 
ForceRedraw() and this is working.

I am also mutex protecting the addition/removal of callback
IDs. This is 
needed to protect the list of callback IDs. Since multiple
callbacks are 
added, more than two threads attempt to modify the list
thereby 
sometimes corrupting it and we see a crash. We keep the list
of callback 
IDs because we need to remove any pending callback in
destructor.

Attached is the updated diff.

Thanks,
Deepak Jain

Eric Hyche wrote:
> Deepak,
>
> Here are my comments:
>
> 1) Did you try Milko and Rahul's suggestion? Here
>    it is as I understand it:
>      - Check the thread id right after we enter
>        CBaseSurface::Blt() or
CBaseSurface::BltSubRects()
>      - If we are not on the thread we were created on,
>        then save m_pSite into our callback struct
>        and schedule the callback and then exit
>        CBaseSurface::Blt() or
CBaseSurface::BltSubRects().
>      - When the callback fires, then call
m_pSite->ForceRedraw().
>        This will synchronously call back into Blt()
with the
>        most up-to-date frame, but now on the main
thread.
>
>    I seem to remember in your status email you said
something about
>    frames being dropped. Why were frames being dropped?
Where
>    were they being dropped? In CBaseSurface or in the
base video
>    renderer? Also, I'd like to know a few other
things:
>      - how long (min, avg, max) is it between
scheduling
>        the callback with g_timeout_add(0,..) and the
callback
>        actually executing?
>      - how often does this happen: you get a blt on a
>        non-main thread, so you schedule a callback. In
between
>        the time the callback is scheduled and the time
it fires,
>        you get a blt on the main thread (so that blt
goes through).
>
>    Overall, I think we should try to make this
suggestion work.
>    Or if it's not working, we need to understand why it
doesn't work.
>    If we can make this work, then the fix becomes a lot
simpler:
>    we don't have to worry about whether we are in
overlay mode
>    or basic_blt mode, etc.
>
>    The rest of my comments have to do with the fix as
it currently
>    stands. But top priority is to try the suggestion
above and
>    either get it work, or understand why it doesn't
work.
>
> 2) If we stick with what you currently have (and for
some reason
>    Milko and Rahul's suggestion above does not work),
then 
>    I think we won't need the mutexes after all. The
reason is
>    that access to the CBaseRootSurface is mutex
protected
>    already. Note the code in CBaseSurface::Blt() here
>    (just for the HX_BASIC_BLT mode):
>
>         while( HXR_OK != pSurface->Lock(0))
>
>    This is calling a Lock() on a mutex inside of
CBaseRootSurface().
>    So at least for the HX_BASIC_BLT mode, we won't
need
>    to add a separate mutex inside of
CBaseRootSurface().
>
>    However, you will need to call pBase->Lock() and
>    pBase->Unlock() on either side of your call to
>    pBase->_MinimalBlt().
>    
> 3) In your callbacks for UpdateOverlay(), the problem
I
>    see is that we have rotating buffers. From my
looking
>    at the code, it looks like the base surface calls
>    _LockInternalSurface(), which chooses from a ring
of
>    buffers. (Usually it's 2, but it could be more than
2.)
>    Then it writes into that buffer and then calls
UpdateOverlay(),
>    which calls XvShmPutImage() or XvPutImage() on the
current
>    buffer.
>
>    The problem is that another blt on the main thread
could come
>    in between the time that the callback is scheduled
and 
>    the callback executes. In that case, the
"current buffer"
>    switches and so the srcRect, dstRect, and flags you
saved
>    are no longer valid for the current image.
>
>    So I think in your callback we should be using the
>    saved m_lastUpdateDestRect and m_lastUpdateSrcRect.
I guess
>    since flags are not currently saved, we'll have to
save
>    them as well.
>
> 4) Instead of HELIX_CONFIG_USE_GTKMAIN_THREAD,
>    let's call it something more descriptive like 
>    HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD
>
> 5) Instead of using pthread_self() to get the
>    current thread ID, you can use the cross-platform
>    HXGetCurrentThreadID() defined in
>    commonsystempubthrdutil.h.
>
> 6) +    unsigned int m_IDMainThread;
>
>    +   unsigned int m_MainThreadID;
>   
>    These should be UINT32, since
HXGetCurrentThreadID()
>    returns UINT32.
>
>
> Thanks,
>
> Eric
>
> =============================================
> Eric Hyche (ehychereal.com)
> Technical Lead
> RealNetworks, Inc.  
>
>   
>> -----Original Message-----
>> From: helix-client-dev-bounceshelixcommunity.org 
>> [mailto:helix-client-dev-bounceshelixcommunity.org] On 
>> Behalf Of Deepak Jain
>> Sent: Thursday, April 24, 2008 7:22 AM
>> To: video-devhelixcommunity.org; helix-client-devhelixcommunity.org
>> Subject: [Helix-client-dev] CR:[RESENDING] Changes
to fix the 
>> Xlib crash happening during the playback with UI
for LitePlayer.
>>
>> Resending the updated diff.
>>
>> Thanks,
>> Deepak Jain
>>
>> Deepak Jain wrote:
>>     
>>> Synopsis:
>>> Changes to fix the Xlib crash happening during
the playback with UI 
>>> for LitePlayer.
>>>
>>> Overview:
>>> When we were playing a rm/wm file with UI, we
were getting *Xlib: 
>>> unexpected async reply message* because we were
blitting on 
>>>       
>> multiple 
>>     
>>> threads. Now we have scheduled a callback
before call to 
>>> _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp) if we 
>>> detect that we are not on the main gtk thread.
When the callback 
>>> occurs, the callback occurs on the main thread
and we call 
>>> _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp). 
>>>       
>> This does 
>>     
>>> the blitting on the main thread.
>>>
>>> Files Added:
>>> /video/sitelib/linux2.pcf
>>>
>>> Files Modified:
>>> /video/sitelib/baseroot.cpp
>>> /video/sitelib/basesurf.cpp
>>> /video/sitelib/pub/basesurf.h
>>> /video/sitelib/pub/baseroot.h
>>>
>>> Image Size and Heap Use impact (Client -Only):
>>> None.
>>>
>>> Platforms and Profiles Affected:
>>> None
>>>
>>> Distribution Libraries Affected:
>>> None
>>>
>>> Distribution library impact and planned
action:
>>> None
>>>
>>> Platforms and Profiles Build Verified:
>>> BIF branch    -> wombat
>>> Target(s)      ->  LitePlayerWombat
>>> Profile          -> helix-client-moblin
>>> SYSTEM_ID -> linux-2.2-libc6-gcc32-i586
>>>
>>> Branch:
>>> hxclient_3_1_0_atlas, HEAD
>>>
>>> Files Attached:
>>> sitelib_diff.txt
>>> linux2.pcf
>>>
>>> Thanks,
>>> Deepak Jain
>>>
>>>       
>>
------------------------------------------------------------
--
>> ----------
>>     
>>> # on gcc we want to turn on all warnings
>>> extra_cflags = ""
>>> using_gcc = 0
>>> if string.find(platform.cc.cmd, 'gcc') != -1:
>>>     using_gcc = 1
>>>     extra_cflags = "-Wall"
>>>
>>> # grab flags from pkgconfig
>>> import shell
>>> import string
>>>
>>> # see if we're using the target gtk version
(triggers setting of the
>>> # DISABLE_DEPRECATED flag)
>>>
>>> (exitstatus, gtk_mod_version) =
shell.run("pkg-config 
>>>       
>> --modversion gtk+-2.0")
>>     
>>> if exitstatus != 0:
>>> 	e = err.Error()
>>> 	e.Set("pkg-config failed")
>>> 	raise err.error, e
>>>
>>> if string.find(gtk_mod_version,
"2.0") == 0:
>>> 	project.AddDefines('G_DISABLE_DEPRECATED',
>>> 					   'GDK_DISABLE_DEPRECATED',
>>> 					   'GTK_DISABLE_DEPRECATED')
>>>
>>> pkg_modules = "gtk+-2.0"
>>>
>>> if
project.IsDefined('HELIX_FEATURE_LIBGLADE'):
>>> 	pkg_modules = pkg_modules + "
libglade-2.0 gmodule-2.0"
>>>
>>> (exitstatus, gtk_config_output_cflags) = 
>>>       
>> shell.run("pkg-config --cflags " +
pkg_modules)
>>     
>>> (exitstatus, gtk_config_output_ldflags) = 
>>>       
>> shell.run("pkg-config --libs " +
pkg_modules)
>>     
>>> gtk_cflags =
string.split(gtk_config_output_cflags)
>>> gtk_ldflags =
string.split(gtk_config_output_ldflags)
>>>
>>> gtk_ld_paths = []
>>> gtk_libs = []
>>> gtk_includes = []
>>> gtk_defines = []
>>> gtk_other_cflags = ""
>>> gtk_other_ldflags = ""
>>>
>>> for x in gtk_cflags:
>>> 		if x[0:2] == '-I':
>>> 				gtk_includes[-1:-1] = [ x[2:] ]
>>> 		elif x[0:2] == '-D':
>>> 				gtk_defines[-1:-1] = [ x[2:] ]
>>> 		else:
>>> 				gtk_other_cflags = 
>>>       
>> gtk_other_cflags + " " + x
>>     
>>> for x in gtk_ldflags:
>>> 		if x[0:2] == '-l':
>>> 				gtk_libs[-1:-1] = [ x[2:] ]
>>> 		elif x[0:2] == '-L':
>>> 				gtk_ld_paths[-1:-1] = [ x ]
>>> 		else:
>>> 				gtk_other_ldflags = 
>>>       
>> gtk_other_ldflags + " " + x              
 
>>     
>>> # add the flags
>>> project.AddSystemLibraries(gtk_libs)
>>> project.AddIncludes(gtk_includes)
>>> project.AddSystemPaths(gtk_ld_paths)
>>> project.AddDefines(gtk_defines)
>>>
>>> platform.cc.args["default"] =
platform.cc.args["default"] + 
>>>       
>> " " + gtk_other_cflags + " " +
extra_cflags
>>     
>>> platform.cxx.args["default"] =
platform.cxx.args["default"] 
>>>       
>> + " " + gtk_other_cflags + " "
+ extra_cflags
>>     
>>> # platform.link.args["default"] = 
>>>       
>> platform.link.args["default"] + "
" + gtk_other_ldflags
>>     
>>> project.AddDynamicLibraries(gtk_other_ldflags)
>>>   
>>>
>>>       
>>
------------------------------------------------------------
--
>> ----------
>>     
>>> Index: sitelib/baseroot.cpp
>>>
============================================================
=======
>>> RCS file:
/cvsroot/video/sitelib/baseroot.cpp,v
>>> retrieving revision 1.12
>>> diff -u -r1.12 baseroot.cpp
>>> --- sitelib/baseroot.cpp	6 Jul 2007 20:53:58
-0000	1.12
>>> +++ sitelib/baseroot.cpp	24 Apr 2008 07:47:11
-0000
>>>  -123,6 +123,10 
>>>      , m_bUseCardMemory(FALSE)
>>>      , m_pUnlockingSite(NULL)
>>>      , zm_pColorAcc(NULL)
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +    , m_MainThreadID(0)
>>> +    , m_pMutexMinimalBlt(NULL)
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>  {
>>>  #ifdef _BLT_IN_DEBUG
>>>     m_nBLTMode = HX_WINDOWLESS_DEBUG;
>>>  -134,7 +138,10 
>>>     HX_ASSERT( m_pSite );
>>>     m_pContext->AddRef();
>>>     m_pSite->AddRef();
>>> -
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +	m_MainThreadID = pthread_self();
>>> +	CreateInstanceCCF(CLSID_IHXMutex, 
>>>       
>> (void**)&m_pMutexMinimalBlt, m_pContext);
>>     
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>     CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pMutex, 
>>>       
>> m_pContext);
>>     
>>>     CreateInstanceCCF(CLSID_IHXMutex, 
>>>       
>> (void**)&m_pCompMutex, m_pContext);
>>     
>>>  
>>>  -190,7 +197,14 
>>>  #ifdef _WINDOWS
>>>     HX_RELEASE(m_pPlayer);
>>>  #endif
>>> -
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +	while(!m_listTimeOutCallback.IsEmpty())
>>> +	{
>>> +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
>>> +		g_source_remove (id);
>>> +	}
>>> +	HX_RELEASE(m_pMutexMinimalBlt);
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>     HX_RELEASE(m_pMutex);
>>>     HX_RELEASE(m_pCompMutex);
>>>     HX_RELEASE(m_pContext);
>>>  -271,6 +285,25 
>>>      }
>>>  }
>>>  
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +struct GtkInfoMinimalBlt
>>> +{	
>>> +	CBaseRootSurface* 	pBase;	
>>> +	HXxRect         	rDestRect;	
>>> +};
>>> +gboolean
CBaseRootSurface::CallbackToMinimalBlt(gpointer data)
>>> +{
>>> +	GtkInfoMinimalBlt* pGtkInfoMinimalBlt = 
>>>       
>> (GtkInfoMinimalBlt*)data;	
>>     
>>> +	
>>>       
>>
pGtkInfoMinimalBlt->pBase->_MinimalBlt(pGtkInfoMinimal
Blt->rDestRect);
>>     
>>>
+	if(!pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback
.IsEmpty())
>>> +	{	
>>> +		
>>>       
>>
pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback.Remov
eHead();
>>     
>>> +	}
>>> +	HX_DELETE(pGtkInfoMinimalBlt);	
>>> +	return FALSE;
>>> +}
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +
>>>  STDMETHODIMP CBaseRootSurface::Blt( UCHAR*    
          
>>>       
>> pImageData,
>>     
>>>                                     
HXBitmapInfoHeader* 
>>>       
>> pBitmapInfo,
>>     
>>>                                     
REF(HXxRect)         rDestRect,
>>>  -532,7 +565,26 
>>>                                           
rSrcRect.left, 
>>>       
>> rSrcRect.top, dxSrc, dySrc);
>>     
>>>  
>>>              if(
!m_pSite->IsCompositionLocked() && returnVal !=
-1)
>>> +            {
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +            	unsigned int cur_thread =
pthread_self();
>>> +				if (cur_thread != m_MainThreadID)
>>> +				{	
>>> +	            	GtkInfoMinimalBlt* ptr = new
GtkInfoMinimalBlt;
>>> +					guint id = 0;
>>> +	            	ptr->pBase = this;	
>>> +	            	ptr->rDestRect = rDestRect;	
>>> +	            	id = g_timeout_add(0, 
>>>       
>> CallbackToMinimalBlt, (gpointer*)ptr);
>>     
>>> +					
>>>       
>> m_listTimeOutCallback.AddTail((void*)id);
>>     
>>> +		    		return HXR_OK;
>>> +				}
>>> +				m_pMutexMinimalBlt->Lock();
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>                  _MinimalBlt(rDestRect);
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +				m_pMutexMinimalBlt->Unlock();
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +            }
>>>           }
>>>        }
>>>        if (!returnVal)
>>> Index: sitelib/basesurf.cpp
>>>
============================================================
=======
>>> RCS file:
/cvsroot/video/sitelib/basesurf.cpp,v
>>> retrieving revision 1.34
>>> diff -u -r1.34 basesurf.cpp
>>> --- sitelib/basesurf.cpp	1 Aug 2007 00:11:31
-0000	1.34
>>> +++ sitelib/basesurf.cpp	24 Apr 2008 07:47:15
-0000
>>>  -185,6 +185,9 
>>>      , m_bImageBlocksGood(FALSE)
>>>      , m_pOverlayManager(NULL)
>>>      , m_bAllowOverlayShrinking(FALSE)
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +    , m_IDMainThread(0)
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>  {
>>>      HX_ASSERT( m_pContext );
>>>      m_pContext->AddRef();
>>>  -201,6 +204,10 
>>>      m_TimeStamps.Init(m_pContext, this);
>>>  #endif
>>>  
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +    m_IDMainThread = pthread_self();
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +
>>>      IHXPreferences* pPreferences = NULL;
>>>      IHXBuffer*      pBuffer      = NULL;
>>>      HXFLOAT         fTmp         =
(float)m_fScrollBarZoom;
>>>  -235,6 +242,13 
>>>      HX_DELETE(m_pHwMemObj);
>>>  
>>>      HX_RELEASE(m_pRootSurface);
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +    while(!m_listTimeOutCallback.IsEmpty())
>>> +    {
>>> +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
>>> +		g_source_remove (id);
>>> +    }
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>  
>>>      // CBaseSite:estroy
calls EndOptimizedBlt.  We can't call
>>>      // EndOptimizedBlt from the destructor
since it calls 
>>>       
>> DestroySurfaces
>>     
>>>  -3811,6 +3825,27 
>>>      m_nUpdateOverlayByPassCount =
OVERLAY_BYPASS_THRESHOLD+1;
>>>  }
>>>  
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +struct GtkMainUpdateOverlay
>>> +{	
>>> +	CBaseSurface* 		pBase;	
>>> +	HXxRect         	rDestRect;
>>> +	HXxRect				rSrcRect;
>>> +	INT32				rflags;
>>> +};
>>> +gboolean
CBaseSurface::CallbackToUpdateOverlay(gpointer data)
>>> +{
>>> +	GtkMainUpdateOverlay* pGtkMainUpdateOverlay =

>>>       
>> (GtkMainUpdateOverlay*)data;	
>>     
>>> +	
>>>       
>>
pGtkMainUpdateOverlay->pBase->_UpdateOverlay(&pGtk
MainUpdateOv
>> erlay->rDestRect,
&pGtkMainUpdateOverlay->rSrcRect, 
>> pGtkMainUpdateOverlay->rflags);	
>>     
>>> +	
>>>       
>>
if(!pGtkMainUpdateOverlay->pBase->m_listTimeOutCallbac
k.IsEmpty())
>>     
>>> +	{	
>>> +		
>>>       
>>
pGtkMainUpdateOverlay->pBase->m_listTimeOutCallback.Re
moveHead();
>>     
>>> +	}
>>> +	HX_DELETE(pGtkMainUpdateOverlay);	
>>> +	return FALSE;
>>> +}
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +
>>>  HX_RESULT CBaseSurface::UpdateOverlay( 
REF(HXxRect) 
>>>       
>> /*IN*/  rDestRect,
>>     
>>>                                         
REF(HXxRect) 
>>>       
>> /*IN*/  rSrcRect,
>>     
>>>                                          int x,
int y)
>>>  -3993,6 +4028,21 
>>>              m_nUpdateOverlayByPassCount = 0;
>>>              memcpy(&m_lastUpdateDestRect,
&destRect, 
>>>       
>> sizeof(HXxRect)); /* Flawfinder: ignore */
>>     
>>>              memcpy(&m_lastUpdateSrcRect, 
&srcRect,  
>>>       
>> sizeof(HXxRect)); /* Flawfinder: ignore */
>>     
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +			unsigned int cur_thread = pthread_self();
>>> +			if (cur_thread != m_IDMainThread)
>>> +			{
>>> +				GtkMainUpdateOverlay* ptr = new 
>>>       
>> GtkMainUpdateOverlay;	
>>     
>>> +				guint id = 0;
>>> +				ptr->pBase = this;	
>>> +				ptr->rDestRect = destRect;	
>>> +				ptr->rSrcRect = srcRect;
>>> +				ptr->rflags = flags;
>>> +				id = g_timeout_add(0, 
>>>       
>> CallbackToUpdateOverlay, (gpointer*)ptr);	
>>     
>>> +				
>>>       
>> m_listTimeOutCallback.AddTail((void*)id);				
>>     
>>> +				return HXR_OK;
>>> +			}
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>              _UpdateOverlay(&destRect,
&srcRect, flags);
>>>  #ifdef _CHECK_PERFORMANCE
>>>              NumOfUpdateOverlays++;       
>>> Index: sitelib/pub/baseroot.h
>>>
============================================================
=======
>>> RCS file:
/cvsroot/video/sitelib/pub/baseroot.h,v
>>> retrieving revision 1.8
>>> diff -u -r1.8 baseroot.h
>>> --- sitelib/pub/baseroot.h	6 Jul 2007 20:54:02
-0000	1.8
>>> +++ sitelib/pub/baseroot.h	24 Apr 2008 07:47:17
-0000
>>>  -52,7 +52,12 
>>>  #include "hxengin.h"
>>>  #include "hxslist.h"
>>>  #include "baseobj.h"
>>> -
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +#include <glib/gtypes.h>
>>> +#include <gtk/gtk.h>
>>> +#include <glib.h>
>>> +#include <pthread.h>
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>  #ifndef _BASEROOT_H_
>>>  #define _BASEROOT_H_
>>>  
>>>  -148,7 +153,12 
>>>      void         UnlockCompMutex();
>>>  
>>>      ColorFuncAccess* GetColorAccess() {return
zm_pColorAcc;}
>>> -   
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +   unsigned int m_MainThreadID;
>>> +   static gboolean
CallbackToMinimalBlt(gpointer data);
>>> +   CHXSimpleList m_listTimeOutCallback;
>>> +   IHXMutex*    m_pMutexMinimalBlt;
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD 
>>>  protected:
>>>      IHXMutex*    m_pMutex;
>>>      IHXMutex*    m_pCompMutex;
>>> Index: sitelib/pub/basesurf.h
>>>
============================================================
=======
>>> RCS file:
/cvsroot/video/sitelib/pub/basesurf.h,v
>>> retrieving revision 1.11
>>> diff -u -r1.11 basesurf.h
>>> --- sitelib/pub/basesurf.h	6 Jul 2007 20:54:03
-0000	1.11
>>> +++ sitelib/pub/basesurf.h	24 Apr 2008 07:47:18
-0000
>>>  -58,6 +58,12 
>>>  #include "hxwin.h"
>>>  #include "baseobj.h"
>>>  
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +#include <glib/gtypes.h>
>>> +#include <gtk/gtk.h>
>>> +#include <glib.h>
>>> +#include <pthread.h>
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>>  #if !defined(_GOLD) && 0
>>>  #include "timestmp.h"    
>>>  #endif
>>>  -237,6 +243,12 
>>>  
>>>      HXxSize* GetSurfaceSize()   {return
&m_surfaceSize;}
>>>  
>>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +    unsigned int m_IDMainThread;
>>> +    static gboolean
CallbackToUpdateOverlay(gpointer data);
>>> +    CHXSimpleList m_listTimeOutCallback;
>>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
>>> +
>>>  private:
>>>     
>>>      CBaseSurface();
>>>   
>>>
>>>       
>>
------------------------------------------------------------
--
>> ----------
>>     
>>>
_______________________________________________
>>> Helix-client-dev mailing list
>>> Helix-client-devhelixcommunity.org
>>> http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev
>>>   
>>>       
>>     
>
>
>   


_______________________________________________
Helix-client-dev mailing list
Helix-client-devhelixcommunity.org
http://lists.helixcommunity.org/mailman/listinf
o/helix-client-dev

  
RE: Changes to fix the Xlib crash happening during the playback wi
country flaguser name
United States
2008-04-25 08:21:43
Deepak,

Hey, that *is* great news!

My comments:

+#ifdef HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD
+    while(!m_listTimeOutCallback.IsEmpty())
+    {
+    	HX_LOCK(m_pMutexForceRedraw);
+		guint id  = (guint)m_listTimeOutCallback.RemoveHead();
+		HX_UNLOCK(m_pMutexForceRedraw);
+		g_source_remove (id);
+    }
+    HX_RELEASE(m_pMutexForceRedraw);
+#endif //HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD

Since m_listTimeOutCallback checks the number
of entries in the list, then the lock/unlock needs
to be completely outside this loop, like this:

+#ifdef HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD
+    HX_LOCK(m_pMutexForceRedraw);
+    while(!m_listTimeOutCallback.IsEmpty())
+    {
+        guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
+        g_source_remove (id);
+    }
+    HX_UNLOCK(m_pMutexForceRedraw);
+    HX_RELEASE(m_pMutexForceRedraw);
+#endif //HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD

One additional change I can see is that we
need this behavior to be not only compile-time 
controllable (as it is using
HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD)
but we also need it to be run-time controllable
via a pref setting.

The reason is that we will be building a single vidsite.so
and that same binary will be used for both the standalone
RealPlayer for MID and the LitePlayer. In the LitePlayer,
we DO want to force all blts to happen on the main gtk
thread. We DON'T want to make this restriction for
the RealPlayer for MID.

So we need to add a pref check when the CBaseSurface is
created
and only enforce blt-on-main-gtk-thread behavior if:
  - HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD is defined at
compile-time; AND
  - the pref is set to 1.

Let's call the pref something like
"BltOnlyOnGTKThread".

The rest looks good.

Thanks,

Eric

=============================================
Eric Hyche (ehychereal.com)
Technical Lead
RealNetworks, Inc.  

> -----Original Message-----
> From: Deepak Jain [mailto:deepakjreal.com] 
> Sent: Friday, April 25, 2008 8:43 AM
> To: ehychereal.com
> Cc: video-devhelixcommunity.org; helix-client-devhelixcommunity.org
> Subject: Re: [Helix-client-dev] CR:[RESENDING] Changes
to fix 
> the Xlib crash happening during the playback with UI
for LitePlayer.
> 
> Hi Eric,
> 
> Good News!
> 
> Milko and Rahul's suggestion worked. Earlier, i was
using 
> ForceRedraw() 
> option in baseroot.cpp's callback function without
saving any 
> site but 
> using the existing member pointer of CBaseSite in
baseroot.cpp.
> 
> Now as you suggested to check the Thread ID's in Blt
function of 
> basesurf.cpp and schedule a callback if we are not on
the main thread 
> after saving the m_pSite in structure. From the
callback, i 
> am calling 
> ForceRedraw() and this is working.
> 
> I am also mutex protecting the addition/removal of
callback 
> IDs. This is 
> needed to protect the list of callback IDs. Since
multiple 
> callbacks are 
> added, more than two threads attempt to modify the list
thereby 
> sometimes corrupting it and we see a crash. We keep the
list 
> of callback 
> IDs because we need to remove any pending callback in
destructor.
> 
> Attached is the updated diff.
> 
> Thanks,
> Deepak Jain
> 
> Eric Hyche wrote:
> > Deepak,
> >
> > Here are my comments:
> >
> > 1) Did you try Milko and Rahul's suggestion? Here
> >    it is as I understand it:
> >      - Check the thread id right after we enter
> >        CBaseSurface::Blt() or
CBaseSurface::BltSubRects()
> >      - If we are not on the thread we were created
on,
> >        then save m_pSite into our callback struct
> >        and schedule the callback and then exit
> >        CBaseSurface::Blt() or
CBaseSurface::BltSubRects().
> >      - When the callback fires, then call
m_pSite->ForceRedraw().
> >        This will synchronously call back into
Blt() with the
> >        most up-to-date frame, but now on the main
thread.
> >
> >    I seem to remember in your status email you
said something about
> >    frames being dropped. Why were frames being
dropped? Where
> >    were they being dropped? In CBaseSurface or in
the base video
> >    renderer? Also, I'd like to know a few other
things:
> >      - how long (min, avg, max) is it between
scheduling
> >        the callback with g_timeout_add(0,..) and
the callback
> >        actually executing?
> >      - how often does this happen: you get a blt
on a
> >        non-main thread, so you schedule a
callback. In between
> >        the time the callback is scheduled and the
time it fires,
> >        you get a blt on the main thread (so that
blt goes through).
> >
> >    Overall, I think we should try to make this
suggestion work.
> >    Or if it's not working, we need to understand
why it 
> doesn't work.
> >    If we can make this work, then the fix becomes
a lot simpler:
> >    we don't have to worry about whether we are in
overlay mode
> >    or basic_blt mode, etc.
> >
> >    The rest of my comments have to do with the fix
as it currently
> >    stands. But top priority is to try the
suggestion above and
> >    either get it work, or understand why it
doesn't work.
> >
> > 2) If we stick with what you currently have (and
for some reason
> >    Milko and Rahul's suggestion above does not
work), then 
> >    I think we won't need the mutexes after all.
The reason is
> >    that access to the CBaseRootSurface is mutex
protected
> >    already. Note the code in CBaseSurface::Blt()
here
> >    (just for the HX_BASIC_BLT mode):
> >
> >         while( HXR_OK != pSurface->Lock(0))
> >
> >    This is calling a Lock() on a mutex inside of
CBaseRootSurface().
> >    So at least for the HX_BASIC_BLT mode, we won't
need
> >    to add a separate mutex inside of
CBaseRootSurface().
> >
> >    However, you will need to call pBase->Lock()
and
> >    pBase->Unlock() on either side of your call
to
> >    pBase->_MinimalBlt().
> >    
> > 3) In your callbacks for UpdateOverlay(), the
problem I
> >    see is that we have rotating buffers. From my
looking
> >    at the code, it looks like the base surface
calls
> >    _LockInternalSurface(), which chooses from a
ring of
> >    buffers. (Usually it's 2, but it could be more
than 2.)
> >    Then it writes into that buffer and then calls
UpdateOverlay(),
> >    which calls XvShmPutImage() or XvPutImage() on
the current
> >    buffer.
> >
> >    The problem is that another blt on the main
thread could come
> >    in between the time that the callback is
scheduled and 
> >    the callback executes. In that case, the
"current buffer"
> >    switches and so the srcRect, dstRect, and flags
you saved
> >    are no longer valid for the current image.
> >
> >    So I think in your callback we should be using
the
> >    saved m_lastUpdateDestRect and
m_lastUpdateSrcRect. I guess
> >    since flags are not currently saved, we'll have
to save
> >    them as well.
> >
> > 4) Instead of HELIX_CONFIG_USE_GTKMAIN_THREAD,
> >    let's call it something more descriptive like 
> >    HELIX_CONFIG_BLT_ONLY_ON_GTK_THREAD
> >
> > 5) Instead of using pthread_self() to get the
> >    current thread ID, you can use the
cross-platform
> >    HXGetCurrentThreadID() defined in
> >    commonsystempubthrdutil.h.
> >
> > 6) +    unsigned int m_IDMainThread;
> >
> >    +   unsigned int m_MainThreadID;
> >   
> >    These should be UINT32, since
HXGetCurrentThreadID()
> >    returns UINT32.
> >
> >
> > Thanks,
> >
> > Eric
> >
> > =============================================
> > Eric Hyche (ehychereal.com)
> > Technical Lead
> > RealNetworks, Inc.  
> >
> >   
> >> -----Original Message-----
> >> From: helix-client-dev-bounceshelixcommunity.org 
> >> [mailto:helix-client-dev-bounceshelixcommunity.org] On 
> >> Behalf Of Deepak Jain
> >> Sent: Thursday, April 24, 2008 7:22 AM
> >> To: video-devhelixcommunity.org; 
> helix-client-devhelixcommunity.org
> >> Subject: [Helix-client-dev] CR:[RESENDING]
Changes to fix the 
> >> Xlib crash happening during the playback with
UI for LitePlayer.
> >>
> >> Resending the updated diff.
> >>
> >> Thanks,
> >> Deepak Jain
> >>
> >> Deepak Jain wrote:
> >>     
> >>> Synopsis:
> >>> Changes to fix the Xlib crash happening
during the 
> playback with UI 
> >>> for LitePlayer.
> >>>
> >>> Overview:
> >>> When we were playing a rm/wm file with UI,
we were getting *Xlib: 
> >>> unexpected async reply message* because we
were blitting on 
> >>>       
> >> multiple 
> >>     
> >>> threads. Now we have scheduled a callback
before call to 
> >>> _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp) if we 
> >>> detect that we are not on the main gtk
thread. When the callback 
> >>> occurs, the callback occurs on the main
thread and we call 
> >>> _MinimalBlt(baseroot.cpp) and
_UpdateOverlay(basesurf.cpp). 
> >>>       
> >> This does 
> >>     
> >>> the blitting on the main thread.
> >>>
> >>> Files Added:
> >>> /video/sitelib/linux2.pcf
> >>>
> >>> Files Modified:
> >>> /video/sitelib/baseroot.cpp
> >>> /video/sitelib/basesurf.cpp
> >>> /video/sitelib/pub/basesurf.h
> >>> /video/sitelib/pub/baseroot.h
> >>>
> >>> Image Size and Heap Use impact (Client
-Only):
> >>> None.
> >>>
> >>> Platforms and Profiles Affected:
> >>> None
> >>>
> >>> Distribution Libraries Affected:
> >>> None
> >>>
> >>> Distribution library impact and planned
action:
> >>> None
> >>>
> >>> Platforms and Profiles Build Verified:
> >>> BIF branch    -> wombat
> >>> Target(s)      ->  LitePlayerWombat
> >>> Profile          ->
helix-client-moblin
> >>> SYSTEM_ID ->
linux-2.2-libc6-gcc32-i586
> >>>
> >>> Branch:
> >>> hxclient_3_1_0_atlas, HEAD
> >>>
> >>> Files Attached:
> >>> sitelib_diff.txt
> >>> linux2.pcf
> >>>
> >>> Thanks,
> >>> Deepak Jain
> >>>
> >>>       
> >>
------------------------------------------------------------
--
> >> ----------
> >>     
> >>> # on gcc we want to turn on all warnings
> >>> extra_cflags = ""
> >>> using_gcc = 0
> >>> if string.find(platform.cc.cmd, 'gcc') !=
-1:
> >>>     using_gcc = 1
> >>>     extra_cflags = "-Wall"
> >>>
> >>> # grab flags from pkgconfig
> >>> import shell
> >>> import string
> >>>
> >>> # see if we're using the target gtk
version (triggers 
> setting of the
> >>> # DISABLE_DEPRECATED flag)
> >>>
> >>> (exitstatus, gtk_mod_version) =
shell.run("pkg-config 
> >>>       
> >> --modversion gtk+-2.0")
> >>     
> >>> if exitstatus != 0:
> >>> 	e = err.Error()
> >>> 	e.Set("pkg-config failed")
> >>> 	raise err.error, e
> >>>
> >>> if string.find(gtk_mod_version,
"2.0") == 0:
> >>>
	project.AddDefines('G_DISABLE_DEPRECATED',
> >>> 					   'GDK_DISABLE_DEPRECATED',
> >>> 					   'GTK_DISABLE_DEPRECATED')
> >>>
> >>> pkg_modules = "gtk+-2.0"
> >>>
> >>> if
project.IsDefined('HELIX_FEATURE_LIBGLADE'):
> >>> 	pkg_modules = pkg_modules + "
libglade-2.0 gmodule-2.0"
> >>>
> >>> (exitstatus, gtk_config_output_cflags) = 
> >>>       
> >> shell.run("pkg-config --cflags " +
pkg_modules)
> >>     
> >>> (exitstatus, gtk_config_output_ldflags) =

> >>>       
> >> shell.run("pkg-config --libs " +
pkg_modules)
> >>     
> >>> gtk_cflags =
string.split(gtk_config_output_cflags)
> >>> gtk_ldflags =
string.split(gtk_config_output_ldflags)
> >>>
> >>> gtk_ld_paths = []
> >>> gtk_libs = []
> >>> gtk_includes = []
> >>> gtk_defines = []
> >>> gtk_other_cflags = ""
> >>> gtk_other_ldflags = ""
> >>>
> >>> for x in gtk_cflags:
> >>> 		if x[0:2] == '-I':
> >>> 				gtk_includes[-1:-1] = [ x[2:] ]
> >>> 		elif x[0:2] == '-D':
> >>> 				gtk_defines[-1:-1] = [ x[2:] ]
> >>> 		else:
> >>> 				gtk_other_cflags = 
> >>>       
> >> gtk_other_cflags + " " + x
> >>     
> >>> for x in gtk_ldflags:
> >>> 		if x[0:2] == '-l':
> >>> 				gtk_libs[-1:-1] = [ x[2:] ]
> >>> 		elif x[0:2] == '-L':
> >>> 				gtk_ld_paths[-1:-1] = [ x ]
> >>> 		else:
> >>> 				gtk_other_ldflags = 
> >>>       
> >> gtk_other_ldflags + " " + x         
      
> >>     
> >>> # add the flags
> >>> project.AddSystemLibraries(gtk_libs)
> >>> project.AddIncludes(gtk_includes)
> >>> project.AddSystemPaths(gtk_ld_paths)
> >>> project.AddDefines(gtk_defines)
> >>>
> >>> platform.cc.args["default"] =
platform.cc.args["default"] + 
> >>>       
> >> " " + gtk_other_cflags + "
" + extra_cflags
> >>     
> >>> platform.cxx.args["default"] =
platform.cxx.args["default"] 
> >>>       
> >> + " " + gtk_other_cflags + "
" + extra_cflags
> >>     
> >>> # platform.link.args["default"]
= 
> >>>       
> >> platform.link.args["default"] +
" " + gtk_other_ldflags
> >>     
> >>>
project.AddDynamicLibraries(gtk_other_ldflags)
> >>>   
> >>>
> >>>       
> >>
------------------------------------------------------------
--
> >> ----------
> >>     
> >>> Index: sitelib/baseroot.cpp
> >>> 
>
============================================================
=======
> >>> RCS file:
/cvsroot/video/sitelib/baseroot.cpp,v
> >>> retrieving revision 1.12
> >>> diff -u -r1.12 baseroot.cpp
> >>> --- sitelib/baseroot.cpp	6 Jul 2007
20:53:58 -0000	1.12
> >>> +++ sitelib/baseroot.cpp	24 Apr 2008
07:47:11 -0000
> >>>  -123,6 +123,10 
> >>>      , m_bUseCardMemory(FALSE)
> >>>      , m_pUnlockingSite(NULL)
> >>>      , zm_pColorAcc(NULL)
> >>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>> +    , m_MainThreadID(0)
> >>> +    , m_pMutexMinimalBlt(NULL)
> >>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>>  {
> >>>  #ifdef _BLT_IN_DEBUG
> >>>     m_nBLTMode = HX_WINDOWLESS_DEBUG;
> >>>  -134,7 +138,10 
> >>>     HX_ASSERT( m_pSite );
> >>>     m_pContext->AddRef();
> >>>     m_pSite->AddRef();
> >>> -
> >>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>> +	m_MainThreadID = pthread_self();
> >>> +	CreateInstanceCCF(CLSID_IHXMutex, 
> >>>       
> >> (void**)&m_pMutexMinimalBlt, m_pContext);
> >>     
> >>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>>     CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pMutex, 
> >>>       
> >> m_pContext);
> >>     
> >>>     CreateInstanceCCF(CLSID_IHXMutex, 
> >>>       
> >> (void**)&m_pCompMutex, m_pContext);
> >>     
> >>>  
> >>>  -190,7 +197,14 
> >>>  #ifdef _WINDOWS
> >>>     HX_RELEASE(m_pPlayer);
> >>>  #endif
> >>> -
> >>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>> +	while(!m_listTimeOutCallback.IsEmpty())
> >>> +	{
> >>> +		guint id  =
(guint)m_listTimeOutCallback.RemoveHead();
> >>> +		g_source_remove (id);
> >>> +	}
> >>> +	HX_RELEASE(m_pMutexMinimalBlt);
> >>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>>     HX_RELEASE(m_pMutex);
> >>>     HX_RELEASE(m_pCompMutex);
> >>>     HX_RELEASE(m_pContext);
> >>>  -271,6 +285,25 
> >>>      }
> >>>  }
> >>>  
> >>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>> +struct GtkInfoMinimalBlt
> >>> +{	
> >>> +	CBaseRootSurface* 	pBase;	
> >>> +	HXxRect         	rDestRect;	
> >>> +};
> >>> +gboolean
CBaseRootSurface::CallbackToMinimalBlt(gpointer data)
> >>> +{
> >>> +	GtkInfoMinimalBlt* pGtkInfoMinimalBlt =

> >>>       
> >> (GtkInfoMinimalBlt*)data;	
> >>     
> >>> +	
> >>>       
> >> 
>
pGtkInfoMinimalBlt->pBase->_MinimalBlt(pGtkInfoMinimal
Blt->rDestRect);
> >>     
> >>>
+	if(!pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback
.IsEmpty())
> >>> +	{	
> >>> +		
> >>>       
> >>
pGtkInfoMinimalBlt->pBase->m_listTimeOutCallback.Remov
eHead();
> >>     
> >>> +	}
> >>> +	HX_DELETE(pGtkInfoMinimalBlt);	
> >>> +	return FALSE;
> >>> +}
> >>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>> +
> >>>  STDMETHODIMP CBaseRootSurface::Blt(
UCHAR*               
> >>>       
> >> pImageData,
> >>     
> >>>                                     
HXBitmapInfoHeader* 
> >>>       
> >> pBitmapInfo,
> >>     
> >>>                                     
REF(HXxRect)         
> rDestRect,
> >>>  -532,7 +565,26 
> >>>                                           
rSrcRect.left, 
> >>>       
> >> rSrcRect.top, dxSrc, dySrc);
> >>     
> >>>  
> >>>              if(
!m_pSite->IsCompositionLocked() && 
> returnVal != -1)
> >>> +            {
> >>> +#ifdef HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>> +            	unsigned int cur_thread =
pthread_self();
> >>> +				if (cur_thread != m_MainThreadID)
> >>> +				{	
> >>> +	            	GtkInfoMinimalBlt* ptr =
new GtkInfoMinimalBlt;
> >>> +					guint id = 0;
> >>> +	            	ptr->pBase = this;	
> >>> +	            	ptr->rDestRect =
rDestRect;	
> >>> +	            	id = g_timeout_add(0, 
> >>>       
> >> CallbackToMinimalBlt, (gpointer*)ptr);
> >>     
> >>> +					
> >>>       
> >> m_listTimeOutCallback.AddTail((void*)id);
> >>     
> >>> +		    		return HXR_OK;
> >>> +				}
> >>> +				m_pMutexMinimalBlt->Lock();
> >>> +#endif //HELIX_CONFIG_USE_GTKMAIN_THREAD
> >>>