int cmyth_chain_set_current(cmyth_chain_t chain, cmyth_proginfo_t prog) { unsigned int i; int rc = -1; void (*callback)(cmyth_proginfo_t prog) = NULL; cmyth_proginfo_t cb_prog = NULL; if ((chain == NULL) || (prog == NULL)) { return -1; } pthread_mutex_lock(&chain->chain_mutex); for (i=0; i<chain->chain_count; i++) { if (cmyth_proginfo_compare(prog, chain->chain_list[i]->prog) == 0) { chain->chain_current = i; callback = chain->chain_callback; if (callback) { cb_prog = ref_hold(chain->chain_list[i]->prog); } break; } } pthread_mutex_unlock(&chain->chain_mutex); if (callback && cb_prog) { callback(cb_prog); ref_release(cb_prog); } return rc; }
int cmyth_proglist_delete_item(cmyth_proglist_t pl, cmyth_proginfo_t prog) { int i; cmyth_proginfo_t old; int ret = -EINVAL; if (!pl) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program list\n", __FUNCTION__); return -EINVAL; } if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program item\n", __FUNCTION__); return -EINVAL; } pthread_mutex_lock(&pl->proglist_mutex); for (i=0; i<pl->proglist_count; i++) { if (cmyth_proginfo_compare(prog, pl->proglist_list[i]) == 0) { old = pl->proglist_list[i]; memmove(pl->proglist_list+i, pl->proglist_list+i+1, (pl->proglist_count-i-1)*sizeof(cmyth_proginfo_t)); pl->proglist_count--; ref_release(old); ret = 0; goto out; } } out: pthread_mutex_unlock(&pl->proglist_mutex); return ret; }
cmyth_file_t cmyth_chain_get_file(cmyth_chain_t chain, cmyth_proginfo_t prog) { cmyth_file_t file = NULL; unsigned int i; if ((chain == NULL) || (prog == NULL)) { return NULL; } pthread_mutex_lock(&chain->chain_mutex); for (i=0; i<chain->chain_count; i++) { if (cmyth_proginfo_compare(prog, chain->chain_list[i]->prog) == 0) { file = ref_hold(chain->chain_list[i]->file); break; } } pthread_mutex_unlock(&chain->chain_mutex); return file; }
static void cmyth_chain_update(cmyth_chain_t chain, cmyth_recorder_t rec, char *msg) { char *p; cmyth_proginfo_t prog = NULL; cmyth_chain_entry_t entry; int size, tip; long long offset; int start = 0; char *path; if ((p=strchr(msg, ' ')) != NULL) { *(p++) = '\0'; if (strcmp(msg, "LIVETV_CHAIN UPDATE") != 0) { return; } } else { p = msg; } prog = cmyth_recorder_get_cur_proginfo(rec); if (prog == NULL) { return; } path = cmyth_proginfo_pathname(prog); if (path == NULL) { return; } if (strlen(path) == 0) { ref_release(path); ref_release(prog); return; } ref_release(path); pthread_mutex_lock(&chain->chain_mutex); if (!chain->chain_id || (strncmp(p, chain->chain_id, strlen(p)) != 0)) { goto out; } tip = chain->chain_count - 1; if (tip >= 0) { path = cmyth_proginfo_pathname(chain->chain_list[tip]->prog); ref_release(path); if (cmyth_proginfo_compare(prog, chain->chain_list[tip]->prog) == 0) { ref_release(prog); goto out; } offset = chain->chain_list[tip]->offset + cmyth_proginfo_length(chain->chain_list[tip]->prog); } else { offset = 0; start = 1; } size = sizeof(*chain->chain_list) * (++chain->chain_count); chain->chain_list = ref_realloc(chain->chain_list, size); entry = ref_alloc(sizeof(*entry)); entry->prog = prog; entry->file = NULL; entry->offset = offset; chain->chain_list[tip+1] = entry; pthread_cond_broadcast(&chain->chain_cond); out: pthread_mutex_unlock(&chain->chain_mutex); if (start) { chain->chain_current = 0; cmyth_chain_switch(chain, 0); } }