import pygst
pygst.require('0.10')
import gst,time

import base64

pipeline = gst.parse_launch ("audiotestsrc ! tee name = t ! queue ! fakesink ") 

t =  pipeline.get_by_name("t")
def add(pipeline):
	global t
	bin = gst.parse_bin_from_description("queue ! audioconvert ! vorbisenc ! rtpvorbispay ! rtpvorbisdepay name=d ! vorbisdec ! audioconvert ! alsasink sync=false async=false", True)
	pipeline.add(bin)
	pipeline.set_state(gst.STATE_PLAYING);
	t.link(bin)
	return bin.get_by_name("d")

dp = add(pipeline)
	
pipeline.set_state(gst.STATE_PLAYING);

oldconfig = None

while True:
	time.sleep(1)
	caps = dp.get_pad("sink").get_negotiated_caps()
	config =  caps[0]["configuration"]
	if not oldconfig:
		print "original config: ", config 
	elif config != oldconfig:
		print "DIFFERENT CONFIGURATION: ", config
	else:
		print "same"
	oldconfig = config
	dp = add(pipeline)

pipeline.set_state(gst.STATE_NULL);
