OPAL  Version 3.18.8
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 
29 #ifndef GSTREAMER_GSTENDPOINT_H
30 #define GSTREAMER_GSTENDPOINT_H
31 
32 #include <ep/localep.h>
33 
34 #include <ptclib/gstreamer.h>
35 
36 #if OPAL_GSTREAMER
37 
38 class GstMediaStream;
39 
40 
41 #define OPAL_GST_STRINTF_FMT "{%s}"
42 #define OPAL_GST_NAME "name"
43 #define OPAL_GST_SAMPLE_RATE "sample-rate"
44 #define OPAL_GST_PT "pt"
45 #define OPAL_GST_MTU "mtu"
46 #define OPAL_GST_WIDTH "width"
47 #define OPAL_GST_HEIGHT "height"
48 #define OPAL_GST_FRAME_RATE "frame-rate"
49 #define OPAL_GST_BIT_RATE "bit-rate"
50 #define OPAL_GST_BIT_RATE_K "bit-rate-kbps"
51 #define OPAL_GST_BLOCK_SIZE "blocksize"
52 #define OPAL_GST_LATENCY "latency"
53 #define OPAL_GST_REMOTE_IP "remote-ip"
54 #define OPAL_GST_REMOTE_PPRT "remote-port"
55 
56 
71 class GstEndPoint : public OpalLocalEndPoint
72 {
73  PCLASSINFO(GstEndPoint, OpalLocalEndPoint);
74  public:
79  GstEndPoint(
80  OpalManager & manager,
81  const char *prefix = "gst"
82  );
83 
86  virtual ~GstEndPoint();
88 
101  virtual OpalMediaFormatList GetMediaFormats() const;
102 
107  OpalCall & call,
108  void * userData,
109  unsigned options,
110  OpalConnection::StringOptions * stringOptions
111  );
113 
143  virtual bool BuildPipeline(
144  ostream & description,
145  const GstMediaStream * audioStream
146 #if OPAL_VIDEO
147  , const GstMediaStream * videoStream
148 #endif
149  );
150 
151  /* Configure the pipeline when it is already in NULL state */
152  virtual bool ConfigurePipeline(PGstPipeline & pipeline, const GstMediaStream & stream);
153 
154  virtual bool BuildAudioSourcePipeline(ostream & desc, const GstMediaStream & stream, int rtpIndex);
155  virtual bool BuildAudioSinkPipeline(ostream & desc, const GstMediaStream & stream, int rtpIndex);
156 
157  virtual bool OutputRTPSource(ostream & desc, const GstMediaStream & stream, int rtpIndex);
158  virtual bool OutputRTPSink(ostream & desc, const GstMediaStream & stream, int rtpIndex);
159 
160  bool SetAudioSourceDevice(const PString & elementName);
161  virtual bool BuildAudioSourceDevice(ostream & desc, const GstMediaStream & stream);
162  const PString & GetAudioSourceDevice() const { return m_audioSourceDevice; }
163 
164  bool SetAudioSinkDevice(const PString & elementName);
165  const PString & GetAudioSinkDevice() const { return m_audioSinkDevice; }
166  virtual bool BuildAudioSinkDevice(ostream & desc, const GstMediaStream & stream);
167 
168  bool SetJitterBufferPipeline(const PString & elementName);
169  const PString & GetJitterBufferPipeline() const { return m_jitterBuffer; }
170  static const PString & GetPipelineJitterBufferName();
171  virtual bool BuildJitterBufferPipeline(ostream & desc, const GstMediaStream & stream);
172 
173  bool SetRTPPipeline(const PString & elementName);
174  const PString & GetRTPPipeline() const { return m_rtpbin; }
175  static const PString & GetPipelineRTPName();
176  virtual bool BuildRTPPipeline(ostream & desc, const GstMediaStream & stream, unsigned index);
177 
178  static const PString & GetPipelineAudioSourceName();
179  virtual bool BuildAppSource(ostream & desc, const PString & name);
180 
181  static const PString & GetPipelineAudioSinkName();
182  virtual bool BuildAppSink(ostream & desc, const PString & name, int rtpIndex);
183 
184  static const PString & GetPipelineVolumeName();
185  virtual bool BuildVolume(ostream & desc, const PString & name);
186 
187 #if OPAL_VIDEO
188  virtual bool BuildVideoSourcePipeline(ostream & desc, const GstMediaStream & stream, int rtpIndex);
189  virtual bool BuildVideoSinkPipeline(ostream & desc, const GstMediaStream & stream, int rtpIndex);
190 
191  bool SetVideoSourceDevice(const PString & elementName);
192  const PString & GetVideoSourceDevice() const { return m_videoSourceDevice; }
193  virtual bool BuildVideoSourceDevice(ostream & desc, const GstMediaStream & stream);
194 
195  bool SetVideoSinkDevice(const PString & elementName);
196  const PString & GetVideoSinkDevice() const { return m_videoSinkDevice; }
197  virtual bool BuildVideoSinkDevice(ostream & desc, const GstMediaStream & stream);
198 
199  bool SetVideoSourceColourConverter(const PString & elementName);
200  const PString & GetVideoSourceColourConverter() const { return m_videoSourceColourConverter; }
201 
202  bool SetVideoSinkColourConverter(const PString & elementName);
203  const PString & GetVideoSinkColourConverter() const { return m_videoSinkColourConverter; }
204 
205  static const PString & GetPipelineVideoSourceName();
206  static const PString & GetPipelineVideoSinkName();
207 #endif // OPAL_VIDEO
208 
210  struct CodecPipelines {
211  PString m_encoder;
212  PString m_packetiser;
213  PString m_decoder;
214  PString m_depacketiser;
215  };
216 
222  bool SetMapping(
223  const OpalMediaFormat & mediaFormat,
224  const CodecPipelines & info
225  );
226 
228  bool GetMapping(
229  const OpalMediaFormat & mediaFormat,
230  CodecPipelines & info
231  ) const;
232 
233  virtual bool BuildEncoder(ostream & desc, const GstMediaStream & stream);
234  virtual bool BuildDecoder(ostream & desc, const GstMediaStream & stream);
236 
237  protected:
238  PString m_rtpbin;
239  PString m_jitterBuffer;
240  PString m_audioSourceDevice;
241  PString m_audioSinkDevice;
242 #if OPAL_VIDEO
243  PString m_videoSourceDevice;
244  PString m_videoSinkDevice;
245  PString m_videoSourceColourConverter;
246  PString m_videoSinkColourConverter;
247 #endif // OPAL_VIDEO
248 
249  // Translation table
250  typedef map<OpalMediaFormat, CodecPipelines> CodecPipelineMap;
251 
252  CodecPipelineMap m_MediaFormatToGStreamer;
253  OpalMediaFormatList m_mediaFormatsAvailable;
254 };
255 
256 
259 class GstConnection : public OpalLocalConnection
260 {
261  PCLASSINFO(GstConnection, OpalLocalConnection);
262  public:
267  GstConnection(
268  OpalCall & call,
269  GstEndPoint & ep,
270  void * /*userData*/,
271  unsigned options,
272  OpalConnection::StringOptions * stringOptions,
273  char tokenPrefix = 'G'
274  );
276 
294  const OpalMediaFormat & mediaFormat,
295  unsigned sessionID,
296  PBoolean isSource
297  );
298 
302  virtual PBoolean SetAudioVolume(
303  PBoolean source,
304  unsigned percentage
305  );
306 
310  virtual PBoolean GetAudioVolume(
311  PBoolean source,
312  unsigned & percentage
313  );
314 
317  virtual bool SetAudioMute(
318  bool source,
319  bool mute
320  );
321 
324  virtual bool GetAudioMute(
325  bool source,
326  bool & mute
327  );
329 
336  virtual bool OpenPipeline(
337  PGstPipeline & pipeline,
338  const GstMediaStream & stream
339  );
340 
341  virtual bool ConfigurePipeline(PGstPipeline & pipeline, const GstMediaStream & stream);
343 
344  protected:
345  GstEndPoint & m_endpoint;
346 };
347 
348 
351 class GstMediaStream : public OpalMediaStream
352 {
353  PCLASSINFO(GstMediaStream, OpalMediaStream);
354  public:
359  GstMediaStream(
360  GstConnection & conn,
361  const OpalMediaFormat & mediaFormat,
362  unsigned sessionID,
363  bool isSource
364  );
365  ~GstMediaStream();
367 
374  virtual PBoolean Open();
375 
381  virtual PBoolean Start();
382 
388  virtual PBoolean ReadPacket(
389  RTP_DataFrame & packet
390  );
391 
397  virtual PBoolean WritePacket(
398  RTP_DataFrame & packet
399  );
400 
406  virtual PBoolean SetDataSize(
407  PINDEX dataSize,
408  PINDEX frameTime
409  );
410 
417  virtual PBoolean IsSynchronous() const;
418 
426  virtual PBoolean RequiresPatchThread(
427  OpalMediaStream * stream
428  ) const;
429 
437  virtual bool RequireMediaTransportThread(
438  OpalMediaStream & stream
439  ) const;
440 
444  virtual bool SetAudioVolume(
445  unsigned percentage
446  );
447 
451  virtual bool GetAudioVolume(
452  unsigned & percentage
453  );
454 
457  virtual bool SetAudioMute(
458  bool mute
459  );
460 
463  virtual bool GetAudioMute(
464  bool & mute
465  );
467 
468  protected:
474  virtual void InternalClose();
475  virtual bool InternalSetPaused(bool pause, bool fromUser, bool fromPatch);
476 
477  bool StartPlaying(
478  PGstElement::States & state
479  );
480 
481  // Member variables.
482  GstConnection & m_connection;
483  PGstPipeline m_pipeline;
484  PGstAppSrc m_pipeSource; // Must be after m_pipeline so is destroyed before it
485  PGstAppSink m_pipeSink; // Ditto
486  PGstElement m_pipeVolume;
487 };
488 
489 
490 #endif // OPAL_GSTREAMER
491 
492 #endif // GSTREAMER_GSTENDPOINT_H
Definition: manager.h:150
virtual PBoolean IsSynchronous() const =0
virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat &mediaFormat, unsigned sessionID, PBoolean isSource)
Definition: localep.h:469
OpalLocalEndPoint & m_endpoint
Definition: localep.h:830
virtual PBoolean Open()
virtual bool InternalSetPaused(bool pause, bool fromUser, bool fromPatch)
Definition: mediafmt.h:112
virtual PBoolean GetAudioVolume(PBoolean source, unsigned &percentage)
Definition: connection.h:530
Definition: rtp.h:540
Definition: localep.h:63
virtual bool RequireMediaTransportThread(OpalMediaStream &stream) const
Definition: mediafmt.h:806
Definition: call.h:62
virtual OpalMediaFormatList GetMediaFormats() const
virtual void InternalClose()=0
virtual bool SetAudioMute(bool source, bool mute)
virtual bool GetAudioMute(bool source, bool &mute)
virtual PBoolean SetDataSize(PINDEX dataSize, PINDEX frameTime)
OpalConnection & m_connection
Definition: mediastrm.h:463
virtual PBoolean RequiresPatchThread() const
Definition: mediastrm.h:110
virtual PBoolean Start()
virtual PBoolean WritePacket(RTP_DataFrame &packet)
virtual OpalLocalConnection * CreateConnection(OpalCall &call, void *userData, unsigned options, OpalConnection::StringOptions *stringOptions)
virtual PBoolean SetAudioVolume(PBoolean source, unsigned percentage)
virtual PBoolean ReadPacket(RTP_DataFrame &packet)