標籤:style blog http color 使用 資料
先貼代碼,
#define WIFI_W 640
#define WIFI_H 480
struct ctx{ uchar* frame;};class CConnectWIFI{public: CConnectWIFI(void); void Init(HWND hWnd); libvlc_instance_t* m_vlcInst; libvlc_media_player_t* m_vlcMplay; libvlc_media_t* m_vlcMedia; struct ctx context; ~CConnectWIFI(void);};CConnectWIFI::CConnectWIFI(void){ m_vlcInst = NULL; m_vlcMplay = NULL; m_vlcMedia = NULL; context.frame = new uchar[WIFI_W * WIFI_H * 3]; memset(context.frame, 0, WIFI_W*WIFI_H*3); m_vlcInst = libvlc_new(0, NULL); }CConnectWIFI::~CConnectWIFI(void){ if(m_vlcMplay) { libvlc_media_player_release(m_vlcMplay); m_vlcMplay = NULL; } if(m_vlcInst) { libvlc_release(m_vlcInst); m_vlcInst = NULL; } if (context.frame) { delete []context.frame; context.frame = NULL; }}void* lock(void* data, void** p_pixels){ struct ctx* ctx = (struct ctx*)data; *p_pixels = ctx->frame; return NULL;}void unlock(void* data, void* id, void* const* p_pixels){ uchar* pixels = (uchar*)*p_pixels; ImageProcessCallBack(pixels, WIFI_W, WIFI_H);}void display(void *data, void *id){ //(void) data; //ASSERT(id == NULL);}void CConnectWIFI::Init(HWND hWnd){ m_vlcMedia = libvlc_media_new_location(m_vlcInst, "http://10.10.1.1:8196"); libvlc_media_add_option(m_vlcMedia, ":network-caching=10"); m_vlcMplay = libvlc_media_player_new_from_media(m_vlcMedia); libvlc_media_player_set_hwnd(m_vlcMplay, hWnd); libvlc_media_release(m_vlcMedia); libvlc_video_set_callbacks(m_vlcMplay, lock, unlock, display, &context); libvlc_video_set_format(m_vlcMplay, "RV24", WIFI_W, WIFI_H, WIFI_W * 3); int res = libvlc_media_player_play(m_vlcMplay);}
以上代碼是訪問wifi映像裝置的一段代碼,也是第一次接觸vlc,很多地方不是很清楚。
其中libvlc_media_add_option(m_vlcMedia, ":network-caching=10");是為瞭解決緩衝時間過長導致延遲的問題,如果太大了則延遲嚴重,太小了則很卡,根據情況設定。另外還有個問題不理解,串連正常之後,突然中斷網路,竟然還能調用回呼函數ImageProcessCallBack,且一隻調用,只不過都是同一幀資料。難道是所謂的“拉”(pull)模式?這個問題怎麼解決,有做過的麻煩請在下方留言,感謝!