Commit c4d34b41 authored by Mans Rullgard's avatar Mans Rullgard

mqadec: detect bluos api version

parent d44e5a57
......@@ -26,6 +26,7 @@ struct ssc_decode *ssc_decode_open(int *channels, int *rate1,
int *fd, void **cb_data, int options,
const char *device);
int ssc_decode_read(struct ssc_decode *);
const char *ssc_decode_device(struct ssc_decode *);
const char *ssc_decode_status(struct ssc_decode *);
void ssc_decode_close(struct ssc_decode *);
......
......@@ -35,6 +35,8 @@
#define BUF_SIZE 4096
static int bluos_api;
static SNDFILE *infile;
static SF_INFO infmt;
static uint8_t buf[BUF_SIZE];
......@@ -85,7 +87,10 @@ static int get_samples(int frame_size, uint8_t **samples, int eof, int *end)
*samples = &buf[buf_pos];
return size / frame_size;
if (bluos_api > 0)
size /= frame_size;
return size;
}
static void consume(int len)
......@@ -97,8 +102,12 @@ static void consume(int len)
static size_t write_samples(void *p, void *buf, size_t len)
{
int32_t *s = buf;
size_t ret;
int i;
if (bluos_api < 1)
len /= 8;
samples_out += len;
if (!outfile) {
......@@ -120,17 +129,23 @@ static size_t write_samples(void *p, void *buf, size_t len)
for (i = 0; i < len * 2; i++)
s[i] <<= 8;
return sf_writef_int(outfile, s, len);
ret = sf_writef_int(outfile, s, len);
if (bluos_api < 1)
ret *= 8;
return ret;
}
static int write_size(void *p)
{
return BUF_SIZE;
return bluos_api < 1 ? BUF_SIZE * 8 : BUF_SIZE;
}
int main(int argc, char **argv)
{
struct ssc_decode *sscd;
const char *dev;
int dummy = 0;
int channels = 2;
int rate1 = 0;
......@@ -138,6 +153,7 @@ int main(int argc, char **argv)
int bits = 32;
int options = 0;
int mqa = 0;
int nc = 0;
int opt;
while ((opt = getopt(argc, argv, "o:r:")) != -1) {
......@@ -180,6 +196,22 @@ int main(int argc, char **argv)
return 1;
}
dev = ssc_decode_device(sscd);
while ((dev = strchr(dev, ','))) {
dev++;
nc++;
}
if (nc == 2) {
bluos_api = 0;
} else if (nc == 3) {
bluos_api = 1;
} else {
fprintf(stderr, "warning: unknown libbluos_ssc version\n");
bluos_api = 1;
}
while (ssc_decode_read(sscd) > 0) {
if (!mqa) {
const char *s = ssc_decode_status(sscd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment