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