Exemple #1
0
/*
 * cmyth_livetv_chain_setup(cmyth_recorder_t old_rec)
 * 
 * Scope: PUBLIC
 *
 * Description
 *
 * Set up the file information the recorder needs to watch live
 * tv.  The recorder is supplied.  This will be duplicated and
 * released, so the caller can re-use the same variable to hold the
 * return.  The new copy of the recorder will have a livetv chain
 * within it.
 *
 * Return Value:
 *
 * Success: A pointer to a new recorder structure with a livetvchain
 *
 * Failure: NULL but the recorder passed in is not released the
 *					caller needs to do this on a failure.
 */
cmyth_recorder_t
cmyth_livetv_chain_setup(cmyth_recorder_t rec, int tcp_rcvbuf,
			 void (*prog_update_callback)(cmyth_proginfo_t))
{

	cmyth_recorder_t new_rec = NULL;
	char url[1024];
	cmyth_conn_t control;
	cmyth_proginfo_t loc_prog, loc_prog2;
	cmyth_file_t ft;
	int i=0;


	if (!rec) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s: no recorder connection\n",
			  __FUNCTION__);
		return NULL;
	}

	control = rec->rec_conn;
	/* Get the current recording information */
	loc_prog = cmyth_recorder_get_cur_proginfo(rec);

	/* Since backend will pretty much lockup when trying to open an *
	 * empty file, like the dummy file first generated by dvd       */
	loc_prog2 = (cmyth_proginfo_t)ref_hold(loc_prog);
	while(i++<5 && (loc_prog2 == NULL || (loc_prog2 && loc_prog2->proginfo_Length == 0))) {
		usleep(200000);
		if(loc_prog2)
			ref_release(loc_prog2);
		loc_prog2 = cmyth_recorder_get_cur_proginfo(rec);
		loc_prog2 = cmyth_proginfo_get_detail(control, loc_prog2);
	}

	if (loc_prog == NULL) {
		cmyth_dbg(CMYTH_DBG_DEBUG, "%s: could not get current filename\n",
			  __FUNCTION__);
		goto out;
	}

	pthread_mutex_lock(&mutex);

	sprintf(url, "myth://%s:%d%s",loc_prog->proginfo_hostname, rec->rec_port,
					loc_prog->proginfo_pathname);

	new_rec = cmyth_recorder_dup(rec);
	if (new_rec == NULL) {
		cmyth_dbg(CMYTH_DBG_DEBUG, "%s: cannot create recorder\n",
			  __FUNCTION__);
		goto out;
	}
	ref_release(rec);

	if(new_rec->rec_livetv_chain == NULL) {
		cmyth_dbg(CMYTH_DBG_DEBUG, "%s: error no livetv_chain\n",
			  __FUNCTION__);
		new_rec = NULL;
		goto out;
	}

	if(cmyth_livetv_chain_has_url(new_rec, url) == -1) {
		ft = cmyth_conn_connect_file(loc_prog, new_rec->rec_conn, 16*1024, tcp_rcvbuf);
		if (!ft) {
			cmyth_dbg(CMYTH_DBG_ERROR,
	  			"%s: cmyth_conn_connect_file(%s) failed\n",
	  			__FUNCTION__, url);
			new_rec = NULL;
			goto out;
		}
		if(cmyth_livetv_chain_add(new_rec, url, ft, loc_prog) == -1) {
			cmyth_dbg(CMYTH_DBG_ERROR,
		 			"%s: cmyth_livetv_chain_add(%s) failed\n",
		 			__FUNCTION__, url);
			new_rec = NULL;
			goto out;
		}
		new_rec->rec_livetv_chain->prog_update_callback = prog_update_callback;
		ref_release(ft);
		cmyth_livetv_chain_switch(new_rec, 0);
	}


	ref_release(loc_prog);
    out:
	pthread_mutex_unlock(&mutex);

	return new_rec;
}
Exemple #2
0
/*
 * cmyth_livetv_chain_setup(cmyth_recorder_t old_rec)
 *
 * Scope: PUBLIC
 *
 * Description
 *
 * Set up the file information the recorder needs to watch live
 * tv.  The recorder is supplied.  This will be duplicated and
 * released, so the caller can re-use the same variable to hold the
 * return.  The new copy of the recorder will have a livetv chain
 * within it.
 *
 * Return Value:
 *
 * Success: A pointer to a new recorder structure with a livetvchain
 *
 * Failure: NULL but the recorder passed in is not released the
 *					caller needs to do this on a failure.
 */
cmyth_recorder_t
cmyth_livetv_chain_setup(cmyth_recorder_t rec, int tcp_rcvbuf,
                         void (*prog_update_callback)(cmyth_proginfo_t))
{

    cmyth_recorder_t new_rec = NULL;
    char url[1024];
    cmyth_conn_t control;
    cmyth_proginfo_t loc_prog;
    cmyth_file_t ft;

    if (!rec) {
        cmyth_dbg(CMYTH_DBG_ERROR, "%s: no recorder connection\n",
                  __FUNCTION__);
        return NULL;
    }

    control = rec->rec_conn;
    /* Get the current recording information */
    loc_prog = cmyth_recorder_get_cur_proginfo(rec);

    if (loc_prog == NULL) {
        cmyth_dbg(CMYTH_DBG_DEBUG, "%s: could not get current filename\n",
                  __FUNCTION__);
        goto out;
    }

    pthread_mutex_lock(&mutex);

    new_rec = cmyth_recorder_dup(rec);
    if (new_rec == NULL) {
        cmyth_dbg(CMYTH_DBG_DEBUG, "%s: cannot create recorder\n",
                  __FUNCTION__);
        goto out;
    }
    ref_release(rec);

    if(new_rec->rec_livetv_chain == NULL) {
        cmyth_dbg(CMYTH_DBG_DEBUG, "%s: error no livetv_chain\n",
                  __FUNCTION__);
        new_rec = NULL;
        goto out;
    }

    sprintf(url, "myth://%s:%d%s", loc_prog->proginfo_hostname, rec->rec_port,
            loc_prog->proginfo_pathname);

    if(cmyth_livetv_chain_has_url(new_rec, url) == -1) {
        new_rec->rec_livetv_chain->livetv_tcp_rcvbuf = tcp_rcvbuf;
        ft = cmyth_conn_connect_file(loc_prog, new_rec->rec_conn, 4096, new_rec->rec_livetv_chain->livetv_tcp_rcvbuf);
        if (!ft) {
            cmyth_dbg(CMYTH_DBG_ERROR,
                      "%s: cmyth_conn_connect_file(%s) failed\n",
                      __FUNCTION__, url);
            new_rec = NULL;
            goto out;
        }
    }
    if(cmyth_livetv_chain_add(new_rec, url, ft, loc_prog) == -1) {
        cmyth_dbg(CMYTH_DBG_ERROR,
                  "%s: cmyth_livetv_chain_add(%s) failed\n",
                  __FUNCTION__, url);
        new_rec = NULL;
        ref_release(ft);
        goto out;
    }

    new_rec->rec_livetv_chain->prog_update_callback = prog_update_callback;
    ref_release(ft);

    /* JLB: Manage program breaks
     * Switch ON watch signal
     */
    new_rec->rec_livetv_chain->livetv_watch = 1;

    cmyth_livetv_chain_switch(new_rec, 0);


out:
    pthread_mutex_unlock(&mutex);
    ref_release(loc_prog);

    return new_rec;
}
Exemple #3
0
/*
 * cmyth_livetv_chain_update(cmyth_recorder_t rec, char * chainid, int buff)
 * 
 * Scope: PUBLIC
 *
 * Description
 *
 * Called in response to the backend's notification of a chain update.
 * The recorder is supplied and will be queried for the current recording
 * to determine if a new file needs to be added to the chain of files
 * in the live tv instance.
 *
 * Return Value:
 *
 * Success: 0
 *
 * Failure: -1
 */
int
cmyth_livetv_chain_update(cmyth_recorder_t rec, char * chainid,
													int tcp_rcvbuf)
{
	int ret=0;
	char url[1024];
	cmyth_conn_t control;
	cmyth_proginfo_t loc_prog;
	cmyth_file_t ft;

  if (!rec) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s: rec is NULL\n", __FUNCTION__);
		goto out;
	}

	control = rec->rec_conn;

	loc_prog = cmyth_recorder_get_cur_proginfo(rec);
	pthread_mutex_lock(&mutex);

	if(rec->rec_livetv_chain) {
		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, 16*1024, tcp_rcvbuf);
				if (!ft) {
					cmyth_dbg(CMYTH_DBG_ERROR,
			  			"%s: cmyth_conn_connect_file(%s) failed\n",
			  			__FUNCTION__, url);
					ret = -1;
					goto out;
				}
				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;
				}
				ref_release(ft);
				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: chainid doesn't match recorder's chainid!!\n",
			 		__FUNCTION__, url);
			ret = -1;
		}
	}
	else {
		cmyth_dbg(CMYTH_DBG_ERROR,
		 		"%s: rec_livetv_chain is NULL!!\n",
		 		__FUNCTION__, url);
		ret = -1;
	}

	ref_release(loc_prog);
	out:
	pthread_mutex_unlock(&mutex);

	return ret;
}
Exemple #4
0
/*
 * cmyth_livetv_chain_update(cmyth_recorder_t rec, char * chainid, int buff)
 *
 * Scope: PUBLIC
 *
 * Description
 *
 * Called in response to the backend's notification of a chain update.
 * The recorder is supplied and will be queried for the current recording
 * to determine if a new file needs to be added to the chain of files
 * in the live tv instance.
 *
 * Return Value:
 *
 * Success: 0
 *
 * Failure: -1
 */
int
cmyth_livetv_chain_update(cmyth_recorder_t rec, char * chainid)
{
    int ret;
    char url[1024];
    cmyth_proginfo_t loc_prog;
    cmyth_file_t ft;

    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 != 1) {
            cmyth_dbg(CMYTH_DBG_DEBUG,
                      "%s: skip chain update\n",
                      __FUNCTION__);
            return 0;
        }
    }

    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;
    }

    pthread_mutex_lock(&mutex);

    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;
            }
            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;
                ref_release(ft);
                goto out;
            }
            ref_release(ft);
            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: chainid doesn't match recorder's chainid!!\n",
                  __FUNCTION__, url);
        ret = -1;
    }

out:
    pthread_mutex_unlock(&mutex);
    ref_release(loc_prog);

    return ret;
}