@@ -125,7 +125,7 @@ static int make_gap_list(lwlibav_audio_handler_t* hp, VSMap* out, const VSAPI* v
125125 set_error_on_init (out , vsapi , "lsmas: the resampled audio gap is too large." );
126126 return -1 ;
127127 }
128- adhp -> gap_list [gap_index ].pts_in_samples = gap_start ;
128+ adhp -> gap_list [gap_index ].pts_in_samples = gap_start + hp -> lwh . av_gap ;
129129 adhp -> gap_list [gap_index ].length = (int )gap_length ;
130130 gap_index ++ ;
131131 }
@@ -147,10 +147,10 @@ static int delay_audio(lwlibav_audio_handler_t* hp, int64_t* start, int64_t want
147147 return 1 ;
148148}
149149
150- static int decode_audio_range (
151- uint8_t * buf , int64_t output_start , int64_t length , int64_t removed_gap_length , lwlibav_audio_handler_t * hp )
150+ static int decode_audio_range (uint8_t * buf , int64_t output_start , int64_t length , lwlibav_audio_handler_t * hp )
152151{
153- int64_t source_start = output_start - removed_gap_length ;
152+ /* Synthetic gap frames are already part of the decoder's PCM timeline. */
153+ int64_t source_start = output_start ;
154154 if (!delay_audio (hp , & source_start , length ))
155155 return 0 ;
156156 return lwlibav_audio_get_pcm_samples (hp -> adhp , hp -> aohp , buf , source_start , length ) == (uint64_t )length ? 0 : -1 ;
@@ -161,35 +161,31 @@ static int render_audio(uint8_t* buf, int64_t start, int64_t wanted_length, lwli
161161 lwlibav_audio_decode_handler_t * adhp = hp -> adhp ;
162162 lwlibav_audio_output_handler_t * aohp = hp -> aohp ;
163163 if (!aohp -> fill_audio_gaps || !adhp -> gap_list )
164- return decode_audio_range (buf , start , wanted_length , 0 , hp );
164+ return decode_audio_range (buf , start , wanted_length , hp );
165165
166166 int64_t end = start + wanted_length ;
167167 int64_t cursor = start ;
168- int64_t removed_gap_length = 0 ;
169168 for (int i = 0 ; i < adhp -> gap_count ; i ++ ) {
170- int64_t gap_start = adhp -> gap_list [i ].pts_in_samples + hp -> lwh . av_gap ;
169+ int64_t gap_start = adhp -> gap_list [i ].pts_in_samples ;
171170 int64_t gap_length = adhp -> gap_list [i ].length ;
172171 int64_t gap_end = gap_start + gap_length ;
173- if (gap_end <= cursor ) {
174- removed_gap_length += gap_length ;
172+ if (gap_end <= cursor )
175173 continue ;
176- }
177174 if (gap_start >= end )
178175 break ;
179176 if (gap_start > cursor ) {
180177 int64_t decode_length = MIN (gap_start , end ) - cursor ;
181178 uint8_t * decode_buf = buf + (cursor - start ) * aohp -> output_block_align ;
182- if (decode_audio_range (decode_buf , cursor , decode_length , removed_gap_length , hp ) < 0 )
179+ if (decode_audio_range (decode_buf , cursor , decode_length , hp ) < 0 )
183180 return -1 ;
184181 }
185182 cursor = MAX (cursor , gap_end );
186- removed_gap_length += gap_length ;
187183 if (cursor >= end )
188184 return 0 ;
189185 }
190186 if (cursor < end ) {
191187 uint8_t * decode_buf = buf + (cursor - start ) * aohp -> output_block_align ;
192- if (decode_audio_range (decode_buf , cursor , end - cursor , removed_gap_length , hp ) < 0 )
188+ if (decode_audio_range (decode_buf , cursor , end - cursor , hp ) < 0 )
193189 return -1 ;
194190 }
195191 return 0 ;
0 commit comments