示例#1
0
/* Create a title and get PID's by scanning first few bytes. */
int mpeg3_create_title(mpeg3_demuxer_t *demuxer, 
	FILE *toc)
{
	int result = 0, done = 0, counter_start, counter;
	mpeg3_t *file = demuxer->file;
	int64_t next_byte, prev_byte;
	double next_time, prev_time, absolute_time;
	long i;
	mpeg3_title_t *title;
	u_int32_t test_header = 0;

	demuxer->error_flag = 0;
	demuxer->read_all = 1;

/* Create a single title */
	if(!demuxer->total_titles)
	{
		demuxer->titles[0] = mpeg3_new_title(file, file->fs->path);
		demuxer->total_titles = 1;
		mpeg3demux_open_title(demuxer, 0);
	}

	title = demuxer->titles[0];
	title->total_bytes = mpeg3io_total_bytes(title->fs);
	title->start_byte = 0;
	title->end_byte = title->total_bytes;

// Create default cell
	mpeg3_new_cell(title, 
		0, 
		title->end_byte,
		0,
		title->end_byte,
		0);


/* Get PID's and tracks */
	if(file->is_transport_stream || file->is_program_stream)
	{
		mpeg3io_seek(title->fs, 0);
		while(!done && !result && !mpeg3io_eof(title->fs))
		{
			next_byte = mpeg3io_tell(title->fs);
			result = mpeg3_read_next_packet(demuxer);

/* Just get the first bytes if not building a toc to get the stream ID's. */
			if(next_byte > 0x1000000 && !toc) done = 1;
		}
	}

	mpeg3io_seek(title->fs, 0);
	demuxer->read_all = 0;
	return 0;
}
示例#2
0
int mpeg3_read_toc(mpeg3_t *file)
{
	char string[MPEG3_STRLEN];
	int version;

/* Test version number */
	mpeg3io_seek(file->fs, 0);
	fscanf(file->fs->fd, "%s %d", string, &version);
	if(version != TOCVERSION && version != TOCVIDEO) return 1;
	switch(version)
	{
		case TOCVIDEO:
			file->is_video_stream = 1;
			break;
	}

/* Read titles */
	read_titles(file->demuxer, version);
	return 0;
}
示例#3
0
/* If toc is 0 just read the first and last timecode. */
int mpeg3demux_create_title(mpeg3_demuxer_t *demuxer, 
		int timecode_search, 
		FILE *toc)
{
	int result = 0, done = 0, counter_start, counter;
	mpeg3_t *file = demuxer->file;
	long next_byte, prev_byte;
	double next_time, prev_time, absolute_time;
	long i;
	mpeg3_title_t *title;
	u_int32_t test_header = 0;
	mpeg3demux_timecode_t *timecode = 0;

	demuxer->error_flag = 0;
	demuxer->read_all = 1;

/* Create a single title */
	if(!demuxer->total_titles)
	{
		demuxer->titles[0] = mpeg3_new_title(file, file->fs->path);
		demuxer->total_titles = 1;
		mpeg3demux_open_title(demuxer, 0);
	}
	title = demuxer->titles[0];
	title->total_bytes = mpeg3io_total_bytes(title->fs);


/* Get the packet size from the file */
	if(file->is_program_stream)
	{
		mpeg3io_seek(title->fs, 4);
		for(i = 0; i < MPEG3_MAX_PACKSIZE && 
			test_header != MPEG3_PACK_START_CODE; i++)
		{
			test_header <<= 8;
			test_header |= mpeg3io_read_char(title->fs);
		}
		if(i < MPEG3_MAX_PACKSIZE) demuxer->packet_size = i;
		if(i < MPEG3_DVD_PACKET_SIZE) demuxer->packet_size = 4096;
		mpeg3io_seek(title->fs, 0);
	}
	else
		demuxer->packet_size = file->packet_size;

/* Get timecodes for the title */
	if(file->is_transport_stream || file->is_program_stream)
	{
		mpeg3io_seek(title->fs, 0);
		while(!done && !result && !mpeg3io_eof(title->fs))
		{
			next_byte = mpeg3io_tell(title->fs);
			result = mpeg3_read_next_packet(demuxer);

			if(!result)
			{
				next_time = demuxer->time;
//printf("%f %f\n", next_time, prev_time);
				if(next_time < prev_time || 
					next_time - prev_time > MPEG3_CONTIGUOUS_THRESHOLD ||
					!title->timecode_table_size)
				{
/* Discontinuous */
					timecode = mpeg3_append_timecode(demuxer, 
						title, 
						prev_byte, 
						prev_time, 
						next_byte, 
						next_time,
						0,
						0);
/*
 * printf("timecode: %ld %ld %f %f\n",
 * 				timecode->start_byte,
 * 				timecode->end_byte,
 * 				timecode->start_time,
 * 				timecode->end_time);
 */

					counter_start = next_time;
				}
				prev_time = next_time;
				prev_byte = next_byte;
				counter = next_time;
			}

/* Just get the first bytes if not building a toc to get the stream ID's. */
			if(next_byte > 0x100000 && 
				(!timecode_search || !toc)) done = 1;
		}

/* Get the last timecode */
		if(!toc || !timecode_search)
		{
			demuxer->read_all = 0;
			result = mpeg3io_seek(title->fs, title->total_bytes);
			if(!result) result = mpeg3_read_prev_packet(demuxer);
		}

		if(title->timecode_table && timecode)
		{
			timecode->end_byte = title->total_bytes;
//			timecode->end_byte = mpeg3io_tell(title->fs)/*  + demuxer->packet_size */;
			timecode->end_time = demuxer->time;
			timecode->absolute_end_time = timecode->end_time - timecode->start_time;
		}
	}

	mpeg3io_seek(title->fs, 0);
	demuxer->read_all = 0;
	return 0;
}