#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 2013-08-19 Thomas DEBESSE <thomas.debesse (ad) rcf.fr>
# Example of a correct pipeline that produces abnormal sound after several hours of normal sound

import os
os.environ["GST_DEBUG"] = '3'

import gi
gi.require_version("Gst", "1.0")

from gi.repository import Gst, GObject
GObject.threads_init()

Gst.init(None)

mainloop = GObject.MainLoop()

alsa_iface="hw:0"

pipeline = Gst.Pipeline()
src = Gst.ElementFactory.make("alsasrc", "src")
src.set_property("device", alsa_iface)

conv = Gst.ElementFactory.make("audioconvert", "conv")
samp = Gst.ElementFactory.make("audioresample", "samp")

caps = Gst.caps_from_string("audio/x-raw, format=S16LE")

filtr = Gst.ElementFactory.make("capsfilter", "filtr")
filtr.set_property("caps", caps)

sink = Gst.ElementFactory.make("alsasink", "sink")
sink.set_property("device", alsa_iface)
sink.set_property("sync", False)

pipeline.add(src)
pipeline.add(conv)
pipeline.add(samp)
pipeline.add(filtr)
pipeline.add(sink)

src.link(conv)
conv.link(samp)
samp.link(filtr)
filtr.link(sink)

pipeline.set_state(Gst.State.PLAYING)

mainloop.run()

#EOF
