mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-16 01:03:16 -05:00
[input] Split file_http.c input into file.c and http.c
The common code is by now limited, and there is a lot of http-specific code.
This commit is contained in:
parent
3c65f8a71e
commit
37521406f3
@ -130,7 +130,7 @@ forked_daapd_SOURCES = main.c \
|
|||||||
worker.c worker.h \
|
worker.c worker.h \
|
||||||
settings.c settings.h \
|
settings.c settings.h \
|
||||||
input.h input.c \
|
input.h input.c \
|
||||||
inputs/file_http.c inputs/pipe.c inputs/timer.c \
|
inputs/file.c inputs/http.c inputs/pipe.c inputs/timer.c \
|
||||||
outputs.h outputs.c \
|
outputs.h outputs.c \
|
||||||
outputs/rtp_common.h outputs/rtp_common.c \
|
outputs/rtp_common.h outputs/rtp_common.c \
|
||||||
outputs/raop.c $(RAOP_VERIFICATION_SRC) \
|
outputs/raop.c $(RAOP_VERIFICATION_SRC) \
|
||||||
|
114
src/inputs/file.c
Normal file
114
src/inputs/file.c
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017-2020 Espen Jurgensen
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <event2/buffer.h>
|
||||||
|
|
||||||
|
#include "transcode.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
/*---------------------------- Input implementation --------------------------*/
|
||||||
|
|
||||||
|
// Important! If you change any of the below then consider if the change also
|
||||||
|
// should be made in http.c
|
||||||
|
|
||||||
|
static int
|
||||||
|
setup(struct input_source *source)
|
||||||
|
{
|
||||||
|
struct transcode_ctx *ctx;
|
||||||
|
|
||||||
|
ctx = transcode_setup(XCODE_PCM_NATIVE, NULL, source->data_kind, source->path, source->len_ms, NULL);
|
||||||
|
if (!ctx)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
CHECK_NULL(L_PLAYER, source->evbuf = evbuffer_new());
|
||||||
|
|
||||||
|
source->quality.sample_rate = transcode_encode_query(ctx->encode_ctx, "sample_rate");
|
||||||
|
source->quality.bits_per_sample = transcode_encode_query(ctx->encode_ctx, "bits_per_sample");
|
||||||
|
source->quality.channels = transcode_encode_query(ctx->encode_ctx, "channels");
|
||||||
|
|
||||||
|
source->input_ctx = ctx;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
stop(struct input_source *source)
|
||||||
|
{
|
||||||
|
struct transcode_ctx *ctx = source->input_ctx;
|
||||||
|
|
||||||
|
transcode_cleanup(&ctx);
|
||||||
|
|
||||||
|
if (source->evbuf)
|
||||||
|
evbuffer_free(source->evbuf);
|
||||||
|
|
||||||
|
source->input_ctx = NULL;
|
||||||
|
source->evbuf = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
play(struct input_source *source)
|
||||||
|
{
|
||||||
|
struct transcode_ctx *ctx = source->input_ctx;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
// We set "wanted" to 1 because the read size doesn't matter to us
|
||||||
|
// TODO optimize?
|
||||||
|
ret = transcode(source->evbuf, NULL, ctx, 1);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
input_write(source->evbuf, &source->quality, INPUT_FLAG_EOF);
|
||||||
|
stop(source);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (ret < 0)
|
||||||
|
{
|
||||||
|
input_write(NULL, NULL, INPUT_FLAG_ERROR);
|
||||||
|
stop(source);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
input_write(source->evbuf, &source->quality, 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
seek(struct input_source *source, int seek_ms)
|
||||||
|
{
|
||||||
|
return transcode_seek(source->input_ctx, seek_ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct input_definition input_file =
|
||||||
|
{
|
||||||
|
.name = "file",
|
||||||
|
.type = INPUT_TYPE_FILE,
|
||||||
|
.disabled = 0,
|
||||||
|
.setup = setup,
|
||||||
|
.play = play,
|
||||||
|
.stop = stop,
|
||||||
|
.seek = seek,
|
||||||
|
};
|
@ -289,10 +289,20 @@ metadata_prepare(struct input_source *source)
|
|||||||
|
|
||||||
/*---------------------------- Input implementation --------------------------*/
|
/*---------------------------- Input implementation --------------------------*/
|
||||||
|
|
||||||
|
// Important! If you change any of the below then consider if the change also
|
||||||
|
// should be made in file.c
|
||||||
|
|
||||||
static int
|
static int
|
||||||
setup(struct input_source *source)
|
setup(struct input_source *source)
|
||||||
{
|
{
|
||||||
struct transcode_ctx *ctx;
|
struct transcode_ctx *ctx;
|
||||||
|
char *url;
|
||||||
|
|
||||||
|
if (http_stream_setup(&url, source->path) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
free(source->path);
|
||||||
|
source->path = url;
|
||||||
|
|
||||||
ctx = transcode_setup(XCODE_PCM_NATIVE, NULL, source->data_kind, source->path, source->len_ms, NULL);
|
ctx = transcode_setup(XCODE_PCM_NATIVE, NULL, source->data_kind, source->path, source->len_ms, NULL);
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
@ -309,20 +319,6 @@ setup(struct input_source *source)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
setup_http(struct input_source *source)
|
|
||||||
{
|
|
||||||
char *url;
|
|
||||||
|
|
||||||
if (http_stream_setup(&url, source->path) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
free(source->path);
|
|
||||||
source->path = url;
|
|
||||||
|
|
||||||
return setup(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
stop(struct input_source *source)
|
stop(struct input_source *source)
|
||||||
{
|
{
|
||||||
@ -372,12 +368,6 @@ play(struct input_source *source)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
seek(struct input_source *source, int seek_ms)
|
seek(struct input_source *source, int seek_ms)
|
||||||
{
|
|
||||||
return transcode_seek(source->input_ctx, seek_ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
seek_http(struct input_source *source, int seek_ms)
|
|
||||||
{
|
{
|
||||||
// Stream is live/unknown length so can't seek. We return 0 anyway, because
|
// Stream is live/unknown length so can't seek. We return 0 anyway, because
|
||||||
// it is valid for the input to request a seek, since the input is not
|
// it is valid for the input to request a seek, since the input is not
|
||||||
@ -389,7 +379,7 @@ seek_http(struct input_source *source, int seek_ms)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
metadata_get_http(struct input_metadata *metadata, struct input_source *source)
|
metadata_get(struct input_metadata *metadata, struct input_source *source)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&prepared_metadata.lock);
|
pthread_mutex_lock(&prepared_metadata.lock);
|
||||||
|
|
||||||
@ -404,39 +394,28 @@ metadata_get_http(struct input_metadata *metadata, struct input_source *source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
init_http(void)
|
init(void)
|
||||||
{
|
{
|
||||||
CHECK_ERR(L_PLAYER, mutex_init(&prepared_metadata.lock));
|
CHECK_ERR(L_PLAYER, mutex_init(&prepared_metadata.lock));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
deinit_http(void)
|
deinit(void)
|
||||||
{
|
{
|
||||||
CHECK_ERR(L_PLAYER, pthread_mutex_destroy(&prepared_metadata.lock));
|
CHECK_ERR(L_PLAYER, pthread_mutex_destroy(&prepared_metadata.lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct input_definition input_file =
|
|
||||||
{
|
|
||||||
.name = "file",
|
|
||||||
.type = INPUT_TYPE_FILE,
|
|
||||||
.disabled = 0,
|
|
||||||
.setup = setup,
|
|
||||||
.play = play,
|
|
||||||
.stop = stop,
|
|
||||||
.seek = seek,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct input_definition input_http =
|
struct input_definition input_http =
|
||||||
{
|
{
|
||||||
.name = "http",
|
.name = "http",
|
||||||
.type = INPUT_TYPE_HTTP,
|
.type = INPUT_TYPE_HTTP,
|
||||||
.disabled = 0,
|
.disabled = 0,
|
||||||
.setup = setup_http,
|
.setup = setup,
|
||||||
.play = play,
|
.play = play,
|
||||||
.stop = stop,
|
.stop = stop,
|
||||||
.metadata_get = metadata_get_http,
|
.metadata_get = metadata_get,
|
||||||
.seek = seek_http,
|
.seek = seek,
|
||||||
.init = init_http,
|
.init = init,
|
||||||
.deinit = deinit_http,
|
.deinit = deinit,
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user