Пример #1
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 ((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);
}
Пример #2
0
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 = fopen(url, "rb");
    if (read->stream) {
        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);
    }
    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;
}