| 1 | // Generated by gmmproc 2.50.1 -- DO NOT MODIFY! |
| 2 | #ifndef _GSTREAMERMM_TASK_H |
| 3 | #define _GSTREAMERMM_TASK_H |
| 4 | |
| 5 | |
| 6 | #include <glibmm/ustring.h> |
| 7 | #include <sigc++/sigc++.h> |
| 8 | |
| 9 | /* gstreamermm - a C++ wrapper for gstreamer |
| 10 | * |
| 11 | * Copyright 2008-2015 The gstreamermm Development Team |
| 12 | * |
| 13 | * This library is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU Lesser General Public |
| 15 | * License as published by the Free Software Foundation; either |
| 16 | * version 2.1 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This library is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | * Lesser General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU Lesser General Public |
| 24 | * License along with this library; if not, write to the Free |
| 25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
| 28 | #include <gst/gst.h> |
| 29 | #include <gstreamermm/object.h> |
| 30 | #include <glibmm/threads.h> |
| 31 | #include <memory> |
| 32 | |
| 33 | |
| 34 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 35 | using GstTask = struct _GstTask; |
| 36 | using GstTaskClass = struct _GstTaskClass; |
| 37 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
| 38 | |
| 39 | |
| 40 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 41 | namespace Gst |
| 42 | { class Task_Class; } // namespace Gst |
| 43 | #endif //DOXYGEN_SHOULD_SKIP_THIS |
| 44 | |
| 45 | namespace Gst |
| 46 | { |
| 47 | |
| 48 | /** @addtogroup gstreamermmEnums gstreamermm Enums and Flags */ |
| 49 | |
| 50 | /** |
| 51 | * @var TaskState TASK_STARTED |
| 52 | * The task is started and running. |
| 53 | * |
| 54 | * @var TaskState TASK_STOPPED |
| 55 | * The task is stopped. |
| 56 | * |
| 57 | * @var TaskState TASK_PAUSED |
| 58 | * The task is paused. |
| 59 | * |
| 60 | * @enum TaskState |
| 61 | * |
| 62 | * The different states a task can be in |
| 63 | * |
| 64 | * @ingroup gstreamermmEnums |
| 65 | */ |
| 66 | enum TaskState |
| 67 | { |
| 68 | TASK_STARTED, |
| 69 | TASK_STOPPED, |
| 70 | TASK_PAUSED |
| 71 | }; |
| 72 | |
| 73 | } // namespace Gst |
| 74 | |
| 75 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 76 | namespace Glib |
| 77 | { |
| 78 | |
| 79 | template <> |
| 80 | class Value<Gst::TaskState> : public Glib::Value_Enum<Gst::TaskState> |
| 81 | { |
| 82 | public: |
| 83 | static GType value_type() G_GNUC_CONST; |
| 84 | }; |
| 85 | |
| 86 | } // namespace Glib |
| 87 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
| 88 | |
| 89 | namespace Gst |
| 90 | { |
| 91 | |
| 92 | |
| 93 | class TaskPool; |
| 94 | |
| 95 | /** A class representing GStreamer streaming threads. |
| 96 | * Gst::Task is used by Gst::Element and Gst::Pad to provide the data passing |
| 97 | * threads in a Gst::Pipeline. |
| 98 | * |
| 99 | * A Gst::Pad will typically start a Gst::Task to push or pull data to/from the |
| 100 | * peer pads. Most source elements start a Gst::Task to push data. In some |
| 101 | * cases a demuxer element can start a Gst::Task to pull data from a peer |
| 102 | * element. This is typically done when the demuxer can perform random access |
| 103 | * on the upstream peer element for improved performance. |
| 104 | * |
| 105 | * Although convenience functions exist on Gst::Pad to start/pause/stop tasks, |
| 106 | * it might sometimes be needed to create a Gst::Task manually if it is not |
| 107 | * related to a Gst::Pad. |
| 108 | * |
| 109 | * Before the Gst::Task can be run, it needs a Glib::StaticRecMutex that can be |
| 110 | * set with set_lock(). |
| 111 | * |
| 112 | * The task can be started, paused and stopped with start(), pause() and stop() |
| 113 | * respectively. |
| 114 | * |
| 115 | * A Gst::Task will repeadedly call the Gst::Task::SlotTask that was provided |
| 116 | * when creating the task with create(). Before calling the function it will |
| 117 | * acquire the provided lock. |
| 118 | * |
| 119 | * Stopping a task with stop() will not immediatly make sure the task is not |
| 120 | * running anymore. Use join() to make sure the task is completely stopped and |
| 121 | * the thread is stopped. |
| 122 | * |
| 123 | * Task functions can send a Gst::Message to send out-of-band data to the |
| 124 | * application. The application can receive messages from the Gst::Bus in its |
| 125 | * mainloop. |
| 126 | * |
| 127 | * For debugging purposes, the task will configure its object name as the thread |
| 128 | * name on Linux. Please note that the object name should be configured before the |
| 129 | * task is started; changing the object name after the task has been started, has |
| 130 | * no effect on the thread name. |
| 131 | * |
| 132 | * Last reviewed on 2015-10-14 (1.5.2) |
| 133 | */ |
| 134 | |
| 135 | class Task : public Object |
| 136 | { |
| 137 | |
| 138 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 139 | |
| 140 | public: |
| 141 | using CppObjectType = Task; |
| 142 | using CppClassType = Task_Class; |
| 143 | using BaseObjectType = GstTask; |
| 144 | using BaseClassType = GstTaskClass; |
| 145 | |
| 146 | // noncopyable |
| 147 | Task(const Task&) = delete; |
| 148 | Task& operator=(const Task&) = delete; |
| 149 | |
| 150 | private: friend class Task_Class; |
| 151 | static CppClassType task_class_; |
| 152 | |
| 153 | protected: |
| 154 | explicit Task(const Glib::ConstructParams& construct_params); |
| 155 | explicit Task(GstTask* castitem); |
| 156 | |
| 157 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
| 158 | |
| 159 | public: |
| 160 | |
| 161 | Task(Task&& src) noexcept; |
| 162 | Task& operator=(Task&& src) noexcept; |
| 163 | |
| 164 | ~Task() noexcept override; |
| 165 | |
| 166 | /** Get the GType for this class, for use with the underlying GObject type system. |
| 167 | */ |
| 168 | static GType get_type() G_GNUC_CONST; |
| 169 | |
| 170 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 171 | |
| 172 | |
| 173 | static GType get_base_type() G_GNUC_CONST; |
| 174 | #endif |
| 175 | |
| 176 | ///Provides access to the underlying C GObject. |
| 177 | GstTask* gobj() { return reinterpret_cast<GstTask*>(gobject_); } |
| 178 | |
| 179 | ///Provides access to the underlying C GObject. |
| 180 | const GstTask* gobj() const { return reinterpret_cast<GstTask*>(gobject_); } |
| 181 | |
| 182 | ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. |
| 183 | GstTask* gobj_copy(); |
| 184 | |
| 185 | private: |
| 186 | |
| 187 | |
| 188 | public: |
| 189 | /** For example, |
| 190 | * void on_do_task();. |
| 191 | */ |
| 192 | typedef sigc::slot<void> SlotTask; |
| 193 | |
| 194 | /** |
| 195 | * Bidirectional slot |
| 196 | */ |
| 197 | typedef sigc::slot<void, const Glib::RefPtr<Gst::Task>&, |
| 198 | Glib::Threads::Thread*> TaskThreadSlot; |
| 199 | /** For example, |
| 200 | * void on_enter(const Glib::RefPtr<Gst::Task>& task, Glib::Threads::Thread& |
| 201 | * thread);. |
| 202 | * A thread is entered, this slot is called when the new thread enters its |
| 203 | * function. |
| 204 | */ |
| 205 | typedef TaskThreadSlot SlotEnter; |
| 206 | |
| 207 | /** For example, |
| 208 | * void on_leave(const Glib::RefPtr<Gst::Task>& task, Glib::Threads::Thread& |
| 209 | * thread);. |
| 210 | * A thread is exiting, this is called when the thread is about to leave its |
| 211 | * function. |
| 212 | */ |
| 213 | typedef TaskThreadSlot SlotLeave; |
| 214 | |
| 215 | protected: |
| 216 | explicit Task(const SlotTask& task_slot); |
| 217 | |
| 218 | public: |
| 219 | /** Create a new Gst::Task that will repeatedly call the provided slot as a |
| 220 | * parameter. Typically the task will run in a new thread. |
| 221 | * |
| 222 | * The slot cannot be changed after the task has been created. You must |
| 223 | * create a new Gst::Task to change the slot. |
| 224 | * |
| 225 | * @param task_slot The Gst::Task::SlotTask to use. |
| 226 | * @return A new Gst::Task. MT safe. |
| 227 | */ |
| 228 | |
| 229 | static Glib::RefPtr<Task> create(const SlotTask& task_slot); |
| 230 | |
| 231 | |
| 232 | /** Set the mutex used by the task. The mutex will be acquired before |
| 233 | * calling the Gst::TaskFunction. |
| 234 | * |
| 235 | * This function has to be called before calling pause() or |
| 236 | * start(). |
| 237 | * |
| 238 | * MT safe. |
| 239 | * |
| 240 | * @param mutex The RecMutex to use. |
| 241 | */ |
| 242 | void set_lock(Glib::Threads::RecMutex& mutex); |
| 243 | |
| 244 | /** Set @a pool as the new GstTaskPool for @a task. Any new streaming threads that |
| 245 | * will be created by @a task will now use @a pool. |
| 246 | * |
| 247 | * MT safe. |
| 248 | * |
| 249 | * @param pool A Gst::TaskPool. |
| 250 | */ |
| 251 | void set_pool(const Glib::RefPtr<Gst::TaskPool>& pool); |
| 252 | |
| 253 | /** Get the Gst::TaskPool that this task will use for its streaming |
| 254 | * threads. |
| 255 | * |
| 256 | * MT safe. |
| 257 | * |
| 258 | * @return The Gst::TaskPool used by @a task. Gst::Object::unref() |
| 259 | * after usage. |
| 260 | */ |
| 261 | Glib::RefPtr<Gst::TaskPool> get_pool(); |
| 262 | |
| 263 | /** Get the Gst::TaskPool that this task will use for its streaming |
| 264 | * threads. |
| 265 | * |
| 266 | * MT safe. |
| 267 | * |
| 268 | * @return The Gst::TaskPool used by @a task. Gst::Object::unref() |
| 269 | * after usage. |
| 270 | */ |
| 271 | Glib::RefPtr<const Gst::TaskPool> get_pool() const; |
| 272 | |
| 273 | /** Call enter_slot when the task function of task is entered. |
| 274 | * |
| 275 | * @param enter_slot |
| 276 | */ |
| 277 | void set_enter_slot(const SlotEnter& enter_slot); |
| 278 | |
| 279 | |
| 280 | /** Call leave_func when the task function of task is left. |
| 281 | * |
| 282 | * @param leave_slot |
| 283 | */ |
| 284 | void set_leave_slot(const SlotLeave& leave_slot); |
| 285 | |
| 286 | |
| 287 | /** Get the current state of the task. |
| 288 | * |
| 289 | * @return The Gst::TaskState of the task |
| 290 | * |
| 291 | * MT safe. |
| 292 | */ |
| 293 | TaskState get_state() const; |
| 294 | |
| 295 | /** Sets the state of @a task to @a state. |
| 296 | * |
| 297 | * The @a task must have a lock associated with it using |
| 298 | * set_lock() when going to GST_TASK_STARTED or GST_TASK_PAUSED or |
| 299 | * this function will return <tt>false</tt>. |
| 300 | * |
| 301 | * MT safe. |
| 302 | * |
| 303 | * @param state The new task state. |
| 304 | * @return <tt>true</tt> if the state could be changed. |
| 305 | */ |
| 306 | void set_state(Gst::TaskState state); |
| 307 | |
| 308 | /** Pauses @a task. This method can also be called on a task in the |
| 309 | * stopped state, in which case a thread will be started and will remain |
| 310 | * in the paused state. This function does not wait for the task to complete |
| 311 | * the paused state. |
| 312 | * |
| 313 | * @return <tt>true</tt> if the task could be paused. |
| 314 | * |
| 315 | * MT safe. |
| 316 | */ |
| 317 | bool pause(); |
| 318 | |
| 319 | /** Starts @a task. The @a task must have a lock associated with it using |
| 320 | * set_lock() or this function will return <tt>false</tt>. |
| 321 | * |
| 322 | * @return <tt>true</tt> if the task could be started. |
| 323 | * |
| 324 | * MT safe. |
| 325 | */ |
| 326 | bool start(); |
| 327 | |
| 328 | /** Stops @a task. This method merely schedules the task to stop and |
| 329 | * will not wait for the task to have completely stopped. Use |
| 330 | * join() to stop and wait for completion. |
| 331 | * |
| 332 | * @return <tt>true</tt> if the task could be stopped. |
| 333 | * |
| 334 | * MT safe. |
| 335 | */ |
| 336 | bool stop(); |
| 337 | |
| 338 | /** Joins @a task. After this call, it is safe to unref the task |
| 339 | * and clean up the lock set with set_lock(). |
| 340 | * |
| 341 | * The task will automatically be stopped with this call. |
| 342 | * |
| 343 | * This function cannot be called from within a task function as this |
| 344 | * would cause a deadlock. The function will detect this and print a |
| 345 | * g_warning. |
| 346 | * |
| 347 | * @return <tt>true</tt> if the task could be joined. |
| 348 | * |
| 349 | * MT safe. |
| 350 | */ |
| 351 | bool join(); |
| 352 | |
| 353 | /** Wait for all tasks to be stopped. This is mainly used internally |
| 354 | * to ensure proper cleanup of internal data structures in test suites. |
| 355 | * |
| 356 | * MT safe. |
| 357 | */ |
| 358 | static void cleanup_all(); |
| 359 | |
| 360 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 361 | private: |
| 362 | // todo this slot should be moved in move constructor, but for now it's |
| 363 | // impossible to provide custom move constructor |
| 364 | // (see https://bugzilla.gnome.org/show_bug.cgi?id=756593). |
| 365 | // However, task should be managed by RefPtr class, so move constructor |
| 366 | // and move assignment operator will never be called. |
| 367 | std::unique_ptr<SlotTask> m_slot; |
| 368 | #endif |
| 369 | |
| 370 | |
| 371 | public: |
| 372 | |
| 373 | public: |
| 374 | //C++ methods used to invoke GTK+ virtual functions: |
| 375 | |
| 376 | protected: |
| 377 | //GTK+ Virtual Functions (override these to change behaviour): |
| 378 | |
| 379 | //Default Signal Handlers:: |
| 380 | |
| 381 | |
| 382 | }; |
| 383 | |
| 384 | } // namespace Gst |
| 385 | |
| 386 | |
| 387 | namespace Glib |
| 388 | { |
| 389 | /** A Glib::wrap() method for this object. |
| 390 | * |
| 391 | * @param object The C instance. |
| 392 | * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref. |
| 393 | * @result A C++ instance that wraps this C instance. |
| 394 | * |
| 395 | * @relates Gst::Task |
| 396 | */ |
| 397 | Glib::RefPtr<Gst::Task> wrap(GstTask* object, bool take_copy = false); |
| 398 | } |
| 399 | |
| 400 | |
| 401 | #endif /* _GSTREAMERMM_TASK_H */ |
| 402 |