FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour evaluar algo de harbour en c.
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
evaluar algo de harbour en c.
Posted: Thu Dec 06, 2018 07: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 (fw): Select all Collapse
/*---------------------------------------------------------------------------------------------*/
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 (fw): Select all Collapse
/*---------------------------------------------------------------------*/
/*
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)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: evaluar algo de harbour en c.
Posted: 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)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: evaluar algo de harbour en c.
Posted: Fri Dec 07, 2018 08:08 AM

muy bien :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: evaluar algo de harbour en c.
Posted: Fri Dec 07, 2018 07: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 (fw): Select all Collapse
PROCEDURE VLC_MYEVENT( nEvent )
聽 聽Debug( "Event: " + cstr( nEvent ) )
RETURN

Code (fw): Select all Collapse
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)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: evaluar algo de harbour en c.
Posted: Fri Dec 07, 2018 07: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)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: evaluar algo de harbour en c.
Posted: Fri Dec 07, 2018 07:56 PM
esto funciona bien, no hay cuelge.
En el viewdegung se muestra la informaci贸n sin problema:

Code (fw): Select all Collapse
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 );
}

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: evaluar algo de harbour en c.
Posted: Fri Dec 07, 2018 09:59 PM
itentando cambiar la cosa por un codeblock.
sin la llamada a hb_evalBlock0 funciona y muestra la informacion de depuraci贸n
:-)
Code (fw): Select all Collapse
聽 聽::bEval 聽 聽 聽:= {|| Debug( time() ) }

Code (fw): Select all Collapse
聽 聽 聽 聽 聽 聽 聽 聽 聽 ::pMediaPlayer := VLC_CreateMediaPlayer( ::pMedia )
聽 聽 聽 聽 聽 聽 聽 聽 聽 IF !Empty( ::pMediaPlayer )
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽VLC_MediaRelease( ::pMedia )
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽::pMedia := NIL
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽::pEventManager := VLC_EventManager( ::pMediaPlayer )
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽VLC_EventAttach( ::pEventManager, ::bEval )

Code (fw): Select all Collapse
....
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 (fw): Select all Collapse
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)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: evaluar algo de harbour en c.
Posted: Mon Dec 10, 2018 05:45 PM
De momento funcionando ok con este c贸digo:
Code (fw): Select all Collapse
PROCEDURE VLC_MYEVENT( uParam )
聽 聽Debug( " Event: " + cstr( uParam ) )
RETURN

Code (fw): Select all Collapse
...
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)

Continue the discussion