📄 h265vviewprocess.cpp
字号:
/*
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2006-2008 Beijing, pengzhen (pengzhenxp@yahoo.com.cn) //
// //
///////////////////////////////////////////////////////////////////////////////
*/
void CH265VView::LoadVideo()
{
if( m_device_Video )
{
if( m_iVideoFrames >= m_iVideoTotalFrames )
{
m_pVideoFile.SeekToBegin() ; m_iVideoFrames =0 ;
}
m_pVideoFile.Read(m_pVideo_Y, m_iVideo_Size );
m_iVideoFrames ++ ;
}
else
{
if( m_iVideoFrames >= m_iVideoTotalFramesResource )
{
m_pVideo_Resource_Work = m_pVideo_Resource ; m_iVideoFrames =0 ;
}
fast_memcpy(m_pVideo_Y, m_pVideo_Resource_Work, m_iVideo_Resource_Size );
//memcpy(m_pVideo_Y, m_pVideo_Resource_Work, m_iVideo_Resource_Size );
m_pVideo_Resource_Work += m_iVideo_Resource_Size;
m_iVideoFrames ++ ;
}
}
void CH265VView::LoadAudio()
{
if( m_device_Audio )
{
if( m_iAudioFrames >= m_iAudioTotalFrames )
{
m_pAudioFile.SeekToBegin() ; m_iAudioFrames =0 ;
m_pAudioFile.Seek( audio_wave_header_size, CFile::current ) ; /* wave header size */
}
m_pAudioFile.Read(m_dap_ctx.sample, m_iAudio_Size );
m_iAudioFrames ++ ;
}
else
{
if( m_iAudioFrames >= m_iAudioTotalFramesResource )
{
m_pAudio_Resource_Work = m_pAudio_Resource ; m_iAudioFrames =0 ;
}
fast_memcpy(m_dap_ctx.sample, m_pAudio_Resource_Work, m_iAudio_Size );
m_pAudio_Resource_Work += m_iAudio_Size;
m_iAudioFrames ++ ;
}
}
void CH265VView::ProcessVideo()
{
LARGE_INTEGER t_start, t_end ;
m_dvp_ctx.i420_y = m_pVideo_Y ;
m_dvp_ctx.i420_u = m_pVideo_U ;
m_dvp_ctx.i420_v = m_pVideo_V ;
QueryPerformanceCounter( &t_start ) ; /* start timer */
m_Dvp_Functions( &m_dvp_ctx );
QueryPerformanceCounter( &t_end ) ; /* end timer */
m_iTotalCycles += t_end.QuadPart - t_start.QuadPart ;
if(m_dvp_Compression)
{
if( m_dvp_ctx.stream_length )
{
Write_AVI_Video(m_dvp_ctx.stream, m_dvp_ctx.stream_length, (m_dvp_ctx.type == POT_I) ) ;
}
dvp_frame_number ++ ;
if( ((int)(dvp_frame_number) >= m_iVideoTotalFramesWork) | m_pMessageDlg.m_bClosed )
{
ClearDvp_Compression(); Write_AVI_Finish0() ; BeginView() ;
m_pMessageDlg.str3 = m_pMessageDlg.str4 ;
::SendMessage(m_pMessageDlg.m_hWnd, WM_USER_CTRL, WM_USER_ABOUT_MSG3, 0);
::SendMessage(m_pMessageDlg.m_hWnd, WM_USER_CTRL, WM_USER_ABOUT_EXIT, 2000);
}
int _frames = (int )( dvp_frame_number + 1 ) ;
float _second = (float)( (double)(m_iTotalCycles) /(m_iCPU_Freq.QuadPart) ) ;
int _mips = (int )( (double)(m_iTotalCycles) * m_dvp_ctx.fps /(_frames*1000*1000.0) ) ;
float _freq = (float)( m_iCPU_Freq.QuadPart/(1000*1000*1000.0) ) ;
m_pMessageDlg.str2.Format(TEXT("F=%dF, S=%.2fS, MIPS=%dM, CPUF=%.1fG"),
_frames, _second, _mips, _freq ) ;
::SendMessage(m_pMessageDlg.m_hWnd, WM_USER_CTRL, WM_USER_ABOUT_MSG2, 0);
if( m_device_Video )
{
m_pMessageDlg.str3.Format(TEXT("file = %s"), (const char*)m_pVideoFileName );
::SendMessage(m_pMessageDlg.m_hWnd, WM_USER_CTRL, WM_USER_ABOUT_MSG3, 0);
}
}
else
{
dvp_frame_number ++ ;
if( ((int)(dvp_frame_number) >= m_iVideoTotalFramesWork) )
{
dvp_frame_number = 0 ; BeginView() ;
}
}
}
void CH265VView::ProcessAudio()
{
LARGE_INTEGER t_start, t_end ;
//m_dap_ctx.sample = m_pAudio_Sample ;
//m_dap_ctx.stream = m_pAudio_Stream ;
QueryPerformanceCounter( &t_start ) ; /* start timer */
m_Dap_Functions( &m_dap_ctx );
QueryPerformanceCounter( &t_end ) ; /* end timer */
m_iTotalCycles += t_end.QuadPart - t_start.QuadPart ;
if(m_dap_Compression)
{
Write_AVI_Audio(m_dap_ctx.stream, m_dap_ctx.stream_length, 1 ) ;
dap_frame_number ++ ;
if( ((int)(dap_frame_number) >= m_iAudioTotalFramesWork) | m_pMessageDlg.m_bClosed )
{
ClearDap_Compression(); Write_AVI_Finish0() ; BeginView() ;
m_pMessageDlg.str3 = m_pMessageDlg.str4 ;
::SendMessage(m_pMessageDlg.m_hWnd, WM_USER_CTRL, WM_USER_ABOUT_MSG3, 0);
::SendMessage(m_pMessageDlg.m_hWnd, WM_USER_CTRL, WM_USER_ABOUT_EXIT, 2000);
}
#define ff_dap_fps(X) ((double)(X.sps * X.ch)/DAP_FRAME_SIZE)
int _frames = (int )( dap_frame_number + 1 ) ;
float _second = (float)( (double)(m_iTotalCycles) /(m_iCPU_Freq.QuadPart) ) ;
int _mips = (int )( (double)(m_iTotalCycles) * ff_dap_fps(m_dap_ctx) /(_frames*1000*1000.0) ) ;
float _freq = (float)( m_iCPU_Freq.QuadPart/(1000*1000*1000.0) ) ;
#undef ff_dap_fps
m_pMessageDlg.str2.Format(TEXT("F=%dF, S=%.2fS, MIPS=%dM, CPUF=%.1fG"),
_frames, _second, _mips, _freq ) ;
::SendMessage(m_pMessageDlg.m_hWnd, WM_USER_CTRL, WM_USER_ABOUT_MSG2, 0);
if( m_device_Audio )
{
m_pMessageDlg.str3.Format(TEXT("file = %s"), (const char*)m_pAudioFileName );
::SendMessage(m_pMessageDlg.m_hWnd, WM_USER_CTRL, WM_USER_ABOUT_MSG3, 0);
}
}
else
{
dap_frame_number ++ ;
if( ((int)(dap_frame_number) >= m_iAudioTotalFramesWork) )
{
dap_frame_number = 0 ; BeginView() ;
}
}
}
void CH265VView::ProcessSystem()
{
if( m_iWndIndex <= m_iSendWindowId+1 ) { LoadVideo(); } /* video */
//if( m_iWndIndex <= m_iSendWindowId+1 ) { LoadAudio(); } /* audio */
DrawCurrentText() ;
if( m_bSendWnd && m_dvp ) { ProcessVideo() ; } /* video */
if( m_bSendWnd && /* m_dap */ m_dap_Compression ) { LoadAudio(); ProcessAudio() ; } /* audio */
if( m_view ) DisplayVideoYuv();
if( m_bHistogram ) DrawHistogram() ;
if( m_dvp_pack_yuv420 ) { GET_YUYV() ; }
}
void CH265VView::DisplayVideo()
{
m_pMediaVideoRenderer->Draw( 0 ) ;
if( m_pProcessShareData->m_bDrawMatrix ) DrawMatrix() ;
}
void CH265VView::GoVideo()
{
acquire_exclusive();
if(m_device_Video)
{
m_pVideoFile.SeekToBegin();
m_pVideoFile.Seek( (m_iVideo_Size)*m_iVideoFrames , CFile::current ) ;
}
else
{
m_pVideo_Resource_Work = m_pVideo_Resource + (m_iVideo_Resource_Size)*m_iVideoFrames ;
}
ProcessSystem() ; DisplayVideo() ;
release_exclusive();
}
void CH265VView::DisplayVideoYuv()
{
if( m_view_Y ) //Y
{
BYTE* p = NULL ;
int i, size ;
p = (BYTE*)m_pVideo_U ;
size = m_iVideo_Size0 >> 1 ;
if( p ) { i = size ; while( i -- ) *p++ = 128 ; }
}
if( m_view_U ) //U
{
BYTE* p = NULL ;
BYTE* p1 = NULL ;
int i, size ;
p = (BYTE*)m_pVideo_Y ;
p1 = (BYTE*)m_pVideo_V ;
size = m_iVideo_Size0 ;
if( p ) { i = size ; while( i -- ) *p++ = 128 ; }
if( p1 ) { i = size >>2 ; while( i -- ) *p1++ = 128 ; }
}
if( m_view_V ) //V
{
BYTE* p = NULL ;
BYTE* p1 = NULL ;
int i, size ;
p = (BYTE*)m_pVideo_Y ;
p1 = (BYTE*)m_pVideo_U ;
size = m_iVideo_Size0 ;
if( p ) { i = size ; while( i -- ) *p++ = 128 ; }
if( p1 ) { i = size >>2 ; while( i -- ) *p1++ = 128 ; }
}
}
#if 0
void CH265VView::DrawMV( )
{
int x1 = m_pProcessShareData->m_pImagePos.x >>4 , x ;
int y1 = m_pProcessShareData->m_pImagePos.y >>4 , y ;
motion_vector mv0 = {0,0};
motion_vector* mv1 = (motion_vector*) m_dvp_ctx.motion_vector ;
motion_vector* mv = ( m_bSendWnd && mv1 ) ? &mv1[ y1*mb_stride + x1 ] : &mv0 ;
//CPaintDC dc( this ) ;
//CWindowDC dc( this ) ;
CClientDC dc( this ) ;
CRect rc;
CBrush brush( RGB(0xff, 0, 0) );
CBrush *oldBrush=dc.SelectObject(&brush);
x1 <<= 4;
y1 <<= 4;
//x = get_xy( (x1 + mv->x + MV_SIZE/2) , wid_win_scale ) ;
//y = get_xy( (y1 + mv->y + MV_SIZE/2) , hei_win_scale ) ;
x = get_xy( (x1 + mv->x/2 + MV_SIZE/2) , wid_win_scale ) ;
y = get_xy( (y1 + mv->y/2 + MV_SIZE/2) , hei_win_scale ) ;
//rc = CRect( x-2,y-2, x+2,y+2 );
rc = CRect( x-3,y-3, x+3,y+3 );
dc.RoundRect(&rc, CPoint(x,y) );
dc.SelectObject(oldBrush);
}
void CH265VView::DrawMatrix( )
{
//CPaintDC dc( this ) ;
//CWindowDC dc( this ) ;
CClientDC dc( this ) ;
CRect rc;
CBrush brush( m_bSendWnd ? RGB(0, 0xff, 0) : RGB(0, 0, 0xff) );
CBrush *oldBrush=dc.SelectObject(&brush);
int x1, x ;
int y1, y ;
int mb_width1 ;
int mb_height1 ;
int mb_x ;
int mb_y ;
int mb_xy0 = 0 ;
motion_vector mv0 = {0,0};
motion_vector* mv1 = (motion_vector*) m_dvp_ctx.motion_vector ;
motion_vector* mv ;
y1 =0 ;
mb_y=0 ;
mb_height1 = mb_height ;
while( mb_height1-- )
{
x1 =0 ;
mb_x=0 ;
mb_width1 = mb_width ;
while( mb_width1-- )
{
mv = ( m_bSendWnd && mv1 ) ? &mv1[ mb_xy0+mb_x ] : &mv0 ;
//x = get_xy( (x1 + mv->x + MV_SIZE/2) , wid_win_scale ) ;
//y = get_xy( (y1 + mv->y + MV_SIZE/2) , hei_win_scale ) ;
x = get_xy( (x1 + mv->x/2 + MV_SIZE/2) , wid_win_scale ) ;
y = get_xy( (y1 + mv->y/2 + MV_SIZE/2) , hei_win_scale ) ;
rc = CRect( x-2,y-2, x+2,y+2 );
dc.RoundRect(&rc, CPoint(x,y) );
mb_x ++ ;
x1 += MV_SIZE ;
}
mb_y ++ ;
y1 += MV_SIZE ;
mb_xy0 += mb_stride ;
}
dc.SelectObject(oldBrush);
}
#endif /* */
void CH265VView::DrawHistogram( )
{
int width = m_iVideo_Width ;
int height = m_iVideo_Height ;
int stride = m_iVideo_Width ;
int width1 = width>>1 ;
int height1 = height>>1 ;
int dw = width1 ;
int dh = height1 ;
dvp_ctx* dvp = &m_dvp_ctx ;
BYTE* lpYuv420P_Y = (BYTE*)m_pVideo_Y ;
BYTE* lpYuv420P_U = (BYTE*)m_pVideo_U ;
BYTE* lpYuv420P_V = (BYTE*)m_pVideo_V ;
if( m_dvp_Wavelets_Analysis )
{
int bands = m_dvp_ctx.bands ;
while( bands -- )
{
if(!bands)
{
dvp_get_histogram( dvp, lpYuv420P_Y, width1, height1, stride, dh-2 ) ;
dvp_draw_histogram( dvp, lpYuv420P_Y, stride, 1, 1, dw-2, dh-2 ) ;
}
dvp_get_histogram( dvp, lpYuv420P_Y+width1, width1, height1, stride, dh-2 ) ;
dvp_draw_histogram( dvp, lpYuv420P_Y, stride, dw+1, 1, dw-2, dh-2 ) ;
dvp_get_histogram( dvp, lpYuv420P_Y+((width1*height1)<<1), width1, height1, stride, dh-2 ) ;
dvp_draw_histogram( dvp, lpYuv420P_Y, stride, 1 , dh-1, dw-2, dh-2) ;
//dvp_draw_histogram( dvp, lpYuv420P_Y, stride, 1 , dh+1, dw-2, dh-2) ;
dvp_get_histogram( dvp, lpYuv420P_Y+((width1*height1)<<1)+width1, width1, height1, stride, dh ) ;
dvp_draw_histogram( dvp, lpYuv420P_Y, stride, dw+1, dh-1, dw-2, dh-2 ) ;
//dvp_draw_histogram( dvp, lpYuv420P_Y, stride, dw+1, dh+1, dw-2, dh-2 ) ;
width1 >>=1 ; height1 >>=1; dw >>=1; dh >>=1 ;
}
}
else
{
dvp_get_histogram( dvp, m_pVideo_Y, width, height, width, dh ) ;
dvp_draw_histogram( dvp, lpYuv420P_Y, stride, 2 , 0 , dw-4, dh ) ;
dvp_get_histogram( dvp, lpYuv420P_U, width1, height1, width1, dh ) ;
dvp_draw_histogram( dvp, lpYuv420P_Y, stride, dw+2, 0 , dw-4, dh ) ;
dvp_get_histogram( dvp, lpYuv420P_V, width1, height1, width1, dh ) ;
dvp_draw_histogram( dvp, lpYuv420P_Y, stride, 2 , dh, dw-4, dh ) ;
}
}
void CH265VView::DisplayHistogramText( BOOL isDraw )
{
if( isDraw )
m_pApp->SetStatusBarText( "Histogram : top-left curve is Y; right curve is Cb; left-bottom curve is Cr." );
}
void CH265VView::ManualSegmentationImage()
{
BYTE pixel = m_pProcessShareData->pixel ;
BYTE *p = (BYTE*)m_pVideo_Y;
int i = m_iVideo_Width * m_iVideo_Height ;
while( i-- ) { if( *p > pixel ) *p =0x00 ; p++ ; }
if( m_dvp_pack_yuv420 ) { GET_YUYV() ; }
InvalidateRect( NULL , FALSE );
//ValidateRect( NULL );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -