split header/packet sizes fixes
diff --git a/ChangeLog b/ChangeLog
index 4e97a3d..ba18382 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-01-02  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: another try at split headers/packet sizes
+	* src/ptp.c: ditto
+	* src/libusb-glue.c: ditto
+
 2007-01-01  Linus Walleij <triad@df.lth.se>
 
 	* src/libmtp.c: move default setting of split headers
diff --git a/src/libmtp.c b/src/libmtp.c
index fe28b19..38b0ef0 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -2702,15 +2702,9 @@
 		new_track.StorageID = store;
 		new_track.ParentObject = parenthandle;
     
-    // get split headers correct
-    if (ptp_operation_issupported(params,PTP_OC_MTP_SendObjectPropList))
-      params->split_header_data = 1;
-    
     // Create the object
     ret = ptp_sendobjectinfo(params, &store, &localph, &metadata->item_id, &new_track);
     
-    params->split_header_data = 0;
-    
     if (ret != PTP_RC_OK) {
       ptp_perror(params, ret);
       printf("LIBMTP_Send_Track_From_File_Descriptor: Could not send object info.\n");
@@ -2731,14 +2725,8 @@
   ptp_usb->current_transfer_complete = 0;
   ptp_usb->current_transfer_callback = callback;
   ptp_usb->current_transfer_callback_data = data;
-  
-  // get split headers correct
-  if (ptp_operation_issupported(params,PTP_OC_MTP_SendObjectPropList))
-    params->split_header_data = 1;
 
   ret = ptp_sendobject_fromfd(params, fd, metadata->filesize);
-  
-  params->split_header_data = 0;
 
   ptp_usb->callback_active = 0;
   ptp_usb->current_transfer_callback = NULL;
@@ -3098,10 +3086,6 @@
       return -1;
     }
   }
-
-  // get split headers correct
-  if (ptp_operation_issupported(params,PTP_OC_MTP_SendObjectPropList))
-    params->split_header_data = 1;
     
   if (filedata->filesize != (uint64_t) -1) {
     // Callbacks
@@ -3129,8 +3113,6 @@
       printf("Return code: 0x%04x (look this up in ptp.h for an explanation).\n",  ret);
     }
   }
-  
-  params->split_header_data = 0;
 
   if (ret != PTP_RC_OK) {
     ptp_perror(params, ret);
diff --git a/src/libusb-glue.c b/src/libusb-glue.c
index 86debd6..8d60b77 100644
--- a/src/libusb-glue.c
+++ b/src/libusb-glue.c
@@ -418,6 +418,8 @@
     toread = size - curread;
     if (toread > CONTEXT_BLOCK_SIZE)
       toread = CONTEXT_BLOCK_SIZE;
+    else if (toread > ptp_usb->outep_maxpacket)
+      toread -= toread % ptp_usb->outep_maxpacket;
 
     result = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, (char*)bytes, toread, ptpcam_usb_timeout);
     if (result == 0) {
diff --git a/src/ptp.c b/src/ptp.c
index c8157f4..717e064 100644
--- a/src/ptp.c
+++ b/src/ptp.c
@@ -310,6 +310,10 @@
 		/* Evaluate full data length. */
 		len=dtoh32(usbdata.length)-PTP_USB_BULK_HDR_LEN;
 
+		/* autodetect split header/data MTP devices */ 	 
+		if (dtoh32(usbdata.length) > 12 && (rlen==12)) 	 
+			params->split_header_data = 1;
+
 		data = malloc(PTP_USB_BULK_HS_MAX_PACKET_LEN);
 		/* Copy first part of data to 'data' */
 		handler->putfunc(
@@ -2848,9 +2852,6 @@
 	ptp.Param5 = (uint32_t) (objectsize & 0xffffffffU);
 	ptp.Nparam = 5;
   
-	// we always use a split header here
-	params->split_header_data = 1;
-
 	/* Set object handle to 0 for a new object */
 	oplsize = ptp_pack_OPL(params,proplist,&opldata);
 	ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, oplsize, &opldata, NULL); 
@@ -2858,9 +2859,6 @@
 	*store = ptp.Param1;
 	*parenthandle = ptp.Param2;
 	*handle = ptp.Param3; 
-
-	params->split_header_data = 0;
-
 	return ret;
 }