Exemple #1
0
/*
 * cmyth_livetv_chain_add_url(cmyth_recorder_t rec, char * url)
 * 
 * Scope: PRIVATE
 *
 * Description
 *
 * Called to add a url to a livetv chain structure. The url is added
 * only if it is not already there.
 *
 * Return Value:
 *
 * Success: 0
 *
 * Faiure: -1
 */
static int
cmyth_livetv_chain_add_url(cmyth_recorder_t rec, char * url)
{
	char ** tmp;
	cmyth_file_t * fp;
	cmyth_proginfo_t * pi;
	int ret = 0;

	if(cmyth_livetv_chain_has_url(rec,url) == -1) {
		if(rec->rec_livetv_chain->chain_current == -1) {
			rec->rec_livetv_chain->chain_ct = 1;
			rec->rec_livetv_chain->chain_current = 0;
			/* Nothing in the chain yet, allocate the space */
			tmp = (char**)ref_alloc(sizeof(char *));
			fp = (cmyth_file_t *)ref_alloc(sizeof(cmyth_file_t));
			pi = (cmyth_proginfo_t *)ref_alloc(sizeof(cmyth_proginfo_t));
		}
		else {
			rec->rec_livetv_chain->chain_ct++;
			tmp = (char**)ref_realloc(rec->rec_livetv_chain->chain_urls,
								sizeof(char *)*rec->rec_livetv_chain->chain_ct);
			fp = (cmyth_file_t *)
					ref_realloc(rec->rec_livetv_chain->chain_files,
								sizeof(cmyth_file_t)*rec->rec_livetv_chain->chain_ct);
			pi = (cmyth_proginfo_t *)
					ref_realloc(rec->rec_livetv_chain->progs,
								sizeof(cmyth_proginfo_t)*rec->rec_livetv_chain->chain_ct);
		}
		if(tmp != NULL && fp != NULL) {
			rec->rec_livetv_chain->chain_urls = ref_hold(tmp);
			rec->rec_livetv_chain->chain_files = ref_hold(fp);
			rec->rec_livetv_chain->progs = ref_hold(pi);
			ref_release(tmp);
			ref_release(fp);
			ref_release(pi);
			rec->rec_livetv_chain->chain_urls[rec->rec_livetv_chain->chain_ct-1]
							= ref_strdup(url);
			rec->rec_livetv_chain->chain_files[rec->rec_livetv_chain->chain_ct-1]
							= ref_hold(NULL);
			rec->rec_livetv_chain->progs[rec->rec_livetv_chain->chain_ct-1]
							= ref_hold(NULL);
		}
		else {
			ret = -1;
			cmyth_dbg(CMYTH_DBG_ERROR,
			 		"%s: memory allocation request failed\n",
			 		__FUNCTION__);
		}

	}
	return ret;
}
Exemple #2
0
static int
query_buffer_check_len(cmyth_mysql_query_t *query, int len)
{
    if(len + query->buf_used >= query->buf_size)
    {
	/* Increase buffer size by len or out->source_len, whichever
	 * is bigger
	 */
	if(query->source_len > len) 
	    query->buf_size += query->source_len;
	else
	    query->buf_size += len;
	query->buf = ref_realloc(query->buf,query->buf_size);
	if(query->buf == NULL)
	{
	    cmyth_mysql_query_reset(query);
	    return -1;
	}
    }
    return 0;
}
Exemple #3
0
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);
	}
}