Esempio n. 1
0
File: sap.c Progetto: forthyen/SDesk
static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address )
{
    int i_read;
    char buffer[SAP_MAX_BUFFER];
    int i_tot = 0;
    mtime_t i_temp;
    int i_rate;

    if( p_address->t1 == 0 )
    {
        p_address->t1 = mdate();
        return VLC_SUCCESS;
    }
    do
    {
        /* Might be too slow if we have huge data */
        i_read = net_ReadNonBlock( p_sap, p_address->i_rfd, buffer,
                                   SAP_MAX_BUFFER, 0 );
        i_tot += i_read;
    } while( i_read > 0 && i_tot < SAP_MAX_BUFFER );

    i_temp = mdate();

    /* We calculate the rate every 5 seconds */
    if( i_temp - p_address->t1 < 5000000 )
    {
        p_address->i_buff += i_tot;
        return VLC_SUCCESS;
    }

    /* Bits/second */
    i_rate = (int)(8*1000000*((mtime_t)p_address->i_buff + (mtime_t)i_tot ) /
                        (i_temp - p_address->t1 ));

    p_address->i_limit = 10000;

    p_address->i_interval = ((1000*i_rate / p_address->i_limit) *
                            (MAX_INTERVAL - MIN_INTERVAL))/1000 + MIN_INTERVAL;

    if( p_address->i_interval > MAX_INTERVAL || p_address->i_interval < 0 )
    {
        p_address->i_interval = MAX_INTERVAL;
    }
#ifdef EXTRA_DEBUG
    msg_Dbg( p_sap,"%s:%i : Rate=%i, Interval = %i s",
                    p_address->psz_address,p_address->i_port,
                    i_rate,
                    p_address->i_interval );
#endif

    p_address->b_ready = VLC_TRUE;

    p_address->t1 = i_temp;
    p_address->i_buff = 0;

    return VLC_SUCCESS;
}
Esempio n. 2
0
/*****************************************************************************
 * NetCommand: Get a command from the network
 *****************************************************************************/
static void NetCommand( sout_stream_t *p_stream )
{
    sout_stream_sys_t *p_sys = p_stream->p_sys;
    char psz_buffer[11];
    int i_len = net_ReadNonBlock( p_stream, p_sys->i_fd, NULL, (uint8_t *)&psz_buffer[0],
                                  sizeof( psz_buffer ) - 1, 0 );

    if ( i_len > 0 )
    {
        psz_buffer[i_len] = '\0';
        int i_cmd = strtol( psz_buffer, NULL, 0 );
        if ( i_cmd < -1 || i_cmd > p_sys->i_nb_pictures )
        {
            msg_Err( p_stream, "got a wrong command (%d)", i_cmd );
            return;
        }

        p_sys->i_cmd = i_cmd;

        msg_Dbg( p_stream, "new command: %d old:%d", p_sys->i_cmd,
                 p_sys->i_old_cmd );
    }
}
Esempio n. 3
0
vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
{
    int i_read = 0;

#ifdef WIN32
    if( p_intf->p_sys->i_socket == -1 )
        return ReadWin32( p_intf, p_buffer, pi_size );
#endif

    while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
           (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
                       STDIN_FILENO : p_intf->p_sys->i_socket,
                       p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
    {
        if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
            break;

        (*pi_size)++;
    }

    /* Connection closed */
    if( i_read == -1 )
    {
        p_intf->p_sys->i_socket = -1;
        p_buffer[ *pi_size ] = 0;
        return VLC_TRUE;
    }

    if( *pi_size == MAX_LINE_LENGTH ||
        p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
    {
        p_buffer[ *pi_size ] = 0;
        return VLC_TRUE;
    }

    return VLC_FALSE;
}