4
/* Undefine if libnjb was compiled for libusb support */
5
#undef LIBNJB_COMPILED_FOR_LIBUSB
10
#ifdef LIBNJB_COMPILED_FOR_LIBUSB
13
#include <dev/usb/usb.h>
16
#define NJB_MAX_DEVICES 0xFF
18
/* Enumerators to identify different jukeboxes */
19
#define NJB_DEVICE_NJB1 0x00
20
#define NJB_DEVICE_NJB2 0x01
21
#define NJB_DEVICE_NJB3 0x02
22
#define NJB_DEVICE_NJBZEN 0x03
23
#define NJB_DEVICE_NJBZEN2 0x04
24
#define NJB_DEVICE_NJBZENNX 0x05
25
#define NJB_DEVICE_NJBZENXTRA 0x06
26
#define NJB_DEVICE_DELLDJ 0x07
28
#define NJB_POWER_BATTERY 0x00
29
#define NJB_POWER_AC_CHARGED 0x01
30
#define NJB_POWER_AC_CHARGING 0x03
32
#define ID_DATA_ASCII 0
35
#define NJB_CODEC_MP3 "MP3"
36
#define NJB_CODEC_WMA "WMA"
37
#define NJB_CODEC_WAV "WAV"
39
#define FR_SIZE "FILE SIZE"
40
#define FR_LENGTH "LENGTH"
41
#define FR_CODEC "CODEC"
42
#define FR_TITLE "TITLE"
43
#define FR_ALBUM "ALBUM"
44
#define FR_GENRE "GENRE"
45
#define FR_ARTIST "ARTIST"
46
#define FR_TRACK "TRACK NUM"
47
#define FR_FNAME "FNAME"
48
#define FR_YEAR "YEAR"
49
#define FR_PROTECTED "PlayOnly"
51
/* Sound adjustment parameters */
53
#define NJB_SOUND_SET_VOLUME 0x01
54
#define NJB_SOUND_SET_BASS 0x02
55
#define NJB_SOUND_SET_TREBLE 0x03
56
#define NJB_SOUND_SET_MUTING 0x04
57
#define NJB_SOUND_SET_MIDRANGE 0x05
58
#define NJB_SOUND_SET_MIDFREQ 0x06
59
#define NJB_SOUND_SET_EAX 0x07
60
#define NJB_SOUND_SET_EAXAMT 0x08
61
#define NJB_SOUND_SET_HEADPHONE 0x09
62
#define NJB_SOUND_SET_REAR 0x0A
63
#define NJB_SOUND_SET_EQSTATUS 0x0D
67
#define EO_USBCTL 1 /* I/O failure on USB control pipe */
68
#define EO_USBBLK 2 /* I/O failure on USB data pipe */
69
#define EO_RDSHORT 3 /* short read on USB data pipe */
70
#define EO_NOMEM 4 /* out of memory */
71
#define EO_BADDATA 5 /* invalid data */
72
#define EO_EOM 6 /* end of data */
73
#define EO_BADSTATUS 7 /* bad status from Jukebox */
74
#define EO_BADNJBID 8 /* Jukebox ID has changed */
75
#define EO_BADCOUNT 9 /* library count mismatch */
76
#define EO_WRSHORT 10 /* short write on USB data pipe */
77
#define EO_NULLTMP 11 /* temporary transfer dir not defined */
78
#define EO_TOOBIG 12 /* block size too big */
79
#define EO_CANTMOVE 13 /* can't move file to destination */
80
#define EO_TIMEOUT 14 /* operation timed out */
81
#define EO_ABORTED 15 /* operation aborted */
82
#define EO_EOF 16 /* received EOF */
83
#define EO_DEVICE 17 /* can't open device for read/write */
84
#define EO_INIT 18 /* can't initialize device */
85
#define EO_TMPFILE 19 /* can't create temporary file */
86
#define EO_XFERDENIED 20 /* transfer request denied */
87
#define EO_WRFILE 21 /* error writing output file */
88
#define EO_XFERERROR 22 /* bad transfer completion status */
89
#define EO_SRCFILE 23 /* can't read source file */
90
#define EO_INVALID 24 /* invalid arguments */
91
#define EO_AGAIN 25 /* resource temporarily unavailable */
96
#define DD_USBBLKLIM 2
99
#define DD_BSDKDEBUG 16
103
#define NJB_UC_8859 0
104
#define NJB_UC_UTF8 1
106
/* NJB structure definitions */
109
unsigned char id[16]; /* Move all of this into njb_t eventually */
116
char productName[33];
121
unsigned char id[16];
125
#define OWNER_STRING_LENGTH 128
126
typedef unsigned char owner_string[OWNER_STRING_LENGTH + 1];
128
#ifndef LIBNJB_COMPILED_FOR_LIBUSB
136
typedef struct njb_t njb_t;
137
typedef struct songid_frame_t songid_frame_t;
138
typedef struct songid_t songid_t;
139
typedef struct playlist_track_struct playlist_track_t;
140
typedef struct playlist_struct playlist_t;
141
typedef struct datafile_struct datafile_t;
144
#ifdef LIBNJB_COMPILED_FOR_LIBUSB
145
struct usb_device *device;
149
usb_dev_handle *ctl; /* made protocol.c port easier */
151
usb_dev_handle *bout;
153
usb_dev_handle *iout;
160
struct usb_device_info info;
162
int device_type; /* what kind of jukebox it is */
163
unsigned char id[16];
167
int extrarun_on_rename; /* Used during renaming of tracks in series 3 protocol */
168
int get_extended_tag_info; /* Get extended tags */
169
int reset_get_track_tag;
170
int reset_get_playlist;
171
int reset_get_datafile_tag;
175
unsigned char *protocol_state; /* dereferenced and maintained individually by protocol implementations */
176
u_int8_t fwMajor; /* should eventually be moved here from njbid_t */
181
/* Song/track tag definitions */
183
struct songid_frame_t {
189
songid_frame_t *next;
195
songid_frame_t *first;
196
songid_frame_t *last;
198
songid_t *next; /* Used on NJB3 only */
201
/* Playlist definitions */
203
struct playlist_track_struct {
205
struct playlist_track_struct *prev;
206
struct playlist_track_struct *next;
209
struct playlist_struct {
213
#define NJB_PL_UNCHANGED 1
214
#define NJB_PL_CHNAME 2
215
#define NJB_PL_CHTRACKS 3
218
playlist_track_t *first;
219
playlist_track_t *last;
220
playlist_track_t *cur;
221
playlist_t *nextpl; /* Used on NJB3 only */
224
/* Data file tag definitions */
226
struct datafile_struct {
235
/* EAX block definition */
255
int16_t *frequencies;
285
typedef int XferCallback(u_int64_t sent, u_int64_t total,
286
const char* buf, unsigned len, void *data);
288
int NJB_Set_TmpDir (njb_t *njb, const char *dir);
289
const char *NJB_Get_TmpDir (njb_t *njb);
290
int NJB_Discover(njb_t *njbs, int limit, int *n);
291
int NJB_Open(njb_t *njb);
292
void NJB_Close(njb_t *njb);
293
int NJB_Capture (njb_t *njb);
294
int NJB_Release (njb_t *njb);
295
njbid_t *NJB_Ping(njb_t *njb);
296
void NJB_Get_Extended_Tags (njb_t *njb, int extended);
297
void NJB_Reset_Get_Track_Tag (njb_t *njb);
298
songid_t *NJB_Get_Track_Tag (njb_t *njb);
299
void NJB_Reset_Get_Playlist (njb_t *njb);
300
playlist_t *NJB_Get_Playlist (njb_t *njb);
301
int NJB_Get_Disk_Usage (njb_t *njb, u_int64_t *btotal, u_int64_t *bfree);
302
char *NJB_Get_Owner_String (njb_t *njb);
303
int NJB_Set_Owner_String (njb_t *njb, const char *name);
304
void NJB_Reset_Get_Datafile_Tag (njb_t *njb);
305
datafile_t *NJB_Get_Datafile_Tag (njb_t *njb);
306
eax_t *NJB_Get_EAX (njb_t *njb);
307
int NJB_Refresh_EAX (njb_t *njb, eax_t *eax);
308
njb_time_t *NJB_Get_Time(njb_t *njb);
309
int NJB_Set_Time(njb_t *njb, njb_time_t *time);
310
int NJB_Set_Bitmap(njb_t *njb, const char * pbm_file);
311
int NJB_Delete_Playlist (njb_t *njb, u_int32_t plid);
312
int NJB_Update_Playlist (njb_t *njb, playlist_t *pl);
313
int NJB_Delete_Track (njb_t *njb, u_int32_t trackid);
314
int NJB_Delete_Datafile (njb_t *njb, u_int32_t fileid);
315
#define NJB_Get_File NJB_Get_Track
316
int NJB_Get_Track (njb_t *njb, u_int32_t trackid, u_int32_t size,
317
const char *path, XferCallback *callback, void *data);
318
int NJB_Send_Track (njb_t *njb, const char *path, const char *codec,
319
const char *title, const char *album, const char *genre,
320
const char *artist, u_int32_t length, u_int32_t tracknum,
321
const char *year, int protect,
322
XferCallback *callback, void *data, u_int32_t *trackid);
323
int NJB_Send_File (njb_t *njb, const char *path, const char *name,
324
XferCallback *callback, void *data, u_int32_t *fileid);
325
int NJB_Replace_Track_Tag(njb_t *njb, u_int32_t trackid, const char *codec,
326
const char *title, const char *album, const char *genre,
327
const char *artist, u_int32_t length, u_int32_t tracknum,
328
u_int32_t filesize, const char *fname, const char *year, int protect);
329
int NJB_Play_Track (njb_t *njb, u_int32_t trackid);
330
int NJB_Queue_Track (njb_t *njb, u_int32_t trackid);
331
int NJB_Stop_Play (njb_t *njb);
332
int NJB_Pause_Play (njb_t *njb);
333
int NJB_Resume_Play (njb_t *njb);
334
int NJB_Seek_Track (njb_t *njb, u_int32_t position);
335
int NJB_Elapsed_Time (njb_t *njb, u_int16_t *elapsed, int *change);
336
int NJB_Adjust_Sound(njb_t *njb, u_int8_t effect, u_int16_t value);
337
void NJB_Set_Debug (int debug_flags);
338
void NJB_Set_Unicode (int unicode_flag);
340
/* Error functions */
342
void njb_error_reset_geterror (void);
343
const char *njb_error_geterror (void);
344
const char *njb_error_string (int err);
345
void njb_error_dump (FILE *fp);
347
/* Song/track tag functions */
349
songid_t *songid_new (void);
350
songid_t *songid_unpack (void *data, size_t nbytes);
351
unsigned char *songid_pack (songid_t *song, u_int32_t *size);
352
unsigned char *songid_pack3 (songid_t *song, u_int32_t *size);
353
void songid_destroy (songid_t *song);
354
void songid_addframe (songid_t *song, songid_frame_t *frame);
355
void songid_dump (songid_t *song, FILE *fp);
356
void songid_reset_getframe (songid_t *song);
357
songid_frame_t *songid_getframe (songid_t *song);
358
songid_frame_t *songid_findframe (songid_t *song, const char *label);
360
songid_frame_t *songid_frame_new (u_int16_t labelsz, const void *label,
361
u_int16_t type, u_int16_t datasz, const void *data);
362
void songid_frame_destroy (songid_frame_t *frame);
363
void songid_frame_dump (songid_frame_t *frame, FILE *fp);
364
u_int32_t songid_frame_data32 (songid_frame_t *frame);
366
#define songid_frame_new_codec(a) songid_frame_new(6,FR_CODEC,ID_DATA_ASCII,strlen(a)+1,a)
367
#define songid_frame_new_title(a) songid_frame_new(6,FR_TITLE,ID_DATA_ASCII,strlen(a)+1,a)
368
#define songid_frame_new_album(a) songid_frame_new(6,FR_ALBUM,ID_DATA_ASCII,strlen(a)+1,a)
369
#define songid_frame_new_genre(a) songid_frame_new(6,FR_GENRE,ID_DATA_ASCII,strlen(a)+1,a)
370
#define songid_frame_new_artist(a) songid_frame_new(7,FR_ARTIST,ID_DATA_ASCII,strlen(a)+1,a)
371
#define songid_frame_new_length(a) songid_frame_new(7,FR_LENGTH,ID_DATA_BIN,sizeof(u_int32_t),a)
372
#define songid_frame_new_filesize(a) songid_frame_new(10,FR_SIZE,ID_DATA_BIN,sizeof(u_int32_t),a)
373
#define songid_frame_new_tracknum(a) songid_frame_new(10,FR_TRACK,ID_DATA_BIN,sizeof(u_int32_t),a)
374
#define songid_frame_new_fname(a) songid_frame_new(10,FR_FNAME,ID_DATA_ASCII,strlen(a)+1,a)
375
#define songid_frame_new_year(a) songid_frame_new(10,FR_YEAR,ID_DATA_ASCII,strlen(a)+1,a)
376
#define songid_frame_new_protected(a) songid_frame_new(10,FR_PROTECTED,ID_DATA_ASCII,strlen(a)+1,a)
378
u_int32_t songid_size (songid_t *song);
379
u_int32_t songid_length (songid_t *song);
380
u_int32_t songid_track (songid_t *song);
381
const char *songid_label (songid_t *song, const char *label);
382
#define songid_title(a) songid_label(a,FR_TITLE);
383
#define songid_album(a) songid_label(a,FR_ALBUM);
384
#define songid_genre(a) songid_label(a,FR_GENRE);
385
#define songid_codec(a) songid_label(a,FR_CODEC);
386
#define songid_fname(a) songid_label(a,FR_FNAME);
387
#define songid_artist(a) songid_label(a,FR_ARTIST);
388
#define songid_year(a) songid_label(a,FR_YEAR);
389
#define songid_protected(a) songid_label(a,FR_PROTECTED);
391
/* Playlist fuctions */
393
playlist_t *playlist_new (void);
394
void playlist_destroy (playlist_t *pl);
395
void playlist_addtrack (playlist_t *pl, playlist_track_t *track,
398
#define NJB_PL_START 1
399
void playlist_reset_gettrack (playlist_t *pl);
400
playlist_track_t *playlist_gettrack (playlist_t *pl);
401
int playlist_set_name (playlist_t *pl, const char *name);
402
void playlist_deltrack (playlist_t *pl, unsigned int pos);
403
void playlist_dump(playlist_t *pl, FILE *fp);
404
playlist_t *playlist_unpack (void *data, size_t nbytes);
405
u_int32_t playlist_pack (playlist_t *pl, char *data);
407
playlist_track_t *playlist_track_new (u_int32_t trackid);
408
void playlist_track_destroy (playlist_track_t *track);
410
/* Data file tag functions */
412
datafile_t *datafile_new (void);
413
void datafile_destroy (datafile_t *df);
414
void datafile_dump(datafile_t *df, FILE *fp);
415
datafile_t *datafile_unpack (unsigned char *data, size_t nbytes);
416
unsigned char *datafile_pack (datafile_t *df, u_int32_t *size);
417
u_int64_t datafile_size (datafile_t *df);
418
void datafile_set_size (datafile_t *df, u_int64_t size);
419
void datafile_set_time (datafile_t *df, time_t ts);
420
int datafile_set_name (datafile_t *df, const char *filename);
421
unsigned char *datafile_pack3 (njb_t *njb, datafile_t *df, u_int32_t *size);
425
eax_t *eax_unpack(void *data, size_t nbytes);
426
eax_t *eax_unpack3(void *data);
427
void eax_destroy(eax_t *eax);
428
void eax_refresh(eax_t *eax, unsigned char *data, size_t numbytes);
432
njb_time_t *time_unpack(void *data);
433
njb_time_t *time_unpack3(void *data);
434
void *time_pack(njb_time_t *time);
435
void *time_pack3(njb_time_t *time);