/* * Copyright (C) 2013 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 . */ #include #include #include "logger/Logger.hpp" #include "AvConvTranscodeStreamResource.hpp" namespace UserInterface { AvConvTranscodeStreamResource::AvConvTranscodeStreamResource(const Transcode::Parameters& parameters, Wt::WObject *parent) : Wt::WResource(parent), _parameters( parameters ) { LMS_LOG(MOD_UI, SEV_DEBUG) << "CONSTRUCTING RESOURCE"; } AvConvTranscodeStreamResource::~AvConvTranscodeStreamResource() { LMS_LOG(MOD_UI, SEV_DEBUG) << "DESTRUCTING RESOURCE"; beingDeleted(); } 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(); std::shared_ptr transcoder; if (continuation) transcoder = boost::any_cast >(continuation->data()); if (!transcoder) { LMS_LOG(MOD_UI, SEV_DEBUG) << "Launching transcoder"; transcoder = std::make_shared( _parameters); LMS_LOG(MOD_UI, SEV_DEBUG) << "Mime type set to '" << _parameters.getOutputFormat().getMimeType() << "'"; response.setMimeType(_parameters.getOutputFormat().getMimeType()); } if (!transcoder->isComplete()) { std::vector data; data.reserve(chunkSize); transcoder->process(data, chunkSize); // Give the client all the output data response.out().write(reinterpret_cast(&data[0]), data.size()); if (!response.out()) LMS_LOG(MOD_UI, SEV_ERROR) << "Write failed!"; } if (!transcoder->isComplete() && response.out()) { continuation = response.createContinuation(); continuation->setData(transcoder); } else LMS_LOG(MOD_UI, SEV_DEBUG) << "No more data!"; } } // namespace UserInterface