Skip to content

services discovery: mtp: rework implementation

Romain Vimont requested to merge rom1v/vlc:mtp into master

The MTP service discovery exposed all the media detected on a device flatten at the first level. As a consequence, the media items of this MTP device were displayed at the same level as other devices in the UI, which messed up the whole view.

Also, the implementation only supported one MTP device at a time.

This MR reworks the implementation to:

  • add a device node (with the name of the device) at the first level, parent of all media detected on this device
  • add support for multiple devices, with one device node per device

In addition, there were other problems, fixed by this MR:

  • the device name was not correctly detected
  • there were memory leaks on error and on close

Note: there are a lot of code moves, so the diff contains legacy code. I suggest to read the commits individually.

For the device node, I'm not sure what type to use and what MRL (which must not be NULL):

input_item_NewExt( "vlc://nop", name, INPUT_DURATION_INDEFINITE, ITEM_TYPE_NODE, ITEM_LOCAL );

Before: mtp_ko

After: mtp_ok


Unfortunately, mtp/libmtp is very fragile in itself.

Only my Nexus 5 works correctly in practice.

For my other devices, LIBMTP_Open_Raw_Device() never returns, and blocks the whole mtp thread :/

Also, some devices are just ignored because the VID:PID is not known by libmtp:

Device 0 (VID=2a70 and PID=9012) is UNKNOWN in libmtp v1.1.19.
Please report this VID/PID and the device model to the libmtp development team
Edited by Romain Vimont

Merge request reports