windows使用libvlc進行網路串流遇到的一些問題及解決方案

來源:互聯網
上載者:User

標籤: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)模式?這個問題怎麼解決,有做過的麻煩請在下方留言,感謝!
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.