summaryrefslogtreecommitdiff
path: root/voctocore/lib/avsource.py
blob: 9b2a6eaf94b3c644fb7025b06a315ba9eed8523a (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. from gi.repository import Gst
  4. from lib.config import Config
  5. from lib.tcpsingleconnection import TCPSingleConnection
  6. class AVSource(TCPSingleConnection):
  7. def __init__(self, name, port):
  8. self.log = logging.getLogger('AVSource['+name+']')
  9. super().__init__(port)
  10. self.name = name
  11. def on_accepted(self, conn, addr):
  12. pipeline = """
  13. fdsrc fd={fd} !
  14. matroskademux name=demux
  15. demux. !
  16. {acaps} !
  17. queue !
  18. tee name=atee
  19. atee. ! queue ! interaudiosink channel=audio_{name}_mixer
  20. atee. ! queue ! interaudiosink channel=audio_{name}_mirror
  21. """.format(
  22. fd=conn.fileno(),
  23. name=self.name,
  24. acaps=Config.get('mix', 'audiocaps')
  25. )
  26. if Config.getboolean('previews', 'enabled'):
  27. pipeline += """
  28. atee. ! queue ! interaudiosink channel=audio_{name}_preview
  29. """.format(
  30. name=self.name
  31. )
  32. pipeline += """
  33. demux. !
  34. {vcaps} !
  35. queue !
  36. tee name=vtee
  37. vtee. ! queue ! intervideosink channel=video_{name}_mixer
  38. vtee. ! queue ! intervideosink channel=video_{name}_mirror
  39. """.format(
  40. fd=conn.fileno(),
  41. name=self.name,
  42. vcaps=Config.get('mix', 'videocaps')
  43. )
  44. if Config.getboolean('previews', 'enabled'):
  45. pipeline += """
  46. vtee. ! queue ! intervideosink channel=video_{name}_preview
  47. """.format(
  48. name=self.name
  49. )
  50. self.log.debug('Launching Source-Pipeline:\n%s', pipeline)
  51. self.receiverPipeline = Gst.parse_launch(pipeline)
  52. self.log.debug('Binding End-of-Stream-Signal on Source-Pipeline')
  53. self.receiverPipeline.bus.add_signal_watch()
  54. self.receiverPipeline.bus.connect("message::eos", self.on_eos)
  55. self.receiverPipeline.bus.connect("message::error", self.on_error)
  56. self.receiverPipeline.set_state(Gst.State.PLAYING)
  57. def on_eos(self, bus, message):
  58. self.log.debug('Received End-of-Stream-Signal on Source-Pipeline')
  59. if self.currentConnection is not None:
  60. self.disconnect()
  61. def on_error(self, bus, message):
  62. self.log.debug('Received Error-Signal on Source-Pipeline')
  63. (error, debug) = message.parse_error()
  64. self.log.debug('Error-Details: #%u: %s', error.code, debug)
  65. if self.currentConnection is not None:
  66. self.disconnect()
  67. def disconnect(self):
  68. self.receiverPipeline.set_state(Gst.State.NULL)
  69. self.receiverPipeline = None
  70. self.close_connection()