"libvlc_vlm_add_vod" blocks the thread

This forum is about all development around libVLC.
captainst
Blank Cone
Blank Cone
Posts: 24
Joined: 01 Sep 2011 16:43

"libvlc_vlm_add_vod" blocks the thread

Postby captainst » 01 Sep 2011 17:05

Hello Everyone,

I want to embed the libvlc into my VC++6.0 program to make it a simple RTSP server. The stream is "pushed" from another computer using RTP (also by VLC player), then the program publish the stream using RTSP.

The code is:

Code: Select all

void test () { const char * const vlc_args[] = { "--plugin-path=D:\\VideoLAN\\VLC", "--sout-udp-caching=100", "--udp-caching=100", "--rtsp-caching=100", "--sout-rtp-caching=100"}; const char * const vlm_args[] = { "--no-sout-rtp-sap", "--no-sout-standard-sap", "--ttl=1", "--sout-keep", "--rtsp-session-timeout=20"}; libvlc_instance_t* m_pLibvlcInst=NULL; m_pLibvlcInst = libvlc_new(sizeof(vlc_args)/ sizeof(vlc_args[0]),vlc_args); // init n = libvlc_vlm_add_vod(m_pLibvlcInst, "PUB0", "rtp://@:5004/", sizeof(vlm_args)/ sizeof(vlm_args[0]), vlm_args, true, NULL); // VOD source is rtp @ 5004, publishing point "PUB0" }
I am not sure if I've done the above correctly. But if the other computer is not "pushing" the stream through rtp to port 5004, The program freezes at libvlc_vlm_add_vod() function call. When the other computer starts pushing, program is un-blocked. And I have verified then the stream may be played at "rtsp://192.168.55.102/PUB0".

From this link: http://wiki.videolan.org/Documentation: ... _Internals, last paragraph <Thread Creation>, VLM should create a new thread after "libvlc_vlm_add_vod" being called. So I don't know why it is blocked?

Can someone help me? Many thanks in advance

captainst
Blank Cone
Blank Cone
Posts: 24
Joined: 01 Sep 2011 16:43

Re: "libvlc_vlm_add_vod" blocks the thread

Postby captainst » 02 Sep 2011 05:18

I see another issue around VOD:

After calling to the function "libvlc_vlm_add_vod" with b_enabled==true in thread A, the call to the functions including "libvlc_vlm_del_media", "libvlc_vlm_release", "libvlc_release" from other thread will block and freeze unconditionally, and for-ever.

Has anybody used these functions before ? I suppose that I have made some error ...

Sébastien Escudier
Big Cone-huna
Big Cone-huna
Posts: 853
Joined: 06 Nov 2008 08:38
Operating System: linux

Re: "libvlc_vlm_add_vod" blocks the thread

Postby Sébastien Escudier » 02 Sep 2011 08:21

The freeze issue when you create the VOD is "normal".
That's because vlc tries to parse the stream, and it waits until your RTP input stream is available.

You should not create VOD with a live input, that's useless.
Instead, you can create a broadcast with sout = #rtp{sdp=rtsp://192.168.55.102/PUB0}

captainst
Blank Cone
Blank Cone
Posts: 24
Joined: 01 Sep 2011 16:43

Re: "libvlc_vlm_add_vod" blocks the thread

Postby captainst » 02 Sep 2011 09:50

Thank you Sébastien. I tried to stream with broadcast, indeed this problem does not show up.

However this brings another problem: My program has to be aware if there is client currently connected to the RTSP service. When using VOD to stream, my program receives the "events" like "libvlc_VlmMediaInstanceStatusPlaying", or "libvlc_VlmMediaInstanceStatusEnd", when a client connects or disconnects.
However using the broadcast service the program does not receive these events.

Is there a work around on this ? Thanks again!

Sébastien Escudier
Big Cone-huna
Big Cone-huna
Posts: 853
Joined: 06 Nov 2008 08:38
Operating System: linux

Re: "libvlc_vlm_add_vod" blocks the thread

Postby Sébastien Escudier » 02 Sep 2011 09:54

hmmm, I don"t think so.
But the advantage of this solution, is that the input RTP stream is read only once.
With VOD it would be opened once per client.

captainst
Blank Cone
Blank Cone
Posts: 24
Joined: 01 Sep 2011 16:43

Re: "libvlc_vlm_add_vod" blocks the thread

Postby captainst » 02 Sep 2011 10:12

Thanks again for the quick support!

It is important for us to know if there is any client connecting to the RTSP service. Since if no client is viewing the publishing point, the server program has to tell the live stream source (web camera) to stop the RTP stream pushing, which is using 3G network. (so money issue...)

Since the "broadcast" method does not return this information, I'd have to stick to the VOD solution.

I came up with a brutal way to solve the problem: I pass the parameter "b_enabled"==false to the function libvlc_vlm_add_vod, and call the "libvlc_vlm_set_enabled" function in a seperate thread, like this:

Code: Select all

libvlc_vlm_add_vod(m_pLibvlcInst, "PUB0", "rtp://@:5004/", sizeof(vlm_args)/ sizeof(vlm_args[0]), vlm_args, false, NULL); // add VOD but not enabled threadHandle = CreateThread(0,0,WaitForVODStart,"PUB0",0,NULL); // create a new thread "WaitForVODStart"
the thread function does nothing else but enable the VOD (freeze), and delete media. (the delete media function has to reside in the same thread where libvlc_vlm_set_enabled is called)

Code: Select all

DWORD WINAPI WaitForVODStart (LPVOID lpParam) { libvlc_vlm_set_enabled (m_pLibvlcInst, (const char*)lpParam, true); // enable the VOD, block until a valid source come in while (1) { if (m_bThreadLive) // m_bThreadLive set outside the thread function like semaforo Sleep(100); else { libvlc_vlm_del_media(m_pLibvlcInst, (const char*)lpParam); break; } } return 0; }
Mamamia what a brutal solution! :lol:


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 12 guests