📄 h265vviewresource.cpp
字号:
/*
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2006-2008 Beijing, pengzhen (pengzhenxp@yahoo.com.cn) //
// //
///////////////////////////////////////////////////////////////////////////////
*/
void CH265VView::GetProcessShareData( HWND hWnd /*= NULL*/ , BOOL bWndStart /*= FALSE*/ )
{
/* Process Share Data */
m_pProcessShareData = CH265VApp::m_pProcessShareData ;
/* Process Share Data */
m_iWndIndex = m_pProcessShareData->m_iExeCount ;
m_bSendWnd = m_bSendWindow ;
m_pProcessShareData->m_hWnd[m_iWndIndex] = hWnd /*this->m_hWnd*/ ;
m_pVideoFileName = m_pProcessShareData->m_pVideoFileName ; /* video */
m_pAudioFileName = m_pProcessShareData->m_pAudioFileName ; /* audio */
//m_device_Video = m_pProcessShareData->m_device_Video ;
//m_pProcessShareData->m_bDrawMatrix = FALSE ;
/* for CH265VView::SystemExecute() */
if(bWndStart)
{
m_pProcessShareData->m_iExeCount ++ ; /* next window */
m_pProcessShareData->m_bWndStart = TRUE ; /* Recieve Windows Started */
}
else
{
m_pProcessShareData->width = m_iVideo_Resource_Width ;
m_pProcessShareData->height = m_iVideo_Resource_Height ;
}
}
void CH265VView::GetMemoryBuffer()
{
BYTE* lpBuffer = ((BYTE*)m_pProcessShareData) + sizeof(ProcessShareData) ;
/* audio */
m_dap_ctx.sample = lpBuffer ; /* sample */
m_dap_ctx.stream = lpBuffer + m_iAudio_Resource_Size0 * 4 ; /* stream */
//m_pAudio_Sample = lpBuffer ; /* sample */
//m_pAudio_Stream = lpBuffer + m_iAudio_Resource_Size0 * 4 ; /* stream */
lpBuffer += m_MaxAudioSize ;
/* video */
m_dvp_ctx.stream = lpBuffer ; /* stream */
lpBuffer += ((m_MaxImageWidth*m_MaxImageHeight)*4) ; /* decode */
/* YUV420 */
m_pVideo_Y = lpBuffer + m_iWndIndex*m_MaxYuv420Size ;
}
void CH265VView::SetMemoryBuffer(int width , int height )
{
if( (m_iVideo_Width == width) && (m_iVideo_Height == height) ) return ;
BYTE * lpBuffer = (BYTE*)m_pVideo_Y ;
if( m_bSendWnd ) dvp_init( &m_dvp_ctx, width, height ) ;
m_iVideo_Width = width ;
m_iVideo_Height = height ;
m_iVideo_Size0 = width*height ;
m_iVideo_Size = m_iVideo_Size0*3/2 ; /* YUV420 */
/* YUV420 */
m_pVideo_U = lpBuffer + (m_iVideo_Size0) ;
m_pVideo_V = lpBuffer + (m_iVideo_Size0) + (m_iVideo_Size0>>2) ;
/* MV */
mb_width = MV_width(width) ;
mb_height = MV_height(height) ;
//mb_stride = mb_width ;
mb_stride = MV_stride(mb_width) ;
wid_win_scale = get_scale(m_pClientRect.Width(), m_iVideo_Width ) ;
hei_win_scale = get_scale(m_pClientRect.Height(), m_iVideo_Height ) ;
//wid_pic_scale1 = get_scale(256*2, m_pClientRect.Width() ) ;
wid_pic_scale = get_scale(m_iVideo_Width, m_pClientRect.Width() ) ;
hei_pic_scale = get_scale(m_iVideo_Height, m_pClientRect.Height() ) ;
}
void CH265VView::GetVideoRender( BOOL bDrawRectFlag )
{
int thread_ctrl_flag = thread_ctrl() ; StopView() ;
SetMemoryBuffer( m_pProcessShareData->width , m_pProcessShareData->height ) ;
m_iVideo_Width = m_pProcessShareData->width ;
m_iVideo_Height = m_pProcessShareData->height ;
if( bDrawRectFlag ) m_pMediaVideoRenderer->ddraw_exit() ;
if( ! m_pMediaVideoRenderer->ddraw_init( 1 , m_iVideo_Width , m_iVideo_Height ) )
{
PRINTF("OVERLAY RGB ERROR" ) ;
}
if( bDrawRectFlag ) SetDrawRect() ;
if(m_device_Video)
{
m_pVideoFile.SeekToBegin() ;
m_iVideoFrames = 0 ; m_pVideo_Resource_Work = m_pVideo_Resource ;
}
if( thread_ctrl_flag ) StartView() ;
}
void CH265VView::GetConvertYuv()
{
m_dvp_pack_yuv420 = dvp_pack_yuv420( MPV_CSP_YUY2 ) ;
#ifndef __YUV__
if( m_pMediaVideoRenderer->m_bIsOverlayRGBFlag )
switch( m_pMediaVideoRenderer->m_iColorFormat )
{
case CF_RGB15 : m_dvp_pack_yuv420 = dvp_pack_yuv420( MPV_CSP_RGB555 ) ; break ;
case CF_RGB16 : m_dvp_pack_yuv420 = dvp_pack_yuv420( MPV_CSP_RGB565 ) ; break ;
case CF_RGB24 : m_dvp_pack_yuv420 = dvp_pack_yuv420( MPV_CSP_RGB24 ) ; break ;
case CF_RGB32 : m_dvp_pack_yuv420 = dvp_pack_yuv420( MPV_CSP_RGB32 ) ; break ;
}
#endif //__YUV__
}
void CH265VView::GetResource( int iResourceId, void** lpResource , int* lpResourceSize )
{
CH265VApp *lpApp = (CH265VApp*)AfxGetApp() ;
HANDLE hInst = lpApp ? lpApp->m_hInstance : NULL ;
HRSRC hSr = NULL ;
HGLOBAL hG = NULL ;
void* lpBuf = NULL ;
int len = 0 ;
hSr = FindResource( (HINSTANCE)(hInst) , MAKEINTRESOURCE(iResourceId) , "RT_RCDATA" );
if( hSr )
{
hG = LoadResource( (HINSTANCE)(hInst) , hSr );
len = SizeofResource( (HINSTANCE)(hInst) , hSr );
if( hG ) { lpBuf = LockResource( hG ); }
}
*lpResource = lpBuf ;
*lpResourceSize = len ;
/* DeleteObject( hG ); */
}
void CH265VView::GetResource()
{
/* video */ /* Yuv420 */
GetResource( IDR_YUV420P, (void**)&m_pVideo_Resource , (int*)&m_iVideoTotalFramesResource ) ;
m_pVideo_Resource_Work = m_pVideo_Resource ;
m_iVideoTotalFramesResource = m_iVideoTotalFramesResource / ( m_iVideo_Resource_Size ) ;
/* audio */ /* PCM0 */
GetResource( IDR_PCM0, (void**)&m_pAudio_Resource , (int*)&m_iAudioTotalFramesResource ) ;
m_iAudioTotalFramesResource = GetAudioRIFF( m_pAudio_Resource, m_iAudioTotalFramesResource ) ;
m_pAudio_Resource += audio_wave_header_size ; /* wave header size */
m_pAudio_Resource_Work = m_pAudio_Resource ;
//m_iAudioTotalFramesResource = (m_iAudioTotalFramesResource - audio_wave_header_size)/( m_iAudio_Resource_Size ) ;
}
void CH265VView::SetImageSize( CSize* lpVideoSize )
{
acquire_exclusive();
if( (int)lpVideoSize->cx != m_iVideo_Width ||
(int)lpVideoSize->cy != m_iVideo_Height )
{
m_pProcessShareData->width = (int)lpVideoSize->cx ;
m_pProcessShareData->height = (int)lpVideoSize->cy ;
GetVideoRender() ;
}
m_pText.Format( TEXT("picture width=%d; height=%d"), m_pProcessShareData->width, m_pProcessShareData->height ) ;
m_pApp->SetStatusBarText( m_pText ) ;
release_exclusive();
}
void CH265VView::OpenVideoFile()
{
if( m_device_Video ) { m_pVideoFile.Close(); }
m_device_Video = m_pVideoFile.Open( (char*)m_pVideoFileName,
CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary );
if( m_device_Video )
{
m_iVideoTotalFrames = (int)(m_pVideoFile.GetLength()/(m_iVideo_Size)) ;
m_pProcessShareData->m_device = m_device ;
m_pText.Format( TEXT("picture width=%d; height=%d"), m_pProcessShareData->width, m_pProcessShareData->height ) ;
m_pApp->SetStatusBarText( m_pText ) ;
}
m_iVideoFrames = 0 ; dvp_frame_number = 0 ; /* */
}
void CH265VView::OpenAudioFile()
{
if( m_device_Audio ) { m_pAudioFile.Close(); }
m_device_Audio = m_pAudioFile.Open( (char*)m_pAudioFileName,
CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary );
if( m_device_Audio )
{
int iLength = (int)m_pAudioFile.GetLength() ;
BYTE lpRIFF[audio_wave_header_size];
m_pAudioFile.Read(lpRIFF, audio_wave_header_size );
m_iAudioTotalFrames = GetAudioRIFF( lpRIFF, iLength ) ; /* wave header size */
//m_pProcessShareData->m_device = m_device ;
}
m_iAudioFrames = 0 ; dap_frame_number = 0 ; /* */
}
int CH265VView::GetAudioRIFF( BYTE* lpBuffer, int iLength )
{
WAVEFORMATEX * wfx = (WAVEFORMATEX*)( lpBuffer + 20 ) ;
if( (wfx->nChannels == 1) | (wfx->nChannels == 2) ) m_dap_ctx.ch = wfx->nChannels ;
if( wfx->nSamplesPerSec != 0 ) m_dap_ctx.sps = wfx->nSamplesPerSec ;
m_iAudio_Size = m_iAudio_Resource_Size * m_dap_ctx.ch ; /* */
int iAudioTotalFrames = ( iLength -audio_wave_header_size )/(m_iAudio_Size) ;
if( iAudioTotalFrames < 0 ) iAudioTotalFrames = 0 ;
//if( m_pSystemManage.m_pAudioCodecManage_Dlg )
m_pSystemManage.m_pAudioCodecManage_Dlg->SetAudioCodec1( &m_dap_ctx ) ;
return iAudioTotalFrames ;
}
BOOL CH265VView::GetInFileName( CString lpFileNameIn, volatile char* lpFileNameOut, int iFileMinSize )
{
CFileStatus status;
if( ! CFile::GetStatus( lpFileNameIn , status ) ) return FALSE ;
if( status.m_size < iFileMinSize ) return FALSE ;
if( CString ( (const char*)lpFileNameOut ) == CString (status.m_szFullName ) ) return FALSE ;
strcpy( (char*)lpFileNameOut, status.m_szFullName );
return TRUE ;
}
BOOL CH265VView::GetOutFileName( volatile char* lpFileNameIn, CString szFilter, CString szFilter1 )
{
CString lpFilter = CString( szFilter ) + CString( TEXT(" compression files (*.avi)|*.avi||") ) ;
CString lpFileName = ( (m_device_Video | m_device_Audio) & (strlen( (char*)lpFileNameIn ) !=0) ) ?
CString( (char*)lpFileNameIn ) : CString( TEXT("test") ) ;
lpFileName += CString( TEXT("_") ) + szFilter + CString( TEXT(".avi") ) ;
CFileDialog lpFileDlg( FALSE, NULL, (const char*)lpFileName, OFN_OVERWRITEPROMPT, lpFilter );
if( lpFileDlg.DoModal() == IDOK )
{
m_pOutStreamName = lpFileDlg.GetPathName() ;
}
else
{
return FALSE ;
}
FILE*fp = fopen( (const char*)m_pOutStreamName, "wb" ); if(fp) fclose(fp);
return TRUE ;
}
void CH265VView::SetDrawRect()
{
acquire_exclusive();
m_pMediaVideoRenderer->SetDrawRect( this->m_hWnd , 0 );
GetClientRect(&m_pClientRect);
wid_win_scale = get_scale(m_pClientRect.Width(), m_iVideo_Width ) ;
hei_win_scale = get_scale(m_pClientRect.Height(), m_iVideo_Height ) ;
wid_pic_scale1 = get_scale(256*2, m_pClientRect.Width() ) ;
wid_pic_scale = get_scale(m_iVideo_Width, m_pClientRect.Width() ) ;
hei_pic_scale = get_scale(m_iVideo_Height, m_pClientRect.Height() ) ;
InvalidateRect( NULL , FALSE );
release_exclusive();
}
void CH265VView::DrawCurrentText()
{
CWnd* lpWnd = GetParent() ;
if(lpWnd)
{
int x=0,y=0;
if( m_bHistogram )
{
x = get_xy( m_pMousePos.x, wid_pic_scale1) ;
y = get_xy( m_pMousePos.y, hei_pic_scale ) ;
x = x - ( (x>>8)<<8 ) ; //256 = 1<<8
x = m_dvp_Wavelets_Analysis ? x<<(m_dvp_ctx.bands-1) : x ; //x = x - ( (x>>8)<<8 ) ;
}
else
{
x = get_xy( m_pMousePos.x, wid_pic_scale) ;
y = get_xy( m_pMousePos.y, hei_pic_scale) ;
}
m_pImagePos = CPoint(x,y);
m_pText.Format( "%s : f=%d x=%d y=%d ", m_pText0, m_iVideoFrames, x, y ) ;
lpWnd->SetWindowText( m_pText );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -