Ejemplo n.º 1
0
void m2ts_net_io(void *cbk, GF_NETIO_Parameter *param)
{
    GF_Err e;
    M2TSIn *m2ts = (M2TSIn *) cbk;
    assert( m2ts );
    /*handle service message*/
    gf_term_download_update_stats(m2ts->ts->dnload);

    if (param->msg_type==GF_NETIO_DATA_TRANSFERED) {
        e = GF_EOS;
    } else if (param->msg_type==GF_NETIO_DATA_EXCHANGE) {
        e = GF_OK;
        assert( m2ts->ts);
        if (param->size > 0) {
            /*process chunk*/
            assert(param->data);
            if (m2ts->network_buffer_size < param->size) {
                m2ts->network_buffer = gf_realloc(m2ts->network_buffer, sizeof(char) * param->size);
                m2ts->network_buffer_size = param->size;
            }
            assert( m2ts->network_buffer );
            memcpy(m2ts->network_buffer, param->data, param->size);
            gf_m2ts_process_data(m2ts->ts, m2ts->network_buffer, param->size);
        }

        /*if asked to regulate, wait until we get a play request*/
        if (m2ts->ts->run_state && !m2ts->ts->nb_playing && m2ts->ts->file_regulate) {
            while (m2ts->ts->run_state && !m2ts->ts->nb_playing && m2ts->ts->file_regulate) {
                gf_sleep(50);
                continue;
            }
        } else {
            gf_sleep(1);
        }
        if (!m2ts->ts->run_state) {
            if (m2ts->ts->dnload)
                gf_term_download_del( m2ts->ts->dnload );
            m2ts->ts->dnload = NULL;
        }

    } else {
        e = param->error;
    }

    switch (e) {
    case GF_EOS:
        if (!m2ts->is_connected) {
            gf_term_on_connect(m2ts->service, NULL, GF_OK);
        }
        return;
    case GF_OK:
        return;
    default:
        if (!m2ts->ts_setup) {
            m2ts->ts_setup = 1;
        }
        GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER,("[MPEGTSIn] : Error while getting data : %s\n", gf_error_to_string(e)));
        gf_term_on_connect(m2ts->service, NULL, e);
    }
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: Bevara/GPAC
int main(int argc, char **argv)
{
	u8 data[188];
	u32 size;
	MPEDemux *mpedemux;

	if (argc < 2) {
		usage();
		return GF_OK;
	}

	GF_SAFEALLOC(mpedemux, MPEDemux);
	mpedemux->ts_demux = gf_m2ts_demux_new();
	mpedemux->ts_demux->on_event = mpedemux_on_event;
	mpedemux->ts_demux->user = mpedemux;

	mpedemux->ts_file = fopen(argv[1], "rb");

	while (1) {
		/*read chunks by chunks*/
		size = fread(data, 1, 188, mpedemux->ts_file);
		if (!size) break;
		/*process chunk*/
		gf_m2ts_process_data(mpedemux->ts_demux, data, size);
	}

	gf_m2ts_demux_del(mpedemux->ts_demux);
	gf_free(mpedemux);
	return GF_OK;
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: ARSekkat/gpac
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;
}