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; }
void DC_DownloadFile(GF_InputService *plug, char *url) { DCReader *read = (DCReader *) plug->priv; read->dnload = gf_service_download_new(read->service, url, 0, DC_NetIO, read); if (!read->dnload) { gf_service_connect_ack(read->service, NULL, GF_NOT_SUPPORTED); } else { /*start our download (threaded)*/ gf_dm_sess_process(read->dnload); } }
void jp_download_file(GF_InputService *plug, const char *url) { IMGLoader *read = (IMGLoader *) plug->priv; read->dnload = gf_service_download_new(read->service, url, 0, IMG_NetIO, read); if (!read->dnload) { gf_service_connect_ack(read->service, NULL, GF_NOT_SUPPORTED); } else { /*start our download (threaded)*/ gf_dm_sess_process(read->dnload); } /*service confirm is done once fetched*/ }
GF_DASHFileIOSession mpdin_dash_io_create(GF_DASHFileIO *dashio, Bool persistent, const char *url, s32 group_idx) { GF_MPDGroup *group = NULL; GF_DownloadSession *sess; u32 flags = GF_NETIO_SESSION_NOT_THREADED; GF_MPD_In *mpdin = (GF_MPD_In *)dashio->udta; if (mpdin->memory_storage) flags |= GF_NETIO_SESSION_MEMORY_CACHE; if (persistent) flags |= GF_NETIO_SESSION_PERSISTENT; if (group_idx>=0) { group = gf_dash_get_group_udta(mpdin->dash, group_idx); } if (group) { group->netio_assigned = GF_TRUE; group->sess = sess = gf_service_download_new(mpdin->service, url, flags, mpdin_dash_segment_netio, group); } else { sess = gf_service_download_new(mpdin->service, url, flags, NULL, NULL); } return (GF_DASHFileIOSession ) sess; }
static void SAF_DownloadFile(GF_InputService *plug, char *url) { SAFIn *read = (SAFIn*) plug->priv; read->dnload = gf_service_download_new(read->service, url, 0, SAF_NetIO, read); if (!read->dnload) { read->needs_connection = 0; gf_service_connect_ack(read->service, NULL, GF_NOT_SUPPORTED); } else { /*start our download (threaded)*/ gf_dm_sess_process(read->dnload); } /*service confirm is done once fetched*/ }
void ac3_download_file(GF_InputService *plug, char *url) { AC3Reader *read = (AC3Reader*) plug->priv; read->needs_connection = GF_TRUE; read->dnload = gf_service_download_new(read->service, url, 0, AC3_NetIO, read); if (!read->dnload ) { read->needs_connection = GF_FALSE; gf_service_connect_ack(read->service, NULL, GF_NOT_SUPPORTED); } else { /*start our download (threaded)*/ gf_dm_sess_process(read->dnload); } /*service confirm is done once fetched*/ }
void VTT_download_file(GF_InputService *plug, const char *url) { VTTIn *vttin = (VTTIn *) plug->priv; if (!plug || !url) return; vttin->needs_connection = GF_TRUE; vttin->dnload = gf_service_download_new(vttin->service, url, 0, VTT_NetIO, plug); if (!vttin->dnload) { vttin->needs_connection = GF_FALSE; gf_service_connect_ack(vttin->service, NULL, GF_NOT_SUPPORTED); } else { /*start our download (threaded)*/ gf_dm_sess_process(vttin->dnload); } /*service confirm is done once fetched*/ }
void isor_setup_download(GF_InputService *plug, const char *url) { ISOMReader *read = (ISOMReader *) plug->priv; read->dnload = gf_service_download_new(read->service, url, 0, isor_net_io, read); if (!read->dnload) { if (read->input->query_proxy && read->input->proxy_udta && read->input->proxy_type) { send_proxy_command(read, GF_FALSE, GF_FALSE, GF_NOT_SUPPORTED, NULL, NULL); } else { gf_service_connect_ack(read->service, NULL, GF_NOT_SUPPORTED); } } else { /*start our download (threaded)*/ gf_dm_sess_process(read->dnload); } /*service confirm is done once IOD can be fetched*/ }
void RP_FetchSDP(RTPClient *rtp, char *url, RTPStream *stream, char *original_url) { SDPFetch *sdp; /*if local URL get file*/ if (strstr(url, "data:application/sdp")) { RP_SDPFromData(rtp, url, stream); return; } if (!strnicmp(url, "file://", 7) || !strstr(url, "://")) { RP_SDPFromFile(rtp, url, stream); return; } sdp = (SDPFetch*)gf_malloc(sizeof(SDPFetch)); memset(sdp, 0, sizeof(SDPFetch)); sdp->client = rtp; sdp->remote_url = gf_strdup(url); sdp->chan = stream; if (original_url) { sdp->original_url = gf_strdup(original_url); } /*otherwise setup download*/ if (rtp->dnload) gf_service_download_del(rtp->dnload); rtp->dnload = NULL; rtp->sdp_temp = sdp; rtp->dnload = gf_service_download_new(rtp->service, url, 0, SDP_NetIO, rtp); if (!rtp->dnload) { gf_service_connect_ack(rtp->service, NULL, GF_NOT_SUPPORTED); } else { /*start our download (threaded)*/ gf_dm_sess_process(rtp->dnload); } /*service confirm is done once fetched*/ }
static GF_Err FFD_ConnectService(GF_InputService *plug, GF_ClientService *serv, const char *url) { GF_Err e; s64 last_aud_pts; u32 i; s32 res; Bool is_local; const char *sOpt; char *ext, szName[1024]; FFDemux *ffd = plug->priv; AVInputFormat *av_in = NULL; char szExt[20]; if (ffd->ctx) return GF_SERVICE_ERROR; assert( url && strlen(url) < 1024); strcpy(szName, url); ext = strrchr(szName, '#'); ffd->service_type = 0; e = GF_NOT_SUPPORTED; ffd->service = serv; if (ext) { if (!stricmp(&ext[1], "video")) ffd->service_type = 1; else if (!stricmp(&ext[1], "audio")) ffd->service_type = 2; ext[0] = 0; } /*some extensions not supported by ffmpeg, overload input format*/ ext = strrchr(szName, '.'); strcpy(szExt, ext ? ext+1 : ""); strlwr(szExt); if (!strcmp(szExt, "cmp")) av_in = av_find_input_format("m4v"); is_local = (strnicmp(url, "file://", 7) && strstr(url, "://")) ? 0 : 1; GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[FFMPEG] opening file %s - local %d - av_in %08x\n", url, is_local, av_in)); if (!is_local) { AVProbeData pd; /*setup wraper for FFMPEG I/O*/ ffd->buffer_size = 8192; sOpt = gf_modules_get_option((GF_BaseInterface *)plug, "FFMPEG", "IOBufferSize"); if (sOpt) ffd->buffer_size = atoi(sOpt); ffd->buffer = gf_malloc(sizeof(char)*ffd->buffer_size); #ifdef FFMPEG_DUMP_REMOTE ffd->outdbg = gf_f64_open("ffdeb.raw", "wb"); #endif #ifdef USE_PRE_0_7 init_put_byte(&ffd->io, ffd->buffer, ffd->buffer_size, 0, ffd, ff_url_read, NULL, NULL); ffd->io.is_streamed = 1; #else ffd->io.seekable = 1; #endif ffd->dnload = gf_service_download_new(ffd->service, url, GF_NETIO_SESSION_NOT_THREADED | GF_NETIO_SESSION_NOT_CACHED, NULL, ffd); if (!ffd->dnload) return GF_URL_ERROR; while (1) { u32 read; e = gf_dm_sess_fetch_data(ffd->dnload, ffd->buffer + ffd->buffer_used, ffd->buffer_size - ffd->buffer_used, &read); if (e==GF_EOS) break; /*we're sync!!*/ if (e==GF_IP_NETWORK_EMPTY) continue; if (e) goto err_exit; ffd->buffer_used += read; if (ffd->buffer_used == ffd->buffer_size) break; } if (e==GF_EOS) { const char *cache_file = gf_dm_sess_get_cache_name(ffd->dnload); res = open_file(&ffd->ctx, cache_file, av_in); } else { pd.filename = szName; pd.buf_size = ffd->buffer_used; pd.buf = (u8 *) ffd->buffer; av_in = av_probe_input_format(&pd, 1); if (!av_in) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[FFMPEG] error probing file %s - probe start with %c %c %c %c\n", url, ffd->buffer[0], ffd->buffer[1], ffd->buffer[2], ffd->buffer[3])); return GF_NOT_SUPPORTED; } /*setup downloader*/ av_in->flags |= AVFMT_NOFILE; #ifdef USE_AVFORMAT_OPEN_INPUT /*commit ffmpeg 603b8bc2a109978c8499b06d2556f1433306eca7*/ res = avformat_open_input(&ffd->ctx, szName, av_in, NULL); #else res = av_open_input_stream(&ffd->ctx, &ffd->io, szName, av_in, NULL); #endif } } else { res = open_file(&ffd->ctx, szName, av_in); } switch (res) { #ifndef _WIN32_WCE case 0: e = GF_OK; break; case AVERROR_IO: e = GF_URL_ERROR; goto err_exit; case AVERROR_INVALIDDATA: e = GF_NON_COMPLIANT_BITSTREAM; goto err_exit; case AVERROR_NOMEM: e = GF_OUT_OF_MEM; goto err_exit; case AVERROR_NOFMT: e = GF_NOT_SUPPORTED; goto err_exit; #endif default: e = GF_SERVICE_ERROR; goto err_exit; } GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[FFMPEG] looking for streams in %s - %d streams - type %s\n", ffd->ctx->filename, ffd->ctx->nb_streams, ffd->ctx->iformat->name)); res = av_find_stream_info(ffd->ctx); if (res <0) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[FFMPEG] cannot locate streams - error %d\n", res)); e = GF_NOT_SUPPORTED; goto err_exit; } GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[FFMPEG] file %s opened - %d streams\n", url, ffd->ctx->nb_streams)); /*figure out if we can use codecs or not*/ ffd->audio_st = ffd->video_st = -1; for (i = 0; i < ffd->ctx->nb_streams; i++) { AVCodecContext *enc = ffd->ctx->streams[i]->codec; switch(enc->codec_type) { case AVMEDIA_TYPE_AUDIO: if ((ffd->audio_st<0) && (ffd->service_type!=1)) { ffd->audio_st = i; ffd->audio_tscale = ffd->ctx->streams[i]->time_base; } break; case AVMEDIA_TYPE_VIDEO: if ((ffd->video_st<0) && (ffd->service_type!=2)) { ffd->video_st = i; ffd->video_tscale = ffd->ctx->streams[i]->time_base; } break; default: break; } } if ((ffd->service_type==1) && (ffd->video_st<0)) goto err_exit; if ((ffd->service_type==2) && (ffd->audio_st<0)) goto err_exit; if ((ffd->video_st<0) && (ffd->audio_st<0)) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[FFMPEG] No supported streams in file\n")); goto err_exit; } sOpt = gf_modules_get_option((GF_BaseInterface *)plug, "FFMPEG", "DataBufferMS"); ffd->data_buffer_ms = 0; if (sOpt) ffd->data_buffer_ms = atoi(sOpt); if (!ffd->data_buffer_ms) ffd->data_buffer_ms = FFD_DATA_BUFFER; /*build seek*/ if (is_local) { /*check we do have increasing pts. If not we can't rely on pts, we must skip SL we assume video pts is always present*/ if (ffd->audio_st>=0) { last_aud_pts = 0; for (i=0; i<20; i++) { AVPacket pkt; pkt.stream_index = -1; if (av_read_frame(ffd->ctx, &pkt) <0) break; if (pkt.pts == AV_NOPTS_VALUE) pkt.pts = pkt.dts; if (pkt.stream_index==ffd->audio_st) last_aud_pts = pkt.pts; } if (last_aud_pts*ffd->audio_tscale.den<10*ffd->audio_tscale.num) ffd->unreliable_audio_timing = 1; } ffd->seekable = (av_seek_frame(ffd->ctx, -1, 0, AVSEEK_FLAG_BACKWARD)<0) ? 0 : 1; if (!ffd->seekable) { #ifndef FF_API_CLOSE_INPUT_FILE av_close_input_file(ffd->ctx); #else avformat_close_input(&ffd->ctx); #endif ffd->ctx = NULL; open_file(&ffd->ctx, szName, av_in); av_find_stream_info(ffd->ctx); } } /*let's go*/ gf_service_connect_ack(serv, NULL, GF_OK); /*if (!ffd->service_type)*/ FFD_SetupObjects(ffd); ffd->service_type = 0; return GF_OK; err_exit: GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[FFMPEG] Error opening file %s: %s\n", url, gf_error_to_string(e))); #ifndef FF_API_CLOSE_INPUT_FILE if (ffd->ctx) av_close_input_file(ffd->ctx); #else if (ffd->ctx) avformat_close_input(&ffd->ctx); #endif ffd->ctx = NULL; gf_service_connect_ack(serv, NULL, e); return GF_OK; }