evaluar algo de harbour en c.

evaluar algo de harbour en c.

Postby carlos vargas » Thu Dec 06, 2018 7:18 pm

tengo una clase llamada tvlc, la cual tiene una data llamada bOnEvent de tipo codeblock
ese codeblock necesito pasarlo a c y que se evalue su contenido.
estoy muy confundido con esto ya que supera mis pocos conocimientos en c.

esto es lo que tengo el api de vlc, tiene un event manager, al cual se le debe indicar que
hacer bajo ciertas condiciones.
Code: Select all  Expand view
/*---------------------------------------------------------------------------------------------*/
CLASS TVlc

   /*hidden datas and methods*/
   HIDDEN:
   DATA bOnEvent
   DATA hContainer
   DATA pInstance, pMedia, pMediaPlayer, pEventManager, nStatus
   DATA nVolumeStep INIT 5
   DATA nVolume     INIT 50
   DATA nLen        INIT 0
   DATA nPos        INIT 0
   DATA nTime       INIT 0
   DATA cMediaFile  INIT ""
   DATA aMetaInfo
...

/*Play mediafile*/
METHOD Play() CLASS TVlc

   /*If paused, resume*/
   IF ::Status() == VLC_INPUT_STATE_PAUSED
      ::Pause()
   ELSE
      /*Is playing, exit*/
      IF ::Status() == VLC_INPUT_STATE_PLAYING
         RETURN NIL
      ELSE
         /*If defines mediafile*/
         IF !Empty( ::cMediaFile )
            /*Init info value*/
            ::nLen  := 0
            ::nPos  := 0
            ::nTime := 0

            /*clear metainfo*/
            ::aMetaInfo := NIL

            /*Exist vlc instance*/
            IF !Empty( ::pInstance )

               /*Create media instance*/
               ::pMedia := VLC_CreateMedia( ::pInstance, ::cMediaFile )

               IF !Empty( ::pMedia )
                 
                  /*if metainfo parse medifile and get metainfo*/
                  IF ::lMetaInfo
                     VLC_MediaParse( ::pMedia )
                     ::aMetaInfo := VLC_MediaGetMeta( ::pMedia )
                  ENDIF

                  /*Create mediaplayer instance*/
                  ::pMediaPlayer := VLC_CreateMediaPlayer( ::pMedia )

                  /*Exist mediaplayer instance*/
                  IF !Empty( ::pMediaPlayer )

                     /*Relase media handle, not need*/
                     VLC_MediaRelease( ::pMedia )
                     ::pMedia := NIL
                     
                     /*create event mediamanager*/
                     ::pEventManager := VLC_EventManager( ::pMediaPlayer )

                     /*Define windows container for mediaplayer*/
                     VLC_SetWindow( ::pMediaPlayer, ::hContainer )

                     /*Apply volume*/
                     ::Volume( ::nVolume )

                     /*Play media*/
                     ::nStatus := VLC_Play( ::pMediaPlayer )
 

Code: Select all  Expand view

/*---------------------------------------------------------------------*/
/*
Get the Event Manager from which the media player send event.
return the event manager associated with p_mi (mediaplayer)
LIBVLC_API libvlc_event_manager_t * libvlc_media_player_event_manager ( libvlc_media_player_t *p_mi );
*/

HB_FUNC( VLC_EVENTMANAGER )
{
   libvlc_media_player_t *mediaplayer = (libvlc_media_player_t *) hb_parptr( 1 );
   if( mediaplayer )
   {
      hb_retptr( (void *) libvlc_media_player_event_manager( mediaplayer ) );
   }
   else
   {
      hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
   }
}
/*---------------------------------------------------------------------*/

HB_FUNC( VLC_EVENTATTACH )
{
   libvlc_event_manager_t *eventmanager = (libvlc_event_manager_t *) hb_parptr( 1 );
   if( eventmanager )
   {
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerMediaChanged   , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerNothingSpecial , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerOpening        , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerPlaying        , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerPaused         , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerStopped        , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerEndReached     , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerTimeChanged    , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerPositionChanged, vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerPausableChanged, vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerMuted          , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerUnmuted        , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerAudioVolume    , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerLengthChanged  , vlc_mycallback, NULL );
   }
}

/*---------------------------------------------------------------------*/

HB_FUNC( VLC_EVENTDETCH )
{
   libvlc_event_manager_t *eventmanager = (libvlc_event_manager_t *) hb_parptr( 1 );
   if( eventmanager )
   {
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerMediaChanged   , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerNothingSpecial , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerOpening        , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerPlaying        , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerPaused         , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerStopped        , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerEndReached     , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerTimeChanged    , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerPositionChanged, vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerPausableChanged, vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerMuted          , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerUnmuted        , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerAudioVolume    , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerLengthChanged  , vlc_mycallback, NULL );
   }
}

/*---------------------------------------------------------------------*/

void vlc_mycallback( const libvlc_event_t *event, void *param )
{
   switch ( event->type )
   {
      case libvlc_MediaPlayerMediaChanged:
      case libvlc_MediaPlayerNothingSpecial:
      case libvlc_MediaPlayerOpening:
      case libvlc_MediaPlayerPlaying:
      case libvlc_MediaPlayerPaused:
      case libvlc_MediaPlayerStopped:
      case libvlc_MediaPlayerEndReached:
      case libvlc_MediaPlayerTimeChanged:
      case libvlc_MediaPlayerPositionChanged:
      case libvlc_MediaPlayerPausableChanged:
      case libvlc_MediaPlayerMuted:
      case libvlc_MediaPlayerUnmuted:
      case libvlc_MediaPlayerAudioVolume:
         break;
   }
}
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1719
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: evaluar algo de harbour en c.

Postby carlos vargas » Thu Dec 06, 2018 11:00 pm

/*
static PHB_SYMB pSymbol = NULL;
if( ! pSymbol )
pSymbol = hb_dynsymSymbol( hb_dynsymGet( "OBTNEVENTS" ) );
if( pSymbol )
{
hb_vmPushSymbol( pSymbol );
hb_vmPushNil();
hb_vmPushNumInt( ( LONG_PTR ) hButton );
hb_vmPushLong( Msg );
hb_vmPushNumInt( wParam );
hb_vmPushNumInt( lParam );
hb_vmDo( 4 );
}

*/
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1719
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: evaluar algo de harbour en c.

Postby Antonio Linares » Fri Dec 07, 2018 8:08 am

muy bien :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42063
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: evaluar algo de harbour en c.

Postby carlos vargas » Fri Dec 07, 2018 7:02 pm

Antonio, este código en raras ocaciones que funciona, y luego ni ejecutando el exe funciona.
de pronto funciona y falla nuevamente.
este callback es llamado cada 300 milisegundos aproximadamente por vlc internamente. es esto un problema?
Code: Select all  Expand view

PROCEDURE VLC_MYEVENT( nEvent )
   Debug( "Event: " + cstr( nEvent ) )
RETURN

Code: Select all  Expand view

void vlc_mycallback( const libvlc_event_t *event, void *param )
{
   static PHB_SYMB pSymbol = NULL;
   if ( ! pSymbol)
   {
      pSymbol = hb_dynsymSymbol( hb_dynsymGet( "VLC_MYEVENT" ) );
   }
   if ( pSymbol )
   {
      hb_vmPushSymbol( pSymbol );
      hb_vmPushNil();
      hb_vmPushInteger( ( HB_INT ) event->type );
      hb_vmDo( 1 );
   }
   //DebugC( "Callback" );
   //DebugN( (float) event->type );
   /*
   switch ( event->type )
   {
      case libvlc_MediaPlayerMediaChanged:
      case libvlc_MediaPlayerNothingSpecial:
      case libvlc_MediaPlayerOpening:
      case libvlc_MediaPlayerPlaying:
      case libvlc_MediaPlayerPaused:
      case libvlc_MediaPlayerStopped:
      case libvlc_MediaPlayerEndReached:
      case libvlc_MediaPlayerTimeChanged:
      case libvlc_MediaPlayerPositionChanged:
      case libvlc_MediaPlayerPausableChanged:
      case libvlc_MediaPlayerMuted:
      case libvlc_MediaPlayerUnmuted:
      case libvlc_MediaPlayerAudioVolume:
         break;
   }
   */

}
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1719
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: evaluar algo de harbour en c.

Postby carlos vargas » Fri Dec 07, 2018 7:14 pm

Application Internal Error - d:\myplayer\myplayer.exe
Terminated at: 2018-12-07 13:14:03
Error irrecuperable 9015: S¡mbolo item esperado desde hb_vmDo()
Called from WINRUN(0)
Called from TWINDOW:ACTIVATE(1052) in .\source\classes\WINDOW.PRG
Called from MAIN(54) in source\myplayer.prg
------------------------------------------------------------------------
Application Internal Error - d:\myplayer\myplayer.exe
Terminated at: 2018-12-07 13:14:13
Error irrecuperable 9020: Un item estaba siendo copiado sobre s¡ mismo desde hb_itemCopy()
Called from DIRECTORY(0)
Called from FSIZE(190) in .\source\function\FILENAME.PRG
Called from ERRORDIALOG(141) in .\source\function\ERRSYSW.PRG
Called from (b)ERRORSYS(23) in .\source\function\ERRSYSW.PRG
Called from LMOUSEDOWN(0)
Called from VLC_MYEVENT(683) in source\tvlc.prg
Called from TCONTROL:MOUSEMOVE(0) in .\source\classes\CONTROL.PRG
Called from TCONTROL:MOUSEMOVE(0) in .\source\classes\CONTROL.PRG
Called from (b)TBUTTON(46) in .\source\classes\BUTTON.PRG
Called from TBUTTON:MOUSEMOVE(0) in .\source\classes\BUTTON.PRG
Called from TWINDOW:HANDLEEVENT(0)
Called from TBUTTON:HANDLEEVENT(1732) in .\source\classes\CONTROL.PRG
Called from _FWH(3451) in .\source\classes\WINDOW.PRG
Called from WINRUN(0)
Called from TWINDOW:ACTIVATE(1052) in .\source\classes\WINDOW.PRG
Called from MAIN(54) in source\myplayer.prg
------------------------------------------------------------------------
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1719
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: evaluar algo de harbour en c.

Postby carlos vargas » Fri Dec 07, 2018 7:56 pm

esto funciona bien, no hay cuelge.
En el viewdegung se muestra la información sin problema:

Code: Select all  Expand view
void vlc_mycallback( const libvlc_event_t *event, void *param )
{
   DebugC( "Callback" );
   DebugN( (float) event->type );
   DebugN( (float) event->u.media_player_time_changed.new_time );
}
 

Image
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1719
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: evaluar algo de harbour en c.

Postby carlos vargas » Fri Dec 07, 2018 9:59 pm

itentando cambiar la cosa por un codeblock.
sin la llamada a hb_evalBlock0 funciona y muestra la informacion de depuración
:-(
Code: Select all  Expand view

   ::bEval      := {|| Debug( time() ) }
 

Code: Select all  Expand view

                  ::pMediaPlayer := VLC_CreateMediaPlayer( ::pMedia )
                  IF !Empty( ::pMediaPlayer )
                     VLC_MediaRelease( ::pMedia )
                     ::pMedia := NIL
                     ::pEventManager := VLC_EventManager( ::pMediaPlayer )
                     VLC_EventAttach( ::pEventManager, ::bEval )
 

Code: Select all  Expand view

....
HB_FUNC( VLC_EVENTATTACH )
{
   libvlc_event_manager_t *eventmanager = (libvlc_event_manager_t *) hb_parptr( 1 );
   void *pCB = (void *) hb_param( 2, HB_IT_BLOCK );
   if( eventmanager )
   {
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerMediaChanged   , vlc_mycallback, pCB );
 

 
Code: Select all  Expand view

void vlc_mycallback( const libvlc_event_t *pEvt, void *pUserData )
{
   PHB_ITEM pCode = (PHB_ITEM) pUserData;
   switch ( pEvt->type )
   {
      case libvlc_MediaPlayerTimeChanged:
         if( pCode )
         {
            hb_evalBlock0( pCode );
            //DebugN( (float) pEvt->u.media_player_time_changed.new_time );
         }
         break;
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1719
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: evaluar algo de harbour en c.

Postby carlos vargas » Mon Dec 10, 2018 5:45 pm

De momento funcionando ok con este código:
Code: Select all  Expand view

PROCEDURE VLC_MYEVENT( uParam )
   Debug( " Event: " + cstr( uParam ) )
RETURN
 

Code: Select all  Expand view

...
static PHB_DYNS pFunc = NULL;
...
void vlc_mycallback( const libvlc_event_t *pEvt, void *pUserData )
{
   if( pFunc == NULL )
   {
      pFunc = hb_dynsymGetCase( "VLC_MYEVENT" );
   }
   switch ( pEvt->type )
   {
     ...
      case libvlc_MediaPlayerTimeChanged:
         if( hb_dynsymIsFunction( pFunc ) )
         {
            hb_vmPushDynSym( pFunc );
            hb_vmPushNil();
            hb_vmPushLong( (long) pEvt->u.media_player_time_changed.new_time );
            hb_vmDo(1);
         }
         break;
...
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1719
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 58 guests