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

📄 net_avtcp.cpp

📁 实时监控
💻 CPP
字号:
#include "stdafx.h"
#include "net_avtcp.h"
#include "../NetDef.h"
#include "safe_destroy.h"

// added 2003-10-25, for another decoder lib
#include "../../decoder.h"
#include "net_cmdtcp.h"
#include "../../decoder_factory.h"
#include "reg.h"

extern ULONG use_mpeg4;
extern int  nCurListenGroup ;
extern int	nPreListenGroup ;
extern bool is_cmd_data(byte* buf);
extern FILE *fppppp;

extern BOOL port_type[MAX_PORT];

extern int start_port;
extern LPCTSTR rkSettings;
extern LPCTSTR rvBindPort;
//////////////////////////////////////////////////////////////////////////


COLOR_SPACE net_avtcp::cs = csAUTO;
BOOL net_avtcp::video_mem = TRUE;
int  unused_port()
{
	if(start_port<BEGIN_PORT || start_port > END_PORT)
		start_port = BEGIN_PORT;
	int port = 0;
	for(int i=0;i<MAX_PORT;i++)
	{
		if(!port_type[i])
		{
			port_type[i] = TRUE;
			port = i+start_port;
			if(port > END_PORT)
				port = port - END_PORT + BEGIN_PORT;
			write_dword(rkSettings, rvBindPort, port+1);
			return port;
		}
	}
	return -1;
}
 
//##ModelId=3F9A1D240395
void net_avtcp::switch_audio(int group)
{
	if (nCurListenGroup < 0)  {  //mute
		nPreListenGroup = group ;
	}
	else  { //normal
		nPreListenGroup = nCurListenGroup ;
		nCurListenGroup = group ;
	}
}

//##ModelId=3F9A1D2403AA
void net_avtcp::mute()
{
	nCurListenGroup = -1 ;
}

//##ModelId=3F9A1D2403BD
void net_avtcp::unmute()
{
	nCurListenGroup = nPreListenGroup ;
}

//##ModelId=3F9A1D2403C7
bool net_avtcp::is_muted()
{
	return (nCurListenGroup < 0) ;
}

//##ModelId=3F9A1D24039F
void net_avtcp::mute_toggle()
{
	if( is_muted() )
		unmute();
	else
		mute();
}

//##ModelId=3F9A1D2403DB
int net_avtcp::get_audio_group()
{
	return nCurListenGroup ;
}

//////////////////////////////////////////////////////////////////////////
// net_avtcp 类
//##ModelId=3F9A1D2403E5
net_avtcp::net_avtcp(int idx):
remote_ip(0), remote_port(0), chnl(0)//, tick(0)
, exit(false)
, cb(NULL), index(idx)
, dec(NULL)
{
	avtcp_mode = 0;

	VOD_id = 0;

	bits = 0;
	bitrate = 0;
	bitrate_1 = 0;
	bitrate_2 = 0;
	bitrate_3 = 0;
	bitrate_4 = 0;
	InitializeCriticalSection(&m_cs);
}

//##ModelId=3F9A1D250007
net_avtcp::~net_avtcp()
{
	DeleteCriticalSection(&m_cs);
}


void net_avtcp::on_disconnect(ULONG from_ip, USHORT from_port)
{
//	if( cb )
//		POST_NOTIFY(cb, NTM_CMD_REQUEST_NOT_OK, from_ip, MAKEDWORD(from_port, chnl));
	leave();
}

//##ModelId=3F9A1D240254
//extern int m_tttt;

bool net_avtcp::on_net_tcp_recv(byte* buf, int length, ULONG from_ip, USHORT from_port)
{
	if( exit )
		return false;
	if(is_cmd_data(buf))
	{
		net_cmdtcp *p =	net_cmdtcp::m_netcmdp;
		if(p)
			p->on_net_tcp_recv(buf, length, from_ip, from_port, index);
		return true;	
	}
	bits += length;
	EnterCriticalSection(&m_cs);
	if(dec)
	{
		dec->push_data(buf, length);
	}
	LeaveCriticalSection(&m_cs);
	return true;
}

/*
 *	创建对象, 分配资源(启动解码线程等)
 */
//##ModelId=3F9A1D250011
bool net_avtcp::create(ULONG ip, USHORT port,BOOL bUdpav)
{
	exit = false;
	
	extern USHORT network_bindport;
	if( !net_clienttcp::create(ip, port, network_bindport++,bUdpav) )
		return false;

	dec = decoder_factory::create(use_mpeg4 != 0, index, cb, cs, video_mem, bUdpav);
	if( !dec )
	{
		MessageBox(NULL, _T("Error: Failed to initialize decoder component."), _T("Decoder failure"), MB_OK | MB_ICONERROR);
		return false;
	}

	return true;
}

/*
 *	销毁对象, 关闭解码线程
 */
//##ModelId=3F9A1D25001C
void net_avtcp::destroy()
{
	exit = true;
	decoder_factory::destroy(index);
	net_clienttcp::destroy();
	safe_destroy(dec);	
}

/*
 *	退出多播组, 关闭实时图像
 */
//##ModelId=3F9A1D250043
void net_avtcp::leave()
{
    cb = NULL;
	remote_ip = 0;
	remote_port = 0;
	chnl = 0;

	destroy();
}

//##ModelId=3F9A1D250045
bool net_avtcp::open_channel(ULONG mip, USHORT mport, int channel,BOOL bUdpav)
{
	if( !create(mip, mport,bUdpav))   
	{
		destroy();
		return false;
	}

	remote_ip = mip;
	remote_port = mport;
	chnl = channel;
	
	POST_NOTIFY(cb, NTM_CMD_CHANNEL_OPENED, remote_ip, MAKEDWORD(mport, channel));
	return true;
}

//##ModelId=3F9A1D25006B
void net_avtcp::close_channel(ULONG ip, USHORT port, int channel)
{
	if( remote_ip == ip &&
		remote_port == port &&
		chnl == channel )
		leave();
}

//##ModelId=3F9A1D250080
void net_avtcp::logout(ULONG ip, USHORT port)
{
	if( remote_ip == ip &&
		remote_port == port )
		leave();
}

//##ModelId=3F9A1D250093
ULONG net_avtcp::svr_ip() const
{
	return remote_ip;
}

//##ModelId=3F9A1D25009D
USHORT net_avtcp::svr_port() const
{
	return remote_port;
}

//##ModelId=3F9A1D25009F
int net_avtcp::svr_chnl() const
{
	return chnl;
}

//##ModelId=3F9A1D2500A8
bool net_avtcp::is_opened() const
{
	return remote_ip != 0;
}

bool net_avtcp::is_vod() const
{
	if(remote_ip && remote_port)
	{
		return chnl == -1;
	}

	return false;
}
//##ModelId=3F9A1D2500BB
bool net_avtcp::snapshot(LPCTSTR bmpfile)
{
	if( dec )
		dec->snapshot(bmpfile);
	return true;
}

void net_avtcp::set_cb(VIDEO_CALLEE vcb)
{
	cb = vcb;
	if( IsWindow(vcb))
		update_window();
}
BOOL net_avtcp::set_cb_showhandle(VIDEO_CALLEE cb)
{
	if(dec)
		return dec->set_cb_showhandle(cb);
	return FALSE;
}


//##ModelId=3F9A1D2500C5
void net_avtcp::set_cb(VIDEO_CALLEE vcb, ULONG ip, USHORT port, LONG channel)
{
	cb = vcb;
	remote_ip = ip;
	remote_port = port;
	chnl = channel;

	if(IsWindow(vcb))
		update_window();
}


//##ModelId=3F9A1D2500CF
void net_avtcp::update_window()
{
	if( dec )
		dec->update_pos();
}

//##ModelId=3F9A1D2500D0
void net_avtcp::set_video_renderer(COLOR_SPACE _cs, BOOL _video_mem)
{
	cs = _cs;
	video_mem = _video_mem;
}

void net_avtcp::lr_begin(TCHAR drive)
{
	if( dec )
		dec->lr_begin(drive, chnl);
}

void net_avtcp::lr_end()
{
	//if( !lc.lr_is_recording() )
	//	return;
	
	//lc.lr_end();
	if( dec )
		dec->lr_end();
}

void net_avtcp::lr_get_drive(TCHAR* drive)
{
	if( !dec )
		*drive = 0;
	else
		*drive = dec->lr_get_drive();
}

struct __rebuild{};

void net_avtcp::set_play_mode(int mode)
{
	if( dec )
		dec->set_play_mode(mode);

	avtcp_mode = mode;
}

void net_avtcp::set_vod_id(ULONG id)
{
	VOD_id = id;
}

ULONG net_avtcp::get_vod_id()
{
	if(!is_vod())
		return 0;
	return VOD_id;
}


int net_avtcp::get_play_mode()
{
	if(!is_vod())
		return 0;
	return avtcp_mode;
}

void net_avtcp::go()
{
	if( dec )
		dec->go();
}

void net_avtcp::draw()
{
	if( dec )
		dec->draw();
}

BOOL net_avtcp::join(ULONG ip,USHORT port)
{
	return net_clienttcp::join(ip,port);
}

SOCKET net_avtcp::get_socket()
{
	return net_clienttcp::connect_socket;
}

BOOL net_avtcp::create_udp_socket(ULONG ip,USHORT port)
{
	return net_clienttcp::create_udp_socket(ip,port);
}

⌨️ 快捷键说明

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