-
Notifications
You must be signed in to change notification settings - Fork 42
/
gmusicbrowser_server.pm
75 lines (65 loc) · 1.74 KB
/
gmusicbrowser_server.pm
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
# 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 opus/;
}
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;
}
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;