mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 13:07:03 +03:00
Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3
This commit is contained in:
@@ -136,7 +136,7 @@ const static actrls_t controls = {
|
|||||||
NULL, NULL, // rew, fwd
|
NULL, NULL, // rew, fwd
|
||||||
bt_prev, bt_next, // prev, next
|
bt_prev, bt_next, // prev, next
|
||||||
NULL, NULL, NULL, NULL, // left, right, up, down
|
NULL, NULL, NULL, NULL, // left, right, up, down
|
||||||
NULL, NULL, NULL, NULL, NULL, NULL, // pre1-6
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // pre1-10
|
||||||
bt_volume_down, bt_volume_up, bt_toggle// knob left, knob_right, knob push
|
bt_volume_down, bt_volume_up, bt_toggle// knob left, knob_right, knob push
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ const static actrls_t controls = {
|
|||||||
NULL, NULL, // rew, fwd
|
NULL, NULL, // rew, fwd
|
||||||
raop_prev, raop_next, // prev, next
|
raop_prev, raop_next, // prev, next
|
||||||
NULL, NULL, NULL, NULL, // left, right, up, down
|
NULL, NULL, NULL, NULL, // left, right, up, down
|
||||||
NULL, NULL, NULL, NULL, NULL, NULL, // pre1-6
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // pre1-10
|
||||||
raop_volume_down, raop_volume_up, raop_toggle// knob left, knob_right, knob push
|
raop_volume_down, raop_volume_up, raop_toggle// knob left, knob_right, knob push
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ static const actrls_config_map_t actrls_config_map[] =
|
|||||||
static const char * actrls_action_s[ ] = { EP(ACTRLS_POWER),EP(ACTRLS_VOLUP),EP(ACTRLS_VOLDOWN),EP(ACTRLS_TOGGLE),EP(ACTRLS_PLAY),
|
static const char * actrls_action_s[ ] = { EP(ACTRLS_POWER),EP(ACTRLS_VOLUP),EP(ACTRLS_VOLDOWN),EP(ACTRLS_TOGGLE),EP(ACTRLS_PLAY),
|
||||||
EP(ACTRLS_PAUSE),EP(ACTRLS_STOP),EP(ACTRLS_REW),EP(ACTRLS_FWD),EP(ACTRLS_PREV),EP(ACTRLS_NEXT),
|
EP(ACTRLS_PAUSE),EP(ACTRLS_STOP),EP(ACTRLS_REW),EP(ACTRLS_FWD),EP(ACTRLS_PREV),EP(ACTRLS_NEXT),
|
||||||
EP(BCTRLS_UP),EP(BCTRLS_DOWN),EP(BCTRLS_LEFT),EP(BCTRLS_RIGHT),
|
EP(BCTRLS_UP),EP(BCTRLS_DOWN),EP(BCTRLS_LEFT),EP(BCTRLS_RIGHT),
|
||||||
EP(BCTRLS_PS1),EP(BCTRLS_PS2),EP(BCTRLS_PS3),EP(BCTRLS_PS4),EP(BCTRLS_PS5),EP(BCTRLS_PS6),EP(BCTRLS_PS7),EP(BCTRLS_PS8),EP(BCTRLS_PS9),EP(BCTRLS_PS10),
|
EP(BCTRLS_PS0),EP(BCTRLS_PS1),EP(BCTRLS_PS2),EP(BCTRLS_PS3),EP(BCTRLS_PS4),EP(BCTRLS_PS5),EP(BCTRLS_PS6),EP(BCTRLS_PS7),EP(BCTRLS_PS8),EP(BCTRLS_PS9),
|
||||||
EP(KNOB_LEFT),EP(KNOB_RIGHT),EP(KNOB_PUSH),
|
EP(KNOB_LEFT),EP(KNOB_RIGHT),EP(KNOB_PUSH),
|
||||||
""} ;
|
""} ;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
typedef enum { ACTRLS_NONE = -1, ACTRLS_POWER,ACTRLS_VOLUP, ACTRLS_VOLDOWN, ACTRLS_TOGGLE, ACTRLS_PLAY,
|
typedef enum { ACTRLS_NONE = -1, ACTRLS_POWER,ACTRLS_VOLUP, ACTRLS_VOLDOWN, ACTRLS_TOGGLE, ACTRLS_PLAY,
|
||||||
ACTRLS_PAUSE, ACTRLS_STOP, ACTRLS_REW, ACTRLS_FWD, ACTRLS_PREV, ACTRLS_NEXT,
|
ACTRLS_PAUSE, ACTRLS_STOP, ACTRLS_REW, ACTRLS_FWD, ACTRLS_PREV, ACTRLS_NEXT,
|
||||||
BCTRLS_UP, BCTRLS_DOWN, BCTRLS_LEFT, BCTRLS_RIGHT,
|
BCTRLS_UP, BCTRLS_DOWN, BCTRLS_LEFT, BCTRLS_RIGHT,
|
||||||
BCTRLS_PS1,BCTRLS_PS2,BCTRLS_PS3,BCTRLS_PS4,BCTRLS_PS5,BCTRLS_PS6,BCTRLS_PS7,BCTRLS_PS8,BCTRLS_PS9,BCTRLS_PS10,
|
BCTRLS_PS0,BCTRLS_PS1,BCTRLS_PS2,BCTRLS_PS3,BCTRLS_PS4,BCTRLS_PS5,BCTRLS_PS6,BCTRLS_PS7,BCTRLS_PS8,BCTRLS_PS9,
|
||||||
KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
|
KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
|
||||||
ACTRLS_REMAP, ACTRLS_MAX
|
ACTRLS_REMAP, ACTRLS_MAX
|
||||||
} actrls_action_e;
|
} actrls_action_e;
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ void cspotPlayer::runTask() {
|
|||||||
CSPOT_LOG(info, "disconnecting player %s", name.c_str());
|
CSPOT_LOG(info, "disconnecting player %s", name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// we want to release memory ASAP and fore sure
|
// we want to release memory ASAP and for sure
|
||||||
centralAudioBuffer.reset();
|
centralAudioBuffer.reset();
|
||||||
ctx.reset();
|
ctx.reset();
|
||||||
token.clear();
|
token.clear();
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ const static actrls_t controls = {
|
|||||||
NULL, NULL, // rew, fwd
|
NULL, NULL, // rew, fwd
|
||||||
cspot_prev, cspot_next, // prev, next
|
cspot_prev, cspot_next, // prev, next
|
||||||
NULL, NULL, NULL, NULL, // left, right, up, down
|
NULL, NULL, NULL, NULL, // left, right, up, down
|
||||||
NULL, NULL, NULL, NULL, NULL, NULL, // pre1-6
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // pre1-10
|
||||||
cspot_volume_down, cspot_volume_up, cspot_toggle// knob left, knob_right, knob push
|
cspot_volume_down, cspot_volume_up, cspot_toggle// knob left, knob_right, knob push
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ static log_level loglevel = lINFO;
|
|||||||
enum { BUTN_POWER_FRONT = 0X0A, BUTN_ARROW_UP, BUTN_ARROW_DOWN, BUTN_ARROW_LEFT, BUTN_KNOB_PUSH, BUTN_SEARCH,
|
enum { BUTN_POWER_FRONT = 0X0A, BUTN_ARROW_UP, BUTN_ARROW_DOWN, BUTN_ARROW_LEFT, BUTN_KNOB_PUSH, BUTN_SEARCH,
|
||||||
BUTN_REW, BUTN_FWD, BUTN_PLAY, BUTN_ADD, BUTN_BRIGHTNESS, BUTN_NOW_PLAYING,
|
BUTN_REW, BUTN_FWD, BUTN_PLAY, BUTN_ADD, BUTN_BRIGHTNESS, BUTN_NOW_PLAYING,
|
||||||
BUTN_PAUSE = 0X17, BUTN_BROWSE, BUTN_VOLUP_FRONT, BUTN_VOLDOWN_FRONT, BUTN_SIZE, BUTN_VISUAL, BUTN_VOLUMEMODE,
|
BUTN_PAUSE = 0X17, BUTN_BROWSE, BUTN_VOLUP_FRONT, BUTN_VOLDOWN_FRONT, BUTN_SIZE, BUTN_VISUAL, BUTN_VOLUMEMODE,
|
||||||
BUTN_PRESET_1 = 0X23, BUTN_PRESET_2, BUTN_PRESET_3, BUTN_PRESET_4, BUTN_PRESET_5, BUTN_PRESET_6, BUTN_PRESET_7, BUTN_PRESET_8, BUTN_PRESET_9, BUTN_PRESET_10,
|
BUTN_PRESET_0 = 0x22, BUTN_PRESET_1, BUTN_PRESET_2, BUTN_PRESET_3, BUTN_PRESET_4, BUTN_PRESET_5, BUTN_PRESET_6, BUTN_PRESET_7, BUTN_PRESET_8, BUTN_PRESET_9,
|
||||||
BUTN_SNOOZE,
|
BUTN_SNOOZE,
|
||||||
BUTN_KNOB_LEFT = 0X5A, BUTN_KNOB_RIGHT };
|
BUTN_KNOB_LEFT = 0X5A, BUTN_KNOB_RIGHT };
|
||||||
|
|
||||||
@@ -143,6 +143,7 @@ LMS_CALLBACK(down, ARROW_DOWN, arrow_down)
|
|||||||
LMS_CALLBACK(left, ARROW_LEFT, arrow_left)
|
LMS_CALLBACK(left, ARROW_LEFT, arrow_left)
|
||||||
LMS_CALLBACK(right, ARROW_RIGHT, arrow_right)
|
LMS_CALLBACK(right, ARROW_RIGHT, arrow_right)
|
||||||
|
|
||||||
|
LMS_CALLBACK(pre0, PRESET_0, preset_0.single)
|
||||||
LMS_CALLBACK(pre1, PRESET_1, preset_1.single)
|
LMS_CALLBACK(pre1, PRESET_1, preset_1.single)
|
||||||
LMS_CALLBACK(pre2, PRESET_2, preset_2.single)
|
LMS_CALLBACK(pre2, PRESET_2, preset_2.single)
|
||||||
LMS_CALLBACK(pre3, PRESET_3, preset_3.single)
|
LMS_CALLBACK(pre3, PRESET_3, preset_3.single)
|
||||||
@@ -152,7 +153,6 @@ LMS_CALLBACK(pre6, PRESET_6, preset_6.single)
|
|||||||
LMS_CALLBACK(pre7, PRESET_7, preset_7.single)
|
LMS_CALLBACK(pre7, PRESET_7, preset_7.single)
|
||||||
LMS_CALLBACK(pre8, PRESET_8, preset_8.single)
|
LMS_CALLBACK(pre8, PRESET_8, preset_8.single)
|
||||||
LMS_CALLBACK(pre9, PRESET_9, preset_9.single)
|
LMS_CALLBACK(pre9, PRESET_9, preset_9.single)
|
||||||
LMS_CALLBACK(pre10, PRESET_10, preset_10.single)
|
|
||||||
|
|
||||||
LMS_CALLBACK(knob_left, KNOB_LEFT, knob_left)
|
LMS_CALLBACK(knob_left, KNOB_LEFT, knob_left)
|
||||||
LMS_CALLBACK(knob_right, KNOB_RIGHT, knob_right)
|
LMS_CALLBACK(knob_right, KNOB_RIGHT, knob_right)
|
||||||
@@ -167,7 +167,7 @@ const actrls_t LMS_controls = {
|
|||||||
lms_prev, lms_next, // prev, next
|
lms_prev, lms_next, // prev, next
|
||||||
lms_up, lms_down,
|
lms_up, lms_down,
|
||||||
lms_left, lms_right,
|
lms_left, lms_right,
|
||||||
lms_pre1, lms_pre2, lms_pre3, lms_pre4, lms_pre5, lms_pre6, lms_pre7, lms_pre8, lms_pre9, lms_pre10,
|
lms_pre0, lms_pre1, lms_pre2, lms_pre3, lms_pre4, lms_pre5, lms_pre6, lms_pre7, lms_pre8, lms_pre9,
|
||||||
lms_knob_left, lms_knob_right, lms_knob_push,
|
lms_knob_left, lms_knob_right, lms_knob_push,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -247,13 +247,17 @@ void decode_close(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void decode_flush(void) {
|
void decode_flush(bool close) {
|
||||||
LOG_INFO("decode flush");
|
LOG_INFO("decode flush");
|
||||||
LOCK_D;
|
LOCK_D;
|
||||||
decode.state = DECODE_STOPPED;
|
decode.state = DECODE_STOPPED;
|
||||||
IF_PROCESS(
|
IF_PROCESS(
|
||||||
process_flush();
|
process_flush();
|
||||||
);
|
);
|
||||||
|
if (close && codec) {
|
||||||
|
codec->close();
|
||||||
|
codec = NULL;
|
||||||
|
}
|
||||||
UNLOCK_D;
|
UNLOCK_D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,17 +44,17 @@
|
|||||||
#define MAX_OPUS_FRAMES 5760
|
#define MAX_OPUS_FRAMES 5760
|
||||||
|
|
||||||
struct opus {
|
struct opus {
|
||||||
enum {OGG_SYNC, OGG_HEADER, OGG_PCM, OGG_DECODE} status;
|
enum {OGG_SYNC, OGG_ID_HEADER, OGG_COMMENT_HEADER} status;
|
||||||
ogg_stream_state state;
|
ogg_stream_state state;
|
||||||
ogg_packet packet;
|
ogg_packet packet;
|
||||||
ogg_sync_state sync;
|
ogg_sync_state sync;
|
||||||
ogg_page page;
|
ogg_page page;
|
||||||
OpusDecoder* decoder;
|
OpusDecoder* decoder;
|
||||||
int rate, gain, pre_skip;
|
int rate, gain, pre_skip;
|
||||||
bool fetch;
|
|
||||||
size_t overframes;
|
size_t overframes;
|
||||||
u8_t *overbuf;
|
u8_t *overbuf;
|
||||||
int channels;
|
int channels;
|
||||||
|
bool eos;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !LINKALL
|
#if !LINKALL
|
||||||
@@ -102,15 +102,11 @@ extern struct processstate process;
|
|||||||
#if PROCESS
|
#if PROCESS
|
||||||
#define LOCK_O_direct if (decode.direct) mutex_lock(outputbuf->mutex)
|
#define LOCK_O_direct if (decode.direct) mutex_lock(outputbuf->mutex)
|
||||||
#define UNLOCK_O_direct if (decode.direct) mutex_unlock(outputbuf->mutex)
|
#define UNLOCK_O_direct if (decode.direct) mutex_unlock(outputbuf->mutex)
|
||||||
#define LOCK_O_not_direct if (!decode.direct) mutex_lock(outputbuf->mutex)
|
|
||||||
#define UNLOCK_O_not_direct if (!decode.direct) mutex_unlock(outputbuf->mutex)
|
|
||||||
#define IF_DIRECT(x) if (decode.direct) { x }
|
#define IF_DIRECT(x) if (decode.direct) { x }
|
||||||
#define IF_PROCESS(x) if (!decode.direct) { x }
|
#define IF_PROCESS(x) if (!decode.direct) { x }
|
||||||
#else
|
#else
|
||||||
#define LOCK_O_direct mutex_lock(outputbuf->mutex)
|
#define LOCK_O_direct mutex_lock(outputbuf->mutex)
|
||||||
#define UNLOCK_O_direct mutex_unlock(outputbuf->mutex)
|
#define UNLOCK_O_direct mutex_unlock(outputbuf->mutex)
|
||||||
#define LOCK_O_not_direct
|
|
||||||
#define UNLOCK_O_not_direct
|
|
||||||
#define IF_DIRECT(x) { x }
|
#define IF_DIRECT(x) { x }
|
||||||
#define IF_PROCESS(x)
|
#define IF_PROCESS(x)
|
||||||
#endif
|
#endif
|
||||||
@@ -163,14 +159,14 @@ static int get_opus_packet(void) {
|
|||||||
|
|
||||||
static int read_opus_header(void) {
|
static int read_opus_header(void) {
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
bool fetch = true;
|
||||||
|
|
||||||
LOCK_S;
|
LOCK_S;
|
||||||
size_t bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
|
size_t bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
|
||||||
|
|
||||||
while (bytes && !status) {
|
while (bytes && !status) {
|
||||||
|
|
||||||
// first fetch a page if we need one
|
// first fetch a page if we need one
|
||||||
if (u->fetch) {
|
if (fetch) {
|
||||||
size_t consumed = min(bytes, 4096);
|
size_t consumed = min(bytes, 4096);
|
||||||
char* buffer = OG(&gu, sync_buffer, &u->sync, consumed);
|
char* buffer = OG(&gu, sync_buffer, &u->sync, consumed);
|
||||||
memcpy(buffer, streambuf->readp, consumed);
|
memcpy(buffer, streambuf->readp, consumed);
|
||||||
@@ -180,24 +176,23 @@ static int read_opus_header(void) {
|
|||||||
bytes -= consumed;
|
bytes -= consumed;
|
||||||
|
|
||||||
if (!OG(&gu, sync_pageseek, &u->sync, &u->page)) continue;
|
if (!OG(&gu, sync_pageseek, &u->sync, &u->page)) continue;
|
||||||
u->fetch = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//bytes = min(bytes, size);
|
|
||||||
switch (u->status) {
|
switch (u->status) {
|
||||||
case OGG_SYNC:
|
case OGG_SYNC:
|
||||||
u->status = OGG_HEADER;
|
u->status = OGG_ID_HEADER;
|
||||||
OG(&gu, stream_reset_serialno, &u->state, OG(&gu, page_serialno, &u->page));
|
OG(&gu, stream_reset_serialno, &u->state, OG(&gu, page_serialno, &u->page));
|
||||||
|
fetch = false;
|
||||||
break;
|
break;
|
||||||
case OGG_HEADER:
|
case OGG_ID_HEADER:
|
||||||
status = OG(&gu, stream_pagein, &u->state, &u->page);
|
status = OG(&gu, stream_pagein, &u->state, &u->page);
|
||||||
if (OG(&gu, stream_packetout, &u->state, &u->packet)) {
|
if (OG(&gu, stream_packetout, &u->state, &u->packet)) {
|
||||||
u->status = OGG_PCM;
|
|
||||||
if (u->packet.bytes < 19 || memcmp(u->packet.packet, "OpusHead", 8)) {
|
if (u->packet.bytes < 19 || memcmp(u->packet.packet, "OpusHead", 8)) {
|
||||||
LOG_ERROR("wrong opus header packet (size:%u)", u->packet.bytes);
|
LOG_ERROR("wrong opus header packet (size:%u)", u->packet.bytes);
|
||||||
status = -100;
|
status = -100;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
u->status = OGG_COMMENT_HEADER;
|
||||||
u->channels = u->packet.packet[9];
|
u->channels = u->packet.packet[9];
|
||||||
u->pre_skip = parse_uint16(u->packet.packet + 10);
|
u->pre_skip = parse_uint16(u->packet.packet + 10);
|
||||||
u->rate = parse_uint32(u->packet.packet + 12);
|
u->rate = parse_uint32(u->packet.packet + 12);
|
||||||
@@ -207,11 +202,10 @@ static int read_opus_header(void) {
|
|||||||
LOG_ERROR("can't create decoder %d (channels:%u)", status, u->channels);
|
LOG_ERROR("can't create decoder %d (channels:%u)", status, u->channels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
u->fetch = true;
|
fetch = true;
|
||||||
break;
|
break;
|
||||||
case OGG_PCM:
|
case OGG_COMMENT_HEADER:
|
||||||
// loop until we have consumed VorbisComment and get ready for a new packet
|
// skip pakets to consume VorbisComment. With opus, header packets align on pages
|
||||||
u->fetch = true;
|
|
||||||
status = OG(&gu, page_packets, &u->page);
|
status = OG(&gu, page_packets, &u->page);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -226,7 +220,6 @@ static int read_opus_header(void) {
|
|||||||
static decode_state opus_decompress(void) {
|
static decode_state opus_decompress(void) {
|
||||||
frames_t frames;
|
frames_t frames;
|
||||||
int n;
|
int n;
|
||||||
static int channels;
|
|
||||||
u8_t *write_buf;
|
u8_t *write_buf;
|
||||||
|
|
||||||
if (decode.new_stream) {
|
if (decode.new_stream) {
|
||||||
@@ -247,7 +240,10 @@ static decode_state opus_decompress(void) {
|
|||||||
decode.new_stream = false;
|
decode.new_stream = false;
|
||||||
UNLOCK_O;
|
UNLOCK_O;
|
||||||
|
|
||||||
channels = u->channels;
|
if (u->channels > 2) {
|
||||||
|
LOG_WARN("too many channels: %d", u->channels);
|
||||||
|
return DECODE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_INFO("setting track_start");
|
LOG_INFO("setting track_start");
|
||||||
}
|
}
|
||||||
@@ -271,7 +267,7 @@ static decode_state opus_decompress(void) {
|
|||||||
u->overframes = 0;
|
u->overframes = 0;
|
||||||
} else if (get_opus_packet() > 0) {
|
} else if (get_opus_packet() > 0) {
|
||||||
if (frames < MAX_OPUS_FRAMES) {
|
if (frames < MAX_OPUS_FRAMES) {
|
||||||
// don't have enough contiguous space, use the overflow buffer (still works if n < 0)
|
// don't have enough contiguous space, use the overflow buffer
|
||||||
n = OP(&gu, decode, u->decoder, u->packet.packet, u->packet.bytes, (opus_int16*) u->overbuf, MAX_OPUS_FRAMES, 0);
|
n = OP(&gu, decode, u->decoder, u->packet.packet, u->packet.bytes, (opus_int16*) u->overbuf, MAX_OPUS_FRAMES, 0);
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
u->overframes = n - min(n, frames);
|
u->overframes = n - min(n, frames);
|
||||||
@@ -287,7 +283,7 @@ static decode_state opus_decompress(void) {
|
|||||||
} else if (!OG(&go, page_eos, &u->page)) {
|
} else if (!OG(&go, page_eos, &u->page)) {
|
||||||
UNLOCK_O_direct;
|
UNLOCK_O_direct;
|
||||||
return DECODE_RUNNING;
|
return DECODE_RUNNING;
|
||||||
}
|
} else u->eos = true;
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
frames_t count;
|
frames_t count;
|
||||||
@@ -295,7 +291,7 @@ static decode_state opus_decompress(void) {
|
|||||||
ISAMPLE_T *optr;
|
ISAMPLE_T *optr;
|
||||||
|
|
||||||
frames = n;
|
frames = n;
|
||||||
count = frames * channels;
|
count = frames * u->channels;
|
||||||
|
|
||||||
// work backward to unpack samples (if needed)
|
// work backward to unpack samples (if needed)
|
||||||
iptr = (s16_t *) write_buf + count;
|
iptr = (s16_t *) write_buf + count;
|
||||||
@@ -306,13 +302,13 @@ static decode_state opus_decompress(void) {
|
|||||||
optr = (ISAMPLE_T *) write_buf + frames * 2;
|
optr = (ISAMPLE_T *) write_buf + frames * 2;
|
||||||
)
|
)
|
||||||
|
|
||||||
if (channels == 2) {
|
if (u->channels == 2) {
|
||||||
#if BYTES_PER_FRAME == 8
|
#if BYTES_PER_FRAME == 8
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*--optr = ALIGN(*--iptr);
|
*--optr = ALIGN(*--iptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (channels == 1) {
|
} else if (u->channels == 1) {
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*--optr = ALIGN(*--iptr);
|
*--optr = ALIGN(*--iptr);
|
||||||
*--optr = ALIGN(*iptr);
|
*--optr = ALIGN(*iptr);
|
||||||
@@ -330,7 +326,7 @@ static decode_state opus_decompress(void) {
|
|||||||
|
|
||||||
} else if (n == 0) {
|
} else if (n == 0) {
|
||||||
|
|
||||||
if (stream.state <= DISCONNECT) {
|
if (stream.state <= DISCONNECT && u->eos) {
|
||||||
LOG_INFO("end of decode");
|
LOG_INFO("end of decode");
|
||||||
UNLOCK_O_direct;
|
UNLOCK_O_direct;
|
||||||
return DECODE_COMPLETE;
|
return DECODE_COMPLETE;
|
||||||
@@ -346,7 +342,6 @@ static decode_state opus_decompress(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UNLOCK_O_direct;
|
UNLOCK_O_direct;
|
||||||
|
|
||||||
return DECODE_RUNNING;
|
return DECODE_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,11 +351,12 @@ static void opus_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
|
|||||||
|
|
||||||
if (!u->overbuf) u->overbuf = malloc(MAX_OPUS_FRAMES * BYTES_PER_FRAME);
|
if (!u->overbuf) u->overbuf = malloc(MAX_OPUS_FRAMES * BYTES_PER_FRAME);
|
||||||
|
|
||||||
|
u->eos = false;
|
||||||
u->status = OGG_SYNC;
|
u->status = OGG_SYNC;
|
||||||
u->fetch = true;
|
|
||||||
u->overframes = 0;
|
u->overframes = 0;
|
||||||
|
|
||||||
OG(&gu, sync_init, &u->sync);
|
OG(&gu, sync_clear, &u->sync);
|
||||||
|
OG(&gu, stream_clear, &u->state);
|
||||||
OG(&gu, stream_init, &u->state, -1);
|
OG(&gu, stream_init, &u->state, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,11 +374,17 @@ static void opus_close(void) {
|
|||||||
static bool load_opus(void) {
|
static bool load_opus(void) {
|
||||||
#if !LINKALL
|
#if !LINKALL
|
||||||
char *err;
|
char *err;
|
||||||
void *g_handle = dlopen(LIBOGG, RTLD_NOW);
|
|
||||||
void *u.handle = dlopen(LIBOPUS, RTLD_NOW);
|
|
||||||
|
|
||||||
if (!g_handle || !u_handle) {
|
void *u.handle = dlopen(LIBOPUS, RTLD_NOW);
|
||||||
LOG_INFO("dlerror: %s", dlerror());
|
if (!u_handle) {
|
||||||
|
LOG_INFO("opus dlerror: %s", dlerror());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *g_handle = dlopen(LIBOGG, RTLD_NOW);
|
||||||
|
if (!g_handle) {
|
||||||
|
dlclose(u_handle);
|
||||||
|
LOG_INFO("ogg dlerror: %s", dlerror());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,6 +401,7 @@ static bool load_opus(void) {
|
|||||||
g_handle->ogg_stream_pagein = dlsym(g_handle->handle, "ogg_stream_pagein");
|
g_handle->ogg_stream_pagein = dlsym(g_handle->handle, "ogg_stream_pagein");
|
||||||
g_handle->ogg_stream_packetout = dlsym(g_handle->handle, "ogg_stream_packetout");
|
g_handle->ogg_stream_packetout = dlsym(g_handle->handle, "ogg_stream_packetout");
|
||||||
g_handle->ogg_page_packets = dlsym(g_handle->handle, "ogg_page_packets");
|
g_handle->ogg_page_packets = dlsym(g_handle->handle, "ogg_page_packets");
|
||||||
|
|
||||||
u_handle->opus_decoder_create = dlsym(u_handle->handle, "opus_decoder_create");
|
u_handle->opus_decoder_create = dlsym(u_handle->handle, "opus_decoder_create");
|
||||||
u_handle->opus_decoder_destroy = dlsym(u_handle->handle, "opus_decoder_destroy");
|
u_handle->opus_decoder_destroy = dlsym(u_handle->handle, "opus_decoder_destroy");
|
||||||
u_handle->opus_decode = dlsym(u_handle->handle, "opus_decode");
|
u_handle->opus_decode = dlsym(u_handle->handle, "opus_decode");
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ static void process_strm(u8_t *pkt, int len) {
|
|||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
case 'q':
|
case 'q':
|
||||||
decode_flush();
|
decode_flush(strm->command == 'q');
|
||||||
if (!output.external) output_flush();
|
if (!output.external) output_flush();
|
||||||
status.frames_played = 0;
|
status.frames_played = 0;
|
||||||
if (stream_disconnect() && strm->command == 'f') sendSTAT("STMf", 0);
|
if (stream_disconnect() && strm->command == 'f') sendSTAT("STMf", 0);
|
||||||
|
|||||||
@@ -622,7 +622,7 @@ struct codec {
|
|||||||
|
|
||||||
void decode_init(log_level level, const char *include_codecs, const char *exclude_codecs);
|
void decode_init(log_level level, const char *include_codecs, const char *exclude_codecs);
|
||||||
void decode_close(void);
|
void decode_close(void);
|
||||||
void decode_flush(void);
|
void decode_flush(bool close);
|
||||||
unsigned decode_newstream(unsigned sample_rate, unsigned supported_rates[]);
|
unsigned decode_newstream(unsigned sample_rate, unsigned supported_rates[]);
|
||||||
void codec_open(u8_t format, u8_t sample_size, u8_t sample_rate, u8_t channels, u8_t endianness);
|
void codec_open(u8_t format, u8_t sample_size, u8_t sample_rate, u8_t channels, u8_t endianness);
|
||||||
|
|
||||||
|
|||||||
@@ -21,52 +21,81 @@
|
|||||||
|
|
||||||
#include "squeezelite.h"
|
#include "squeezelite.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* with some low-end CPU, the decode call takes a fair bit of time and if the outputbuf is locked during that
|
|
||||||
* period, the output_thread (or equivalent) will be locked although there is plenty of samples available.
|
|
||||||
* Normally, with PRIO_INHERIT, that thread should increase decoder priority and get the lock quickly but it
|
|
||||||
* seems that when the streambuf has plenty of data, the decode thread grabs the CPU to much, even it the output
|
|
||||||
* thread has a higher priority. Using an interim buffer where vorbis decoder writes the output is not great from
|
|
||||||
* an efficiency (one extra memory copy) point of view, but it allows the lock to not be kept for too long
|
|
||||||
*/
|
|
||||||
#if EMBEDDED
|
|
||||||
#define FRAME_BUF 2048
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BYTES_PER_FRAME == 4
|
|
||||||
#define ALIGN(n) (n)
|
|
||||||
#else
|
|
||||||
#define ALIGN(n) (n << 16)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// automatically select between floating point (preferred) and fixed point libraries:
|
// automatically select between floating point (preferred) and fixed point libraries:
|
||||||
// NOTE: works with Tremor version here: http://svn.xiph.org/trunk/Tremor, not vorbisidec.1.0.2 currently in ubuntu
|
// NOTE: works with Tremor version here: http://svn.xiph.org/trunk/Tremor, not vorbisidec.1.0.2 currently in ubuntu
|
||||||
|
|
||||||
// we take common definations from <vorbis/vorbisfile.h> even though we can use tremor at run time
|
#include <ogg/ogg.h>
|
||||||
// tremor's OggVorbis_File struct is normally smaller so this is ok, but padding added to malloc in case it is bigger
|
|
||||||
#define OV_EXCLUDE_STATIC_CALLBACKS
|
|
||||||
|
|
||||||
#ifdef TREMOR_ONLY
|
#ifdef TREMOR_ONLY
|
||||||
#include <ivorbisfile.h>
|
#include <vorbis/ivorbiscodec.h>
|
||||||
#else
|
#else
|
||||||
#include <vorbis/vorbisfile.h>
|
#include <vorbis/codec.h>
|
||||||
|
static bool tremor = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// this is tremor packing, not mine...
|
||||||
|
static inline int32_t clip15(int32_t x) {
|
||||||
|
int ret = x;
|
||||||
|
ret -= ((x<=32767)-1)&(x-32767);
|
||||||
|
ret -= ((x>=-32768)-1)&(x+32768);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if BYTES_PER_FRAME == 4
|
||||||
|
#define ALIGN(n) clip15((n) >> 9);
|
||||||
|
#define ALIGN_FLOAT(n) ((n)*32768.0f + 0.5f)
|
||||||
|
#else
|
||||||
|
#define ALIGN(n) (clip15((n) >> 9) << 16)
|
||||||
|
#define ALIGN_FLOAT ((n)*32768.0f*65536.0f + 0.5f)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct vorbis {
|
struct vorbis {
|
||||||
OggVorbis_File *vf;
|
bool opened;
|
||||||
bool opened, end;
|
enum { OGG_SYNC, OGG_ID_HEADER, OGG_COMMENT_HEADER, OGG_SETUP_HEADER } status;
|
||||||
#if FRAME_BUF
|
struct {
|
||||||
u8_t *write_buf;
|
ogg_stream_state state;
|
||||||
#endif
|
ogg_packet packet;
|
||||||
|
ogg_sync_state sync;
|
||||||
|
ogg_page page;
|
||||||
|
};
|
||||||
|
struct {
|
||||||
|
vorbis_dsp_state decoder;
|
||||||
|
vorbis_info info;
|
||||||
|
vorbis_comment comment;
|
||||||
|
vorbis_block block;
|
||||||
|
};
|
||||||
|
int rate, channels;
|
||||||
|
uint32_t overflow;
|
||||||
|
bool eos;
|
||||||
|
};
|
||||||
|
|
||||||
#if !LINKALL
|
#if !LINKALL
|
||||||
|
static struct vorbis {
|
||||||
// vorbis symbols to be dynamically loaded - from either vorbisfile or vorbisidec (tremor) version of library
|
// vorbis symbols to be dynamically loaded - from either vorbisfile or vorbisidec (tremor) version of library
|
||||||
vorbis_info *(* ov_info)(OggVorbis_File *vf, int link);
|
vorbis_info *(* ov_info)(OggVorbis_File *vf, int link);
|
||||||
int (* ov_clear)(OggVorbis_File *vf);
|
int (* ov_clear)(OggVorbis_File *vf);
|
||||||
long (* ov_read)(OggVorbis_File *vf, char *buffer, int length, int bigendianp, int word, int sgned, int *bitstream);
|
long (* ov_read)(OggVorbis_File *vf, char *buffer, int length, int bigendianp, int word, int sgned, int *bitstream);
|
||||||
long (* ov_read_tremor)(OggVorbis_File *vf, char *buffer, int length, int *bitstream);
|
long (* ov_read_tremor)(OggVorbis_File *vf, char *buffer, int length, int *bitstream);
|
||||||
int (* ov_open_callbacks)(void *datasource, OggVorbis_File *vf, const char *initial, long ibytes, ov_callbacks callbacks);
|
int (* ov_open_callbacks)(void *datasource, OggVorbis_File *vf, const char *initial, long ibytes, ov_callbacks callbacks);
|
||||||
|
} gv;
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
void *handle;
|
||||||
|
int (*ogg_stream_init)(ogg_stream_state* os, int serialno);
|
||||||
|
int (*ogg_stream_clear)(ogg_stream_state* os);
|
||||||
|
int (*ogg_stream_reset)(ogg_stream_state* os);
|
||||||
|
int (*ogg_stream_eos)(ogg_stream_state* os);
|
||||||
|
int (*ogg_stream_reset_serialno)(ogg_stream_state* os, int serialno);
|
||||||
|
int (*ogg_sync_clear)(ogg_sync_state* oy);
|
||||||
|
void (*ogg_packet_clear)(ogg_packet* op);
|
||||||
|
char* (*ogg_sync_buffer)(ogg_sync_state* oy, long size);
|
||||||
|
int (*ogg_sync_wrote)(ogg_sync_state* oy, long bytes);
|
||||||
|
long (*ogg_sync_pageseek)(ogg_sync_state* oy, ogg_page* og);
|
||||||
|
int (*ogg_sync_pageout)(ogg_sync_state* oy, ogg_page* og);
|
||||||
|
int (*ogg_stream_pagein)(ogg_stream_state* os, ogg_page* og);
|
||||||
|
int (*ogg_stream_packetout)(ogg_stream_state* os, ogg_packet* op);
|
||||||
|
int (*ogg_page_packets)(const ogg_page* og);
|
||||||
|
} go;
|
||||||
#endif
|
#endif
|
||||||
};
|
|
||||||
|
|
||||||
static struct vorbis *v;
|
static struct vorbis *v;
|
||||||
|
|
||||||
@@ -86,183 +115,249 @@ extern struct processstate process;
|
|||||||
#if PROCESS
|
#if PROCESS
|
||||||
#define LOCK_O_direct if (decode.direct) mutex_lock(outputbuf->mutex)
|
#define LOCK_O_direct if (decode.direct) mutex_lock(outputbuf->mutex)
|
||||||
#define UNLOCK_O_direct if (decode.direct) mutex_unlock(outputbuf->mutex)
|
#define UNLOCK_O_direct if (decode.direct) mutex_unlock(outputbuf->mutex)
|
||||||
#define LOCK_O_not_direct if (!decode.direct) mutex_lock(outputbuf->mutex)
|
|
||||||
#define UNLOCK_O_not_direct if (!decode.direct) mutex_unlock(outputbuf->mutex)
|
|
||||||
#define IF_DIRECT(x) if (decode.direct) { x }
|
#define IF_DIRECT(x) if (decode.direct) { x }
|
||||||
#define IF_PROCESS(x) if (!decode.direct) { x }
|
#define IF_PROCESS(x) if (!decode.direct) { x }
|
||||||
#else
|
#else
|
||||||
#define LOCK_O_direct mutex_lock(outputbuf->mutex)
|
#define LOCK_O_direct mutex_lock(outputbuf->mutex)
|
||||||
#define UNLOCK_O_direct mutex_unlock(outputbuf->mutex)
|
#define UNLOCK_O_direct mutex_unlock(outputbuf->mutex)
|
||||||
#define LOCK_O_not_direct
|
|
||||||
#define UNLOCK_O_not_direct
|
|
||||||
#define IF_DIRECT(x) { x }
|
#define IF_DIRECT(x) { x }
|
||||||
#define IF_PROCESS(x)
|
#define IF_PROCESS(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LINKALL
|
#if LINKALL
|
||||||
#define OV(h, fn, ...) (ov_ ## fn)(__VA_ARGS__)
|
#define OV(h, fn, ...) (vorbis_ ## fn)(__VA_ARGS__)
|
||||||
#define TREMOR(h) 0
|
#define OG(h, fn, ...) (ogg_ ## fn)(__VA_ARGS__)
|
||||||
#if !WIN
|
|
||||||
extern int ov_read_tremor(); // needed to enable compilation, not linked
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
#define OV(h, fn, ...) (h)->ov_##fn(__VA_ARGS__)
|
#define OV(h, fn, ...) (h)->ov_##fn(__VA_ARGS__)
|
||||||
#define TREMOR(h) (h)->ov_read_tremor
|
#define OG(h, fn, ...) (h)->ogg_ ## fn(__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// called with mutex locked within vorbis_decode to avoid locking O before S
|
static int get_ogg_packet(void) {
|
||||||
static size_t _read_cb(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
int status = 0;
|
||||||
size_t bytes;
|
|
||||||
|
LOCK_S;
|
||||||
|
size_t bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
|
||||||
|
|
||||||
|
while (!(status = OG(&go, stream_packetout, &v->state, &v->packet)) && bytes) {
|
||||||
|
do {
|
||||||
|
size_t consumed = min(bytes, 4096);
|
||||||
|
char* buffer = OG(&gv, sync_buffer, &v->sync, consumed);
|
||||||
|
memcpy(buffer, streambuf->readp, consumed);
|
||||||
|
OG(&gv, sync_wrote, &v->sync, consumed);
|
||||||
|
|
||||||
|
_buf_inc_readp(streambuf, consumed);
|
||||||
|
bytes -= consumed;
|
||||||
|
} while (!(status = OG(&go, sync_pageseek, &v->sync, &v->page)) && bytes);
|
||||||
|
|
||||||
|
// if we have a new page, put it in
|
||||||
|
if (status) OG(&go, stream_pagein, &v->state, &v->page);
|
||||||
|
}
|
||||||
|
|
||||||
|
UNLOCK_S;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_vorbis_header(void) {
|
||||||
|
int status = 0;
|
||||||
|
bool fetch = true;
|
||||||
|
|
||||||
LOCK_S;
|
LOCK_S;
|
||||||
|
|
||||||
bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
|
size_t bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
|
||||||
bytes = min(bytes, size * nmemb);
|
|
||||||
|
|
||||||
memcpy(ptr, streambuf->readp, bytes);
|
while (bytes && !status) {
|
||||||
_buf_inc_readp(streambuf, bytes);
|
// first fetch a page if we need one
|
||||||
|
if (fetch) {
|
||||||
|
size_t consumed = min(bytes, 4096);
|
||||||
|
char* buffer = OG(&go, sync_buffer, &v->sync, consumed);
|
||||||
|
memcpy(buffer, streambuf->readp, consumed);
|
||||||
|
OG(&go, sync_wrote, &v->sync, consumed);
|
||||||
|
|
||||||
UNLOCK_S;
|
_buf_inc_readp(streambuf, consumed);
|
||||||
|
bytes -= consumed;
|
||||||
|
|
||||||
return bytes / size;
|
if (!OG(&go, sync_pageseek, &v->sync, &v->page)) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are needed for older versions of tremor, later versions and libvorbis allow NULL to be used
|
switch (v->status) {
|
||||||
static int _seek_cb(void *datasource, ogg_int64_t offset, int whence) { return -1; }
|
case OGG_SYNC:
|
||||||
static int _close_cb(void *datasource) { return 0; }
|
v->status = OGG_ID_HEADER;
|
||||||
static long _tell_cb(void *datasource) { return 0; }
|
OG(&go, stream_reset_serialno, &v->state, OG(&go, page_serialno, &v->page));
|
||||||
|
fetch = false;
|
||||||
|
break;
|
||||||
|
case OGG_ID_HEADER:
|
||||||
|
status = OG(&go, stream_pagein, &v->state, &v->page);
|
||||||
|
if (!OG(&go, stream_packetout, &v->state, &v->packet)) break;
|
||||||
|
|
||||||
|
OV(&gv, info_init, &v->info);
|
||||||
|
status = OV(&gv, synthesis_headerin, &v->info, &v->comment, &v->packet);
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
LOG_ERROR("vorbis id header packet error %d", status);
|
||||||
|
status = -1;
|
||||||
|
} else {
|
||||||
|
v->channels = v->info.channels;
|
||||||
|
v->rate = v->info.rate;
|
||||||
|
v->status = OGG_COMMENT_HEADER;
|
||||||
|
|
||||||
|
// only fetch if no other packet already in (they should not)
|
||||||
|
fetch = OG(&go, page_packets, &v->page) <= 1;
|
||||||
|
if (!fetch) LOG_INFO("id packet should terminate page");
|
||||||
|
LOG_INFO("id acquired");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OGG_SETUP_HEADER:
|
||||||
|
// header packets don't align with pages on Vorbis (contrary to Opus)
|
||||||
|
if (fetch) OG(&go, stream_pagein, &v->state, &v->page);
|
||||||
|
|
||||||
|
// finally build a codec if we have the packet
|
||||||
|
status = OG(&go, stream_packetout, &v->state, &v->packet);
|
||||||
|
if (status && ((status = OV(&gv, synthesis_headerin, &v->info, &v->comment, &v->packet)) ||
|
||||||
|
(status = OV(&gv, synthesis_init, &v->decoder, &v->info)))) {
|
||||||
|
LOG_ERROR("vorbis setup header packet error %d", status);
|
||||||
|
// no need to free comment, it's fake
|
||||||
|
OV(&gv, info_clear, &v->info);
|
||||||
|
status = -1;
|
||||||
|
} else {
|
||||||
|
OV(&gv, block_init, &v->decoder, &v->block);
|
||||||
|
v->opened = true;
|
||||||
|
LOG_INFO("codec up and running (rate: %d, channels:%d)", v->rate, v->channels);
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
//@FIXME: can we have audio on that page as well?
|
||||||
|
break;
|
||||||
|
case OGG_COMMENT_HEADER: {
|
||||||
|
// don't consume VorbisComment, just skip it
|
||||||
|
int packets = OG(&go, page_packets, &v->page);
|
||||||
|
if (packets) {
|
||||||
|
v->status = OGG_SETUP_HEADER;
|
||||||
|
OG(&go, stream_pagein, &v->state, &v->page);
|
||||||
|
OG(&go, stream_packetout, &v->state, &v->packet);
|
||||||
|
|
||||||
|
OV(&gv, comment_init, &v->comment);
|
||||||
|
v->comment.vendor = "N/A";
|
||||||
|
|
||||||
|
// because of lack of page alignment, we might have the setup page already fully in
|
||||||
|
if (packets > 1) fetch = false;
|
||||||
|
LOG_INFO("comment skipped succesfully");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UNLOCK_S;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int pcm_out(vorbis_dsp_state* decoder, void*** pcm) {
|
||||||
|
#ifndef TREMOR_ONLY
|
||||||
|
if (!tremor) return OV(&gv, synthesis_pcmout, decoder, (ogg_float_t***) pcm);
|
||||||
|
#endif
|
||||||
|
return OV(&gv, synthesis_pcmout, decoder, (ogg_int32_t***) pcm);
|
||||||
|
}
|
||||||
|
|
||||||
static decode_state vorbis_decode(void) {
|
static decode_state vorbis_decode(void) {
|
||||||
static int channels;
|
|
||||||
frames_t frames;
|
frames_t frames;
|
||||||
int bytes, s, n;
|
int n = 0;
|
||||||
u8_t *write_buf;
|
u8_t *write_buf;
|
||||||
|
void** pcm = NULL;
|
||||||
LOCK_S;
|
|
||||||
|
|
||||||
if (stream.state <= DISCONNECT && v->end) {
|
|
||||||
UNLOCK_S;
|
|
||||||
return DECODE_COMPLETE;
|
|
||||||
}
|
|
||||||
|
|
||||||
UNLOCK_S;
|
|
||||||
|
|
||||||
if (decode.new_stream) {
|
if (decode.new_stream) {
|
||||||
ov_callbacks cbs;
|
int status = read_vorbis_header();
|
||||||
int err;
|
|
||||||
struct vorbis_info *info;
|
|
||||||
|
|
||||||
cbs.read_func = _read_cb;
|
if (status == 0) {
|
||||||
|
return DECODE_RUNNING;
|
||||||
if (TREMOR(v)) {
|
} else if (status < 0) {
|
||||||
cbs.seek_func = _seek_cb; cbs.close_func = _close_cb; cbs.tell_func = _tell_cb;
|
LOG_WARN("can't create codec");
|
||||||
} else {
|
return DECODE_ERROR;
|
||||||
cbs.seek_func = NULL; cbs.close_func = NULL; cbs.tell_func = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = OV(v, open_callbacks, streambuf, v->vf, NULL, 0, cbs)) < 0) {
|
|
||||||
LOG_WARN("open_callbacks error: %d", err);
|
|
||||||
return DECODE_COMPLETE;
|
|
||||||
}
|
|
||||||
|
|
||||||
v->opened = true;
|
|
||||||
info = OV(v, info, v->vf, -1);
|
|
||||||
|
|
||||||
LOG_INFO("setting track_start");
|
|
||||||
LOCK_O;
|
LOCK_O;
|
||||||
output.next_sample_rate = decode_newstream(info->rate, output.supported_rates);
|
output.next_sample_rate = decode_newstream(v->rate, output.supported_rates);
|
||||||
IF_DSD( output.next_fmt = PCM; )
|
IF_DSD( output.next_fmt = PCM; )
|
||||||
output.track_start = outputbuf->writep;
|
output.track_start = outputbuf->writep;
|
||||||
if (output.fade_mode) _checkfade(true);
|
if (output.fade_mode) _checkfade(true);
|
||||||
decode.new_stream = false;
|
decode.new_stream = false;
|
||||||
UNLOCK_O;
|
UNLOCK_O;
|
||||||
|
|
||||||
channels = info->channels;
|
if (v->channels > 2) {
|
||||||
|
LOG_WARN("too many channels: %d", v->channels);
|
||||||
if (channels > 2) {
|
|
||||||
LOG_WARN("too many channels: %d", channels);
|
|
||||||
return DECODE_ERROR;
|
return DECODE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_INFO("setting track_start");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FRAME_BUF
|
|
||||||
IF_DIRECT(
|
|
||||||
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
|
||||||
frames = min(frames, FRAME_BUF);
|
|
||||||
write_buf = v->write_buf;
|
|
||||||
);
|
|
||||||
#else
|
|
||||||
LOCK_O_direct;
|
LOCK_O_direct;
|
||||||
IF_DIRECT(
|
IF_DIRECT(
|
||||||
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
||||||
write_buf = outputbuf->writep;
|
write_buf = outputbuf->writep;
|
||||||
);
|
);
|
||||||
#endif
|
|
||||||
IF_PROCESS(
|
IF_PROCESS(
|
||||||
frames = process.max_in_frames;
|
frames = process.max_in_frames;
|
||||||
write_buf = process.inbuf;
|
write_buf = process.inbuf;
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes = frames * 2 * channels; // samples returned are 16 bits
|
if (v->overflow) {
|
||||||
v->end = frames == 0;
|
n = pcm_out(&v->decoder, &pcm);
|
||||||
|
v->overflow = n - min(n, frames);
|
||||||
// write the decoded frames into outputbuf even though they are 16 bits per sample, then unpack them
|
} else if (get_ogg_packet() > 0) {
|
||||||
#ifdef TREMOR_ONLY
|
n = OV(&gv, synthesis, &v->block, &v->packet);
|
||||||
n = OV(v, read, v->vf, (char *)write_buf, bytes, &s);
|
if (n == 0) n = OV(&gv, synthesis_blockin, &v->decoder, &v->block);
|
||||||
#else
|
if (n == 0) n = pcm_out(&v->decoder, &pcm);
|
||||||
if (!TREMOR(v)) {
|
v->overflow = n - min(n, frames);
|
||||||
#if SL_LITTLE_ENDIAN
|
} else if (!OG(&go, page_eos, &v->page)) {
|
||||||
n = OV(v, read, v->vf, (char *)write_buf, bytes, 0, 2, 1, &s);
|
UNLOCK_O_direct;
|
||||||
#else
|
return DECODE_RUNNING;
|
||||||
n = OV(v, read, v->vf, (char *)write_buf, bytes, 1, 2, 1, &s);
|
} else v->eos = true;
|
||||||
#endif
|
|
||||||
#if !WIN
|
|
||||||
} else {
|
|
||||||
n = OV(v, read_tremor, v->vf, (char *)write_buf, bytes, &s);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if FRAME_BUF
|
|
||||||
LOCK_O_direct;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
frames_t count;
|
ISAMPLE_T *optr = (ISAMPLE_T*) write_buf;
|
||||||
s16_t *iptr;
|
frames = min(n, frames);
|
||||||
ISAMPLE_T *optr;
|
frames_t count = frames;
|
||||||
|
|
||||||
frames = n / 2 / channels;
|
#ifndef TREMOR_ONLY
|
||||||
count = frames * channels;
|
if (!tremor) {
|
||||||
|
if (v->channels == 2) {
|
||||||
|
float* iptr_l = (float*) pcm[0];
|
||||||
|
float* iptr_r = (float*) pcm[1];
|
||||||
|
|
||||||
// work backward to unpack samples (if needed)
|
while (count--) {
|
||||||
iptr = (s16_t *) write_buf + count;
|
*optr++ = ALIGN_FLOAT(*iptr_l++);
|
||||||
IF_DIRECT(
|
*optr++ = ALIGN_FLOAT(*iptr_r++);;
|
||||||
optr = (ISAMPLE_T *) outputbuf->writep + frames * 2;
|
}
|
||||||
)
|
} else if (v->channels == 1) {
|
||||||
IF_PROCESS(
|
float* iptr = pcm[0];
|
||||||
optr = (ISAMPLE_T *) write_buf + frames * 2;
|
while (count--) {
|
||||||
)
|
*optr++ = ALIGN_FLOAT(*iptr);
|
||||||
|
*optr++ = ALIGN_FLOAT(*iptr++);
|
||||||
if (channels == 2) {
|
}
|
||||||
#if BYTES_PER_FRAME == 4
|
}
|
||||||
#if FRAME_BUF
|
} else
|
||||||
// copy needed only when DIRECT and FRAME_BUF
|
|
||||||
IF_DIRECT(
|
|
||||||
memcpy(outputbuf->writep, write_buf, frames * BYTES_PER_FRAME);
|
|
||||||
)
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
|
{
|
||||||
|
if (v->channels == 2) {
|
||||||
|
s32_t* iptr_l = (s32_t*) pcm[0];
|
||||||
|
s32_t* iptr_r = (s32_t*) pcm[1];
|
||||||
|
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*--optr = ALIGN(*--iptr);
|
*optr++ = ALIGN(*iptr_l++);
|
||||||
|
*optr++ = ALIGN(*iptr_r++);
|
||||||
|
}
|
||||||
|
} else if (v->channels == 1) {
|
||||||
|
s32_t* iptr = (s32_t*) pcm[0];
|
||||||
|
while (count--) {
|
||||||
|
*optr++ = ALIGN(*iptr);
|
||||||
|
*optr++ = ALIGN(*iptr++);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (channels == 1) {
|
// return samples to vorbis/tremor decoder
|
||||||
while (count--) {
|
OV(&gv, synthesis_read, &v->decoder, frames);
|
||||||
*--optr = ALIGN(*--iptr);
|
|
||||||
*--optr = ALIGN(*iptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IF_DIRECT(
|
IF_DIRECT(
|
||||||
_buf_inc_writep(outputbuf, frames * BYTES_PER_FRAME);
|
_buf_inc_writep(outputbuf, frames * BYTES_PER_FRAME);
|
||||||
@@ -275,19 +370,14 @@ static decode_state vorbis_decode(void) {
|
|||||||
|
|
||||||
} else if (n == 0) {
|
} else if (n == 0) {
|
||||||
|
|
||||||
if (stream.state <= DISCONNECT) {
|
if (stream.state <= DISCONNECT && v->eos) {
|
||||||
LOG_INFO("partial decode");
|
LOG_INFO("end of decode");
|
||||||
UNLOCK_O_direct;
|
UNLOCK_O_direct;
|
||||||
return DECODE_COMPLETE;
|
return DECODE_COMPLETE;
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("no frame decoded");
|
LOG_INFO("no frame decoded");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (n == OV_HOLE) {
|
|
||||||
|
|
||||||
// recoverable hole in stream, seen when skipping
|
|
||||||
LOG_DEBUG("hole in stream");
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
LOG_INFO("ov_read error: %d", n);
|
LOG_INFO("ov_read error: %d", n);
|
||||||
@@ -300,55 +390,81 @@ static decode_state vorbis_decode(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void vorbis_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
|
static void vorbis_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
|
||||||
if (!v->vf) {
|
LOG_INFO("OPENING CODEC");
|
||||||
v->vf = malloc(sizeof(OggVorbis_File) + 128); // add some padding as struct size may be larger
|
|
||||||
memset(v->vf, 0, sizeof(OggVorbis_File) + 128);
|
|
||||||
#if FRAME_BUF
|
|
||||||
v->write_buf = malloc(FRAME_BUF * BYTES_PER_FRAME);
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
if (v->opened) {
|
if (v->opened) {
|
||||||
OV(v, clear, v->vf);
|
OV(&go, block_clear, &v->block);
|
||||||
v->opened = false;
|
OV(&go, info_clear, &v->info);
|
||||||
}
|
OV(&go, dsp_clear, &v->decoder);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vorbis_close(void) {
|
v->eos = false;
|
||||||
if (v->opened) {
|
|
||||||
OV(v, clear, v->vf);
|
|
||||||
v->opened = false;
|
v->opened = false;
|
||||||
|
v->status = OGG_SYNC;
|
||||||
|
v->overflow = 0;
|
||||||
|
|
||||||
|
OG(&gu, sync_clear, &v->sync);
|
||||||
|
OG(&gu, stream_clear, &v->state);
|
||||||
|
OG(&gu, stream_init, &v->state, -1);
|
||||||
}
|
}
|
||||||
free(v->vf);
|
|
||||||
#if FRAME_BUF
|
static void vorbis_close() {
|
||||||
free(v->write_buf);
|
return;
|
||||||
v->write_buf = NULL;
|
LOG_INFO("CLOSING CODEC");
|
||||||
#endif
|
if (v->opened) {
|
||||||
v->vf = NULL;
|
OV(&go, block_clear, &v->block);
|
||||||
v->end = false;
|
OV(&go, info_clear, &v->info);
|
||||||
|
OV(&go, dsp_clear, &v->decoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
v->opened = false;
|
||||||
|
|
||||||
|
OG(&go, stream_clear, &v->state);
|
||||||
|
OG(&go, sync_clear, &v->sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool load_vorbis() {
|
static bool load_vorbis() {
|
||||||
#if !LINKALL
|
#if !LINKALL
|
||||||
void *handle = dlopen(LIBVORBIS, RTLD_NOW);
|
|
||||||
char *err;
|
char *err;
|
||||||
bool tremor = false;
|
|
||||||
|
|
||||||
if (!handle) {
|
void *g_handle = dlopen(LIBOGG, RTLD_NOW);
|
||||||
handle = dlopen(LIBTREMOR, RTLD_NOW);
|
if (!g_handle) {
|
||||||
if (handle) {
|
LOG_INFO("ogg dlerror: %s", dlerror());
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
void *v_handle = NULL;
|
||||||
|
#ifndef TREMOR_ONLY
|
||||||
|
v_handle = dlopen(LIBVORBIS, RTLD_NOW);
|
||||||
|
#endif
|
||||||
|
if (!v_handle) {
|
||||||
|
v_handle = dlopen(LIBTREMOR, RTLD_NOW);
|
||||||
|
if (v_handle) {
|
||||||
tremor = true;
|
tremor = true;
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("dlerror: %s", dlerror());
|
dlclose(g_handle);
|
||||||
|
LOG_INFO("vorbis/tremor dlerror: %s", dlerror());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v->ov_read = tremor ? NULL : dlsym(handle, "ov_read");
|
g_handle->ogg_stream_clear = dlsym(g_handle->handle, "ogg_stream_clear");
|
||||||
v->ov_read_tremor = tremor ? dlsym(handle, "ov_read") : NULL;
|
g_handle->ogg_stream_reset = dlsym(g_handle->handle, "ogg_stream_reset");
|
||||||
v->ov_info = dlsym(handle, "ov_info");
|
g_handle->ogg_stream_eos = dlsym(g_handle->handle, "ogg_stream_eos");
|
||||||
v->ov_clear = dlsym(handle, "ov_clear");
|
g_handle->ogg_stream_reset_serialno = dlsym(g_handle->handle, "ogg_stream_reset_serialno");
|
||||||
v->ov_open_callbacks = dlsym(handle, "ov_open_callbacks");
|
g_handle->ogg_sync_clear = dlsym(g_handle->handle, "ogg_sync_clear");
|
||||||
|
g_handle->ogg_packet_clear = dlsym(g_handle->handle, "ogg_packet_clear");
|
||||||
|
g_handle->ogg_sync_buffer = dlsym(g_handle->handle, "ogg_sync_buffer");
|
||||||
|
g_handle->ogg_sync_wrote = dlsym(g_handle->handle, "ogg_sync_wrote");
|
||||||
|
g_handle->ogg_sync_pageseek = dlsym(g_handle->handle, "ogg_sync_pageseek");
|
||||||
|
g_handle->ogg_sync_pageout = dlsym(g_handle->handle, "ogg_sync_pageout");
|
||||||
|
g_handle->ogg_stream_pagein = dlsym(g_handle->handle, "ogg_stream_pagein");
|
||||||
|
g_handle->ogg_stream_packetout = dlsym(g_handle->handle, "ogg_stream_packetout");
|
||||||
|
g_handle->ogg_page_packets = dlsym(g_handle->handle, "ogg_page_packets");
|
||||||
|
|
||||||
|
v_handle.ov_read = dlsym(handle, "ov_read");
|
||||||
|
v_handle.ov_info = dlsym(handle, "ov_info");
|
||||||
|
v_handle.ov_clear = dlsym(handle, "ov_clear");
|
||||||
|
v_handle.ov_open_callbacks = dlsym(handle, "ov_open_callbacks");
|
||||||
|
|
||||||
if ((err = dlerror()) != NULL) {
|
if ((err = dlerror()) != NULL) {
|
||||||
LOG_INFO("dlerror: %s", err);
|
LOG_INFO("dlerror: %s", err);
|
||||||
@@ -372,12 +488,10 @@ struct codec *register_vorbis(void) {
|
|||||||
vorbis_decode,// decode
|
vorbis_decode,// decode
|
||||||
};
|
};
|
||||||
|
|
||||||
v = malloc(sizeof(struct vorbis));
|
if ((v = calloc(1, sizeof(struct vorbis))) == NULL) {
|
||||||
if (!v) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
v->vf = NULL;
|
|
||||||
v->opened = false;
|
v->opened = false;
|
||||||
|
|
||||||
if (!load_vorbis()) {
|
if (!load_vorbis()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user