Changeset 53d7625 for gutenbach/debian


Ignore:
Timestamp:
Oct 24, 2003, 4:31:42 PM (21 years ago)
Author:
jtwang <jtwang>
Branches:
master, debian, mac, no-cups, nodebathena, web
Children:
ab55f2e
Parents:
6761cd4
git-author:
jtwang <jtwang> (10/24/03 16:31:42)
git-committer:
jtwang <jtwang> (10/24/03 16:31:42)
Message:

Removed output buffer when playing MPEG streams because files seem to
be cut by mpg123 if transfer cannot keep up with the file bitrate when
output buffer is enabled.

Added code to handle shoutcast playlists (Content-Type: audio/x-scpls)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gutenbach/debian/lib/sipbmp3-filter

    r6761cd4 r53d7625  
    22# Play the data on STDIN as an audio file
    33#
    4 # $Id: sipbmp3-filter,v 1.10 2003-10-22 20:36:08 jhawk Exp $
     4# $Id: sipbmp3-filter,v 1.11 2003-10-24 20:31:42 jtwang Exp $
    55# $Source: /tmp/tmp.UFBNno9997/RCS/sipbmp3-filter,v $
    66#
     
    4343#  -P logname
    4444#  -Q queuename (lpr -Q)
     45#  -Z random user-specified options
    4546#  -a printcap af (accounting file name)
    4647#  -d printcap sd entry (spool dir)
     
    122123    #
    123124    # Where <URI> is a valid URI for the stream, and <format> is a
    124     # recognized format name (currently 'MP3' or 'OGG'). <user:pass>
    125     # is an optional user and password pair for HTTP Basic Auth.
     125    # recognized format name (currently 'MP3' or 'OGG' or 'SHOUTCAST').
     126    # <user:pass> is an optional user and password pair for HTTP Basic Auth.
    126127    my $format, $uri, $userpass;
    127128
     
    152153              print ZEPHYR "Couldn't fork: $!\n";
    153154              close(ZEPHYR);
    154               return;
     155              die;
    155156          }
    156157
     
    165166              elsif ($contenttype eq "application/x-ogg") { $format="OGG" }
    166167              elsif ($contenttype eq "application/ogg") { $format="OGG" }
     168              elsif ($contenttype eq "audio/x-scpls") { $format="SHOUTCAST" }
    167169              else {
    168170                  print ZEPHYR
     
    194196    if (($format eq "MP3") ||
    195197        ($format eq "mp3")) {
    196       print ZEPHYR "Playing MP3 audio stream...\n";
     198      print ZEPHYR "MP3 audio stream...\n";
    197199      close(ZEPHYR);
    198200      &play_mpeg_stream($uri, $userpass);
    199     } elsif (($format eq "OGG") ||
     201    }
     202    elsif ($format eq "SHOUTCAST") {
     203        print ZEPHYR "Shoutcast playlist...\n";
     204        #Don't close ZEPHYR yet, will print the name of the stream if available
     205        $uri = &get_shoutcast($uri);
     206        close(ZEPHYR);
     207        &play_mpeg_stream($uri, undef);
     208    }   
     209    elsif (($format eq "OGG") ||
    200210             ($format eq "ogg")) {
    201       print ZEPHYR "Playing OggVorbis audio stream...\n";
     211      print ZEPHYR "OggVorbis stream...\n";
    202212      close(ZEPHYR);
    203213      &play_ogg_stream($uri, $userpass);
     
    208218}
    209219
     220# Process a Shoutcast playlist
     221# get_shoutcast(URI)
     222sub get_shoutcast {
     223  my $uri = shift(@_);
     224 
     225  # grab the shoutcast .pls file
     226  my $pid = open(W3M, "-|");
     227  unless (defined $pid) {
     228      print ZEPHYR "Couldn't fork: $!\n";
     229      close(ZEPHYR);
     230      die;
     231  }
     232  if (!$pid) { # child
     233      exec("/mit/sipb/bin/w3m","-dump_source",$uri) || die "Couldn't fork";
     234  }
     235  while (<W3M>) {
     236      if (/^File\d+=(\S+)/) {
     237          push(@uris, $1);
     238      }
     239      if (/^Title\d+=(.+)$/) {
     240          push(@titles, $1);
     241      }
     242  }
     243  close(W3M);
     244 
     245  # choose a random server
     246  $server = int(rand scalar(@uris));
     247  # print the name of the stream if available
     248  print ZEPHYR "$titles[$server]\n";
     249  return $uris[$server];
     250}
    210251
    211252# Play an MPEG audio stream
     
    255296      # redirect STDERR to STDOUT
    256297      open STDERR, '>&STDOUT';
    257       exec("/mit/infoagents/bin/mpg123", "-b16384", "-q", $up, $uri) ||
     298
     299      # disabling the buffer seems to improve streaming performances
     300      # (files don't get cut in the middle) - perhaps mpg123 fails to
     301      # wait for OS TCP buffer to be filled. -- jtwang 22 Oct 2003
     302      #exec("/mit/infoagents/bin/mpg123", "-b16384", "-q", $up, $uri ||
     303      #   die "Couldn't exec";
     304      exec("/mit/infoagents/bin/mpg123", "-q", $up, $uri) ||
    258305          die "Couldn't exec";
    259306  }
Note: See TracChangeset for help on using the changeset viewer.