4 atrack_t(zmpeg3_t *zsrc, int custom_id, int format,
5 demuxer_t *demux, int no)
7 channels = zsrc->channel_counts ? zsrc->channel_counts[no] : 0;
10 demuxer = new demuxer_t(zsrc, this, 0, custom_id);
11 if( zsrc->seekable ) {
12 demux->copy_titles(demuxer);
22 if( zsrc->sample_offsets ) { /* Copy pointers */
23 sample_offsets = zsrc->sample_offsets[number];
24 total_sample_offsets = zsrc->total_sample_offsets[number];
25 total_samples = zsrc->total_samples[number];
26 demuxer->stream_end = zsrc->audio_eof[number];
27 nudge = zsrc->nudging[number];
32 new_atrack_t(int custom_id, int format, demuxer_t *demux, int number)
34 atrack_t *new_atrack = new atrack_t(this,custom_id,format,demux,number);
35 new_atrack->audio = new_audio_t(new_atrack, format);
36 if( !new_atrack->audio ) { /* Failed */
47 if( audio ) delete audio;
48 if( demuxer ) delete demuxer;
49 if( sample_offsets && private_offsets ) {
50 delete [] sample_offsets;
55 extend_sample_offsets()
57 if( sample_offsets_allocated <= total_sample_offsets ) {
58 long new_allocation = ZMAX(2*total_sample_offsets, 1024);
59 int64_t *new_offsets = new int64_t[new_allocation];
60 for( int i=0; i<total_sample_offsets; ++i )
61 new_offsets[i] = sample_offsets[i];
62 delete [] sample_offsets;
63 sample_offsets = new_offsets;
64 sample_offsets_allocated = new_allocation;
69 append_samples(int64_t offset)
71 extend_sample_offsets();
72 sample_offsets[total_sample_offsets++] = offset;
76 void zatrack_t::update_audio_time()
78 double pts = frame_pts;
81 int64_t audio_pos = audio->audio_position();
82 if( pts_starttime < 0. && sample_rate > 0 ) {
84 pts_offset = audio_pos / (double)sample_rate;
86 pts_origin = pts - pts_offset;
88 else if( pts < pts_starttime ) { // check for pts rollover
89 if( pts_starttime-pts > 0x100000000ll / 90000 )
90 pts += 0x200000000ll / 90000;
92 double atime = pts_audio_time(pts);
93 if( atime > audio_time ) {
94 pts_position = audio_pos;
96 //zmsgs("track %02x audio_time=%f\n", pid, audio_time);
100 double zatrack_t::get_audio_time()
102 double atime = audio_time;
103 if( atime >= 0 && sample_rate > 0 ) {
104 int64_t audio_pos = audio->audio_position();
105 atime += (audio_pos-pts_position) / (double)sample_rate;
114 demuxer->pes_audio_time = -1.;
115 pts_starttime = demuxer->src->pts_padding >= 0 ? -1. : 0.;
122 int64_t zatrack_t::apparent_position()
124 int64_t pos = demuxer->absolute_position();
126 int r = total_sample_offsets;
129 int64_t mpos = sample_offsets[m];
130 if( pos == mpos ) return m;
131 if( pos > mpos ) l = m;
134 int64_t result = (int64_t)l * AUDIO_CHUNKSIZE;
135 if( r < total_sample_offsets )
136 result += (AUDIO_CHUNKSIZE * (pos - sample_offsets[l])) /
137 (sample_offsets[r] - sample_offsets[l]);