r1005: Increase the number of displayed digits for resample audio dialog box
[cinelerra_cv/mob.git] / libmpeg3 / mpeg3vtrack.c
blob7be45cf0adde437144f46a8f0c8f489b382f03c9
1 #include "libmpeg3.h"
2 #include "mpeg3protos.h"
4 #include <stdlib.h>
6 mpeg3_vtrack_t* mpeg3_new_vtrack(mpeg3_t *file,
7 int custom_id,
8 mpeg3_demuxer_t *demuxer,
9 int number)
11 int result = 0;
12 mpeg3_vtrack_t *new_vtrack;
14 new_vtrack = calloc(1, sizeof(mpeg3_vtrack_t));
15 new_vtrack->demuxer = mpeg3_new_demuxer(file, 0, 1, custom_id);
16 new_vtrack->frame_cache = mpeg3_new_cache();
17 if(file->seekable)
19 mpeg3demux_copy_titles(new_vtrack->demuxer, demuxer);
21 new_vtrack->current_position = 0;
22 new_vtrack->pid = custom_id;
24 // Copy pointers
25 if(file->frame_offsets)
27 new_vtrack->frame_offsets = file->frame_offsets[number];
28 new_vtrack->total_frame_offsets = file->total_frame_offsets[number];
29 new_vtrack->keyframe_numbers = file->keyframe_numbers[number];
30 new_vtrack->total_keyframe_numbers = file->total_keyframe_numbers[number];
31 new_vtrack->demuxer->stream_end = file->video_eof[number];
34 /* Get information about the track here. */
35 new_vtrack->video = mpeg3video_new(file,
36 new_vtrack);
38 if(!new_vtrack->video)
40 /* Failed */
41 mpeg3_delete_vtrack(file, new_vtrack);
42 new_vtrack = 0;
46 return new_vtrack;
49 int mpeg3_delete_vtrack(mpeg3_t *file, mpeg3_vtrack_t *vtrack)
51 if(vtrack->video) mpeg3video_delete(vtrack->video);
52 if(vtrack->demuxer) mpeg3_delete_demuxer(vtrack->demuxer);
53 if(vtrack->private_offsets)
55 if(vtrack->frame_offsets) free(vtrack->frame_offsets);
56 if(vtrack->keyframe_numbers) free(vtrack->keyframe_numbers);
58 mpeg3_delete_cache(vtrack->frame_cache);
60 int i;
61 for(i = 0; i < vtrack->total_subtitles; i++)
63 mpeg3_delete_subtitle(vtrack->subtitles[i]);
65 if(vtrack->subtitles) free(vtrack->subtitles);
66 free(vtrack);
67 return 0;
70 static int last_keyframe = 0;
71 void mpeg3_append_frame(mpeg3_vtrack_t *vtrack, int64_t offset, int is_keyframe)
73 if(vtrack->total_frame_offsets >= vtrack->frame_offsets_allocated)
75 vtrack->frame_offsets_allocated =
76 MAX(vtrack->total_frame_offsets * 2, 1024);
77 vtrack->frame_offsets = realloc(vtrack->frame_offsets,
78 sizeof(int64_t) * vtrack->frame_offsets_allocated);
81 vtrack->frame_offsets[vtrack->total_frame_offsets++] = offset;
83 if(is_keyframe)
85 if(vtrack->total_keyframe_numbers >= vtrack->keyframe_numbers_allocated)
87 vtrack->keyframe_numbers_allocated =
88 MAX(vtrack->total_keyframe_numbers * 2, 1024);
89 vtrack->keyframe_numbers = realloc(vtrack->keyframe_numbers,
90 sizeof(int64_t) * vtrack->keyframe_numbers_allocated);
93 // Because the frame offsets are for the frame
94 // after, this needs to take off one frame.
95 int corrected_frame = vtrack->total_frame_offsets - 2;
96 if(corrected_frame < 0) corrected_frame = 0;
97 vtrack->keyframe_numbers[vtrack->total_keyframe_numbers++] =
98 corrected_frame;
101 vtrack->private_offsets = 1;