Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int
- cmyth_livetv_chain_update(cmyth_recorder_t rec, char * chainid)
- {
- int ret, retry;
- char url[1024];
- cmyth_proginfo_t loc_prog;
- cmyth_file_t ft = NULL;
- ret = 0;
- if (!rec) {
- cmyth_dbg(CMYTH_DBG_ERROR, "%s: rec is NULL\n", __FUNCTION__);
- return -1;
- }
- /* JLB: Manage program break
- * Skip chain update, it will doing later
- */
- if (!rec->rec_livetv_chain) {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: rec_livetv_chain is NULL\n",
- __FUNCTION__, url);
- return -1;
- }
- else {
- if (rec->rec_livetv_chain->livetv_watch == 0) {
- cmyth_dbg(CMYTH_DBG_DEBUG,
- "%s: the next program is awaited: skip chain update\n",
- __FUNCTION__);
- return 0;
- }
- }
- cmyth_dbg(CMYTH_DBG_DEBUG, "%s: updating chain\n", __FUNCTION__);
- loc_prog = cmyth_recorder_get_cur_proginfo(rec);
- if (!loc_prog) {
- cmyth_dbg(CMYTH_DBG_ERROR, "%s: recorder is not recording\n", __FUNCTION__);
- return -1;
- }
- for (retry = 0; retry < 5; retry++) {
- if (strncmp(rec->rec_livetv_chain->chainid, chainid, strlen(chainid)) == 0) {
- sprintf(url, "myth://%s:%d%s", loc_prog->proginfo_hostname, rec->rec_port, loc_prog->proginfo_pathname);
- if (cmyth_livetv_chain_has_url(rec, url) != -1) {
- ref_release(loc_prog);
- //cmyth_dbg(CMYTH_DBG_WARN, "%s: maybe wrong url %s, wait some 250ms before try again\n", __FUNCTION__, url+45); // KM
- //usleep(250000);
- loc_prog = cmyth_recorder_get_cur_proginfo(rec);
- if (!loc_prog) {
- cmyth_dbg(CMYTH_DBG_ERROR, "%s: recorder is not recording\n", __FUNCTION__);
- return -1;
- }
- }
- else {
- cmyth_dbg(CMYTH_DBG_WARN, "%s: %d retrys needed before getting correct url %s\n", __FUNCTION__, retry, url+45); // KM
- break;
- }
- }
- else {
- break;
- }
- }
- if (strncmp(rec->rec_livetv_chain->chainid, chainid, strlen(chainid)) == 0) {
- sprintf(url, "myth://%s:%d%s", loc_prog->proginfo_hostname, rec->rec_port,
- loc_prog->proginfo_pathname);
- /*
- Now check if this file is in the recorder chain and if not
- then open a new file transfer and add it to the chain.
- */
- if (cmyth_livetv_chain_has_url(rec, url) == -1) {
- ft = cmyth_conn_connect_file(loc_prog, rec->rec_conn, 4096, rec->rec_livetv_chain->livetv_tcp_rcvbuf);
- if (!ft) {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_conn_connect_file(%s) failed\n",
- __FUNCTION__, url);
- ret = -1;
- goto out;
- }
- /*
- * file in the chain could be dummy and then
- * backend close file transfer socket immediately.
- * In other cases add the chain else wait next chain update to
- * add a valid program.
- */
- if (cmyth_file_is_open(ft) > 0) {
- if(cmyth_livetv_chain_add(rec, url, ft, loc_prog) == -1) {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_livetv_chain_add(%s) failed\n",
- __FUNCTION__, url);
- ret = -1;
- goto out;
- }
- if (rec->rec_livetv_chain->chain_switch_on_create) {
- cmyth_livetv_chain_switch(rec, LAST);
- rec->rec_livetv_chain->chain_switch_on_create = 0;
- }
- }
- else {
- cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_file_is_open() fails, %s not added\n", __FUNCTION__, url+45); // KM
- ret = -1;
- }
- }
- else {
- cmyth_dbg(CMYTH_DBG_DEBUG, "%s: %s is already in the chain\n", __FUNCTION__, url+45); // KM
- }
- }
- else {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: chainid doesn't match recorder's chainid!!\n",
- __FUNCTION__, url);
- ret = -1;
- }
- out:
- ref_release(ft);
- ref_release(loc_prog);
- return ret;
- }
Add Comment
Please, Sign In to add comment