blob: 248d78fb5a08b11615224f82bf2ef1f860a79353 [file] [log] [blame]
/**
* \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 <sys/types.h>
#include "ptp.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 libnjb global type definitions
* @{
*/
typedef enum {
LIBMTP_CODEC_WAV,
LIBMTP_CODEC_MP3,
LIBMTP_CODEC_WMA,
LIBMTP_CODEC_UNKNOWN
} LIBMTP_codec_t;
typedef struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t; /**< @see LIBMTP_mtpdevice_struct */
typedef struct LIBMTP_track_struct LIBMTP_track_t; /**< @see LIBMTP_mtptrack_t */
/** @} */
/**
* Internal USB struct (TODO: discard for device struct?)
*/
typedef struct _PTP_USB PTP_USB;
struct _PTP_USB {
usb_dev_handle* handle;
int inep;
int outep;
int intep;
};
/**
* Main MTP device object struct
*/
struct LIBMTP_mtpdevice_struct {
uint8_t interface_number; /**< Interface number of this device */
PTPParams *params; /**< Parameters for this device */
PTP_USB *ptp_usb; /**< USB device for this device */
unsigned storage_id; /**< The storage ID for this device */
uint8_t maximum_battery_level; /**< The maximum battery level for this device */
};
/**
* 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 */
uint64_t filesize; /**< Size of track file in bytes */
LIBMTP_codec_t codec; /**< Codec used for the current track */
LIBMTP_track_t *next; /**< Next track in list or NULL if last track */
};
/* Make functions available for C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* 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 buf intermediate buffer
* @param len intermediate buffer length
* @param data a user-defined dereferencable pointer
* @return if anything else than 0 is returned, the current transfer will be
* interrupted.
*/
typedef int LIBMTP_progressfunc_t (uint64_t const sent, uint64_t const total,
uint8_t const * const buf, uint32_t const len, void const * const data);
/**
* @defgroup internals The libmtp internal state manipulation API.
* @{
*/
void LIBMTP_Init(void);
/**
* @}
* @defgroup basic The basic device management API.
* @{
*/
LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void);
void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*);
char *LIBMTP_Get_Ownername(LIBMTP_mtpdevice_t*);
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);
/**
* @}
* @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*);
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);
int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *,
int const, LIBMTP_track_t * const,
LIBMTP_progressfunc_t const * const,
void const * const);
int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *,
LIBMTP_track_t const * const);
int LIBMTP_Delete_Track(LIBMTP_mtpdevice_t *, uint32_t);
/** @} */
/* End of C++ exports */
#ifdef __cplusplus
}
#endif
#endif /* LIBMTP_H_INCLUSION_GUARD */