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 
57  namespace error {
58  LUMIERA_ERROR_DEFINE (CANT_PLAY, "unable to build playback or render process for this configuration");
59  }
60 }//(End) namespace lumiera
61 
62 
63 namespace steam {
64 namespace play {
65 
66 //using std::string;
67 //using lumiera::Subsys;
68 //using std::bind;
69  using lib::Sync;
70  using lib::RecursiveLock_NoWait;
71  using std::weak_ptr;
72  using std::bind;
73 //using std::function;
74  using std::placeholders::_1;
75  using util::remove_if;
76  using util::and_all;
77 
78 
79  namespace { // hidden local details of the service implementation....
80 
81 
82 
83 
84 
85 
86 
87  } // (End) hidden service impl details
88 
89  using lumiera::Play;
90 
91  typedef POutputManager Output;
92 
93 
94 
96  : public Sync<RecursiveLock_NoWait>
97  {
98  typedef weak_ptr<PlayProcess> Entry;
99  typedef std::vector<Entry> ProcTable;
100 
103  ProcTable processes_;
104 
105  public:
106 
108  establishProcess (PlayProcess* newProcess)
109  {
110  Play::Controller frontend;
111  try {
112  frontend.activate (newProcess, bind (&ProcessTable::endProcess, this, _1 ));
113  }
114  catch(...)
115  {
116  delete newProcess;
117  throw;
118  }
119 
120  Lock sync{this};
121  processes_.push_back (frontend); // keeping a weak-reference
122  return frontend;
123  }
124 
125 
126  bool
127  isActive() const
128  {
129  return not and_all (processes_, isDead);
130  }
131 
132  private:
133  void
134  endProcess (PlayProcess* dyingProcess)
135  {
137  delete dyingProcess;
138 
139  Lock sync{this};
140  remove_if (processes_, isDead);
141  }
142 
143  static bool
144  isDead (Entry const& e)
145  {
146  return e.expired();
147  }
148  };
149 
150 
151 
152 
153  PlayService::~PlayService()
154  {
155  if (pTable_->isActive())
156  {
157  UNIMPLEMENTED ("block waiting for any ongoing play processes. Ensure the process table is empty -- OR -- hand it over to some kind of cleanup service");
158  }
159  ENSURE (!pTable_->isActive());
160  }
161 
162 
169  PlayService::PlayService()
170  : pTable_(new ProcessTable)
171  { }
172 
173 
174 
175 
176 
189  PlayService::connect (ModelPorts dataGenerators, POutputManager outputPossibilities)
190  {
191  Timings playbackTimings (lib::time::FrameRate::PAL);
192 
193  return pTable_->establishProcess(
194  PlayProcess::initiate(dataGenerators,
195  buildRenderConfiguration(outputPossibilities, playbackTimings)));
196  }
197 
198 
199 
205 }} // namespace steam::play
206 
207 
208 namespace lumiera {
209 
210  /* ==== convenience shortcuts for creating a PlayProcess ==== */
211 
222  {
223  return this->connect (ports, output);
224  }
225 
226 
232  {
233  UNIMPLEMENTED ("build PlayProcess based on a set of pipes");
234  }
235 
236 
242  {
243  UNIMPLEMENTED ("build PlayProcess for a Timeline");
244  }
245 
246 
252  {
253  UNIMPLEMENTED ("build PlayProcess directly for a Viewer element");
254  }
255 
256 
262  {
263  UNIMPLEMENTED ("build PlayProcess for a single Fork");
264  }
265 
266 
272  {
273  UNIMPLEMENTED ("build virtual Timeline and PlayProcess to show a single Clip");
274  }
275 
276 
277 }
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:91
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:319
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:121
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:80
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:680
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:80