static int dash_server_onvod(void* /*dash*/, http_session_t* session, const char* /*method*/, const char* path)
{
    char fullpath[PATH_MAX];
    int r = path_concat(path + 5 /* /vod/ */, LOCALPATH, fullpath);
	printf("vod: %s\n", fullpath);

	if (0 == r && path_testfile(fullpath))
	{
		// MIME
		if (strendswith(fullpath, ".mpd"))
			http_server_set_content_type(session, "application/xml+dash");
		else if (strendswith(fullpath, ".mp4") || strendswith(fullpath, ".m4v"))
            http_server_set_header(session, "content-type", "video/mp4");
        else if (strendswith(fullpath, ".m4a"))
            http_server_set_header(session, "content-type", "audio/mp4");

		//http_server_set_header(session, "Transfer-Encoding", "chunked");

		// cross domain
		http_server_set_header(session, "Access-Control-Allow-Origin", "*");
		http_server_set_header(session, "Access-Control-Allow-Methods", "GET, POST, PUT");

		return http_server_sendfile(session, fullpath, NULL, NULL);
	}

	return http_server_send(session, 404, "", 0, NULL, NULL);
}
Exemple #2
0
static int hls_server_onhttp(void* http, void* session, const char* method, const char* path)
{
	// decode request uri
	void* url = url_parse(path);
	std::string s = url_getpath(url);
	url_free(url);
	path = s.c_str();

	if (0 == strncmp(path, "/live/", 6))
	{
		std::vector<std::string> paths;
		Split(path + 6, "/", paths);

		if (strendswith(path, ".m3u8") && 1 == paths.size())
		{
			std::string app = paths[0].substr(0, paths[0].length() - 5);
			if (s_playlists.find(app) == s_playlists.end())
			{
				hls_playlist_t* playlist = new hls_playlist_t();
				playlist->file = app;
				playlist->m3u8 = hls_m3u8_create(HLS_LIVE_NUM);
				playlist->hls = hls_media_create(HLS_DURATION * 1000, hls_handler, playlist);
				playlist->i = 0;
				s_playlists[app] = playlist;

				thread_create(&playlist->t, hls_server_worker, playlist);
			}

			return hls_server_m3u8(session, app);
		}
		else if (strendswith(path, ".ts") && 2 == paths.size())
		{
			if (s_playlists.find(paths[0]) != s_playlists.end())
			{
				return hls_server_ts(session, paths[0], paths[1]);
			}
		}
	}
	else if (0 == strncmp(path, "/vod/", 5))
	{
		if (path_testfile(path+5))
		{
			return hls_server_reply_file(session, path + 5);
		}
	}

	return hls_server_reply(session, 404, "");
}
static int dash_server_onlive(void* dash, http_session_t* session, const char* /*method*/, const char* path)
{
    char fullpath[PATH_MAX];
    int r = path_concat(path + 6 /* /live/ */, LOCALPATH, fullpath);
	printf("live: %s\n", fullpath);

	const char* name = path_basename(fullpath);
	if (strendswith(name, ".mpd"))
	{
        return dash_server_mpd(session, (dash_playlist_t*)dash);
	}
	else if (path_testfile(name))
	{
		// cross domain
		http_server_set_header(session, "Access-Control-Allow-Origin", "*");
		http_server_set_header(session, "Access-Control-Allow-Methods", "GET, POST, PUT");
		return http_server_sendfile(session, name, NULL, NULL);
	}

	return http_server_send(session, 404, "", 0, NULL, NULL);
}