Roxen.git / server / modules / icecast / icecast.pike

version» Context lines:

Roxen.git/server/modules/icecast/icecast.pike:1:   inherit "module"; - constant cvs_version="$Id: icecast.pike,v 1.4 2001/04/10 05:26:29 per Exp $"; + constant cvs_version="$Id: icecast.pike,v 1.5 2001/04/11 08:45:49 per Exp $";   constant thread_safe=1;      #define BSIZE 8192   #define METAINTERVAL 4192      #include <module.h>   #include <roxen.h>   #include <stat.h>   #include <request_trace.h>   
Roxen.git/server/modules/icecast/icecast.pike:53:    callbacks += ({ callback });    }       void remove_callback( function callback )    {    callbacks -= ({ callback });    }       void call_callbacks( mixed ... args )    { -  +     foreach( callbacks, function f )    if( mixed e = catch( f(@args) ) )    {    werror(describe_backtrace( e ) ); -  callbacks -= ({f}); +  remove_callback( f );    }    }       int realtime()    {    return (time()*1000+(int)(time(time())*1000)) - stream_start;    }       void destroy()    {    catch(fd->set_blocking());    catch(fd->close());    }       void feeder_thread( )    { -  while( realtime() > stream_position ) +  while( sizeof(callbacks) && +  realtime() > stream_position )    {    string frame = get_frame();    while( !frame )    {    fd->set_blocking();    fd->close();    fd = playlist->next_file();    buffer = 0;    bpos = 0;    frame = get_frame();    } -  +  // Actually, this is supposed to be quite constant.    stream_position += strlen(frame)*8000 / bitrate; -  +  werror( "%d\n", strlen(frame)*8000 / bitrate );    call_callbacks( frame ); -  }; +  } +  if(!sizeof(callbacks)) +  { +  stream_position = 0; +  stream_start = (time()*1000+(int)(time(time())*1000)); +  }    call_out( feeder_thread, 0.02 );    }       void start()    {    feeder_thread( ); // not actually a thread right now.    }       // Low level code.    static string buffer;    static int bpos;       static string|int getbytes( int n, int|void s )    {    if( !fd )    fd = playlist->next_file(); -  +  if( !fd ) +  return s?0:-1; +     if( !buffer || !strlen(buffer) )    {    bpos = 0;    buffer = fd->read( BSIZE );    }    if( !strlen(buffer) )    return s?0:-1;    if( s )    {    if( strlen(buffer) - bpos > n )
Roxen.git/server/modules/icecast/icecast.pike:263:    mapping handle( RequestID id )    {    NOCACHE();    accessed++;    if( connections == max_connections )    {    denied++;    return Roxen.http_string_answer( "Too many listeners\n" );    }    +  if( !stream->fd ) +  stream->fd = stream->playlist->next_file();       mapping meta = stream->playlist->metadata();    if( !meta )    {    denied++;    return Roxen.http_string_answer( "Too early\n" );    }       connections++;    int use_metadata;
Roxen.git/server/modules/icecast/icecast.pike:403:    mapping current_md;       int connected = time();       string status()    {    return sprintf( "%d. %s Time: %ds Remote: %s "    "%d sent, %d skipped<br />",id,protocol,    time()-connected,    (fd->query_address()/" ")[0], -  sent-skipped, skipped ); +  sent, skipped );    }       string gen_metadata( )    {    if(!current_md )    current_md = stream->playlist->metadata();    string s = sprintf( " StreamTitle='%s';StreamUrl='%s';",    current_md->name || current_md->path,    "")+"\0";    while( strlen(s) & 15 ) s+= "\0";
Roxen.git/server/modules/icecast/icecast.pike:426:    }       static void callback( string frame )    {    buffer += ({ frame });    if( sizeof( buffer ) > 10 )    {    skipped++;    buffer = buffer[1..];    } -  if( !sizeof( buffer ) ) +  if( sizeof( buffer ) == 1 )    send_more();    }       int headers_done;       static void send_more()    {    if( !strlen(current_block) )    {    headers_done = 1;
Roxen.git/server/modules/icecast/icecast.pike:451:    current_block = buffer[0];       if( do_meta )    {    if( (strlen( current_block ) + sent_bytes) - last_meta >= METAINTERVAL )    {    last_meta = (strlen( current_block ) + sent_bytes);    current_block += gen_metadata();    }    } -  +     buffer = buffer[1..];    sent++;    }    int n = fd->write( current_block ); -  if( !n || n < 0 ) -  closed(); + // if( n < 0 && fd->errno() ) + // closed(); +  if( n > 0 ) +  {    if( headers_done )    sent_bytes += n;    current_block = current_block[n..];    } -  +  }       static void md_callback( mapping metadata )    {    current_md = metadata;    }       static void closed( )    { -  +  fd->set_blocking( );    fd = 0;    stream->remove_callback( callback );    stream->playlist->remove_md_callback( md_callback );    _ccb( this_object() ); -  destruct( this_object() ); +  werror("Closed from client side\n"); + // destruct( this_object() );    }       static void create( Stdio.File _fd, string buffer,    string prot, int _meta, MPEGStream _stream,    function _closed )    {    protocol = prot;    fd = _fd;    do_meta = _meta;    stream = _stream;    _ccb = _closed;    current_block = buffer; -  fd->set_nonblocking( lambda(){}, send_more, closed ); +  fd->set_nonblocking( 0, send_more, closed );    if( stream )    stream->add_callback( callback );    if( stream->playlist )    stream->playlist->add_md_callback( md_callback );    }   }         class VarStreams   {