Exemple #1
0
static Bool uir_process(GF_TermExt *termext, u32 action, void *param)
{
	const char *opt, *uifile;
	GF_UIRecord *uir = termext->udta;

	switch (action) {
	case GF_TERM_EXT_START:
		uir->term = (GF_Terminal *) param;
		opt = gf_modules_get_option((GF_BaseInterface*)termext, "UIRecord", "Mode");
		if (!opt) return 0;
		uifile = gf_modules_get_option((GF_BaseInterface*)termext, "UIRecord", "File");
		if (!uifile) return 0;

		if (!strcmp(opt, "Play")) {
			uir->uif = gf_f64_open(uifile, "rb");
			if (!uir->uif) return 0;
			uir->bs = gf_bs_from_file(uir->uif, GF_BITSTREAM_READ);
			termext->caps |= GF_TERM_EXTENSION_NOT_THREADED;

			uir->evt_filter.on_event = uir_on_event_play;
			uir->evt_filter.udta = uir;
			gf_term_add_event_filter(uir->term, &uir->evt_filter);

			uir_load_event(uir);
		} else if (!strcmp(opt, "Record")) {
			uir->uif = gf_f64_open(uifile, "wb");
			if (!uir->uif) return 0;
			uir->bs = gf_bs_from_file(uir->uif, GF_BITSTREAM_WRITE);

			uir->evt_filter.on_event = uir_on_event_record;
			uir->evt_filter.udta = uir;
			gf_term_add_event_filter(uir->term, &uir->evt_filter);
		} else {
			return 0;
		}
		return 1;

	case GF_TERM_EXT_STOP:
		if (uir->uif) fclose(uir->uif);
		if (uir->bs) gf_bs_del(uir->bs);
		gf_term_remove_event_filter(uir->term, &uir->evt_filter);
		uir->term = NULL;
		/*auto-disable the plugin by default*/
		gf_modules_set_option((GF_BaseInterface*)termext, "UIRecord", "Mode", "Disable");
		break;

	case GF_TERM_EXT_PROCESS:
		/*flush all events until current time if reached*/
		while (uir->evt_loaded && uir->ck && (uir->next_time <= gf_clock_time(uir->ck) )) {
			uir->term->compositor->video_out->on_event(uir->term->compositor->video_out->evt_cbk_hdl, &uir->next_event);
			uir_load_event(uir);
		}
		break;
	}
	return 0;
}
Exemple #2
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;
}
Exemple #3
0
static GF_Err gf_text_guess_format(char *filename, u32 *fmt)
{
	char szLine[2048], szTest[10];
	u32 val;
	FILE *test = gf_f64_open(filename, "rt");
	if (!test) return GF_URL_ERROR;

	while (fgets(szLine, 2048, test) != NULL) {
		REM_TRAIL_MARKS(szLine, "\r\n\t ")

		if (strlen(szLine)) break;
	}
	*fmt = GF_TEXT_IMPORT_NONE;
	if ((szLine[0]=='{') && strstr(szLine, "}{")) *fmt = GF_TEXT_IMPORT_SUB;
	else if (sscanf(szLine, "%u", &val)==1) {
		sprintf(szTest, "%u", val);
		if (!strcmp(szTest, szLine)) *fmt = GF_TEXT_IMPORT_SRT;
	}
	else if (!strnicmp(szLine, "<?xml ", 6)) {
		char *ext = strrchr(filename, '.');
		if (!strnicmp(ext, ".ttxt", 5)) *fmt = GF_TEXT_IMPORT_TTXT;
		ext = strstr(szLine, "?>");
		if (ext) ext += 2;
		if (!ext[0]) {
			if (!fgets(szLine, 2048, test))
				szLine[0] = '\0';
		}
		if (strstr(szLine, "x-quicktime-tx3g")) *fmt = GF_TEXT_IMPORT_TEXML;
	}
	fclose(test);
	return GF_OK;
}
Exemple #4
0
static GF_Err AC3_ConnectService(GF_InputService *plug, GF_ClientService *serv, const char *url)
{
	char szURL[2048];
	char *ext;
	GF_Err reply;
	AC3Reader *read = plug->priv;
	read->service = serv;

	if (read->dnload) gf_service_download_del(read->dnload);
	read->dnload = NULL;

	strcpy(szURL, url);
	ext = strrchr(szURL, '#');
	if (ext) ext[0] = 0;

	/*remote fetch*/
	read->is_remote = !ac3_is_local(szURL);
	if (read->is_remote) {
		ac3_download_file(plug, (char *) szURL);
		return GF_OK;
	}

	reply = GF_OK;
	read->stream = gf_f64_open(szURL, "rb");
	if (!read->stream) {
		reply = GF_URL_ERROR;
	} else if (!AC3_ConfigureFromFile(read)) {
		fclose(read->stream);
		read->stream = NULL;
		reply = GF_NOT_SUPPORTED;
	}
	gf_service_connect_ack(serv, NULL, reply);
	if (!reply && read->is_inline ) AC3_SetupObject(read);
	return GF_OK;
}
Exemple #5
0
GF_Err swf_to_svg_init(SWFReader *read)
{
    char szFileName[GF_MAX_PATH];
    sprintf(szFileName, "%s.svg", read->load->fileName);
    /*init callbacks*/
    read->svg_output = gf_f64_open(szFileName, "wt");
    fprintf(read->svg_output, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    fprintf(read->svg_output, "<svg xmlns=\"http://www.w3.org/2000/svg\" ");
    fprintf(read->svg_output, "xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
    fprintf(read->svg_output, "width=\"100%%\" ");
    fprintf(read->svg_output, "height=\"100%%\" ");
    fprintf(read->svg_output, "viewBox=\"0 0 %d %d\" ", FIX2INT(read->width), FIX2INT(read->height));
    fprintf(read->svg_output, "viewport-fill=\"rgb(255,255,255)\" ");
    fprintf(read->svg_output, ">\n");
    fprintf(read->svg_output, "<g id=\"frame%d\" display=\"none\">\n",read->current_frame);
    fprintf(read->svg_output, "<animate attributeName=\"display\" to=\"inline\" begin=\"%f\" end=\"%f\" fill=\"remove\" restart=\"never\"/>\n",
        1.0*(read->current_frame)/read->frame_rate, 1.0*(read->current_frame+1)/read->frame_rate);
    read->show_frame = swf_svg_show_frame;
    read->allocate_depth = swf_svg_allocate_depth;
    read->place_obj = swf_svg_place_obj;
    read->remove_obj = swf_svg_remove_obj;
    read->define_shape = swf_svg_define_shape;
    read->define_sprite = swf_svg_define_sprite;
    read->set_backcol = swf_svg_set_backcol;
    read->define_button = swf_svg_define_button;
    read->define_text = swf_svg_define_text;
    read->define_edit_text = swf_svg_define_edit_text;
    read->setup_sound = swf_svg_setup_sound;
    read->start_sound = swf_svg_start_sound;
    read->setup_image = swf_svg_setup_image;
    read->action = swf_svg_action;
    read->finalize = swf_svg_finalize;
    return GF_OK;
}
Exemple #6
0
void Playlist::OpenPlayList(CString fileName)
{
	FILE *pl;
	PLEntry *ple;
	Bool load_m3u, go;
	char szLine[GF_MAX_PATH], *sep;
	char szPath[GF_MAX_PATH];

	strcpy(szPath, fileName);
	sep = strrchr(szPath, '\\');
	if (sep) sep[1] = 0;
	else szPath[0] = 0;

	pl = gf_f64_open(fileName, "rt");
	if (!pl) return;
	ple = NULL;
	load_m3u = GF_TRUE;
	while (!feof(pl)) {
		fgets(szLine, GF_MAX_PATH, pl);
		go = GF_TRUE;
		while (go) {
			switch (szLine[strlen(szLine)-1]) {
			case '\n':
			case '\r':
			case ' ':
				szLine[strlen(szLine)-1] = 0;
				break;
			default:
				go = GF_FALSE;
				break;
			}
		}
		if (!strlen(szLine)) continue;
		if (!stricmp(szLine, "[playlist]")) {
			load_m3u = GF_FALSE;
		} else if (load_m3u) {
			ple = new PLEntry(szLine, szPath);
			gf_list_add(m_entries, ple);
		} else if (!strnicmp(szLine, "file", 4)) {
			char *st = strchr(szLine, '=');
			if (!st) ple = NULL;
			else {
				ple = new PLEntry(st + 1, szPath);
				gf_list_add(m_entries, ple);
			}
		} else if (ple && !strnicmp(szLine, "Length", 6)) {
			char *st = strchr(szLine, '=');
			s32 d = atoi(st + 1);
			if (d>0) ple->m_duration = d;
		} else if (ple && !strnicmp(szLine, "Title", 5)) {
			char *st = strchr(szLine, '=');
			gf_free(ple->m_disp_name);
			ple->m_disp_name = gf_strdup(st + 6);
		}
	}
	fclose(pl);
	m_all_dead_entries=-1;
	m_cur_entry = -1;
	RefreshList();
}
Exemple #7
0
static u32 check_existing_file(char *base_file, char *ext, char *data, u32 data_size, u32 idx)
{
	char szFile[GF_MAX_PATH];
	u64 fsize;
	FILE *f;
	
	sprintf(szFile, "%s%04X%s", base_file, idx, ext);
	
	f = gf_f64_open(szFile, "rb");
	if (!f) return 0;

	gf_f64_seek(f, 0, SEEK_END);
	fsize = gf_f64_tell(f);
	if (fsize==data_size) {
		u32 offset=0;
		char cache[1024];
		gf_f64_seek(f, 0, SEEK_SET);
		while (fsize) {
			u32 read = (u32) fread(cache, 1, 1024, f);
			fsize -= read;
			if (memcmp(cache, data+offset, sizeof(char)*read)) break;
			offset+=read;
		}
		fclose(f);
		f = NULL;
		/*same file*/
		if (!fsize) return 2;
	}
	if (f)
	  fclose(f);
	return 1;
}
Exemple #8
0
GF_EXPORT
FILE *gf_temp_file_new()
{
#if defined(_WIN32_WCE)
	TCHAR pPath[MAX_PATH+1];
	TCHAR pTemp[MAX_PATH+1];
	if (!GetTempPath(MAX_PATH, pPath)) {
		pPath[0] = '.';
		pPath[1] = '.';
	}
	if (GetTempFileName(pPath, TEXT("git"), 0, pTemp))
		return _wfopen(pTemp, TEXT("w+b"));

	return NULL;
#elif defined(WIN32)
	char tmp[MAX_PATH], t_file[100];
	FILE *res = tmpfile();
	if (res) return res;
	{
		u32 err = GetLastError();
		GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[Win32] system failure for tmpfile(): 0x%08x\n", err));
	}
	/*tmpfile() may fail under vista ...*/
	if (!GetEnvironmentVariable("TEMP",tmp,MAX_PATH))
		return NULL;
	sprintf(t_file, "\\gpac_%08x.tmp", (u32) tmp);
	strcat(tmp, t_file);
	return gf_f64_open(tmp, "w+b");
#else
	return tmpfile();
#endif
}
Exemple #9
0
static char *validator_create_snapshot(GF_Validator *validator)
{
	GF_Err e;
	GF_VideoSurface fb;
	GF_Terminal *term = validator->term;
	char *dumpname;

	dumpname = validator_get_snapshot_name(validator, validator->is_recording, validator->snapshot_number);

	e = gf_term_get_screen_buffer(term, &fb);
	if (e) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[Validator] Error dumping screen buffer %s\n", gf_error_to_string(e)));
	} else {
		u32 dst_size = fb.width*fb.height*3;
		char *dst=gf_malloc(sizeof(char)*dst_size);

		e = gf_img_png_enc(fb.video_buffer, fb.width, fb.height, fb.pitch_y, fb.pixel_format, dst, &dst_size);
		if (e) {
			GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[Validator] Error encoding PNG %s\n", gf_error_to_string(e)));
		} else {
			FILE *png = gf_f64_open(dumpname, "wb");
			if (!png) {
				GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[Validator] Error writing file %s\n", dumpname));
			} else {
				gf_fwrite(dst, dst_size, 1, png);
				fclose(png);
				GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[Validator] Writing file %s\n", dumpname));
			}
		}
		if (dst) gf_free(dst);
		gf_term_release_screen_buffer(term, &fb);
	}
	validator->snapshot_number++;
	return dumpname;
}
Exemple #10
0
void IMG_NetIO(void *cbk, GF_NETIO_Parameter *param)
{
    GF_Err e;
    const char *szCache;
    IMGLoader *read = (IMGLoader *) cbk;
    if (!read->dnload) return;

    /*handle service message*/
    gf_service_download_update_stats(read->dnload);

    e = param->error;
    /*wait to get the whole file*/
    if (!e && (param->msg_type!=GF_NETIO_DATA_TRANSFERED)) return;

    if (param->msg_type==GF_NETIO_DATA_TRANSFERED) {
        szCache = gf_dm_sess_get_cache_name(read->dnload);
        if (!szCache) e = GF_IO_ERR;
        else {
            read->stream = gf_f64_open((char *) szCache, "rb");
            if (!read->stream) e = GF_SERVICE_ERROR;
            else {
                e = GF_OK;
                gf_f64_seek(read->stream, 0, SEEK_END);
                read->data_size = (u32) gf_f64_tell(read->stream);
                gf_f64_seek(read->stream, 0, SEEK_SET);
            }
        }
    }
    /*OK confirm*/
    gf_service_connect_ack(read->service, NULL, e);
    if (!e) IMG_SetupObject(read);
}
Exemple #11
0
GF_Err gf_isom_extract_meta_xml(GF_ISOFile *file, Bool root_meta, u32 track_num, char *outName, Bool *is_binary)
{
	u32 i, count;
	FILE *didfile;
	GF_XMLBox *xml = NULL;
	GF_MetaBox *meta = gf_isom_get_meta(file, root_meta, track_num);
	if (!meta) return GF_BAD_PARAM;

	/*Find XMLBox*/
	count = gf_list_count(meta->other_boxes);
	for (i = 0; i <count; i++) {
		GF_Box *a = (GF_Box *)gf_list_get(meta->other_boxes, i);
		if ((a->type == GF_ISOM_BOX_TYPE_XML) || (a->type == GF_ISOM_BOX_TYPE_BXML) ) {
			xml = (GF_XMLBox *)a;
			break;
		}
	}
	if (!xml || !xml->xml || !xml->xml_length) return GF_BAD_PARAM;
	
	didfile = gf_f64_open(outName, "wt");
	if (!didfile) return GF_IO_ERR;
	fwrite(xml->xml, xml->xml_length, 1, didfile);
	fclose(didfile);

	if (is_binary) *is_binary = (xml->type==GF_ISOM_BOX_TYPE_BXML) ? 1 : 0;
	return GF_OK;
}
Exemple #12
0
Bool gf_cache_check_if_cache_file_is_corrupted(const DownloadedCacheEntry entry) {

	FILE *the_cache = gf_f64_open ( entry->cache_filename, "rb" );
	if ( the_cache )
	{
		char * endPtr;
		const char * keyValue = gf_cfg_get_key ( entry->properties, CACHE_SECTION_NAME, CACHE_SECTION_NAME_CONTENT_SIZE );

		gf_f64_seek ( the_cache, 0, SEEK_END );
		entry->cacheSize = ( u32 ) gf_f64_tell ( the_cache );
		fclose ( the_cache );
		if (keyValue) {
			entry->contentLength = strtoul( keyValue, &endPtr, 10);
			if (*endPtr!='\0' || entry->contentLength != entry->cacheSize) {
				entry->flags |= CORRUPTED;
				GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[CACHE] gf_cache_create_entry:%d, Cache corrupted: file and cache info size mismatch.\n", __LINE__));
			}
		} else {
			entry->flags |= CORRUPTED;
			GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[CACHE] gf_cache_create_entry:%d, CACHE is corrupted !\n", __LINE__));
		}
	} else {
		entry->flags |= CORRUPTED;
	}
	return entry->flags & CORRUPTED;
}
Exemple #13
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;
}
Exemple #14
0
GF_EXPORT
GF_Err gf_cfg_save(GF_Config *iniFile)
{
	u32 i, j;
	IniSection *sec;
	IniKey *key;
	FILE *file;

	if (!iniFile->hasChanged) return GF_OK;
	if (iniFile->skip_changes) return GF_OK;
	if (!iniFile->fileName) return GF_OK;

	file = gf_f64_open(iniFile->fileName, "wt");
	if (!file) return GF_IO_ERR;

	i=0;
	while ( (sec = (IniSection *) gf_list_enum(iniFile->sections, &i)) ) {
		/*Temporary sections are not saved*/
		if (!strnicmp(sec->section_name, "Temp", 4)) continue;

		fprintf(file, "[%s]\n", sec->section_name);
		j=0;
		while ( (key = (IniKey *) gf_list_enum(sec->keys, &j)) ) {
			fprintf(file, "%s=%s\n", key->name, key->value);
		}
		/* end of section */
		fprintf(file, "\n");
	}
	fclose(file);
	return GF_OK;
}
Exemple #15
0
static GF_Err ISMA_GetGPAC_KMS(ISMAEAPriv *priv, GF_Channel *ch, const char *kms_url)
{
	GF_Err e;
	FILE *t;
	GF_DownloadSession * sess;
	if (!strnicmp(kms_url, "(ipmp)", 6)) return GF_NOT_SUPPORTED;
	else if (!strnicmp(kms_url, "(uri)", 5)) kms_url += 5;
	else if (!strnicmp(kms_url, "file://", 7)) kms_url += 7;

	e = GF_OK;
	/*try local*/
	t = (strstr(kms_url, "://") == NULL) ? gf_f64_open(kms_url, "r") : NULL;
	if (t) {
		fclose(t);
		return gf_ismacryp_gpac_get_info(ch->esd->ESID, (char *)kms_url, priv->key, priv->salt);
	}
	/*note that gpac doesn't have TLS support -> not really usefull. As a general remark, ISMACryp
	is supported as a proof of concept, crypto and IPMP being the last priority on gpac...*/
	GF_LOG(GF_LOG_INFO, GF_LOG_MEDIA, ("[CENC/ISMA] Fetching ISMACryp key for channel %d\n", ch->esd->ESID) );

	sess = gf_term_download_new(ch->service, kms_url, 0, ISMA_KMS_NetIO, ch);
	if (!sess) return GF_IO_ERR;
	/*start our download (threaded)*/
	gf_dm_sess_process(sess);

	while (1) {
		e = gf_dm_sess_get_stats(sess, NULL, NULL, NULL, NULL, NULL, NULL);
		if (e) break;
	}
	if (e==GF_EOS) {
		e = gf_ismacryp_gpac_get_info(ch->esd->ESID, (char *) gf_dm_sess_get_cache_name(sess), priv->key, priv->salt);
	}
	gf_term_download_del(sess);
	return e;
}
Exemple #16
0
GF_Err WriteToFile(GF_ISOFile *movie)
{
	FILE *stream;
	GF_BitStream *bs;
	MovieWriter mw;
	GF_Err e = GF_OK;
	if (!movie) return GF_BAD_PARAM;

	if (movie->openMode == GF_ISOM_OPEN_READ) return GF_BAD_PARAM;

	e = gf_isom_insert_copyright(movie);
	if (e) return e;

	memset(&mw, 0, sizeof(mw));
	mw.movie = movie;

	//capture mode: we don't need a new bitstream
	if (movie->openMode == GF_ISOM_OPEN_WRITE) {
		e = WriteFlat(&mw, 0, movie->editFileMap->bs);
	} else {
		//OK, we need a new bitstream
		stream = gf_f64_open(movie->finalName, "w+b");
		if (!stream) return GF_IO_ERR;
		bs = gf_bs_from_file(stream, GF_BITSTREAM_WRITE);
		if (!bs) {
			fclose(stream);
			return GF_OUT_OF_MEM;
		}

		switch (movie->storageMode) {
		case GF_ISOM_STORE_TIGHT:
		case GF_ISOM_STORE_INTERLEAVED:
			e = WriteInterleaved(&mw, bs, 0);
			break;
		case GF_ISOM_STORE_DRIFT_INTERLEAVED:
			e = WriteInterleaved(&mw, bs, 1);
			break;
		case GF_ISOM_STORE_STREAMABLE:
			e = WriteFlat(&mw, 1, bs);
			break;
		default:
			e = WriteFlat(&mw, 0, bs);
			break;
		}
		
		gf_bs_del(bs);
		fclose(stream);
	}
	if (mw.buffer) gf_free(mw.buffer);
	if (mw.nb_done<mw.total_samples) {
		gf_set_progress("ISO File Writing", mw.total_samples, mw.total_samples);
	}
	return e;
}
Exemple #17
0
static void live_session_setup(LiveSession *livesess, char *ip, u16 port, u32 path_mtu, u32 ttl, char *ifce_addr, char *sdp_name)
{
	RTPChannel *rtpch;
	u32 count = gf_seng_get_stream_count(livesess->seng);
	u32 i;
	char *iod64 = gf_seng_get_base64_iod(livesess->seng);
	char *sdp = gf_rtp_streamer_format_sdp_header("GPACSceneStreamer", ip, NULL, iod64);
	if (iod64) gf_free(iod64);

	for (i=0; i<count; i++) {
		u16 ESID;
		u32 st, oti, ts;
		char *config = NULL;
		u32 config_len;
		gf_seng_get_stream_config(livesess->seng, i, &ESID, &config, &config_len, &st, &oti, &ts);

		GF_SAFEALLOC(rtpch, RTPChannel);
		rtpch->timescale = ts;
		rtpch->init_time = gf_sys_clock();

		switch (st) {
		case GF_STREAM_OD:
		case GF_STREAM_SCENE:
			rtpch->rtp = gf_rtp_streamer_new_extended(st, oti, ts, ip, port, path_mtu, ttl, ifce_addr, 
								 GP_RTP_PCK_SYSTEMS_CAROUSEL, (char *) config, config_len,
								 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4);

			if (rtpch->rtp) {
				gf_rtp_streamer_disable_auto_rtcp(rtpch->rtp);
				rtpch->manual_rtcp = 1;
			}
			break;
		default:
			rtpch->rtp = gf_rtp_streamer_new(st, oti, ts, ip, port, path_mtu, ttl, ifce_addr, GP_RTP_PCK_SIGNAL_RAP, (char *) config, config_len);
			break;
		}
		rtpch->ESID = ESID;
		rtpch->adjust_carousel_time = 1;
		gf_list_add(livesess->streams, rtpch);

		gf_rtp_streamer_append_sdp(rtpch->rtp, ESID, (char *) config, config_len, NULL, &sdp);

		/*fetch initial config of the broadcast*/
		gf_seng_get_stream_carousel_info(livesess->seng, ESID, &rtpch->carousel_period, &rtpch->aggregate_on_stream);

		port += 2;
	}
    if (sdp) {
		FILE *out = gf_f64_open(sdp_name, "wt");
        fprintf(out, "%s", sdp);
		fclose(out);
	    gf_free(sdp);
    }
}
Exemple #18
0
static Bool svg_check_download(SVGIn *svgin)
{
	u64 size;
	FILE *f = gf_f64_open(svgin->file_name, "rb");
	if (!f) return 0;
	gf_f64_seek(f, 0, SEEK_END);
	size = gf_f64_tell(f);
	fclose(f);
	if (size==svgin->file_size) return 1;
	return 0;
}
Exemple #19
0
static void setup_logs()
{
	if (log_file) fclose(log_file);
	log_file = NULL;

	gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_ERROR);
	gf_log_set_callback(NULL, NULL);

	if (log_rti) {
		const char *filename = gf_cfg_get_key(user.config, "General", "LogFile");
		if (!filename) {
			gf_cfg_set_key(user.config, "General", "LogFile", "\\gpac_logs.txt");
			filename = "\\gpac_logs.txt";
		}
		log_file = gf_f64_open(filename, "a+t");

		fprintf(log_file, "!! GPAC RunTime Info for file %s !!\n", the_url);
		fprintf(log_file, "SysTime(ms)\tSceneTime(ms)\tCPU\tFPS\tMemory(kB)\tObservation\n");

		gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_ERROR);
		gf_log_set_tool_level(GF_LOG_RTI, GF_LOG_DEBUG);
		gf_log_set_callback(log_file, on_gpac_rti_log);

		GF_LOG(GF_LOG_DEBUG, GF_LOG_RTI, ("[RTI] System state when enabling log\n"));
	} else {
		const char *filename = gf_cfg_get_key(user.config, "General", "LogFile");
		if (!filename) {
			gf_cfg_set_key(user.config, "General", "LogFile", "\\gpac_logs.txt");
			filename = "\\gpac_logs.txt";
		}
		const char *logs = gf_cfg_get_key(user.config, "General", "Logs");
		if (logs) {
			if (gf_log_set_tools_levels( logs ) != GF_OK) {
			} else {
				if (log_file = gf_f64_open(filename, "a+t")) {
					gf_log_set_callback(log_file, on_gpac_log);
				}
			}
		}
	}
}
Exemple #20
0
static Bool IsLargeFile(char *path)
{
#ifndef _WIN32_WCE
	FILE *stream;
	s64 size;
	stream = gf_f64_open(path, "rb");
	if (!stream) return 0;
	gf_f64_seek(stream, 0, SEEK_END);
	size = gf_f64_tell(stream);
	fclose(stream);
	if (size == -1L) return 0;
	if (size > 0xFFFFFFFF) return 1;
#endif
	return 0;
}
Exemple #21
0
GF_CacheReader gf_cache_reader_new(const DownloadedCacheEntry entry) {
	GF_CacheReader reader;
	if (entry == NULL)
		return NULL;
	reader = gf_malloc(sizeof(struct __CacheReaderStruct));
	if (reader == NULL)
		return NULL;
	reader->readPtr = gf_f64_open( entry->cache_filename, "rb" );
	reader->readPosition = 0;
	if (!reader->readPtr) {
		gf_cache_reader_del(reader);
		return NULL;
	}
	return reader;
}
Exemple #22
0
GF_Err gf_cache_open_write_cache( const DownloadedCacheEntry entry, const GF_DownloadSession * sess ) {
	CHECK_ENTRY;
	if (!sess)
		return GF_BAD_PARAM;
#ifdef ENABLE_WRITE_MX
	GF_LOG(GF_LOG_DEBUG, GF_LOG_NETWORK,("[CACHE] Locking write mutex %p for entry=%s\n", (void*) (entry->write_mutex), entry->url) );
	gf_mx_p(entry->write_mutex);
#endif
	entry->write_session = sess;
	if (!entry->continue_file) {
		assert( ! entry->writeFilePtr);

		entry->written_in_cache = 0;
	}
	entry->flags &= ~CORRUPTED;


	if (entry->memory_stored) {
		GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[CACHE] Opening cache file %s for write (%s)...\n", entry->cache_filename, entry->url));
		if (!entry->mem_allocated || (entry->mem_allocated < entry->contentLength)) {
			if (entry->contentLength) entry->mem_allocated = entry->contentLength;
			else if (!entry->mem_allocated) entry->mem_allocated = 81920;
			entry->mem_storage = gf_realloc(entry->mem_storage, sizeof(char)* (entry->mem_allocated + 2) );
		}
		if (!entry->mem_allocated) {
			GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[CACHE] Failed to create memory storage for file %s\n", entry->url));
			return GF_OUT_OF_MEM;
		}
		sprintf(entry->cache_filename, "gmem://%d@%p", entry->contentLength, entry->mem_storage);
		return GF_OK;
	}

	GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[CACHE] Opening cache file %s for write (%s)...\n", entry->cache_filename, entry->url));
	entry->writeFilePtr = gf_f64_open(entry->cache_filename, entry->continue_file ? "a+b" : "wb");
	if (!entry->writeFilePtr) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK,
		       ("[CACHE] Error while opening cache file %s for writting.\n", entry->cache_filename));
		entry->write_session = NULL;
#ifdef ENABLE_WRITE_MX
		gf_mx_v(entry->write_mutex);
#endif
		return GF_IO_ERR;
	}
	entry->file_exists = 1;
	if (entry->continue_file )
		gf_f64_seek(entry->writeFilePtr, 0, SEEK_END);
	return GF_OK;
}
Exemple #23
0
static Bool OGG_ReadPage(OGGReader *read, ogg_page *oggpage)
{
	char buf[OGG_BUFFER_SIZE];
	GF_Err e;

	/*remote file, check if we use cache*/
	if (read->is_remote) {
		u32 total_size, status;
		e = gf_dm_sess_get_stats(read->dnload, NULL, NULL, &total_size, NULL, NULL, &status);
		/*not ready*/
		if ((e<GF_OK) || (status > GF_NETIO_DATA_EXCHANGE)) return 0;
		if (status == GF_NETIO_DATA_EXCHANGE) {
			if (!total_size && !read->is_live) {
				read->is_live = 1;
				read->tune_in_time = gf_sys_clock();
			}
			else if (!read->is_live  && !read->ogfile) {
				const char *szCache = gf_dm_sess_get_cache_name(read->dnload);
				if (!szCache) return 0;
				read->ogfile = gf_f64_open((char *) szCache, "rb");
				if (!read->ogfile) return 0;
			}
		}
	}

    while (ogg_sync_pageout(&read->oy, oggpage ) != 1 ) {
        char *buffer;
		u32 bytes;
		
		if (read->ogfile) {
			if (feof(read->ogfile)) {
				OGG_EndOfFile(read);
				return 0;
			}
			bytes = fread(buf, 1, OGG_BUFFER_SIZE, read->ogfile);
		} else {
			e = gf_dm_sess_fetch_data(read->dnload, buf, OGG_BUFFER_SIZE, &bytes);
			if (e) return 0;
		}
		if (!bytes) return 0;
		buffer = ogg_sync_buffer(&read->oy, bytes);
		memcpy(buffer, buf, bytes);
        ogg_sync_wrote(&read->oy, bytes);
    }
    return 1;
}
Exemple #24
0
/*Dummy input just send a file name, no multitrack to handle so we don't need to check sub_url nor expected type*/
static GF_Descriptor *DC_GetServiceDesc(GF_InputService *plug, u32 expect_type, const char *sub_url)
{
	u32 size = 0;
	char *uri;
	GF_ESD *esd;
	GF_BitStream *bs;
	DCReader *read = (DCReader *) plug->priv;
	GF_InitialObjectDescriptor *iod = (GF_InitialObjectDescriptor *) gf_odf_desc_new(GF_ODF_IOD_TAG);
	iod->scene_profileAndLevel = 1;
	iod->graphics_profileAndLevel = 1;
	iod->OD_profileAndLevel = 1;
	iod->audio_profileAndLevel = 0xFE;
	iod->visual_profileAndLevel = 0xFE;
	iod->objectDescriptorID = 1;

	if (read->is_views_url) {
		iod->URLString = gf_strdup(read->url);
		return (GF_Descriptor *)iod;
	}

	esd = gf_odf_desc_esd_new(0);
	esd->slConfig->timestampResolution = 1000;
	esd->slConfig->useTimestampsFlag = 1;
	esd->ESID = 0xFFFE;
	esd->decoderConfig->streamType = GF_STREAM_PRIVATE_SCENE;
	esd->decoderConfig->objectTypeIndication = read->oti;
	if (read->dnload) {
		uri = (char *) gf_dm_sess_get_cache_name(read->dnload);
		gf_dm_sess_get_stats(read->dnload, NULL, NULL, &size, NULL, NULL, NULL);
	} else {
		FILE *f = gf_f64_open(read->url, "rt");
		gf_f64_seek(f, 0, SEEK_END);
		size = (u32) gf_f64_tell(f);
		fclose(f);
		uri = read->url;
	}
	bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
	gf_bs_write_u32(bs, size);
	gf_bs_write_data(bs, uri, (u32) strlen(uri));
	gf_bs_get_content(bs, &esd->decoderConfig->decoderSpecificInfo->data, &esd->decoderConfig->decoderSpecificInfo->dataLength);
	gf_bs_del(bs);

	gf_list_add(iod->ESDescriptors, esd);
	return (GF_Descriptor *)iod;
}
Exemple #25
0
GF_Err gf_img_file_dec(char *png_filename, u32 *hint_oti, u32 *width, u32 *height, u32 *pixel_format, char **dst, u32 *dst_size)
{
    u32 fsize, read, oti;
    FILE *f;
    char *data;
    GF_Err e;
    f = gf_f64_open(png_filename, "rb");
    if (!f) return GF_URL_ERROR;

	oti = 0;
	if (!hint_oti || ! *hint_oti) {
		char *ext = strrchr(png_filename, '.');
		if (!ext) return GF_NOT_SUPPORTED;
		if (!stricmp(ext, ".png")) oti = GPAC_OTI_IMAGE_PNG;
		else if (!stricmp(ext, ".jpg") || !stricmp(ext, ".jpeg")) oti = GPAC_OTI_IMAGE_JPEG;
	}
    gf_f64_seek(f, 0, SEEK_END);
    fsize = (u32)gf_f64_tell(f);
    gf_f64_seek(f, 0, SEEK_SET);
    data = gf_malloc(fsize);
    read = fread(data, sizeof(char), fsize, f);
	fclose( f );
    if (read != fsize) return GF_IO_ERR;

	e = GF_NOT_SUPPORTED;
	*dst_size = 0;
	if (oti == GPAC_OTI_IMAGE_JPEG) {
#ifdef GPAC_HAS_JPEG
		e = gf_img_jpeg_dec(data, fsize, width, height, pixel_format, NULL, dst_size, 0);
		if (*dst_size) {
			*dst = gf_malloc(*dst_size);
			return gf_img_jpeg_dec(data, fsize, width, height, pixel_format, NULL, dst_size, 0);
		}
#endif
	} else if (oti == GPAC_OTI_IMAGE_PNG) {
#ifdef GPAC_HAS_PNG
		e = gf_img_png_dec(data, fsize, width, height, pixel_format, NULL, dst_size);
		if (*dst_size) {
			*dst = gf_malloc(*dst_size);
			return gf_img_png_dec(data, fsize, width, height, pixel_format, *dst, dst_size);
		}
#endif
	}
	return e;
}
Exemple #26
0
GF_Err gf_webvtt_dump_iso_track(GF_MediaExporter *dumper, char *szName, u32 track, Bool merge)
{
    GF_Err  e;
    u32     i;
    u32     count;
    u32     timescale;
    FILE    *out;
    u32     di;
    u64     duration;
    GF_WebVTTParser *parser;

    out = szName ? gf_f64_open(szName, "wt") : stdout;
    if (!out) return GF_IO_ERR;// gf_export_message(dumper, GF_IO_ERR, "Error opening %s for writing - check disk access & permissions", szName);

    parser = gf_webvtt_parser_new();
    parser->user = out;
    parser->on_cue_read = gf_webvtt_dump_cue;

    e = gf_webvtt_dump_header(out, dumper->file, track, 1);
    if (e) goto exit;

    timescale = gf_isom_get_media_timescale(dumper->file, track);

    count = gf_isom_get_sample_count(dumper->file, track);
    for (i=0; i<count; i++) {
        GF_ISOSample *samp = gf_isom_get_sample(dumper->file, track, i+1, &di);
        if (!samp) {
            e = gf_isom_last_error(dumper->file);
            goto exit;
        }
        e = gf_webvtt_parse_iso_sample(parser, timescale, samp, merge);
        if (e) goto exit;
        //gf_webvtt_dump_iso_sample(out, timescale, samp);
    }
    duration = gf_isom_get_media_duration(dumper->file, track);
    gf_webvtt_parser_dump_finalize(parser, duration);

exit:
    gf_webvtt_parser_del(parser);
    if (szName) fclose(out);
    return e;
}
Exemple #27
0
void MP4T_DumpSDP(GF_ISOFile *file, const char *name)
{
	const char *sdp;
	u32 size, i;
	FILE *f;

	f = gf_f64_open(name, "wt");
	//get the movie SDP
	gf_isom_sdp_get(file, &sdp, &size);
	fwrite(sdp, size, 1, f);
	fprintf(f, "\r\n");

	//then tracks
	for (i=0; i<gf_isom_get_track_count(file); i++) {
		if (gf_isom_get_media_type(file, i+1) != GF_ISOM_MEDIA_HINT) continue;
		gf_isom_sdp_track_get(file, i+1, &sdp, &size);
		fwrite(sdp, size, 1, f);
	}
	fclose(f);
}
Exemple #28
0
GF_Err gf_isom_set_meta_xml(GF_ISOFile *file, Bool root_meta, u32 track_num, char *XMLFileName, Bool IsBinaryXML)
{
	GF_Err e;
	FILE *xmlfile;
	GF_XMLBox *xml;
	GF_MetaBox *meta;

	e = CanAccessMovie(file, GF_ISOM_OPEN_WRITE);
	if (e) return e;

	meta = gf_isom_get_meta(file, root_meta, track_num);
	if (!meta) return GF_BAD_PARAM;

	e = gf_isom_remove_meta_xml(file, root_meta, track_num);
	if (e) return e;

	xml = (GF_XMLBox *)xml_New();
	if (!xml) return GF_OUT_OF_MEM;
	gf_list_add(meta->other_boxes, xml);
	if (IsBinaryXML) xml->type = GF_ISOM_BOX_TYPE_BXML;


	/*assume 32bit max size = 4Go should be sufficient for a DID!!*/
	xmlfile = gf_f64_open(XMLFileName, "rb");
	if (!xmlfile) return GF_URL_ERROR;
	gf_f64_seek(xmlfile, 0, SEEK_END);
	assert(gf_f64_tell(xmlfile) < 1<<31);
	xml->xml_length = (u32) gf_f64_tell(xmlfile);
	gf_f64_seek(xmlfile, 0, SEEK_SET);
	xml->xml = (char*)gf_malloc(sizeof(unsigned char)*xml->xml_length);
	xml->xml_length = fread(xml->xml, 1, sizeof(unsigned char)*xml->xml_length, xmlfile);
	if (ferror(xmlfile)) {
		gf_free(xml->xml);
		xml->xml = NULL;
		return GF_BAD_PARAM;
	}
	fclose(xmlfile);
	return GF_OK;
}
Exemple #29
0
void Playlist::Save(char *szPath, Bool save_m3u)
{
	FILE *out = gf_f64_open(szPath, "wt");
	if (!save_m3u)
		fprintf(out, "[playlist]\nNumberOfEntries=%d\n", gf_list_count(m_entries));

	for (u32 i=0; i<gf_list_count(m_entries); i++) {
		PLEntry *ple = (PLEntry *) gf_list_get(m_entries, i);
		if (save_m3u) {
			fprintf(out, "%s\n", ple->m_url);
		} else {
			fprintf(out, "File%d=%s\n", i+1, ple->m_url);
			fprintf(out, "Title%d=%s\n", i+1, ple->m_disp_name);
			fprintf(out, "Length%d=%d\n", i+1, ple->m_duration ? ple->m_duration : -1);

		}
	}
	if (!save_m3u) fprintf(out, "Version=2\n");

	fprintf(out, "\n");
	fclose(out);
}
Exemple #30
0
void COsmo4AppView::SetupLogs()
{
	const char *opt;

#ifndef GPAC_GUI_ONLY
	gf_mx_p(m_mx);
	if (do_log) {
		gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_NONE);
		do_log = 0;
	}
	/*setup GPAC logs: log all errors*/
	opt = gf_cfg_get_key(m_user.config, "General", "Logs");
	if (opt && !strstr(opt, "none")){
		const char *filename = gf_cfg_get_key(m_user.config, "General", "LogFile");
		if (!filename) {
			gf_cfg_set_key(m_user.config, "General", "LogFile", "\\data\\gpac_logs.txt");
			filename = "\\data\\gpac_logs.txt";
		}
		m_Logs = gf_f64_open(filename, "wt");
		if (!m_Logs) {
			MessageBox("Cannot open log file - disabling logs", "Warning !");
		} else {
			MessageBox("Debug logs enabled!", filename);
			do_log = 1;
			gf_log_set_tools_levels( opt );
		}
	}
	if (!do_log) {
		gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_ERROR);
		if (m_Logs) fclose(m_Logs);
	}

	gf_log_set_callback(this, on_gpac_log);
	gf_mx_v(m_mx);

	GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("Osmo4 logs initialized\n"));
#endif
}