00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "pre.hpp"
00025 #include "proc/assetmanager.hpp"
00026 #include "proc/asset/media.hpp"
00027 #include "proc/asset/clip.hpp"
00028 #include "proc/asset/unknown.hpp"
00029 #include "proc/mobject/session/clip.hpp"
00030 #include "proc/mobject/session/mobjectfactory.hpp"
00031 #include "lib/util.hpp"
00032 #include "include/nobugcfg.h"
00033
00034 #include <boost/regex.hpp>
00035 #include <boost/format.hpp>
00036
00037
00038 using util::isnil;
00039
00040 using boost::format;
00041 using boost::regex;
00042 using boost::smatch;
00043 using boost::regex_search;
00044 using std::tr1::dynamic_pointer_cast;
00045
00046
00047 namespace asset
00048 {
00049
00050 namespace
00051 {
00056 string extractName (const string& path)
00057 {
00058 regex pathname_pattern("([^/\\.]+)(\\.\\w+)?$");
00059 smatch match;
00060
00061 if (regex_search (path, match, pathname_pattern))
00062 return util::sanitize (string (match[1]));
00063 else
00064 return "";
00065 }
00066 }
00067
00068
00069
00070
00071
00072 Media::PClipMO
00073 Media::createClip ()
00074 {
00075 PClip clipAsset (getClipAsset());
00076 PClipMO clipMO = clipAsset->createClip();
00077
00078 ENSURE (clipMO->isValid());
00079 return clipMO;
00080 }
00081
00082
00087 Media::PClip
00088 Media::getClipAsset ()
00089 {
00090 if (PMedia parent = this->checkCompound())
00091 return parent->getClipAsset();
00092 else
00093 return Media::create(*this);
00094 }
00095
00096
00097 Media::PMedia
00098 Media::checkCompound() const
00099 {
00100 vector<PAsset> parents = this->getParents();
00101 PMedia parent;
00102 if ( !isnil (parents))
00103 parent = dynamic_pointer_cast<Media,Asset> (parents[0]);
00104 return parent;
00105 }
00106
00107
00108 Media::PProcPatt
00109 Media::howtoProc () const
00110 {
00111 UNIMPLEMENTED ("calculate and return processing pattern for media asset");
00112 PProcPatt ppatt;
00113
00114 ENSURE (ppatt);
00115 return ppatt;
00116 }
00117
00118
00119 lumiera::Time
00120 Media::getLength() const
00121 {
00122 return len_;
00123 }
00124
00125
00126
00127 MediaFactory Media::create;
00128
00129
00130
00138 MediaFactory::PType
00139 MediaFactory::operator() (Asset::Ident& key, const string& file)
00140 {
00141 asset::Media* pM (0);
00142 AssetManager& aMang = AssetManager::instance();
00143
00144 TODO ("check and fix Category if necessary");
00145
00146 if (isnil (file))
00147 {
00148 if (isnil (key.name)) key.name="nil";
00149 ID<Asset> id = aMang.getID (key);
00150 if (aMang.known (id))
00151 return aMang.getAsset(ID<Media>(id));
00152 else
00153 pM = new Unknown(key);
00154 }
00155 else
00156 {
00157 if (isnil (key.name)) key.name=extractName(file);
00158 TODO ("file exists?");
00159 TODO ("extract media file properties");
00160 Time length(25);
00161 TODO ("detecting and wiring multichannel compound media!");
00162 pM = new Media (key,file,length);
00163 }
00164 ASSERT (pM);
00165 ENSURE (key.category.hasKind (VIDEO) || key.category.hasKind(AUDIO));
00166 ENSURE (!isnil (key.name));
00167 ENSURE (dynamic_cast<Media*>(pM) || (isnil (file) && dynamic_cast<Unknown*>(pM)));
00168
00169 return aMang.getAsset (pM->getID());
00170
00171 }
00172
00173
00177 MediaFactory::PType
00178 MediaFactory::operator() (const string& file, const Category& cat)
00179 {
00180 Asset::Ident key(extractName(file), cat, "lumi", 1);
00181 return operator() (key, file);
00182 }
00183
00184 MediaFactory::PType
00185 MediaFactory::operator() (const string& file, asset::Kind kind)
00186 {
00187 Category cat(kind);
00188 return operator() (file, cat);
00189 }
00190
00191
00192 MediaFactory::PType
00193 MediaFactory::operator() (const char* file, const Category& cat)
00194 {
00195 if (!file) file = "";
00196 return operator() (string(file),cat);
00197 }
00198
00199 MediaFactory::PType
00200 MediaFactory::operator() (const char* file, asset::Kind kind)
00201 {
00202 if (!file) file = "";
00203 return operator() (string(file),kind);
00204 }
00205
00206 MediaFactory::PType
00207 MediaFactory::operator() (Asset::Ident& key, const char* file)
00208 {
00209 if (!file) file = "";
00210 return operator() (key, string(file));
00211 }
00212
00213
00222 P<asset::Clip>
00223 MediaFactory::operator() (asset::Media& mediaref) throw(lumiera::error::Invalid)
00224 {
00225 if (mediaref.checkCompound())
00226 throw lumiera::error::Invalid (str(format("Attempt to create a asset::Clip from the media %s, "
00227 "which is not toplevel but rather part or a compound "
00228 "(multichannel) media. Found parent Media %s.")
00229 % string(mediaref)
00230 % string(*mediaref.checkCompound()))
00231 ,LUMIERA_ERROR_PART_OF_COMPOUND
00232 );
00233 asset::Clip* pC = new asset::Clip (mediaref);
00234 return AssetManager::instance().wrap (*pC);
00235 }
00236
00237 LUMIERA_ERROR_DEFINE (PART_OF_COMPOUND, "part of compound used as toplevel element");
00238
00239
00240
00241
00242 }