www.gusucode.com > 嵌入式linux系统的网络编程源码程序 > 嵌入式linux系统的网络编程源码程序/视频会议源码/audio_send.cpp

    ///////////////////////////////////////////////////////
// FileName:	audio_send.cpp
// Author:		b1gm0use
// Project:		myaudio

#include <iostream>
#include <qapplication.h>
#include <string.h>

#include "capture_event.h"
#include "audio_send.h"
#include "audio_cap.h"
#include "audio.h"

using namespace std;

///////////////////////////////////////////////////////
// Public Functions
///////////////////////////////////////////////////////


// 构造函数
audio_send::audio_send ( void ) // {{{
{
	verbose_output( 2, "create audio_send" );

	ap = NULL;

	last_image[0] = last_image[1] = NULL;

	frame = 0;

} // }}}


// 析构函数
audio_send::~audio_send ( void ) // {{{
{
		delete [] last_image[0];
		delete [] last_image[1];
} // }}}
	
// 初始化函数
int audio_send::init ( AudioPlayer * ap_in ) // {{{
{
	ap =  ap_in;

	return 0;

} // }}}


// 发送捕捉图像完成的消息
// 维护两个缓冲区,交替使用
// 这个函数中的缓冲区有待优化
int audio_send::send_image ( const BUFF * image, int size ) // {{{
{

	verbose_output( 2, "begin audio send." );
	
	//开辟与获取图像大小相当的缓冲区
	if ( NULL == last_image[frame] )
	{
		last_image[frame] = new BUFF[ size ];

		if ( NULL == last_image[frame] )
		{
			cerr << "Can't alloc new memory" << endl;
			exit( 1 );
		}
	}

	verbose_output( 3, "readjust image buffer" );

	memcpy( last_image[frame], image, size );


	//发送消息
	capture_event * event = new capture_event( AUDIO_EVENT, last_image[frame], size );

	verbose_output( 3, "sending new image change event." );

	QApplication::postEvent( (QObject *) ap, (QEvent *) event );

	frame ^= 1;


	return 0;

} // }}}