新聞中心

EEPW首頁 > 消費電子 > 設(shè)計應(yīng)用 > 基于wince的網(wǎng)絡(luò)音視頻通信

基于wince的網(wǎng)絡(luò)音視頻通信

作者: 時間:2011-01-14 來源:網(wǎng)絡(luò) 收藏


{

//-------------------------UDP連接--------------------------//

m_CEUdp.m_OnUdpRecv = OnUdpCERecv;

DWORD nResult = m_CEUdp.Open(p,local_port,remote_ip,remote_port);

if (nResult 《=0)

{

AfxMessageBox(_T(“打開端口失敗”));

return;

}

//---------------------------------------------------//

g_pOut = new CWaveOut();

g_pIn = new CWaveIn();

g_pOut-》StartPlay();

g_pIn-》StartRec(OnRecording,(DWORD)p);

//---------------------------------------------------//

GdiplusStartup( m_gdiPlusToken, m_gdiPlusInPut, NULL ); //初始化GDI+

memset(video_data,0,Video_Width*Video_Height);

index=0;

}

//=====================================================================

// 語法格式: void FreeAV()

// 實現(xiàn)功能: 釋放、

// 參數(shù): 無

// 返回值: 無

//=====================================================================

void FreeAV()

{

//---------------------------------------------------//

g_pOut-》StopPlay();

g_pIn-》StopRec();

delete g_pOut;

delete g_pIn;

//---------------------------------------------------//

GdiplusShutdown(m_gdiPlusToken); //銷毀GDI+

//------------------------UDP--------------------------//

m_CEUdp.Close();

}

//=====================================================================

// 語法格式: void RecAndPlay(WPARAM wParam,LPARAM lParam,HWND hwnd)

// 實現(xiàn)功能: 接收網(wǎng)絡(luò)傳來的音頻,以及播放

// 參數(shù): wParam,表示數(shù)據(jù);lParam,表示數(shù)據(jù)長度;hwnd,表示顯示視頻的窗口句柄

// 返回值: 無

//=====================================================================

static void CALLBACK OnUdpCERecv(CWnd *pWnd,char* buf,int nLen,sockaddr * addr)

{

/*測試收到的數(shù)據(jù)大小

CString tmp;

tmp.Format(L“%d”,nLen);

MessageBox(0,tmp,0,0);

return;*/

//-------------------------如果是音頻數(shù)據(jù)--------------------------//

if(nLen==Compr_AudioData_Size)

{

g726_Decode(buf,(unsigned char*)wave_data);

g_pOut-》Play(wave_data,AudioData_Size);

return;

}

//-------------------------如果是視頻數(shù)據(jù)--------------------------//

if(nLen==VideoData_Size)//完整的視頻數(shù)據(jù)塊

{

for(int i=0;i《nLen;i++)

{

video_data[index]=buf[i];

index++;

}

return;

}

//視頻數(shù)據(jù)塊的最后一塊

for(int i=0;i《nLen;i++)

{

video_data[index]=buf[i];

index++;

}

//如果JPEG圖像特別大,則肯定是出錯,則拋棄

if(index》Video_Width*Video_Height)

{

//MessageBox(0,“緩沖區(qū)出錯”,“錯誤信息”,0);

return;

}

try{

IPicture *pPic;

IStream *pStm ;

//分配全局存儲空間

HGLOBAL hGlobal=GlobalAlloc(GMEM_MOVEABLE,index);

LPVOID pvData=NULL ;

//鎖定分配內(nèi)存塊

pvData=GlobalLock(hGlobal);

//復(fù)制數(shù)據(jù)包video_data到pvData

memcpy(pvData,video_data,index);

GlobalUnlock(hGlobal);

CreateStreamOnHGlobal(hGlobal,TRUE,pStm);

ULARGE_INTEGER pSeek;

LARGE_INTEGER dlibMove ={ 0 } ;

pStm-》Seek(dlibMove,STREAM_SEEK_SET ,pSeek);

// Sleep(15);

//裝入圖形文件

if(FAILED(OleLoadPicture(pStm,index,TRUE,IID_IPicture,(LPVOID*)pPic)))

{//附:如果video_data這個數(shù)組包含的圖像有錯,則OleLoadPicture 容易產(chǎn)生讀寫內(nèi)存錯誤

// pPic-》Release();

// pStm-》Release();

return ;

}

Image img(pStm,0);

Graphics mGraphics(GetDC(pWnd-》m_hWnd));

mGraphics.DrawImage(img, 0, 0, Video_Width, Video_Height);

img.~Image();//會出錯

mGraphics.~Graphics();

pPic-》Release();

pStm-》Release();

}

catch(CException * e)

{}

memset(video_data,0,Video_Width*Video_Height);

index=0;

}

//=====================================================================

// 語法格式: static void OnRecording(char *data,int length,DWORD userdata)

// 實現(xiàn)功能: 釋放音頻

// 參數(shù): data表示數(shù)據(jù),length表示數(shù)據(jù)長度,userdata暫時沒用

// 返回值: 無

//=====================================================================

static void OnRecording(char *data,int length,DWORD userdata)

{

memcpy(pin,g_pIn-》buffer,AudioData_Size);

g726_Encode((unsigned char*)pin,pout);

m_CEUdp.SendData(pout,Compr_AudioData_Size);

}

};

本文引用地址:http://butianyuan.cn/article/166249.htm

上一頁 1 2 3 下一頁

關(guān)鍵詞: 音頻 視頻

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉