Пример #1
0
GF_EXPORT
void gf_service_download_update_stats(GF_DownloadSession * sess)
{
	GF_ClientService *serv;
	const char *szURI;
	u32 total_size, bytes_done, bytes_per_sec;
	GF_NetIOStatus net_status;

	if (!sess) return;

	gf_dm_sess_get_stats(sess, NULL, &szURI, &total_size, &bytes_done, &bytes_per_sec, &net_status);
	serv = (GF_ClientService *)gf_dm_sess_get_private(sess);
	switch (net_status) {
	case GF_NETIO_SETUP:
		gf_term_message(serv->term, serv->url, "Connecting", GF_OK);
		break;
	case GF_NETIO_CONNECTED:
		gf_term_message(serv->term, serv->url, "Connected", GF_OK);
		break;
	case GF_NETIO_WAIT_FOR_REPLY:
		gf_term_message(serv->term, serv->url, "Waiting for reply...", GF_OK);
		break;
	case GF_NETIO_PARSE_REPLY:
		gf_term_message(serv->term, serv->url, "Starting download...", GF_OK);
		break;
	case GF_NETIO_DATA_EXCHANGE:
		/*notify some connection / ...*/
		if (total_size) {
			GF_Event evt;
			evt.type = GF_EVENT_PROGRESS;
			evt.progress.progress_type = 1;
			evt.progress.service = szURI;
			evt.progress.total = total_size;
			evt.progress.done = bytes_done;
			evt.progress.bytes_per_seconds = bytes_per_sec;
			gf_term_send_event(serv->term, &evt);
		}
		GF_LOG(GF_LOG_DEBUG, GF_LOG_NETWORK, ("[HTTP] %s received %d / %d\n", szURI, bytes_done, total_size));
		gf_term_service_media_event_with_download(serv->owner, GF_EVENT_MEDIA_PROGRESS, bytes_done, total_size, bytes_per_sec);
		break;
	case GF_NETIO_DATA_TRANSFERED:
		gf_term_service_media_event(serv->owner, GF_EVENT_MEDIA_LOAD_DONE);
		if (serv->owner && !(serv->owner->flags & GF_ODM_DESTROYED) && serv->owner->duration) {
			GF_Clock *ck = gf_odm_get_media_clock(serv->owner);
			if (!gf_clock_is_started(ck)) {
				GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[HTTP Resource] Done retrieving file - resuming playback\n"));
				if (serv->is_paused) {
					serv->is_paused = 0;
#ifndef GPAC_DISABLE_VRML
					mediacontrol_resume(serv->owner, 0);
#endif
				}
			}
		}
		break;
	default:
		break;
	}
}
Пример #2
0
GF_EXPORT
void gf_term_download_update_stats(GF_DownloadSession * sess)
{
	GF_ClientService *serv;
	const char *szURI;
	u32 total_size, bytes_done, net_status, bytes_per_sec;

	if (!sess) return;

	gf_dm_sess_get_stats(sess, NULL, &szURI, &total_size, &bytes_done, &bytes_per_sec, &net_status);
	serv = (GF_ClientService *)gf_dm_sess_get_private(sess);
	switch (net_status) {
	case GF_NETIO_SETUP:
		gf_term_on_message(serv, GF_OK, "Connecting");
		break;
	case GF_NETIO_CONNECTED:
		gf_term_on_message(serv, GF_OK, "Connected");
		break;
	case GF_NETIO_WAIT_FOR_REPLY:
		gf_term_on_message(serv, GF_OK, "Waiting for reply...");
		break;
	case GF_NETIO_PARSE_REPLY:
		gf_term_on_message(serv, GF_OK, "Starting download...");
		break;
	case GF_NETIO_DATA_EXCHANGE:
		/*notify some connection / ...*/
		if (total_size) {
			GF_Event evt;
			evt.type = GF_EVENT_PROGRESS;
			evt.progress.progress_type = 1;
			evt.progress.service = szURI;
			evt.progress.total = total_size;
			evt.progress.done = bytes_done;
			evt.progress.bytes_per_seconds = bytes_per_sec;
			gf_term_send_event(serv->term, &evt);
		}
		GF_LOG(GF_LOG_DEBUG, GF_LOG_NETWORK, ("[HTTP] %s received %d / %d\n", szURI, bytes_done, total_size));
		gf_term_service_media_event_with_download(serv->owner, GF_EVENT_MEDIA_PROGRESS, bytes_done, total_size, bytes_per_sec);

		/*JLF fix this*/
		if (0&& (serv->download_rebuffer || serv->auto_rebuffer) && serv->owner && !(serv->owner->flags & GF_ODM_DESTROYED) && serv->owner->duration) {
			GF_Clock *ck = gf_odm_get_media_clock(serv->owner);
			Double download_percent, playback_percent, adj_percent;
			download_percent = 100 * bytes_done;
			download_percent /= total_size;

			playback_percent = 100 * serv->owner->current_time;
			playback_percent /= serv->owner->duration;
			if (serv->auto_rebuffer)
				adj_percent = 0.0;
			else
				adj_percent = 100.0 * serv->download_rebuffer / serv->owner->duration;

			if (playback_percent >= download_percent) {
				if (gf_clock_is_started(ck)) {
					GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[HTTP Resource] Played %d %% but downloaded %d %% - Pausing\n", (u32) playback_percent, (u32) download_percent));
					if (!serv->is_paused) {
						serv->is_paused = 1;
						mediacontrol_pause(serv->owner);
					}
					gf_term_service_media_event(serv->owner, GF_EVENT_MEDIA_WAITING);
					gf_term_on_message(serv, GF_OK, "HTTP Buffering ...");
				}
			} else if (playback_percent + adj_percent <= download_percent) {
				Double time_to_play = 0;
				Double time_to_download = 0;
				/*automatic rebuffer: make sure we can finish playback before resuming*/
				if (serv->auto_rebuffer) {
					if (bytes_per_sec) {
						time_to_download = 1000.0*(total_size - bytes_done);
						time_to_download /= bytes_per_sec;
					}
					time_to_play = (Double) serv->owner->duration;
					time_to_play -= serv->owner->current_time;
				}
				if ((time_to_download<=time_to_play) && !gf_clock_is_started(ck)) {
					GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[HTTP Resource] Played %d %% and downloaded %d %% - Resuming\n", (u32) playback_percent, (u32) download_percent));
					if (serv->auto_rebuffer) {
						GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[HTTP Resource] Auto-rebuffer done: should be done downloading in %d ms and remains %d ms to play\n", (u32) time_to_download, (u32) (serv->owner->duration - serv->owner->current_time) ));
					}
					gf_term_service_media_event(serv->owner, GF_EVENT_MEDIA_PLAYING);
					if (serv->is_paused) {
						serv->is_paused = 0;
						mediacontrol_resume(serv->owner);
					}
					gf_term_on_message(serv, GF_OK, "HTTP Resuming playback");
				}
			}
		}
		break;
	case GF_NETIO_DATA_TRANSFERED:
		gf_term_service_media_event(serv->owner, GF_EVENT_MEDIA_LOAD_DONE);
		if (serv->owner && !(serv->owner->flags & GF_ODM_DESTROYED) && serv->owner->duration) {
			GF_Clock *ck = gf_odm_get_media_clock(serv->owner);
			if (!gf_clock_is_started(ck)) {
				GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[HTTP Resource] Done retrieving file - resuming playback\n"));
				if (serv->is_paused) {
					serv->is_paused = 0;
					mediacontrol_resume(serv->owner);
				}
			}
		}
		break;
	}
}