Lumiera  0.pre.03
»edit your freedom«
play-service.cpp
Go to the documentation of this file.
1 /*
2  PlayService - interface: render- and playback control
3 
4  Copyright (C) Lumiera.org
5  2011, 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 
32 #include "lib/error.hpp"
33 #include "include/play-facade.hpp"
38 #include "lib/util-foreach.hpp"
39 
40 
41 #include <string>
42 //#include <memory>
44 #include <memory>
45 
46 
47 
48 namespace lumiera {
49 
50 
51  Play::~Play() { } // emit VTables here...
52 
55 
56 }//(End) namespace lumiera
57 
58 
59 namespace steam {
60 namespace play {
61 
62 //using std::string;
63 //using lumiera::Subsys;
64 //using std::bind;
65  using lib::Sync;
66  using lib::RecursiveLock_NoWait;
67  using std::weak_ptr;
68  using std::bind;
69 //using std::function;
70  using std::placeholders::_1;
71  using util::remove_if;
72  using util::and_all;
73 
74 
75  namespace { // hidden local details of the service implementation....
76 
77 
78 
79 
80 
81 
82 
83  } // (End) hidden service impl details
84 
85  using lumiera::Play;
86 
87  typedef POutputManager Output;
88 
89 
90 
92  : public Sync<RecursiveLock_NoWait>
93  {
94  typedef weak_ptr<PlayProcess> Entry;
95  typedef std::vector<Entry> ProcTable;
96 
99  ProcTable processes_;
100 
101  public:
102 
104  establishProcess (PlayProcess* newProcess)
105  {
106  Play::Controller frontend;
107  try {
108  frontend.activate (newProcess, bind (&ProcessTable::endProcess, this, _1 ));
109  }
110  catch(...)
111  {
112  delete newProcess;
113  throw;
114  }
115 
116  Lock sync{this};
117  processes_.push_back (frontend); // keeping a weak-reference
118  return frontend;
119  }
120 
121 
122  bool
123  isActive() const
124  {
125  return not and_all (processes_, isDead);
126  }
127 
128  private:
129  void
130  endProcess (PlayProcess* dyingProcess)
131  {
133  delete dyingProcess;
134 
135  Lock sync{this};
136  remove_if (processes_, isDead);
137  }
138 
139  static bool
140  isDead (Entry const& e)
141  {
142  return e.expired();
143  }
144  };
145 
146 
147 
148 
149  PlayService::~PlayService()
150  {
151  if (pTable_->isActive())
152  {
153  UNIMPLEMENTED ("block waiting for any ongoing play processes. Ensure the process table is empty -- OR -- hand it over to some kind of cleanup service");
154  }
155  ENSURE (!pTable_->isActive());
156  }
157 
158 
165  PlayService::PlayService()
166  : pTable_(new ProcessTable)
167  { }
168 
169 
170 
171 
172 
185  PlayService::connect (ModelPorts dataGenerators, POutputManager outputPossibilities)
186  {
187  Timings playbackTimings (lib::time::FrameRate::PAL);
188 
189  return pTable_->establishProcess(
190  PlayProcess::initiate(dataGenerators,
191  buildRenderConfiguration(outputPossibilities, playbackTimings)));
192  }
193 
194 
195 
200  LUMIERA_ERROR_DEFINE (CANT_PLAY, "unable to build playback or render process for this configuration");
201 
202 
203 
204 }} // namespace steam::play
205 
206 
207 namespace lumiera {
208 
209  /* ==== convenience shortcuts for creating a PlayProcess ==== */
210 
221  {
222  return this->connect (ports, output);
223  }
224 
225 
231  {
232  UNIMPLEMENTED ("build PlayProcess based on a set of pipes");
233  }
234 
235 
241  {
242  UNIMPLEMENTED ("build PlayProcess for a Timeline");
243  }
244 
245 
251  {
252  UNIMPLEMENTED ("build PlayProcess directly for a Viewer element");
253  }
254 
255 
261  {
262  UNIMPLEMENTED ("build PlayProcess for a single Fork");
263  }
264 
265 
271  {
272  UNIMPLEMENTED ("build virtual Timeline and PlayProcess to show a single Clip");
273  }
274 
275 
276 }
Facility for monitor object based locking.
Definition: sync.hpp:217
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:89
Primary service of the Player subsystem: Starting and controlling render/playback.
Controller perform(ModelPorts, Output)
Generic point-of-Service for starting playback.
Strategy to hold all the detail knowledge necessary to establish a running render CalculationStream...
Generic frame timing specification.
Definition: timings.hpp:95
scoped guard to control the actual locking.
Definition: sync.hpp:234
bool and_all(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
Steam-Layer implementation namespace root.
virtual Controller connect(ModelPorts, POutputManager)
Implementation: build a PlayProcess.
Public access point to the playback service provided by the »play-out subsystem«
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:289
Playback/Render process within the Lumiera Player.
Interface to the Player subsystem of Lumiera (Steam-Layer).
Definition: play-facade.hpp:82
static lib::Depend< Play > facade
get an implementation instance of this service
Definition: play-facade.hpp:90
RenderConfigurator::ConnectFunction buildRenderConfiguration(POutputManager outputPossibilities, Timings playTimings)
Factory function to build a RenderConfigurator specifically tailored for a PlayProcess, about to be started.
Continuous playback process, which has been hooked up and started with a fixed set of output slots...
bool remove_if(SET &set, FUN test)
remove all elements fulfilling a given predicate from a (sorted) set.
Definition: util.hpp:294
Lumiera error handling (C++ interface).
A global service to handle all external output connections.
Handle & activate(IMP *impl, DEL whenDead)
Activation of the handle by the managing service.
Definition: handle.hpp:115
Lumiera public interface.
Definition: advice.cpp:113
static PlayProcess * initiate(ModelPorts dataGenerators, FeedBuilder)
Factory: Initialise and configure a new PlayProcess.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:78
Perform operations "for each element" of a collection.
Organisational unit of an ongoing render- or playback process.
static const FrameRate PAL
predefined constant for PAL framerate
Definition: timevalue.hpp:673
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:80