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 if(file
->is_transport_stream
)
31 fprintf(output
, "TRANSPORT_STREAM\n");
33 fprintf(output
, "PATH: %s\n"
36 demuxer
->titles
[i
]->fs
->path
,
37 demuxer
->titles
[i
]->total_bytes
,
40 /* Just print the first title's streams */
42 mpeg3demux_print_streams(demuxer
, output
);
44 mpeg3demux_print_timecodes(demuxer
->titles
[i
], output
);
51 char complete_path
[MPEG3_STRLEN
];
52 mpeg3io_complete_path(complete_path
, path
);
54 mpeg3demux_create_title(demuxer
, timecode_search
, output
);
56 fprintf(output
, "TOCVERSION %d\n"
57 "PATH: %s\n", TOCVERSION
, complete_path
);
59 if(file
->is_program_stream
)
60 fprintf(output
, "PROGRAM_STREAM\n");
62 if(file
->is_transport_stream
)
63 fprintf(output
, "TRANSPORT_STREAM\n");
65 if(file
->is_video_stream
)
66 fprintf(output
, "VIDEO_STREAM\n");
68 if(file
->is_audio_stream
)
69 fprintf(output
, "AUDIO_STREAM\n");
71 /* Just print the first title's streams */
72 if(print_streams
) mpeg3demux_print_streams(demuxer
, output
);
74 if(file
->is_transport_stream
|| file
->is_program_stream
)
76 fprintf(output
, "SIZE: %ld\n", demuxer
->titles
[demuxer
->current_title
]->total_bytes
);
77 fprintf(output
, "PACKETSIZE: %ld\n", file
->packet_size
);
80 mpeg3demux_print_timecodes(demuxer
->titles
[demuxer
->current_title
], output
);
84 mpeg3_delete_demuxer(demuxer
);
90 /* Read the title information from a toc */
91 static int read_titles(mpeg3_demuxer_t
*demuxer
, int version
)
93 char string1
[MPEG3_STRLEN
], string2
[MPEG3_STRLEN
];
94 long start_byte
, end_byte
;
95 double start_time
, end_time
;
97 mpeg3_title_t
*title
= 0;
98 mpeg3_t
*file
= demuxer
->file
;
100 // Eventually use IFO file to generate titles
101 while(!feof(file
->fs
->fd
))
106 // Scanf is broken for single word lines
108 byte
= fgetc(file
->fs
->fd
);
111 byte
!= 0xa) string
[i
++] = byte
;
112 }while(byte
!= 0xd &&
114 !feof(file
->fs
->fd
) &&
120 sscanf(string
, "%s %s %ld %lf %lf %f",
128 //printf("read_titles 2 %d %s %s %ld %f %f %f\n", strlen(string), string1, string2, end_byte, start_time, end_time, program);
129 if(!strncasecmp(string1
, "PATH:", 5))
131 //printf("read_titles 2\n");
132 title
= demuxer
->titles
[demuxer
->total_titles
++] = mpeg3_new_title(file
, string2
);
135 if(!strcasecmp(string1
, "PROGRAM_STREAM"))
137 //printf("read_titles 3\n");
138 file
->is_program_stream
= 1;
141 if(!strcasecmp(string1
, "TRANSPORT_STREAM"))
143 //printf("read_titles 4\n");
144 file
->is_transport_stream
= 1;
149 mpeg3demux_cell_t
*timecode
;
150 start_byte
= atol(string2
);
151 //printf("read_titles 5\n");
152 if(!strcasecmp(string1
, "REGION:"))
154 timecode
= mpeg3_append_timecode(demuxer
,
164 //printf("mpeg3toc2 3\n");
165 timecode
->start_byte
= start_byte
;
166 //printf("mpeg3toc2 4\n");
167 timecode
->end_byte
= end_byte
;
168 timecode
->start_time
= start_time
;
169 timecode
->end_time
= end_time
;
170 timecode
->program
= program
;
175 * printf("read_title %p end: %f start: %f\n",
177 * timecode->end_time,
178 * timecode->start_time);
184 if(!strcasecmp(string1
, "ASTREAM:"))
185 demuxer
->astream_table
[start_byte
] = end_byte
;
187 if(!strcasecmp(string1
, "VSTREAM:"))
188 demuxer
->vstream_table
[start_byte
] = end_byte
;
190 if(!strcasecmp(string1
, "SIZE:"))
191 title
->total_bytes
= start_byte
;
193 if(!strcasecmp(string1
, "PACKETSIZE:"))
194 file
->packet_size
= start_byte
;
195 //printf("read_titles 3\n");
200 mpeg3demux_assign_programs(demuxer
);
201 mpeg3demux_open_title(demuxer
, 0);
205 int mpeg3_read_toc(mpeg3_t
*file
)
207 char string
[MPEG3_STRLEN
];
210 /* Test version number */
211 mpeg3io_seek(file
->fs
, 0);
212 fscanf(file
->fs
->fd
, "%s %d", string
, &version
);
213 if(version
!= TOCVERSION
&& version
!= TOCVIDEO
) return 1;
217 file
->is_video_stream
= 1;
222 read_titles(file
->demuxer
, version
);