[input/xcode] Write to input buffer with the sources native sample rate/format

Still WIP at this point since the player and output can't use the use improved
quality yet, and because rtptimes etc. are likely incorrect
This commit is contained in:
ejurgensen
2019-01-11 19:34:36 +01:00
parent 84e813038b
commit 9182597605
8 changed files with 146 additions and 61 deletions

View File

@@ -26,12 +26,13 @@
#include "transcode.h"
#include "http.h"
#include "misc.h"
#include "logger.h"
#include "input.h"
static int
setup(struct player_source *ps)
{
ps->input_ctx = transcode_setup(XCODE_PCM16_NOHEADER, ps->data_kind, ps->path, ps->len_ms, NULL);
ps->input_ctx = transcode_setup(XCODE_PCM_NATIVE, ps->data_kind, ps->path, ps->len_ms, NULL);
if (!ps->input_ctx)
return -1;
@@ -57,27 +58,33 @@ setup_http(struct player_source *ps)
static int
start(struct player_source *ps)
{
struct transcode_ctx *ctx = ps->input_ctx;
struct evbuffer *evbuf;
short flags;
int sample_rate;
int bps;
int ret;
int icy_timer;
evbuf = evbuffer_new();
sample_rate = transcode_encode_query(ctx->encode_ctx, "sample_rate");
bps = transcode_encode_query(ctx->encode_ctx, "bits_per_sample");
ret = -1;
flags = 0;
while (!input_loop_break && !(flags & INPUT_FLAG_EOF))
{
// We set "wanted" to 1 because the read size doesn't matter to us
// TODO optimize?
ret = transcode(evbuf, &icy_timer, ps->input_ctx, 1);
ret = transcode(evbuf, &icy_timer, ctx, 1);
if (ret < 0)
break;
flags = ((ret == 0) ? INPUT_FLAG_EOF : 0) |
(icy_timer ? INPUT_FLAG_METADATA : 0);
ret = input_write(evbuf, flags);
ret = input_write(evbuf, sample_rate, bps, flags);
if (ret < 0)
break;
}

View File

@@ -103,6 +103,9 @@ static pthread_t tid_pipe;
static struct event_base *evbase_pipe;
static struct commands_base *cmdbase;
// From config - the sample rate and bps of the pipe input
static int pipe_sample_rate;
static int pipe_bits_per_sample;
// From config - should we watch library pipes for data or only start on request
static int pipe_autostart;
// The mfi id of the pipe autostarted by the pipe thread
@@ -307,7 +310,7 @@ parse_progress(struct input_metadata *m, char *progress)
m->rtptime = start; // Not actually used - we have our own rtptime
m->offset = (pos > start) ? (pos - start) : 0;
m->song_length = (end - start) * 10 / 441; // Convert to ms based on 44100
m->song_length = (end - start) * 1000 / pipe_sample_rate;
}
static void
@@ -845,7 +848,7 @@ start(struct player_source *ps)
ret = evbuffer_read(evbuf, pipe->fd, PIPE_READ_MAX);
if ((ret == 0) && (pipe->is_autostarted))
{
input_write(evbuf, INPUT_FLAG_EOF); // Autostop
input_write(evbuf, pipe_sample_rate, pipe_bits_per_sample, INPUT_FLAG_EOF); // Autostop
break;
}
else if ((ret == 0) || ((ret < 0) && (errno == EAGAIN)))
@@ -862,7 +865,7 @@ start(struct player_source *ps)
flags = (pipe_metadata_is_new ? INPUT_FLAG_METADATA : 0);
pipe_metadata_is_new = 0;
ret = input_write(evbuf, flags);
ret = input_write(evbuf, pipe_sample_rate, pipe_bits_per_sample, flags);
if (ret < 0)
break;
}
@@ -945,6 +948,20 @@ init(void)
CHECK_ERR(L_PLAYER, listener_add(pipe_listener_cb, LISTENER_DATABASE));
}
pipe_sample_rate = cfg_getint(cfg_getsec(cfg, "library"), "pipe_sample_rate");
if (pipe_sample_rate != 44100 || pipe_sample_rate != 48000 || pipe_sample_rate != 96000)
{
DPRINTF(E_FATAL, L_PLAYER, "The configuration of pipe_sample_rate is invalid: %d\n", pipe_sample_rate);
return -1;
}
pipe_bits_per_sample = cfg_getint(cfg_getsec(cfg, "library"), "pipe_bits_per_sample");
if (pipe_bits_per_sample != 16 || pipe_bits_per_sample != 24)
{
DPRINTF(E_FATAL, L_PLAYER, "The configuration of pipe_bits_per_sample is invalid: %d\n", pipe_bits_per_sample);
return -1;
}
return 0;
}