#!/usr/bin/env python

import sys

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

def main(args):
    _, uri, ip, port, base_time = args
    port, base_time = int(port), int(base_time)

    # make the pipeline
    pipeline = gst.parse_launch('gnomevfssrc name=src ! oggdemux ! '
                                'theoradec ! ffmpegcolorspace ! '
                                'videoscale ! ximagesink')
    pipeline.get_by_name('src').set_uri(uri) # uri interface

    # disable the pipeline's management of base_time -- we're going
    # to set it ourselves.
    pipeline.set_new_stream_time(gst.CLOCK_TIME_NONE)

    # make a clock slaving to the network
    clock = gst.NetClientClock(None, ip, port, base_time)

    # use it in the pipeline
    pipeline.set_base_time(base_time)
    pipeline.use_clock(clock)

    # now we go :)
    pipeline.set_state(gst.STATE_PLAYING)

    # wait until things stop
    pipeline.get_bus().poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, -1)
    pipeline.set_state(gst.STATE_NULL)

if __name__ == '__main__':
    main(sys.argv)
