diff options
author | Linus Walleij <triad@df.lth.se> | 2006-08-26 22:08:37 +0000 |
---|---|---|
committer | Linus Walleij <triad@df.lth.se> | 2006-08-26 22:08:37 +0000 |
commit | d214b9bae4e9b0c106a21ff3a3c24029982f9d50 (patch) | |
tree | 9c4eba5c7aa0decbb1aa21fb1c2d65573319cf85 | |
parent | e7f44bee7b415ad8930273fb7242c988f6039457 (diff) | |
download | libmtp-d214b9bae4e9b0c106a21ff3a3c24029982f9d50.tar.gz |
Fixes galorelibmtp-0-0-14
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/libmtp.c | 39 | ||||
-rw-r--r-- | src/libmtp.h.in | 2 | ||||
-rw-r--r-- | src/libusb-glue.c | 23 | ||||
-rw-r--r-- | src/libusb-glue.h | 6 |
6 files changed, 72 insertions, 7 deletions
@@ -1,3 +1,10 @@ +2006-08-26 Linus Walleij <triad@df.lth.se> + + * configure.ac: version bump. + * src/libmtp.c: fix bug and reinstate callbacks. + * src/libusb-glue.h: dito. + * src/libusb-glue.c: dito. + 2006-08-25 Linus Walleij <triad@df.lth.se> * src/libmtp.c: use the new file descriptor sender function. diff --git a/configure.ac b/configure.ac index 94b7fdd..008a778 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.52) -AC_INIT([libmtp], [0.0.13], [libmtp-users@lists.sourceforge.net]) +AC_INIT([libmtp], [0.0.14], [libmtp-users@lists.sourceforge.net]) AM_INIT_AUTOMAKE([foreign]) AC_CONFIG_SRCDIR([src/libmtp.c]) AC_CONFIG_HEADER([config.h]) diff --git a/src/libmtp.c b/src/libmtp.c index b8dd8f2..c52fef1 100644 --- a/src/libmtp.c +++ b/src/libmtp.c @@ -760,6 +760,13 @@ LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void) // Allocate a parameter block params = (PTPParams *) malloc(sizeof(PTPParams)); ptp_usb = (PTP_USB *) malloc(sizeof(PTP_USB)); + // Callbacks and stuff + ptp_usb->callback_active = 0; + ptp_usb->current_transfer_total = 0; + ptp_usb->current_transfer_complete = 0; + ptp_usb->current_transfer_callback = NULL; + + // get storage ID ret = connect_first_device(params, ptp_usb, &interface_number); switch (ret) @@ -819,7 +826,7 @@ LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void) // Initialize iconv() converters... unicode_init(tmpdevice); - + /* * Then get the handles and try to locate the default folders. * This has the desired side effect of cacheing all handles from @@ -2154,6 +2161,7 @@ int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *device, PTPObjectInfo new_track; PTPParams *params = (PTPParams *) device->params; uint32_t localph = parenthandle; + PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; if (localph == 0) { localph = device->default_music_folder; @@ -2181,12 +2189,25 @@ int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *device, return -1; } + ptp_usb->callback_active = 1; + ptp_usb->current_transfer_total = metadata->filesize+12; // 12 = USB header size + ptp_usb->current_transfer_complete = 0; + ptp_usb->current_transfer_callback = callback; + ptp_usb->current_transfer_callback_data = data; + ret = ptp_sendobject_fromfd(params, fd, metadata->filesize); if (ret != PTP_RC_OK) { + ptp_usb->callback_active = 0; + ptp_usb->current_transfer_callback = NULL; + ptp_usb->current_transfer_callback_data = NULL; ptp_perror(params, ret); printf("LIBMTP_Send_Track_From_File_Descriptor: Could not send object\n"); return -1; } + + ptp_usb->callback_active = 0; + ptp_usb->current_transfer_callback = NULL; + ptp_usb->current_transfer_callback_data = NULL; // Set track metadata for the new fine track subcall_ret = LIBMTP_Update_Track_Metadata(device, metadata); @@ -2286,6 +2307,7 @@ int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *device, uint32_t localph = parenthandle; PTPObjectInfo new_file; PTPParams *params = (PTPParams *) device->params; + PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; new_file.Filename = filedata->filename; new_file.ObjectCompressedSize = filedata->filesize; @@ -2339,14 +2361,27 @@ int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *device, printf("LIBMTP_Send_File_From_File_Descriptor: Could not send object info\n"); return -1; } - + + ptp_usb->callback_active = 1; + ptp_usb->current_transfer_total = filedata->filesize+12; // 12 = USB header size + ptp_usb->current_transfer_complete = 0; + ptp_usb->current_transfer_callback = callback; + ptp_usb->current_transfer_callback_data = data; + ret = ptp_sendobject_fromfd(params, fd, filedata->filesize); if (ret != PTP_RC_OK) { + ptp_usb->callback_active = 0; + ptp_usb->current_transfer_callback = NULL; + ptp_usb->current_transfer_callback_data = NULL; ptp_perror(params, ret); printf("LIBMTP_Send_File_From_File_Descriptor: Could not send object\n"); return -1; } + ptp_usb->callback_active = 0; + ptp_usb->current_transfer_callback = NULL; + ptp_usb->current_transfer_callback_data = NULL; + // Added object so flush handles. flush_handles(device); return 0; diff --git a/src/libmtp.h.in b/src/libmtp.h.in index 582ff6b..b60d467 100644 --- a/src/libmtp.h.in +++ b/src/libmtp.h.in @@ -94,7 +94,7 @@ typedef struct LIBMTP_object_struct LIBMTP_object_t; /**< @see LIBMTP_object_t * * @return if anything else than 0 is returned, the current transfer will be * interrupted / cancelled. */ -typedef int LIBMTP_progressfunc_t (uint64_t const sent, uint64_t const total, +typedef int (* LIBMTP_progressfunc_t) (uint64_t const sent, uint64_t const total, void const * const data); /** diff --git a/src/libusb-glue.c b/src/libusb-glue.c index 6c3c475..7e9116a 100644 --- a/src/libusb-glue.c +++ b/src/libusb-glue.c @@ -372,7 +372,7 @@ ptp_write_func (unsigned char *bytes, unsigned int size, void *data) /* * gp_port_write returns (in case of success) the number of bytes - * write. Too large blocks (>5x MB) could timeout. + * written. Too large blocks (>5x MB) could timeout. */ while (curwrite < size) { towrite = size-curwrite; @@ -385,9 +385,26 @@ ptp_write_func (unsigned char *bytes, unsigned int size, void *data) if (result < towrite) /* short writes happen */ break; } - if ((size % dev->descriptor.bMaxPacketSize0) == 0) { - result=USB_BULK_WRITE(ptp_usb->handle,ptp_usb->outep,(char *)"x",0,ptpcam_usb_timeout); + + // Increase counters, call callback + if (ptp_usb->callback_active) { + ptp_usb->current_transfer_complete += result; + if (ptp_usb->current_transfer_callback != NULL) { + (void) ptp_usb->current_transfer_callback(ptp_usb->current_transfer_complete, + ptp_usb->current_transfer_total, + ptp_usb->current_transfer_callback_data); + } + } + + // If this is the last transfer (callbacks only active if this function called repeatedly with + // new data, otherwise this is a single large transaction which ends here). + if (!ptp_usb->callback_active || ptp_usb->current_transfer_total == ptp_usb->current_transfer_complete) { + // Then terminate an even packet boundary write with a zero length packet + if ((size % dev->descriptor.bMaxPacketSize0) == 0) { + result=USB_BULK_WRITE(ptp_usb->handle,ptp_usb->outep,(char *)"x",0,ptpcam_usb_timeout); + } } + if (result < 0) return PTP_ERROR_IO; return PTP_RC_OK; diff --git a/src/libusb-glue.h b/src/libusb-glue.h index 729446b..1d62dff 100644 --- a/src/libusb-glue.h +++ b/src/libusb-glue.h @@ -25,6 +25,12 @@ struct _PTP_USB { int outep; int outep_maxpacket; int intep; + /** File transfer callbacks and counters */ + int callback_active; + uint64_t current_transfer_total; + uint64_t current_transfer_complete; + LIBMTP_progressfunc_t current_transfer_callback; + void *current_transfer_callback_data; }; int get_device_list(LIBMTP_device_entry_t ** const devices, int * const numdevs); |