Enigma2 plugin to to play various online streams (mostly Latvian).

basic-tutorial-2.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. # -*- coding:utf-8 -*-
  3. # GStreamer SDK Tutorials in Python
  4. #
  5. # basic-tutorial-2
  6. #
  7. """
  8. basic-tutorial-2: GStreamer concepts
  9. http://docs.gstreamer.com/display/GstSDK/Basic+tutorial+2%3A+GStreamer+concepts
  10. """
  11. import sys
  12. from gi.repository import Gst
  13. Gst.init(None)
  14. # Create the elements
  15. source = Gst.ElementFactory.make("videotestsrc", "source")
  16. sink = Gst.ElementFactory.make("autovideosink", "sink")
  17. # Create the empty pipeline
  18. pipeline = Gst.Pipeline.new("test-pipeline")
  19. if not source or not sink or not pipeline:
  20. print("Not all elements could be created.", file=sys.stderr)
  21. exit(-1)
  22. # Build the pipeline
  23. pipeline.add(source)
  24. pipeline.add(sink)
  25. if not Gst.Element.link(source, sink):
  26. print("Elements could not be linked.", file=sys.stderr)
  27. exit(-1)
  28. # Modify the source's properties
  29. source.set_property("pattern", 0)
  30. # Start playing
  31. ret = pipeline.set_state(Gst.State.PLAYING)
  32. if ret == Gst.StateChangeReturn.FAILURE:
  33. print("Unable to set the pipeline to the playing state.", file=sys.stderr)
  34. exit(-1)
  35. # Wait until error or EOS
  36. bus = pipeline.get_bus()
  37. msg = bus.timed_pop_filtered(
  38. Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS)
  39. # Parse message
  40. if (msg):
  41. if msg.type == Gst.MessageType.ERROR:
  42. err, debug = msg.parse_error()
  43. print("Error received from element %s: %s" % (
  44. msg.src.get_name(), err), file=sys.stderr)
  45. print("Debugging information: %s" % debug, file=sys.stderr)
  46. elif msg.type == Gst.MessageType.EOS:
  47. print("End-Of-Stream reached.")
  48. else:
  49. print("Unexpected message received.", file=sys.stderr)
  50. # Free resources
  51. pipeline.set_state(Gst.State.NULL)