Removed unnecessary output transcode queue
This commit is contained in:
@@ -164,32 +164,28 @@ bool
|
||||
MediaRequestHandler::processGetPart(const MediaRequest::GetPart& request, MediaResponse::PartResult& response)
|
||||
{
|
||||
std::size_t dataSize = request.requested_data_size();
|
||||
std::vector<unsigned char> data;
|
||||
if (dataSize > _maxPartSize)
|
||||
dataSize = _maxPartSize;
|
||||
|
||||
if (_transcoders.find(request.handle()) == _transcoders.end())
|
||||
TranscoderMap::iterator itTranscoder = _transcoders.find(request.handle());
|
||||
if (itTranscoder == _transcoders.end())
|
||||
{
|
||||
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "No transcoder found for handle " << request.handle();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<Transcode::AvConvTranscoder> transcoder = _transcoders[request.handle()];
|
||||
std::shared_ptr<Transcode::AvConvTranscoder> transcoder = itTranscoder->second;
|
||||
|
||||
while (!transcoder->isComplete() && transcoder->getOutputData().size() < dataSize)
|
||||
transcoder->process();
|
||||
if (!transcoder->isComplete())
|
||||
{
|
||||
data.reserve(dataSize);
|
||||
transcoder->process(data, dataSize);
|
||||
}
|
||||
|
||||
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "MediaRequestHandler::processGetPart, handle = " << request.handle() << ", isComplete = " << std::boolalpha << transcoder->isComplete() << ", size = " << transcoder->getOutputData().size();
|
||||
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "MediaRequestHandler::processGetPart, handle = " << request.handle() << ", isComplete = " << std::boolalpha << transcoder->isComplete() << ", size = " << data.size();
|
||||
|
||||
Transcode::AvConvTranscoder::data_type::iterator itEnd;
|
||||
if (transcoder->getOutputData().size() > dataSize)
|
||||
itEnd = transcoder->getOutputData().begin() + dataSize;
|
||||
else
|
||||
itEnd = transcoder->getOutputData().end();
|
||||
|
||||
std::copy(transcoder->getOutputData().begin(), itEnd, std::back_inserter(*response.mutable_data()));
|
||||
|
||||
// Consume sent bytes
|
||||
transcoder->getOutputData().erase(transcoder->getOutputData().begin(), itEnd);
|
||||
std::copy(data.begin(), data.end(), std::back_inserter(*response.mutable_data()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,9 @@ class MediaRequestHandler
|
||||
|
||||
// bool processVideoPrepare(const AudioCollectionRequest::GetGenreList& request, AudioCollectionResponse::GenreList& response);
|
||||
|
||||
std::map<uint32_t, std::shared_ptr<Transcode::AvConvTranscoder> > _transcoders;
|
||||
typedef std::map<uint32_t, std::shared_ptr<Transcode::AvConvTranscoder> > TranscoderMap;
|
||||
|
||||
TranscoderMap _transcoders;
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
|
||||
@@ -168,14 +168,17 @@ AvConvTranscoder::AvConvTranscoder(const Parameters& parameters)
|
||||
}
|
||||
|
||||
void
|
||||
AvConvTranscoder::process(void)
|
||||
AvConvTranscoder::process(std::vector<unsigned char>& output, std::size_t maxSize)
|
||||
{
|
||||
std::size_t readDatasSize = 1024; // TODO parametrize elsewhere?
|
||||
std::size_t readDataSize = 0;
|
||||
|
||||
if (_isComplete)
|
||||
return;
|
||||
|
||||
char ch;
|
||||
while(readDatasSize != 0 && _in && _in.get(ch)) {
|
||||
_data.push_back(ch);
|
||||
--readDatasSize;
|
||||
while(readDataSize < maxSize && _in && _in.get(ch)) {
|
||||
output.push_back(ch);
|
||||
readDataSize++;
|
||||
}
|
||||
|
||||
if (!_in || _in.fail() || _in.eof()) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <boost/process.hpp>
|
||||
@@ -37,21 +37,18 @@ namespace Transcode
|
||||
class AvConvTranscoder
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::deque<unsigned char> data_type;
|
||||
|
||||
static void init();
|
||||
|
||||
~AvConvTranscoder();
|
||||
|
||||
AvConvTranscoder(const Parameters& parameters);
|
||||
|
||||
data_type& getOutputData() { return _data; }
|
||||
|
||||
const Parameters& getParameters(void) const { return _parameters; }
|
||||
|
||||
// Process a bunch of input data
|
||||
void process(void);
|
||||
// Get a bunch of input data
|
||||
// Place it at the end of the parameter, no more that maxSize bytes
|
||||
void process(std::vector<unsigned char>& output, std::size_t maxSize);
|
||||
|
||||
bool isComplete(void) const { return _isComplete;};
|
||||
|
||||
private:
|
||||
@@ -74,7 +71,6 @@ class AvConvTranscoder
|
||||
|
||||
static boost::filesystem::path _avConvPath;
|
||||
|
||||
data_type _data;
|
||||
bool _isComplete;
|
||||
};
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ void
|
||||
AvConvTranscodeStreamResource::handleRequest(const Wt::Http::Request& request,
|
||||
Wt::Http::Response& response)
|
||||
{
|
||||
static const std::size_t chunkSize = 8192; // TODO parametrize?
|
||||
|
||||
// see if this request is for a continuation:
|
||||
Wt::Http::ResponseContinuation *continuation = request.continuation();
|
||||
|
||||
@@ -59,34 +61,21 @@ AvConvTranscodeStreamResource::handleRequest(const Wt::Http::Request& request,
|
||||
response.setMimeType(_parameters.getOutputFormat().getMimeType());
|
||||
}
|
||||
|
||||
Transcode::AvConvTranscoder::data_type& data = transcoder->getOutputData();
|
||||
|
||||
while (!transcoder->isComplete() && data.size() < _bufferSize)
|
||||
transcoder->process();
|
||||
|
||||
// Give the client all the output data
|
||||
Transcode::AvConvTranscoder::data_type::const_iterator it = data.begin();
|
||||
bool copySuccess = true;
|
||||
std::size_t copiedSize = 0;
|
||||
for (Transcode::AvConvTranscoder::data_type::const_iterator it = data.begin(); it != data.end(); ++it)
|
||||
if (!transcoder->isComplete())
|
||||
{
|
||||
if (!response.out().put(*it)) {
|
||||
copySuccess = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
copiedSize++;
|
||||
std::vector<unsigned char> data;
|
||||
data.reserve(chunkSize);
|
||||
|
||||
transcoder->process(data, chunkSize);
|
||||
|
||||
// Give the client all the output data
|
||||
response.out().write(reinterpret_cast<char*>(&data[0]), data.size());
|
||||
|
||||
if (!response.out())
|
||||
LMS_LOG(MOD_UI, SEV_ERROR) << "Write failed!";
|
||||
}
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Wrote " << copiedSize << " bytes";
|
||||
|
||||
if (!copySuccess)
|
||||
LMS_LOG(MOD_UI, SEV_ERROR) << "** Write failed!";
|
||||
|
||||
// Consume copied bytes
|
||||
data.erase(data.begin(), data.begin() + copiedSize);
|
||||
|
||||
if (copySuccess && !transcoder->isComplete()) {
|
||||
if (!transcoder->isComplete() && response.out()) {
|
||||
continuation = response.createContinuation();
|
||||
continuation->setData(transcoder);
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Continuation set!";
|
||||
|
||||
Reference in New Issue
Block a user