From 940d6de201099472d4062c195bb0e550f1c8f3ee Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 26 Nov 2007 04:27:27 +0100 Subject: [PATCH] Asset/Clip now using the dependency relation. DependantAssets_test now complete, finally... --- src/common/util.hpp | 18 ++++++- src/proc/asset.cpp | 51 ++++++++----------- src/proc/asset.hpp | 8 +-- src/proc/asset/clip.cpp | 4 +- src/proc/asset/clip.hpp | 5 +- src/proc/asset/db.hpp | 2 +- src/proc/asset/media.cpp | 5 +- src/proc/asset/media.hpp | 18 +++---- src/proc/asset/preview.cpp | 4 +- src/proc/asset/preview.hpp | 2 +- src/proc/asset/unknown.cpp | 4 +- src/proc/assetmanager.cpp | 6 ++- src/proc/assetmanager.hpp | 2 +- src/proc/mobject/session/clip.cpp | 8 +++ src/proc/mobject/session/clip.hpp | 7 +++ src/proc/mobject/session/mobjectfactory.hpp | 1 - .../proc/asset/assetdiagnostics.hpp | 22 ++++++-- .../proc/asset/dependantassetstest.cpp | 25 +++++---- tests/components/proc/asset/makecliptest.cpp | 15 +----- 19 files changed, 123 insertions(+), 84 deletions(-) diff --git a/src/common/util.hpp b/src/common/util.hpp index 6d5119b14..4857382d6 100644 --- a/src/common/util.hpp +++ b/src/common/util.hpp @@ -96,7 +96,7 @@ namespace util * in any sequencial container */ template 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 + 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 diff --git a/src/proc/asset.cpp b/src/proc/asset.cpp index 1fb15ce47..5ca25754e 100644 --- a/src/proc/asset.cpp +++ b/src/proc/asset.cpp @@ -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 - 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 - inline const V* - deref (const shared_ptr& ptr) - { - return ptr.get(); - } - - //////////////////////////////////////////////////////////TODO: factor this out as library function + function check_isActive + = bind ( &Asset::isActive + , bind (&PAsset::get, _1 ) + ); bool all_parents_enabled (const vector& parents) { - return and_all (parents, bind (&Asset::isActive, - bind (&deref,_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 diff --git a/src/proc/asset.hpp b/src/proc/asset.hpp index e915067a7..4173cf31b 100644 --- a/src/proc/asset.hpp +++ b/src/proc/asset.hpp @@ -106,6 +106,7 @@ namespace asset class AssetManager; typedef const ID& IDA; typedef shared_ptr PAsset; + typedef shared_ptr PcAsset; @@ -216,7 +217,7 @@ namespace asset vector parents; vector 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()); diff --git a/src/proc/asset/clip.cpp b/src/proc/asset/clip.cpp index 4de320bf4..1fee2b091 100644 --- a/src/proc/asset/clip.cpp +++ b/src/proc/asset/clip.cpp @@ -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); } diff --git a/src/proc/asset/clip.hpp b/src/proc/asset/clip.hpp index 80392f290..142f73fdc 100644 --- a/src/proc/asset/clip.hpp +++ b/src/proc/asset/clip.hpp @@ -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 (); diff --git a/src/proc/asset/db.hpp b/src/proc/asset/db.hpp index 6e8914ec9..c0ba4b19f 100644 --- a/src/proc/asset/db.hpp +++ b/src/proc/asset/db.hpp @@ -137,7 +137,7 @@ namespace asset /** intended for diagnostics */ void - asList (list& output) const + asList (list& output) const { IdHashtable::const_iterator i = table.begin(); IdHashtable::const_iterator e = table.end(); diff --git a/src/proc/asset/media.cpp b/src/proc/asset/media.cpp index 6d61d7004..05f4417ad 100644 --- a/src/proc/asset/media.cpp +++ b/src/proc/asset/media.cpp @@ -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 - 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, " diff --git a/src/proc/asset/media.hpp b/src/proc/asset/media.hpp index defaf51b2..3ba17ec52 100644 --- a/src/proc/asset/media.hpp +++ b/src/proc/asset/media.hpp @@ -73,7 +73,7 @@ namespace asset public: typedef shared_ptr PMedia; - typedef shared_ptr PClip; + typedef shared_ptr PClip; typedef shared_ptr PProcPatt; typedef mobject::session::PClipMO PClipMO; @@ -86,6 +86,13 @@ namespace asset return static_cast& > (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 - operator() (const asset::Media& mediaref) throw(cinelerra::error::Invalid); + operator() (asset::Media& mediaref) throw(cinelerra::error::Invalid); }; diff --git a/src/proc/asset/preview.cpp b/src/proc/asset/preview.cpp index d626d7525..e2a920d57 100644 --- a/src/proc/asset/preview.cpp +++ b/src/proc/asset/preview.cpp @@ -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"); } diff --git a/src/proc/asset/preview.hpp b/src/proc/asset/preview.hpp index 0d2176b5e..462e9149d 100644 --- a/src/proc/asset/preview.hpp +++ b/src/proc/asset/preview.hpp @@ -38,7 +38,7 @@ namespace asset class Preview : public Unknown { protected: - Preview (const Media& mediaref); + Preview (Media& mediaref); friend class MediaFactory; }; diff --git a/src/proc/asset/unknown.cpp b/src/proc/asset/unknown.cpp index 3e3620cdc..48194d878 100644 --- a/src/proc/asset/unknown.cpp +++ b/src/proc/asset/unknown.cpp @@ -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) { diff --git a/src/proc/assetmanager.cpp b/src/proc/assetmanager.cpp index 617d45f46..c59354cf2 100644 --- a/src/proc/assetmanager.cpp +++ b/src/proc/assetmanager.cpp @@ -213,10 +213,10 @@ namespace asset - list + list AssetManager::listContent() const { - list res; + list 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 AssetManager::getPtr (const Asset& asset); template shared_ptr AssetManager::getPtr (const Media& asset); + template shared_ptr AssetManager::getPtr (const Clip& asset); } // namespace asset diff --git a/src/proc/assetmanager.hpp b/src/proc/assetmanager.hpp index 01e21447c..71988cd0d 100644 --- a/src/proc/assetmanager.hpp +++ b/src/proc/assetmanager.hpp @@ -91,7 +91,7 @@ namespace asset void remove (IDA id) ; /** extract a sorted list of all registered Assets */ - list listContent() const; + list listContent() const; diff --git a/src/proc/mobject/session/clip.cpp b/src/proc/mobject/session/clip.cpp index 68333f36e..0ce3894ae 100644 --- a/src/proc/mobject/session/clip.cpp +++ b/src/proc/mobject/session/clip.cpp @@ -68,6 +68,14 @@ namespace mobject { return asset::AssetManager::getPtr (mediaDef_); } + + + PClipAsset + Clip::findClipAsset () const + { + return asset::AssetManager::getPtr (clipDef_); + } + diff --git a/src/proc/mobject/session/clip.hpp b/src/proc/mobject/session/clip.hpp index 0843de9d5..a4e0c7271 100644 --- a/src/proc/mobject/session/clip.hpp +++ b/src/proc/mobject/session/clip.hpp @@ -39,6 +39,7 @@ namespace mobject { using asset::Media; typedef shared_ptr PMedia; + typedef shared_ptr 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 PClipMO; diff --git a/src/proc/mobject/session/mobjectfactory.hpp b/src/proc/mobject/session/mobjectfactory.hpp index aeb267f3a..e8fe05794 100644 --- a/src/proc/mobject/session/mobjectfactory.hpp +++ b/src/proc/mobject/session/mobjectfactory.hpp @@ -43,7 +43,6 @@ namespace mobject class Clip; class Effect; - typedef shared_ptr PClipAsset; class MObjectFactory { diff --git a/tests/components/proc/asset/assetdiagnostics.hpp b/tests/components/proc/asset/assetdiagnostics.hpp index 3fcd89c7a..e4147f3a4 100644 --- a/tests/components/proc/asset/assetdiagnostics.hpp +++ b/tests/components/proc/asset/assetdiagnostics.hpp @@ -40,6 +40,7 @@ #include #include +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 assets (AssetManager::instance().listContent()); + list assets (AssetManager::instance().listContent()); cout << "----all-registered-Assets----\n"; for_each (assets, bind (&dump, _1)); } + + + template + inline bool + dependencyCheck (C child, P parent) + { + return (child == parent) + || (0 < child->getParents().size() + && (parent == child->getParents()[0]) + && (contains (parent->getDependant(), child))); + ; + } + diff --git a/tests/components/proc/asset/dependantassetstest.cpp b/tests/components/proc/asset/dependantassetstest.cpp index 52611b692..49c5510a2 100644 --- a/tests/components/proc/asset/dependantassetstest.cpp +++ b/tests/components/proc/asset/dependantassetstest.cpp @@ -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 -#include - -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 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)); + } }; diff --git a/tests/components/proc/asset/makecliptest.cpp b/tests/components/proc/asset/makecliptest.cpp index 55c8e8376..5ec6a76bc 100644 --- a/tests/components/proc/asset/makecliptest.cpp +++ b/tests/components/proc/asset/makecliptest.cpp @@ -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 - ; - } };