PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gstreamer.h
Go to the documentation of this file.
1 /*
2  * gstreamer.h
3  *
4  * Interface classes for Gstreamer.
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 2011 Vox Lucida Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Vox Lucida Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision$
27  * $Author$
28  * $Date$
29  */
30 
31 #ifndef PTLIB_GSTREMER_H
32 #define PTLIB_GSTREMER_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <ptlib.h>
39 
40 #if P_GSTREAMER
41 
42 #include <list>
43 
44 
46 // GStreamer classes
47 
48 
50 class PGBaseObject : public PObject
51 {
52  PCLASSINFO(PGBaseObject, PObject)
53  protected:
54  PGBaseObject();
55 
56  private:
57  PGBaseObject(const PGBaseObject &) { }
58  void operator=(const PGBaseObject &) { }
59 
60  public:
61  ~PGBaseObject();
62 
63  template<typename T> T * As() const { return reinterpret_cast<T *>(m_object); }
64  void * Ptr() const { return m_object; }
65  operator bool() const { return m_object != NULL; }
66  bool operator!() const { return m_object == NULL; }
67 
68  virtual bool IsValid() const;
69  virtual bool Attach(void * object);
70  void * Detach();
71  void SetNULL();
72 
73  protected:
74  virtual void Unreference() = 0;
75 
76  private:
77  void * m_object;
78 };
79 
80 
84 class PGObject : public PGBaseObject
85 {
86  PCLASSINFO(PGObject, PGBaseObject)
87  protected:
88  PGObject() { }
89  PGObject(const PGObject & other);
90  void operator=(const PGObject &);
91 
92  public:
93  ~PGObject() { SetNULL(); }
94 
95  protected:
96  virtual void Unreference();
97 
98  public:
99  virtual bool IsValid() const;
100 
101  bool Set(
102  const char * attribute,
103  const char * value
104  );
105  bool Get(
106  const char * attribute,
107  PString & value
108  );
109 };
110 
111 
115 class PGstMiniObject : public PGBaseObject
116 {
117  PCLASSINFO(PGstMiniObject, PGBaseObject)
118  protected:
119  PGstMiniObject() { }
120  PGstMiniObject(const PGstMiniObject & other);
121  void operator=(const PGstMiniObject &);
122 
123  public:
124  ~PGstMiniObject() { SetNULL(); }
125 
126  virtual bool IsValid() const;
127 
128  protected:
129  virtual void Unreference();
130 };
131 
132 
136 class PGstObject : public PGObject
137 {
138  PCLASSINFO(PGstObject, PGObject)
139  public:
140 
141  PString GetName() const;
142 };
143 
144 
148 class PGstPluginFeature : public PGstObject
149 {
150  PCLASSINFO(PGstPluginFeature, PGstObject)
151  public:
152  PString GetName() const;
153 
154  enum InspectSearchField {
155  ByKlass,
156  ByName,
157  ByLongName,
158  ByDescription
159  };
160  static PStringList Inspect(
161  const char * regex,
162  InspectSearchField searchField,
163  bool detailed = true
164  );
165  static PStringList Inspect(
166  const char * regex,
167  bool detailed = true
168  ) { return Inspect(regex, ByKlass, detailed); }
169 };
170 
171 
175 class PGstElementFactory : public PGstPluginFeature
176 {
177  PCLASSINFO(PGstElementFactory, PGstPluginFeature)
178  public:
179  PGstElementFactory(
180  const char * factoryName = NULL
181  );
182 
183  PString GetKlass() const;
184  PString GetDescription() const;
185 };
186 
187 
191 class PGstElement : public PGstObject
192 {
193  PCLASSINFO(PGstElement, PGstObject)
194  public:
195  PGstElement() { }
196  PGstElement(
197  const char * factoryName,
198  const char * name
199  );
200 
201  PString GetName() const;
202  bool SetName(const PString & name);
203 
204  bool Link(
205  const PGstElement & dest
206  );
207 
208  P_DECLARE_TRACED_ENUM(States,
209  VoidPending,
210  Null,
211  Ready,
212  Paused,
213  Playing
214  );
215 
216  P_DECLARE_TRACED_ENUM(StateResult,
217  Failed,
218  Success,
219  Changing,
220  NoPreRoll
221  );
222  StateResult SetState(
223  States newState,
224  const PTimeInterval & timeout = 0
225  );
226  StateResult GetState(
227  States & state
228  );
229  StateResult GetPendingState(
230  States & state
231  );
232  StateResult WaitStateChange();
233  StateResult WaitStateChange(
234  const PTimeInterval & timeout
235  );
236 };
237 
238 
242 class PGstBaseIterator : public PGBaseObject
243 {
244  PCLASSINFO(PGstBaseIterator, PGBaseObject)
245  public:
246  ~PGstBaseIterator() { SetNULL(); }
247 
248  virtual bool Attach(void * object);
249 
250  P_DECLARE_TRACED_ENUM(Result,
251  Done,
252  Success,
253  NeedResync,
254  Error
255  );
256  Result operator++() { return InternalNext(); }
257 
258  Result GetLastResult() const { return m_lastResult; }
259 
260  void Resync();
261 
262  protected:
263  PGstBaseIterator(PGBaseObject & valueRef);
264 
265  virtual void Unreference();
266  Result InternalNext();
267 
268  PGBaseObject & m_valueRef;
269  Result m_lastResult;
270 };
271 
272 
273 template <class T>
274 class PGstIterator : public PGstBaseIterator
275 {
276  PCLASSINFO(PGstIterator, PGstBaseIterator)
277  public:
278  PGstIterator() : PGstBaseIterator(m_value) { }
279  const T * operator->() const { return &m_value; }
280  const T & operator*() const { return m_value; }
281  protected:
282  T m_value;
283 };
284 
285 
289 class PGstBin : public PGstElement
290 {
291  PCLASSINFO(PGstBin, PGstElement)
292  public:
293  bool AddElement(
294  const PGstElement & element
295  );
296 
297  bool GetByName(
298  const char * name,
299  PGstElement & element
300  ) const;
301 
302  bool GetElements(
303  PGstIterator<PGstElement> & iterator,
304  bool recursive = false
305  ) const;
306 };
307 
308 
312 class PGstAppSrc : public PGstElement
313 {
314  PCLASSINFO(PGstAppSrc, PGstElement)
315  public:
316  PGstAppSrc() { }
317  PGstAppSrc(
318  const PGstBin & bin,
319  const char * name
320  );
321 
322  P_DECLARE_TRACED_ENUM(Types,
323  Stream,
324  Seekable,
325  RandomAccess
326  );
327  void SetType(Types type);
328  Types GetType() const;
329 
330  bool Push(
331  const void * data,
332  PINDEX size
333  );
334 
335  bool EndStream();
336 };
337 
338 
342 class PGstAppSink : public PGstElement
343 {
344  PCLASSINFO(PGstAppSink, PGstElement)
345  public:
346  PGstAppSink() { }
347  PGstAppSink(
348  const PGstBin & bin,
349  const char * name
350  );
351 
352  bool Pull(
353  void * data,
354  PINDEX & size
355  );
356 
357  bool IsEndStream();
358 };
359 
360 
364 class PGstPipeline : public PGstBin
365 {
366  PCLASSINFO(PGstPipeline, PGstBin)
367  public:
368  PGstPipeline(
369  const char * name = NULL
370  );
371 
372  bool Parse(
373  const char * description
374  );
375 };
376 
377 
381 class PGstMessage : public PGstMiniObject
382 {
383  PCLASSINFO(PGstMessage, PGstMiniObject)
384  public:
385 
386  PString GetType() const;
387 
388  void PrintOn(ostream & strm) const;
389 };
390 
391 
395 class PGstBus : public PGstObject
396 {
397  PCLASSINFO(PGstBus, PGstObject)
398  public:
399  PGstBus() { }
400  PGstBus(
401  const PGstPipeline & pipeline
402  );
403 
404  bool HavePending();
405  bool Peek(PGstMessage & message);
406  bool Pop(PGstMessage & message);
407  bool Pop(PGstMessage & message, PTimeInterval & wait);
408 
409  typedef PNotifierTemplate<PGstMessage> Notifier;
410  #define PDECLARE_GstBusNotifier(cls, fn) PDECLARE_NOTIFIER2(PGstBus, cls, fn, PGstMessage)
411  #define PDECLARE_ASYNC_GstBusNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(PGstBus, cls, fn, PGstMessage)
412  #define PCREATE_GstBusNotifier(fn) PCREATE_NOTIFIER2(fn, PGstMessage)
413 
414  bool SetNotifier(
415  Notifier & notifier
416  );
417 };
418 
419 
420 #endif // P_GSTREAMER
421 
422 #endif // PTLIB_GSTREMER_H
423 
424 
425 // End Of File ///////////////////////////////////////////////////////////////