Lumiera  0.pre.03
»edit your freedom«
media.cpp
Go to the documentation of this file.
1 /*
2  Media(Asset) - key abstraction: media-like assets
3 
4  Copyright (C)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
14 
20 #include "lib/error.hpp"
21 #include "steam/common.hpp"
22 #include "steam/assetmanager.hpp"
23 #include "steam/asset/media.hpp"
24 #include "steam/asset/clip.hpp"
25 #include "steam/asset/unknown.hpp"
27 #include "lib/time/timevalue.hpp"
28 #include "lib/format-string.hpp"
29 #include "lib/util.hpp"
30 #include "include/logging.h"
31 
32 #include <regex>
33 
34 
35 using util::_Fmt;
36 using util::isnil;
37 using lib::time::FSecs;
40 using backend_interface::MediaAccessFacade;
41 
42 using std::regex;
43 using std::smatch;
44 using std::regex_search;
45 using std::dynamic_pointer_cast;
46 
47 namespace error = lumiera::error;
48 
49 namespace steam {
50 namespace asset {
51 
52  namespace { // Implementation details
53 
58  string extractName (const string& path)
59  {
60  static regex PATHNAME_PATTERN("([^/\\.]+)(\\.\\w+)?$");
61  smatch match;
62 
63  if (regex_search (path, match, PATHNAME_PATTERN))
64  return util::sanitise (string (match[1]));
65  else
66  return "";
67  }
68  }
69 
70 
71 
72 
73 
76  {
77  PClipAsset clipAsset (getClipAsset());
78  PClip clipMO = clipAsset->createClip();
79 
80  ENSURE (clipMO->isValid());
81  return clipMO;
82  }
83 
84 
91  {
92  if (PMedia parent = this->checkCompound())
93  return parent->getClipAsset();
94  else
95  return Media::create(*this);
96  }
97 
98 
101  {
102  vector<PAsset> parents = this->getParents();
103  PMedia parent;
104  if ( !isnil (parents)) // primary parent is a media asset?
105  parent = dynamic_pointer_cast<Media,Asset> (parents[0]);
106  return parent;
107  }
108 
109 
112  {
113  UNIMPLEMENTED ("calculate and return processing pattern for media asset");
114  PProcPatt ppatt; //TODO:null
115 
116  ENSURE (ppatt);
117  return ppatt;
118  }
119 
120 
121  Duration
123  {
124  return len_;
125  }
126 
127 
128 
130 
131 
132 
142  MediaFactory::operator() (Asset::Ident& key, const string& file)
143  {
144  asset::Media* pM (0);
146 
148 
149  if (isnil (file))
150  {
151  if (isnil (key.name)) key.name="nil";
152  ID<Asset> id = aMang.getID (key);
153  if (aMang.known (id))
154  return aMang.getAsset(ID<Media>(id));
155  else
156  pM = new Unknown(key);
157  }
158  else
159  {
160  if (isnil (key.name)) key.name=extractName(file);
161 
162  MediaAccessFacade& maf = MediaAccessFacade::instance();
163  MediaDesc& handle = maf.queryFile(key.name);
164  Duration length = handle.length;
165 
167  pM = new Media (key,file,length);
168  }
169  ASSERT (pM);
170  ENSURE (key.category.hasKind (VIDEO) || key.category.hasKind(AUDIO));
171  ENSURE (!isnil (key.name));
172  ENSURE (dynamic_cast<Media*>(pM) || (isnil (file) && dynamic_cast<Unknown*>(pM)));
173 
174  return aMang.getAsset (pM->getID()); // note: because we query with an ID<Media>,
175  // we get a Media smart ptr.
176  }
177 
178 
183  MediaFactory::operator() (const string& file, const Category& cat)
184  {
185  Asset::Ident key(extractName(file), cat, "lumi", 1);
186  return operator() (key, file);
187  }
188 
190  MediaFactory::operator() (const string& file, asset::Kind kind)
191  {
192  Category cat(kind);
193  return operator() (file, cat);
194  }
195 
196 
198  MediaFactory::operator() (const char* file, const Category& cat)
199  {
200  if (!file) file = "";
201  return operator() (string(file),cat);
202  }
203 
205  MediaFactory::operator() (const char* file, asset::Kind kind)
206  {
207  if (!file) file = "";
208  return operator() (string(file),kind);
209  }
210 
212  MediaFactory::operator() (Asset::Ident& key, const char* file)
213  {
214  if (!file) file = "";
215  return operator() (key, string(file));
216  }
217 
218 
229  {
230  if (mediaref.checkCompound())
231  throw error::Invalid (_Fmt("Attempt to create a asset::Clip from the media %s, "
232  "which is not toplevel but rather part of a compound "
233  "(multichannel) media. Found parent Media %s.")
234  % mediaref
235  % *mediaref.checkCompound()
236  ,LUMIERA_ERROR_PART_OF_COMPOUND);
237  Clip* pC = new Clip (mediaref);
238  return AssetManager::instance().wrap (*pC);
239  }
240 
241  LUMIERA_ERROR_DEFINE (PART_OF_COMPOUND, "part of compound used as toplevel element");
242 
243 
244 
245 
246 }} // namespace asset
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:82
static ID< Asset > getID(const Asset::Ident &)
provide the unique ID for given Asset::Ident tuple
Basic set of definitions and includes commonly used together.
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:155
PType operator()(Asset::Ident &key, const string &file="")
Factory method for Media Asset instances.
Definition: media.cpp:142
Steam-Layer Interface: Asset Lookup and Organisation.
PClip createClip()
Service Access Point for creating a Clip entity usable within the Session from a given Media or Clip ...
Definition: media.cpp:75
key abstraction: media-like assets
Definition: media.hpp:63
Media data represented a specific kind of Asset.
Tree like classification of Assets.
Definition: category.hpp:66
virtual const ID< Media > & getID() const
<
Definition: media.hpp:78
Descriptor holding the global information record required for further handling this kind of media wit...
Front-end for printf-style string template interpolation.
virtual PClipAsset getClipAsset()
get or create the correct asset::Clip corresponding to this media
Definition: media.cpp:90
Facade for the Asset subsystem.
This header is for including and configuring NoBug.
static MediaFactory create
storage for the static MediaFactory instance
Definition: media.hpp:75
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
Factory specialised for creating Media Asset objects.
Definition: media.hpp:134
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:149
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
ElementBoxWidget::Config::Qualifier kind(Kind kind)
qualify the basic use case for the new ElementBoxWidget
virtual Duration getLength() const
Definition: media.cpp:122
Placeholder Asset for unknown or unavailable media source.
Definition: unknown.hpp:45
Superinterface describing especially bookkeeping properties.
Definition: asset.hpp:139
Marker Asset to indicate an unknown media source.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:220
Definition of Asset representation for a media clip.
Lumiera error handling (C++ interface).
const vector< PAsset > & getParents() const
List of entities this asset depends on or requires to be functional.
Definition: asset.hpp:276
Kind
top-level distinction of different Kinds of Assets.
Definition: category.hpp:46
lib::P< KIND > getAsset(const ID< KIND > &id)
find and return corresponding object
bookkeeping (Asset) view of a media clip.
Definition: asset/clip.hpp:35
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
PProcPatt howtoProc() const
Service Access Point for getting a processing template describing how to build the render nodes netwo...
Definition: media.cpp:111
string extractName(const string &path)
helper: extract a name token out of a given path/filename
Definition: media.cpp:58
a family of time value like entities and their relationships.
asset::Category category
primary tree like classification of the asset.
Definition: asset.hpp:160
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:35
virtual PMedia checkCompound() const
predicate to decide if this asset::Media is part of a compound (multichannel) media.
Definition: media.cpp:100
Abstraction interface to query for a media file.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:71