Audio-Daemon

 view release on metacpan or  search on metacpan

Daemon/Shout.pm  view on Meta::CPAN

  my $tagline = "\"".$tag->{TITLE}."\" by ".$tag->{ARTIST};
  $player->updateMetadata($tagline);
  $self->{state}{curbyte} = 0;
  return 1;
}

sub closefile {
  my $self = shift;
  $self->debug("Closing open file");
  $self->{state}{curbyte} = 0;
  close $self->{_fh};
}

sub send_chunk {
  my $self = shift;
  return if (! defined $self->{_fh});
  my $player = $self->player;
  
  $self->{Pass}{chunk} = $self->{Pass}{chunk} || 2048;
  my $buff;
  my $len = sysread($self->{_fh}, $buff, $self->{Pass}{chunk});
  if ($len == 0 || ! defined $len) {
    $self->closefile;
    if ($self->{state}{regid} == $#{$self->{playlist}} && (! $self->{state}{repeat})) {
     $self->{state}{state} = 0;
    } else {
     $self->next;
     $self->initfile;
     $self->send_chunk;
    }
  } else {
    $self->{state}{curbyte} += $len;
    unless ($player->sendData($buff)) {
      $self->crit("send failed: ".$player->error);
    } else {
      $player->sleep;
    }
  }
}

sub send_status {
  my $self = shift;
  my $socket = $self->socket;
  my $out = $self->get_info;
  my $out = join $self->{sep}, @$out;
  $socket->send($out);
}

__END__

=head1 NAME 

Audio::Daemon::Shout - Audio::Daemon backend for libshout (icecast)

=head1 SYNOPSIS

  use Audio::Daemon::Shout;

  # set things up
  my $daemon = new Audio::Daemon::Shout( 
               Port => 9101, Allow => '10.1.1.0/24, 127.0.0.1',
               Pass => { bitrate => 64, ip => '10.10.10.1',
                         name => 'Jay\'s List',
                         port => 18000, mountpoint => 'admin',
                         password => 'secret', chunk => 4096} );

  # this should never return... it is a daemon after all.
  $daemon->mainloop;
  
=head1 DESCRIPTION

This is a Audio::Daemon module for interfacing with libshout and
consequently, icecast servers.  It uses the same client as all
Audio::Daemon modules, except the volume has no effect.

=head1 CONSTRUCTORS

There is but one method to contruct a new C<Audio::Daemon::MPG123::Server> object:

=over 4

=item Audio::Daemon::Shout->new(
      Port => $port, 
      [Log => \&logsub], 
      [Allow => <allowips>], 
      [Deny => <denyips>],
      Pass => { (whole slew of parameters for libshout connection) });

The new method can take the following arguments:

=over 4

=item Port

The local port to start listening and accepting commands on.

=item Log

This takes a reference to a function that's called for logging purposes, the format passed in is:

=over 4

<type>, <msg>, [caller(1)]

where <type> is one of debug, info, error, crit, warn.  
<msg> is the text message, and [caller] is the array 
returned by the second form of the perlfunc caller().
This will give you the method, line number, etc. of 
where the messagee is coming from.  With this logging 
feature, I don't have to worry about syslog, stdout, 
or how to report errors or debug info... you do!

=back 4

=item Allow, Deny

Access Control.  If you specify something for the Allow 
variable, it assumes everything not allowed will be 
denied.  If you specify something to denied it assumes 
everything else is allowed.  Wither neither set, everything 
is allowed.  It accepts multple formats all seperated by 



( run in 1.178 second using v1.01-cache-2.11-cpan-39bf76dae61 )