| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Netx::WebRadio; |
|
3
|
1
|
|
|
1
|
|
22373
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
41
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
99
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
|
9
|
|
|
|
|
|
|
#use Exporter (); |
|
10
|
1
|
|
|
1
|
|
5
|
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
167
|
|
|
11
|
1
|
|
|
1
|
|
20796
|
$VERSION = 0.03; |
|
12
|
|
|
|
|
|
|
#@ISA = qw (Exporter); |
|
13
|
|
|
|
|
|
|
#@EXPORT = qw (); |
|
14
|
|
|
|
|
|
|
#@EXPORT_OK = qw (); |
|
15
|
|
|
|
|
|
|
#%EXPORT_TAGS = (); |
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
33
|
|
|
18
|
1
|
|
|
1
|
|
879
|
use IO::Poll 0.04 qw(POLLIN POLLOUT POLLERR POLLHUP); |
|
|
1
|
|
|
|
|
9133
|
|
|
|
1
|
|
|
|
|
108
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Class::MethodMaker |
|
21
|
1
|
|
|
|
|
10
|
new_with_init => 'new', |
|
22
|
1
|
|
|
1
|
|
932
|
get_set => [ qw /timeout poll stations station_sockets/ ]; |
|
|
1
|
|
|
|
|
912891
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Netx::WebRadio - receive one or more webradio-stations |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use Netx::WebRadio |
|
34
|
|
|
|
|
|
|
my $receiver = Netx::WebRadio->new(); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $station = Netx::WebRadio::Station::Shoutcast->new();
|
|
37
|
|
|
|
|
|
|
$station->host( $server->[0] );
|
|
38
|
|
|
|
|
|
|
$station->port( $server->[1] );
|
|
39
|
|
|
|
|
|
|
$receiver->add_station( $station ) if $station->connect( $server->[0], $server->[1] ) ;
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
while ($receiver->number_of_stations) {
|
|
42
|
|
|
|
|
|
|
$receiver->receive();
|
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
THIS IS BETA SOFTWARE! |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Netx::WebRadio is a framework for receiving one or more webradio streams. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
It's implemented with the so-called 'template-pattern' - inherit from it and overload some mehtods. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Netx::WebRadio works as a multiplexer for one or more Netx::WebRadio::Station-objects (eg Netx::WebRadio::Station::Shoutcast). |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 USAGE |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
To change the handling of certain events (timeout, disconnect) you have to overload some methods. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Look at the Examples/ directory for examples. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 METHODS |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 add_station |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Usage : $receiver->add_station( $station ) |
|
66
|
|
|
|
|
|
|
Purpose : |
|
67
|
|
|
|
|
|
|
Adds a (already connected) station for receiving. |
|
68
|
|
|
|
|
|
|
Returns : nothing |
|
69
|
|
|
|
|
|
|
Argument : station-object |
|
70
|
|
|
|
|
|
|
Throws : nothing |
|
71
|
|
|
|
|
|
|
See Also : remove_station |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub add_station { |
|
76
|
0
|
|
|
0
|
1
|
0
|
my ($self, $station) = @_; |
|
77
|
0
|
0
|
|
|
|
0
|
croak "no station specified" unless $station; |
|
78
|
0
|
|
|
|
|
0
|
$self->poll->mask( $station->socket => $station->pollmode ); |
|
79
|
0
|
|
|
|
|
0
|
$self->store_station_socket( $station ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 remove_station |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Usage : $receiver->remove_station( $station ) |
|
85
|
|
|
|
|
|
|
Purpose : |
|
86
|
|
|
|
|
|
|
Removes a station. |
|
87
|
|
|
|
|
|
|
Returns : nothing |
|
88
|
|
|
|
|
|
|
Argument : station-object |
|
89
|
|
|
|
|
|
|
Throws : nothing |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub remove_station { |
|
94
|
0
|
|
|
0
|
1
|
0
|
my ($self, $station) = @_; |
|
95
|
0
|
0
|
|
|
|
0
|
croak "no station specified" unless $station; |
|
96
|
0
|
|
|
|
|
0
|
$self->poll->remove( $station->socket ); |
|
97
|
0
|
|
|
|
|
0
|
$self->remove_station_socket( $station ); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 number_of_stations |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Usage : $receiver->number_of_stations() |
|
103
|
|
|
|
|
|
|
Purpose : |
|
104
|
|
|
|
|
|
|
Returns the number of stations. |
|
105
|
|
|
|
|
|
|
Returns : number of stations |
|
106
|
|
|
|
|
|
|
Argument : nothing |
|
107
|
|
|
|
|
|
|
Throws : nothing |
|
108
|
|
|
|
|
|
|
See Also : |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub number_of_stations { |
|
113
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
114
|
0
|
|
|
|
|
0
|
return $self->poll->handles |
|
115
|
|
|
|
|
|
|
}; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 receive |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Usage : $receiver->receive() |
|
120
|
|
|
|
|
|
|
Purpose : |
|
121
|
|
|
|
|
|
|
Tries to receive next chunk from all stations. |
|
122
|
|
|
|
|
|
|
Call it in a loop. |
|
123
|
|
|
|
|
|
|
Returns : nothing |
|
124
|
|
|
|
|
|
|
Argument : nothing |
|
125
|
|
|
|
|
|
|
Throws : nothing |
|
126
|
|
|
|
|
|
|
See Also : |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub receive { |
|
131
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
0
|
if ($self->poll->handles) { |
|
134
|
0
|
|
|
|
|
0
|
$self->poll->poll( $self->timeout ); |
|
135
|
0
|
|
|
|
|
0
|
my @ready = $self->poll->handles(POLLIN|POLLHUP|POLLERR|POLLOUT); |
|
136
|
0
|
0
|
|
|
|
0
|
unless ( scalar @ready ) { |
|
137
|
0
|
|
|
|
|
0
|
$self->timeout_all_stations(); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
0
|
foreach my $socket ( @ready ) { |
|
141
|
0
|
|
|
|
|
0
|
my $station = $self->get_station_by_socket( $socket ); |
|
142
|
0
|
|
|
|
|
0
|
my $return = $station->receive(); |
|
143
|
0
|
0
|
|
|
|
0
|
if ( $return ) { |
|
144
|
0
|
|
|
|
|
0
|
$self->poll->mask( $socket => $station->pollmode ); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
else { |
|
147
|
0
|
|
|
|
|
0
|
$self->error_in_station( $station ); |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 timeout |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Usage : $receiver->timeout( 30 ) |
|
156
|
|
|
|
|
|
|
Purpose : |
|
157
|
|
|
|
|
|
|
Sets the timeout value for all stations. |
|
158
|
|
|
|
|
|
|
Returns : nothing |
|
159
|
|
|
|
|
|
|
Argument : timeout in seconds |
|
160
|
|
|
|
|
|
|
Throws : nothing |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
See Also : timeout_all_stations |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Overload the following methods: |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 init |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Usage : init is called from new |
|
169
|
|
|
|
|
|
|
Purpose : |
|
170
|
|
|
|
|
|
|
Initializes some values, create Poll-Object. |
|
171
|
|
|
|
|
|
|
Always call SUPER::init if you overload this method. |
|
172
|
|
|
|
|
|
|
Returns : nothing |
|
173
|
|
|
|
|
|
|
Argument : nothing |
|
174
|
|
|
|
|
|
|
Throws : nothing |
|
175
|
|
|
|
|
|
|
See Also : |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub init { |
|
180
|
1
|
|
|
1
|
1
|
72
|
my $self = shift; |
|
181
|
1
|
|
33
|
|
|
12
|
$self->poll( IO::Poll->new() |
|
182
|
|
|
|
|
|
|
or croak "Couldn't create IO::Poll-Object" ); |
|
183
|
1
|
50
|
|
|
|
87
|
$self->timeout(30) unless $self->timeout(); |
|
184
|
1
|
|
|
|
|
70
|
$self->station_sockets( {} ); |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 timeout_all_stations |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Usage : timeout_all_stations is called if there is a network-timeout. |
|
190
|
|
|
|
|
|
|
Purpose : |
|
191
|
|
|
|
|
|
|
overload it :) |
|
192
|
|
|
|
|
|
|
You can change the timeout-time with the 'timeout'-method. |
|
193
|
|
|
|
|
|
|
Returns : nothing |
|
194
|
|
|
|
|
|
|
Argument : nothing |
|
195
|
|
|
|
|
|
|
Throws : nothing |
|
196
|
|
|
|
|
|
|
See Also : timeout |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub timeout_all_stations { |
|
201
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
202
|
0
|
|
|
|
|
|
return; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 error_in_station |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Usage : error_in_station is called if a station returns an error. |
|
208
|
|
|
|
|
|
|
Purpose : |
|
209
|
|
|
|
|
|
|
overload it :) |
|
210
|
|
|
|
|
|
|
The default implementation removes the station from the receiver. |
|
211
|
|
|
|
|
|
|
Returns : nothing |
|
212
|
|
|
|
|
|
|
Argument : nothing |
|
213
|
|
|
|
|
|
|
Throws : nothing |
|
214
|
|
|
|
|
|
|
See Also : timeout |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub error_in_station { |
|
219
|
0
|
|
|
0
|
1
|
|
my ($self, $station) = @_; |
|
220
|
0
|
|
|
|
|
|
carp "error in station\n"; |
|
221
|
0
|
|
|
|
|
|
$self->remove_station( $station ); |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 BUGS |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Doesn't work under Win32... please send patches :-) |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 SUPPORT |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 AUTHOR |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Nathanael Obermayer |
|
237
|
|
|
|
|
|
|
CPAN ID: nathanael |
|
238
|
|
|
|
|
|
|
natom-pause@smi2le.net |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
243
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
246
|
|
|
|
|
|
|
LICENSE file included with this module. |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
perl(1). |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub get_station_by_socket { |
|
257
|
0
|
|
|
0
|
0
|
|
my ($self, $socket) = @_; |
|
258
|
0
|
|
|
|
|
|
return $self->station_sockets->{ $socket }; |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub store_station_socket { |
|
262
|
0
|
|
|
0
|
0
|
|
my ($self, $station) = @_; |
|
263
|
0
|
|
|
|
|
|
$self->station_sockets->{ $station->socket } = $station; |
|
264
|
|
|
|
|
|
|
} |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub remove_station_socket { |
|
267
|
0
|
|
|
0
|
0
|
|
my ($self, $station) = @_; |
|
268
|
0
|
|
|
|
|
|
$self->station_sockets->{ $station->socket } = undef; |
|
269
|
|
|
|
|
|
|
} |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
1; #this line is important and will help the module return a true value |
|
273
|
|
|
|
|
|
|
__END__ |