Asset/Clip now using the dependency relation.

DependantAssets_test now complete, finally...
This commit is contained in:
Fischlurch 2007-11-26 04:27:27 +01:00
parent 855d0706d9
commit 940d6de201
19 changed files with 123 additions and 84 deletions

View file

@ -96,7 +96,7 @@ namespace util
* in any sequencial container */
template <typename SEQ>
inline bool
contains (SEQ& cont, typename SEQ::value_type& val)
contains (SEQ& cont, typename SEQ::const_reference val)
{
typename SEQ::const_iterator begin = cont.begin();
typename SEQ::const_iterator end = cont.end();
@ -128,6 +128,22 @@ namespace util
}
/** shortcut for testing all elements of a collection
* with the given predicate.
*/
template <typename SEQ, typename Oper>
inline bool
and_all (SEQ& coll, Oper predicate)
{
typename SEQ::const_iterator e = coll.end();
typename SEQ::const_iterator i = coll.begin();
while (i!=e && predicate(*i)) ++i;
return i==e;
}
/** produce an identifier based on the given string.
* remove non-standard-chars, reduce sequences of punctuation

View file

@ -36,6 +36,7 @@ using boost::function;
using util::contains;
using util::removeall;
using util::for_each;
using util::and_all;
using util::cStr;
@ -52,7 +53,7 @@ namespace asset
* concrete subclasses are created via specialized Factories
*/
Asset::Asset (const Ident& idi)
: ident(idi), id(AssetManager::reg (this, idi)), disabled(false)
: ident(idi), id(AssetManager::reg (this, idi)), enabled(true)
{
TRACE (assetmem, "ctor Asset(id=%lu) : adr=%x %s", size_t(id), this, cStr(this->ident) );
}
@ -76,35 +77,18 @@ namespace asset
return str (id_tuple % ident.name % ident.category % ident.org % ident.version);
}
//////////////////////////////////////////////////////////TODO: factor this out as library function
template <typename SEQ, typename Oper>
inline bool
and_all (SEQ& coll, Oper predicate)
{
typename SEQ::const_iterator e = coll.end();
typename SEQ::const_iterator i = coll.begin();
while (i!=e && predicate(*i)) ++i;
return i==e;
}
template<class V>
inline const V*
deref (const shared_ptr<V>& ptr)
{
return ptr.get();
}
//////////////////////////////////////////////////////////TODO: factor this out as library function
function<bool(const PAsset&)> check_isActive
= bind ( &Asset::isActive
, bind (&PAsset::get, _1 )
);
bool
all_parents_enabled (const vector<PAsset>& parents)
{
return and_all (parents, bind (&Asset::isActive,
bind (&deref<Asset>,_1) )); //////////TODO: possibly define an operator->
return and_all (parents, check_isActive);
}
/**
@ -114,29 +98,30 @@ namespace asset
bool
Asset::isActive () const
{
return !this->disabled
return this->enabled
&& all_parents_enabled (parents);
}
void
propagate_down (PAsset child, bool on)
{
child->enable(on);
}
/**change the enablement status of this asset. */
bool
Asset::enable (bool on) throw(cinelerra::error::State)
{
if (on != this->disabled)
if (on == this->enabled)
return true;
if (on && !all_parents_enabled (parents))
return false;
disabled = !on;
// can indeed to do the toggle...
this->enabled = on;
for_each (dependants, bind (&propagate_down, _1 ,on));
return true; ////////TODO??
return true;
}
@ -184,6 +169,14 @@ namespace asset
parents.push_back (parent);
parent->dependants.push_back(p_this);
}
void
Asset::defineDependency (Asset& parent)
{
PAsset p_parent (AssetManager::getPtr(parent));
ASSERT (p_parent);
defineDependency (p_parent);
}
} // namespace asset

View file

@ -106,6 +106,7 @@ namespace asset
class AssetManager;
typedef const ID<Asset>& IDA;
typedef shared_ptr<Asset> PAsset;
typedef shared_ptr<const Asset> PcAsset;
@ -216,7 +217,7 @@ namespace asset
vector<PAsset> parents;
vector<PAsset> dependants;
bool disabled;
bool enabled;
@ -246,7 +247,8 @@ namespace asset
/** establish a connection between this and the given parent asset,
* denoting we are in some way dependant on the parent. */
virtual void defineDependency (PAsset parent);
void defineDependency (PAsset parent);
void defineDependency (Asset& parent);
friend class AssetManager;
friend class DB;
@ -307,7 +309,7 @@ namespace asset
/** convienient for debugging */
inline string str (const PAsset& a)
inline string str (PcAsset& a)
{
if (a)
return string (*a.get());

View file

@ -59,14 +59,14 @@ namespace asset
Clip::Clip (const Media& mediaref)
Clip::Clip (Media& mediaref)
: Media (createClipIdent (mediaref),
mediaref.getFilename(),
mediaref.getLength())
, source_ (mediaref)
, clipMO_ (createClipMO (*this, source_))
{
this->defineDependency (mediaref);
}

View file

@ -38,15 +38,14 @@ namespace asset
/** media source of this clip */
const Media& source_;
/** the corresponding (dependant) clip-MO
* @todo seems to be obsolete by the reworked design of multichannel media 11/07 */
/** the corresponding (dependant) clip-MO */
PClipMO clipMO_;
public:
virtual PClipMO createClip () const;
protected:
Clip (const Media& mediaref);
Clip (Media& mediaref);
friend class MediaFactory;
virtual PClip getClipAsset ();

View file

@ -137,7 +137,7 @@ namespace asset
/** intended for diagnostics */
void
asList (list<PAsset>& output) const
asList (list<PcAsset>& output) const
{
IdHashtable::const_iterator i = table.begin();
IdHashtable::const_iterator e = table.end();

View file

@ -213,12 +213,13 @@ namespace asset
/** Factory method for creating a Clip asset based
* on the given Media asset. This asset::Clip can be used
* to create clip in the EDL covering the whole length of
* this media.
* this media.
* @note creates a dependency between media and new clip
* @throw Invalid if the given media asset is not top-level,
* but rather part or a multichannel (compound) media
*/
shared_ptr<asset::Clip>
MediaFactory::operator() (const asset::Media& mediaref) throw(cinelerra::error::Invalid)
MediaFactory::operator() (asset::Media& mediaref) throw(cinelerra::error::Invalid)
{
if (mediaref.checkCompound())
throw cinelerra::error::Invalid (str(format("Attempt to create a asset::Clip from the media %s, "

View file

@ -73,7 +73,7 @@ namespace asset
public:
typedef shared_ptr<Media> PMedia;
typedef shared_ptr<const asset::Clip> PClip;
typedef shared_ptr<asset::Clip> PClip;
typedef shared_ptr<asset::ProcPatt> PProcPatt;
typedef mobject::session::PClipMO PClipMO;
@ -86,6 +86,13 @@ namespace asset
return static_cast<const ID<Media>& > (Asset::getID());
}
/** Service Access Point for getting a processing template
* describing how to build the render nodes network
* necessary for this Media or Clip. This includes
* Codecs and postprocessing (stretching, deinterlacing...)
*/
PProcPatt howtoProc () const;
/** Service Access Point for creating a Clip entity usable within
* the EDL/Session from a given Media or Clip Asset. As a sideeffect,
* a corresponding asset::Clip is created as well if necessary.
@ -95,13 +102,6 @@ namespace asset
*/
PClipMO createClip ();
/** Service Access Point for getting a processing template
* describing how to build the render nodes network
* necessary for this Media or Clip. This includes
* Codecs and postprocessing (stretching, deinterlacing...)
*/
PProcPatt howtoProc () const;
/** @return the overall length of the media represented by this asset */
virtual Time getLength () const;
@ -151,7 +151,7 @@ namespace asset
PType operator() (const char* file, asset::Kind);
shared_ptr<asset::Clip>
operator() (const asset::Media& mediaref) throw(cinelerra::error::Invalid);
operator() (asset::Media& mediaref) throw(cinelerra::error::Invalid);
};

View file

@ -52,12 +52,14 @@ namespace asset
/** create a preview placeholder ("proxy media") for the given
* media asset. The name of the created media asset is derived
* by decorating the original media's name.
* @note creates a dependency between the media and this proxy
*/
Preview::Preview (const Media& mediaref)
Preview::Preview (Media& mediaref)
: Unknown (createProxyIdent (mediaref.ident),
mediaref.getFilename(),
mediaref.getLength())
{
this->defineDependency (mediaref);
UNIMPLEMENTED ("do something to setup proxy media");
}

View file

@ -38,7 +38,7 @@ namespace asset
class Preview : public Unknown
{
protected:
Preview (const Media& mediaref);
Preview (Media& mediaref);
friend class MediaFactory;
};

View file

@ -34,7 +34,9 @@ namespace asset
/** create a placeholder for a media with the given identity.
* the denoted original media (identity) can be accessed later
* on using the Unknown::getOrg() function */
* on using the Unknown::getOrg() function.
* @note we don't depend on the refered media...
*/
Unknown::Unknown (const Asset::Ident& idi, string name, Time length)
: Media (idi, name, length)
{

View file

@ -213,10 +213,10 @@ namespace asset
list<PAsset>
list<PcAsset>
AssetManager::listContent() const
{
list<PAsset> res;
list<PcAsset> res;
registry.asList (res);
res.sort();
return res;
@ -233,6 +233,7 @@ namespace asset
/************************************************************/
#include "proc/asset/media.hpp"
#include "proc/asset/clip.hpp"
#include "proc/asset/proc.hpp"
#include "proc/asset/struct.hpp"
#include "proc/asset/meta.hpp"
@ -252,6 +253,7 @@ namespace asset
template shared_ptr<Asset> AssetManager::getPtr (const Asset& asset);
template shared_ptr<Media> AssetManager::getPtr (const Media& asset);
template shared_ptr<Clip> AssetManager::getPtr (const Clip& asset);
} // namespace asset

View file

@ -91,7 +91,7 @@ namespace asset
void remove (IDA id) ;
/** extract a sorted list of all registered Assets */
list<PAsset> listContent() const;
list<PcAsset> listContent() const;

View file

@ -68,6 +68,14 @@ namespace mobject
{
return asset::AssetManager::getPtr (mediaDef_);
}
PClipAsset
Clip::findClipAsset () const
{
return asset::AssetManager::getPtr (clipDef_);
}

View file

@ -39,6 +39,7 @@ namespace mobject
{
using asset::Media;
typedef shared_ptr<Media> PMedia;
typedef shared_ptr<asset::Clip> PClipAsset;
/**
@ -74,6 +75,12 @@ namespace mobject
/** access the underlying media asset */
PMedia getMedia () const;
/** locate the corresponding asset
* representing this clip or the whole
* compound in case of a multichannel clip
*/
PClipAsset findClipAsset () const;
};
typedef Placement<Clip> PClipMO;

View file

@ -43,7 +43,6 @@ namespace mobject
class Clip;
class Effect;
typedef shared_ptr<const asset::Clip> PClipAsset;
class MObjectFactory
{

View file

@ -40,6 +40,7 @@
#include <boost/bind.hpp>
#include <iostream>
using util::contains;
using util::for_each;
using boost::format;
using boost::bind;
@ -50,7 +51,8 @@ using std::cout;
namespace asset
{
inline void dump (const PAsset& aa)
inline void
dump (PcAsset& aa)
{
if (!aa)
cout << "Asset(NULL)\n";
@ -60,12 +62,26 @@ namespace asset
cout << fmt % str(aa) % aa->getID() % aa.get() % &aa % (aa.use_count() - 1) << "\n";
} }
inline void dumpAssetManager ()
inline void
dumpAssetManager ()
{
list<PAsset> assets (AssetManager::instance().listContent());
list<PcAsset> assets (AssetManager::instance().listContent());
cout << "----all-registered-Assets----\n";
for_each (assets, bind (&dump, _1));
}
template<class C, class P>
inline bool
dependencyCheck (C child, P parent)
{
return (child == parent)
|| (0 < child->getParents().size()
&& (parent == child->getParents()[0])
&& (contains (parent->getDependant(), child)));
;
}

View file

@ -23,15 +23,14 @@
#include "common/test/run.hpp"
#include "proc/asset/testasset.hpp"
#include "proc/asset/assetdiagnostics.hpp"
#include "proc/asset/media.hpp"
#include "proc/asset/clip.hpp"
#include "common/util.hpp"
//#include <boost/format.hpp>
#include <iostream>
using util::isnil;
using util::contains;
//using boost::format;
using std::string;
using util::isnil;
namespace asset
@ -54,13 +53,13 @@ namespace asset
{
checkDependencyMechanics ();
checkUnlinking ();
TODO ("activate missing testcases");
checkEnablementPropagation ();
/////TODO checkRealAssetDependencyRegistration ();
checkRealAssetDependencyRegistration ();
}
typedef TestAsset<Asset> TA;
typedef TA::PA PTestA;
/** @test check operation of basic asset dependency support
*/
@ -74,8 +73,6 @@ namespace asset
ASSERT (a1 == a2->getParents()[0]); // TestAsset registered a1 as parent
ASSERT (a2 == a1->getDependant()[0]);
TRACE(test, "a1.cnt=%i",a1.use_count());
TRACE(test, "a2.cnt=%i",a2.use_count());
PAsset a3 = TA::create();
a2->set_depend(a3);
ASSERT (a3 == a2->getParents()[1]);
@ -196,7 +193,13 @@ namespace asset
*/
void checkRealAssetDependencyRegistration ()
{
UNIMPLEMENTED ("handling of Asset dependencies");
// -----Media and Clip--------------------------------
typedef Media::PMedia PM;
typedef Media::PClip PC;
PM mm = asset::Media::create("test-1", VIDEO);
PC cc = mm->createClip()->findClipAsset();
ASSERT (dependencyCheck (cc,mm));
}
};

View file

@ -27,8 +27,7 @@
#include "proc/assetmanager.hpp"
#include "proc/asset/media.hpp"
#include "proc/mobject/session/clip.hpp"
//#include "proc/asset/assetdiagnostics.hpp"
#include "proc/asset/assetdiagnostics.hpp"
using util::contains;
using util::isnil;
@ -68,22 +67,12 @@ namespace asset
TODO ("implement Processing Pattern!!!");
// ASSERT (cm->howtoProc() == mm->howtoProc());
ASSERT (cm->ident.org == mm->ident.org);
ASSERT (dependencyCheck (mm,cm));
ASSERT (dependencyCheck (cm,mm));
TRACE (assetmem, "leaving MakeClip_test::run()");
TRACE (mobjectmem, "leaving MakeClip_test::run()");
}
bool dependencyCheck (PM media, PM clip)
{
TODO ("check asset dependencies, when this feature is implemented");
return true; //TODO
return (0 < clip->getParents().size())
&& (media == clip->getParents()[0])
// && (contains (media->getDependant(), clip)); //TODO implement Asset dependecies
;
}
};