Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/libmpeg3.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmpeg3/libmpeg3.c | 672 |
1 files changed, 672 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3.c b/core/multimedia/opieplayer/libmpeg3/libmpeg3.c new file mode 100644 index 0000000..c0fc570 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3.c | |||
@@ -0,0 +1,672 @@ | |||
1 | #include "libmpeg3.h" | ||
2 | #include "mpeg3protos.h" | ||
3 | |||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | |||
7 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | ||
8 | |||
9 | mpeg3_t* mpeg3_new(char *path) | ||
10 | { | ||
11 | int i; | ||
12 | mpeg3_t *file = (mpeg3_t*)calloc(1, sizeof(mpeg3_t)); | ||
13 | file->cpus = 1; | ||
14 | file->fs = mpeg3_new_fs(path); | ||
15 | file->have_mmx = mpeg3_mmx_test(); | ||
16 | file->demuxer = mpeg3_new_demuxer(file, 0, 0, -1); | ||
17 | return file; | ||
18 | } | ||
19 | |||
20 | int mpeg3_delete(mpeg3_t *file) | ||
21 | { | ||
22 | int i; | ||
23 | |||
24 | for(i = 0; i < file->total_vstreams; i++) | ||
25 | mpeg3_delete_vtrack(file, file->vtrack[i]); | ||
26 | |||
27 | for(i = 0; i < file->total_astreams; i++) | ||
28 | mpeg3_delete_atrack(file, file->atrack[i]); | ||
29 | |||
30 | mpeg3_delete_fs(file->fs); | ||
31 | mpeg3_delete_demuxer(file->demuxer); | ||
32 | free(file); | ||
33 | } | ||
34 | |||
35 | int mpeg3_check_sig(char *path) | ||
36 | { | ||
37 | mpeg3_fs_t *fs; | ||
38 | unsigned int bits; | ||
39 | char *ext; | ||
40 | int result = 0; | ||
41 | |||
42 | fs = mpeg3_new_fs(path); | ||
43 | if(mpeg3io_open_file(fs)) | ||
44 | { | ||
45 | /* File not found */ | ||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | bits = mpeg3io_read_int32(fs); | ||
50 | /* Test header */ | ||
51 | if(bits == MPEG3_TOC_PREFIX || bits == MPEG3_TOC_PREFIXLOWER) | ||
52 | { | ||
53 | result = 1; | ||
54 | } | ||
55 | else | ||
56 | if((((bits >> 24) & 0xff) == MPEG3_SYNC_BYTE) || | ||
57 | (bits == MPEG3_PACK_START_CODE) || | ||
58 | ((bits & 0xfff00000) == 0xfff00000) || | ||
59 | (bits == MPEG3_SEQUENCE_START_CODE) || | ||
60 | (bits == MPEG3_PICTURE_START_CODE) || | ||
61 | (((bits & 0xffff0000) >> 16) == MPEG3_AC3_START_CODE) || | ||
62 | ((bits >> 8) == MPEG3_ID3_PREFIX) || | ||
63 | (bits == MPEG3_RIFF_CODE)) | ||
64 | { | ||
65 | result = 1; | ||
66 | |||
67 | ext = strrchr(path, '.'); | ||
68 | if(ext) | ||
69 | { | ||
70 | /* Test file extension. */ | ||
71 | if(strncasecmp(ext, ".mp2", 4) && | ||
72 | strncasecmp(ext, ".mp3", 4) && | ||
73 | strncasecmp(ext, ".m1v", 4) && | ||
74 | strncasecmp(ext, ".m2v", 4) && | ||
75 | strncasecmp(ext, ".m2s", 4) && | ||
76 | strncasecmp(ext, ".mpg", 4) && | ||
77 | strncasecmp(ext, ".vob", 4) && | ||
78 | strncasecmp(ext, ".mpeg", 4) && | ||
79 | strncasecmp(ext, ".ac3", 4)) | ||
80 | result = 0; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | mpeg3io_close_file(fs); | ||
85 | mpeg3_delete_fs(fs); | ||
86 | return result; | ||
87 | } | ||
88 | |||
89 | mpeg3_t* mpeg3_open_copy(char *path, mpeg3_t *old_file) | ||
90 | { | ||
91 | mpeg3_t *file = 0; | ||
92 | unsigned int bits; | ||
93 | int i, done; | ||
94 | |||
95 | /* Initialize the file structure */ | ||
96 | file = mpeg3_new(path); | ||
97 | |||
98 | /* Need to perform authentication before reading a single byte. */ | ||
99 | if(mpeg3io_open_file(file->fs)) | ||
100 | { | ||
101 | mpeg3_delete(file); | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | /* =============================== Create the title objects ========================= */ | ||
106 | bits = mpeg3io_read_int32(file->fs); | ||
107 | |||
108 | if(bits == MPEG3_TOC_PREFIX || bits == MPEG3_TOC_PREFIXLOWER) /* TOCV */ | ||
109 | { | ||
110 | /* Table of contents for another file */ | ||
111 | if(mpeg3_read_toc(file)) | ||
112 | { | ||
113 | mpeg3_delete(file); | ||
114 | return 0; | ||
115 | } | ||
116 | mpeg3io_close_file(file->fs); | ||
117 | } | ||
118 | else | ||
119 | if(((bits >> 24) & 0xff) == MPEG3_SYNC_BYTE) | ||
120 | { | ||
121 | /* Transport stream */ | ||
122 | file->packet_size = MPEG3_TS_PACKET_SIZE; | ||
123 | file->is_transport_stream = 1; | ||
124 | } | ||
125 | else | ||
126 | if(bits == MPEG3_PACK_START_CODE) | ||
127 | { | ||
128 | /* Program stream */ | ||
129 | file->packet_size = MPEG3_DVD_PACKET_SIZE; | ||
130 | file->is_program_stream = 1; | ||
131 | } | ||
132 | else | ||
133 | if((bits & 0xfff00000) == 0xfff00000 || | ||
134 | ((bits >> 8) == MPEG3_ID3_PREFIX) || | ||
135 | (bits == MPEG3_RIFF_CODE)) | ||
136 | { | ||
137 | /* MPEG Audio only */ | ||
138 | file->packet_size = MPEG3_DVD_PACKET_SIZE; | ||
139 | file->has_audio = 1; | ||
140 | file->is_audio_stream = 1; | ||
141 | } | ||
142 | else | ||
143 | if(bits == MPEG3_SEQUENCE_START_CODE || | ||
144 | bits == MPEG3_PICTURE_START_CODE) | ||
145 | { | ||
146 | /* Video only */ | ||
147 | file->packet_size = MPEG3_DVD_PACKET_SIZE; | ||
148 | file->is_video_stream = 1; | ||
149 | } | ||
150 | else | ||
151 | if(((bits & 0xffff0000) >> 16) == MPEG3_AC3_START_CODE) | ||
152 | { | ||
153 | /* AC3 Audio only */ | ||
154 | file->packet_size = MPEG3_DVD_PACKET_SIZE; | ||
155 | file->has_audio = 1; | ||
156 | file->is_audio_stream = 1; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | /* file->packet_size = MPEG3_DVD_PACKET_SIZE; */ | ||
161 | /* file->is_audio_stream = 1; */ | ||
162 | mpeg3_delete(file); | ||
163 | fprintf(stderr, "mpeg3_open: not an MPEG 2 stream\n"); | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | /* Create title */ | ||
168 | /* Copy timecodes from an old demuxer */ | ||
169 | if(old_file && mpeg3_get_demuxer(old_file)) | ||
170 | { | ||
171 | mpeg3demux_copy_titles(file->demuxer, mpeg3_get_demuxer(old_file)); | ||
172 | } | ||
173 | else | ||
174 | /* Start from scratch */ | ||
175 | if(!file->demuxer->total_titles) | ||
176 | { | ||
177 | mpeg3demux_create_title(file->demuxer, 0, 0); | ||
178 | } | ||
179 | |||
180 | /* =============================== Get title information ========================= */ | ||
181 | if(file->is_transport_stream || file->is_program_stream) | ||
182 | { | ||
183 | /* Create video tracks */ | ||
184 | /* Video must be created before audio because audio uses the video timecode */ | ||
185 | /* to get its length. */ | ||
186 | for(i = 0; i < MPEG3_MAX_STREAMS; i++) | ||
187 | { | ||
188 | if(file->demuxer->vstream_table[i]) | ||
189 | { | ||
190 | file->vtrack[file->total_vstreams] = mpeg3_new_vtrack(file, i, file->demuxer); | ||
191 | if(file->vtrack[file->total_vstreams]) file->total_vstreams++; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | /* Create audio tracks */ | ||
196 | for(i = 0; i < MPEG3_MAX_STREAMS; i++) | ||
197 | { | ||
198 | if(file->demuxer->astream_table[i]) | ||
199 | { | ||
200 | file->atrack[file->total_astreams] = mpeg3_new_atrack(file, | ||
201 | i, | ||
202 | file->demuxer->astream_table[i], | ||
203 | file->demuxer); | ||
204 | if(file->atrack[file->total_astreams]) file->total_astreams++; | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | else | ||
209 | if(file->is_video_stream) | ||
210 | { | ||
211 | /* Create video tracks */ | ||
212 | file->vtrack[0] = mpeg3_new_vtrack(file, -1, file->demuxer); | ||
213 | if(file->vtrack[0]) file->total_vstreams++; | ||
214 | } | ||
215 | else | ||
216 | if(file->is_audio_stream) | ||
217 | { | ||
218 | /* Create audio tracks */ | ||
219 | file->atrack[0] = mpeg3_new_atrack(file, -1, AUDIO_UNKNOWN, file->demuxer); | ||
220 | if(file->atrack[0]) file->total_astreams++; | ||
221 | } | ||
222 | |||
223 | if(file->total_vstreams) file->has_video = 1; | ||
224 | if(file->total_astreams) file->has_audio = 1; | ||
225 | |||
226 | mpeg3io_close_file(file->fs); | ||
227 | return file; | ||
228 | } | ||
229 | |||
230 | mpeg3_t* mpeg3_open(char *path) | ||
231 | { | ||
232 | return mpeg3_open_copy(path, 0); | ||
233 | } | ||
234 | |||
235 | int mpeg3_close(mpeg3_t *file) | ||
236 | { | ||
237 | /* File is closed in the same procedure it is opened in. */ | ||
238 | mpeg3_delete(file); | ||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | int mpeg3_set_cpus(mpeg3_t *file, int cpus) | ||
243 | { | ||
244 | int i; | ||
245 | file->cpus = cpus; | ||
246 | for(i = 0; i < file->total_vstreams; i++) | ||
247 | mpeg3video_set_cpus(file->vtrack[i]->video, cpus); | ||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | int mpeg3_set_mmx(mpeg3_t *file, int use_mmx) | ||
252 | { | ||
253 | int i; | ||
254 | file->have_mmx = use_mmx; | ||
255 | for(i = 0; i < file->total_vstreams; i++) | ||
256 | mpeg3video_set_mmx(file->vtrack[i]->video, use_mmx); | ||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | int mpeg3_generate_toc(FILE *output, char *path, int timecode_search, int print_streams) | ||
261 | { | ||
262 | mpeg3_t *file = mpeg3_open(path); | ||
263 | mpeg3_demuxer_t *demuxer; | ||
264 | int i; | ||
265 | |||
266 | if(file) | ||
267 | { | ||
268 | fprintf(output, "TOCVERSION 2\n" | ||
269 | "PATH: %s\n", path); | ||
270 | demuxer = mpeg3_new_demuxer(file, 0, 0, -1); | ||
271 | mpeg3demux_create_title(demuxer, timecode_search, output); | ||
272 | /* Just print the first title's streams */ | ||
273 | if(print_streams) mpeg3demux_print_streams(demuxer, output); | ||
274 | |||
275 | fprintf(output, "SIZE: %ld\n", demuxer->titles[demuxer->current_title]->total_bytes); | ||
276 | fprintf(output, "PACKETSIZE: %ld\n", demuxer->packet_size); | ||
277 | |||
278 | mpeg3demux_print_timecodes(demuxer->titles[demuxer->current_title], output); | ||
279 | |||
280 | mpeg3_delete_demuxer(demuxer); | ||
281 | mpeg3_close(file); | ||
282 | return 0; | ||
283 | } | ||
284 | return 1; | ||
285 | } | ||
286 | |||
287 | int mpeg3_read_toc(mpeg3_t *file) | ||
288 | { | ||
289 | char string[MPEG3_STRLEN]; | ||
290 | int number1; | ||
291 | |||
292 | /* Test version number */ | ||
293 | file->is_program_stream = 1; | ||
294 | mpeg3io_seek(file->fs, 0); | ||
295 | fscanf(file->fs->fd, "%s %d", string, &number1); | ||
296 | if(number1 > 2 || number1 < 2) return 1; | ||
297 | |||
298 | /* Read titles */ | ||
299 | mpeg3demux_read_titles(file->demuxer); | ||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | int mpeg3_has_audio(mpeg3_t *file) | ||
304 | { | ||
305 | return file->has_audio; | ||
306 | } | ||
307 | |||
308 | int mpeg3_total_astreams(mpeg3_t *file) | ||
309 | { | ||
310 | return file->total_astreams; | ||
311 | } | ||
312 | |||
313 | int mpeg3_audio_channels(mpeg3_t *file, | ||
314 | int stream) | ||
315 | { | ||
316 | if(file->has_audio) | ||
317 | return file->atrack[stream]->channels; | ||
318 | return -1; | ||
319 | } | ||
320 | |||
321 | int mpeg3_sample_rate(mpeg3_t *file, | ||
322 | int stream) | ||
323 | { | ||
324 | if(file->has_audio) | ||
325 | return file->atrack[stream]->sample_rate; | ||
326 | return -1; | ||
327 | } | ||
328 | |||
329 | long mpeg3_get_sample(mpeg3_t *file, | ||
330 | int stream) | ||
331 | { | ||
332 | if(file->has_audio) | ||
333 | return file->atrack[stream]->current_position; | ||
334 | return -1; | ||
335 | } | ||
336 | |||
337 | int mpeg3_set_sample(mpeg3_t *file, | ||
338 | long sample, | ||
339 | int stream) | ||
340 | { | ||
341 | if(file->has_audio) | ||
342 | { | ||
343 | file->atrack[stream]->current_position = sample; | ||
344 | mpeg3audio_seek_sample(file->atrack[stream]->audio, sample); | ||
345 | return 0; | ||
346 | } | ||
347 | return -1; | ||
348 | } | ||
349 | |||
350 | long mpeg3_audio_samples(mpeg3_t *file, | ||
351 | int stream) | ||
352 | { | ||
353 | if(file->has_audio) | ||
354 | return file->atrack[stream]->total_samples; | ||
355 | return -1; | ||
356 | } | ||
357 | |||
358 | int mpeg3_has_video(mpeg3_t *file) | ||
359 | { | ||
360 | return file->has_video; | ||
361 | } | ||
362 | |||
363 | int mpeg3_total_vstreams(mpeg3_t *file) | ||
364 | { | ||
365 | return file->total_vstreams; | ||
366 | } | ||
367 | |||
368 | int mpeg3_video_width(mpeg3_t *file, | ||
369 | int stream) | ||
370 | { | ||
371 | if(file->has_video) | ||
372 | return file->vtrack[stream]->width; | ||
373 | return -1; | ||
374 | } | ||
375 | |||
376 | int mpeg3_video_height(mpeg3_t *file, | ||
377 | int stream) | ||
378 | { | ||
379 | if(file->has_video) | ||
380 | return file->vtrack[stream]->height; | ||
381 | return -1; | ||
382 | } | ||
383 | |||
384 | float mpeg3_frame_rate(mpeg3_t *file, | ||
385 | int stream) | ||
386 | { | ||
387 | if(file->has_video) | ||
388 | return file->vtrack[stream]->frame_rate; | ||
389 | return -1; | ||
390 | } | ||
391 | |||
392 | long mpeg3_video_frames(mpeg3_t *file, | ||
393 | int stream) | ||
394 | { | ||
395 | if(file->has_video) | ||
396 | return file->vtrack[stream]->total_frames; | ||
397 | return -1; | ||
398 | } | ||
399 | |||
400 | long mpeg3_get_frame(mpeg3_t *file, | ||
401 | int stream) | ||
402 | { | ||
403 | if(file->has_video) | ||
404 | return file->vtrack[stream]->current_position; | ||
405 | return -1; | ||
406 | } | ||
407 | |||
408 | int mpeg3_set_frame(mpeg3_t *file, | ||
409 | long frame, | ||
410 | int stream) | ||
411 | { | ||
412 | if(file->has_video) | ||
413 | { | ||
414 | file->vtrack[stream]->current_position = frame; | ||
415 | mpeg3video_seek_frame(file->vtrack[stream]->video, frame); | ||
416 | return 0; | ||
417 | } | ||
418 | return -1; | ||
419 | } | ||
420 | |||
421 | int mpeg3_seek_percentage(mpeg3_t *file, double percentage) | ||
422 | { | ||
423 | int i; | ||
424 | for(i = 0; i < file->total_astreams; i++) | ||
425 | { | ||
426 | mpeg3audio_seek_percentage(file->atrack[i]->audio, percentage); | ||
427 | } | ||
428 | |||
429 | for(i = 0; i < file->total_vstreams; i++) | ||
430 | { | ||
431 | mpeg3video_seek_percentage(file->vtrack[i]->video, percentage); | ||
432 | } | ||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | int mpeg3_previous_frame(mpeg3_t *file, int stream) | ||
437 | { | ||
438 | file->last_type_read = 2; | ||
439 | file->last_stream_read = stream; | ||
440 | |||
441 | if(file->has_video) | ||
442 | return mpeg3video_previous_frame(file->vtrack[stream]->video); | ||
443 | } | ||
444 | |||
445 | double mpeg3_tell_percentage(mpeg3_t *file) | ||
446 | { | ||
447 | double percent = 0; | ||
448 | if(file->last_type_read == 1) | ||
449 | { | ||
450 | percent = mpeg3demux_tell_percentage(file->atrack[file->last_stream_read]->demuxer); | ||
451 | } | ||
452 | |||
453 | if(file->last_type_read == 2) | ||
454 | { | ||
455 | percent = mpeg3demux_tell_percentage(file->vtrack[file->last_stream_read]->demuxer); | ||
456 | } | ||
457 | return percent; | ||
458 | } | ||
459 | |||
460 | double mpeg3_get_time(mpeg3_t *file) | ||
461 | { | ||
462 | double atime = 0, vtime = 0; | ||
463 | |||
464 | if(file->is_transport_stream || file->is_program_stream) | ||
465 | { | ||
466 | /* Timecode only available in transport stream */ | ||
467 | if(file->last_type_read == 1) | ||
468 | { | ||
469 | atime = mpeg3demux_get_time(file->atrack[file->last_stream_read]->demuxer); | ||
470 | } | ||
471 | else | ||
472 | if(file->last_type_read == 2) | ||
473 | { | ||
474 | vtime = mpeg3demux_get_time(file->vtrack[file->last_stream_read]->demuxer); | ||
475 | } | ||
476 | } | ||
477 | else | ||
478 | { | ||
479 | /* Use percentage and total time */ | ||
480 | if(file->has_audio) | ||
481 | { | ||
482 | atime = mpeg3demux_tell_percentage(file->atrack[0]->demuxer) * | ||
483 | mpeg3_audio_samples(file, 0) / mpeg3_sample_rate(file, 0); | ||
484 | } | ||
485 | |||
486 | if(file->has_video) | ||
487 | { | ||
488 | vtime = mpeg3demux_tell_percentage(file->vtrack[0]->demuxer) * | ||
489 | mpeg3_video_frames(file, 0) / mpeg3_frame_rate(file, 0); | ||
490 | } | ||
491 | } | ||
492 | |||
493 | return MAX(atime, vtime); | ||
494 | } | ||
495 | |||
496 | int mpeg3_end_of_audio(mpeg3_t *file, int stream) | ||
497 | { | ||
498 | int result = 0; | ||
499 | result = mpeg3demux_eof(file->atrack[stream]->demuxer); | ||
500 | return result; | ||
501 | } | ||
502 | |||
503 | int mpeg3_end_of_video(mpeg3_t *file, int stream) | ||
504 | { | ||
505 | int result = 0; | ||
506 | result = mpeg3demux_eof(file->vtrack[stream]->demuxer); | ||
507 | return result; | ||
508 | } | ||
509 | |||
510 | |||
511 | int mpeg3_read_frame(mpeg3_t *file, | ||
512 | unsigned char **output_rows, | ||
513 | int in_x, | ||
514 | int in_y, | ||
515 | int in_w, | ||
516 | int in_h, | ||
517 | int out_w, | ||
518 | int out_h, | ||
519 | int color_model, | ||
520 | int stream) | ||
521 | { | ||
522 | int result = -1; | ||
523 | |||
524 | if(file->has_video) | ||
525 | { | ||
526 | result = mpeg3video_read_frame(file->vtrack[stream]->video, | ||
527 | file->vtrack[stream]->current_position, | ||
528 | output_rows, | ||
529 | in_x, | ||
530 | in_y, | ||
531 | in_w, | ||
532 | in_h, | ||
533 | out_w, | ||
534 | out_h, | ||
535 | color_model); | ||
536 | file->last_type_read = 2; | ||
537 | file->last_stream_read = stream; | ||
538 | file->vtrack[stream]->current_position++; | ||
539 | } | ||
540 | return result; | ||
541 | } | ||
542 | |||
543 | int mpeg3_drop_frames(mpeg3_t *file, long frames, int stream) | ||
544 | { | ||
545 | int result = -1; | ||
546 | |||
547 | if(file->has_video) | ||
548 | { | ||
549 | result = mpeg3video_drop_frames(file->vtrack[stream]->video, | ||
550 | frames); | ||
551 | if(frames > 0) file->vtrack[stream]->current_position += frames; | ||
552 | file->last_type_read = 2; | ||
553 | file->last_stream_read = stream; | ||
554 | } | ||
555 | return result; | ||
556 | } | ||
557 | |||
558 | int mpeg3_read_yuvframe(mpeg3_t *file, | ||
559 | char *y_output, | ||
560 | char *u_output, | ||
561 | char *v_output, | ||
562 | int in_x, | ||
563 | int in_y, | ||
564 | int in_w, | ||
565 | int in_h, | ||
566 | int stream) | ||
567 | { | ||
568 | int result = -1; | ||
569 | |||
570 | //printf("mpeg3_read_yuvframe 1 %d %d\n", mpeg3demux_tell(file->vtrack[stream]->demuxer), mpeg3demuxer_total_bytes(file->vtrack[stream]->demuxer)); | ||
571 | if(file->has_video) | ||
572 | { | ||
573 | result = mpeg3video_read_yuvframe(file->vtrack[stream]->video, | ||
574 | file->vtrack[stream]->current_position, | ||
575 | y_output, | ||
576 | u_output, | ||
577 | v_output, | ||
578 | in_x, | ||
579 | in_y, | ||
580 | in_w, | ||
581 | in_h); | ||
582 | file->last_type_read = 2; | ||
583 | file->last_stream_read = stream; | ||
584 | file->vtrack[stream]->current_position++; | ||
585 | } | ||
586 | //printf("mpeg3_read_yuvframe 2 %d %d\n", mpeg3demux_tell(file->vtrack[stream]->demuxer), mpeg3demuxer_total_bytes(file->vtrack[stream]->demuxer)); | ||
587 | return result; | ||
588 | } | ||
589 | |||
590 | |||
591 | int mpeg3_read_audio(mpeg3_t *file, | ||
592 | mpeg3_real_t *output_f, | ||
593 | short *output_i, int sampleSpacing, | ||
594 | int channel, | ||
595 | long samples, | ||
596 | int stream) | ||
597 | { | ||
598 | int result = -1; | ||
599 | |||
600 | //printf("mpeg3_read_audio 1 %d %d\n", mpeg3demux_tell(file->atrack[stream]->demuxer), mpeg3demuxer_total_bytes(file->atrack[stream]->demuxer)); | ||
601 | if(file->has_audio) | ||
602 | { | ||
603 | result = mpeg3audio_decode_audio(file->atrack[stream]->audio, | ||
604 | output_f, | ||
605 | output_i, sampleSpacing, | ||
606 | channel, | ||
607 | file->atrack[stream]->current_position, | ||
608 | samples); | ||
609 | file->last_type_read = 1; | ||
610 | file->last_stream_read = stream; | ||
611 | file->atrack[stream]->current_position += samples; | ||
612 | } | ||
613 | //printf("mpeg3_read_audio 2 %d %d\n", mpeg3demux_tell(file->atrack[stream]->demuxer), mpeg3demuxer_total_bytes(file->atrack[stream]->demuxer)); | ||
614 | |||
615 | return result; | ||
616 | } | ||
617 | |||
618 | int mpeg3_reread_audio(mpeg3_t *file, | ||
619 | mpeg3_real_t *output_f, | ||
620 | short *output_i, int sampleSpacing, | ||
621 | int channel, | ||
622 | long samples, | ||
623 | int stream) | ||
624 | { | ||
625 | if(file->has_audio) | ||
626 | { | ||
627 | mpeg3_set_sample(file, | ||
628 | file->atrack[stream]->current_position - samples, | ||
629 | stream); | ||
630 | file->last_type_read = 1; | ||
631 | file->last_stream_read = stream; | ||
632 | return mpeg3_read_audio(file, | ||
633 | output_f, | ||
634 | output_i, sampleSpacing, | ||
635 | channel, | ||
636 | samples, | ||
637 | stream); | ||
638 | } | ||
639 | return -1; | ||
640 | } | ||
641 | |||
642 | int mpeg3_read_audio_chunk(mpeg3_t *file, | ||
643 | unsigned char *output, | ||
644 | long *size, | ||
645 | long max_size, | ||
646 | int stream) | ||
647 | { | ||
648 | int result = 0; | ||
649 | if(file->has_audio) | ||
650 | { | ||
651 | result = mpeg3audio_read_raw(file->atrack[stream]->audio, output, size, max_size); | ||
652 | file->last_type_read = 1; | ||
653 | file->last_stream_read = stream; | ||
654 | } | ||
655 | return result; | ||
656 | } | ||
657 | |||
658 | int mpeg3_read_video_chunk(mpeg3_t *file, | ||
659 | unsigned char *output, | ||
660 | long *size, | ||
661 | long max_size, | ||
662 | int stream) | ||
663 | { | ||
664 | int result = 0; | ||
665 | if(file->has_video) | ||
666 | { | ||
667 | result = mpeg3video_read_raw(file->vtrack[stream]->video, output, size, max_size); | ||
668 | file->last_type_read = 2; | ||
669 | file->last_stream_read = stream; | ||
670 | } | ||
671 | return result; | ||
672 | } | ||