[httpd/cache] Misc fixing up

This commit is contained in:
ejurgensen 2024-01-14 21:38:04 +01:00
parent 2d9200fcdf
commit 088c393dd6
5 changed files with 33 additions and 19 deletions

View File

@ -859,7 +859,7 @@ cache_daap_update_cb(int fd, short what, void *arg)
static enum command_state
xcode_header_get(void *arg, int *retval)
{
#define Q_TMPL "SELECT header FROM data WHERE length(header) > 0 AND id = ? AND format = ?;"
#define Q_TMPL "SELECT header FROM data WHERE length(header) > 0 AND file_id = ? AND format = ?;"
struct cache_arg *cmdarg = arg;
sqlite3_stmt *stmt = NULL;
int ret;
@ -915,10 +915,13 @@ xcode_toggle(void *arg, int *retval)
{
bool *enable = arg;
cache_xcode_is_enabled = *enable;
if (*enable == cache_xcode_is_enabled)
goto end;
cache_xcode_is_enabled = *enable;
xcode_trigger();
end:
*retval = 0;
return COMMAND_END;
}

View File

@ -925,7 +925,7 @@ speaker_update_handler_cb(void *arg)
const char *prefer_format = cfg_getstr(cfg_getsec(cfg, "library"), "prefer_format");
bool want_mp4;
want_mp4 = (prefer_format && strcmp(prefer_format, "alac"));
want_mp4 = (prefer_format && (strcmp(prefer_format, "alac") == 0));
if (!want_mp4)
player_speaker_enumerate(speaker_enum_cb, &want_mp4);
@ -1009,6 +1009,7 @@ httpd_stream_file(struct httpd_request *hreq, int id)
struct media_file_info *mfi = NULL;
struct stream_ctx *st = NULL;
enum transcode_profile profile;
enum transcode_profile spk_profile;
const char *param;
const char *param_end;
const char *ctype;
@ -1069,7 +1070,7 @@ httpd_stream_file(struct httpd_request *hreq, int id)
}
param = httpd_header_find(hreq->in_headers, "Accept-Codecs");
profile = httpd_xcode_profile_get(hreq->user_agent, hreq->peer_address, param, mfi->codectype);
profile = transcode_needed(hreq->user_agent, param, mfi->codectype);
if (profile == XCODE_UNKNOWN)
{
DPRINTF(E_LOG, L_HTTPD, "Could not serve '%s' to client, unable to determine output format\n", mfi->path);
@ -1082,6 +1083,10 @@ httpd_stream_file(struct httpd_request *hreq, int id)
{
DPRINTF(E_INFO, L_HTTPD, "Preparing to transcode %s\n", mfi->path);
spk_profile = httpd_xcode_profile_get(hreq);
if (spk_profile != XCODE_NONE)
profile = spk_profile;
st = stream_new_transcode(mfi, profile, hreq, offset, end_offset, stream_chunk_xcode_cb);
if (!st)
goto error;
@ -1191,23 +1196,18 @@ httpd_stream_file(struct httpd_request *hreq, int id)
// Returns enum transcode_profile, but is just declared with int so we don't
// need to include transcode.h in httpd_internal.h
int
httpd_xcode_profile_get(const char *user_agent, const char *address, const char *accept_codecs, const char *codec)
httpd_xcode_profile_get(struct httpd_request *hreq)
{
enum transcode_profile profile;
struct player_speaker_info spk;
int ret;
profile = transcode_needed(user_agent, accept_codecs, codec);
if (profile == XCODE_NONE)
return profile;
DPRINTF(E_DBG, L_HTTPD, "Checking if client '%s' is a speaker\n", address);
DPRINTF(E_DBG, L_HTTPD, "Checking if client '%s' is a speaker\n", hreq->peer_address);
// A Roku Soundbridge may also be RCP device/speaker for which the user may
// have set a prefered streaming format
ret = player_speaker_get_byaddress(&spk, address);
ret = player_speaker_get_byaddress(&spk, hreq->peer_address);
if (ret < 0)
return profile;
return XCODE_NONE;
if (spk.format == MEDIA_FORMAT_WAV)
return XCODE_WAV;
@ -1216,7 +1216,7 @@ httpd_xcode_profile_get(const char *user_agent, const char *address, const char
if (spk.format == MEDIA_FORMAT_ALAC)
return XCODE_MP4_ALAC;
return profile;
return XCODE_NONE;
}
struct evbuffer *

View File

@ -1149,6 +1149,7 @@ daap_reply_songlist_generic(struct httpd_request *hreq, int playlist)
const char *accept_codecs;
const char *tag;
size_t len;
enum transcode_profile spk_profile;
enum transcode_profile profile;
struct transcode_metadata_string xcode_metadata;
struct media_quality quality = { 0 };
@ -1222,6 +1223,8 @@ daap_reply_songlist_generic(struct httpd_request *hreq, int playlist)
accept_codecs = httpd_header_find(hreq->in_headers, "Accept-Codecs");
}
spk_profile = httpd_xcode_profile_get(hreq);
nsongs = 0;
while ((ret = db_query_fetch_file(&dbmfi, &qp)) == 0)
{
@ -1229,13 +1232,16 @@ daap_reply_songlist_generic(struct httpd_request *hreq, int playlist)
// Not sure if the is_remote path is really needed. Note that if you
// change the below you might need to do the same in rsp_reply_playlist()
profile = s->is_remote ? XCODE_WAV : httpd_xcode_profile_get(hreq->user_agent, hreq->peer_address, accept_codecs, dbmfi.codectype);
profile = s->is_remote ? XCODE_WAV : transcode_needed(hreq->user_agent, accept_codecs, dbmfi.codectype);
if (profile == XCODE_UNKNOWN)
{
DPRINTF(E_LOG, L_DAAP, "Cannot transcode '%s', codec type is unknown\n", dbmfi.fname);
}
else if (profile != XCODE_NONE)
{
if (spk_profile != XCODE_NONE)
profile = spk_profile;
if (safe_atou32(dbmfi.song_length, &len_ms) < 0)
len_ms = 3 * 60 * 1000; // just a fallback default

View File

@ -207,7 +207,7 @@ void
httpd_stream_file(struct httpd_request *hreq, int id);
int
httpd_xcode_profile_get(const char *user_agent, const char *address, const char *accept_codecs, const char *codec);
httpd_xcode_profile_get(struct httpd_request *hreq);
void
httpd_request_handler_set(struct httpd_request *hreq);

View File

@ -415,7 +415,7 @@ rsp_reply_db(struct httpd_request *hreq)
}
static int
item_add(xml_node *parent, struct query_params *qp, const char *user_agent, const char *address, const char *accept_codecs, int mode)
item_add(xml_node *parent, struct query_params *qp, enum transcode_profile spk_profile, const char *user_agent, const char *accept_codecs, int mode)
{
struct media_quality quality = { 0 };
struct db_media_file_info dbmfi;
@ -432,13 +432,16 @@ item_add(xml_node *parent, struct query_params *qp, const char *user_agent, cons
if (ret != 0)
return ret;
profile = httpd_xcode_profile_get(user_agent, address, accept_codecs, dbmfi.codectype);
profile = transcode_needed(user_agent, accept_codecs, dbmfi.codectype);
if (profile == XCODE_UNKNOWN)
{
DPRINTF(E_LOG, L_DAAP, "Cannot transcode '%s', codec type is unknown\n", dbmfi.fname);
}
else if (profile != XCODE_NONE)
{
if (spk_profile != XCODE_NONE)
profile = spk_profile; // User has configured a specific transcode format for this speaker
orgcodec = dbmfi.codectype;
if (safe_atou32(dbmfi.song_length, &len_ms) < 0)
@ -485,6 +488,7 @@ rsp_reply_playlist(struct httpd_request *hreq)
struct query_params qp;
const char *param;
const char *accept_codecs;
enum transcode_profile spk_profile;
xml_node *response;
xml_node *items;
int mode;
@ -494,6 +498,7 @@ rsp_reply_playlist(struct httpd_request *hreq)
memset(&qp, 0, sizeof(struct query_params));
accept_codecs = httpd_header_find(hreq->in_headers, "Accept-Codecs");
spk_profile = httpd_xcode_profile_get(hreq);
ret = safe_atoi32(hreq->path_parts[2], &qp.id);
if (ret < 0)
@ -555,7 +560,7 @@ rsp_reply_playlist(struct httpd_request *hreq)
items = xml_new_node(response, "items", NULL);
do
{
ret = item_add(items, &qp, hreq->user_agent, hreq->peer_address, accept_codecs, mode);
ret = item_add(items, &qp, spk_profile, hreq->user_agent, accept_codecs, mode);
}
while (ret == 0);