summaryrefslogtreecommitdiff
path: root/src/libmtp.h.in
blob: b60d46721b222b69ce1617e8e0f941b919451b18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/**
 * \file libmtp.h
 *
 * Interface to the Media Transfer Protocol library.
 *
 * <code>
 * #include <libmtp.h>
 * </code>
 */
#ifndef LIBMTP_H_INCLUSION_GUARD
#define LIBMTP_H_INCLUSION_GUARD

#define LIBMTP_VERSION @VERSION@

/* This handles MSVC pecularities */
#ifdef _MSC_VER
#include <windows.h>
#define __WIN32__
#define snprintf _snprintf
#define ssize_t SSIZE_T
#endif

#include <stdio.h>
#include <usb.h>
#include <stdint.h>

#ifdef __WIN32__
/*
 * Windows specific code, types that do not exist in Windows
 * sys/types.h
 */
typedef char int8_t;
typedef unsigned char uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#endif

/**
 * @defgroup types libmtp global type definitions
 * @{
 * The filetypes defined here are the external types used
 * by the libmtp library interface. The types used internally
 * as PTP-defined enumerator types is something different.
 */
typedef enum {
  LIBMTP_FILETYPE_WAV,
  LIBMTP_FILETYPE_MP3,
  LIBMTP_FILETYPE_WMA,
  LIBMTP_FILETYPE_OGG,
  LIBMTP_FILETYPE_AUDIBLE,
  LIBMTP_FILETYPE_MP4,
  LIBMTP_FILETYPE_UNDEF_AUDIO,
  LIBMTP_FILETYPE_WMV,
  LIBMTP_FILETYPE_AVI,
  LIBMTP_FILETYPE_MPEG,
  LIBMTP_FILETYPE_ASF,
  LIBMTP_FILETYPE_QT,
  LIBMTP_FILETYPE_UNDEF_VIDEO,
  LIBMTP_FILETYPE_JPEG,
  LIBMTP_FILETYPE_JFIF,
  LIBMTP_FILETYPE_TIFF,
  LIBMTP_FILETYPE_BMP,
  LIBMTP_FILETYPE_GIF,
  LIBMTP_FILETYPE_PICT,
  LIBMTP_FILETYPE_PNG,
  LIBMTP_FILETYPE_VCALENDAR1,
  LIBMTP_FILETYPE_VCALENDAR2,
  LIBMTP_FILETYPE_VCARD2,
  LIBMTP_FILETYPE_VCARD3,
  LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT,
  LIBMTP_FILETYPE_WINEXEC,
  LIBMTP_FILETYPE_TEXT,
  LIBMTP_FILETYPE_HTML,
  LIBMTP_FILETYPE_UNKNOWN
} LIBMTP_filetype_t;
typedef struct LIBMTP_device_entry_struct LIBMTP_device_entry_t; /**< @see LIBMTP_device_entry_struct */
typedef struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t; /**< @see LIBMTP_mtpdevice_struct */
typedef struct LIBMTP_file_struct LIBMTP_file_t; /**< @see LIBMTP_file_struct */
typedef struct LIBMTP_track_struct LIBMTP_track_t; /**< @see LIBMTP_track_struct */
typedef struct LIBMTP_playlist_struct LIBMTP_playlist_t; /**< @see LIBMTP_playlist_struct */
typedef struct LIBMTP_folder_struct LIBMTP_folder_t; /**< @see LIBMTP_folder_t */
typedef struct LIBMTP_object_struct LIBMTP_object_t; /**< @see LIBMTP_object_t */

/** 
 * The callback type definition. Notice that a progress percentage ratio
 * is easy to calculate by dividing <code>sent</code> by 
 * <code>total</code>.
 * @param sent the number of bytes sent so far
 * @param total the total number of bytes to send
 * @param data a user-defined dereferencable pointer
 * @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,
                		void const * const data);

/** 
 * @} 
 * @defgroup structar libmtp data structures
 * @{
 */

/**
 * A data structure to hold MTP device entries
 */
struct LIBMTP_device_entry_struct {
  char *name; /**< The descriptive name of this device */
  uint16_t vendor_id; /**< Vendor ID for this device */
  uint16_t product_id; /**< Product ID for this device */
};

/**
 * Main MTP device object struct
 */
struct LIBMTP_mtpdevice_struct {
  /** Interface number of this device */
  uint8_t interface_number;
  /** 
   * Parameters for this device, must be cast into 
   * \c (PTPParams*) before internal use.
   */
  void *params;
  /** 
   * USB device for this device, must be cast into
   * \c (PTP_USB*) before internal use.
   */
  void *usbinfo;
  /** The storage ID for this device */
  unsigned storage_id;
  /** The maximum battery level for this device */
  uint8_t maximum_battery_level;
  /** Default music folder */
  uint32_t default_music_folder;
  /** Default playlist folder */
  uint32_t default_playlist_folder;
  /** Default picture folder */
  uint32_t default_picture_folder;
  /** Default video folder */
  uint32_t default_video_folder;
  /** Default organizer folder */
  uint32_t default_organizer_folder;
  /** Default ZENcast folder (only Creative devices...) */
  uint32_t default_zencast_folder;
  /** Per device iconv() converters, only used internally */
  void *cd;
};

/**
 * MTP file struct
 */
struct LIBMTP_file_struct {
  uint32_t item_id; /**< Unique item ID */
  uint32_t parent_id; /**< ID of parent folder */
  char *filename; /**< Filename of this file */
  uint64_t filesize; /**< Size of file in bytes */
  LIBMTP_filetype_t filetype; /**< Filetype used for the current file */
  LIBMTP_file_t *next; /**< Next file in list or NULL if last file */
};

/**
 * MTP track struct
 */
struct LIBMTP_track_struct {
  uint32_t item_id; /**< Unique item ID */
  char *title; /**< Track title */
  char *artist; /**< Name of recording artist */
  char *genre; /**< Genre name for track */
  char *album; /**< Album name for track */
  char *date; /**< Date of original recording as a string */
  char *filename; /**< Original filename of this track */
  uint16_t tracknumber; /**< Track number (in sequence on recording) */
  uint32_t duration; /**< Duration in milliseconds */
  uint32_t samplerate; /**< Sample rate of original file, min 0x1f80 max 0xbb80 */	
  uint16_t nochannels; /**< Number of channels in this recording 0 = unknown, 1 or 2 */
  uint32_t wavecodec; /**< FourCC wave codec name */
  uint32_t bitrate; /**< (Average) bitrate for this file min=1 max=0x16e360 */
  uint16_t bitratetype; /**< 0 = unused, 1 = constant, 2 = VBR, 3 = free */
  uint16_t rating; /**< User rating 0-100 (0x00-0x64) */
  uint32_t usecount; /**< Number of times used/played */
  uint64_t filesize; /**< Size of track file in bytes */
  LIBMTP_filetype_t filetype; /**< Filetype used for the current track */
  LIBMTP_track_t *next; /**< Next track in list or NULL if last track */
};

/**
 * MTP Playlist structure
 */
struct LIBMTP_playlist_struct {
  uint32_t playlist_id; /**< Unique playlist ID */
  char *name; /**< Name of playlist */
  uint32_t *tracks; /**< The tracks in this playlist */
  uint32_t no_tracks; /**< The number of tracks in this playlist */
  LIBMTP_playlist_t *next; /**< Next playlist or NULL if last playlist */
};

/**
 * MTP Folder structure
 */
struct LIBMTP_folder_struct {
  uint32_t folder_id; /**< Unique folder ID */
  uint32_t parent_id; /**< ID of parent folder */
  char *name; /**< Name of folder */
  LIBMTP_folder_t *sibling; /**< Next folder at same level or NULL if no more */
  LIBMTP_folder_t *child; /**< Child folder or NULL if no children */
};

/**
 * LIBMTP Object Structure
 */
struct LIBMTP_object_struct { 
  uint32_t id; 
  uint32_t parent; 
  uint32_t type; 
  uint32_t size;
  char *name; 
  void *data; 
  LIBMTP_object_t *sibling; 
  LIBMTP_object_t *child; 
}; 

/** @} */

/* Make functions available for C++ */
#ifdef __cplusplus
extern "C" {
#endif

/**
 * @defgroup internals The libmtp internals API.
 * @{
 */
void LIBMTP_Init(void);
int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const, int * const);
/**
 * @}
 * @defgroup basic The basic device management API.
 * @{
 */
int LIBMTP_Detect_Descriptor(uint16_t*,uint16_t*);
LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void);
void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*);
void LIBMTP_Dump_Device_Info(LIBMTP_mtpdevice_t*);
char *LIBMTP_Get_Modelname(LIBMTP_mtpdevice_t*);
char *LIBMTP_Get_Serialnumber(LIBMTP_mtpdevice_t*);
char *LIBMTP_Get_Deviceversion(LIBMTP_mtpdevice_t*);
char *LIBMTP_Get_Friendlyname(LIBMTP_mtpdevice_t*);
int LIBMTP_Set_Friendlyname(LIBMTP_mtpdevice_t*, char const * const);
char *LIBMTP_Get_Syncpartner(LIBMTP_mtpdevice_t*);
int LIBMTP_Set_Syncpartner(LIBMTP_mtpdevice_t*, char const * const);
int LIBMTP_Get_Storageinfo(LIBMTP_mtpdevice_t *, uint64_t * const, 
			uint64_t * const, char ** const storage_description, 
			char ** const volume_label);
int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *, 
			    uint8_t * const, 
			    uint8_t * const);
int LIBMTP_Get_Secure_Time(LIBMTP_mtpdevice_t *, char ** const);
int LIBMTP_Get_Device_Certificate(LIBMTP_mtpdevice_t *, char ** const);
int LIBMTP_Get_Supported_Filetypes(LIBMTP_mtpdevice_t *, uint16_t ** const, uint16_t * const);

/**
 * @}
 * @defgroup files The file management API.
 * @{
 */
LIBMTP_file_t *LIBMTP_new_file_t(void);
void LIBMTP_destroy_file_t(LIBMTP_file_t*);
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);
int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const, 
			LIBMTP_progressfunc_t const * 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,
			 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,
			void const * const, uint32_t const);
/**
 * @}
 * @defgroup tracks The track management API.
 * @{
 */
LIBMTP_track_t *LIBMTP_new_track_t(void);
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);
int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const, 
			LIBMTP_progressfunc_t const * 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,
			 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,
			 void const * const, uint32_t const);
int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *, 
			LIBMTP_track_t const * const);
int LIBMTP_Track_Exists(LIBMTP_mtpdevice_t *, uint32_t);
/** @} */

/**
 * @}
 * @defgroup folders The folder management API.
 * @{
 */
LIBMTP_folder_t *LIBMTP_new_folder_t(void);
void LIBMTP_destroy_folder_t(LIBMTP_folder_t*);
LIBMTP_folder_t *LIBMTP_Get_Folder_List(LIBMTP_mtpdevice_t*);
LIBMTP_folder_t *LIBMTP_Find_Folder(LIBMTP_folder_t*, uint32_t const);
uint32_t LIBMTP_Create_Folder(LIBMTP_mtpdevice_t*, char *, uint32_t);
/** @} */


/**
 * @}
 * @defgroup playlists The audio/video playlist management API.
 * @{
 */
LIBMTP_playlist_t *LIBMTP_new_playlist_t(void);
void LIBMTP_destroy_playlist_t(LIBMTP_playlist_t *);
LIBMTP_playlist_t *LIBMTP_Get_Playlist_List(LIBMTP_mtpdevice_t *);
LIBMTP_playlist_t *LIBMTP_Get_Playlist(LIBMTP_mtpdevice_t *, uint32_t const);
int LIBMTP_Create_New_Playlist(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t * const, uint32_t const);
int LIBMTP_Update_Playlist(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t const * const);


/**
 * @}
 * @defgroup objects The object management API.
 * @{
 */
char *LIBMTP_Get_String_From_Object(LIBMTP_mtpdevice_t *,const uint32_t, const uint32_t, uint8_t);
uint32_t LIBMTP_Get_U32_From_Object(LIBMTP_mtpdevice_t *,const uint32_t, const uint32_t, const uint32_t);
uint16_t LIBMTP_Get_U16_From_Object(LIBMTP_mtpdevice_t *,const uint32_t, const uint32_t, const uint16_t);
int LIBMTP_Set_Object_String(LIBMTP_mtpdevice_t *,const uint32_t,const uint32_t, 
                             char const * const, const uint8_t);
int LIBMTP_Set_Object_U32(LIBMTP_mtpdevice_t *,const uint32_t, const uint32_t, const uint32_t);
int LIBMTP_Set_Object_U16(LIBMTP_mtpdevice_t *,const uint32_t, const uint32_t, const uint16_t);
int LIBMTP_Get_Object_References(LIBMTP_mtpdevice_t *, const uint32_t, uint32_t **, uint32_t *);
int LIBMTP_Set_Object_References(LIBMTP_mtpdevice_t *, const uint32_t, uint32_t const * const, const uint32_t);
LIBMTP_object_t *LIBMTP_Make_List(LIBMTP_mtpdevice_t *, uint32_t *, uint32_t, uint32_t *, uint32_t);
LIBMTP_object_t *LIBMTP_Find_Object(LIBMTP_object_t *, const uint32_t);
void LIBMTP_Dump_List(LIBMTP_object_t *);
LIBMTP_object_t *LIBMTP_new_object_t(void);
void LIBMTP_destroy_object_t(LIBMTP_object_t *, uint32_t);
int LIBMTP_Delete_Object(LIBMTP_mtpdevice_t *, uint32_t);
/** @} */

/**
 * @}
 * @defgroup File mapping The file mapping API
 * @{
 */
int LIBMTP_Register_Filetype(char const * const, LIBMTP_filetype_t const, 
			     uint16_t const, void const * const, 
			     void const * const, void const * const);
int LIBMTP_Set_Filetype_Description(LIBMTP_filetype_t, char const * const);
int LIBMTP_Set_Constructor(LIBMTP_filetype_t, void const * const);
int LIBMTP_Set_Destructor(LIBMTP_filetype_t, void const * const);
int LIBMTP_Set_Datafunc(LIBMTP_filetype_t, void const * const);
/** @} */


/* End of C++ exports */
#ifdef __cplusplus
}
#endif

#endif /* LIBMTP_H_INCLUSION_GUARD */