Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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"
23#include "steam/asset/media.hpp"
24#include "steam/asset/clip.hpp"
28#include "lib/format-string.hpp"
29#include "lib/util.hpp"
30#include "include/logging.h"
31
32#include <regex>
33
34
35using util::_Fmt;
36using util::isnil;
41
42using std::regex;
43using std::smatch;
44using std::regex_search;
45using std::dynamic_pointer_cast;
46
47namespace error = lumiera::error;
48
49namespace steam {
50namespace 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
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) or key.category.hasKind(AUDIO));
171 ENSURE (not isnil (key.name));
172 ENSURE (dynamic_cast<Media*>(pM) or (isnil (file) and 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
207 {
208 if (mediaref.checkCompound())
209 throw error::Invalid (_Fmt("Attempt to create a asset::Clip from the media %s, "
210 "which is not toplevel but rather part of a compound "
211 "(multichannel) media. Found parent Media %s.")
212 % mediaref
213 % *mediaref.checkCompound()
214 ,LUMIERA_ERROR_PART_OF_COMPOUND);
215 Clip* pC = new Clip (mediaref);
216 return AssetManager::instance().wrap (*pC);
217 }
218
219 LUMIERA_ERROR_DEFINE (PART_OF_COMPOUND, "part of compound used as toplevel element");
220
221
222
223
224}} // namespace asset
Definition of Asset representation for a media clip.
Steam-Layer Interface: Asset Lookup and Organisation.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
Duration is the internal Lumiera time metric.
Facade for the Asset subsystem.
static ID< Asset > getID(const Asset::Ident &)
provide the unique ID for given Asset::Ident tuple
lib::P< KIND > getAsset(const ID< KIND > &id)
find and return corresponding object
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
const vector< PAsset > & getParents() const
List of entities this asset depends on or requires to be functional.
Definition asset.hpp:274
vector< PAsset > parents
Definition asset.hpp:224
Tree like classification of Assets.
Definition category.hpp:68
bool hasKind(Kind refKind) const
Definition category.hpp:79
bookkeeping (Asset) view of a media clip.
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition asset.hpp:98
Factory specialised for creating Media Asset objects.
Definition media.hpp:136
PType operator()(Asset::Ident &key, const string &file="")
Factory method for Media Asset instances.
Definition media.cpp:142
key abstraction: media-like assets
Definition media.hpp:64
static MediaFactory create
storage for the static MediaFactory instance
Definition media.hpp:75
virtual Duration getLength() const
Definition media.cpp:122
PProcPatt howtoProc() const
Service Access Point for getting a processing template describing how to build the render nodes netwo...
Definition media.cpp:111
PClip createClip()
Service Access Point for creating a Clip entity usable within the Session from a given Media or Clip ...
Definition media.cpp:75
virtual const ID< Media > & getID() const
<
Definition media.hpp:78
virtual PMedia checkCompound() const
predicate to decide if this asset::Media is part of a compound (multichannel) media.
Definition media.cpp:100
virtual PClipAsset getClipAsset()
get or create the correct asset::Clip corresponding to this media
Definition media.cpp:90
mobject::Placement< mobject::session::Clip > PClip
Definition media.hpp:72
const Duration len_
Definition media.hpp:66
Placeholder Asset for unknown or unavailable media source.
Definition unknown.hpp:46
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
A front-end for using printf-style formatting.
Interface to the vault layer: provides functions for querying (opening) a media file,...
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition error.h:71
Lumiera error handling (C++ interface).
Front-end for printf-style string template interpolation.
This header is for including and configuring NoBug.
Abstraction interface to query for a media file.
Media data represented a specific kind of Asset.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
LumieraError< LERR_(INVALID)> Invalid
Definition error.hpp:211
string extractName(const string &path)
helper: extract a name token out of a given path/filename
Definition media.cpp:58
The asset subsystem of the Steam-Layer.
Kind
top-level distinction of different Kinds of Assets.
Definition category.hpp:48
Steam-Layer implementation namespace root.
std::string sanitise(std::string const &)
produce an identifier based on the given string.
Definition util.cpp:57
bool isnil(lib::time::Duration const &dur)
Basic set of definitions and includes commonly used together.
a POD comprised of all the information sufficiently identifying any given Asset.
Definition asset.hpp:147
asset::Category category
primary tree like classification of the asset.
Definition asset.hpp:156
string name
element ID, comprehensible but sanitised.
Definition asset.hpp:151
Descriptor holding the global information record required for further handling this kind of media wit...
a family of time value like entities and their relationships.
Marker Asset to indicate an unknown media source.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...