⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callaudio.cpp

📁 kphone-4.2,SHELL协议的VOIP电话
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#include <sys/types.h>#include <unistd.h>#include <signal.h>#include <qsettings.h>#include <qmessagebox.h>#include "../config.h"#include "../dissipate2/sipprotocol.h"#include "../dissipate2/sipcall.h"#include "../dissipate2/sdp.h"#include "dspaudioout.h"#include "dspaudioin.h"#include "dspoutrtp.h"#include "dspoutoss.h"#include "kphoneview.h"#ifdef ALSA_SUPPORT#include "dspoutalsa.h"#endif#ifdef JACK_SUPPORT#include "dspaudiojackout.h"#include "dspaudiojackin.h"#endif#include "callaudio.h"CallAudio::CallAudio(  KPhoneView *phoneview ){	view = phoneview;	if( view->useStunSrv() ) {		setStunSrv( view->getStunSrv() );	}	jack_audioout = 0;	jack_audioin = 0;	output = 0;	input = 0;	curcall = 0;	curmember = 0;	audiomode = oss;	setOSSFilename( QString::null );	setOSSFilename2( QString::null );	setALSADevicename( QString::null );	setVideoSW( QString::null );	local.setIpAddress( "0.0.0.0" );	QSettings settings;	payload = settings.readNumEntry( "/kphone/dsp/SizeOfPayload", 160 );	codec = codecILBC_20;	rtpCodec = codecUnknown;	videoCodec = codecUnknown;	videoRtpCodec = codecUnknown;	bodyMask = QString::null;	useStun = false;	symMedia = false;	pidVideo = 0;	audio_fd = -1;}CallAudio::~CallAudio( void ){	if( output ) {		if( output->running() ) {			output->setCancel();			output->wait();		}		delete output;	}	if( input ) {		if( input->running() ) {			input->setCancel();			input->wait();		}		delete input;	}}void CallAudio::setAudiomode( QString str ){	if( str.upper() == "OSS" ) {		if( audiomode == oss ) return;		audiomode = oss;	} else if( str.upper() == "ALSA" ) {		if( audiomode == alsa ) return;		audiomode = alsa;	} else if( str.upper() == "JACK" ) {		if( audiomode == jack ) return;		audiomode = jack;	}	renegotiateCall();}void CallAudio::setOSSFilename( const QString &devname ){	if( devname == QString::null ) {		ossfilename = "/dev/dsp";	} else {		ossfilename = devname;	}}void CallAudio::setOSSFilename2( const QString &devname ){	if( devname == QString::null ) {		ossfilename2 = "/dev/dsp";	} else {		ossfilename2 = devname;	}}void CallAudio::setALSADevicename( const QString &devname ){	if( devname == QString::null ) {		alsadevicename = "default";	} else {		alsadevicename = devname;	}}void CallAudio::setVideoSW( const QString &sw ){	if( sw == QString::null ) {		videoSW = "vic";	} else {		videoSW = sw;	}}void CallAudio::audioIn( void ){	QString hostname = remote.getIpAddress();	unsigned int portnum = remote.getPort();	if( hostname == QString::null || portnum == 0 ) {		printf( tr("CallAudio: SendToRemote called but we don't have a valid session description yet") + "\n" );		return;	}	if( remote.isOnHold() ) {		printf( tr("CallAudio: Remote is currently putting us on hold, waiting patiently") + "\n" );		return;	}	printf( tr("CallAudio: Sending to remote site %s:%d") + "\n", hostname.latin1(), portnum );	if( input ) {		stopListeningAudio();	}	DspOut *out;	DspOut *in;	if( audiomode == oss ) {		DspOutRtp *outrtp;		if (symMedia) {			outrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum(), hostname, &socket );		} else {			outrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum(), hostname );		}		outrtp->setPortNum( portnum );		outrtp->openDevice( DspOut::WriteOnly );		outrtp->setPayload( payload );		DspOutOss *inaudio = new DspOutOss( ossfilename2 );		QSettings settings;		if( settings.readEntry( "/kphone/audio/mode", "readwrite" ) == "readwrite" ) {			if( !inaudio->openDevice( audio_fd ) ) {				printf( tr("** audioIn: openDevice Failed.") + "\n" );			}		} else {			printf( tr("CallAudio: Opening OSS device %s for Input") + "\n", ossfilename2.latin1() );			if( !inaudio->openDevice( DspOut::ReadOnly ) ) {				printf( tr("** audioIn: openDevice Failed.") + "\n" );			}		}		inaudio->readBuffer(2);		out = outrtp;		in = inaudio;		printf( tr("CallAudio: Creating OSS->RTP Diverter") + "\n" );		input = new DspAudioIn( in, out );#ifdef ALSA_SUPPORT	} else if( audiomode == alsa ) {		DspOutRtp *outrtp;		if (symMedia) {			outrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum(), hostname, &socket );		} else {			outrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum(), hostname );		}		outrtp->setPortNum( portnum );		outrtp->openDevice( DspOut::WriteOnly );		outrtp->setPayload( payload );		DspOutAlsa *inaudio = new DspOutAlsa( alsadevicename );		QSettings settings;		printf( "CallAudio: Opening ALSA device for Input \n" );		if( !inaudio->openDevice( DspOut::ReadOnly ) ) {			printf( "** audioIn: openDevice Failed.\n" );		}		out = outrtp;		in = inaudio;		printf( "CallAudio: Creating ALSA->RTP Diverter\n" );		input = new DspAudioIn( in, out );#endif#ifdef JACK_SUPPORT	} else if( audiomode == jack ) {		DspOutRtp *outrtp;		if (symMedia) {			outrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum(), hostname, &socket );		} else {			outrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum(), hostname );		}		outrtp->setPortNum( portnum );		outrtp->openDevice( DspOut::WriteOnly );		outrtp->setPayload( payload );				printf( "CallAudio: Creating JACK->RTP Diverter\n" );		QString s = curcall->getCallId();		QString name = "Kphone-" + s.left( s.find( '@' )) + "-in";		jack_audioin = new DspAudioJackIn( outrtp, name );#endif	}	if( curcall->getCallType() == SipCall::videoCall ) {		printf( tr("CallAudio: Opening SW for video input and output") + "\n" );		pidVideo = fork();		if( !pidVideo ) {			QSettings settings;			QString videoSW = settings.readEntry(				"/kphone/video/videoSW", "/usr/local/bin/vic" );			QString videoCodec = getVideoRtpCodecName();			QString SW = videoSW;			if( SW.contains( "/" ) ) {				SW = SW.mid( SW.findRev( '/' ) + 1 );			}			QString videoSWParam = hostname + "/" +				QString::number( remote.getVideoPort() ) + "/";			videoSWParam += videoCodec + "/16/" +				QString::number( local.getVideoPort() );			printf( "CallAudio: execlp( %s, %s, %s, 0)\n",				videoSW.latin1(), SW.latin1(), videoSWParam.latin1() );			execlp( videoSW.latin1(), SW.latin1(), videoSWParam.latin1(), 0 );			printf( tr("error executing ") + videoSW + "\n" );			exit(1);		}	}}void CallAudio::stopListeningAudio( void ){	if( input ) {		if( input->running() ) {			input->setCancel();			input->wait();		}		delete input;	}	input = 0;#ifdef JACK_SUPPORT	if( jack_audioin ) {		jack_audioin->exit();//		delete jack_audioin;	}	jack_audioin = 0;#endif	remote = SdpMessage::null;}SdpMessage CallAudio::audioOut( void ){	printf( "CallAudio: listening for incomming RTP\n" );	if( output ) {		stopSendingAudio();	}	DspOut *out;	DspOut *in;	local.setIpAddress( Sip::getLocalAddress() );	local.setName( "The Funky Flow" );	if( audiomode == oss ) {		DspOutRtp *inrtp;		if (symMedia) {			inrtp = new DspOutRtp( getRtpCodec(),				getRtpCodecNum(), QString::null, &socket );		} else {			inrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum() );		}		inrtp->setPayload( payload );		if( useStun ) {			inrtp->setStunSrv( stunSrv );		}		inrtp->openDevice( DspOut::ReadOnly );		local.setPort( inrtp->getPortNum() );		local.setVideoPort( inrtp->getVideoPortNum() );		DspOutOss *outoss = new DspOutOss( ossfilename );		QSettings settings;		if( settings.readEntry( "/kphone/audio/mode", "readwrite" ) == "readwrite" ) {			printf( tr("CallAudio: Opening OSS device %s for Input and Output") + "\n", ossfilename.latin1() );			if( !outoss->openDevice( DspOut::ReadWrite ) ) {				printf( tr("** audioOut: openDevice Failed.") + "\n" );			} else {				audio_fd = outoss->audio_fd;			}		} else {			printf( tr("CallAudio: Opening OSS device %s for Output") + "\n", ossfilename.latin1() );			if( !outoss->openDevice( DspOut::WriteOnly )){				printf( tr("** audioOut: openDevice Failed.") + "\n" );			}		}		in = inrtp;		out = outoss;		printf( tr("CallAudio: Creating RTP->OSS Diverter") + "\n" );		output = new DspAudioOut( in, out );#ifdef ALSA_SUPPORT	} else if( audiomode == alsa ) {		DspOutRtp *inrtp;		if (symMedia) {			inrtp = new DspOutRtp( getRtpCodec(),				getRtpCodecNum(), QString::null, &socket );		} else {			inrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum() );		}		inrtp->setPayload( payload );		if( useStun ) {			inrtp->setStunSrv( stunSrv );		}		inrtp->openDevice( DspOut::ReadOnly );		local.setPort( inrtp->getPortNum() );		local.setVideoPort( inrtp->getVideoPortNum() );		DspOutAlsa *outalsa = new DspOutAlsa( alsadevicename );		QSettings settings;		printf( "CallAudio: Opening ALSA device for Output\n" );		if( !outalsa->openDevice( DspOut::WriteOnly )){			printf( "** audioOut: openDevice Failed.\n" );		}		in = inrtp;		out = outalsa;		printf( tr("CallAudio: Creating RTP->ALSA Diverter") + "\n" );		output = new DspAudioOut( in, out );#endif#ifdef JACK_SUPPORT	} else if( audiomode == jack ) {		DspOutRtp *inrtp;		if (symMedia) {			inrtp = new DspOutRtp( getRtpCodec(),				getRtpCodecNum(), QString::null, &socket );		} else {			inrtp = new DspOutRtp( getRtpCodec(), getRtpCodecNum() );		}		inrtp->setPayload( payload );		if( useStun ) {			inrtp->setStunSrv( stunSrv );		}		inrtp->openDevice( DspOut::ReadOnly );		local.setPort( inrtp->getPortNum() );		local.setVideoPort( inrtp->getVideoPortNum() );		printf( "CallAudio: Creating RTP->JACK Diverter\n" );		QString s = curcall->getCallId();		QString name = "Kphone-" + s.left( s.find( '@' )) + "-out";		jack_audioout = new DspAudioJackOut( inrtp, name );		if ( !jack_audioout->ok() ) {			QMessageBox::critical( view, "KPhone", "CallAudioJackOut: Error, jack server not running?" );		}#endif	}	return local;}void CallAudio::stopSendingAudio( void ){	if( output ) {		if( output->running() ) {			output->setCancel();			output->wait();		}		delete output;	}	output = 0;#ifdef JACK_SUPPORT	if( jack_audioout ) {		jack_audioout->exit();		delete jack_audioout;	}	jack_audioout = 0;#endif	local.setIpAddress( "0.0.0.0" );	local.setName( "Idle" );	local.setPort( 0 );	local.setVideoPort( 0 );}void CallAudio::saveAudioSettings( void ){	QSettings settings;	settings.writeEntry( "/kphone/audio/oss-filename", getOSSFilename() );	settings.writeEntry( "/kphone/audio/oss-filename2", getOSSFilename2() );}void CallAudio::readAudioSettings( void ){	QSettings settings;	setOSSFilename( settings.readEntry( "/kphone/audio/oss-filename" ) );	setOSSFilename2( settings.readEntry( "/kphone/audio/oss-filename2" ) );	setALSADevicename( settings.readEntry( "/kphone/audio/alsa-devicename" ) );	if( settings.readEntry( "/kphone/Symmetric/Media", "Yes" ) == "Yes" ) {		setSymMediaMode( true );	}	QString audiomodestr = settings.readEntry( "/kphone/audio/audio", "oss" );	setAudiomode( audiomodestr );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -