PTLib  Version 2.18.8
 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 
27 #ifndef PTLIB_GSTREMER_H
28 #define PTLIB_GSTREMER_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <ptlib.h>
35 
36 #if P_GSTREAMER
37 
38 #include <list>
39 
40 
42 // GStreamer classes
43 
44 
46 class PGBaseObject : public PObject
47 {
48  PCLASSINFO(PGBaseObject, PObject)
49  protected:
50  PGBaseObject();
51 
52  private:
53  PGBaseObject(const PGBaseObject &) { }
54  void operator=(const PGBaseObject &) { }
55 
56  public:
57  ~PGBaseObject();
58 
59  template<typename T> T * As() const { return reinterpret_cast<T *>(m_object); }
60  void * Ptr() const { return m_object; }
61  operator bool() const { return m_object != NULL; }
62  bool operator!() const { return m_object == NULL; }
63 
64  virtual bool IsValid() const;
65  virtual bool Attach(void * object);
66  void * Detach();
67  void SetNULL();
68 
69  protected:
70  virtual void Unreference() = 0;
71 
72  private:
73  void * m_object;
74 };
75 
76 
80 class PGObject : public PGBaseObject
81 {
82  PCLASSINFO(PGObject, PGBaseObject)
83  protected:
84  PGObject() { }
85  PGObject(const PGObject & other);
86  void operator=(const PGObject &);
87 
88  public:
89  ~PGObject() { SetNULL(); }
90 
91  protected:
92  virtual void Unreference();
93 
94  public:
95  virtual bool IsValid() const;
96 
97  bool Set(
98  const char * attribute,
99  bool value
100  );
101  bool Get(
102  const char * attribute,
103  bool & value
104  );
105 
106  bool Set(
107  const char * attribute,
108  int value
109  );
110  bool Get(
111  const char * attribute,
112  int & value
113  );
114 
115  bool Set(
116  const char * attribute,
117  double value
118  );
119  bool Get(
120  const char * attribute,
121  double & value
122  );
123 
124  bool Set(
125  const char * attribute,
126  const char * value
127  );
128  bool Get(
129  const char * attribute,
130  PString & value
131  );
132 };
133 
134 
138 class PGstMiniObject : public PGBaseObject
139 {
140  PCLASSINFO(PGstMiniObject, PGBaseObject)
141  protected:
142  PGstMiniObject() { }
143  PGstMiniObject(const PGstMiniObject & other);
144  void operator=(const PGstMiniObject &);
145 
146  public:
147  ~PGstMiniObject() { SetNULL(); }
148 
149  virtual bool IsValid() const;
150 
151  protected:
152  virtual void Unreference();
153 };
154 
155 
159 class PGstObject : public PGObject
160 {
161  PCLASSINFO(PGstObject, PGObject)
162  public:
163 
164  PString GetName() const;
165 
166  bool SetSockFd(int fd);
167 };
168 
169 
173 class PGstPluginFeature : public PGstObject
174 {
175  PCLASSINFO(PGstPluginFeature, PGstObject)
176  public:
177  PString GetName() const;
178 
179  enum InspectSearchField {
180  ByKlass,
181  ByName,
182  ByLongName,
183  ByDescription
184  };
185  static PStringList Inspect(
186  const char * regex,
187  InspectSearchField searchField,
188  bool detailed = true
189  );
190  static PStringList Inspect(
191  const char * regex,
192  bool detailed = true
193  ) { return Inspect(regex, ByKlass, detailed); }
194 };
195 
196 
200 class PGstElementFactory : public PGstPluginFeature
201 {
202  PCLASSINFO(PGstElementFactory, PGstPluginFeature)
203  public:
204  PGstElementFactory(
205  const char * factoryName = NULL
206  );
207 
208  PString GetKlass() const;
209  PString GetDescription() const;
210 };
211 
212 
216 class PGstElement : public PGstObject
217 {
218  PCLASSINFO(PGstElement, PGstObject)
219  public:
220  PGstElement() { }
221  PGstElement(
222  const char * factoryName,
223  const char * name
224  );
225 
226  PString GetName() const;
227  bool SetName(const PString & name);
228 
229  bool Link(
230  const PGstElement & dest
231  );
232 
233  P_DECLARE_TRACED_ENUM(States,
234  VoidPending,
235  Null,
236  Ready,
237  Paused,
238  Playing
239  );
240 
241  P_DECLARE_TRACED_ENUM(StateResult,
242  Failed,
243  Success,
244  Changing,
245  NoPreRoll
246  );
247  StateResult SetState(
248  States newState,
249  const PTimeInterval & timeout = 0
250  );
251  StateResult GetState(
252  States & state
253  );
254  StateResult GetPendingState(
255  States & state
256  );
257  StateResult WaitStateChange();
258  StateResult WaitStateChange(
259  const PTimeInterval & timeout
260  );
261 };
262 
263 
267 class PGstBaseIterator : public PGBaseObject
268 {
269  PCLASSINFO(PGstBaseIterator, PGBaseObject)
270  public:
271  ~PGstBaseIterator() { SetNULL(); }
272 
273  virtual bool Attach(void * object);
274 
275  P_DECLARE_TRACED_ENUM(Result,
276  Done,
277  Success,
278  NeedResync,
279  Error
280  );
281  Result operator++() { return InternalNext(); }
282 
283  Result GetLastResult() const { return m_lastResult; }
284 
285  void Resync();
286 
287  protected:
288  PGstBaseIterator(PGBaseObject & valueRef);
289 
290  virtual void Unreference();
291  Result InternalNext();
292 
293  PGBaseObject & m_valueRef;
294  Result m_lastResult;
295 };
296 
297 
298 template <class T>
299 class PGstIterator : public PGstBaseIterator
300 {
301  PCLASSINFO(PGstIterator, PGstBaseIterator)
302  public:
303  PGstIterator() : PGstBaseIterator(m_value) { }
304  const T * operator->() const { return &m_value; }
305  const T & operator*() const { return m_value; }
306  protected:
307  T m_value;
308 };
309 
310 
314 class PGstBin : public PGstElement
315 {
316  PCLASSINFO(PGstBin, PGstElement)
317  public:
318  bool AddElement(
319  const PGstElement & element
320  );
321 
322  bool GetByName(
323  const char * name,
324  PGstElement & element
325  ) const;
326 
327  bool GetElements(
328  PGstIterator<PGstElement> & iterator,
329  bool recursive = false
330  ) const;
331 };
332 
333 
337 class PGstAppSrc : public PGstElement
338 {
339  PCLASSINFO(PGstAppSrc, PGstElement)
340  public:
341  PGstAppSrc() { }
342  PGstAppSrc(
343  const PGstBin & bin,
344  const char * name
345  );
346 
347  P_DECLARE_TRACED_ENUM(Types,
348  Stream,
349  Seekable,
350  RandomAccess
351  );
352  void SetType(Types type);
353  Types GetType() const;
354 
355  bool Push(
356  const void * data,
357  PINDEX size
358  );
359 
360  bool EndStream();
361 };
362 
363 
367 class PGstAppSink : public PGstElement
368 {
369  PCLASSINFO(PGstAppSink, PGstElement)
370  public:
371  PGstAppSink() { }
372  PGstAppSink(
373  const PGstBin & bin,
374  const char * name
375  );
376 
377  bool Pull(
378  void * data,
379  PINDEX & size
380  );
381 
382  bool IsEndStream();
383 };
384 
385 
389 class PGstPipeline : public PGstBin
390 {
391  PCLASSINFO(PGstPipeline, PGstBin)
392  public:
393  PGstPipeline(
394  const char * name = NULL
395  );
396 
397  bool Parse(
398  const char * description
399  );
400 };
401 
402 
406 class PGstMessage : public PGstMiniObject
407 {
408  PCLASSINFO(PGstMessage, PGstMiniObject)
409  public:
410 
411  PString GetType() const;
412 
413  void PrintOn(ostream & strm) const;
414 };
415 
416 
420 class PGstBus : public PGstObject
421 {
422  PCLASSINFO(PGstBus, PGstObject)
423  public:
424  PGstBus() { }
425  PGstBus(
426  const PGstPipeline & pipeline
427  );
428 
429  bool HavePending();
430  bool Peek(PGstMessage & message);
431  bool Pop(PGstMessage & message);
432  bool Pop(PGstMessage & message, PTimeInterval & wait);
433 
434  typedef PNotifierTemplate<PGstMessage> Notifier;
435  #define PDECLARE_GstBusNotifier(cls, fn) PDECLARE_NOTIFIER2(PGstBus, cls, fn, PGstMessage)
436  #define PDECLARE_ASYNC_GstBusNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(PGstBus, cls, fn, PGstMessage)
437  #define PCREATE_GstBusNotifier(fn) PCREATE_NOTIFIER2(fn, PGstMessage)
438 
439  bool SetNotifier(
440  Notifier & notifier
441  );
442 };
443 
444 
445 #endif // P_GSTREAMER
446 
447 #endif // PTLIB_GSTREMER_H
448 
449 
450 // End Of File ///////////////////////////////////////////////////////////////
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
The PNotifier and PNotifierFunction classes build a completely type safe mechanism for calling arbitr...
Definition: notifier.h:109
The character string class.
Definition: pstring.h:108
#define P_DECLARE_TRACED_ENUM
Definition: object.h:1119
This is a list collection class of PString objects.
Definition: pstring.h:2562
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
void PrintOn(ostream &strm) const