Subonsic API: added estimateContentLength parameter support for stream endpoint. fixes #244

This commit is contained in:
emeric
2022-08-20 14:56:16 +02:00
parent 49f0d40515
commit 1fb838c8d0
13 changed files with 162 additions and 104 deletions
+9 -4
View File
@@ -54,8 +54,9 @@ userTranscodeFormatToAvFormat(AudioFormat format)
struct StreamParameters
{
std::filesystem::path trackPath;
Av::InputFileParameters inputFileParameters;
std::optional<Av::TranscodeParameters> transcodeParameters;
bool estimateContentLength {};
};
static
@@ -68,9 +69,12 @@ getStreamParameters(RequestContext& context)
// Optional params
std::optional<std::size_t> maxBitRate {getParameterAs<std::size_t>(context.parameters, "maxBitRate")};
std::optional<std::string> format {getParameterAs<std::string>(context.parameters, "format")};
bool estimateContentLength {getParameterAs<bool>(context.parameters, "estimateContentLength").value_or(false)};
StreamParameters parameters;
parameters.estimateContentLength = estimateContentLength;
auto transaction {context.dbSession.createSharedTransaction()};
{
@@ -78,7 +82,8 @@ getStreamParameters(RequestContext& context)
if (!track)
throw RequestedDataNotFoundError {};
parameters.trackPath = track->getPath();
parameters.inputFileParameters.trackPath = track->getPath();
parameters.inputFileParameters.duration = track->getDuration();
}
{
@@ -155,9 +160,9 @@ handleStream(RequestContext& context, const Wt::Http::Request& request, Wt::Http
{
StreamParameters streamParameters {getStreamParameters(context)};
if (streamParameters.transcodeParameters)
resourceHandler = Av::createTranscodeResourceHandler(streamParameters.trackPath, *streamParameters.transcodeParameters);
resourceHandler = Av::createTranscodeResourceHandler(streamParameters.inputFileParameters, *streamParameters.transcodeParameters, streamParameters.estimateContentLength);
else
resourceHandler = createFileResourceHandler(streamParameters.trackPath);
resourceHandler = createFileResourceHandler(streamParameters.inputFileParameters.trackPath);
}
else
{
-13
View File
@@ -136,17 +136,4 @@ namespace StringUtils
return std::nullopt;
}
template<>
std::optional<bool>
readAs(std::string_view str)
{
if (str == "true")
return true;
else if (str == "false")
return false;
return {};
}
}
-4
View File
@@ -58,9 +58,5 @@ namespace StringUtils
template<>
std::optional<Database::TrackListId>
readAs(std::string_view str);
template<>
std::optional<bool>
readAs(std::string_view str);
}