Beispiel #1
0
GF_InputService *NewM2TSReader()
{
    M2TSIn *reader;
    GF_InputService *plug = gf_malloc(sizeof(GF_InputService));
    memset(plug, 0, sizeof(GF_InputService));
    GF_REGISTER_MODULE_INTERFACE(plug, GF_NET_CLIENT_INTERFACE, "GPAC MPEG-2 TS Reader", "gpac distribution")

    plug->CanHandleURL = M2TS_CanHandleURL;
    plug->CanHandleURLInService = M2TS_CanHandleURLInService;
    plug->ConnectService = M2TS_ConnectService;
    plug->CloseService = M2TS_CloseService;
    plug->GetServiceDescriptor = M2TS_GetServiceDesc;
    plug->ConnectChannel = M2TS_ConnectChannel;
    plug->DisconnectChannel = M2TS_DisconnectChannel;
    plug->ServiceCommand = M2TS_ServiceCommand;
    plug->RegisterMimeTypes = M2TS_RegisterMimeTypes;

    reader = gf_malloc(sizeof(M2TSIn));
    memset(reader, 0, sizeof(M2TSIn));
    plug->priv = reader;
    reader->ts = gf_m2ts_demux_new();
    reader->ts->on_event = M2TS_OnEvent;
    reader->ts->user = reader;
    reader->ts->demux_and_play = 1;
    reader->ts->th = gf_th_new("MPEG-2 TS Demux");

    reader->mx = gf_mx_new("MPEG2 Demux");

    return plug;
}
Beispiel #2
0
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;
}
Beispiel #3
0
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;
}