A
download otdialap.cpp
Language: C++
Copyright: (c) 1995-99 OpenComm do Brasil Ltda.
LOC: 94
Project Info
Open Telephony Server(opentel)
Server: SourceForge
Type: cvs
...el\server\drivers\dialogic\
   dialogic.dsp
   otdialap.cpp
   otdialap.h
   otdialar.cpp
   otdialar.h
   otdialdev.h
   otdialdrv.cpp
   otdialdrv.h
   otdialdti.cpp
   otdialdti.h
   otdialdxx.cpp
   otdialdxx.h
   otdialei.cpp
   otdialei.h
   otdialev.cpp
   otdialev.h
   otdialex.cpp
   otdialex.h
   otdialgc.cpp
   otdialgc.h
   otdialmsi.cpp
   otdialmsi.h
   otdialogic.cpp
   otdialogic.h
   otdialsc.cpp
   otdialsc.h
   otdialtd.cpp
   otdialtd.h
   otdialtg.cpp
   otdialtg.h

/*****************************************************************************
* OpenTel Telephony Server & Framework
* Copyright (c) 1995-99 OpenComm do Brasil Ltda.
* Todos os direitos reservados.
* Este arquivo contem material confidencial de OpenComm do Brasil, e deve
* darse tratamento como tal.
******************************************************************************/


#ident "@(#) $Header: /cvsroot/opentel/opentel/server/drivers/dialogic/otdialap.cpp,v 1.2 2000/03/24 05:16:43 jbernab Exp $"

#include <otconfig.h>

#ifdef _WINDOWS
#include <windows.h>
#include <io.h>
#endif

extern "C" {
#include <srllib.h>
#include <dxxxlib.h>
};

#ifdef __unix
#include <stdio.h>
#include <stdlib.h>
extern "C" int open( const char *, int );
#endif

#include <fcntl.h>

#include <otcallc.includes>
#include <dialogic/otdialogic.h>
#include <dialogic/otdialdxx.h>
#include <otarchive.includes>
#include <otaudiopla.includes>
#include <dialogic/otdialap.h>

// Group Headers
#include <otgroup.includes>
#include <otgroupim.includes>


OtDialogicAudioPlayer::OtDialogicAudioPlayer( OtDialogicDxx *dxx ) {

        m_dxx = dxx;

        if ( m_dxx )
                m_dxx->addTarget( this );

        setName(OtString ("OtDialogicAudioPlayer(") + OtString(ATDV_NAMEP(m_dxx->getFd())) + ")" );

}

OtDialogicAudioPlayer::~OtDialogicAudioPlayer() {

        if ( m_dxx )
                m_dxx->removeTarget( this );
}

OtTimeSlotListener *OtDialogicAudioPlayer::getListener()
{
        return m_dxx->getListener();
}

OtTimeSlotTransmitter *OtDialogicAudioPlayer::getTransmitter()
{
        return m_dxx->getTransmitter();
}

/* Message reception */
void OtDialogicAudioPlayer::onMessage( OtMessage *msg ) {

        OtEvent *e = ((OtDlgMsg *)msg)->getEv();

        if( e->getClass() == OtDialogicEvent::eventClass ) {
                if ( e->getType() == TDX_PLAY ) {
                        /* The reproduction terminated */
                        /* Lets see why */

                        /* if the reproduction is over, we should close the file now */
#ifdef _WINDOWS
                        _close( m_iott.io_fhandle );
#else
                        close( m_iott.io_fhandle );
#endif
                        m_playing = false;

                        int evt = ATDX_TERMMSK( sr_getevtdev() );

//TODO See if we send Termination information on this event...
// For now we send every other thing like user stop
                        if ( evt & TM_EOD ) {
                                dispatchEvent( OtAudioPlayerEvent::eventEndOfData );
                        }
                        else {                  //      else if ( evt & TM_USRSTOP ) {
                                dispatchEvent( OtAudioPlayerEvent::eventUserStop );
                        }

                }
        }

//      OtMessageTarget::onMessage( msg );
}

/* Digital sound reproduction */
void OtDialogicAudioPlayer::play( const OtString &filename ) {

        if ( isPlaying() )
                throw OtException( "Error: Player already playing!" );


#ifdef _WINDOWS
        if ( ( m_iott.io_fhandle = open( filename, _O_RDONLY ) ) < 0 )
#else
        if ( ( m_iott.io_fhandle = open( filename, O_RDONLY ) ) < 0 )
#endif
                throw OtException( "Error: Could not open source file!" );

        // Set this resource as the resource talking
        // if nescesary do routing this tx to rx of primary
        // could throw exception
        ((OtGroupImpl *)getGroup())->setTalking(this);

        dx_clrtpt( m_tpt, 1 );

        /* TODO: agregar razones para detener automaticamente */

#if 1
        m_tpt[0].tp_type   = IO_EOT; /* only entry in the table */
        m_tpt[0].tp_termno = DX_MAXDTMF; /* Maximum digits */
        m_tpt[0].tp_length = 1; /* terminate in the first digit */
        m_tpt[0].tp_flags = TF_MAXDTMF; /* default flags */
#endif

        m_iott.io_type = IO_EOT | IO_DEV;
        m_iott.io_offset = ( unsigned long )58;
        m_iott.io_length = -1;

        if ( dx_play( m_dxx->getFd(), &m_iott, m_tpt, EV_ASYNC |PM_SR8 |MD_ADPCM|PM_ALAW) < 0 )
//      if ( dx_play( m_dxx->getFd(), &m_iott, NULL, EV_ASYNC |PM_SR8 |MD_ADPCM|PM_ALAW) < 0 )
                throw OtDialogicException( m_dxx->getFd(), "Error: dx_play returned error" );

        m_playing = true;
}

/* Stop playback */
void OtDialogicAudioPlayer::stop() {

        if ( dx_stopch( m_dxx->getFd(), EV_SYNC ) < 0 )
                throw OtDialogicException( m_dxx->getFd(), "Error: dx_stop failed" );
}

void OtDialogicAudioPlayer::dispatchEvent( OtEventType t ) {

        OtAudioPlayerEvent ev( *this , t );
        postEvent( ev );
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us