Ejemplo n.º 1
0
/*
 * cmyth_livetv_chain_seek(cmyth_recorder_t file, long long offset, int whence)
 *
 * Scope: PUBLIC
 *
 * Description
 *
 * Seek to a new position in the file based on the value of whence:
 *	SEEK_SET
 *		The offset is set to offset bytes.
 *	SEEK_CUR
 *		The offset is set to the current position plus offset bytes.
 *	SEEK_END
 *		The offset is set to the size of the file minus offset bytes.
 *
 * Return Value:
 *
 * Sucess: 0
 *
 * Failure: an int containing -errno
 */
static long long
cmyth_livetv_chain_seek(cmyth_recorder_t rec, long long offset, int whence)
{
    long long ret;
    cmyth_file_t file;

    if (rec == NULL)
        return -EINVAL;

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

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

    if ((file=cmyth_livetv_current_file(rec)) == NULL) {
        ret = -1;
        goto out;
    }

    /*
     * XXX: This needs to seek across the entire chain...
     */

    ret = cmyth_file_seek(file, offset, whence);

    ref_release(file);

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

    return ret;
}
Ejemplo n.º 2
0
Archivo: mythfuse.c Proyecto: tsp/cmyth
static int
do_seek(int i, off_t offset, int whence)
{
	off_t pos;

	pos = cmyth_file_seek(files[i].file, offset, whence);

	return pos;
}
Ejemplo n.º 3
0
long long MythFile::Seek(long long offset, int whence)
{
  long long retval = 0;
  retval = cmyth_file_seek(*m_file_t, offset, whence);
  return retval;
}
Ejemplo n.º 4
0
/*
 * cmyth_livetv_chain_seek(cmyth_recorder_t file, long long offset, int whence)
 * 
 * Scope: PUBLIC
 *
 * Description
 *
 * Seek to a new position in the file based on the value of whence:
 *	SEEK_SET
 *		The offset is set to offset bytes.
 *	SEEK_CUR
 *		The offset is set to the current position plus offset bytes.
 *	SEEK_END
 *		The offset is set to the size of the file minus offset bytes.
 *
 * Return Value:
 *
 * Sucess: 0
 *
 * Failure: an int containing -errno
 */
static long long
cmyth_livetv_chain_seek(cmyth_recorder_t rec, long long offset, int whence)
{
	long long ret;
	cmyth_file_t fp;
	int cur, ct;

	if (rec == NULL)
		return -EINVAL;

	ct  = rec->rec_livetv_chain->chain_ct;

	if (whence == SEEK_END) {

		offset -= rec->rec_livetv_file->file_req;
		for (cur = rec->rec_livetv_chain->chain_current; cur < ct; cur++) {
			offset += rec->rec_livetv_chain->chain_files[cur]->file_length;
		}

		cur = rec->rec_livetv_chain->chain_current;
		fp  = rec->rec_livetv_chain->chain_files[cur];
		whence = SEEK_CUR;
	}

	if (whence == SEEK_SET) {

		for (cur = 0; cur < ct; cur++) {
    			fp = rec->rec_livetv_chain->chain_files[cur];
			if (offset < (long long)fp->file_length)
				break;
			offset -= fp->file_length;
		}
	}

	if (whence == SEEK_CUR) {

	if (offset == 0) {
		cur     = rec->rec_livetv_chain->chain_current;
		offset += rec->rec_livetv_chain->chain_files[cur]->file_req;
		for (; cur > 0; cur--) {
			offset += rec->rec_livetv_chain->chain_files[cur-1]->file_length;
		}
		return offset;
	}

	offset += fp->file_req;

	while (offset > (long long)fp->file_length) {
		cur++;
		offset -= fp->file_length;
		if(cur == ct)
			return -1;
		fp = rec->rec_livetv_chain->chain_files[cur];
	}

	while (offset < 0) {
		cur--;
		if(cur < 0)
			return -1;
		fp = rec->rec_livetv_chain->chain_files[cur];
		offset += fp->file_length;
	}

	offset -= fp->file_req;
  }

	pthread_mutex_lock(&mutex);

	ret = cmyth_file_seek(fp, offset, whence);

	PRINTF("** SSDEBUG: new pos %lld after seek command\n", ret);

	cur -= rec->rec_livetv_chain->chain_current;
	if (ret >= 0 && cur) {
		cmyth_livetv_chain_switch(rec, cur);
	}

	pthread_mutex_unlock(&mutex);

	return ret;
}
Ejemplo n.º 5
0
/*
 * cmyth_recorder_set_channel(cmyth_recorder_t rec,
 *                            char *channame)
 * 
 * Scope: PUBLIC
 *
 * Description
 *
 * Request that the recorder 'rec' change channels to the channel
 * named 'channame'.
 *
 * Note that the recorder must not be actively recording when this
 * request is made or bad things may happen to the server (i.e. it may
 * segfault).
 *
 * Return Value:
 *
 * Success: 0
 *
 * Failure: -(ERRNO)
 */
int
cmyth_recorder_set_channel(cmyth_recorder_t rec, char *channame)
{
	int err;
	int ret = -1;
	char msg[256];
	cmyth_file_t file;

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

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

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

	cmyth_chain_lock(rec->rec_chain);

	snprintf(msg, sizeof(msg),
		 "QUERY_RECORDER %d[]:[]SET_CHANNEL[]:[]%s",
		 rec->rec_id, channame);

	if ((err=cmyth_send_message(rec->rec_conn, msg)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_send_message() failed (%d)\n",
			  __FUNCTION__, err);
		goto fail;
	}

	if ((err=cmyth_rcv_okay(rec->rec_conn)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_okay() failed (%d)\n",
			  __FUNCTION__, err);
		goto fail;
	}

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

	cmyth_chain_add_wait(rec->rec_chain);

	cmyth_chain_unlock(rec->rec_chain);

	if ((file=cmyth_livetv_current_file(rec)) == NULL) {
		goto fail_nolock;
	}

	cmyth_file_seek(file, 0, SEEK_SET);

	ref_release(file);

	ret = 0;

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

fail_nolock:
	return ret;
}