diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | TODO | 23 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | examples/getfile.c | 4 | ||||
-rw-r--r-- | examples/getplaylist.c | 2 | ||||
-rw-r--r-- | examples/refactortest.c | 2 | ||||
-rw-r--r-- | src/libmtp.c | 58 | ||||
-rw-r--r-- | src/libmtp.h.in | 16 | ||||
-rw-r--r-- | src/libusb-glue.c | 11 | ||||
-rw-r--r-- | src/libusb-glue.h | 2 |
11 files changed, 79 insertions, 58 deletions
@@ -1,3 +1,17 @@ +2006-08-27 Linus Walleij <triad@df.lth.se> + + * configure.ac: version bump. Release all these fixes + as 0.0.15. + * src/libusb-glue.c: fixed sucky errors. Added callback + code when reading files. + * src/libusb-glue.h: const correctness. + * src/libmtp.h.in: finally fixup the type on the callbacks. + * src/libmtp.c: more accurate sending callbacks. Callbacks + when getting files also, working correctly. Typeing of + callbacks now OK. + * examples/getfile.c: some display bar cosmetic fixup. + * TODO: lots of the things todo are now done. + 2006-08-26 Linus Walleij <triad@df.lth.se> * configure.ac: version bump. @@ -74,7 +74,8 @@ Contributing ------------ See the project page at http://libmtp.sourceforge.net/ -We always need your help. +We always need your help. There is a mailinglist and a +bug report system there. If you happen upon a device which libmtp claims it cannot autodetect, please submit the vendor ID and device ID @@ -3,28 +3,11 @@ TODO file: * Support abstract MTP album (0xBA03) just like playlists. Too bad that Creative devices do not support them, they group the - albums by using the metadata instead. + albums by using the metadata instead. Support representative + sample (i.e. album cover). * Support playback and volume setting on devices that have it. - (I don't have one - Linus.) - -* Add logic to transfer very large files in chunks, like 1 MB at the - time, or we cannot upload movies... Righ now libmtp just copy the - file to memory and transfer it. - -* Previous fix can help to get the callbacks working again, cause - right now they aren't called. - -* Make the usb r/w stuff in libusb-glue.c take the device as parameter, - then put the callback function in the device and make it call. - (IMPOSSIBLE: the device is created after a lot of writing has already - taken place, shall we use a dummy device holder then?) - -* Fix compiler warnings. + (I don't have one that does - Linus.) * Make an API that can return several devices not just connect to the first one... - -* Add a function that will list the playable file types for a certain - device. (Needs some research and probably a database.) Can the device - be probed to determine supported file types? diff --git a/configure.ac b/configure.ac index 008a778..8606146 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.14], [libmtp-users@lists.sourceforge.net]) +AC_INIT([libmtp], [0.0.15], [libmtp-users@lists.sourceforge.net]) AM_INIT_AUTOMAKE([foreign]) AC_CONFIG_SRCDIR([src/libmtp.c]) AC_CONFIG_HEADER([config.h]) diff --git a/examples/getfile.c b/examples/getfile.c index 303927c..e964795 100644 --- a/examples/getfile.c +++ b/examples/getfile.c @@ -53,8 +53,10 @@ int main (int argc, char **argv) // This function will also work just as well for tracks. if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) { - printf("Error getting file from MTP device.\n"); + printf("\nError getting file from MTP device.\n"); } + // Terminate progress bar. + printf("\n"); LIBMTP_Release_Device(device); printf("OK.\n"); diff --git a/examples/getplaylist.c b/examples/getplaylist.c index 597a903..6362c77 100644 --- a/examples/getplaylist.c +++ b/examples/getplaylist.c @@ -1,6 +1,6 @@ #include "common.h" -uint32_t dump_playlist(LIBMTP_mtpdevice_t *device, uint32_t playlist_id) +static uint32_t dump_playlist(LIBMTP_mtpdevice_t *device, uint32_t playlist_id) { uint32_t *items; uint32_t len, ret; diff --git a/examples/refactortest.c b/examples/refactortest.c index 6e7831a..601b7b7 100644 --- a/examples/refactortest.c +++ b/examples/refactortest.c @@ -54,7 +54,7 @@ #define PTP_OPC_OriginalReleaseDate 0xDC99 #define PTP_OPC_AlbumName 0xDC9A -void test_mp3_datafunc(LIBMTP_mtpdevice_t *device, uint32_t object_id, void *data) +static void test_mp3_datafunc(LIBMTP_mtpdevice_t *device, uint32_t object_id, void *data) { LIBMTP_track_t *track; diff --git a/src/libmtp.c b/src/libmtp.c index a6ddda0..3c3b852 100644 --- a/src/libmtp.c +++ b/src/libmtp.c @@ -1952,7 +1952,7 @@ LIBMTP_track_t *LIBMTP_Get_Trackmetadata(LIBMTP_mtpdevice_t *device, uint32_t co * @see LIBMTP_Get_File_To_File_Descriptor() */ int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id, - char const * const path, LIBMTP_progressfunc_t const * const callback, + char const * const path, LIBMTP_progressfunc_t const callback, void const * const data) { int fd = -1; @@ -2000,12 +2000,13 @@ int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id, int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t *device, uint32_t const id, int const fd, - LIBMTP_progressfunc_t const * const callback, + LIBMTP_progressfunc_t const callback, void const * const data) { PTPObjectInfo oi; uint16_t ret; PTPParams *params = (PTPParams *) device->params; + PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; if (ptp_getobjectinfo(params, id, &oi) != PTP_RC_OK) { printf("LIBMTP_Get_File_To_File_Descriptor(): Could not get object info\n"); @@ -2016,8 +2017,19 @@ int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t *device, return -1; } + // Callbacks + ptp_usb->callback_active = 1; + ptp_usb->current_transfer_total = oi.ObjectCompressedSize+40; // 40??? + ptp_usb->current_transfer_complete = 0; + ptp_usb->current_transfer_callback = callback; + ptp_usb->current_transfer_callback_data = data; + // This now exist in upstream ret = ptp_getobject_tofd(params, id, fd); + + ptp_usb->callback_active = 0; + ptp_usb->current_transfer_callback = NULL; + ptp_usb->current_transfer_callback_data = NULL; if (ret != PTP_RC_OK) { printf("LIBMTP_Get_File_To_File_Descriptor(): Could not get file from device (%d)\n", ret); @@ -2044,7 +2056,7 @@ int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t *device, * @see LIBMTP_Get_Track_To_File_Descriptor() */ int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id, - char const * const path, LIBMTP_progressfunc_t const * const callback, + char const * const path, LIBMTP_progressfunc_t const callback, void const * const data) { // This is just a wrapper @@ -2070,7 +2082,7 @@ int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id, int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t *device, uint32_t const id, int const fd, - LIBMTP_progressfunc_t const * const callback, + LIBMTP_progressfunc_t const callback, void const * const data) { // This is just a wrapper @@ -2098,7 +2110,7 @@ int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t *device, */ int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *device, char const * const path, LIBMTP_track_t * const metadata, - LIBMTP_progressfunc_t const * const callback, + LIBMTP_progressfunc_t const callback, void const * const data, uint32_t const parenthandle) { int fd; @@ -2152,7 +2164,7 @@ int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *device, */ int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *device, int const fd, LIBMTP_track_t * const metadata, - LIBMTP_progressfunc_t const * const callback, + LIBMTP_progressfunc_t const callback, void const * const data, uint32_t const parenthandle) { uint16_t ret; @@ -2189,6 +2201,7 @@ int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *device, return -1; } + // Callbacks ptp_usb->callback_active = 1; ptp_usb->current_transfer_total = metadata->filesize+12+12; // 12 = USB header size, two commands ptp_usb->current_transfer_complete = 0; @@ -2196,19 +2209,17 @@ int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *device, ptp_usb->current_transfer_callback_data = data; ret = ptp_sendobject_fromfd(params, fd, metadata->filesize); + + ptp_usb->callback_active = 0; + ptp_usb->current_transfer_callback = NULL; + ptp_usb->current_transfer_callback_data = NULL; + 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); if (subcall_ret != 0) { @@ -2246,7 +2257,7 @@ int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *device, */ int LIBMTP_Send_File_From_File(LIBMTP_mtpdevice_t *device, char const * const path, LIBMTP_file_t * const filedata, - LIBMTP_progressfunc_t const * const callback, + LIBMTP_progressfunc_t const callback, void const * const data, uint32_t const parenthandle) { int fd; @@ -2299,7 +2310,7 @@ int LIBMTP_Send_File_From_File(LIBMTP_mtpdevice_t *device, */ int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *device, int const fd, LIBMTP_file_t * const filedata, - LIBMTP_progressfunc_t const * const callback, + LIBMTP_progressfunc_t const callback, void const * const data, uint32_t const parenthandle) { uint16_t ret; @@ -2361,7 +2372,8 @@ 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; } - + + // Callbacks ptp_usb->callback_active = 1; ptp_usb->current_transfer_total = filedata->filesize+12+12; // 12 = USB header size, two commands ptp_usb->current_transfer_complete = 0; @@ -2369,19 +2381,17 @@ int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *device, ptp_usb->current_transfer_callback_data = data; ret = ptp_sendobject_fromfd(params, fd, filedata->filesize); + + ptp_usb->callback_active = 0; + ptp_usb->current_transfer_callback = NULL; + ptp_usb->current_transfer_callback_data = NULL; + 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 b60d467..7b6f49c 100644 --- a/src/libmtp.h.in +++ b/src/libmtp.h.in @@ -271,14 +271,14 @@ char const * LIBMTP_Get_Filetype_Description(LIBMTP_filetype_t); LIBMTP_file_t *LIBMTP_Get_Filelisting(LIBMTP_mtpdevice_t *); LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const); int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const, - LIBMTP_progressfunc_t const * const, void const * const); + LIBMTP_progressfunc_t const, void const * const); int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const, - LIBMTP_progressfunc_t const * const, void const * const); + LIBMTP_progressfunc_t const, void const * const); int LIBMTP_Send_File_From_File(LIBMTP_mtpdevice_t *, char const * const, - LIBMTP_file_t * const, LIBMTP_progressfunc_t const * const, + LIBMTP_file_t * const, LIBMTP_progressfunc_t const, void const * const, uint32_t const); int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *, int const, - LIBMTP_file_t * const, LIBMTP_progressfunc_t const * const, + LIBMTP_file_t * const, LIBMTP_progressfunc_t const, void const * const, uint32_t const); /** * @} @@ -290,16 +290,16 @@ void LIBMTP_destroy_track_t(LIBMTP_track_t*); LIBMTP_track_t *LIBMTP_Get_Tracklisting(LIBMTP_mtpdevice_t*); LIBMTP_track_t *LIBMTP_Get_Trackmetadata(LIBMTP_mtpdevice_t*, uint32_t const); int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const, - LIBMTP_progressfunc_t const * const, void const * const); + LIBMTP_progressfunc_t const, void const * const); int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const, - LIBMTP_progressfunc_t const * const, void const * const); + LIBMTP_progressfunc_t const, void const * const); int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *, char const * const, LIBMTP_track_t * const, - LIBMTP_progressfunc_t const * const, + LIBMTP_progressfunc_t const, void const * const, uint32_t const); int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *, int const, LIBMTP_track_t * const, - LIBMTP_progressfunc_t const * const, + LIBMTP_progressfunc_t const, void const * const, uint32_t const); int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *, LIBMTP_track_t const * const); diff --git a/src/libusb-glue.c b/src/libusb-glue.c index 841a4df..394a05d 100644 --- a/src/libusb-glue.c +++ b/src/libusb-glue.c @@ -352,6 +352,17 @@ ptp_read_func (unsigned char *bytes, unsigned int size, void *data, unsigned int if (result < toread) /* short reads are common */ break; } + + // Increase counters, call callback + if (ptp_usb->callback_active) { + ptp_usb->current_transfer_complete += curread; + 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 (result > 0) { *readbytes = curread; return (PTP_RC_OK); diff --git a/src/libusb-glue.h b/src/libusb-glue.h index 1d62dff..6214e8c 100644 --- a/src/libusb-glue.h +++ b/src/libusb-glue.h @@ -30,7 +30,7 @@ struct _PTP_USB { uint64_t current_transfer_total; uint64_t current_transfer_complete; LIBMTP_progressfunc_t current_transfer_callback; - void *current_transfer_callback_data; + void const * current_transfer_callback_data; }; int get_device_list(LIBMTP_device_entry_t ** const devices, int * const numdevs); |