~ubuntu-branches/debian/wheezy/libnjb/wheezy

« back to all changes in this revision

Viewing changes to src/libnjb.h.in

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2004-05-25 13:06:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040525130610-vexcucw1qxq1g4dp
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __LIBNJB__H
 
2
#define __LIBNJB__H
 
3
 
 
4
/* Undefine if libnjb was compiled for libusb support */
 
5
#undef LIBNJB_COMPILED_FOR_LIBUSB
 
6
 
 
7
#include <sys/types.h>
 
8
#include <stdio.h>
 
9
#include <string.h>
 
10
#ifdef LIBNJB_COMPILED_FOR_LIBUSB
 
11
#include <usb.h>
 
12
#else
 
13
#include <dev/usb/usb.h>
 
14
#endif
 
15
 
 
16
#define NJB_MAX_DEVICES 0xFF
 
17
 
 
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
 
27
 
 
28
#define NJB_POWER_BATTERY       0x00
 
29
#define NJB_POWER_AC_CHARGED    0x01
 
30
#define NJB_POWER_AC_CHARGING   0x03
 
31
 
 
32
#define ID_DATA_ASCII   0
 
33
#define ID_DATA_BIN     1
 
34
 
 
35
#define NJB_CODEC_MP3   "MP3"
 
36
#define NJB_CODEC_WMA   "WMA"
 
37
#define NJB_CODEC_WAV   "WAV"
 
38
 
 
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"
 
50
 
 
51
/* Sound adjustment parameters */
 
52
 
 
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
 
64
 
 
65
/* Error codes */
 
66
 
 
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     */
 
92
 
 
93
/* Debug flags */
 
94
 
 
95
#define DD_USBCTL       1
 
96
#define DD_USBBLKLIM    2
 
97
#define DD_USBBLK       4
 
98
#define DD_SUBTRACE     8
 
99
#define DD_BSDKDEBUG    16
 
100
 
 
101
/* Unicode flags */
 
102
 
 
103
#define NJB_UC_8859     0
 
104
#define NJB_UC_UTF8     1
 
105
 
 
106
/* NJB structure definitions */
 
107
 
 
108
typedef struct {
 
109
        unsigned char id[16]; /* Move all of this into njb_t eventually */
 
110
        u_int8_t fwMajor;
 
111
        u_int8_t fwMinor;
 
112
        u_int8_t fwRel;
 
113
        u_int8_t hwMajor;
 
114
        u_int8_t hwMinor;
 
115
        u_int8_t hwRel;
 
116
        char productName[33];
 
117
        u_int8_t power;
 
118
} njbid_t;
 
119
 
 
120
typedef struct {
 
121
        unsigned char id[16];
 
122
        u_int64_t count;
 
123
} njblibctr_t;
 
124
 
 
125
#define OWNER_STRING_LENGTH     128
 
126
typedef unsigned char owner_string[OWNER_STRING_LENGTH + 1];
 
127
 
 
128
#ifndef LIBNJB_COMPILED_FOR_LIBUSB
 
129
typedef struct {
 
130
        int fd;
 
131
        char *dev;
 
132
        size_t pmax;
 
133
} njb_if_t;
 
134
#endif
 
135
 
 
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;
 
142
 
 
143
struct njb_t {
 
144
#ifdef LIBNJB_COMPILED_FOR_LIBUSB
 
145
        struct usb_device *device;
 
146
        usb_dev_handle *dev;
 
147
        int bulkep;
 
148
        int intrep;
 
149
        usb_dev_handle *ctl;            /* made protocol.c port easier */
 
150
        usb_dev_handle *bin;
 
151
        usb_dev_handle *bout;
 
152
        usb_dev_handle *iin;
 
153
        usb_dev_handle *iout;
 
154
#else
 
155
        njb_if_t ctl;
 
156
        njb_if_t bin;
 
157
        njb_if_t bout;
 
158
        njb_if_t iin;
 
159
        njb_if_t iout;
 
160
        struct usb_device_info info;
 
161
#endif
 
162
        int device_type; /* what kind of jukebox it is */
 
163
        unsigned char id[16];
 
164
        char idstring[33];
 
165
        u_int64_t libcount;
 
166
        int session_updated;
 
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;
 
172
        int updated;
 
173
        u_int32_t xfersize;
 
174
        char *tmpdir;
 
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 */
 
177
        u_int8_t fwMinor;
 
178
        u_int8_t fwRel;
 
179
};
 
180
 
 
181
/* Song/track tag definitions */
 
182
 
 
183
struct songid_frame_t {
 
184
        u_int16_t type;
 
185
        u_int16_t labelsz;
 
186
        u_int16_t datasz;
 
187
        void *label;
 
188
        void *data;
 
189
        songid_frame_t *next;
 
190
};
 
191
 
 
192
struct songid_t {
 
193
        u_int32_t trid;
 
194
        u_int16_t nframes;
 
195
        songid_frame_t *first;
 
196
        songid_frame_t *last;
 
197
        songid_frame_t *cur;
 
198
        songid_t *next; /* Used on NJB3 only */
 
199
};
 
200
 
 
201
/* Playlist definitions */
 
202
 
 
203
struct playlist_track_struct {
 
204
        u_int32_t trackid;
 
205
        struct playlist_track_struct *prev;
 
206
        struct playlist_track_struct *next;
 
207
};
 
208
 
 
209
struct playlist_struct {
 
210
        char *name;
 
211
        int _state;
 
212
#define NJB_PL_NEW              0
 
213
#define NJB_PL_UNCHANGED        1
 
214
#define NJB_PL_CHNAME           2
 
215
#define NJB_PL_CHTRACKS         3
 
216
        u_int32_t ntracks;
 
217
        u_int32_t plid;
 
218
        playlist_track_t *first;
 
219
        playlist_track_t *last;
 
220
        playlist_track_t *cur;
 
221
        playlist_t *nextpl; /* Used on NJB3 only */
 
222
};
 
223
 
 
224
/* Data file tag definitions */
 
225
 
 
226
struct datafile_struct {
 
227
        char *filename;
 
228
        u_int32_t timestamp;
 
229
        u_int32_t dfid;
 
230
        u_int32_t msdw;
 
231
        u_int32_t lsdw;
 
232
        datafile_t *nextdf;
 
233
};
 
234
 
 
235
/* EAX block definition */
 
236
 
 
237
typedef struct
 
238
{
 
239
        u_int8_t volume;
 
240
        u_int8_t volumemin;
 
241
        u_int8_t volumemax;
 
242
        int16_t muted;
 
243
        int16_t eq_status;
 
244
        int8_t bass;
 
245
        int8_t bassmin;
 
246
        int8_t bassmax;
 
247
        int8_t midrange;
 
248
        int8_t midrangemin;
 
249
        int8_t midrangemax;
 
250
        int8_t treble;
 
251
        int8_t treblemin;
 
252
        int8_t treblemax;
 
253
        u_int8_t nfreq;
 
254
        u_int8_t freqset;
 
255
        int16_t *frequencies;
 
256
        u_int8_t neffects;
 
257
        u_int8_t acteffect;
 
258
        char **effects;
 
259
        u_int8_t *effamts;
 
260
        u_int8_t nphone;
 
261
        u_int8_t actphone;
 
262
        char **phonemodes;
 
263
        u_int8_t nrear;
 
264
        u_int8_t actrear;
 
265
        char **rears;
 
266
} eax_t;
 
267
 
 
268
typedef struct
 
269
{
 
270
        int16_t year;
 
271
        int16_t month;
 
272
        int16_t day;
 
273
        int16_t weekday;
 
274
        int16_t hours;
 
275
        int16_t minutes;
 
276
        int16_t seconds;
 
277
} njb_time_t;
 
278
 
 
279
#ifdef __cplusplus
 
280
extern "C" {
 
281
#endif
 
282
 
 
283
/* NJB commands */
 
284
 
 
285
typedef int XferCallback(u_int64_t sent, u_int64_t total,
 
286
                const char* buf, unsigned len, void *data);
 
287
 
 
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);
 
339
 
 
340
/* Error functions */
 
341
 
 
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);
 
346
 
 
347
/* Song/track tag functions */
 
348
 
 
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);
 
359
 
 
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);
 
365
 
 
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)
 
377
 
 
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);
 
390
 
 
391
/* Playlist fuctions */
 
392
 
 
393
playlist_t *playlist_new (void);
 
394
void playlist_destroy (playlist_t *pl);
 
395
void playlist_addtrack (playlist_t *pl, playlist_track_t *track, 
 
396
        unsigned int pos);
 
397
#define NJB_PL_END      0
 
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);
 
406
 
 
407
playlist_track_t *playlist_track_new (u_int32_t trackid);
 
408
void playlist_track_destroy (playlist_track_t *track);
 
409
 
 
410
/* Data file tag functions */
 
411
 
 
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);
 
422
 
 
423
/* EAX functions */
 
424
 
 
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);
 
429
 
 
430
/* Time functions */
 
431
 
 
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);
 
436
 
 
437
#ifdef __cplusplus
 
438
}
 
439
#endif
 
440
 
 
441
#endif