Gstreamer.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*\
  2. |*| Copyright 2015 bill-auger <https://github.com/bill-auger/av-caster/issues>
  3. |*|
  4. |*| This file is part of the AvCaster program.
  5. |*|
  6. |*| AvCaster is free software: you can redistribute it and/or modify
  7. |*| it under the terms of the GNU Lesser General Public License version 3
  8. |*| as published by the Free Software Foundation.
  9. |*|
  10. |*| AvCaster is distributed in the hope that it will be useful,
  11. |*| but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. |*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. |*| GNU Lesser General Public License for more details.
  14. |*|
  15. |*| You should have received a copy of the GNU Lesser General Public License
  16. |*| along with AvCaster. If not, see <http://www.gnu.org/licenses/>.
  17. \*/
  18. #ifndef _GSTREAMER_H_
  19. #define _GSTREAMER_H_
  20. #include <gst/gst.h>
  21. #include "Constants.h"
  22. /**
  23. Gstreamer is a the media handling class for the AvCaster application.
  24. It encapsulates interactions with the libgstreamer C library.
  25. */
  26. class Gstreamer
  27. {
  28. friend class AvCaster ;
  29. private:
  30. // setup
  31. static bool Initialize (void* x_window_handle) ;
  32. static void ReloadConfig() ;
  33. static void Shutdown () ;
  34. // pipeline configuration
  35. static bool BuildScreencapBin () ;
  36. static bool BuildCameraBin () ;
  37. static bool BuildTextBin () ;
  38. static bool BuildImageBin () ;
  39. static bool BuildCompositorBin() ;
  40. static bool BuildPreviewBin () ;
  41. static bool BuildAudioBin () ;
  42. static bool BuildMuxerBin () ;
  43. static bool BuildOutputBin () ;
  44. // bin configuration
  45. static bool Reconfigure (const Identifier& config_key) ;
  46. static GstElement* ConfigureScreen () ;
  47. static GstElement* ConfigureCamera () ;
  48. static GstElement* ConfigureText () ;
  49. static GstElement* ConfigureImage () ;
  50. static GstElement* ConfigurePreview() ;
  51. static GstElement* ConfigureAudio () ;
  52. static GstElement* ConfigureOutput () ;
  53. // element configuration
  54. static void ConfigureCaps (GstElement* a_capsfilter , GstCaps* a_caps) ;
  55. static void ConfigureQueue (GstElement* a_queue , guint max_bytes ,
  56. guint64 max_time , guint max_buffers) ;
  57. static void ConfigureScreenSource (GstElement* a_screen_source ,
  58. guint capture_w , guint capture_h ,
  59. guint pattern_n , bool is_active ) ;
  60. static void ConfigureCameraSource (GstElement* a_camera_source , String device_path ,
  61. guint pattern_n , bool is_active ) ;
  62. static void ConfigureTestVideo (GstElement* a_test_source , guint pattern_n) ;
  63. static void ConfigureTextSource (GstElement* a_text_source , String font_desc) ;
  64. static void ConfigureFileSource (GstElement* a_file_source , String file_path) ;
  65. static void ConfigureCompositor (GstElement* a_compositor , guint background_n) ;
  66. static void ConfigureCompositorSink(GstPad* sinkpad , gint w , gint h , gint x , gint y) ;
  67. static bool ConfigureVideoSink (GstElement* a_video_sink) ;
  68. static void ConfigureFauxSource (GstElement* a_faux_source) ;
  69. static void ConfigureX264Encoder (GstElement* an_x264_encoder , guint bitrate) ;
  70. static void ConfigureLameEncoder (GstElement* a_lame_encoder , guint bitrate) ;
  71. static void ConfigureFlvmux (GstElement* a_flvmuxer) ;
  72. // state
  73. static bool SetState (GstElement* an_element , GstState next_state) ;
  74. static void SetMessageHandler (GstPipeline* pipeline ,
  75. GstBusSyncHandler on_message_cb) ;
  76. static GstBusSyncReply HandleMessage (GstBus* message_bus , GstMessage* message ,
  77. GstPipeline* pipeline ) ;
  78. static void HandleErrorMessage(GstMessage* message) ;
  79. // element creation and destruction
  80. static GstElement* NewPipeline (String pipeline_id) ;
  81. static GstElement* NewBin (String bin_id) ;
  82. static GstElement* NewElement (String plugin_id , String element_id) ;
  83. static GstCaps* NewCaps (String caps_str) ;
  84. static bool AddElement (GstElement* a_bin , GstElement* an_element) ;
  85. static bool RemoveElement (GstElement* a_bin , GstElement* an_element) ;
  86. static void DestroyElement (GstElement* an_element) ;
  87. static bool AddBin (GstElement* a_bin) ;
  88. static bool RemoveBin (GstElement* a_bin) ;
  89. static bool LinkElements (GstElement* source , GstElement* sink) ;
  90. static bool LinkPads (GstPad* srcpad , GstPad* sinkpad) ;
  91. static GstPad* NewGhostSrcPad (GstElement* a_bin , GstElement* an_element ,
  92. String public_pad_id ) ;
  93. static GstPad* NewGhostSinkPad (GstElement* a_bin , GstElement* an_element ,
  94. String public_pad_id ) ;
  95. static GstPad* NewGhostPad (GstElement* a_bin , GstElement* an_element ,
  96. String private_pad_id , String public_pad_id) ;
  97. static bool AddGhostPad (GstElement* a_bin , GstPad* public_pad) ;
  98. static GstPad* NewStaticSinkPad (GstElement* an_element) ;
  99. static GstPad* NewStaticSrcPad (GstElement* an_element) ;
  100. static GstPad* NewStaticPad (GstElement* an_element , String template_id) ;
  101. static GstPad* NewRequestSinkPad(GstElement* an_element) ;
  102. static GstPad* NewRequestSrcPad (GstElement* an_element) ;
  103. static GstPad* NewRequestPad (GstElement* an_element , String template_id) ;
  104. // string helpers
  105. static String MakeVideoCapsString (int width , int height , int framerate) ;
  106. static String MakeScreenCapsString(int screencap_w , int screencap_h , int framerate) ;
  107. static String MakeCameraCapsString(int camera_w , int camera_h , int framerate) ;
  108. static String MakeAudioCapsString (String format , int samplerate , int n_channels) ;
  109. static String MakeH264CapsString (int output_w , int output_h , int framerate) ;
  110. static String MakeMp3CapsString (int samplerate , int n_channels) ;
  111. static String MakeLctvUrl (String dest) ;
  112. // getters/setters
  113. static String GetElementId(GstElement* an_element) ;
  114. static String GetPadId (GstPad* a_pad) ;
  115. // state helpers
  116. static bool IsSufficientVersion() ;
  117. static bool IsInitialized () ;
  118. static bool IsPlaying () ;
  119. static bool IsInPipeline (GstElement* an_element) ;
  120. static bool IsInBin (GstElement* a_parent_element , GstElement* a_child_element) ;
  121. // pipeline
  122. static GstElement* Pipeline ;
  123. static GstElement* ScreencapBin ;
  124. static GstElement* ScreenRealSource ;
  125. static GstElement* ScreenFauxSource ;
  126. static GstElement* ScreenCaps ;
  127. static GstElement* CameraBin ;
  128. static GstElement* CameraRealSource ;
  129. static GstElement* CameraFauxSource ;
  130. static GstElement* CameraCaps ;
  131. static GstElement* TextBin ;
  132. static GstElement* ImageBin ;
  133. static GstElement* CompositorBin ;
  134. static GstElement* PreviewBin ;
  135. static GstElement* PreviewQueue ;
  136. static GstElement* PreviewFauxSink ;
  137. static GstElement* PreviewRealSink ;
  138. static GstElement* AudioBin ;
  139. static GstElement* AudioAlsaSource ;
  140. static GstElement* AudioPulseSource ;
  141. static GstElement* AudioJackSource ;
  142. static GstElement* AudioTestSource ;
  143. static GstElement* AudioCaps ;
  144. static GstElement* MuxerBin ;
  145. static GstElement* OutputBin ;
  146. static guintptr PreviewXwin ;
  147. // configuration
  148. static ValueTree ConfigStore ;
  149. } ;
  150. #endif // _GSTREAMER_H_
  151. /* CompositorBin topology
  152. => static sink
  153. -> static src
  154. <? ghost sink
  155. ?> ghost src
  156. {? request src - (corresponds to number of calls to NewRequestSrcPad())
  157. ?} request sink - (corresponds to number of calls to NewRequestSinkPad())
  158. <=> ghost pad link - (corresponds to number of calls to AddGhostSinkPad() or AddGhostSrcPad())
  159. <-> request pad link - (corresponds to number of calls to LinkPads())
  160. <> bin link
  161. ScreencapBin <> CompositorBin<? <=> =>fullscreen_queue-> <-> ?
  162. }compositor->
  163. CameraBin <> CompositorBin<? <=> =>overlay_queue -> <-> ?
  164. ? ?
  165. }compositor-> =>capsfilter-> =>converter-> =>composite_tee{
  166. ? ?
  167. ? <-> =>composite_sink_queue-> <=> ?>CompositorBin <> PreviewBin
  168. =>composite-tee {
  169. ? <-> =>composite_thru_queue-> <=> ?>CompositorBin <> MuxerBin
  170. */