<commit_before>#!/usr/bin/python

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GstNet, GObject

GObject.threads_init()
Gst.init(None)


class Player(object):
    def __init__(self, filepath):
        self._filepath = filepath
        self.player = self.get_pipeline()

        self.bus = self.player.get_bus()
        self.bus.add_signal_watch()
        self.bus.connect("message", self.on_bus_msg)

        self._loop = False

        self.player.set_state(Gst.State.PAUSED)

        # bug ? as i get -1 for the standard
        self.GST_CLOCK_TIME_NONE = 18446744073709551615

        self._prerolling = True
        self._audio_sink = 'pulsesink'

    def stop(self):
        self.player.set_state(Gst.State.NULL)

    def get_pipeline(self):
        return Gst.parse_launch('filesrc location={0} ! '
                                .format(self._filepath)
                                + 'decodebin name=demux demux. \
                                ! eglglessink demux. ! ' + self.audio_sink)

    def on_bus_msg(self, bus, msg):
        if msg is None:
            return
        elif msg.type is Gst.MessageType.SEGMENT_DONE:
            self.player.seek_simple(Gst.Format.TIME, Gst.SeekFlags.SEGMENT, 0)
        elif msg.type is Gst.MessageType.ASYNC_DONE:
            if self._prerolling:
                self.player.seek_simple(Gst.Format.TIME,
                                        Gst.SeekFlags.FLUSH
                                        | Gst.SeekFlags.SEGMENT, 0)
                self.player.set_state(Gst.State.PLAYING)
                self._prerolling = False
        elif msg.type is Gst.MessageType.ERROR:
            print "Got message of type ", msg.type
            print "Got message of src ", msg.src
            print "Got message of error ", msg.parse_error()
            self.player.set_state(Gst.State.NULL)

    def about_to_finish(self, playbin):
        print "about to finish"
        if self._loop:
            print "adding to loop"
            self.player.props.uri = self._last_uri

    @property
    def loop(self):
        return self._loop

    @loop.setter
    def loop(self, value):
        self._loop = value

    @property
    def audio_sink(self):
        return self._audio_sink

    @audio_sink.setter
    def audio_sink(self, value):
        self._audio_sink = value


class MasterPlayer(Player):
    def __init__(self, filepath, port):
        super(MasterPlayer, self).__init__(filepath)

        self._port = port
        self._clock = self.player.get_clock()
        self.player.use_clock(self._clock)
        self._clock_provider = GstNet.NetTimeProvider.new(self._clock,
                                                          None,
                                                          self._port)
        self._base_time = self._clock.get_time()
        self.player.set_start_time(self.GST_CLOCK_TIME_NONE)
        self.player.set_base_time(self._base_time)

    @property
    def base_time(self):
        return self._base_time

    @property
    def port(self):
        return self._port


class SlavePlayer(Player):
    def __init__(self, filepath, ip, port, base_time):
        super(SlavePlayer, self).__init__(filepath)<commit_msg>Remove audio_sink property<commit_after>#!/usr/bin/python

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GstNet, GObject

GObject.threads_init()
Gst.init(None)


class Player(object):
    def __init__(self, filepath):
        self._filepath = filepath
        self.player = self.get_pipeline()

        self.bus = self.player.get_bus()
        self.bus.add_signal_watch()
        self.bus.connect("message", self.on_bus_msg)

        self._loop = False

        self.player.set_state(Gst.State.PAUSED)

        # bug ? as i get -1 for the standard
        self.GST_CLOCK_TIME_NONE = 18446744073709551615

        self._prerolling = True

    def stop(self):
        self.player.set_state(Gst.State.NULL)

    def get_pipeline(self):
        return Gst.parse_launch('filesrc location={0} ! '
                                .format(self._filepath)
                                + 'decodebin name=demux demux. \
                                ! eglglessink sync=true demux. \
                                ! alsasink sync=true')

    def on_bus_msg(self, bus, msg):
        if msg is None:
            return
        elif msg.type is Gst.MessageType.SEGMENT_DONE:
            self.player.seek_simple(Gst.Format.TIME, Gst.SeekFlags.SEGMENT, 0)
        elif msg.type is Gst.MessageType.ASYNC_DONE:
            if self._prerolling:
                self.player.seek_simple(Gst.Format.TIME,
                                        Gst.SeekFlags.FLUSH
                                        | Gst.SeekFlags.SEGMENT, 0)
                self.player.set_state(Gst.State.PLAYING)
                self._prerolling = False
        elif msg.type is Gst.MessageType.ERROR:
            print "Got message of type ", msg.type
            print "Got message of src ", msg.src
            print "Got message of error ", msg.parse_error()
            self.player.set_state(Gst.State.NULL)

    def about_to_finish(self, playbin):
        print "about to finish"
        if self._loop:
            print "adding to loop"
            self.player.props.uri = self._last_uri

    @property
    def loop(self):
        return self._loop

    @loop.setter
    def loop(self, value):
        self._loop = value


class MasterPlayer(Player):
    def __init__(self, filepath, port):
        super(MasterPlayer, self).__init__(filepath)

        self._port = port
        self._clock = self.player.get_clock()
        self.player.use_clock(self._clock)
        self._clock_provider = GstNet.NetTimeProvider.new(self._clock,
                                                          None,
                                                          self._port)
        self._base_time = self._clock.get_time()
        self.player.set_start_time(self.GST_CLOCK_TIME_NONE)
        self.player.set_base_time(self._base_time)

    @property
    def base_time(self):
        return self._base_time

    @property
    def port(self):
        return self._port


class SlavePlayer(Player):
    def __init__(self, filepath, ip, port, base_time):
        super(SlavePlayer, self).__init__(filepath)
{'fraction_non_alphanumeric': 0.09362644314407718, 'fraction_numerical': 0.008223944330222995, 'mean_word_length': 1.784676354029062, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1247818', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1860, 'n_words': 368}