Example #1
0
void InputManager::UpdateName()
{
    assert( p_input );

    /* Update text, name and nowplaying */
    QString name;

    /* Try to get the nowplaying */
    char *format = var_InheritString( p_intf, "input-title-format" );
    char *formatted = NULL;
    if (format != NULL)
    {
        formatted = str_format_meta( p_input, format );
        free( format );
        if( formatted != NULL )
        {
            name = qfu(formatted);
            free( formatted );
        }
    }

    /* If we have Nothing */
    if( name.simplified().isEmpty() )
    {
        char *uri = input_item_GetURI( input_GetItem( p_input ) );
        char *file = uri ? strrchr( uri, '/' ) : NULL;
        if( file != NULL )
        {
            decode_URI( ++file );
            name = qfu(file);
        }
        else
            name = qfu(uri);
        free( uri );
    }

    name = name.trimmed();

    if( oldName != name )
    {
        emit nameChanged( name );
        oldName = name;
    }
}
Example #2
0
void VlcProc::update_current_input()
{
    input_thread_t* pInput = getIntf()->p_sys->p_input;
    if( !pInput )
        return;

    input_item_t *pItem = input_GetItem( pInput );
    if( pItem )
    {
        // Update short name (as defined by --input-title-format)
        char *psz_fmt = var_InheritString( getIntf(), "input-title-format" );
        char *psz_name = NULL;
        if( psz_fmt != NULL )
        {
            psz_name = str_format_meta( pInput, psz_fmt );
            free( psz_fmt );
        }

        SET_TEXT( m_cVarStreamName, UString( getIntf(),
                                             psz_name ? psz_name : "" ) );
        free( psz_name );

        // Update local path (if possible) or full uri
        char *psz_uri = input_item_GetURI( pItem );
        char *psz_path = make_path( psz_uri );
        char *psz_save = psz_path ? psz_path : psz_uri;
        SET_TEXT( m_cVarStreamURI, UString( getIntf(), psz_save ) );
        free( psz_path );
        free( psz_uri );

        // Update art uri
        char *psz_art = input_item_GetArtURL( pItem );
        SET_STRING( m_cVarStreamArt, string( psz_art ? psz_art : "" ) );
        free( psz_art );
    }
}
/*****************************************************************************
 * ItemChange: Playlist item change callback
 *****************************************************************************/
static int ItemChange( vlc_object_t *p_this, const char *psz_var,
                       vlc_value_t oldval, vlc_value_t newval, void *param )
{
    VLC_UNUSED(oldval);
    intf_thread_t *p_intf = (intf_thread_t *)param;
    playlist_t* p_playlist = (playlist_t*) p_this;
    char *psz_buf = NULL;
    input_thread_t *p_input;
    input_item_t *p_item = newval.p_address;
    bool b_is_item_current = !strcmp( "item-current", psz_var );

    /* Don't update Telepathy presence each time an item has been preparsed */
    if( b_is_item_current )
    { /* stores the current input item id */
        p_intf->p_sys->i_id = p_item->i_id;
        p_intf->p_sys->i_item_changes = 0;
    }
    else
    {

        if( p_item->i_id != p_intf->p_sys->i_id ) /* "item-change" */
            return VLC_SUCCESS;
        /* Some variable bitrate inputs call "item-change callbacks each time
         * their length is updated, that is several times per second.
         * We'll limit the number of changes to 10 per input. */
        if( p_intf->p_sys->i_item_changes > 10 )
            return VLC_SUCCESS;
        p_intf->p_sys->i_item_changes++;
    }

    p_input = playlist_CurrentInput( p_playlist );

    if( !p_input ) return VLC_SUCCESS;

    if( p_input->b_dead || !input_GetItem(p_input)->psz_name )
    {
        vlc_object_release( p_input );
        /* Not playing anything ... */
        switch( SendToTelepathy( p_intf, "" ) )
        {
            case VLC_ENOMEM:
                return VLC_ENOMEM;
            default:
                return VLC_SUCCESS;
        }
    }

    if( b_is_item_current )
        var_AddCallback( p_input, "state", StateChange, p_intf );

    /* We format the string to be displayed */
    psz_buf = str_format_meta( (vlc_object_t*) p_intf,
            p_intf->p_sys->psz_format );

    /* We don't need the input anymore */
    vlc_object_release( p_input );

    if( SendToTelepathy( p_intf, psz_buf ) == VLC_ENOMEM )
    {
        free( psz_buf );
        return VLC_ENOMEM;
    }
    free( psz_buf );
    return VLC_SUCCESS;
}