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

    ///////////////////////////////////////////////////////
// FileName:	network_video_send.cpp
// Author:		b1gm0use
// Project:		myvideo

#include <iostream>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <qapplication.h>
#include <qsemaphore.h>

#include "network_video_send.h"
#include "network.h"
#include "capture_event.h"
#include "video.h"
#include "avi.h"

using namespace std;

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

// 构造函数
network_video_send::network_video_send ( avi * avi_ptr_in ) // {{{
{

	verbose_output( 2, "create network_video_send" );

	cfd = 0;
	
	last_buff = NULL;

	avi_ptr = avi_ptr_in;

} // }}}

network_video_send::~network_video_send ( void ) // {{{
{
	delete [] last_buff;
} // }}}

// 初始化函数
int network_video_send::init ( void ) // {{{
{
	verbose_output( 2, "init network_video_send" );

	last_buff = new BUFF [ avi_ptr->video_opt.min_height * avi_ptr->video_opt.factor * avi_ptr->video_opt.min_width * avi_ptr->video_opt.factor * 3 ];

	return SUCCEED;

} // }}}

	
// 向网络上发送图像
int network_video_send::send_image ( const BUFF * buff, int size ) // {{{
{

	verbose_output( 2, "network_video_send send_image" );

	memcpy( last_buff, buff, size );

	capture_event new_event( VIDEO_NET_SEND_EVENT, last_buff, size );

	if ( NULL != avi_ptr->network_ctrl_ptr )
	{
		(*(avi_ptr->send_image_semaphore))++;
		QApplication::sendEvent( (QObject *) avi_ptr->network_ctrl_ptr, (QEvent *) &new_event );	
		(*(avi_ptr->send_image_semaphore))--;
	}

	verbose_output( 3, "send video frame ok" );

	return SUCCEED;

} // }}}