File: gmusicbrowser_server.pm

package info (click to toggle)
gmusicbrowser 1.1.9-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,908 kB
  • sloc: perl: 33,804; makefile: 91; sh: 3
file content (76 lines) | stat: -rw-r--r-- 1,827 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright (C) 2005-2007 Quentin Sculo <squentin@free.fr>
#
# This file is part of Gmusicbrowser.
# Gmusicbrowser is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation
package Play_Server;
use strict;
use warnings;

my ($ChildPID,$WatchTag,$fh,@pidToKill);
my $cmd=$::DATADIR.::SLASH.'iceserver.pl';
$::PlayPacks{Play_Server}=1; #register the package

sub init
{	if (-e $cmd) {return bless {},__PACKAGE__}
	else {return}
}

sub supported_formats
{ qw/flac mp3 mpc oga wv ape m4a/;
}

sub Close {}

sub Play
{	shift;
	close $fh if $fh;
	my $file=shift;
	$ChildPID=open $fh,'-|',$cmd,'-p',$::Options{Icecast_port},$file;
	$WatchTag= Glib::IO->add_watch(fileno($fh),'G_IO_HUP',\&_eos_cb);
}

sub _eos_cb
{	Glib::Source->remove($WatchTag) or warn "couldn't remove watcher";
	undef $WatchTag;
	undef $ChildPID;
	::end_of_file_faketime;
	return 1;
}

sub Stop
{	if ($WatchTag)
	{	Glib::Source->remove($WatchTag) or warn "couldn't remove watcher";
		undef $WatchTag;
	}
	if ($ChildPID)
	{	warn "killing $ChildPID\n" if $::debug;
		#kill TERM=>$ChildPID;
		kill INT=>$ChildPID;
		Glib::Timeout->add( 200,\&_Kill_timeout ) unless @pidToKill;
		push @pidToKill,$ChildPID;
		undef $ChildPID;
	}
}
sub _Kill_timeout	#make sure old children are dead
{	@pidToKill=grep kill(0,$_), @pidToKill;
	if (@pidToKill)
	{ warn "killing -9 @pidToKill\n" if $::debug;
	  kill KILL => @pidToKill;
	  undef @pidToKill;
	}
	#while (waitpid(-1, WNOHANG)>0) {}	#reap dead children
	return 0;
}

sub Pause	{kill STOP=>$ChildPID if $ChildPID}
sub Resume	{kill CONT=>$ChildPID if $ChildPID}
sub SkipTo	{}

sub SetVolume	{}
sub GetVolume	{-1}
sub GetVolumeError { _"Can't change the volume in non-gstreamer iceserver mode" }
sub GetMute	{0}

1;