Merge branch 'develop' for release v3.25.1
This commit is contained in:
@@ -218,5 +218,3 @@
|
|||||||
<message id="Wt.WValidator.Invalid">此字段不能为空</message>
|
<message id="Wt.WValidator.Invalid">此字段不能为空</message>
|
||||||
<message id="Wt.WDoubleValidator.BadRange">这个值应该在 {1} 和 {2}</message>
|
<message id="Wt.WDoubleValidator.BadRange">这个值应该在 {1} 和 {2}</message>
|
||||||
</messages>
|
</messages>
|
||||||
|
|
||||||
</messages>
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ namespace Av
|
|||||||
TranscodeResourceHandler::TranscodeResourceHandler(const std::filesystem::path& trackPath, const TranscodeParameters& parameters)
|
TranscodeResourceHandler::TranscodeResourceHandler(const std::filesystem::path& trackPath, const TranscodeParameters& parameters)
|
||||||
: _transcoder {trackPath, parameters}
|
: _transcoder {trackPath, parameters}
|
||||||
{
|
{
|
||||||
_transcoder.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Wt::Http::ResponseContinuation*
|
Wt::Http::ResponseContinuation*
|
||||||
|
|||||||
@@ -48,11 +48,12 @@ Transcoder::Transcoder(const std::filesystem::path& filePath, const TranscodePar
|
|||||||
, _filePath {filePath}
|
, _filePath {filePath}
|
||||||
, _parameters {parameters}
|
, _parameters {parameters}
|
||||||
{
|
{
|
||||||
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Transcoder::~Transcoder() = default;
|
Transcoder::~Transcoder() = default;
|
||||||
|
|
||||||
bool
|
void
|
||||||
Transcoder::start()
|
Transcoder::start()
|
||||||
{
|
{
|
||||||
if (ffmpegPath.empty())
|
if (ffmpegPath.empty())
|
||||||
@@ -61,20 +62,13 @@ Transcoder::start()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!std::filesystem::exists(_filePath))
|
if (!std::filesystem::exists(_filePath))
|
||||||
{
|
throw Exception {"File '" + _filePath.string() + "' does not exist!"};
|
||||||
LOG(ERROR) << "File '" << _filePath << "' does not exist!";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (!std::filesystem::is_regular_file( _filePath) )
|
else if (!std::filesystem::is_regular_file( _filePath) )
|
||||||
{
|
throw Exception {"File '" + _filePath.string() + "' is not regular!"};
|
||||||
LOG(ERROR) << "File '" << _filePath << "' is not regular!";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (const std::filesystem::filesystem_error& e)
|
catch (const std::filesystem::filesystem_error& e)
|
||||||
{
|
{
|
||||||
LOG(ERROR) << "File error on '" << _filePath.string() << "': " << e.what();
|
throw Exception {"File error '" + _filePath.string() + "': " + e.what()};
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Transcoding file '" << _filePath.string() << "'";
|
LOG(INFO) << "Transcoding file '" << _filePath.string() << "'";
|
||||||
@@ -163,7 +157,7 @@ Transcoder::start()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
throw Exception {"Unhandled format (" + std::to_string(static_cast<int>(_parameters.format)) + ")"};
|
||||||
}
|
}
|
||||||
|
|
||||||
_outputMimeType = formatToMimetype(_parameters.format);
|
_outputMimeType = formatToMimetype(_parameters.format);
|
||||||
@@ -181,11 +175,8 @@ Transcoder::start()
|
|||||||
}
|
}
|
||||||
catch (ChildProcessException& exception)
|
catch (ChildProcessException& exception)
|
||||||
{
|
{
|
||||||
LOG(ERROR) << "Cannot execute '" << ffmpegPath << "': " << exception.what();
|
throw Exception {"Cannot execute '" + ffmpegPath.string() + "': " + exception.what()};
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -223,6 +214,8 @@ Transcoder::readSome(std::byte* buffer, std::size_t bufferSize)
|
|||||||
bool
|
bool
|
||||||
Transcoder::finished() const
|
Transcoder::finished() const
|
||||||
{
|
{
|
||||||
|
assert(_childProcess);
|
||||||
|
|
||||||
return _childProcess->finished();
|
return _childProcess->finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ namespace Av
|
|||||||
Transcoder(Transcoder&&) = delete;
|
Transcoder(Transcoder&&) = delete;
|
||||||
Transcoder& operator=(Transcoder&&) = delete;
|
Transcoder& operator=(Transcoder&&) = delete;
|
||||||
|
|
||||||
bool start();
|
|
||||||
|
|
||||||
using WaitCallback = std::function<void()>;
|
using WaitCallback = std::function<void()>;
|
||||||
void asyncWaitForData(WaitCallback cb);
|
void asyncWaitForData(WaitCallback cb);
|
||||||
|
|
||||||
@@ -58,6 +56,8 @@ namespace Av
|
|||||||
private:
|
private:
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
|
void start();
|
||||||
|
|
||||||
const std::size_t _id {};
|
const std::size_t _id {};
|
||||||
const std::filesystem::path _filePath;
|
const std::filesystem::path _filePath;
|
||||||
const TranscodeParameters _parameters;
|
const TranscodeParameters _parameters;
|
||||||
|
|||||||
@@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <optional>
|
||||||
|
|
||||||
#include <Wt/WDateTime.h>
|
#include <Wt/WDateTime.h>
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#include <Wt/Http/Client.h>
|
#include <Wt/Http/Client.h>
|
||||||
#include <Wt/WIOService.h>
|
#include <Wt/WIOService.h>
|
||||||
|
|||||||
@@ -21,9 +21,9 @@
|
|||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <optional>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string_view>
|
#include <vector>
|
||||||
|
|
||||||
#include <Wt/WDateTime.h>
|
#include <Wt/WDateTime.h>
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "database/Track.hpp"
|
#include "database/Track.hpp"
|
||||||
#include "database/User.hpp"
|
#include "database/User.hpp"
|
||||||
#include "utils/IResourceHandler.hpp"
|
#include "utils/IResourceHandler.hpp"
|
||||||
|
#include "utils/Logger.hpp"
|
||||||
#include "utils/FileResourceHandlerCreator.hpp"
|
#include "utils/FileResourceHandlerCreator.hpp"
|
||||||
#include "utils/Utils.hpp"
|
#include "utils/Utils.hpp"
|
||||||
#include "ParameterParsing.hpp"
|
#include "ParameterParsing.hpp"
|
||||||
@@ -147,24 +148,30 @@ handleStream(RequestContext& context, const Wt::Http::Request& request, Wt::Http
|
|||||||
{
|
{
|
||||||
std::shared_ptr<IResourceHandler> resourceHandler;
|
std::shared_ptr<IResourceHandler> resourceHandler;
|
||||||
|
|
||||||
Wt::Http::ResponseContinuation* continuation = request.continuation();
|
try
|
||||||
if (!continuation)
|
|
||||||
{
|
{
|
||||||
StreamParameters streamParameters {getStreamParameters(context)};
|
Wt::Http::ResponseContinuation* continuation = request.continuation();
|
||||||
if (streamParameters.transcodeParameters)
|
if (!continuation)
|
||||||
resourceHandler = Av::createTranscodeResourceHandler(streamParameters.trackPath, *streamParameters.transcodeParameters);
|
{
|
||||||
|
StreamParameters streamParameters {getStreamParameters(context)};
|
||||||
|
if (streamParameters.transcodeParameters)
|
||||||
|
resourceHandler = Av::createTranscodeResourceHandler(streamParameters.trackPath, *streamParameters.transcodeParameters);
|
||||||
|
else
|
||||||
|
resourceHandler = createFileResourceHandler(streamParameters.trackPath);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
resourceHandler = createFileResourceHandler(streamParameters.trackPath);
|
{
|
||||||
|
resourceHandler = Wt::cpp17::any_cast<std::shared_ptr<IResourceHandler>>(continuation->data());
|
||||||
|
}
|
||||||
|
|
||||||
|
continuation = resourceHandler->processRequest(request, response);
|
||||||
|
if (continuation)
|
||||||
|
continuation->setData(resourceHandler);
|
||||||
}
|
}
|
||||||
else
|
catch (const Av::Exception& e)
|
||||||
{
|
{
|
||||||
resourceHandler = Wt::cpp17::any_cast<std::shared_ptr<IResourceHandler>>(continuation->data());
|
LMS_LOG(API_SUBSONIC, ERROR) << "Caught Av exception: " << e.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
continuation = resourceHandler->processRequest(request, response);
|
|
||||||
if (continuation)
|
|
||||||
continuation->setData(resourceHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace API::Subsonic::Stream
|
||||||
|
|||||||
@@ -69,13 +69,15 @@ ChildProcess::ChildProcess(boost::asio::io_context& ioContext, const std::filesy
|
|||||||
throw SystemException {errno, "pipe2 failed!"};
|
throw SystemException {errno, "pipe2 failed!"};
|
||||||
|
|
||||||
{
|
{
|
||||||
const std::size_t pipeSize {65536*8};
|
#if defined(__linux__) && defined(F_SETPIPE_SZ)
|
||||||
|
// Just a hint here to prevent the writer from writing too many bytes ahead of the reader
|
||||||
|
constexpr std::size_t pipeSize {65536*4};
|
||||||
|
|
||||||
if (fcntl(pipe[0], F_SETPIPE_SZ, pipeSize) == -1)
|
if (fcntl(pipe[0], F_SETPIPE_SZ, pipeSize) == -1)
|
||||||
throw SystemException {errno, "fcntl failed!"};
|
throw SystemException {errno, "fcntl failed!"};
|
||||||
|
|
||||||
if (fcntl(pipe[1], F_SETPIPE_SZ, pipeSize) == -1)
|
if (fcntl(pipe[1], F_SETPIPE_SZ, pipeSize) == -1)
|
||||||
throw SystemException {errno, "fcntl failed!"};
|
throw SystemException {errno, "fcntl failed!"};
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
res = fork();
|
res = fork();
|
||||||
|
|||||||
@@ -180,23 +180,30 @@ AudioTranscodeResource::handleRequest(const Wt::Http::Request& request,
|
|||||||
{
|
{
|
||||||
std::shared_ptr<IResourceHandler> resourceHandler;
|
std::shared_ptr<IResourceHandler> resourceHandler;
|
||||||
|
|
||||||
Wt::Http::ResponseContinuation* continuation {request.continuation()};
|
try
|
||||||
if (!continuation)
|
|
||||||
{
|
{
|
||||||
const std::optional<TranscodeParameters>& parameters {readTranscodeParameters(request)};
|
Wt::Http::ResponseContinuation* continuation {request.continuation()};
|
||||||
if (parameters)
|
if (!continuation)
|
||||||
resourceHandler = Av::createTranscodeResourceHandler(parameters->file, parameters->transcodeParameters);
|
{
|
||||||
}
|
const std::optional<TranscodeParameters>& parameters {readTranscodeParameters(request)};
|
||||||
else
|
if (parameters)
|
||||||
{
|
resourceHandler = Av::createTranscodeResourceHandler(parameters->file, parameters->transcodeParameters);
|
||||||
resourceHandler = Wt::cpp17::any_cast<std::shared_ptr<IResourceHandler>>(continuation->data());
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
resourceHandler = Wt::cpp17::any_cast<std::shared_ptr<IResourceHandler>>(continuation->data());
|
||||||
|
}
|
||||||
|
|
||||||
if (resourceHandler)
|
if (resourceHandler)
|
||||||
|
{
|
||||||
|
continuation = resourceHandler->processRequest(request, response);
|
||||||
|
if (continuation)
|
||||||
|
continuation->setData(resourceHandler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const Av::Exception& e)
|
||||||
{
|
{
|
||||||
continuation = resourceHandler->processRequest(request, response);
|
LOG(ERROR) << "Caught Av exception: " << e.what();
|
||||||
if (continuation)
|
|
||||||
continuation->setData(resourceHandler);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user