<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Copyright 2012-2013 OpenBroadcaster, Inc.

This file is part of OpenBroadcaster Remote.

OpenBroadcaster Remote is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OpenBroadcaster Remote is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with OpenBroadcaster Remote.  If not, see <http://www.gnu.org/licenses/>.
"""

import obplayer

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

import gtk
import gobject

import thread
import threading


class ObPlayer:

    def __init__(self):
        self.media_stop_timestamp = 0  # keep track of when media is supposed to play for (required for 'is_playing').
        self.media_mode = None
        self.player = None
	self.now_playing = None

	self.media_actual_start = 0
	self.stats_seek_time = 0

    def player_init(self):

        self.player = gst.element_factory_make('playbin2', 'player')

        audio_output = obplayer.Config.setting('audio_output')
        if audio_output == 'alsa':
            self.sc_sink = gst.element_factory_make('alsasink', 'sc_sink')
            alsa_device = obplayer.Config.setting('alsa_device')
            if alsa_device != '':
                self.sc_sink.set_property('device', alsa_device)

        elif audio_output == 'esd':
            self.sc_sink = gst.element_factory_make('esdsink', 'sc_sink')

        elif audio_output == 'jack':
            self.sc_sink = gst.element_factory_make('jackaudiosink', 'sc_sink')
            self.sc_sink.set_property('connect', 0)  # don't autoconnect ports.
	    name = obplayer.Config.setting('jack_port_name')
            self.sc_sink.set_property('client-name', name if name else 'obplayer')

        elif audio_output == 'oss':
            self.sc_sink = gst.element_factory_make('osssink', 'sc_sink')

        elif audio_output == 'pulse':
            self.sc_sink = gst.element_factory_make('pulsesink', 'sc_sink')

        elif audio_output == 'test':
            self.sc_sink = gst.element_factory_make('fakesink', 'sc_sink')

        else:
	    # this is stdout audio output (experimental, some possibility to use with streaming but doesn't propery output silence as audio data).
            self.sc_sink = gst.element_factory_make('autoaudiosink', 'sc_sink')

        self.player.set_property('audio-sink', self.sc_sink)

        if obplayer.Config.setting('audiovis'):
            self.audiovis = gst.element_factory_make('libvisual_jess')
            self.player.set_property('flags', self.player.get_property('flags') | 0x00000008)
            self.player.set_property('vis-plugin', self.audiovis)

        self.bus = self.player.get_bus()
	self.bus.add_signal_watch()
	self.bus.enable_sync_message_emission()
	self.bus.connect("sync-message::element", self.sync_handler)

	# NOTE this was possibly another way of making a video output??
        #self.sink = gst.element_factory_make('xvimagesink')
        #self.sink.set_property('force-aspect-ratio', True)
	#self.player.set_property('video-sink', self.sink)

	# wait for state change.
        if self.wait_sync() == False:
            obplayer.Log.log('ObPlayer.init wait for state change (wait_sync()) failed (after stop).', 'error')

    # TODO this function should be moved to Gui, but make sure you don't need self.media_mode, and also see if it's possible to clean up the Gui.  Image displaying isn't working
    def change_media_mode(self, mode):
	if obplayer.Main.headless:
	    return

	if mode == 'image' or (mode == 'audio' and obplayer.Config.setting('audiovis') == 0):
	    obplayer.Gui.gui_gst_area_viewport.hide()
	    obplayer.Gui.gui_drawing_area_viewport.show()

	else:
	    obplayer.Gui.gui_drawing_area_viewport.hide()
	    obplayer.Gui.gui_gst_area_viewport.show()

	self.media_mode = mode

    #
    #
    # Play file.<commit_msg>Added hack to clear the image display canvas<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Copyright 2012-2013 OpenBroadcaster, Inc.

This file is part of OpenBroadcaster Remote.

OpenBroadcaster Remote is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OpenBroadcaster Remote is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with OpenBroadcaster Remote.  If not, see <http://www.gnu.org/licenses/>.
"""

import obplayer

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

import gtk
import gobject

import thread
import threading


class ObPlayer:

    def __init__(self):
        self.media_stop_timestamp = 0  # keep track of when media is supposed to play for (required for 'is_playing').
        self.media_mode = None
        self.player = None
	self.now_playing = None

	self.media_actual_start = 0
	self.stats_seek_time = 0

    def player_init(self):

        self.player = gst.element_factory_make('playbin2', 'player')

        audio_output = obplayer.Config.setting('audio_output')
        if audio_output == 'alsa':
            self.sc_sink = gst.element_factory_make('alsasink', 'sc_sink')
            alsa_device = obplayer.Config.setting('alsa_device')
            if alsa_device != '':
                self.sc_sink.set_property('device', alsa_device)

        elif audio_output == 'esd':
            self.sc_sink = gst.element_factory_make('esdsink', 'sc_sink')

        elif audio_output == 'jack':
            self.sc_sink = gst.element_factory_make('jackaudiosink', 'sc_sink')
            self.sc_sink.set_property('connect', 0)  # don't autoconnect ports.
	    name = obplayer.Config.setting('jack_port_name')
            self.sc_sink.set_property('client-name', name if name else 'obplayer')

        elif audio_output == 'oss':
            self.sc_sink = gst.element_factory_make('osssink', 'sc_sink')

        elif audio_output == 'pulse':
            self.sc_sink = gst.element_factory_make('pulsesink', 'sc_sink')

        elif audio_output == 'test':
            self.sc_sink = gst.element_factory_make('fakesink', 'sc_sink')

        else:
	    # this is stdout audio output (experimental, some possibility to use with streaming but doesn't propery output silence as audio data).
            self.sc_sink = gst.element_factory_make('autoaudiosink', 'sc_sink')

        self.player.set_property('audio-sink', self.sc_sink)

        if obplayer.Config.setting('audiovis'):
            self.audiovis = gst.element_factory_make('libvisual_jess')
            self.player.set_property('flags', self.player.get_property('flags') | 0x00000008)
            self.player.set_property('vis-plugin', self.audiovis)

        self.bus = self.player.get_bus()
	self.bus.add_signal_watch()
	self.bus.enable_sync_message_emission()
	self.bus.connect("sync-message::element", self.sync_handler)

	# NOTE this was possibly another way of making a video output??
        #self.sink = gst.element_factory_make('xvimagesink')
        #self.sink.set_property('force-aspect-ratio', True)
	#self.player.set_property('video-sink', self.sink)

	# wait for state change.
        if self.wait_sync() == False:
            obplayer.Log.log('ObPlayer.init wait for state change (wait_sync()) failed (after stop).', 'error')

    # TODO this function should be moved to Gui, but make sure you don't need self.media_mode, and also see if it's possible to clean up the Gui.  Image displaying isn't working
    def change_media_mode(self, mode):
	if obplayer.Main.headless:
	    return

	if mode == 'image' or (mode == 'audio' and obplayer.Config.setting('audiovis') == 0):
	    obplayer.Gui.gui_gst_area_viewport.hide()
	    obplayer.Gui.gui_drawing_area_viewport.show()
	    # HACK if the image area is not currently visible, then clear what was previous displayed on the image area
	    if not obplayer.Gui.gui_drawing_area_viewport.is_visible():
		obplayer.Gui.pixbuf = False
		obplayer.Gui.pixbuf_original = False

	else:
	    obplayer.Gui.gui_drawing_area_viewport.hide()
	    obplayer.Gui.gui_gst_area_viewport.show()

	self.media_mode = mode

    #
    #
    # Play file.
{'fraction_non_alphanumeric': 0.10120263217608351, 'fraction_numerical': 0.006353528477422283, 'mean_word_length': 3.363861386138614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1503008', 'n_tokens_mistral': 2834, 'n_tokens_neox': 2679, 'n_words': 742}