Beispiel #1
0
GF_EXPORT
char *gf_rtp_streamer_format_sdp_header(char *app_name, char *ip_dest, char *session_name, char *iod64)
{
	u64 size;
	char *sdp;
	FILE *tmp = gf_temp_file_new();
	if (!tmp) return NULL;

	/* write SDP header*/
	fprintf(tmp, "v=0\n");
	fprintf(tmp, "o=%s 3326096807 1117107880000 IN IP%d %s\n", app_name, gf_net_is_ipv6(ip_dest) ? 6 : 4, ip_dest);
	fprintf(tmp, "s=%s\n", (session_name ? session_name : "GPAC Scene Streaming Session"));
	fprintf(tmp, "c=IN IP%d %s\n", gf_net_is_ipv6(ip_dest) ? 6 : 4, ip_dest);
	fprintf(tmp, "t=0 0\n");
	
    if (iod64) fprintf(tmp, "a=mpeg4-iod:\"data:application/mpeg4-iod;base64,%s\"\n", iod64);

	gf_f64_seek(tmp, 0, SEEK_END);
	size = gf_f64_tell(tmp);
	gf_f64_seek(tmp, 0, SEEK_SET);
	sdp = gf_malloc(sizeof(char) * (size_t)(size+1));
	size = fread(sdp, 1, (size_t)size, tmp);
	sdp[size] = 0;
	fclose(tmp);
	return sdp;
}
Beispiel #2
0
GF_DataMap *gf_isom_fdm_new_temp(const char *sPath)
{
	GF_FileDataMap *tmp = (GF_FileDataMap *) gf_malloc(sizeof(GF_FileDataMap));
	if (!tmp) return NULL;
	memset(tmp, 0, sizeof(GF_FileDataMap));
	tmp->type = GF_ISOM_DATA_FILE;
	tmp->mode = GF_ISOM_DATA_MAP_WRITE;

	if (!sPath) {
		tmp->stream = gf_temp_file_new();
	} else {
		char szPath[GF_MAX_PATH];
		if ((sPath[strlen(sPath)-1] != '\\') && (sPath[strlen(sPath)-1] != '/')) {
			sprintf(szPath, "%s%c%p_isotmp", sPath, GF_PATH_SEPARATOR, (void*) tmp);
		} else {
			sprintf(szPath, "%s%p_isotmp", sPath, (void*) tmp);
		}
		tmp->stream = gf_f64_open(szPath, "w+b");
		tmp->temp_file = gf_strdup(szPath);
	}
	if (!tmp->stream) {
		if (tmp->temp_file) gf_free(tmp->temp_file);
		gf_free(tmp);
		return NULL;
	}
	tmp->bs = gf_bs_from_file(tmp->stream, GF_BITSTREAM_WRITE);
	if (!tmp->bs) {
		fclose(tmp->stream);
		gf_free(tmp);
		return NULL;
	}
	return (GF_DataMap *)tmp;
}
Beispiel #3
0
GF_DataMap *gf_isom_fdm_new(const char *sPath, u8 mode)
{
	u8 bs_mode;

	GF_FileDataMap *tmp = (GF_FileDataMap *) gf_malloc(sizeof(GF_FileDataMap));
	if (!tmp) return NULL;
	memset(tmp, 0, sizeof(GF_FileDataMap));
	tmp->type = GF_ISOM_DATA_FILE;
	tmp->mode = mode;

#ifndef GPAC_DISABLE_ISOM_WRITE
	//open a temp file
	if (!strcmp(sPath, "mp4_tmp_edit")) {
		//create  a temp file (that only occurs in EDIT/WRITE mode)
		tmp->stream = gf_temp_file_new();
		bs_mode = GF_BITSTREAM_READ;
	}
#endif

	switch (mode) {
	case GF_ISOM_DATA_MAP_READ:
		if (!tmp->stream) tmp->stream = gf_f64_open(sPath, "rb");
		bs_mode = GF_BITSTREAM_READ;
		break;
	///we open the file in READ/WRITE mode, in case 
	case GF_ISOM_DATA_MAP_WRITE:
		if (!tmp->stream) tmp->stream = gf_f64_open(sPath, "w+b");
		if (!tmp->stream) tmp->stream = gf_f64_open(sPath, "wb");
		bs_mode = GF_BITSTREAM_WRITE;
		break;
	///we open the file in CAT mode, in case 
	case GF_ISOM_DATA_MAP_CAT:
		if (!tmp->stream) tmp->stream = gf_f64_open(sPath, "a+b");
		if (tmp->stream) gf_f64_seek(tmp->stream, 0, SEEK_END);
		bs_mode = GF_BITSTREAM_WRITE;
		break;
	default:
		gf_free(tmp);
		return NULL;
	}
	if (!tmp->stream) {
		gf_free(tmp);
		return NULL;
	}
	tmp->bs = gf_bs_from_file(tmp->stream, bs_mode);
	if (!tmp->bs) {
		fclose(tmp->stream);
		gf_free(tmp);
		return NULL;
	}
	return (GF_DataMap *)tmp;
}
Beispiel #4
0
GF_DataMap *gf_isom_fdm_new(const char *sPath, u8 mode)
{
	u8 bs_mode;

	GF_FileDataMap *tmp = (GF_FileDataMap *) gf_malloc(sizeof(GF_FileDataMap));
	if (!tmp) return NULL;
	memset(tmp, 0, sizeof(GF_FileDataMap));
	tmp->type = GF_ISOM_DATA_FILE;
	tmp->mode = mode;

#ifndef GPAC_DISABLE_ISOM_WRITE
	//open a temp file
	if (!strcmp(sPath, "mp4_tmp_edit")) {
		//create  a temp file (that only occurs in EDIT/WRITE mode)
		tmp->stream = gf_temp_file_new();
		bs_mode = GF_BITSTREAM_READ;
	}
#endif
	if (!strncmp(sPath, "gmem://", 7)) {
		u32 size;
		void *mem_address;
		if (sscanf(sPath, "gmem://%d@%p", &size, &mem_address) != 2)
			return NULL;
		tmp->bs = gf_bs_new((const char *)mem_address, size, GF_BITSTREAM_READ);
		if (!tmp->bs) {
			gf_free(tmp);
			return NULL;
		}
		return (GF_DataMap *)tmp;
	}

	switch (mode) {
	case GF_ISOM_DATA_MAP_READ:
		if (!tmp->stream) tmp->stream = gf_f64_open(sPath, "rb");
		bs_mode = GF_BITSTREAM_READ;
		break;
	///we open the file in READ/WRITE mode, in case
	case GF_ISOM_DATA_MAP_WRITE:
		if (!strcmp(sPath, "std")) {
			tmp->stream = stdout;
			tmp->is_stdout = 1;
		}

		if (!tmp->stream) tmp->stream = gf_f64_open(sPath, "w+b");
		if (!tmp->stream) tmp->stream = gf_f64_open(sPath, "wb");
		bs_mode = GF_BITSTREAM_WRITE;
		break;
	///we open the file in CAT mode, in case
	case GF_ISOM_DATA_MAP_CAT:
		if (!strcmp(sPath, "std")) {
			tmp->stream = stdout;
			tmp->is_stdout = 1;
		}

		if (!tmp->stream) tmp->stream = gf_f64_open(sPath, "a+b");
		if (tmp->stream) gf_f64_seek(tmp->stream, 0, SEEK_END);
		bs_mode = GF_BITSTREAM_WRITE;
		break;
	default:
		gf_free(tmp);
		return NULL;
	}
	if (!tmp->stream) {
		gf_free(tmp);
		return NULL;
	}
	tmp->bs = gf_bs_from_file(tmp->stream, bs_mode);
	if (!tmp->bs) {
		fclose(tmp->stream);
		gf_free(tmp);
		return NULL;
	}
	if (default_write_buffering_size) {
		gf_bs_set_output_buffering(tmp->bs, default_write_buffering_size);
	}
	return (GF_DataMap *)tmp;
}