2006-02-24 09:30:08 +01:00
|
|
|
// Copyright (c) 2006, 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 video_provider_manager.cpp
|
|
|
|
/// @brief Keep track of installed video providers
|
|
|
|
/// @ingroup video_input
|
|
|
|
///
|
2006-02-24 09:30:08 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include "video_provider_manager.h"
|
2010-06-09 01:21:39 +02:00
|
|
|
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2008-03-05 03:05:01 +01:00
|
|
|
#include "video_provider_avs.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_provider_cache.h"
|
|
|
|
#include "video_provider_dummy.h"
|
2008-09-03 19:03:20 +02:00
|
|
|
#include "video_provider_ffmpegsource.h"
|
2009-07-19 06:13:46 +02:00
|
|
|
#include "video_provider_yuv4mpeg.h"
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs.h>
|
|
|
|
#include <libaegisub/log.h>
|
2013-06-08 06:19:40 +02:00
|
|
|
#include <libaegisub/util.h>
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-10-17 16:23:45 +02:00
|
|
|
std::unique_ptr<VideoProvider> VideoProviderFactory::GetProvider(agi::fs::path const& video_file, std::string const& colormatrix) {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<std::string> factories = GetClasses(OPT_GET("Video/Provider")->GetString());
|
|
|
|
factories.insert(factories.begin(), "YUV4MPEG");
|
|
|
|
factories.insert(factories.begin(), "Dummy");
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
bool found = false;
|
|
|
|
bool supported = false;
|
2010-08-02 08:32:01 +02:00
|
|
|
std::string errors;
|
|
|
|
errors.reserve(1024);
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
for (auto const& factory : factories) {
|
2010-12-29 20:35:45 +01:00
|
|
|
std::string err;
|
2006-02-24 09:43:44 +01:00
|
|
|
try {
|
2013-10-17 16:23:45 +02:00
|
|
|
auto provider = Create(factory, video_file, colormatrix);
|
2013-01-04 16:01:50 +01:00
|
|
|
LOG_I("manager/video/provider") << factory << ": opened " << video_file;
|
2013-06-08 06:19:40 +02:00
|
|
|
return provider->WantsCaching() ? agi::util::make_unique<VideoProviderCache>(std::move(provider)) : std::move(provider);
|
2010-08-02 08:32:01 +02:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
catch (agi::fs::FileNotFound const&) {
|
|
|
|
err = "file not found.";
|
2010-08-02 08:32:01 +02:00
|
|
|
// Keep trying other providers as this one may just not be able to
|
|
|
|
// open a valid path
|
|
|
|
}
|
|
|
|
catch (VideoNotSupported const&) {
|
2013-01-04 16:01:50 +01:00
|
|
|
found = true;
|
|
|
|
err = "video is not in a supported format.";
|
2010-08-02 08:32:01 +02:00
|
|
|
}
|
|
|
|
catch (VideoOpenError const& ex) {
|
2013-01-04 16:01:50 +01:00
|
|
|
supported = true;
|
|
|
|
err = ex.GetMessage();
|
2006-02-24 09:43:44 +01:00
|
|
|
}
|
2010-12-29 20:35:45 +01:00
|
|
|
catch (agi::vfr::Error const& ex) {
|
2013-01-04 16:01:50 +01:00
|
|
|
supported = true;
|
|
|
|
err = ex.GetMessage();
|
2010-12-29 20:35:45 +01:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
errors += factory + ": " + err + "\n";
|
|
|
|
LOG_D("manager/video/provider") << factory << ": " << err;
|
2006-02-24 09:43:44 +01:00
|
|
|
}
|
2006-02-24 09:30:08 +01:00
|
|
|
|
2010-08-02 08:32:01 +02:00
|
|
|
// No provider could open the file
|
2013-01-04 16:01:50 +01:00
|
|
|
LOG_E("manager/video/provider") << "Could not open " << video_file;
|
|
|
|
std::string msg = "Could not open " + video_file.string() + ":\n" + errors;
|
2010-08-02 08:32:01 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
if (!found) throw agi::fs::FileNotFound(video_file.string());
|
|
|
|
if (!supported) throw VideoNotSupported(msg);
|
2010-08-02 08:32:01 +02:00
|
|
|
throw VideoOpenError(msg);
|
2006-02-24 09:30:08 +01:00
|
|
|
}
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2010-08-02 08:31:38 +02:00
|
|
|
void VideoProviderFactory::RegisterProviders() {
|
2008-03-05 03:05:01 +01:00
|
|
|
#ifdef WITH_AVISYNTH
|
2010-08-02 08:31:38 +02:00
|
|
|
Register<AvisynthVideoProvider>("Avisynth");
|
2008-03-05 03:05:01 +01:00
|
|
|
#endif
|
2011-12-22 22:25:49 +01:00
|
|
|
#ifdef WITH_FFMS2
|
2010-08-02 08:31:38 +02:00
|
|
|
Register<FFmpegSourceVideoProvider>("FFmpegSource");
|
2008-09-03 19:03:20 +02:00
|
|
|
#endif
|
2010-08-02 08:31:38 +02:00
|
|
|
Register<DummyVideoProvider>("Dummy", true);
|
|
|
|
Register<YUV4MPEGVideoProvider>("YUV4MPEG", true);
|
2008-03-05 03:05:01 +01:00
|
|
|
}
|