# libmtp.h

Go to the documentation of this file.

    00001
    00029 #ifndef LIBMTP_H_INCLUSION_GUARD
    00030 #define LIBMTP_H_INCLUSION_GUARD
    00031
    00032 #define LIBMTP_VERSION 0.3.3
    00033 #define LIBMTP_VERSION_STRING "0.3.3"
    00034
    00035 /* This handles MSVC pecularities */
    00036 #ifdef _MSC_VER
    00037 #include <windows.h>
    00038 #define __WIN32__
    00039 #define snprintf _snprintf
    00040 #define ssize_t SSIZE_T
    00041 #endif
    00042
    00043 #include <stdio.h>
    00044 #include <usb.h>
    00045 #include <stdint.h>
    00046
    00047 #ifdef __WIN32__
    00048 /*
    00049  * Windows specific code, types that do not exist in Windows
    00050  * sys/types.h
    00051  */
    00052 typedef char int8_t;
    00053 typedef unsigned char uint8_t;
    00054 typedef __int16 int16_t;
    00055 typedef unsigned __int16 uint16_t;
    00056 typedef __int32 int32_t;
    00057 typedef unsigned __int32 uint32_t;
    00058 typedef unsigned __int64 uint64_t;
    00059 #endif
    00060
    00068 typedef enum {
    00069   LIBMTP_FILETYPE_WAV,
    00070   LIBMTP_FILETYPE_MP3,
    00071   LIBMTP_FILETYPE_WMA,
    00072   LIBMTP_FILETYPE_OGG,
    00073   LIBMTP_FILETYPE_AUDIBLE,
    00074   LIBMTP_FILETYPE_MP4,
    00075   LIBMTP_FILETYPE_UNDEF_AUDIO,
    00076   LIBMTP_FILETYPE_WMV,
    00077   LIBMTP_FILETYPE_AVI,
    00078   LIBMTP_FILETYPE_MPEG,
    00079   LIBMTP_FILETYPE_ASF,
    00080   LIBMTP_FILETYPE_QT,
    00081   LIBMTP_FILETYPE_UNDEF_VIDEO,
    00082   LIBMTP_FILETYPE_JPEG,
    00083   LIBMTP_FILETYPE_JFIF,
    00084   LIBMTP_FILETYPE_TIFF,
    00085   LIBMTP_FILETYPE_BMP,
    00086   LIBMTP_FILETYPE_GIF,
    00087   LIBMTP_FILETYPE_PICT,
    00088   LIBMTP_FILETYPE_PNG,
    00089   LIBMTP_FILETYPE_VCALENDAR1,
    00090   LIBMTP_FILETYPE_VCALENDAR2,
    00091   LIBMTP_FILETYPE_VCARD2,
    00092   LIBMTP_FILETYPE_VCARD3,
    00093   LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT,
    00094   LIBMTP_FILETYPE_WINEXEC,
    00095   LIBMTP_FILETYPE_TEXT,
    00096   LIBMTP_FILETYPE_HTML,
    00097   LIBMTP_FILETYPE_FIRMWARE,
    00098   LIBMTP_FILETYPE_AAC,
    00099   LIBMTP_FILETYPE_MEDIACARD,
    00100   LIBMTP_FILETYPE_FLAC,
    00101   LIBMTP_FILETYPE_MP2,
    00102   LIBMTP_FILETYPE_M4A,
    00103   LIBMTP_FILETYPE_DOC,
    00104   LIBMTP_FILETYPE_XML,
    00105   LIBMTP_FILETYPE_XLS,
    00106   LIBMTP_FILETYPE_PPT,
    00107   LIBMTP_FILETYPE_MHT,
    00108   LIBMTP_FILETYPE_JP2,
    00109   LIBMTP_FILETYPE_JPX,
    00110   LIBMTP_FILETYPE_UNKNOWN
    00111 } LIBMTP_filetype_t;
    00112
    00120 #define LIBMTP_FILETYPE_IS_AUDIO(a)\
    00121 (a == LIBMTP_FILETYPE_WAV ||\
    00122  a == LIBMTP_FILETYPE_MP3 ||\
    00123  a == LIBMTP_FILETYPE_MP2 ||\
    00124  a == LIBMTP_FILETYPE_WMA ||\
    00125  a == LIBMTP_FILETYPE_OGG ||\
    00126  a == LIBMTP_FILETYPE_FLAC ||\
    00127  a == LIBMTP_FILETYPE_AAC ||\
    00128  a == LIBMTP_FILETYPE_M4A ||\
    00129  a == LIBMTP_FILETYPE_UNDEF_AUDIO)
    00130
    00138 #define LIBMTP_FILETYPE_IS_VIDEO(a)\
    00139 (a == LIBMTP_FILETYPE_WMV ||\
    00140  a == LIBMTP_FILETYPE_AVI ||\
    00141  a == LIBMTP_FILETYPE_MPEG ||\
    00142  a == LIBMTP_FILETYPE_UNDEF_VIDEO)
    00143
    00148 #define LIBMTP_FILETYPE_IS_AUDIOVIDEO(a)\
    00149 (a == LIBMTP_FILETYPE_MP4 ||\
    00150  a == LIBMTP_FILETYPE_ASF ||\
    00151  a == LIBMTP_FILETYPE_QT)
    00152
    00159 #define LIBMTP_FILETYPE_IS_TRACK(a)\
    00160 (LIBMTP_FILETYPE_IS_AUDIO(a) ||\
    00161  LIBMTP_FILETYPE_IS_VIDEO(a) ||\
    00162  LIBMTP_FILETYPE_IS_AUDIOVIDEO(a))
    00163
    00168 #define LIBMTP_FILETYPE_IS_IMAGE(a)\
    00169 (a == LIBMTP_FILETYPE_JPEG ||\
    00170 a == LIBMTP_FILETYPE_JFIF ||\
    00171 a == LIBMTP_FILETYPE_TIFF ||\
    00172 a == LIBMTP_FILETYPE_BMP ||\
    00173 a == LIBMTP_FILETYPE_GIF ||\
    00174 a == LIBMTP_FILETYPE_PICT ||\
    00175 a == LIBMTP_FILETYPE_PNG ||\
    00176 a == LIBMTP_FILETYPE_JP2 ||\
    00177 a == LIBMTP_FILETYPE_JPX ||\
    00178 a == LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT)
    00179
    00184 #define LIBMTP_FILETYPE_IS_ADDRESSBOOK(a)\
    00185 (a == LIBMTP_FILETYPE_VCARD2 ||\
    00186 a == LIBMTP_FILETYPE_VCARD2)
    00187
    00192 #define LIBMTP_FILETYPE_IS_CALENDAR(a)\
    00193 (a == LIBMTP_FILETYPE_VCALENDAR1 ||\
    00194 a == LIBMTP_FILETYPE_VCALENDAR2)
    00195
    00200 typedef enum {
    00201   LIBMTP_ERROR_NONE,
    00202   LIBMTP_ERROR_GENERAL,
    00203   LIBMTP_ERROR_PTP_LAYER,
    00204   LIBMTP_ERROR_USB_LAYER,
    00205   LIBMTP_ERROR_MEMORY_ALLOCATION,
    00206   LIBMTP_ERROR_NO_DEVICE_ATTACHED,
    00207   LIBMTP_ERROR_STORAGE_FULL,
    00208   LIBMTP_ERROR_CONNECTING,
    00209   LIBMTP_ERROR_CANCELLED
    00210 } LIBMTP_error_number_t;
    00211 typedef struct LIBMTP_device_entry_struct LIBMTP_device_entry_t;
    00212 typedef struct LIBMTP_raw_device_struct LIBMTP_raw_device_t;
    00213 typedef struct LIBMTP_error_struct LIBMTP_error_t;
    00214 typedef struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t;
    00215 typedef struct LIBMTP_file_struct LIBMTP_file_t;
    00216 typedef struct LIBMTP_track_struct LIBMTP_track_t;
    00217 typedef struct LIBMTP_playlist_struct LIBMTP_playlist_t;
    00218 typedef struct LIBMTP_album_struct LIBMTP_album_t;
    00219 typedef struct LIBMTP_folder_struct LIBMTP_folder_t;
    00220 typedef struct LIBMTP_object_struct LIBMTP_object_t;
    00221 typedef struct LIBMTP_filesampledata_struct LIBMTP_filesampledata_t;
    00222 typedef struct LIBMTP_devicestorage_struct LIBMTP_devicestorage_t;
    00234 typedef int (* LIBMTP_progressfunc_t) (uint64_t const sent, uint64_t const total,
    00235                                 void const * const data);
    00236
    00246 struct LIBMTP_device_entry_struct {
    00247   char *vendor;
    00248   uint16_t vendor_id;
    00249   char *product;
    00250   uint16_t product_id;
    00251   uint32_t device_flags;
    00252 };
    00253
    00258 struct LIBMTP_raw_device_struct {
    00259   LIBMTP_device_entry_t device_entry;
    00260   uint32_t bus_location;
    00261   uint8_t devnum;
    00262 };
    00263
    00267 struct LIBMTP_error_struct {
    00268   LIBMTP_error_number_t errornumber;
    00269   char *error_text;
    00270   LIBMTP_error_t *next;
    00271 };
    00272
    00276 struct LIBMTP_mtpdevice_struct {
    00280   uint8_t object_bitsize;
    00285   void *params;
    00290   void *usbinfo;
    00297   LIBMTP_devicestorage_t *storage;
    00302   LIBMTP_error_t *errorstack;
    00304   uint8_t maximum_battery_level;
    00306   uint32_t default_music_folder;
    00308   uint32_t default_playlist_folder;
    00310   uint32_t default_picture_folder;
    00312   uint32_t default_video_folder;
    00314   uint32_t default_organizer_folder;
    00316   uint32_t default_zencast_folder;
    00318   uint32_t default_album_folder;
    00320   uint32_t default_text_folder;
    00322   void *cd;
    00323
    00325   LIBMTP_mtpdevice_t *next;
    00326 };
    00327
    00331 struct LIBMTP_file_struct {
    00332   uint32_t item_id;
    00333   uint32_t parent_id;
    00334   uint32_t storage_id;
    00335   char *filename;
    00336   uint64_t filesize;
    00337   LIBMTP_filetype_t filetype;
    00338   LIBMTP_file_t *next;
    00339 };
    00340
    00344 struct LIBMTP_track_struct {
    00345   uint32_t item_id;
    00346   uint32_t parent_id;
    00347   uint32_t storage_id;
    00348   char *title;
    00349   char *artist;
    00350   char *composer;
    00351   char *genre;
    00352   char *album;
    00353   char *date;
    00354   char *filename;
    00355   uint16_t tracknumber;
    00356   uint32_t duration;
    00357   uint32_t samplerate;
    00358   uint16_t nochannels;
    00359   uint32_t wavecodec;
    00360   uint32_t bitrate;
    00361   uint16_t bitratetype;
    00362   uint16_t rating;
    00363   uint32_t usecount;
    00364   uint64_t filesize;
    00365   LIBMTP_filetype_t filetype;
    00366   LIBMTP_track_t *next;
    00367 };
    00368
    00372 struct LIBMTP_playlist_struct {
    00373   uint32_t playlist_id;
    00374   uint32_t parent_id;
    00375   uint32_t storage_id;
    00376   char *name;
    00377   uint32_t *tracks;
    00378   uint32_t no_tracks;
    00379   LIBMTP_playlist_t *next;
    00380 };
    00381
    00385 struct LIBMTP_album_struct {
    00386   uint32_t album_id;
    00387   uint32_t parent_id;
    00388   uint32_t storage_id;
    00389   char *name;
    00390   char *artist;
    00391   char *composer;
    00392   char *genre;
    00393   uint32_t *tracks;
    00394   uint32_t no_tracks;
    00395   LIBMTP_album_t *next;
    00396 };
    00397
    00401 struct LIBMTP_folder_struct {
    00402   uint32_t folder_id;
    00403   uint32_t parent_id;
    00404   uint32_t storage_id;
    00405   char *name;
    00406   LIBMTP_folder_t *sibling;
    00407   LIBMTP_folder_t *child;
    00408 };
    00409
    00413 struct LIBMTP_filesampledata_struct {
    00414   uint32_t width;
    00415   uint32_t height;
    00416   uint32_t duration;
    00417   LIBMTP_filetype_t filetype;
    00418   uint64_t size;
    00419   char *data;
    00420 };
    00421
    00425 struct LIBMTP_devicestorage_struct {
    00426   uint32_t id;
    00427   uint16_t StorageType;
    00428   uint16_t FilesystemType;
    00429   uint16_t AccessCapability;
    00430   uint64_t MaxCapacity;
    00431   uint64_t FreeSpaceInBytes;
    00432   uint64_t FreeSpaceInObjects;
    00433   char *StorageDescription;
    00434   char *VolumeIdentifier;
    00435   LIBMTP_devicestorage_t *next;
    00436   LIBMTP_devicestorage_t *prev;
    00437 };
    00438
    00439
    00442 /* Make functions available for C++ */
    00443 #ifdef __cplusplus
    00444 extern "C" {
    00445 #endif
    00446
    00451 void LIBMTP_Init(void);
    00452 int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const, int * const);
    00458 LIBMTP_error_number_t LIBMTP_Detect_Raw_Devices(LIBMTP_raw_device_t **, int *);
    00459 LIBMTP_mtpdevice_t *LIBMTP_Open_Raw_Device(LIBMTP_raw_device_t *);
    00460 /* Begin old, legacy interface */
    00461 LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void);
    00462 LIBMTP_error_number_t LIBMTP_Get_Connected_Devices(LIBMTP_mtpdevice_t **);
    00463 uint32_t LIBMTP_Number_Devices_In_List(LIBMTP_mtpdevice_t *);
    00464 void LIBMTP_Release_Device_List(LIBMTP_mtpdevice_t*);
    00465 /* End old, legacy interface */
    00466 void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*);
    00467 void LIBMTP_Dump_Device_Info(LIBMTP_mtpdevice_t*);
    00468 int LIBMTP_Reset_Device(LIBMTP_mtpdevice_t*);
    00469 char *LIBMTP_Get_Manufacturername(LIBMTP_mtpdevice_t*);
    00470 char *LIBMTP_Get_Modelname(LIBMTP_mtpdevice_t*);
    00471 char *LIBMTP_Get_Serialnumber(LIBMTP_mtpdevice_t*);
    00472 char *LIBMTP_Get_Deviceversion(LIBMTP_mtpdevice_t*);
    00473 char *LIBMTP_Get_Friendlyname(LIBMTP_mtpdevice_t*);
    00474 int LIBMTP_Set_Friendlyname(LIBMTP_mtpdevice_t*, char const * const);
    00475 char *LIBMTP_Get_Syncpartner(LIBMTP_mtpdevice_t*);
    00476 int LIBMTP_Set_Syncpartner(LIBMTP_mtpdevice_t*, char const * const);
    00477 int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *,
    00478                             uint8_t * const,
    00479                             uint8_t * const);
    00480 int LIBMTP_Get_Secure_Time(LIBMTP_mtpdevice_t *, char ** const);
    00481 int LIBMTP_Get_Device_Certificate(LIBMTP_mtpdevice_t *, char ** const);
    00482 int LIBMTP_Get_Supported_Filetypes(LIBMTP_mtpdevice_t *, uint16_t ** const, uint16_t * const);
    00483 LIBMTP_error_t *LIBMTP_Get_Errorstack(LIBMTP_mtpdevice_t*);
    00484 void LIBMTP_Clear_Errorstack(LIBMTP_mtpdevice_t*);
    00485 void LIBMTP_Dump_Errorstack(LIBMTP_mtpdevice_t*);
    00486
    00487 #define LIBMTP_STORAGE_SORTBY_NOTSORTED 0
    00488 #define LIBMTP_STORAGE_SORTBY_FREESPACE 1
    00489 #define LIBMTP_STORAGE_SORTBY_MAXSPACE  2
    00490
    00491 int LIBMTP_Get_Storage(LIBMTP_mtpdevice_t *, int const);
    00492 int LIBMTP_Format_Storage(LIBMTP_mtpdevice_t *, LIBMTP_devicestorage_t *);
    00493
    00494
    00500 LIBMTP_file_t *LIBMTP_new_file_t(void);
    00501 void LIBMTP_destroy_file_t(LIBMTP_file_t*);
    00502 char const * LIBMTP_Get_Filetype_Description(LIBMTP_filetype_t);
    00503 LIBMTP_file_t *LIBMTP_Get_Filelisting(LIBMTP_mtpdevice_t *);
    00504 LIBMTP_file_t *LIBMTP_Get_Filelisting_With_Callback(LIBMTP_mtpdevice_t *,
    00505       LIBMTP_progressfunc_t const, void const * const);
    00506 LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const);
    00507 int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
    00508                         LIBMTP_progressfunc_t const, void const * const);
    00509 int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
    00510                         LIBMTP_progressfunc_t const, void const * const);
    00511 int LIBMTP_Send_File_From_File(LIBMTP_mtpdevice_t *, char const * const,
    00512                          LIBMTP_file_t * const, LIBMTP_progressfunc_t const,
    00513                          void const * const);
    00514 int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *, int const,
    00515                         LIBMTP_file_t * const, LIBMTP_progressfunc_t const,
    00516                         void const * const);
    00517 int LIBMTP_Set_File_Name(LIBMTP_mtpdevice_t *, LIBMTP_file_t *, const char *);
    00518 LIBMTP_filesampledata_t *LIBMTP_new_filesampledata_t(void);
    00519 void LIBMTP_destroy_filesampledata_t(LIBMTP_filesampledata_t *);
    00520 int LIBMTP_Get_Representative_Sample_Format(LIBMTP_mtpdevice_t *,
    00521                         LIBMTP_filetype_t const,
    00522                         LIBMTP_filesampledata_t **);
    00523 int LIBMTP_Send_Representative_Sample(LIBMTP_mtpdevice_t *, uint32_t const,
    00524                           LIBMTP_filesampledata_t *);
    00525 int LIBMTP_Get_Representative_Sample(LIBMTP_mtpdevice_t *, uint32_t const,
    00526                           LIBMTP_filesampledata_t *);
    00527
    00533 LIBMTP_track_t *LIBMTP_new_track_t(void);
    00534 void LIBMTP_destroy_track_t(LIBMTP_track_t*);
    00535 LIBMTP_track_t *LIBMTP_Get_Tracklisting(LIBMTP_mtpdevice_t*);
    00536 LIBMTP_track_t *LIBMTP_Get_Tracklisting_With_Callback(LIBMTP_mtpdevice_t*,
    00537       LIBMTP_progressfunc_t const, void const * const);
    00538 LIBMTP_track_t *LIBMTP_Get_Trackmetadata(LIBMTP_mtpdevice_t*, uint32_t const);
    00539 int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
    00540                         LIBMTP_progressfunc_t const, void const * const);
    00541 int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
    00542                         LIBMTP_progressfunc_t const, void const * const);
    00543 int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *,
    00544                          char const * const, LIBMTP_track_t * const,
    00545                          LIBMTP_progressfunc_t const,
    00546                          void const * const);
    00547 int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *,
    00548                          int const, LIBMTP_track_t * const,
    00549                          LIBMTP_progressfunc_t const,
    00550                          void const * const);
    00551 int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *,
    00552                         LIBMTP_track_t const * const);
    00553 int LIBMTP_Track_Exists(LIBMTP_mtpdevice_t *, uint32_t);
    00554 int LIBMTP_Set_Track_Name(LIBMTP_mtpdevice_t *, LIBMTP_track_t *, const char *);
    00562 LIBMTP_folder_t *LIBMTP_new_folder_t(void);
    00563 void LIBMTP_destroy_folder_t(LIBMTP_folder_t*);
    00564 LIBMTP_folder_t *LIBMTP_Get_Folder_List(LIBMTP_mtpdevice_t*);
    00565 LIBMTP_folder_t *LIBMTP_Find_Folder(LIBMTP_folder_t*, uint32_t const);
    00566 uint32_t LIBMTP_Create_Folder(LIBMTP_mtpdevice_t*, char *, uint32_t, uint32_t);
    00567 int LIBMTP_Set_Folder_Name(LIBMTP_mtpdevice_t *, LIBMTP_folder_t *, const char *);
    00576 LIBMTP_playlist_t *LIBMTP_new_playlist_t(void);
    00577 void LIBMTP_destroy_playlist_t(LIBMTP_playlist_t *);
    00578 LIBMTP_playlist_t *LIBMTP_Get_Playlist_List(LIBMTP_mtpdevice_t *);
    00579 LIBMTP_playlist_t *LIBMTP_Get_Playlist(LIBMTP_mtpdevice_t *, uint32_t const);
    00580 int LIBMTP_Create_New_Playlist(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t * const);
    00581 int LIBMTP_Update_Playlist(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t const * const);
    00582 int LIBMTP_Set_Playlist_Name(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t *, const char *);
    00583
    00589 LIBMTP_album_t *LIBMTP_new_album_t(void);
    00590 void LIBMTP_destroy_album_t(LIBMTP_album_t *);
    00591 LIBMTP_album_t *LIBMTP_Get_Album_List(LIBMTP_mtpdevice_t *);
    00592 LIBMTP_album_t *LIBMTP_Get_Album(LIBMTP_mtpdevice_t *, uint32_t const);
    00593 int LIBMTP_Create_New_Album(LIBMTP_mtpdevice_t *, LIBMTP_album_t * const);
    00594 int LIBMTP_Update_Album(LIBMTP_mtpdevice_t *, LIBMTP_album_t const * const);
    00595 int LIBMTP_Set_Album_Name(LIBMTP_mtpdevice_t *, LIBMTP_album_t *, const char *);
    00596
    00602 int LIBMTP_Delete_Object(LIBMTP_mtpdevice_t *, uint32_t);
    00603 int LIBMTP_Set_Object_Filename(LIBMTP_mtpdevice_t *, uint32_t , char *);
    00604
    00607 /* End of C++ exports */
    00608 #ifdef __cplusplus
    00609 }
    00610 #endif
    00611
    00612 #endif /* LIBMTP_H_INCLUSION_GUARD */
    00613