2 #include "mpeg3protos.h"
6 mpeg3_atrack_t
* mpeg3_new_atrack(mpeg3_t
*file
,
9 mpeg3_demuxer_t
*demuxer
,
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
);
22 mpeg3demux_copy_titles(new_atrack
->demuxer
, demuxer
);
24 new_atrack
->current_position
= 0;
25 new_atrack
->pid
= custom_id
;
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
,
41 if(!new_atrack
->audio
)
44 mpeg3_delete_atrack(file
, 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
);
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
++] =
74 atrack
->private_offsets
= 1;