Changeset c2ec30b423d074da6feb53c9c01e800ef9bcb286

Show
Ignore:
Timestamp:
27/11/06 02:42:48 (2 years ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1164591768 +0000
git-parent:

[7ac42ed10d35c37ecf2e3dbde47fa904df608200]

git-author:
Rafaël Carré <funman@videolan.org> 1164591768 +0000
Message:

Merge 2 functions for reading meta data
Simplify interval checking
Sleeps 10 seconds more
Releases input 1 time instead of 2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/misc/audioscrobbler.c

    rd3fe7f2 rc2ec30b  
    3737#include <time.h> 
    3838#endif 
    39 /* 
    40  * TODO : 
    41  * check meta_engine's state, and remove delaying of metadata reading 
    42  */ 
     39 
    4340#include <vlc/vlc.h> 
    4441#include <vlc_interface.h> 
     
    8380 
    8481    /* data about audioscrobbler session */ 
    85     int                     i_interval;         /* last interval recorded */ 
    86     time_t                  time_last_interval; /* when was it recorded ? */ 
     82    time_t                  time_next_exchange; /* when can we send data? */ 
    8783    char                    *psz_submit_host;   /* where to submit data ? */ 
    8884    int                     i_submit_port;      /* at which port ?        */ 
     
    114110static int Handshake    ( intf_thread_t *p_sd ); 
    115111static int ReadMetaData ( intf_thread_t *p_this ); 
    116 static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t  *p_input ); 
    117112void DeleteQueue        ( audioscrobbler_queue_t *p_queue ); 
    118113 
     
    186181    } 
    187182 
     183    p_intf->p_sys = p_sys; 
     184 
    188185    vlc_mutex_init( p_this, &p_sys->lock ); 
    189186 
     
    192189    p_sys->psz_submit_file = NULL; 
    193190    p_sys->b_handshaked = VLC_FALSE; 
    194     p_sys->i_interval = 0; 
    195     p_sys->time_last_interval = time( NULL ); 
     191    p_sys->time_next_exchange = time( NULL ); 
    196192    p_sys->psz_username = NULL; 
    197193    p_sys->b_paused = VLC_FALSE; 
     
    212208    p_sys->p_current_song = malloc( sizeof( audioscrobbler_song_t ) ); 
    213209    MALLOC_CHECK( p_sys->p_current_song ) 
     210    time( &p_sys->p_current_song->time_playing ); 
    214211 
    215212    /* queues can't contain more than 10 songs */ 
     
    301298    audioscrobbler_queue_t  *p_first_queue; 
    302299    int                     i_post_socket; 
    303     /* TODO: remove when meta_engine works */ 
    304300    time_t                  played_time; 
    305301 
     
    329325         * and if waiting interval is elapsed */ 
    330326        if ( ( p_sys->p_first_queue->i_songs_nb > 0 ) && 
    331             ( time( NULL ) >= 
    332             ( p_sys->time_last_interval + p_sys->i_interval )  ) ) 
     327            ( time( NULL ) >= p_sys->time_next_exchange ) ) 
    333328        { 
    334329            /* handshake if needed */ 
     
    348343                        intf_UserFatal( p_this, VLC_FALSE, 
    349344                            _("Last.fm username not set"), 
    350                             _("Please set an username or disable
     345                            _("Please set an username or disable
    351346                            "audioscrobbler plugin, and then restart VLC.\n" 
    352347                            "Visit https://www.last.fm/join/ to get an account") 
     
    369364                        /* protocol error : we'll try later */ 
    370365                        vlc_mutex_lock ( &p_sys->lock ); 
    371                         p_sys->i_interval = DEFAULT_INTERVAL
    372                         time( &p_sys->time_last_interval )
     366                        time( &p_sys->time_next_exchange )
     367                        p_sys->time_next_exchange += DEFAULT_INTERVAL
    373368                        vlc_mutex_unlock ( &p_sys->lock ); 
    374369                        break; 
     
    411406            { 
    412407                /* If connection fails, we assume we must handshake again */ 
    413                 p_sys->i_interval = DEFAULT_INTERVAL
    414                 time( &p_sys->time_last_interval )
     408                time( &p_sys->time_next_exchange )
     409                p_sys->time_next_exchange += DEFAULT_INTERVAL
    415410                p_sys->b_handshaked = VLC_FALSE; 
    416411                vlc_mutex_unlock( &p_sys->lock ); 
     
    435430            if ( p_buffer_pos ) 
    436431            { 
    437                 p_sys->i_interval = atoi( p_buffer_pos + 
     432                time( &p_sys->time_next_exchange ); 
     433                p_sys->time_next_exchange += atoi( p_buffer_pos + 
    438434                                            strlen( "INTERVAL " ) ); 
    439                 time( &p_sys->time_last_interval ); 
    440435            } 
    441436 
     
    498493        { 
    499494            /* we read the metadata of the playing song */ 
    500             /* TODO: remove when meta_engine works */ 
    501495            time( &played_time ); 
    502496            played_time -= p_sys->p_current_song->time_playing; 
     
    505499            vlc_mutex_unlock( &p_sys->lock ); 
    506500 
    507             /* TODO: remove when meta_engine works */ 
    508             if( played_time > 10 ) 
     501            if( played_time > 20 ) 
     502            /* wait at least 20 secondes before reading the meta data 
     503             * since the songs must be at least 30s */ 
    509504            { 
    510505                if ( ReadMetaData( p_this ) == VLC_ENOMEM ) 
     
    592587        PL_UNLOCK; 
    593588        pl_Release( p_playlist ); 
     589 
    594590        vlc_mutex_lock( &p_sys->lock ); 
    595591 
     
    598594 
    599595        vlc_mutex_unlock( &p_sys->lock ); 
     596 
    600597        return VLC_SUCCESS; 
    601598    } 
     
    811808    if ( p_buffer_pos ) 
    812809    { 
    813         p_sys->i_interval = atoi( p_buffer_pos + strlen( "INTERVAL " ) ); 
    814         time( &p_sys->time_last_interval ); 
     810        time( &p_sys->time_next_exchange ); 
     811        p_sys->time_next_exchange += 
     812                atoi( p_buffer_pos + strlen( "INTERVAL " ) ); 
    815813    } 
    816814 
     
    968966{ 
    969967    playlist_t          *p_playlist; 
    970     input_thread_t      *p_input    = NULL; 
     968    input_thread_t      *p_input        = NULL; 
    971969    vlc_value_t         video_val; 
    972970 
    973     intf_sys_t          *p_sys      = p_this->p_sys; 
    974  
    975     p_playlist = pl_Yield( p_this ); 
    976     PL_LOCK; 
    977     p_input = p_playlist->p_input; 
    978  
    979     if( !p_input ) 
    980     { 
    981         PL_UNLOCK; 
    982         pl_Release( p_playlist ); 
    983         return( VLC_SUCCESS ); 
    984     } 
    985  
    986     vlc_object_yield( p_input ); 
    987     PL_UNLOCK; 
    988     pl_Release( p_playlist ); 
    989  
    990     var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &video_val, NULL ); 
    991     if( ( video_val.i_int > 0 ) || \ 
    992         ( input_GetItem(p_input)->i_type == ITEM_TYPE_NET ) ) 
    993     { 
    994         msg_Dbg( p_this, "Not an audio only local file -> no submission"); 
    995         vlc_object_release( p_input ); 
    996  
    997         vlc_mutex_lock( &p_sys->lock ); 
    998         p_sys->b_queued = VLC_TRUE; 
    999         p_sys->b_metadata_read = VLC_TRUE; 
    1000         vlc_mutex_unlock( &p_sys->lock ); 
    1001  
    1002         return VLC_SUCCESS; 
    1003     } 
    1004  
    1005     return ReadLocalMetaData( p_this, p_input );     
    1006 } 
    1007  
    1008 /***************************************************************************** 
    1009  * ReadLocalMetaData : Puts current song's meta data in p_sys->p_current_song 
    1010  *****************************************************************************/ 
    1011 static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t  *p_input ) 
    1012 { 
    1013971    char                *psz_title      = NULL; 
    1014972    char                *psz_artist     = NULL; 
     
    1020978    int                 i_status; 
    1021979 
    1022     i_status = input_GetItem(p_input)->p_meta->i_status; 
     980    p_playlist = pl_Yield( p_this ); 
     981    PL_LOCK; 
     982    p_input = p_playlist->p_input; 
     983 
     984    if( !p_input ) 
     985    { 
     986        PL_UNLOCK; 
     987        pl_Release( p_playlist ); 
     988        return( VLC_SUCCESS ); 
     989    } 
     990 
     991    vlc_object_yield( p_input ); 
     992    PL_UNLOCK; 
     993    pl_Release( p_playlist ); 
     994 
     995    var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &video_val, NULL ); 
     996    if( ( video_val.i_int > 0 ) || \ 
     997        ( input_GetItem(p_input)->i_type == ITEM_TYPE_NET ) ) 
     998    { 
     999        msg_Dbg( p_this, "Not an audio only local file -> no submission"); 
     1000        vlc_object_release( p_input ); 
     1001 
     1002        vlc_mutex_lock( &p_sys->lock ); 
     1003        p_sys->b_queued = VLC_TRUE; 
     1004        p_sys->b_metadata_read = VLC_TRUE; 
     1005        vlc_mutex_unlock( &p_sys->lock ); 
     1006 
     1007        return VLC_SUCCESS; 
     1008    } 
    10231009 
    10241010    #define FREE_INPUT_AND_CHARS \ 
     
    10561042        } 
    10571043 
     1044    i_status = input_GetItem(p_input)->p_meta->i_status; 
     1045 
     1046    b_waiting = VLC_TRUE; 
     1047/*  TODO: meta data fetching doesn't work atm 
    10581048    vlc_mutex_lock( &p_sys->lock ); 
    10591049    b_waiting = p_sys->b_waiting_meta; 
    10601050    vlc_mutex_unlock( &p_sys->lock ); 
    1061  
    1062     /* TODO : replace 1 with ( i_status & ITEM_PREPARSED ) 
    1063      * when meta_engine works */ 
    1064     if ( ( b_waiting == VLC_FALSE ) ? 1 : ( i_status & ITEM_META_FETCHED ) ) 
     1051*/ 
     1052 
     1053    /* TODO: item preparsing is buggy on drag&drop and command line arguments 
     1054    if( i_status & ( !b_waiting ? ITEM_PREPARSED : ITEM_META_FETCHED ) ) 
     1055    */ 
     1056    if( 1 ) 
    10651057    { 
    10661058        ALLOC_ITEM_META( psz_artist, p_meta->psz_artist ) 
     
    11011093 
    11021094        msg_Dbg( p_this, "Meta data registered, waiting to be queued" ); 
    1103  
    1104         FREE_INPUT_AND_CHARS 
    1105     } 
    1106      
    1107     vlc_object_release( p_input ); 
     1095    } 
     1096    
     1097    FREE_INPUT_AND_CHARS  
    11081098    return VLC_SUCCESS; 
    11091099#undef FREE_INPUT_AND_CHARS