コード例 #1
0
ファイル: media.c プロジェクト: dulton/hm-platform
gint r_ctrl(const char *inner_path, gint cmd, void *value)
{
    const Demuxer *dmx;
    gchar *mrl, *path;
	gint ls, ls_store, ret = -1;

	path = get_media_path(inner_path, &ls, &ls_store);
	mrl = g_strdup_printf("%s%s", RESOURCE_ROOT, path);
	g_free(path);

	if (ls)
	{
	    if ((dmx = r_find_demuxer(mrl)) == NULL)
	    {
	        rc_log(RC_LOG_DEBUG,
	                "[MT] Could not find a valid demuxer for '%s'\n",
	                mrl);
	        g_free(mrl);
	        return -1;
	    }

		if (dmx->ctrl_track)
			ret = (*dmx->ctrl_track)(mrl, cmd, value);
		g_free(mrl);
		return ret;
	}

	g_free(mrl);
	return -1;
}
コード例 #2
0
ファイル: media.c プロジェクト: dulton/hm-platform
/**
 * @brief Open a new resource and create a new instance
 *
 * @param srv The server object for the vhost requesting the resource
 * @param inner_path The path, relative to the avroot, for the
 *                   resource
 *
 * @return A new Resource object
 * @retval NULL Error while opening resource
 */
Resource *r_open(const char *inner_path, OpenMode mode)
{
    Resource *r;
    const Demuxer *dmx;
    gchar *mrl, *path;
	gint ls, ls_store;		/* ls: use demuxer_ls; ls_store: demuxer_ls with history streams */

	path = get_media_path(inner_path, &ls, &ls_store);
	mrl = g_strdup_printf("%s%s", RESOURCE_ROOT, path);
	g_free(path);

    if ((dmx = r_find_demuxer(mrl)) == NULL)
    {
        rc_log(RC_LOG_DEBUG,
                "[MT] Could not find a valid demuxer for resource %s\n",
                mrl);
        goto error;
    }

    rc_log(RC_LOG_DEBUG, "[MT] registrered demuxer \"%s\" for resource"
                               "\"%s\"\n", dmx->info->name, mrl);

    r = g_slice_new0(Resource);
    r->info = g_slice_new0(ResourceInfo);
    r->info->mrl = mrl;
    r->info->mtime = 0;
    r->info->name = g_path_get_basename(mrl);
    r->info->seekable = (dmx->seek != NULL);

    if (ls && !ls_store)
		r->info->seekable = FALSE;

    r->demuxer = dmx;
	r->mode = mode;

    if (r->demuxer->init(r))
    {
        r_free_cb(r, NULL);
        return NULL;
    }

    /* Now that we have opened the actual resource we can proceed with
     * the extras */

    r->lock = g_mutex_new();

#ifdef HAVE_METADATA
    cpd_find_request(srv, r, filename);
#endif

    return r;
 error:
    g_free(mrl);
    return NULL;
}
コード例 #3
0
ファイル: resource.c プロジェクト: iskey/iskey
/**
 * @brief Open a new resource and create a new instance
 *
 * @param inner_path The path, relative to the avroot, for the
 *                   resource
 *
 * @return A new Resource object
 * @retval NULL Error while opening resource
 */
Resource *r_open(const char *inner_path)
{
    Resource *r = NULL;
    const Demuxer *dmx;
    gchar *mrl = g_strjoin ("/",
                            feng_default_vhost->document_root,
                            inner_path,
                            NULL);

    /* Since right now we don't support any non-file-backed file, we
     * can check here if the file exists and if not simply return,
     * rather than passing through all the other code.
     */
    if ( access(mrl, R_OK) != 0 ) {
        xlog(LOG_ERR, "access");
        goto error;
    }

    if ( (dmx = r_find_demuxer(mrl)) == NULL ) {
        xlog(LOG_DBG,
                "[MT] Could not find a valid demuxer for resource %s\n",
                mrl);
        goto error;
    }

    /* From here on, we don't care any more of the doom of the mrl
     * variable, the called functions will save it for use later, or
     * will free it as needed.
     */

    xlog(LOG_DBG, "[MT] registrered demuxer \"%s\" for resource"
                               "\"%s\"\n", dmx->name, mrl);

    switch(dmx->source) {
#ifdef LIVE_STREAMING
        case LIVE_SOURCE:
            r = r_open_hashed(mrl, dmx);
            break;
#endif
        case STORED_SOURCE:
            r = r_open_direct(mrl, dmx);
            break;
        default:
            g_assert_not_reached();
            break;
    }

    return r;
 error:
    g_free(mrl);
    return NULL;
}
コード例 #4
0
ファイル: resource.c プロジェクト: iskey/feng_build
/**
 * @brief Open a new resource and create a new instance
 *
 * @param srv The server object for the vhost requesting the resource
 * @param inner_path The path, relative to the avroot, for the
 *                   resource
 *
 * @return A new Resource object
 * @retval NULL Error while opening resource
 */
Resource *r_open(struct feng *srv, const char *inner_path)
{
    Resource *r;
    const Demuxer *dmx;
    gchar *mrl = g_strjoin ("/",
                            srv->config_storage[0].document_root->ptr,
                            inner_path,
                            NULL);
	struct stat filestat;

	if (stat(mrl, &filestat) == -1 ) {
		switch(errno) {
        case ENOENT:
            fnc_log(FNC_LOG_ERR,"%s: file not found\n", mrl);
            break;
        default:
            fnc_log(FNC_LOG_ERR,"Cannot stat file %s\n", mrl);
            break;
		}
        goto error;
	}

	if ( S_ISFIFO(filestat.st_mode) ) {
		fnc_log(FNC_LOG_ERR, "%s: not a file\n");
        goto error;
    }

    if ( (dmx = r_find_demuxer(mrl)) == NULL ) {
        fnc_log(FNC_LOG_DEBUG,
                "[MT] Could not find a valid demuxer for resource %s\n",
                mrl);
        goto error;
    }

    fnc_log(FNC_LOG_DEBUG, "[MT] registrered demuxer \"%s\" for resource"
                               "\"%s\"\n", dmx->info->name, mrl);

    r = g_slice_new0(Resource);

    r->info = g_slice_new0(ResourceInfo);

    r->info->mrl = mrl;
    r->info->mtime = filestat.st_mtime;
    r->info->name = g_path_get_basename(inner_path);
    r->info->seekable = (dmx->seek != NULL);

    r->demuxer = dmx;
    r->srv = srv;

    if (r->demuxer->init(r)) {
        r_free_cb(r, NULL);
        return NULL;
    }

    /* Now that we have opened the actual resource we can proceed with
     * the extras */

    r->lock = g_mutex_new();

#ifdef HAVE_METADATA
    cpd_find_request(srv, r, filename);
#endif

    return r;
 error:
    g_free(mrl);
    return NULL;
}