2 #include "mpeg3protos.h"
7 int mpeg3_generate_toc(FILE *output
, char *path
, int timecode_search
, int print_streams
)
9 mpeg3_t
*file
= mpeg3_open(path
);
10 mpeg3_demuxer_t
*demuxer
;
15 demuxer
= mpeg3_new_demuxer(file
, 0, 0, -1);
19 mpeg3io_open_file(file
->fs
);
20 mpeg3demux_read_ifo(file
, demuxer
, 1);
21 mpeg3io_close_file(file
->fs
);
23 for(i
= 0; i
< demuxer
->total_titles
; i
++)
25 fprintf(output
, "TOCVERSION %d\n", TOCVERSION
);
27 if(file
->is_program_stream
)
28 fprintf(output
, "PROGRAM_STREAM\n");
30 fprintf(output
, "TRANSPORT_STREAM\n");
32 fprintf(output
, "PATH: %s\n"
35 demuxer
->titles
[i
]->fs
->path
,
36 demuxer
->titles
[i
]->total_bytes
,
39 /* Just print the first title's streams */
41 mpeg3demux_print_streams(demuxer
, output
);
43 mpeg3demux_print_timecodes(demuxer
->titles
[i
], output
);
50 char complete_path
[MPEG3_STRLEN
];
51 mpeg3io_complete_path(complete_path
, path
);
53 fprintf(output
, "TOCVERSION %d\n"
54 "PATH: %s\n", TOCVERSION
, complete_path
);
55 if(file
->is_program_stream
)
56 fprintf(output
, "PROGRAM_STREAM\n");
58 fprintf(output
, "TRANSPORT_STREAM\n");
60 mpeg3demux_create_title(demuxer
, timecode_search
, output
);
61 /* Just print the first title's streams */
62 if(print_streams
) mpeg3demux_print_streams(demuxer
, output
);
64 if(file
->is_transport_stream
|| file
->is_program_stream
)
66 fprintf(output
, "SIZE: %ld\n", demuxer
->titles
[demuxer
->current_title
]->total_bytes
);
67 fprintf(output
, "PACKETSIZE: %ld\n", file
->packet_size
);
70 mpeg3demux_print_timecodes(demuxer
->titles
[demuxer
->current_title
], output
);
74 mpeg3_delete_demuxer(demuxer
);
80 /* Read the title information from a toc */
81 static int read_titles(mpeg3_demuxer_t
*demuxer
, int version
)
83 char string1
[MPEG3_STRLEN
], string2
[MPEG3_STRLEN
];
84 long start_byte
, end_byte
;
85 double start_time
, end_time
;
87 mpeg3_title_t
*title
= 0;
88 mpeg3_t
*file
= demuxer
->file
;
90 // Eventually use IFO file to generate titles
91 while(!feof(file
->fs
->fd
))
96 // Scanf is broken for single word lines
98 byte
= fgetc(file
->fs
->fd
);
101 byte
!= 0xa) string
[i
++] = byte
;
102 }while(byte
!= 0xd &&
104 !feof(file
->fs
->fd
) &&
110 sscanf(string
, "%s %s %ld %lf %lf %f",
118 //printf("read_titles 2 %d %s %s %ld %f %f %f\n", strlen(string), string1, string2, end_byte, start_time, end_time, program);
119 if(!strncasecmp(string1
, "PATH:", 5))
121 //printf("read_titles 2\n");
122 title
= demuxer
->titles
[demuxer
->total_titles
++] = mpeg3_new_title(file
, string2
);
125 if(!strcasecmp(string1
, "PROGRAM_STREAM"))
127 //printf("read_titles 3\n");
128 file
->is_program_stream
= 1;
131 if(!strcasecmp(string1
, "TRANSPORT_STREAM"))
133 //printf("read_titles 4\n");
134 file
->is_transport_stream
= 1;
139 mpeg3demux_cell_t
*timecode
;
140 start_byte
= atol(string2
);
141 //printf("read_titles 5\n");
142 if(!strcasecmp(string1
, "REGION:"))
144 timecode
= mpeg3_append_timecode(demuxer
,
154 //printf("mpeg3toc2 3\n");
155 timecode
->start_byte
= start_byte
;
156 //printf("mpeg3toc2 4\n");
157 timecode
->end_byte
= end_byte
;
158 timecode
->start_time
= start_time
;
159 timecode
->end_time
= end_time
;
160 timecode
->program
= program
;
162 * printf("read_title %p end: %f start: %f\n",
164 * timecode->end_time,
165 * timecode->start_time);
169 if(!strcasecmp(string1
, "ASTREAM:"))
170 demuxer
->astream_table
[start_byte
] = end_byte
;
172 if(!strcasecmp(string1
, "VSTREAM:"))
173 demuxer
->vstream_table
[start_byte
] = end_byte
;
175 if(!strcasecmp(string1
, "SIZE:"))
176 title
->total_bytes
= start_byte
;
178 if(!strcasecmp(string1
, "PACKETSIZE:"))
179 file
->packet_size
= start_byte
;
180 //printf("read_titles 3\n");
185 mpeg3demux_assign_programs(demuxer
);
186 mpeg3demux_open_title(demuxer
, 0);
190 int mpeg3_read_toc(mpeg3_t
*file
)
192 char string
[MPEG3_STRLEN
];
195 /* Test version number */
196 mpeg3io_seek(file
->fs
, 0);
197 fscanf(file
->fs
->fd
, "%s %d", string
, &version
);
198 if(version
!= TOCVERSION
&& version
!= TOCVIDEO
) return 1;
202 file
->is_video_stream
= 1;
207 read_titles(file
->demuxer
, version
);