OPAL  Version 3.14.3
GstEndPoint.h
Go to the documentation of this file.
1 /*
2  * GstEndPoint.h
3  *
4  * GStreamer support.
5  *
6  * Open Phone Abstraction Library (OPAL)
7  * Formally known as the Open H323 project.
8  *
9  * Copyright (c) 2013 Vox Lucida Pty. Ltd. and Jonathan M. Henson
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Jonathan M. Henson
24  * jonathan.michael.henson@gmail.com, jonathan.henson@innovisit.com
25  *
26  * Contributor(s): Robert Jongbloed (robertj@voxlucida.com.au).
27  *
28  * $Revision: 30917 $
29  * $Author: rjongbloed $
30  * $Date: 2013-11-15 18:29:24 +1100 (Fri, 15 Nov 2013) $
31  */
32 
33 #ifndef GSTREAMER_GSTENDPOINT_H
34 #define GSTREAMER_GSTENDPOINT_H
35 
36 #include <ep/localep.h>
37 
38 #include <ptclib/gstreamer.h>
39 
40 #if OPAL_GSTREAMER
41 
42 class GstMediaStream;
43 
44 
45 #define OPAL_GST_STRINTF_FMT "{%s}"
46 #define OPAL_GST_NAME "name"
47 #define OPAL_GST_SAMPLE_RATE "sample-rate"
48 #define OPAL_GST_PT "pt"
49 #define OPAL_GST_MTU "mtu"
50 #define OPAL_GST_WIDTH "width"
51 #define OPAL_GST_HEIGHT "height"
52 #define OPAL_GST_FRAME_RATE "frame-rate"
53 #define OPAL_GST_BIT_RATE "bit-rate"
54 #define OPAL_GST_BIT_RATE_K "bit-rate-kbps"
55 #define OPAL_GST_BLOCK_SIZE "blocksize"
56 #define OPAL_GST_LATENCY "latency"
57 #define OPAL_GST_REMOTE_IP "remote-ip"
58 #define OPAL_GST_REMOTE_PPRT "remote-port"
59 
60 
75 class GstEndPoint : public OpalLocalEndPoint
76 {
77  PCLASSINFO(GstEndPoint, OpalLocalEndPoint);
78  public:
83  GstEndPoint(
84  OpalManager & manager,
85  const char *prefix = "gst"
86  );
87 
90  virtual ~GstEndPoint();
92 
105  virtual OpalMediaFormatList GetMediaFormats() const;
106 
111  OpalCall & call,
112  void * userData,
113  unsigned options,
114  OpalConnection::StringOptions * stringOptions
115  );
117 
147  virtual bool BuildPipeline(
148  ostream & description,
149  const GstMediaStream * audioStream
150 #if OPAL_VIDEO
151  , const GstMediaStream * videoStream
152 #endif
153  );
154 
155  virtual bool BuildAudioSourcePipeline(ostream & desc, const GstMediaStream & stream, int rtpIndex);
156  virtual bool BuildAudioSinkPipeline(ostream & desc, const GstMediaStream & stream, int rtpIndex);
157 
158  bool SetAudioSourceDevice(const PString & elementName);
159  virtual bool BuildAudioSourceDevice(ostream & desc, const GstMediaStream & stream);
160  const PString & GetAudioSourceDevice() const { return m_audioSourceDevice; }
161 
162  bool SetAudioSinkDevice(const PString & elementName);
163  const PString & GetAudioSinkDevice() const { return m_audioSinkDevice; }
164  virtual bool BuildAudioSinkDevice(ostream & desc, const GstMediaStream & stream);
165 
166  bool SetJitterBufferPipeline(const PString & elementName);
167  const PString & GetJitterBufferPipeline() const { return m_jitterBuffer; }
168  static const PString & GetPipelineJitterBufferName();
169  virtual bool BuildJitterBufferPipeline(ostream & desc, const GstMediaStream & stream);
170 
171  bool SetRTPPipeline(const PString & elementName);
172  const PString & GetRTPPipeline() const { return m_rtpbin; }
173  static const PString & GetPipelineRTPName();
174  virtual bool BuildRTPPipeline(ostream & desc, const GstMediaStream & stream, unsigned index);
175 
176  static const PString & GetPipelineAudioSourceName();
177  virtual bool BuildAppSource(ostream & desc, const PString & name);
178 
179  static const PString & GetPipelineAudioSinkName();
180  virtual bool BuildAppSink(ostream & desc, const PString & name, int rtpIndex);
181 
182 #if OPAL_VIDEO
183  virtual bool BuildVideoSourcePipeline(ostream & desc, const GstMediaStream & stream, int rtpIndex);
184  virtual bool BuildVideoSinkPipeline(ostream & desc, const GstMediaStream & stream, int rtpIndex);
185 
186  bool SetVideoSourceDevice(const PString & elementName);
187  const PString & GetVideoSourceDevice() const { return m_videoSourceDevice; }
188  virtual bool BuildVideoSourceDevice(ostream & desc, const GstMediaStream & stream);
189 
190  bool SetVideoSinkDevice(const PString & elementName);
191  const PString & GetVideoSinkDevice() const { return m_videoSinkDevice; }
192  virtual bool BuildVideoSinkDevice(ostream & desc, const GstMediaStream & stream);
193 
194  bool SetVideoSourceColourConverter(const PString & elementName);
195  const PString & GetVideoSourceColourConverter() const { return m_videoSourceColourConverter; }
196 
197  bool SetVideoSinkColourConverter(const PString & elementName);
198  const PString & GetVideoSinkColourConverter() const { return m_videoSinkColourConverter; }
199 
200  static const PString & GetPipelineVideoSourceName();
201  static const PString & GetPipelineVideoSinkName();
202 #endif // OPAL_VIDEO
203 
205  struct CodecPipelines {
206  PString m_encoder;
207  PString m_packetiser;
208  PString m_decoder;
209  PString m_depacketiser;
210  };
211 
217  bool SetMapping(
218  const OpalMediaFormat & mediaFormat,
219  const CodecPipelines & info
220  );
221 
223  bool GetMapping(
224  const OpalMediaFormat & mediaFormat,
225  CodecPipelines & info
226  ) const;
227 
228  virtual bool BuildEncoder(ostream & desc, const GstMediaStream & stream);
229  virtual bool BuildDecoder(ostream & desc, const GstMediaStream & stream);
231 
232  protected:
233  PString m_rtpbin;
234  PString m_audioSourceDevice;
235  PString m_audioSinkDevice;
236  PString m_jitterBuffer;
237 #if OPAL_VIDEO
238  PString m_videoSourceDevice;
239  PString m_videoSinkDevice;
240  PString m_videoSourceColourConverter;
241  PString m_videoSinkColourConverter;
242 #endif // OPAL_VIDEO
243 
244  // Translation table
245  typedef map<OpalMediaFormat, CodecPipelines> CodecPipelineMap;
246 
247  CodecPipelineMap m_MediaFormatToGStreamer;
248  OpalMediaFormatList m_mediaFormatsAvailable;
249 };
250 
251 
254 class GstConnection : public OpalLocalConnection
255 {
256  PCLASSINFO(GstConnection, OpalLocalConnection);
257  public:
262  GstConnection(
263  OpalCall & call,
264  GstEndPoint & ep,
265  void * /*userData*/,
266  unsigned options,
267  OpalConnection::StringOptions * stringOptions,
268  char tokenPrefix = 'G'
269  );
271 
289  const OpalMediaFormat & mediaFormat,
290  unsigned sessionID,
291  PBoolean isSource
292  );
294 
301  virtual bool OpenPipeline(
302  PGstPipeline & pipeline,
303  const GstMediaStream & stream
304  );
306 
307  protected:
308  GstEndPoint & m_endpoint;
309 #if OPAL_VIDEO
310  PGstPipeline m_freescaleVideoPipeline[2];
311 #endif
312 };
313 
314 
317 class GstMediaStream : public OpalMediaStream
318 {
319  PCLASSINFO(GstMediaStream, OpalMediaStream);
320  public:
325  GstMediaStream(
326  GstConnection & conn,
327  const OpalMediaFormat & mediaFormat,
328  unsigned sessionID,
329  bool isSource
330  );
331  ~GstMediaStream();
333 
340  virtual PBoolean Open();
341 
347  virtual PBoolean ReadPacket(
348  RTP_DataFrame & packet
349  );
350 
356  virtual PBoolean WritePacket(
357  RTP_DataFrame & packet
358  );
359 
365  virtual PBoolean SetDataSize(
366  PINDEX dataSize,
367  PINDEX frameTime
368  );
369 
376  virtual PBoolean IsSynchronous() const;
377 
388  virtual PBoolean RequiresPatchThread() const;
389 
390  virtual bool InternalSetPaused(bool pause, bool fromUser, bool fromPatch);
392 
393  protected:
399  virtual void InternalClose();
400 
401  bool StartPlaying(
402  PGstElement::States & state
403  );
404 
405  // Member variables.
406  GstConnection & m_connection;
407  PGstPipeline m_pipeline;
408  PGstAppSrc m_pipeSource; // Must be after m_pipeline so is destroyed before it
409  PGstAppSink m_pipeSink; // Ditto
410 };
411 
412 
413 #endif // OPAL_GSTREAMER
414 
415 #endif // GSTREAMER_GSTENDPOINT_H