- /* handshake if needed */
- if( p_sys->b_handshaked == VLC_FALSE )
- {
- msg_Dbg( p_this, "Handshaking with last.fm ..." );
-
- switch( Handshake( p_this ) )
- {
- case VLC_ENOMEM:
- MEM_ERROR
- break;
-
- case VLC_ENOVAR:
- /* username not set */
- vlc_mutex_unlock ( &p_sys->lock );
- intf_UserFatal( p_this, VLC_FALSE,
- _("Last.fm username not set"),
- _("Please set an username or disable "
- "audioscrobbler plugin, and then restart VLC.\n"
- "Visit https://www.last.fm/join/ to get an account")
- );
- free( psz_submit );
- free( psz_submit_song );
- free( p_buffer );
- return;
- break;
-
- case VLC_SUCCESS:
- msg_Dbg( p_this, "Handshake successfull :)" );
- vlc_mutex_lock ( &p_sys->lock );
- p_sys->b_handshaked = VLC_TRUE;
- vlc_mutex_unlock ( &p_sys->lock );
- break;
-
- case VLC_EGENERIC:
- default:
- /* protocol error : we'll try later */
- vlc_mutex_lock ( &p_sys->lock );
- time( &p_sys->time_next_exchange );
- p_sys->time_next_exchange += DEFAULT_INTERVAL;
- vlc_mutex_unlock ( &p_sys->lock );
- break;
- }
- /* handshake is done or failed, lets start from
- * beginning to check it out and wait INTERVAL if needed
- */
- continue;
- }
+ vlc_object_unlock( p_intf );
+ msg_Dbg( p_intf, "audioscrobbler is dying");
+ return;
+ }
+ if( mdate() < p_sys->next_exchange )
+ /* wait until we can resubmit, i.e. */
+ b_wait = vlc_object_timedwait( p_intf, p_sys->next_exchange ) == 0;
+ else
+ /* wait for data to submit */
+ /* we are signaled each time there is a song to submit */
+ vlc_object_wait( p_intf );
+ vlc_object_unlock( p_intf );