diff --git a/Makefile b/Makefile index 2f07591..5e9cfb5 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ CFLAGS += -Wall CFLAGS += -Werror +TARGETS = hdjd aac123 explore CFLAGS += -g -all: hdjd aac123 explore +all: $(TARGETS) hdjd: LDFLAGS += $(shell pkg-config --libs libusb-1.0) hdjd: LDFLAGS += $(shell pkg-config --libs alsa) @@ -23,4 +24,4 @@ aactest: LDLIBS += $(shell pkg-config --libs alsa) aactest: LDLIBS += -lfaad -lmp4v2 clean: - rm -f hdjd *.o + rm -f $(TARGETS) *.o diff --git a/aac123.c b/aac123.c index 1da1b01..eff8f51 100644 --- a/aac123.c +++ b/aac123.c @@ -5,25 +5,13 @@ #include #include -/* Some things I use for debugging */ -#ifdef NODUMP -# define DUMPf(fmt, args...) -#else -# define DUMPf(fmt, args...) fprintf(stderr, "%s:%s:%d " fmt "\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#endif -#define DUMP() DUMPf("") -#define DUMP_d(v) DUMPf("%s = %d", #v, v) -#define DUMP_x(v) DUMPf("%s = 0x%x", #v, v) -#define DUMP_s(v) DUMPf("%s = %s", #v, v) -#define DUMP_c(v) DUMPf("%s = '%c' (0x%02x)", #v, v, v) -#define DUMP_p(v) DUMPf("%s = %p", #v, v) +#include "dump.h" static int GetAACTrack(MP4FileHandle *infile) { /* find AAC track */ - int rc; MP4TrackId numTracks = MP4GetNumberOfTracks(infile, NULL, 0); MP4TrackId i; @@ -66,10 +54,9 @@ play_file(snd_pcm_t *snd, char *fn) NeAACDecHandle hDecoder; NeAACDecConfigurationPtr config; - mp4AudioSpecificConfig mp4ASC; unsigned char *buffer; - int buffer_size; + uint32_t buffer_size; unsigned long samplerate; unsigned char channels; @@ -124,9 +111,7 @@ play_file(snd_pcm_t *snd, char *fn) DUMP_d(numSamples); for (sampleId = 1; sampleId <= numSamples; sampleId++) { int rc; - long dur; unsigned int sample_count; - unsigned int delay = 0; NeAACDecFrameInfo frameInfo; buffer = NULL; diff --git a/alsa.c b/alsa.c index 75a90d0..9d34428 100644 --- a/alsa.c +++ b/alsa.c @@ -82,6 +82,7 @@ alsa_read_ready() usb_write(buf, converted); } } + snd_midi_event_free(midi_event_parser); } void @@ -120,10 +121,10 @@ alsa_write(uint8_t *data, size_t datalen) snd_seq_ev_set_direct(&ev); snd_seq_ev_set_source(&ev, seq_port); snd_seq_ev_set_subs(&ev); - if ((r = snd_seq_event_output(snd_handle, &ev)) < 0) { + if ((r = snd_seq_event_output_direct(snd_handle, &ev)) < 0) { fprintf(stderr, "ALSA couldn't write an event: %ld\n", r); abort(); } - snd_seq_drain_output(snd_handle); + snd_midi_event_free(midi_event_parser); } \ No newline at end of file diff --git a/dump.h b/dump.h index c65dd92..9d002c8 100644 --- a/dump.h +++ b/dump.h @@ -1,11 +1,5 @@ -/* obj.h: objecty and exceptiony stuff - * - * Some macros to make C a bit more like C++, but without bringing in - * all of C++'s crapola. - */ - -#ifndef __OBJ_H__ -#define __OBJ_H__ +#ifndef __DUMP_H__ +#define __DUMP_H__ #include #include @@ -18,8 +12,8 @@ # define DUMPf(fmt, args...) fprintf(stderr, "%s:%s:%d " fmt "\n", __FILE__, __FUNCTION__, __LINE__, ##args) #endif #define DUMP() DUMPf("") -#define DUMP_d(v) DUMPf("%s = %d", #v, v) -#define DUMP_l(v) DUMPf("%s = %ld", #v, v) +#define DUMP_d(v) DUMPf("%s = %d", #v, (int)v) +#define DUMP_l(v) DUMPf("%s = %ld", #v, (long)v) #define DUMP_x(v) DUMPf("%s = 0x%x", #v, v) #define DUMP_s(v) DUMPf("%s = %s", #v, v) #define DUMP_c(v) DUMPf("%s = '%c' (0x%02x)", #v, v, v) diff --git a/usb.c b/usb.c index e41153d..2dc7f15 100644 --- a/usb.c +++ b/usb.c @@ -11,6 +11,9 @@ static struct libusb_device_handle *usb_dev; static const struct device *d; +static int writes_pending = 0; +static int reads_pending = 0; + struct device { uint16_t product_id; uint8_t ep_in; @@ -36,6 +39,8 @@ usb_initiate_transfer() struct libusb_transfer *xfer = libusb_alloc_transfer(0); libusb_fill_bulk_transfer(xfer, usb_dev, d->ep_in, buf, 256, usb_xfer_done, NULL, 0); libusb_submit_transfer(xfer); + DUMP(); + reads_pending += 1; } void @@ -43,7 +48,10 @@ usb_xfer_done(struct libusb_transfer *xfer) { uint8_t *data = xfer->buffer; int datalen = xfer->actual_length; + + reads_pending -= 1; + DUMP(); alsa_write(data, datalen); free(data); libusb_free_transfer(xfer); @@ -54,7 +62,7 @@ int usb_setup(char *name, size_t namelen) { if (libusb_init(NULL) < 0) { - return -1; + return -1; } if (libusb_pollfds_handle_timeouts(NULL) == 0) { @@ -93,6 +101,7 @@ usb_setup(char *name, size_t namelen) printf("Opened [%s]\n", name); } + usb_initiate_transfer(); return 0; } @@ -117,7 +126,10 @@ usb_fd_setup(int *nfds, fd_set *rfds, fd_set *wfds) } } - usb_initiate_transfer(); + if (reads_pending + writes_pending > 10) { + fprintf(stderr, "Warning: %d+%d = %d outstanding USB transactions!\n", reads_pending, writes_pending, reads_pending + writes_pending); + } + } void @@ -140,6 +152,7 @@ usb_check_fds(fd_set *rfds, fd_set *wfds) void usb_write_done(struct libusb_transfer *xfer) { + writes_pending -= 1; free(xfer->buffer); libusb_free_transfer(xfer); } @@ -150,6 +163,7 @@ usb_write(uint8_t *data, size_t datalen) struct libusb_transfer *xfer; unsigned char *buf; + writes_pending += 1; xfer = libusb_alloc_transfer(0); buf = (unsigned char *)malloc(datalen); memcpy(buf, data, datalen);