Exemple #1
0
/*
 * cmyth_livetv_chain_request_block(cmyth_recorder_t file, unsigned long len)
 * 
 * Scope: PUBLIC
 *
 * Description
 *
 * Request a file data block of a certain size, and return when the
 * block has been transfered.
 *
 * Return Value:
 *
 * Sucess: number of bytes transfered
 *
 * Failure: an int containing -errno
 */
static int
cmyth_livetv_chain_request_block(cmyth_recorder_t rec, unsigned long len)
{
	int ret, retry;

	cmyth_dbg(CMYTH_DBG_DEBUG, "%s [%s:%d]: (trace) {\n", __FUNCTION__,
				__FILE__, __LINE__);

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

	pthread_mutex_lock(&mutex);

	do {
		retry = 0;
		ret = cmyth_file_request_block(rec->rec_livetv_file, len);
		if (ret == 0) { /* We've gotten to the end, need to progress in the chain */
			/* Switch if there are files left in the chain */
			PRINTF("**SSDEBUG:(cmyth_livetv_request_block): %s\n",
			"reached end of stream must dooSwitcheroo");
			retry = cmyth_livetv_chain_switch(rec, 1);
		}
	}
	while (retry);

	pthread_mutex_unlock(&mutex);

	cmyth_dbg(CMYTH_DBG_DEBUG, "%s [%s:%d]: (trace) }\n",
				__FUNCTION__, __FILE__, __LINE__);

	return ret;
}
Exemple #2
0
static int
fill_buffer(int i, char *buf, size_t size)
{
	int tot, len, n = 0;

	tot = 0;
	len = cmyth_file_request_block(files[i].file, size);
	while (tot < len) {
		n = cmyth_file_get_block(files[i].file, buf+tot, len-tot);
		if (n > 0) {
			tot += n;
		}
		if (n <= 0) {
			return -1;
		}
	}

	debug("%s(): tot %d len %d n %d size %lld\n", __FUNCTION__,
	      tot, len, n, (long long)size);

	if (len < 0) {
		return -1;
	}

	return tot;
}
Exemple #3
0
/*
 * cmyth_livetv_wait()
 *
 * After starting live TV or after a channel change wait here until some
 * recording data is available.
 */
static int
cmyth_livetv_wait(cmyth_recorder_t rec)
{
    int i = 0, rc = -1;
    cmyth_conn_t conn;
    static int failures = 0;

    usleep(250000*failures);

    conn = cmyth_conn_reconnect(rec->rec_conn);

    while (i++ < 10) {
        int len;
        cmyth_proginfo_t prog;
        cmyth_file_t file;

        if (!cmyth_recorder_is_recording(rec)) {
            usleep(1000);
            continue;
        }

        prog = cmyth_recorder_get_cur_proginfo(rec);

        if (prog == NULL) {
            usleep(1000);
            continue;
        }

        file = cmyth_conn_connect_file(prog, conn, 4096, 4096);

        ref_release(prog);

        if (file == NULL) {
            if (failures < 4) {
                failures++;
            }
            usleep(1000);
            continue;
        }

        len = cmyth_file_request_block(file, 512);

        ref_release(file);

        if (len == 512) {
            rc = 0;
            break;
        }

        if (failures < 4) {
            failures++;
        }
        usleep(1000);
    }

    ref_release(conn);

    return rc;
}
Exemple #4
0
/*
 * cmyth_livetv_chain_request_block(cmyth_recorder_t file, unsigned long len)
 *
 * Scope: PUBLIC
 *
 * Description
 *
 * Request a file data block of a certain size, and return when the
 * block has been transfered.
 *
 * Return Value:
 *
 * Sucess: number of bytes transfered
 *
 * Failure: an int containing -errno
 */
static int
cmyth_livetv_chain_request_block(cmyth_recorder_t rec, unsigned long len)
{
    int rc;
    cmyth_file_t file;

    cmyth_dbg(CMYTH_DBG_DEBUG, "%s [%s:%d]: (trace) {\n", __FUNCTION__,
              __FILE__, __LINE__);

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

    if (!rec->rec_connected) {
        return -1;
    }

    pthread_mutex_lock(&rec->rec_conn->conn_mutex);

retry:
    if ((file=cmyth_livetv_current_file(rec)) == NULL) {
        rc = -1;
        goto out;
    }

    rc = cmyth_file_request_block(file, len);

    if (rc == 0) {
        cmyth_dbg(CMYTH_DBG_DEBUG,
                  "%s(): no data, move forward in chain and retry\n",
                  __FUNCTION__);
        if (cmyth_chain_switch(rec->rec_chain, 1) == 0) {
            ref_release(file);
            goto retry;
        }
    }

    ref_release(file);

out:
    pthread_mutex_unlock(&rec->rec_conn->conn_mutex);

    cmyth_dbg(CMYTH_DBG_DEBUG, "%s [%s:%d]: (trace) }\n",
              __FUNCTION__, __FILE__, __LINE__);

    return rc;
}