Subsonic API: do not use ffmpeg to remux the files when transcoding is off. fixes #36
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS 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 LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "AvTranscodeResourceHandler.hpp"
|
||||
|
||||
namespace Av
|
||||
{
|
||||
|
||||
std::unique_ptr<IResourceHandler>
|
||||
createTranscodeResourceHandler(const std::filesystem::path& trackPath, const TranscodeParameters& parameters)
|
||||
{
|
||||
return std::make_unique<TranscodeResourceHandler>(trackPath, parameters);
|
||||
}
|
||||
|
||||
// TODO set some nice HTTP return code
|
||||
|
||||
TranscodeResourceHandler::TranscodeResourceHandler(const std::filesystem::path& trackPath, const TranscodeParameters& parameters)
|
||||
: _transcoder {trackPath, parameters}
|
||||
{
|
||||
_transcoder.start();
|
||||
}
|
||||
|
||||
void
|
||||
TranscodeResourceHandler::processRequest(const Wt::Http::Request& /*request*/, Wt::Http::Response& response)
|
||||
{
|
||||
response.setMimeType(_transcoder.getOutputMimeType());
|
||||
|
||||
if (!_transcoder.isComplete())
|
||||
{
|
||||
std::vector<unsigned char> buffer;
|
||||
|
||||
_transcoder.process(buffer, _chunkSize);
|
||||
response.out().write(reinterpret_cast<const char *>(&buffer[0]), buffer.size());
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
TranscodeResourceHandler::isFinished() const
|
||||
{
|
||||
return _transcoder.isComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS 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 LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include "av/AvTranscoder.hpp"
|
||||
#include "utils/IResourceHandler.hpp"
|
||||
|
||||
namespace Av
|
||||
{
|
||||
|
||||
class TranscodeResourceHandler final : public IResourceHandler
|
||||
{
|
||||
public:
|
||||
TranscodeResourceHandler(const std::filesystem::path& trackPath, const TranscodeParameters& parameters);
|
||||
|
||||
private:
|
||||
|
||||
void processRequest(const Wt::Http::Request& request, Wt::Http::Response& reponse) override;
|
||||
bool isFinished() const override;
|
||||
|
||||
static constexpr std::size_t _chunkSize {262144};
|
||||
const std::filesystem::path _trackPath;
|
||||
Transcoder _transcoder;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user