Changeset c2ec30b423d074da6feb53c9c01e800ef9bcb286
- 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
| rd3fe7f2 |
rc2ec30b |
|
| 37 | 37 | #include <time.h> |
|---|
| 38 | 38 | #endif |
|---|
| 39 | | /* |
|---|
| 40 | | * TODO : |
|---|
| 41 | | * check meta_engine's state, and remove delaying of metadata reading |
|---|
| 42 | | */ |
|---|
| | 39 | |
|---|
| 43 | 40 | #include <vlc/vlc.h> |
|---|
| 44 | 41 | #include <vlc_interface.h> |
|---|
| … | … | |
| 83 | 80 | |
|---|
| 84 | 81 | /* 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? */ |
|---|
| 87 | 83 | char *psz_submit_host; /* where to submit data ? */ |
|---|
| 88 | 84 | int i_submit_port; /* at which port ? */ |
|---|
| … | … | |
| 114 | 110 | static int Handshake ( intf_thread_t *p_sd ); |
|---|
| 115 | 111 | static int ReadMetaData ( intf_thread_t *p_this ); |
|---|
| 116 | | static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t *p_input ); |
|---|
| 117 | 112 | void DeleteQueue ( audioscrobbler_queue_t *p_queue ); |
|---|
| 118 | 113 | |
|---|
| … | … | |
| 186 | 181 | } |
|---|
| 187 | 182 | |
|---|
| | 183 | p_intf->p_sys = p_sys; |
|---|
| | 184 | |
|---|
| 188 | 185 | vlc_mutex_init( p_this, &p_sys->lock ); |
|---|
| 189 | 186 | |
|---|
| … | … | |
| 192 | 189 | p_sys->psz_submit_file = NULL; |
|---|
| 193 | 190 | 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 ); |
|---|
| 196 | 192 | p_sys->psz_username = NULL; |
|---|
| 197 | 193 | p_sys->b_paused = VLC_FALSE; |
|---|
| … | … | |
| 212 | 208 | p_sys->p_current_song = malloc( sizeof( audioscrobbler_song_t ) ); |
|---|
| 213 | 209 | MALLOC_CHECK( p_sys->p_current_song ) |
|---|
| | 210 | time( &p_sys->p_current_song->time_playing ); |
|---|
| 214 | 211 | |
|---|
| 215 | 212 | /* queues can't contain more than 10 songs */ |
|---|
| … | … | |
| 301 | 298 | audioscrobbler_queue_t *p_first_queue; |
|---|
| 302 | 299 | int i_post_socket; |
|---|
| 303 | | /* TODO: remove when meta_engine works */ |
|---|
| 304 | 300 | time_t played_time; |
|---|
| 305 | 301 | |
|---|
| … | … | |
| 329 | 325 | * and if waiting interval is elapsed */ |
|---|
| 330 | 326 | 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 ) ) |
|---|
| 333 | 328 | { |
|---|
| 334 | 329 | /* handshake if needed */ |
|---|
| … | … | |
| 348 | 343 | intf_UserFatal( p_this, VLC_FALSE, |
|---|
| 349 | 344 | _("Last.fm username not set"), |
|---|
| 350 | | _("Please set an username or disable" |
|---|
| | 345 | _("Please set an username or disable " |
|---|
| 351 | 346 | "audioscrobbler plugin, and then restart VLC.\n" |
|---|
| 352 | 347 | "Visit https://www.last.fm/join/ to get an account") |
|---|
| … | … | |
| 369 | 364 | /* protocol error : we'll try later */ |
|---|
| 370 | 365 | 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; |
|---|
| 373 | 368 | vlc_mutex_unlock ( &p_sys->lock ); |
|---|
| 374 | 369 | break; |
|---|
| … | … | |
| 411 | 406 | { |
|---|
| 412 | 407 | /* 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; |
|---|
| 415 | 410 | p_sys->b_handshaked = VLC_FALSE; |
|---|
| 416 | 411 | vlc_mutex_unlock( &p_sys->lock ); |
|---|
| … | … | |
| 435 | 430 | if ( p_buffer_pos ) |
|---|
| 436 | 431 | { |
|---|
| 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 + |
|---|
| 438 | 434 | strlen( "INTERVAL " ) ); |
|---|
| 439 | | time( &p_sys->time_last_interval ); |
|---|
| 440 | 435 | } |
|---|
| 441 | 436 | |
|---|
| … | … | |
| 498 | 493 | { |
|---|
| 499 | 494 | /* we read the metadata of the playing song */ |
|---|
| 500 | | /* TODO: remove when meta_engine works */ |
|---|
| 501 | 495 | time( &played_time ); |
|---|
| 502 | 496 | played_time -= p_sys->p_current_song->time_playing; |
|---|
| … | … | |
| 505 | 499 | vlc_mutex_unlock( &p_sys->lock ); |
|---|
| 506 | 500 | |
|---|
| 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 */ |
|---|
| 509 | 504 | { |
|---|
| 510 | 505 | if ( ReadMetaData( p_this ) == VLC_ENOMEM ) |
|---|
| … | … | |
| 592 | 587 | PL_UNLOCK; |
|---|
| 593 | 588 | pl_Release( p_playlist ); |
|---|
| | 589 | |
|---|
| 594 | 590 | vlc_mutex_lock( &p_sys->lock ); |
|---|
| 595 | 591 | |
|---|
| … | … | |
| 598 | 594 | |
|---|
| 599 | 595 | vlc_mutex_unlock( &p_sys->lock ); |
|---|
| | 596 | |
|---|
| 600 | 597 | return VLC_SUCCESS; |
|---|
| 601 | 598 | } |
|---|
| … | … | |
| 811 | 808 | if ( p_buffer_pos ) |
|---|
| 812 | 809 | { |
|---|
| 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 " ) ); |
|---|
| 815 | 813 | } |
|---|
| 816 | 814 | |
|---|
| … | … | |
| 968 | 966 | { |
|---|
| 969 | 967 | playlist_t *p_playlist; |
|---|
| 970 | | input_thread_t *p_input = NULL; |
|---|
| | 968 | input_thread_t *p_input = NULL; |
|---|
| 971 | 969 | vlc_value_t video_val; |
|---|
| 972 | 970 | |
|---|
| 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 | | { |
|---|
| 1013 | 971 | char *psz_title = NULL; |
|---|
| 1014 | 972 | char *psz_artist = NULL; |
|---|
| … | … | |
| 1020 | 978 | int i_status; |
|---|
| 1021 | 979 | |
|---|
| 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 | } |
|---|
| 1023 | 1009 | |
|---|
| 1024 | 1010 | #define FREE_INPUT_AND_CHARS \ |
|---|
| … | … | |
| 1056 | 1042 | } |
|---|
| 1057 | 1043 | |
|---|
| | 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 |
|---|
| 1058 | 1048 | vlc_mutex_lock( &p_sys->lock ); |
|---|
| 1059 | 1049 | b_waiting = p_sys->b_waiting_meta; |
|---|
| 1060 | 1050 | 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 ) |
|---|
| 1065 | 1057 | { |
|---|
| 1066 | 1058 | ALLOC_ITEM_META( psz_artist, p_meta->psz_artist ) |
|---|
| … | … | |
| 1101 | 1093 | |
|---|
| 1102 | 1094 | 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 |
|---|
| 1108 | 1098 | return VLC_SUCCESS; |
|---|
| 1109 | 1099 | #undef FREE_INPUT_AND_CHARS |
|---|