[Mvpmc-cvs] mvpmc/src mythtv.c,1.69,1.70
Status: Alpha
Brought to you by:
gettler
From: Jon G. <ge...@us...> - 2005-11-10 05:02:45
|
Update of /cvsroot/mvpmc/mvpmc/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31772/src Modified Files: mythtv.c Log Message: Add support for myth events telling us when the recording list or upcoming schedule have changed, so that the program data can be cached, instead of being reloaded from myth every time a new menu is displayed. Index: mythtv.c =================================================================== RCS file: /cvsroot/mvpmc/mvpmc/src/mythtv.c,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** mythtv.c 1 Nov 2005 05:31:58 -0000 1.69 --- mythtv.c 10 Nov 2005 05:02:37 -0000 1.70 *************** *** 66,71 **** --- 66,73 ---- static pthread_mutex_t seek_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t myth_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_cond_t event_cond = PTHREAD_COND_INITIALIZER; static volatile cmyth_conn_t control; /* master backend */ + static volatile cmyth_conn_t event; /* master backend */ static volatile cmyth_conn_t control_slave; /* slave backend */ static volatile cmyth_proginfo_t current_prog; /* program currently being played */ *************** *** 78,81 **** --- 80,86 ---- static volatile cmyth_recorder_t recorder; + static volatile int pending_dirty = 0; + static volatile int episode_dirty = 0; + static volatile int current_livetv; *************** *** 95,99 **** static volatile int video_reading = 0; ! static pthread_t control_thread, wd_thread; #define MAX_TUNER 16 --- 100,104 ---- static volatile int video_reading = 0; ! static pthread_t control_thread, wd_thread, event_thread; #define MAX_TUNER 16 *************** *** 302,305 **** --- 307,315 ---- cmyth_conn_release(c); } + if (event) { + cmyth_conn_t c = event; + event = NULL; + cmyth_conn_release(c); + } } *************** *** 562,577 **** int err; ! if (episode_plist) ! cmyth_proglist_release(episode_plist); ! if ((episode_plist=cmyth_proglist_create()) == NULL) { ! fprintf(stderr, "cannot get program list\n"); ! goto err; ! } ! if ((err=cmyth_proglist_get_all_recorded(control, episode_plist)) < 0) { ! fprintf(stderr, "get recorded failed, err %d\n", err); ! mythtv_shutdown(); ! goto err; } --- 572,593 ---- int err; ! if ((episode_plist == NULL) || episode_dirty) { ! if (episode_plist) ! cmyth_proglist_release(episode_plist); ! if ((episode_plist=cmyth_proglist_create()) == NULL) { ! fprintf(stderr, "cannot get program list\n"); ! goto err; ! } ! if ((err=cmyth_proglist_get_all_recorded(control, episode_plist)) < 0) { ! fprintf(stderr, "get recorded failed, err %d\n", err); ! mythtv_shutdown(); ! goto err; ! } ! ! episode_dirty = 0; ! } else { ! printf("Using cached episode data\n"); } *************** *** 733,738 **** mvpw_add_menu_item(widget, titles[i], (void*)n+2, &item_attr); - cmyth_proglist_release(episode_plist); - episode_plist = NULL; pthread_mutex_unlock(&myth_mutex); } --- 749,752 ---- *************** *** 841,848 **** if ((mythtv_state == MYTHTV_STATE_PROGRAMS) || (mythtv_state == MYTHTV_STATE_PENDING)) { - if (pending_plist) { - cmyth_proglist_release(pending_plist); - pending_plist = NULL; - } return 0; } --- 855,858 ---- *************** *** 967,984 **** mvpw_clear_menu(widget); ! if (pending_plist) ! cmyth_proglist_release(pending_plist); ! if ((pending_plist=cmyth_proglist_create()) == NULL) { ! fprintf(stderr, "cannot get program list\n"); ! ret = -1; ! goto out; ! } ! if ((err=cmyth_proglist_get_all_pending(control, pending_plist)) < 0) { ! fprintf(stderr, "get pending failed, err %d\n", err); ! mythtv_shutdown(); ! ret = -1; ! goto out; } --- 977,1000 ---- mvpw_clear_menu(widget); ! if ((pending_plist == NULL) || pending_dirty) { ! if (pending_plist) ! cmyth_proglist_release(pending_plist); ! if ((pending_plist=cmyth_proglist_create()) == NULL) { ! fprintf(stderr, "cannot get program list\n"); ! ret = -1; ! goto out; ! } ! if ((err=cmyth_proglist_get_all_pending(control, pending_plist)) < 0) { ! fprintf(stderr, "get pending failed, err %d\n", err); ! mythtv_shutdown(); ! ret = -1; ! goto out; ! } ! ! pending_dirty = 0; ! } else { ! printf("Using cached pending data\n"); } *************** *** 1180,1183 **** --- 1196,1233 ---- static void* + event_start(void *arg) + { + cmyth_event_t next; + pthread_mutex_t event_mutex = PTHREAD_MUTEX_INITIALIZER; + + printf("event thread started (pid %d)\n", getpid()); + + pthread_mutex_lock(&event_mutex); + + while (1) { + while (event == NULL) { + pthread_cond_wait(&event_cond, &event_mutex); + } + next = cmyth_event_get(event); + switch (next) { + case CMYTH_EVENT_NONE: + printf("Got empty event (error?)\n"); + sleep(5); + break; + case CMYTH_EVENT_RECORDING_LIST_CHANGE: + printf("Got event RECORDING_LIST_CHANGE\n"); + episode_dirty = 1; + break; + case CMYTH_EVENT_SCHEDULE_CHANGE: + printf("Got event SCHEDULE_CHANGE\n"); + pending_dirty = 1; + break; + } + } + + return NULL; + } + + static void* control_start(void *arg) { *************** *** 1379,1382 **** --- 1429,1440 ---- } + if ((event=cmyth_conn_connect_event(server, port, 16*1024, + mythtv_tcp_control)) == NULL) { + fprintf(stderr, "cannot connect to mythtv server %s\n", + server); + return -1; + } + pthread_cond_signal(&event_cond); + if (!thread) { thread = 1; *************** *** 1384,1387 **** --- 1442,1447 ---- control_start, NULL); pthread_create(&wd_thread, &thread_attr_small, wd_start, NULL); + pthread_create(&event_thread, &thread_attr_small, + event_start, NULL); } *************** *** 1454,1457 **** --- 1514,1518 ---- pthread_mutex_lock(&myth_mutex); ret = cmyth_proginfo_delete_recording(control, hilite_prog); + episode_dirty = 1; if (cmyth_proginfo_compare(hilite_prog, current_prog) == 0) { mythtv_close_file(); *************** *** 1472,1475 **** --- 1533,1537 ---- pthread_mutex_lock(&myth_mutex); ret = cmyth_proginfo_forget_recording(control, hilite_prog); + episode_dirty = 1; if (cmyth_proginfo_compare(hilite_prog, current_prog) == 0) { mythtv_close_file(); |