plugins depending on libaffine
[cinelerra_cv/mob.git] / libmpeg3 / mpeg3atrack.c
blob6ee52d5957c345962846e1534bbb5e75ab52196f
1 #include "libmpeg3.h"
2 #include "mpeg3protos.h"
4 #include <stdlib.h>
6 mpeg3_atrack_t* mpeg3_new_atrack(mpeg3_t *file,
7 int custom_id,
8 int format,
9 mpeg3_demuxer_t *demuxer,
10 int number)
12 mpeg3_atrack_t *new_atrack;
14 new_atrack = calloc(1, sizeof(mpeg3_atrack_t));
15 if(file->channel_counts)
16 new_atrack->channels = file->channel_counts[number];
17 new_atrack->sample_rate = 0;
18 new_atrack->total_samples = 0;
19 new_atrack->demuxer = mpeg3_new_demuxer(file, 1, 0, custom_id);
20 if(file->seekable)
22 mpeg3demux_copy_titles(new_atrack->demuxer, demuxer);
24 new_atrack->current_position = 0;
25 new_atrack->pid = custom_id;
28 /* Copy pointers */
29 if(file->sample_offsets)
31 new_atrack->sample_offsets = file->sample_offsets[number];
32 new_atrack->total_sample_offsets = file->total_sample_offsets[number];
33 new_atrack->total_samples = file->total_samples[number];
34 new_atrack->demuxer->stream_end = file->audio_eof[number];
37 new_atrack->audio = mpeg3audio_new(file,
38 new_atrack,
39 format);
41 if(!new_atrack->audio)
43 /* Failed */
44 mpeg3_delete_atrack(file, new_atrack);
45 new_atrack = 0;
48 return new_atrack;
51 int mpeg3_delete_atrack(mpeg3_t *file, mpeg3_atrack_t *atrack)
53 if(atrack->audio) mpeg3audio_delete(atrack->audio);
54 if(atrack->demuxer) mpeg3_delete_demuxer(atrack->demuxer);
55 if(atrack->sample_offsets && atrack->private_offsets)
57 free(atrack->sample_offsets);
59 free(atrack);
60 return 0;
63 void mpeg3_append_samples(mpeg3_atrack_t *atrack, int64_t offset)
65 if(atrack->total_sample_offsets >= atrack->sample_offsets_allocated)
67 atrack->sample_offsets_allocated =
68 MAX(atrack->total_sample_offsets * 2, 1024);
69 atrack->sample_offsets = realloc(atrack->sample_offsets,
70 sizeof(int64_t) * atrack->sample_offsets_allocated);
72 atrack->sample_offsets[atrack->total_sample_offsets++] =
73 offset;
74 atrack->private_offsets = 1;