gphoto / libgphoto2

The libgphoto2 camera access and control library.
GNU Lesser General Public License v2.1
1.02k stars 324 forks source link

Can't import from Sony Xperia X (MTP) anymore: timeout on USB bus after successful transfer #435

Open wvh opened 5 years ago

wvh commented 5 years ago

Hello,

I've been using Digikam/libgphoto2 to import the pictures on my Sony Xperia X phone running Sailfish OS (Jolla) on to an up-to-date Arch Linux system running KDE and gphoto version 2.5.23.

The last month or so I've been getting IO errors. I checked the debugging output, and it seems the individual pictures are transferred completely, but gphoto2 keeps waiting in the read loop and then times out after 20 seconds. I've compared the debugging hex output with some of the pictures I've transferred before and it seems the full picture has been transferred, but for some reason gphoto2 hangs waiting for more data. I don't know if the miscommunication is on Sailfish's or gphoto2's side.

This is how it looks when I get one picture file from the device with debugging output enabled:

[... lots of hex picture data output ...]
2d80  80 07 8f ca 96 25 8e 47-53 23 ba 21 c1 53 b8 61  .....%.GS#.!.S.a
2d90  bd 3f 0f 7a 39 5e c6 8f-7b 33 ff d9              .?.z9^..{3..

4.019130 gp_port_read                (3): Reading 524288 = 0x80000 bytes from port...
4.019223 gp_port_read                (3): Read    16 = 0x10 out of 524288 bytes from port: (hexdump of 16 bytes)
0000  10 00 00 00 03 00 01 20-ce 07 00 00 40 c6 68 00  ....... ....@.h.

4.019248 gp_port_read                (3): Reading 524288 = 0x80000 bytes from port...
24.019532 gp_libusb1_read [libusb1.c:609](0): 'libusb_bulk_transfer (port->pl->dh, port->settings.usb.inep, (unsigned char*)bytes, size, &curread, port->timeout)' failed:
 Operation timed out (-7)
24.019656 gp_port_read [gphoto2-port.c:441](0): Reading 524288 = 0x80000 bytes from port failed: Timeout reading from or writing to the port (-10)
24.019691 ptp_usb_getdata [usb.c:479] (0): PTP_OC 0x101b receiving data failed: PTP Timeout (0x02fa)
24.019717 get_file_func [library.c:7676](0): 'ptp_getpartialobject (params, oid, offset, xsize, &ximage, &xlen)' failed: 'PTP I/O Error' (0x02ff)
24.019742 gp_context_error            (0): PTP I/O Error

*** Error ***
PTP I/O Error
24.019831 gp_filesystem_get_file      (2): Download of '20190723_152022.jpg' from '/store_00010002/Pictures/Camera' (type 1) failed. Reason: 'I/O problem'
24.019883 gp_camera_file_get [gphoto2-camera.c:1693](0): 'gp_filesystem_get_file (camera->fs, folder, file, type, camera_file, context)' failed: -7
*** Error (-7: 'I/O problem') ***

[... close session output ...]

I don't seem to have a problem transferring music files in KDE (MTP via kio?) and I've tried different USB cables and ports so I don't think this is a hardware problem.

wvh commented 5 years ago

Following the flow in camlibs/ptp2/library.c, function get_file_func() gets the image size from the PTPObject:

        size=ob->oi.ObjectCompressedSize;

The reported size in the debugging output for that file name matches the actual size of the JPG picture, so I'm not sure why the reading loop would hang expecting more output. It would probably help to log how much data was read or was remaining if the transaction times out, to see if there's a discrepancy between what gphoto is expecting and what the device actual sends.