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) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
29 #include "lib/error.hpp"
30 #include "steam/common.hpp"
31 #include "steam/assetmanager.hpp"
32 #include "steam/asset/media.hpp"
33 #include "steam/asset/clip.hpp"
34 #include "steam/asset/unknown.hpp"
36 #include "lib/time/timevalue.hpp"
37 #include "lib/format-string.hpp"
38 #include "lib/util.hpp"
39 #include "include/logging.h"
40 
41 #include <regex>
42 
43 
44 using util::_Fmt;
45 using util::isnil;
46 using lib::time::FSecs;
48 using backend_interface::MediaDesc;
50 
51 using std::regex;
52 using std::smatch;
53 using std::regex_search;
54 using std::dynamic_pointer_cast;
55 
56 namespace error = lumiera::error;
57 
58 namespace steam {
59 namespace asset {
60 
61  namespace { // Implementation details
62 
67  string extractName (const string& path)
68  {
69  static regex PATHNAME_PATTERN("([^/\\.]+)(\\.\\w+)?$");
70  smatch match;
71 
72  if (regex_search (path, match, PATHNAME_PATTERN))
73  return util::sanitise (string (match[1]));
74  else
75  return "";
76  }
77  }
78 
79 
80 
81 
82 
85  {
86  PClipAsset clipAsset (getClipAsset());
87  PClip clipMO = clipAsset->createClip();
88 
89  ENSURE (clipMO->isValid());
90  return clipMO;
91  }
92 
93 
100  {
101  if (PMedia parent = this->checkCompound())
102  return parent->getClipAsset();
103  else
104  return Media::create(*this);
105  }
106 
107 
110  {
111  vector<PAsset> parents = this->getParents();
112  PMedia parent;
113  if ( !isnil (parents)) // primary parent is a media asset?
114  parent = dynamic_pointer_cast<Media,Asset> (parents[0]);
115  return parent;
116  }
117 
118 
121  {
122  UNIMPLEMENTED ("calculate and return processing pattern for media asset");
123  PProcPatt ppatt; //TODO:null
124 
125  ENSURE (ppatt);
126  return ppatt;
127  }
128 
129 
130  Duration
132  {
133  return len_;
134  }
135 
136 
137 
139 
140 
141 
151  MediaFactory::operator() (Asset::Ident& key, const string& file)
152  {
153  asset::Media* pM (0);
155 
157 
158  if (isnil (file))
159  {
160  if (isnil (key.name)) key.name="nil";
161  ID<Asset> id = aMang.getID (key);
162  if (aMang.known (id))
163  return aMang.getAsset(ID<Media>(id));
164  else
165  pM = new Unknown(key);
166  }
167  else
168  {
169  if (isnil (key.name)) key.name=extractName(file);
170 
171  MediaAccessFacade& maf = MediaAccessFacade::instance();
172  MediaDesc& handle = maf.queryFile(key.name);
173  Duration length = handle.length;
174 
176  pM = new Media (key,file,length);
177  }
178  ASSERT (pM);
179  ENSURE (key.category.hasKind (VIDEO) || key.category.hasKind(AUDIO));
180  ENSURE (!isnil (key.name));
181  ENSURE (dynamic_cast<Media*>(pM) || (isnil (file) && dynamic_cast<Unknown*>(pM)));
182 
183  return aMang.getAsset (pM->getID()); // note: because we query with an ID<Media>,
184  // we get a Media smart ptr.
185  }
186 
187 
192  MediaFactory::operator() (const string& file, const Category& cat)
193  {
194  Asset::Ident key(extractName(file), cat, "lumi", 1);
195  return operator() (key, file);
196  }
197 
199  MediaFactory::operator() (const string& file, asset::Kind kind)
200  {
201  Category cat(kind);
202  return operator() (file, cat);
203  }
204 
205 
207  MediaFactory::operator() (const char* file, const Category& cat)
208  {
209  if (!file) file = "";
210  return operator() (string(file),cat);
211  }
212 
214  MediaFactory::operator() (const char* file, asset::Kind kind)
215  {
216  if (!file) file = "";
217  return operator() (string(file),kind);
218  }
219 
221  MediaFactory::operator() (Asset::Ident& key, const char* file)
222  {
223  if (!file) file = "";
224  return operator() (key, string(file));
225  }
226 
227 
238  {
239  if (mediaref.checkCompound())
240  throw error::Invalid (_Fmt("Attempt to create a asset::Clip from the media %s, "
241  "which is not toplevel but rather part of a compound "
242  "(multichannel) media. Found parent Media %s.")
243  % mediaref
244  % *mediaref.checkCompound()
245  ,LERR_(PART_OF_COMPOUND));
246  Clip* pC = new Clip (mediaref);
247  return AssetManager::instance().wrap (*pC);
248  }
249 
250  LUMIERA_ERROR_DEFINE (PART_OF_COMPOUND, "part of compound used as toplevel element");
251 
252 
253 
254 
255 }} // namespace asset
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:89
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:164
PType operator()(Asset::Ident &key, const string &file="")
Factory method for Media Asset instances.
Definition: media.cpp:151
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:84
key abstraction: media-like assets
Definition: media.hpp:72
Media data represented a specific kind of Asset.
Tree like classification of Assets.
Definition: category.hpp:75
virtual const ID< Media > & getID() const
<
Definition: media.hpp:87
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:99
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:84
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:143
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:196
Interface to the vault layer: provides functions for querying (opening) a media file, detecting the channels or streams found within this file etc.
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:158
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:131
Placeholder Asset for unknown or unavailable media source.
Definition: unknown.hpp:54
Superinterface describing especially bookkeeping properties.
Definition: asset.hpp:148
Marker Asset to indicate an unknown media source.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:226
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:285
Kind
top-level distinction of different Kinds of Assets.
Definition: category.hpp:55
lib::P< KIND > getAsset(const ID< KIND > &id)
find and return corresponding object
bookkeeping (Asset) view of a media clip.
Definition: asset/clip.hpp:44
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:474
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:78
PProcPatt howtoProc() const
Service Access Point for getting a processing template describing how to build the render nodes netwo...
Definition: media.cpp:120
string extractName(const string &path)
helper: extract a name token out of a given path/filename
Definition: media.cpp:67
a family of time value like entities and their relationships.
asset::Category category
primary tree like classification of the asset.
Definition: asset.hpp:169
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:44
virtual PMedia checkCompound() const
predicate to decide if this asset::Media is part of a compound (multichannel) media.
Definition: media.cpp:109
Abstraction interface to query for a media file.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:80