#include "display.h"
#include "log.h"
#include "singleton.hpp"
#include
#include "rtp_service.h"
#define ID_TIMER 0
const Uint32 overlay_format = GAL_YV12_OVERLAY;//GAL_YV12_OVERLAY;
CDisplay::CDisplay():
m_started(false)
{
logtrace(("CDisplay::CDisplay begin...\n"));
m_img = calloc(1, YUV_WIDTH*YUV_HEIGHT*3);
logtrace(("CDisplay::CDisplay end ok\n"));
}
CDisplay::~CDisplay()
{
logtrace(("CDisplay::~CDisplay begin...\n"));
logtrace(("CDisplay::~CDisplay end ok\n"));
}
int CDisplay::Display_WinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
int ret =0;
ret = singleton::instance().hanlde_winpro(hWnd,message,wParam,lParam);
return 0;
}
int CDisplay::start()
{
logtrace(("CDisplay::start begin...\n"));
int ret =0;
MSG Msg;
m_started = true;
m_CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
m_CreateInfo.dwExStyle = WS_EX_NONE;
m_CreateInfo.spCaption = WINDOW_Caption;
m_CreateInfo.hMenu = 0;
m_CreateInfo.hCursor = GetSystemCursor(0);
m_CreateInfo.hIcon = 0;
m_CreateInfo.MainWindowProc = Display_WinProc;
m_CreateInfo.lx = 0;
m_CreateInfo.ty = 0;
m_CreateInfo.rx = g_rcScr.right;
m_CreateInfo.by = g_rcScr.bottom;
m_CreateInfo.iBkColor = COLOR_lightwhite;
m_CreateInfo.dwAddData = 0;
m_CreateInfo.hHosting = HWND_DESKTOP;
m_hMainWnd = CreateMainWindow (&m_CreateInfo);
if (m_hMainWnd == HWND_INVALID)
return -1;
ShowWindow(m_hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, m_hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}//! end while
MainWindowThreadCleanup (m_hMainWnd);
logtrace(("CDisplay::start end ok\n"));
return ret;
}
int CDisplay::hanlde_winpro(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
logtrace(("CDisplay::hanlde_winpro begin...\n"));
int ret =0;
//HDC hdc;
switch (message) {
case MSG_CREATE:
{
overlay = CreateYUVOverlay(YUV_WIDTH, YUV_HEIGHT, overlay_format, HDC_SCREEN);
SetTimer (hWnd, ID_TIMER, 100);
}break;
case MSG_CLOSE:
{
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
}break;
case MSG_KEYDOWN:
case MSG_LBUTTONUP:
{
ret = handle_click(hWnd,wParam,lParam);
}break;
case MSG_PAINT:
{
ret = handle_paint(hWnd);
}break;
case MSG_TIMER:
{
logtrace(("CDisplay::hanlde_TIMER HOOOOOOOH\n"));
ret = handle_timer(hWnd);
}break;
default:
{
ret = DefaultMainWinProc(hWnd, message, wParam, lParam);
}break;
}//! end switch
logtrace(("CDisplay::hanlde_winpro end ok\n"));
return ret;
}
int CDisplay::drow_img(void* img,size_t size)
{
logtrace(("CDisplay::drow_img begin...size=<%u>\n",size));
if(m_started)
m_decoder.push_frame(img,size);
logtrace(("CDisplay::drow_img end ok \n"));
return 0;
}
int CDisplay::init_window()
{
logtrace(("CDisplay::init_window begin...\n"));
int ret =0;
logtrace(("CDisplay::init_window end ok ret=<%d>\n",ret));
return ret;
}
int CDisplay::handle_paint(HWND hWnd)
{
logtrace(("CDisplay::handle_paint begin...m_size=<%d>\n",m_size));
int ret =0;
HDC hdc;
hdc = BeginPaint (hWnd);//GetClientDC(hWnd);
EndPaint (hWnd, hdc);
logtrace(("CDisplay::handle_paint end ok ret=<%d>\n",ret));
return ret;
}
int CDisplay::handle_click(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
logtrace(("CDisplay::handle_click begin...\n"));
int ret =0;
ret = handle_paint(hWnd);
logtrace(("CDisplay::handle_click end ok ret=<%d>\n",ret));
return ret;
}
int CDisplay::handle_timer(HWND hWnd)
{
for(int i=0;;i++){
usleep(1000);
ShowYUVOverlay(HDC_SCREEN);
}
//SetTimer (hWnd, ID_TIMER, 1);//100 = 1s
logdebug(("CDisplay::handle_timer end ok \n"));
return 0;
}
void CDisplay::ShowYUVOverlay( HDC hdc)
{
RECT rect;
AVFrame pict;
LockYUVOverlay(overlay);
rect.left = 0;
rect.top=0;
rect.right=YUV_WIDTH;
rect.bottom=YUV_HEIGHT;
pict.data[0] = overlay->pixels[0];
pict.data[1] = overlay->pixels[2];
pict.data[2] = overlay->pixels[1];
pict.linesize[0] = overlay->pitches[0];
pict.linesize[1] = overlay->pitches[2];
pict.linesize[2] = overlay->pitches[1];
m_decoder.try_show(&pict);
UnlockYUVOverlay (overlay);
/* 将 YUV 覆盖显示到 DC 对象上的指定矩形区间 */
DisplayYUVOverlay(overlay, &rect);
}