mediadirs plugin

This forum is about all development around libVLC.
sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

mediadirs plugin

Postby sherington » 16 Jul 2012 20:10

Hello,

I am looking at whether or not it's worth trying to include the native service discovery functions into my bindings. I have read comments in mailing lists stating that the libvlc services discovery might be quite buggy - but if there are some simple things that can be fixed I would like to try and fix them and submit patches if it looks like it will be worthwhile.

Anyway, immediately I am seeing problems in the "mediadirs" module, but I do not know much at all about the vlc module system so I was hoping for a pointer.

In "mediadirs.c" I have put some debug trace in to try and understand why only the video directory is considered, this is the vlc module description:

Code: Select all

vlc_module_begin () set_category( CAT_PLAYLIST ) set_subcategory( SUBCAT_PLAYLIST_SD ) set_shortname( N_("Video") ) set_description( N_("My Videos") ) set_capability( "services_discovery", 0 ) set_callbacks( OpenVideo, Close ) add_shortcut( "video_dir" ) add_submodule () set_shortname( N_("Audio") ) set_description( N_("My Music") ) set_capability( "services_discovery", 0 ) set_callbacks( OpenAudio, Close ) add_shortcut( "audio_dir" ) add_submodule () set_shortname( N_("Picture") ) set_description( N_("My Pictures") ) set_capability( "services_discovery", 0 ) set_callbacks( OpenPicture, Close ) add_shortcut( "picture_dir" ) VLC_SD_PROBE_SUBMODULE vlc_module_end ()
This code fragment is from the module Open() function, the else clauses for Audio and Picture are never executed:

Code: Select all

if( p_sys->i_type == Video ) { p_sys->psz_dir[0] = config_GetUserDir( VLC_VIDEOS_DIR ); p_sys->psz_dir[1] = var_CreateGetString( p_sd, "input-record-path" ); p_sys->psz_var = "record-file"; } else if( p_sys->i_type == Audio ) { p_sys->psz_dir[0] = config_GetUserDir( VLC_MUSIC_DIR ); p_sys->psz_dir[1] = var_CreateGetString( p_sd, "input-record-path" ); p_sys->psz_var = "record-file"; } else if( p_sys->i_type == Picture ) { p_sys->psz_dir[0] = config_GetUserDir( VLC_PICTURES_DIR ); p_sys->psz_dir[1] = var_CreateGetString( p_sd, "snapshot-path" ); p_sys->psz_var = "snapshot-file"; }
From my trace output I can see that this module is only opened once and I see no evidence of the sub-modules being activated. I only ever see video files in the returned list, I never see any audio files or picture files.

If I swap the ordering of the video and audio so audio is first (i.e. audio is the "main" module), then indeed it does find all of my audio files, but now no video files are found.

So if anyone has any hints that would be appreciated...

I did notice other strange things like different results depending on the order in which I instantiate media discoverers, but that's a problem for another time if I can get anywhere with this.

Rémi Denis-Courmont
Developer
Developer
Posts: 15135
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: mediadirs plugin

Postby Rémi Denis-Courmont » 16 Jul 2012 20:58

Working fine in the VLC UI for me.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: mediadirs plugin

Postby sherington » 17 Jul 2012 17:18

I'm trying to understand how this works through libvlc and the media discoverer API, and why this works in the VLC UI but seemingly not through libvlc.

I guess essentially my question is: should I expect, for this module, that the module Open() method should be called once for video (main module), once for audio (submodule) and once for pictures (submodule)? I'm just trying to get a handle on this to start investigating more deeply.

Rémi Denis-Courmont
Developer
Developer
Posts: 15135
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: mediadirs plugin

Postby Rémi Denis-Courmont » 17 Jul 2012 22:45

Uh? It depends on what you're doing?
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: mediadirs plugin

Postby sherington » 18 Jul 2012 08:13

I do this, example shown here is pseudo-code since I am writing Java bindings:

Code: Select all

p_discoverer = libvlc_media_discoverer_new_from_name( p_inst, "mediadirs" ); p_media_list = libvlc_media_discoverer_media_list( p_discoverer );
Then I iterate the media list dumping out the MRL's. In that list I see the contents of my "~/Videos" directory. But I do not see the contents of my "~/Music" directory nor "~/Pictures" directory, despite the mediadirs module having code in it's Open() method that appears to handle audio and pictures too.

I do similar things for discoverers named "audio", "video", "sap" and so on-on, and those appear to work correctly. For audio I get a list of sound-cards attached to my system, with sub-lists of ports or whatever. For "video" I get a list (well I only have one device actually) of attached webcams and such.

So I have it kind of working, but not 100%.

I have not found a single example on how to properly use libvlc_media_discoverer.

erwan10
Developer
Developer
Posts: 415
Joined: 02 Nov 2008 23:16

Re: mediadirs plugin

Postby erwan10 » 25 Jul 2012 16:26

Rather than using the "mediadirs" name, directly use the submodule shortcut you're interested in, namely "video_dir", "audio_dir" or "picture_dir". Using "mediadirs" here works because it defaults on the first submodule available which happens to be "video_dir".

Also, the job of providing items is done by a background thread. So don't expect media_list to be filled with items right away, after returning from libvlc_media_discoverer_new_from_name. In order to make sure this background thread gets elected and do the job, you can for instance add "sleep(1)" just after your libvlc_media_discoverer_new_from_name call.

Rémi Denis-Courmont
Developer
Developer
Posts: 15135
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: mediadirs plugin

Postby Rémi Denis-Courmont » 25 Jul 2012 16:29

sleep(1) provides no warranties. Unless you are running on a real-time operating system with a single processor. And you are not doing that.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: mediadirs plugin

Postby sherington » 25 Jul 2012 16:56

Rather than using the "mediadirs" name, directly use the submodule shortcut you're interested in, namely "video_dir", "audio_dir" or "picture_dir".

That's the key piece of the puzzle I was missing, thanks.
Also, the job of providing items is done by a background thread. So don't expect media_list to be filled with items right away, after returning from libvlc_media_discoverer_new_from_name. In order to make sure this background thread gets elected and do the job, you can for instance add "sleep(1)" just after your libvlc_media_discoverer_new_from_name call.
Do you know if media list events are fired when items are added or deleted? So in theory I could get the original list and do my event_attach calls? And might I miss items being added if I'm unlucky inbetween getting the original list and attaching to the event manager?

erwan10
Developer
Developer
Posts: 415
Joined: 02 Nov 2008 23:16

Re: mediadirs plugin

Postby erwan10 » 25 Jul 2012 18:02

Do you know if media list events are fired when items are added or deleted? So in theory I could get the original list and do my event_attach calls?
I would say yes, media list events are fired (though I have not tested it).
And of course, you have to explicitly attach to them.
And might I miss items being added if I'm unlucky inbetween getting the original list and attaching to the event manager?
In theory, yes, you could be unlucky.
There are no means to know for sure when and how threads are scheduled. I would say libvlc has got a design limitation here, because the libvlc developper should be given a chance to attach to the media list events and only afterwards, start the services discovery module.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: mediadirs plugin

Postby sherington » 25 Jul 2012 21:40

Another problem is to know when exactly this background thread has finished. I added a whole bunch of debug logs to libvlc and the mediadir discovery module, and I don't see anywhere where you get a notification that the discovery is done. So it seems like polling for the list on demand is the best that can be done, unless someone has another idea.

erwan10
Developer
Developer
Posts: 415
Joined: 02 Nov 2008 23:16

Postby erwan10 » 26 Jul 2012 01:16

This discovery is never really done, because user can create new contents at any time (recording a video or audio file, or taking snapshots). the mediadirs discovery modules will add these new items automatically to their respective media lists on the spot.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: mediadirs plugin

Postby sherington » 26 Jul 2012 07:47

OK, if I take this any further I think I need to see if the media list item added/removed events work, and then try and mitigate the potential missed events due to the discoverer starting before the event handler is attached.

Thanks for the hints.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 4 guests