static GF_Err ISOW_Open(GF_StreamingCache *mc, GF_ClientService *serv, const char *location_and_name, Bool keep_existing_files) { char szRoot[GF_MAX_PATH], szPath[GF_MAX_PATH], *ext; ISOMReader *cache = (ISOMReader *)mc->priv; if (cache->mov || cache->service) return GF_BAD_PARAM; strcpy(szRoot, location_and_name); ext = strrchr(szRoot, '.'); if (ext) ext[0] = 0; strcpy(szPath, szRoot); strcat(szPath, ".mp4"); if (keep_existing_files) { FILE *f = gf_fopen(szPath, "rb"); if (f) { u32 i=0; gf_fclose(f); while (1) { sprintf(szPath, "%s_%04d.mp4", szRoot, i); f = gf_fopen(szPath, "rb"); if (!f) break; gf_fclose(f); i++; } } } /*create a new movie in write mode (eg no editing)*/ cache->mov = gf_isom_open(szPath, GF_ISOM_OPEN_WRITE, NULL); if (!cache->mov) return gf_isom_last_error(NULL); cache->service = serv; return GF_OK; }
void VTT_load_script(VTTDec *vttdec, GF_SceneGraph *graph) { GF_Node *n, *root; GF_FieldInfo info; const char *path; FILE *jsfile; if (!graph) return; gf_sg_add_namespace(graph, "http://www.w3.org/2000/svg", NULL); gf_sg_add_namespace(graph, "http://www.w3.org/1999/xlink", "xlink"); gf_sg_add_namespace(graph, "http://www.w3.org/2001/xml-events", "ev"); gf_sg_set_scene_size_info(graph, 800, 600, GF_TRUE); /* modify the scene with an Inline/Animation pointing to the VTT Renderer */ n = root = gf_node_new(graph, TAG_SVG_svg); gf_node_register(root, NULL); gf_sg_set_root_node(graph, root); gf_node_get_attribute_by_name(n, "xmlns", 0, GF_TRUE, GF_FALSE, &info); gf_svg_parse_attribute(n, &info, "http://www.w3.org/2000/svg", 0); VTT_UpdateSizeInfo(vttdec); gf_node_init(n); n = gf_node_new(graph, TAG_SVG_script); gf_node_register(n, root); gf_node_list_add_child(&((GF_ParentNode *)root)->children, n); path = gf_modules_get_option((GF_BaseInterface *)vttdec->module, "WebVTT", "RenderingScript"); if (!path) { /* try to find the JS renderer in the default GPAC installation folder */ const char *startuppath = gf_modules_get_option((GF_BaseInterface *)vttdec->module, "General", "StartupFile"); path = gf_url_concatenate(startuppath, "webvtt-renderer.js"); jsfile = gf_fopen(path, "rt"); if (jsfile) { gf_modules_set_option((GF_BaseInterface *)vttdec->module, "WebVTT", "RenderingScript", path); gf_fclose(jsfile); } else { GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC, ("[WebVTT] Cannot find Rendering Script [WebVTT:RenderingScript] - check config file\n")); return; } } jsfile = gf_fopen(path, "rt"); if (jsfile) { gf_fclose(jsfile); gf_node_get_attribute_by_tag(n, TAG_XLINK_ATT_href, GF_TRUE, GF_FALSE, &info); if (strstr(path, ":\\")) { gf_svg_parse_attribute(n, &info, (char *) path, 0); } else { char szPath[GF_MAX_PATH]; strcpy(szPath, "file://"); strcat(szPath, path); gf_svg_parse_attribute(n, &info, (char *) szPath, 0); } vttdec->has_rendering_script = GF_TRUE; } else { GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC, ("[WebVTT] Cannot open Rendering Script - %s\n", path)); return; } gf_node_init(n); }
void RP_SDPFromFile(RTPClient *rtp, char *file_name, RTPStream *stream) { FILE *_sdp; char *sdp_buf; u32 sdp_size; sdp_buf = NULL; if (file_name && strstr(file_name, "file://")) file_name += strlen("file://"); if (!file_name || !(_sdp = gf_fopen(file_name, "rt")) ) { gf_service_connect_ack(rtp->service, NULL, GF_URL_ERROR); return; } gf_fseek(_sdp, 0, SEEK_END); sdp_size = (u32) gf_ftell(_sdp); gf_fseek(_sdp, 0, SEEK_SET); sdp_buf = (char*)gf_malloc(sdp_size); if (1 > fread(sdp_buf, 1, sdp_size, _sdp)) { gf_service_connect_ack(rtp->service, NULL, GF_URL_ERROR); } else { RP_LoadSDP(rtp, sdp_buf, sdp_size, stream); } gf_fclose(_sdp); gf_free(sdp_buf); }
static GF_Err gf_text_guess_format(char *filename, u32 *fmt) { char szLine[2048], szTest[10]; u32 val; FILE *test = gf_fopen(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; } gf_fclose(test); return GF_OK; }
/*type: 0: header, 1: source*/ FILE *BeginFile(u32 type) { FILE *f; char sPath[GF_MAX_PATH]; if (!type) { sprintf(sPath, "..%c..%c..%cinclude%cgpac%cnodes_x3d.h", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); } else { sprintf(sPath, "..%c..%c..%csrc%cscenegraph%cx3d_nodes.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); } f = gf_fopen(sPath, "wt"); fprintf(f, "%s\n", COPYRIGHT); { time_t rawtime; time(&rawtime); fprintf(f, "\n/*\n\tDO NOT MOFIFY - File generated on GMT %s\n\tBY X3DGen for GPAC Version %s\n*/\n\n", asctime(gmtime(&rawtime)), GPAC_VERSION); } if (!type) { fprintf(f, "#ifndef _GF_X3D_NODES_H\n"); fprintf(f, "#define _GF_X3D_NODES_H\n\n"); fprintf(f, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"); } return f; }
static GF_Err IMG_ConnectService(GF_InputService *plug, GF_ClientService *serv, const char *url) { char *sExt; IMGLoader *read = (IMGLoader *)plug->priv; read->service = serv; if (!url) return GF_BAD_PARAM; sExt = strrchr(url, '.'); if (!stricmp(sExt, ".jpeg") || !stricmp(sExt, ".jpg")) read->img_type = IMG_JPEG; else if (!stricmp(sExt, ".png")) read->img_type = IMG_PNG; else if (!stricmp(sExt, ".pngd")) read->img_type = IMG_PNGD; else if (!stricmp(sExt, ".pngds")) read->img_type = IMG_PNGDS; else if (!stricmp(sExt, ".pngs")) read->img_type = IMG_PNGS; else if (!stricmp(sExt, ".bmp")) read->img_type = IMG_BMP; if (read->dnload) gf_service_download_del(read->dnload); read->dnload = NULL; /*remote fetch*/ if (!jp_is_local(url)) { jp_download_file(plug, url); return GF_OK; } read->stream = gf_fopen(url, "rb"); if (read->stream) { gf_fseek(read->stream, 0, SEEK_END); read->data_size = (u32) gf_ftell(read->stream); gf_fseek(read->stream, 0, SEEK_SET); } gf_service_connect_ack(serv, NULL, read->stream ? GF_OK : GF_URL_ERROR); if (read->stream && read->is_inline) IMG_SetupObject(read); return GF_OK; }
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_fopen(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"); } gf_fclose(file); return GF_OK; }
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; /*try local*/ t = (strstr(kms_url, "://") == NULL) ? gf_fopen(kms_url, "r") : NULL; if (t) { gf_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_service_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_service_download_del(sess); return e; }
GF_EXPORT 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_fopen(outName, "wb"); if (!didfile) return GF_IO_ERR; gf_fwrite(xml->xml, xml->xml_length, 1, didfile); gf_fclose(didfile); if (is_binary) *is_binary = (xml->type==GF_ISOM_BOX_TYPE_BXML) ? 1 : 0; return GF_OK; }
static GF_Err AC3_ConnectService(GF_InputService *plug, GF_ClientService *serv, const char *url) { char szURL[2048]; char *ext; GF_Err reply; AC3Reader *read = (AC3Reader*)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_fopen(szURL, "rb"); if (!read->stream) { reply = GF_URL_ERROR; } else if (!AC3_ConfigureFromFile(read)) { gf_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; }
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 ((e==GF_EOS) && (param->msg_type==GF_NETIO_DATA_EXCHANGE)) 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 { if (read->stream) gf_fclose(read->stream); read->stream = gf_fopen((char *) szCache, "rb"); if (!read->stream) e = GF_SERVICE_ERROR; else { e = GF_OK; gf_fseek(read->stream, 0, SEEK_END); read->data_size = (u32) gf_ftell(read->stream); gf_fseek(read->stream, 0, SEEK_SET); } } } /*OK confirm*/ gf_service_connect_ack(read->service, NULL, e); if (!e) IMG_SetupObject(read); }
GF_EXPORT GF_Config *gf_cfg_init(const char *file, Bool *new_cfg) { GF_Config *cfg; char szPath[GF_MAX_PATH]; if (new_cfg) *new_cfg = GF_FALSE; if (file) { cfg = gf_cfg_new(NULL, file); /*force creation of a new config*/ if (!cfg) { FILE *fcfg = gf_fopen(file, "wt"); if (fcfg) { gf_fclose(fcfg); cfg = gf_cfg_new(NULL, file); if (new_cfg) *new_cfg = GF_TRUE; } } if (cfg) { check_modules_dir(cfg); return cfg; } } if (!get_default_install_path(szPath, GF_PATH_CFG)) { fprintf(stderr, "Fatal error: Cannot create a configuration file in application or user home directory - no write access\n"); return NULL; } cfg = gf_cfg_new(szPath, CFG_FILE_NAME); if (!cfg) { fprintf(stderr, "GPAC config file %s not found in %s - creating new file\n", CFG_FILE_NAME, szPath); cfg = create_default_config(szPath); } if (!cfg) { fprintf(stderr, "\nCannot create config file %s in %s directory\n", CFG_FILE_NAME, szPath); return NULL; } #ifndef GPAC_IPHONE fprintf(stderr, "Using config file in %s directory\n", szPath); #endif check_modules_dir(cfg); if (!gf_cfg_get_key(cfg, "General", "StorageDirectory")) { get_default_install_path(szPath, GF_PATH_CFG); strcat(szPath, "/Storage"); if (!gf_dir_exists(szPath)) gf_mkdir(szPath); gf_cfg_set_key(cfg, "General", "StorageDirectory", szPath); } if (new_cfg) *new_cfg = GF_TRUE; return cfg; }
GF_EXPORT Bool gf_file_exists(const char *fileName) { FILE *f = gf_fopen(fileName, "r"); if (f) { gf_fclose(f); return GF_TRUE; } return GF_FALSE; }
int main(int argc, char **argv) { char data[188]; u32 size, fsize, fdone; GF_M2TS_Demuxer *ts; FILE *src = gf_fopen(argv[1], "rb"); ts = gf_m2ts_demux_new(); ts->on_event = on_m2ts_event; fseek(src, 0, SEEK_END); fsize = ftell(src); fseek(src, 0, SEEK_SET); fdone = 0; while (!feof(src)) { size = fread(data, 1, 188, src); if (size<188) break; gf_m2ts_process_data(ts, data, size); if (has_seen_pat) break; } dest = gf_fopen("pes.mp3", "wb"); gf_m2ts_reset_parsers(ts); gf_fseek(src, 0, SEEK_SET); fdone = 0; while (!feof(src)) { size = fread(data, 1, 188, src); if (size<188) break; gf_m2ts_process_data(ts, data, size); fdone += size; gf_set_progress("MPEG-2 TS Parsing", fdone, fsize); } gf_set_progress("MPEG-2 TS Parsing", fsize, fsize); gf_fclose(src); gf_m2ts_demux_del(ts); if (dest) gf_fclose(dest); return 0; }
void write_bmp(GF_VideoSurface *fb, char *rad_name, u32 img_num) { char str[GF_MAX_PATH]; BITMAPFILEHEADER fh; BITMAPINFOHEADER fi; FILE *fout; u32 j, i; char *ptr; if (img_num<10) { sprintf(str, "%s_00%d.bmp", rad_name, img_num); } else if (img_num<100) { sprintf(str, "%s_0%d.bmp", rad_name, img_num); } else { sprintf(str, "%s_%d.bmp", rad_name, img_num); } fout = gf_fopen(str, "wb"); if (!fout) return; memset(&fh, 0, sizeof(fh)); fh.bfType = 19778; fh.bfOffBits = 14 + 40; memset(&fi, 0, sizeof(char)*40); fi.biSize = sizeof(char)*40; fi.biWidth = fb->width; fi.biHeight = fb->height; fi.biPlanes = 1; fi.biBitCount = 24; fi.biCompression = BI_RGB; fi.biSizeImage = fb->pitch * fb->height; /*NOT ALIGNED!!*/ gf_fwrite(&fh.bfType, 2, 1, fout); gf_fwrite(&fh.bfSize, 4, 1, fout); gf_fwrite(&fh.bfReserved1, 2, 1, fout); gf_fwrite(&fh.bfReserved2, 2, 1, fout); gf_fwrite(&fh.bfOffBits, 4, 1, fout); gf_fwrite(&fi, 1, 40, fout); for (j=fb->height; j>0; j--) { ptr = fb->video_buffer + (j-1)*fb->pitch; //gf_fwrite(ptr, 1, fb->width * 3, fout); for (i=0; i<fb->width; i++) { fputc(ptr[2], fout); fputc(ptr[1], fout); fputc(ptr[0], fout); ptr+=3; } } gf_fclose(fout); }
GF_EXPORT GF_Err gf_webvtt_dump_iso_track(GF_MediaExporter *dumper, char *szName, u32 track, Bool merge, Bool box_dump) { #ifdef GPAC_DISABLE_MEDIA_IMPORT return GF_NOT_SUPPORTED; #else GF_Err e; u32 i; u32 count; u32 timescale; FILE *out; u32 di; u64 duration; GF_WebVTTParser *parser; out = szName ? gf_fopen(szName, "wt") : (dumper->dump_file ? dumper->dump_file : 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; if (box_dump) fprintf(out, "<WebVTTTrack trackID=\"%d\">\n", gf_isom_get_track_id(dumper->file, track) ); e = gf_webvtt_dump_header(out, dumper->file, track, box_dump, 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, box_dump); if (e) { goto exit; } gf_isom_sample_del(&samp); } duration = gf_isom_get_media_duration(dumper->file, track); gf_webvtt_parser_dump_finalize(parser, duration); if (box_dump) fprintf(out, "</WebVTTTrack>\n"); exit: gf_webvtt_parser_del(parser); if (szName) gf_fclose(out); return e; #endif }
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_fopen(sdp_name, "wt"); fprintf(out, "%s", sdp); gf_fclose(out); gf_free(sdp); } }
/* Checks that the file is fully downloaded requires that the file_size is given in the DecoderSpecificInfo */ static Bool vtt_check_download(VTTDec *vttdec) { u64 size; FILE *f = gf_fopen(vttdec->file_name, "rt"); if (!f) return GF_FALSE; gf_fseek(f, 0, SEEK_END); size = gf_ftell(f); gf_fclose(f); if (size==vttdec->file_size) return GF_TRUE; return GF_FALSE; }
void wxPlaylist::OpenPlaylist(wxString filename) { FILE *pl; PLEntry *ple; Bool load_m3u, go; char szLine[GF_MAX_PATH]; pl = gf_fopen(filename.mb_str(wxConvUTF8) , "rt"); if (!pl) return; ple = NULL; load_m3u = 1; while (!feof(pl)) { fgets(szLine, GF_MAX_PATH, pl); go = 1; while (go) { switch (szLine[strlen(szLine)-1]) { case '\n': case '\r': case ' ': szLine[strlen(szLine)-1] = 0; break; default: go = 0; break; } } if (!strlen(szLine)) continue; if (!stricmp(szLine, "[playlist]")) { load_m3u = 0; } else if (load_m3u) { ple = new PLEntry(wxString(szLine, wxConvUTF8) ); gf_list_add(m_entries, ple); } else if (!strnicmp(szLine, "file", 4)) { char *st = strchr(szLine, '='); if (!st) ple = NULL; else { ple = new PLEntry(wxString(st + 1, wxConvUTF8) ); 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); } } gf_fclose(pl); m_all_dead_entries = -1; m_cur_entry = -1; RefreshList(); }
GF_EXPORT FILE *gf_temp_file_new(char ** const fileName) { FILE *res = NULL; #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)) res = _wfopen(pTemp, TEXT("w+b")); #elif defined(WIN32) res = tmpfile(); if (!res) { wchar_t tmp[MAX_PATH]; GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[Win32] system failure for tmpfile(): 0x%08x\n", GetLastError())); /*tmpfile() may fail under vista ...*/ if (GetEnvironmentVariableW(L"TEMP", tmp, MAX_PATH)) { wchar_t tmp2[MAX_PATH], *t_file; char* mbs_t_file; gf_rand_init(GF_FALSE); swprintf(tmp2, MAX_PATH, L"gpac_%d_%08x_", _getpid(), gf_rand()); t_file = _wtempnam(tmp, tmp2); mbs_t_file = wcs_to_utf8(t_file); if (!mbs_t_file) return 0; res = gf_fopen(mbs_t_file, "w+b"); if (res) { gpac_file_handles--; if (fileName) { *fileName = gf_strdup(mbs_t_file); } else { GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("[Win32] temporary file %s won't be deleted - contact the GPAC team\n", mbs_t_file)); } } gf_free(mbs_t_file); free(t_file); } } #else res = tmpfile(); #endif if (res) { gpac_file_handles++; } return res; }
void main(int argc, char **argv) { FILE *in; GF_BitStream *bs; /* generation d'un TS aléatoire */ /* if ((in=gf_fopen(argv[1], "wb")) == NULL) { printf( "Impossible d'ouvrir %s en lecture.\n", argv[1]); } { char buffer[188]; u32 j, i, nb_packets = 300; for (i = 0; i < nb_packets; i++) { buffer[0] = 0x47; for (j = 1; j <188; j++) { buffer[j] = rand();//j; } gf_fwrite(buffer, 1, 188, in); } } gf_fclose(in); if ((in=gf_fopen(argv[1], "rb")) == NULL) { printf( "Impossible d'ouvrir %s en lecture.\n", argv[1]); } bs = gf_bs_from_file(in, GF_BITSTREAM_READ); if (bs == NULL) return; RS_Interleaver(bs, argv[2]); gf_fclose(in); gf_bs_del(bs); */ if ((in=gf_fopen(argv[1], "rb")) == NULL) { printf( "Impossible d'ouvrir %s en lecture.\n", argv[1]); } bs = gf_bs_from_file(in, GF_BITSTREAM_READ); if (bs == NULL) return; RS_Deinterleaver(bs, argv[2]); gf_fclose(in); gf_bs_del(bs); }
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; GF_NetIOStatus 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_fopen((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 = (u32) 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; }
void write_raw(GF_VideoSurface *fb, char *rad_name, u32 img_num) { char str[GF_MAX_PATH]; FILE *fout; if (img_num<10) { sprintf(str, "%s_00%d.raw", rad_name, img_num); } else if (img_num<100) { sprintf(str, "%s_0%d.raw", rad_name, img_num); } else { sprintf(str, "%s_%d.raw", rad_name, img_num); } fout = gf_fopen(str, "wb"); if (!fout) return; gf_fwrite(fb->video_buffer , fb->height*fb->pitch, 1, fout); gf_fclose(fout); }
/*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_fopen(read->url, "rt"); gf_fseek(f, 0, SEEK_END); size = (u32) gf_ftell(f); gf_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; }
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_fopen(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) gf_fclose(out); return e; }
GF_EXPORT 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_fopen(XMLFileName, "rb"); if (!xmlfile) return GF_URL_ERROR; gf_fseek(xmlfile, 0, SEEK_END); assert(gf_ftell(xmlfile) < 1<<31); xml->xml_length = (u32) gf_ftell(xmlfile); gf_fseek(xmlfile, 0, SEEK_SET); xml->xml = (char*)gf_malloc(sizeof(unsigned char)*xml->xml_length); xml->xml_length = (u32) 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; } gf_fclose(xmlfile); return GF_OK; }
void wxPlaylist::Save(char *szPath, Bool save_m3u) { FILE *out = gf_fopen(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); if (ple->m_duration) fprintf(out, "Length%d=%d\n", i+1, ple->m_duration); else fprintf(out, "Length%d=-1\n", i+1); } } if (!save_m3u) fprintf(out, "Version=2\n"); fprintf(out, "\n"); gf_fclose(out); }
GF_EXPORT FILE *gf_temp_file_new() { FILE *res=NULL; #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)) res = _wfopen(pTemp, TEXT("w+b")); #elif defined(WIN32) char tmp[MAX_PATH]; res = tmpfile(); if (!res) { GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("[Win32] system failure for tmpfile(): 0x%08x\n", GetLastError())); /*tmpfile() may fail under vista ...*/ if (GetEnvironmentVariable("TEMP",tmp,MAX_PATH)) { char tmp2[MAX_PATH], *t_file; gf_rand_init(GF_FALSE); sprintf(tmp2, "gpac_%08x_", gf_rand()); t_file = tempnam(tmp, tmp2); res = gf_fopen(t_file, "w+b"); free(t_file); } } #else res = tmpfile(); #endif if (res) { gpac_file_handles++; } return res; }
GF_Err gf_webvtt_parser_init(GF_WebVTTParser *parser, const char *input_file, void *user, GF_Err (*report_message)(void *, GF_Err, char *, const char *), void (*on_sample_parsed)(void *, GF_WebVTTSample *), void (*on_header_parsed)(void *, const char *)) { const char *ext; if (parser) { parser->state = WEBVTT_PARSER_STATE_WAITING_SIGNATURE; ext = strrchr(input_file, '.'); if (ext) { ext++; if (!strcmp(ext, "srt")) { parser->is_srt = GF_TRUE; parser->state = WEBVTT_PARSER_STATE_WAITING_CUE; } } parser->vtt_in = gf_fopen(input_file, "rt"); gf_fseek(parser->vtt_in, 0, SEEK_END); parser->file_size = gf_ftell(parser->vtt_in); gf_fseek(parser->vtt_in, 0, SEEK_SET); parser->unicode_type = gf_text_get_utf_type(parser->vtt_in); if (parser->unicode_type<0) { gf_fclose(parser->vtt_in); return GF_NOT_SUPPORTED; } parser->user = user; parser->report_message = report_message; parser->on_sample_parsed = on_sample_parsed; parser->on_header_parsed = on_header_parsed; return GF_OK; } return GF_BAD_PARAM; }
static Bool CTXLoad_CheckDownload(CTXLoadPriv *priv) { u64 size; FILE *f; u32 now = gf_sys_clock(); if (!priv->file_size && (now - priv->last_check_time < 1000) ) return GF_FALSE; f = gf_fopen(priv->file_name, "rt"); if (!f) return GF_FALSE; gf_fseek(f, 0, SEEK_END); size = gf_ftell(f); gf_fclose(f); /*we MUST have a complete file for now ...*/ if (!priv->file_size) { if (priv->last_check_size == size) return GF_TRUE; priv->last_check_size = size; priv->last_check_time = now; } else { if (size==priv->file_size) return GF_TRUE; } return GF_FALSE; }