2007-01-21 07:30:19 +01:00
|
|
|
// Copyright (c) 2007, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file subtitles_provider_csri.cpp
|
|
|
|
/// @brief Wrapper for CSRI-based subtitle renderers
|
|
|
|
/// @ingroup subtitle_rendering
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-12-31 07:46:22 +01:00
|
|
|
#ifdef WITH_CSRI
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "subtitles_provider_csri.h"
|
2011-11-04 06:11:31 +01:00
|
|
|
|
2013-01-30 04:35:37 +01:00
|
|
|
#include "options.h"
|
2013-01-26 02:57:46 +01:00
|
|
|
#include "subtitle_format.h"
|
2010-08-02 08:32:01 +02:00
|
|
|
#include "video_frame.h"
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs.h>
|
2013-01-30 04:35:37 +01:00
|
|
|
#include <libaegisub/path.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <mutex>
|
|
|
|
|
2012-04-10 22:41:25 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
#define CSRIAPI
|
|
|
|
#endif
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2014-03-11 20:11:05 +01:00
|
|
|
#include <csri/csri.h>
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
// CSRI renderers are not required to be thread safe (and VSFilter very much
|
|
|
|
// is not)
|
|
|
|
static std::mutex csri_mutex;
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2012-04-10 22:41:25 +02:00
|
|
|
CSRISubtitlesProvider::CSRISubtitlesProvider(std::string type)
|
2013-01-24 06:00:34 +01:00
|
|
|
: instance(nullptr, csri_close)
|
2012-04-10 22:41:25 +02:00
|
|
|
{
|
2013-01-04 16:01:50 +01:00
|
|
|
std::lock_guard<std::mutex> lock(csri_mutex);
|
2011-11-04 06:11:31 +01:00
|
|
|
|
2012-04-14 05:17:15 +02:00
|
|
|
for (csri_rend *cur = csri_renderer_default(); cur; cur = csri_renderer_next(cur)) {
|
|
|
|
if (type == csri_renderer_info(cur)->name) {
|
2007-04-08 18:33:53 +02:00
|
|
|
renderer = cur;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-10 22:41:25 +02:00
|
|
|
if (!renderer)
|
2012-04-14 05:17:15 +02:00
|
|
|
throw agi::InternalError("CSRI renderer vanished between initial list and creation?", 0);
|
2012-04-10 22:41:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CSRISubtitlesProvider::~CSRISubtitlesProvider() {
|
2013-01-04 16:01:50 +01:00
|
|
|
agi::fs::Remove(tempfile);
|
2012-04-10 22:41:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
2013-01-24 06:00:34 +01:00
|
|
|
if (tempfile.empty())
|
2013-01-30 04:35:37 +01:00
|
|
|
tempfile = unique_path(config::path->Decode("?temp/csri-%%%%-%%%%-%%%%-%%%%.ass"));
|
2013-01-26 02:57:46 +01:00
|
|
|
SubtitleFormat::GetWriter(tempfile)->WriteFile(subs, tempfile, "utf-8");
|
2012-04-14 05:17:22 +02:00
|
|
|
|
2013-01-24 06:00:34 +01:00
|
|
|
std::lock_guard<std::mutex> lock(csri_mutex);
|
|
|
|
instance = csri_open_file(renderer, tempfile.string().c_str(), nullptr);
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
2013-07-01 05:15:43 +02:00
|
|
|
void CSRISubtitlesProvider::DrawSubtitles(VideoFrame &dst,double time) {
|
2012-04-10 22:41:25 +02:00
|
|
|
if (!instance) return;
|
2011-11-04 06:11:31 +01:00
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
csri_frame frame;
|
2010-12-31 22:03:11 +01:00
|
|
|
if (dst.flipped) {
|
2013-07-01 05:15:43 +02:00
|
|
|
frame.planes[0] = dst.data.data() + (dst.height-1) * dst.width * 4;
|
|
|
|
frame.strides[0] = -(signed)dst.width * 4;
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
2010-12-31 22:03:11 +01:00
|
|
|
else {
|
2013-07-01 05:15:43 +02:00
|
|
|
frame.planes[0] = dst.data.data();
|
|
|
|
frame.strides[0] = dst.width * 4;
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
2010-12-31 22:03:11 +01:00
|
|
|
frame.pixfmt = CSRI_F_BGR_;
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-07-01 05:15:43 +02:00
|
|
|
csri_fmt format = { frame.pixfmt, dst.width, dst.height };
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::lock_guard<std::mutex> lock(csri_mutex);
|
|
|
|
if (!csri_request_fmt(instance, &format))
|
|
|
|
csri_render(instance, &frame, time);
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2010-08-02 08:31:38 +02:00
|
|
|
std::vector<std::string> CSRISubtitlesProvider::GetSubTypes() {
|
|
|
|
std::vector<std::string> final;
|
2012-04-17 01:54:34 +02:00
|
|
|
for (csri_rend *cur = csri_renderer_default(); cur; cur = csri_renderer_next(cur)) {
|
|
|
|
std::string name(csri_renderer_info(cur)->name);
|
|
|
|
if (name.find("aegisub") != name.npos)
|
|
|
|
final.insert(final.begin(), name);
|
|
|
|
else
|
|
|
|
final.push_back(name);
|
2008-03-05 03:58:11 +01:00
|
|
|
}
|
|
|
|
return final;
|
|
|
|
}
|
|
|
|
|
2007-12-31 07:46:22 +01:00
|
|
|
#endif // WITH_CSRI
|