2007-09-02 18:48:22 +02:00
|
|
|
/*
|
|
|
|
|
Media(Asset) - key abstraction: media-like assets
|
|
|
|
|
|
|
|
|
|
Copyright (C) CinelerraCV
|
|
|
|
|
2007, Christian Thaeter <ct@pipapo.org>
|
|
|
|
|
|
|
|
|
|
This program 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 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
2007-09-10 06:45:36 +02:00
|
|
|
#include "proc/assetmanager.hpp"
|
2007-09-02 18:48:22 +02:00
|
|
|
#include "proc/asset/media.hpp"
|
2007-09-10 06:45:36 +02:00
|
|
|
#include "proc/asset/clip.hpp"
|
|
|
|
|
#include "proc/asset/unknown.hpp"
|
2007-09-25 23:39:46 +02:00
|
|
|
#include "proc/mobject/session/clip.hpp"
|
2007-09-10 06:45:36 +02:00
|
|
|
#include "common/util.hpp"
|
|
|
|
|
#include "nobugcfg.h"
|
|
|
|
|
|
|
|
|
|
#include <boost/regex.hpp>
|
|
|
|
|
|
|
|
|
|
using util::isnil;
|
|
|
|
|
|
|
|
|
|
using boost::regex;
|
|
|
|
|
using boost::smatch;
|
|
|
|
|
using boost::regex_search;
|
|
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
|
|
|
|
|
namespace asset
|
|
|
|
|
{
|
|
|
|
|
|
2007-09-10 06:45:36 +02:00
|
|
|
namespace // Implementation details
|
|
|
|
|
{
|
|
|
|
|
/** helper: extract a name token out of a given path/filename
|
|
|
|
|
* @return sanitized token based on the name (minus extension),
|
|
|
|
|
* empty string if not the common filename pattern.
|
|
|
|
|
*/
|
|
|
|
|
string extractName (const string& path)
|
|
|
|
|
{
|
|
|
|
|
regex pathname_pattern("([^/\\.]+)(\\.\\w+)?$");
|
|
|
|
|
smatch match;
|
|
|
|
|
|
|
|
|
|
if (regex_search (path, match, pathname_pattern))
|
|
|
|
|
return util::sanitize (string (match[1]));
|
|
|
|
|
else
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-12 06:53:12 +02:00
|
|
|
|
2007-09-25 23:39:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef shared_ptr<mobject::session::Clip> PClip;
|
|
|
|
|
typedef shared_ptr<asset::ProcPatt> PProcPatt;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PClip
|
|
|
|
|
Media::createClip ()
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED ("create clip from media asset");
|
|
|
|
|
PClip clip; //TODO:null
|
|
|
|
|
|
|
|
|
|
ENSURE (clip);
|
|
|
|
|
return clip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PProcPatt
|
|
|
|
|
Media::howtoProc ()
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED ("calculate and return processing pattern for media asset");
|
|
|
|
|
PProcPatt ppatt; //TODO:null
|
|
|
|
|
|
|
|
|
|
ENSURE (ppatt);
|
|
|
|
|
return ppatt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-12 06:53:12 +02:00
|
|
|
|
|
|
|
|
MediaFactory Media::create; ///< storage for the static MediaFactory instance
|
2007-09-10 06:45:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Factory method for Media Asset instances. Depending on the filename given,
|
|
|
|
|
* either a asset::Media object or an "Unknown" placeholder will be provided. If
|
|
|
|
|
* the given Category already contains an "Unkown", we just get the
|
2007-09-12 06:53:12 +02:00
|
|
|
* corresponding smart-ptr. Otherwise a new asset::Unknown is created.
|
|
|
|
|
* @return an Media smart ptr linked to the internally registered smart ptr
|
|
|
|
|
* created as a side effect of calling the concrete Media subclass ctor.
|
|
|
|
|
*/
|
2007-09-10 06:45:36 +02:00
|
|
|
MediaFactory::PType
|
|
|
|
|
MediaFactory::operator() (Asset::Ident& key, const string& file)
|
|
|
|
|
{
|
|
|
|
|
asset::Media* pM (0);
|
|
|
|
|
AssetManager& aMang = AssetManager::instance();
|
2007-09-12 06:53:12 +02:00
|
|
|
|
2007-09-10 06:45:36 +02:00
|
|
|
TODO ("check and fix Category if necessary");
|
2007-09-12 06:53:12 +02:00
|
|
|
|
2007-09-10 06:45:36 +02:00
|
|
|
if (isnil (file))
|
|
|
|
|
{
|
|
|
|
|
if (isnil (key.name)) key.name="nil";
|
|
|
|
|
ID<Asset> id = aMang.getID (key);
|
|
|
|
|
if (aMang.known (id))
|
|
|
|
|
return aMang.getAsset(ID<Media>(id));
|
|
|
|
|
else
|
|
|
|
|
pM = new Unknown(key);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (isnil (key.name)) key.name=extractName(file);
|
|
|
|
|
TODO ("file exists?");
|
|
|
|
|
pM = new Media (key,file);
|
|
|
|
|
}
|
2007-09-12 06:53:12 +02:00
|
|
|
ASSERT (pM);
|
2007-09-10 06:45:36 +02:00
|
|
|
ENSURE (key.category.hasKind (VIDEO) || key.category.hasKind(AUDIO));
|
2007-09-16 17:17:54 +02:00
|
|
|
ENSURE (!isnil (key.name));
|
2007-09-10 06:45:36 +02:00
|
|
|
ENSURE (dynamic_cast<Media*>(pM) || (isnil (file) && dynamic_cast<Unknown*>(pM)));
|
|
|
|
|
|
2007-09-12 06:53:12 +02:00
|
|
|
return aMang.getAsset (pM->getID()); // note: because we query with an ID<Media>,
|
|
|
|
|
// we get a Media smart ptr.
|
2007-09-10 06:45:36 +02:00
|
|
|
}
|
2007-09-02 18:48:22 +02:00
|
|
|
|
2007-09-10 06:45:36 +02:00
|
|
|
|
|
|
|
|
/** Variant of the Factory method for Media Assets, automatically
|
|
|
|
|
* providing most of the Asset key fields based on the filename given
|
|
|
|
|
*/
|
|
|
|
|
MediaFactory::PType
|
2007-09-16 17:17:54 +02:00
|
|
|
MediaFactory::operator() (const string& file, const Category& cat)
|
2007-09-10 06:45:36 +02:00
|
|
|
{
|
|
|
|
|
Asset::Ident key(extractName(file), cat, "cin3", 1);
|
2007-09-12 06:53:12 +02:00
|
|
|
return operator() (key, file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaFactory::PType
|
|
|
|
|
MediaFactory::operator() (const string& file, asset::Kind kind)
|
|
|
|
|
{
|
|
|
|
|
Category cat(kind);
|
|
|
|
|
return operator() (file, cat);
|
2007-09-10 06:45:36 +02:00
|
|
|
}
|
2007-09-02 18:48:22 +02:00
|
|
|
|
2007-09-10 06:45:36 +02:00
|
|
|
|
|
|
|
|
MediaFactory::PType
|
2007-09-16 17:17:54 +02:00
|
|
|
MediaFactory::operator() (const char* file, const Category& cat)
|
2007-09-10 06:45:36 +02:00
|
|
|
{
|
|
|
|
|
if (!file) file = "";
|
2007-09-12 06:53:12 +02:00
|
|
|
return operator() (string(file),cat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaFactory::PType
|
|
|
|
|
MediaFactory::operator() (const char* file, asset::Kind kind)
|
|
|
|
|
{
|
|
|
|
|
if (!file) file = "";
|
|
|
|
|
return operator() (string(file),kind);
|
2007-09-10 06:45:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaFactory::PType
|
|
|
|
|
MediaFactory::operator() (Asset::Ident& key, const char* file)
|
|
|
|
|
{
|
|
|
|
|
if (!file) file = "";
|
2007-09-12 06:53:12 +02:00
|
|
|
return operator() (key, string(file));
|
2007-09-10 06:45:36 +02:00
|
|
|
}
|
|
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
|
|
|
|
|
} // namespace asset
|