?? video_channel.cpp
字號:
// video_channel.cpp : implementation file
//
#include "stdafx.h"
#include "../DvrManager.h"
#include "net.h"
#include "../toolbars/RightCamera.h"
#include "../toolbars/RightLogin.h"
#include "../toolbars/RightLR.h"
#include "../toolbars/RightMD.h"
#include "../toolbars/RightVOD.h"
#include "../utils/balloonhelp.h"
#include "../utils/common.h"
#include "../utils/custom_msgs.h"
#include "msgbox.h"
#include "video_channel.h"
#include "reg.h"
#include "../utils/BitmapPicture.h"
#include "../utils/Picture.h"
#include "memdc.h"
#include "vector"
#include "safe_destroy.h"
#include "../mem_draw_base.h"
#include "../mem_draw_factory.h"
//////////////////////////////////////////////////////////////////////////
// 2004-02-06
//#include "../net/init_multi_dec.h"
//_init_mutli_dec init_multi_dec;
//////////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define SEL_STYLE WS_EX_CLIENTEDGE
/////////////////////////////////////////////////////////////////////////////
// video_channel
#define WIDTH 352
#define HEIGHT 288
#define draw_byte_total 80
extern LPCTSTR rvVideoLogo;
CPicture VIDEO_LOGO;
//##ModelId=3F90BABD006C
typedef std::vector<video_channel*> vclist;
vclist video_wnds;
//##ModelId=3F90BAA70093
video_channel* video_channel::current_sel()
{
if( cur_sel )
return (video_channel*)cur_sel;
else
return (video_channel*)def;
}
//##ModelId=3F90BAA7009D
video_channel* video_channel::number(int idx)
{
return video_wnds[idx];
}
//##ModelId=3F90BAA700B0
int video_channel::count()
{
return video_wnds.size();
}
//##ModelId=3F90BAA70057
video_channel::video_channel():
v_chnl(-2)
, v_ip(0)
, drawing_grid(false)
, w(0), h(0)
, mem_draw(NULL)
{
mask.alloc(draw_byte_total);
//m_boolcheckbuf=true;
m_draw_id=0;
m_Slow = FALSE;
tcpudp_server = FALSE;
}
//##ModelId=3F90BAA700F7
video_channel::~video_channel()
{
safe_destroy(mem_draw);
}
BEGIN_MESSAGE_MAP(video_channel, baseclass)
//{{AFX_MSG_MAP(video_channel)
ON_WM_DESTROY()
ON_WM_MOVE()
ON_WM_SIZE()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_SNAPSHOT, on_snapshot)
MSG2(NTM_CMD_LOGOUT_OK, on_logout)
MSG2(NTM_CMD_CHANNEL_OPENED, on_channel_opened)
MSG2(NTM_CMD_CHANNEL_CLOSED, on_channel_closed)
MSG2(NTM_CMD_REQUEST_NOT_OK, on_req_failure)
MSG2(NTM_VIDEO_FRAME, on_video_frame)
MSG2(NTM_VOD_SET_SPEED, on_vod_set_speed)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// video_channel message handlers
//##ModelId=3F90BAA700D8
void video_channel::dd_update()
{
CRightLogin* rl = CRightLogin::the_one();
if( IsWindow(rl->m_hWnd) )
rl->PostMessage(WM_UPDATE_WINDOW, (WPARAM)index());
// if( dd )
// dd_update_bound(dd);
}
//##ModelId=3F90BAA70060
bool video_channel::create(int index, CWnd* parent, const CRect& rc /* = CRect */,
DWORD style /* = ... */)
{
if( !baseclass::create(index, parent, rc, style) )
return false;
if( index == 0 )
def = this;
CString str ;
// str.Format(_T("%02d"), index+1);
// title = read_string(rkVWTitle, str);
str.Format(IDS_HWND_FMT, index+1) ;
title = str ;
if( !VIDEO_LOGO.IsLoaded() )
{
CString str = read_string(rkSettings, rvVideoLogo);
if( !str.IsEmpty() )
VIDEO_LOGO.Load(str);
}
video_wnds.push_back(this);
// return dd != 0;
return true;
}
//##ModelId=3F90BAA7016F
void video_channel::OnDestroy()
{
// if( dd )
// {
// dd_destroy(dd);
// dd = 0;
// }
baseclass::OnDestroy();
}
//##ModelId=3F90BAA7007E
void video_channel::report_channel()
{
if( cur_sel && cur_sel != this )
return;
CRightLogin* rl = CRightLogin::the_one();
CRightCamera* rc = CRightCamera::the_one();
CRightLR* rlr = CRightLR::the_one();
rl->m_strVideoTitle.Empty();
rl->m_strChannelIndex.Empty();
rl->m_strChannelIP.Empty();
rl->m_strChannelBitrate.Empty();
rl->m_strNetType.Empty();
if( v_chnl != -1 &&
v_chnl != VOD_GROUP )
if( rc->m_hWnd )
{
rc->m_chnl.Format(IDS_CHNL_FMT, v_chnl+1);
}
rl->m_strVideoTitle = title;
if( is_video_opened() )
{
if( v_chnl != VOD_GROUP )
rl->m_strChannelIndex.Format(IDS_CHNL_FMT, v_chnl+1);
else
rl->m_strChannelIndex = IDString(IDS_VOD);
//rl->m_strChannelIP = get_dvrname(v_ip)+get_alias(v_ip);
rl->m_strChannelIP = get_alias(v_ip);
if( rlr->m_hWnd )
{
rlr->m_ctrl = rl->m_strChannelIP;
rlr->m_str_chnl_info.Format(IDS_CHNL_FMT, v_chnl+1);
}
rl->m_slow = m_Slow;
if(tcpudp_server)
{
if(m_Slow)
rl->m_strNetType = "LAN";
else
rl->m_strNetType = "WAN";
}
}
else
{
static IDString NOT_OPENED_YET(IDS_NOT_OPENED_YET);
rl->m_strChannelIndex = NOT_OPENED_YET;
rl->m_strChannelIP = NOT_OPENED_YET;
rl->m_strChannelBitrate = NOT_OPENED_YET;
rl->m_strNetType = NOT_OPENED_YET;
rc->m_control = NOT_OPENED_YET;
rc->m_chnl = NOT_OPENED_YET;
rlr->m_str_chnl_info = NOT_OPENED_YET;
rlr->m_ctrl = NOT_OPENED_YET;
}
// 2003.7.16. nodman
// 不能直接使用UpdateData,
// 因為在登出成功后, 由網絡線程執行到這里, MFC對多線程比較感冒
// rlogin->UpdateData(FALSE); 會出錯
if( rl->m_hWnd )
{
rl->SendMessage(WM_UPDATE_DATA, FALSE);
rl->PostMessage(NTM_REFRESH_BITRATE,NULL,1);
}
if( rc->m_hWnd )
{
rc->ipp = v_ip;
rc->channel = v_chnl;
rc->PostMessage(WM_UPDATE_DATA, FALSE);
}
if( rlr->m_hWnd )
{
rlr->PostMessage(WM_UPDATE_DATA, FALSE, (LPARAM)this);
}
}
/// 從net_cmd得到消息
/// @{
//void video_channel::on_channel_opened(IPPORT_TYPE, ULONG mip, USHORT mport, ULONG channel)
//##ModelId=3F90BAA7011E
LRESULT video_channel::on_channel_opened(WPARAM w, LPARAM l)
{
ULONG ip = w;
USHORT port = HSHORT(l);
SHORT channel = LSHORT(l);
video_opened(ip, port, channel);
RedrawWindow();
return 0;
}
LRESULT video_channel::on_req_failure(WPARAM w, LPARAM l)
{
on_channel_closed(w, l);
CRightLogin* rl = CRightLogin::the_one();
rl->PostMessage(NTM_CMD_REQUEST_NOT_OK, w, l);
return 0;
}
//void video_channel::on_channel_closed(IPPORT_TYPE, ULONG channel)
//##ModelId=3F90BAA70129
LRESULT video_channel::on_channel_closed(WPARAM w, LPARAM l)
{
drawing_grid = false;
ULONG ip = w;
USHORT port = HSHORT(l);
SHORT channel = LSHORT(l);
video_closed(ip, port, channel);
//CRightLogin::the_one()->PostMessage(NTM_CMD_CHANNEL_CLOSED, w, l);
//m_boolcheckbuf=true;
m_draw_id = 0;
on_unsel();
return 0;
}
//void video_channel::on_logout_success(IPPORT_TYPE)
//##ModelId=3F90BAA70101
LRESULT video_channel::on_logout(WPARAM w, LPARAM l)
{
ULONG ip = w;
USHORT port = HSHORT(l);
SHORT channel = LSHORT(l);
if( v_ip == ip_port(ip, port) )
video_closed(ip, port, v_chnl);
return 0;
}
/// @}
// 當前是否打開通道
//##ModelId=3F90BAA700CE
bool video_channel::is_video_opened()
{
return v_ip;
}
// 當選擇時的處理
//##ModelId=3F90BAA60394
void video_channel::on_sel()
{
report_channel();
CRightVOD* rv = CRightVOD::the_one();
if(rv->m_hWnd)
rv->PostMessage(WM_UPDATE_DATA);
}
//##ModelId=3F90BAA6039E
void video_channel::on_unsel()
{
CRect rc;
GetWindowRect(rc);
CWnd* p = GetParent();
if( !p )
return;
p->ScreenToClient(rc);
rc.InflateRect(2,2,2,2);
p->RedrawWindow(rc);
}
// 查詢打開通道的IP
//##ModelId=3F90BAA700BA
ip_port video_channel::channel_ip()
{
return v_ip;
}
// 查詢打開通道的索引
//##ModelId=3F90BAA700C4
int video_channel::channel_index()
{
return v_chnl;
}
//##ModelId=3F90BAA70183
void video_channel::OnMove(int x, int y)
{
baseclass::OnMove(x, y);
dd_update();
}
//##ModelId=3F90BAA70197
void video_channel::OnSize(UINT nType, int cx, int cy)
{
baseclass::OnSize(nType, cx, cy);
dd_update();
}
//##ModelId=3F90BAA700E2
void video_channel::draw(void* buf)
{
check_grid((byte*)buf);
// dd_draw(dd, (LONG)buf);
}
/*
* 已解碼視頻幀到來
*/
//void video_channel::on_video_frame(int channel, void* vid_buf, ULONG size, int w, int h)
//##ModelId=3F90BAA7013D
LRESULT video_channel::on_video_frame(WPARAM w, LPARAM l)
{
byte* buf = (byte*)w;
cs = (COLOR_SPACE)HSHORT(l);
vs = (VIDEO_STANDARDS)LSHORT(l);
check_grid(buf);
if(is_vod())
{
m_checkbuf=buf;
//m_boolcheckbuf=false;
}
m_draw_id++;
check_playing_mode();
if( v_chnl == 0 )
{
const FRAME_BYTES = 352*288*2; // YUY2 colorspace for H263
//SendStreamToMultiDec(0, buf, FRAME_BYTES);
}
return 0;
}
//##ModelId=3F90BAA700EC
BOOL video_channel::PreTranslateMessage(MSG* pMsg)
{
if( AfxGetMainWnd()->SendMessage(WM_FILTER_ACCEL, (WPARAM)pMsg, 0) )
return TRUE;
// if(pMsg->message == WM_RBUTTONDOWN )
// {
// OnRButtonDown();
// if( drawing_grid )
// return TRUE;
// }
return baseclass::PreTranslateMessage(pMsg);
}
//##ModelId=3F90BAA700D0
bool video_channel::is_vod()
{
return v_chnl == VOD_GROUP;
}
//##ModelId=3F90BAA70164
LRESULT video_channel::on_snapshot(WPARAM w, LPARAM)
{
CRightLogin::the_one()->SendMessage(WM_SNAPSHOT);
/*
* 等待下一幀到來
* 下一幀到的時候, h263 解碼器中, 會判斷snapshot是否為空
* 如果不為空, 就把該幀保存在以snapshot為名的文件中.
* 并設snapshot為空, 以防止多次抓圖.
*/
return 0;
}
//////////////////////////////////////////////////////////////////////////
/// 內部處理
//##ModelId=3F90BAA60331
void video_channel::video_opened(ULONG ip, USHORT port, int chnl)
{
if( v_ip )
return;
v_ip = ip_port(ip,port);
v_chnl = chnl;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -