예제 #1
0
파일: read.c 프로젝트: supperlitt/gpac
GF_Err ISOR_ConnectService(GF_InputService *plug, GF_ClientService *serv, const char *url)
{
    char szURL[2048];
    char *tmp;
    ISOMReader *read;
    if (!plug || !plug->priv || !serv) return GF_SERVICE_ERROR;
    read = (ISOMReader *) plug->priv;

    read->input = plug;
    read->service = serv;

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

    read->base_track_id = 0;
    strcpy(szURL, url);
    tmp = strrchr(szURL, '.');
    if (tmp) {
        tmp = strchr(tmp, '#');
        if (tmp) {
            if (!strnicmp(tmp, "#trackID=", 9)) {
                read->base_track_id = atoi(tmp+9);
            } else {
                read->base_track_id = atoi(tmp+1);
            }
            tmp[0] = 0;
        }
    }

    if (isor_is_local(szURL)) {
        GF_Err e;
        u64 start_range, end_range;
        start_range = end_range = 0;
        if (plug->query_proxy) {
            GF_NetworkCommand param;
            param.command_type = GF_NET_SERVICE_QUERY_INIT_RANGE;
            if (read->input->query_proxy(read->input, &param)==GF_OK) {
                start_range = param.url_query.start_range;
                end_range = param.url_query.end_range;
            }
        }
        e = gf_isom_open_progressive(szURL, start_range, end_range, &read->mov, &read->missing_bytes);
        if (e != GF_OK) {
            GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[IsoMedia] : error while opening %s, error=%s\n", szURL, gf_error_to_string(e)));
            gf_term_on_connect(serv, NULL, e);
            return GF_OK;
        }
        read->frag_type = gf_isom_is_fragmented(read->mov) ? 1 : 0;

        read->time_scale = gf_isom_get_timescale(read->mov);
        /*reply to user*/
        gf_term_on_connect(serv, NULL, GF_OK);
        if (read->no_service_desc) isor_declare_objects(read);
    } else {
        /*setup downloader*/
        isor_setup_download(plug, szURL);
    }
    return GF_OK;
}
예제 #2
0
파일: read.c 프로젝트: supperlitt/gpac
void isor_net_io(void *cbk, GF_NETIO_Parameter *param)
{
    GF_Err e;
    u32 size = 0;
    char *local_name;
    ISOMReader *read = (ISOMReader *) cbk;

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

    if (param->msg_type==GF_NETIO_DATA_TRANSFERED) {
        e = GF_EOS;
    } else if (param->msg_type==GF_NETIO_DATA_EXCHANGE) {
        e = GF_OK;
        size = param->size;
    } else {
        e = param->error;
    }

    if (e<GF_OK) {
        /*error opening service*/
        if (!read->mov) gf_term_on_connect(read->service, NULL, e);
        return;
    }

    /*open file if not done yet (bad interleaving)*/
    if (e==GF_EOS) {
        const char *local_name;
        if (read->mov) return;
        local_name = gf_dm_sess_get_cache_name(read->dnload);
        if (!local_name) {
            gf_term_on_connect(read->service, NULL, GF_SERVICE_ERROR);
            return;
        }
        e = GF_OK;
        read->mov = gf_isom_open(local_name, GF_ISOM_OPEN_READ, NULL);
        if (!read->mov) e = gf_isom_last_error(NULL);
        else read->time_scale = gf_isom_get_timescale(read->mov);
        gf_term_on_connect(read->service, NULL, GF_OK);
        if (read->no_service_desc) isor_declare_objects(read);
    }

    if (!size) return;

    /*service is opened, nothing to do*/
    if (read->mov) return;

    /*try to open the service*/
    local_name = (char *)gf_dm_sess_get_cache_name(read->dnload);
    if (!local_name) {
        gf_term_on_connect(read->service, NULL, GF_SERVICE_ERROR);
        return;
    }

    /*not enogh data yet*/
    if (read->missing_bytes && (read->missing_bytes > size) ) {
        read->missing_bytes -= size;
        return;
    }

    e = gf_isom_open_progressive(local_name, 0, 0, &read->mov, &read->missing_bytes);
    switch (e) {
    case GF_ISOM_INCOMPLETE_FILE:
        return;
    case GF_OK:
        break;
    default:
        gf_term_on_connect(read->service, NULL, e);
        return;
    }
    read->frag_type = gf_isom_is_fragmented(read->mov) ? 1 : 0;

    /*ok let's go*/
    read->time_scale = gf_isom_get_timescale(read->mov);
    gf_term_on_connect(read->service, NULL, GF_OK);
    if (read->no_service_desc) isor_declare_objects(read);
}
예제 #3
0
파일: read.c 프로젝트: dragonlucian/gpac
void isor_net_io(void *cbk, GF_NETIO_Parameter *param)
{
	GF_Err e;
	u32 size = 0;
	char *local_name;
	ISOMReader *read = (ISOMReader *) cbk;

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

	if (param->msg_type==GF_NETIO_DATA_TRANSFERED) {
		e = GF_EOS;
	} else if (param->msg_type==GF_NETIO_DATA_EXCHANGE) {
		e = GF_OK;
		size = param->size;
	} else {
		e = param->error;
	}

	if (e<GF_OK) {
		/*error opening service*/
		if (!read->mov) {
			/* if there is an intermediate between this module and the terminal, report to it */
			if (read->input->query_proxy && read->input->proxy_udta && read->input->proxy_type) {
				send_proxy_command(read, GF_FALSE, GF_FALSE, e, NULL, NULL);
			} else {
				gf_service_connect_ack(read->service, NULL, e);
			}
		}
		return;
	}

	/*open file if not done yet (bad interleaving)*/
	if (e==GF_EOS) {
		const char *local_name;
		if (read->mov) return;
		local_name = gf_dm_sess_get_cache_name(read->dnload);
		if (!local_name) {
			if (read->input->query_proxy && read->input->proxy_udta && read->input->proxy_type) {
				send_proxy_command(read, GF_FALSE, GF_FALSE, GF_SERVICE_ERROR, NULL, NULL);
			} else {
				gf_service_connect_ack(read->service, NULL, GF_SERVICE_ERROR);
			}
			return;
		}
		e = GF_OK;
		read->mov = gf_isom_open(local_name, GF_ISOM_OPEN_READ, NULL);
		if (!read->mov) e = gf_isom_last_error(NULL);
		else read->time_scale = gf_isom_get_timescale(read->mov);
		read->frag_type = gf_isom_is_fragmented(read->mov) ? 1 : 0;
		if (read->input->query_proxy && read->input->proxy_udta && read->input->proxy_type) {
			send_proxy_command(read, GF_FALSE, GF_FALSE, GF_OK, NULL, NULL);
		} else {
			gf_service_connect_ack(read->service, NULL, GF_OK);
		}
		if (read->no_service_desc) isor_declare_objects(read);
	}

	if (!size) return;

	/*service is opened, nothing to do*/
	if (read->mov) {
		isor_check_buffer_level(read);

		/*end of chunk*/
		if (read->frag_type && (param->reply==1) ) {
			u64 bytesMissing = 0;
			gf_mx_p(read->segment_mutex);
			e = gf_isom_refresh_fragmented(read->mov, &bytesMissing, NULL);
			gf_mx_v(read->segment_mutex);
		}
		return;
	}

	/*try to open the service*/
	local_name = (char *)gf_dm_sess_get_cache_name(read->dnload);
	if (!local_name) {
		if (read->input->query_proxy && read->input->proxy_udta && read->input->proxy_type) {
			send_proxy_command(read, GF_FALSE, GF_FALSE, GF_SERVICE_ERROR, NULL, NULL);
		} else {
			gf_service_connect_ack(read->service, NULL, GF_SERVICE_ERROR);
		}
		return;
	}

	/*not enogh data yet*/
	if (read->missing_bytes && (read->missing_bytes > size) ) {
		read->missing_bytes -= size;
		return;
	}

	e = gf_isom_open_progressive(local_name, 0, 0, &read->mov, &read->missing_bytes);
	switch (e) {
	case GF_ISOM_INCOMPLETE_FILE:
		return;
	case GF_OK:
		break;
	default:
		if (read->input->query_proxy && read->input->proxy_udta && read->input->proxy_type) {
			send_proxy_command(read, GF_FALSE, GF_FALSE, e, NULL, NULL);
		} else {
			gf_service_connect_ack(read->service, NULL, e);
		}
		return;
	}
	read->frag_type = gf_isom_is_fragmented(read->mov) ? 1 : 0;

	/*ok let's go, we can setup the decoders */
	read->time_scale = gf_isom_get_timescale(read->mov);
	if (read->input->query_proxy && read->input->proxy_udta && read->input->proxy_type) {
		send_proxy_command(read, GF_FALSE, GF_FALSE, GF_OK, NULL, NULL);
	} else {
		gf_service_connect_ack(read->service, NULL, GF_OK);
	}

	if (read->no_service_desc) isor_declare_objects(read);
}