49
49
AD_EOF = -2 ,
50
50
AD_NEW_FMT = -3 ,
51
51
AD_WAIT = -4 ,
52
+ AD_NO_PROGRESS = -5 ,
52
53
};
53
54
54
55
// Use pitch correction only for speed adjustments by the user, not minor sync
@@ -204,6 +205,18 @@ void uninit_audio_out(struct MPContext *mpctx)
204
205
205
206
static void ao_chain_uninit (struct ao_chain * ao_c )
206
207
{
208
+ struct track * track = ao_c -> track ;
209
+ if (track ) {
210
+ assert (track -> ao_c == ao_c );
211
+ track -> ao_c = NULL ;
212
+ assert (track -> d_audio == ao_c -> audio_src );
213
+ track -> d_audio = NULL ;
214
+ audio_uninit (ao_c -> audio_src );
215
+ }
216
+
217
+ if (ao_c -> filter_src )
218
+ lavfi_set_connected (ao_c -> filter_src , false);
219
+
207
220
af_destroy (ao_c -> af );
208
221
talloc_free (ao_c -> input_frame );
209
222
talloc_free (ao_c -> ao_buffer );
@@ -213,18 +226,10 @@ static void ao_chain_uninit(struct ao_chain *ao_c)
213
226
void uninit_audio_chain (struct MPContext * mpctx )
214
227
{
215
228
if (mpctx -> ao_chain ) {
216
- struct track * track = mpctx -> current_track [0 ][STREAM_AUDIO ];
217
- assert (track );
218
- assert (track -> d_audio == mpctx -> ao_chain -> audio_src );
219
-
220
229
mixer_uninit_audio (mpctx -> mixer );
221
-
222
- audio_uninit (track -> d_audio );
223
- track -> d_audio = NULL ;
224
- mpctx -> ao_chain -> audio_src = NULL ;
225
-
226
230
ao_chain_uninit (mpctx -> ao_chain );
227
231
mpctx -> ao_chain = NULL ;
232
+
228
233
mpctx -> audio_status = STATUS_EOF ;
229
234
reselect_demux_streams (mpctx );
230
235
@@ -379,6 +384,9 @@ int init_audio_decoder(struct MPContext *mpctx, struct track *track)
379
384
return 1 ;
380
385
381
386
init_error :
387
+ if (track -> sink )
388
+ lavfi_set_connected (track -> sink , false);
389
+ track -> sink = NULL ;
382
390
audio_uninit (track -> d_audio );
383
391
track -> d_audio = NULL ;
384
392
error_on_track (mpctx , track );
@@ -387,31 +395,46 @@ int init_audio_decoder(struct MPContext *mpctx, struct track *track)
387
395
388
396
void reinit_audio_chain (struct MPContext * mpctx )
389
397
{
390
- assert (!mpctx -> ao_chain );
398
+ reinit_audio_chain_src (mpctx , NULL );
399
+ }
391
400
392
- struct track * track = mpctx -> current_track [0 ][STREAM_AUDIO ];
393
- struct sh_stream * sh = track ? track -> stream : NULL ;
394
- if (!sh ) {
395
- uninit_audio_out (mpctx );
396
- goto no_audio ;
401
+ void reinit_audio_chain_src (struct MPContext * mpctx , struct lavfi_pad * src )
402
+ {
403
+ struct track * track = NULL ;
404
+ struct sh_stream * sh = NULL ;
405
+ if (!src ) {
406
+ track = mpctx -> current_track [0 ][STREAM_AUDIO ];
407
+ if (!track )
408
+ return ;
409
+ sh = track ? track -> stream : NULL ;
410
+ if (!sh ) {
411
+ uninit_audio_out (mpctx );
412
+ goto no_audio ;
413
+ }
397
414
}
415
+ assert (!mpctx -> ao_chain );
398
416
399
417
mp_notify (mpctx , MPV_EVENT_AUDIO_RECONFIG , NULL );
400
418
401
419
struct ao_chain * ao_c = ao_c = talloc_zero (NULL , struct ao_chain );
402
420
mpctx -> ao_chain = ao_c ;
403
421
ao_c -> log = mpctx -> log ;
404
422
ao_c -> af = af_new (mpctx -> global );
405
- ao_c -> af -> replaygain_data = sh -> codec -> replaygain_data ;
423
+ if (sh )
424
+ ao_c -> af -> replaygain_data = sh -> codec -> replaygain_data ;
406
425
ao_c -> spdif_passthrough = true;
407
426
ao_c -> pts = MP_NOPTS_VALUE ;
408
427
ao_c -> ao_buffer = mp_audio_buffer_create (NULL );
409
428
ao_c -> ao = mpctx -> ao ;
410
429
411
- if (!init_audio_decoder (mpctx , track ))
412
- goto init_error ;
413
-
414
- ao_c -> audio_src = track -> d_audio ;
430
+ ao_c -> filter_src = src ;
431
+ if (!ao_c -> filter_src ) {
432
+ ao_c -> track = track ;
433
+ track -> ao_c = ao_c ;
434
+ if (!init_audio_decoder (mpctx , track ))
435
+ goto init_error ;
436
+ ao_c -> audio_src = track -> d_audio ;
437
+ }
415
438
416
439
reset_audio_state (mpctx );
417
440
@@ -597,15 +620,18 @@ static int decode_new_frame(struct ao_chain *ao_c)
597
620
if (ao_c -> input_frame )
598
621
return AD_OK ;
599
622
600
- int res = DATA_AGAIN ;
601
- while (res == DATA_AGAIN ) {
623
+ int res = DATA_EOF ;
624
+ if (ao_c -> filter_src ) {
625
+ res = lavfi_request_frame_a (ao_c -> filter_src , & ao_c -> input_frame );
626
+ } else if (ao_c -> audio_src ) {
602
627
audio_work (ao_c -> audio_src );
603
628
res = audio_get_frame (ao_c -> audio_src , & ao_c -> input_frame );
604
629
}
605
630
606
631
switch (res ) {
607
632
case DATA_OK : return AD_OK ;
608
633
case DATA_WAIT : return AD_WAIT ;
634
+ case DATA_AGAIN : return AD_NO_PROGRESS ;
609
635
case DATA_EOF : return AD_EOF ;
610
636
default : abort ();
611
637
}
@@ -633,6 +659,8 @@ static int filter_audio(struct ao_chain *ao_c, struct mp_audio_buffer *outbuf,
633
659
break ;
634
660
635
661
res = decode_new_frame (ao_c );
662
+ if (res == AD_NO_PROGRESS )
663
+ break ;
636
664
if (res < 0 ) {
637
665
// drain filters first (especially for true EOF case)
638
666
copy_output (afs , outbuf , minsamples , true);
@@ -764,6 +792,10 @@ void fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
764
792
status = filter_audio (mpctx -> ao_chain , ao_c -> ao_buffer , playsize );
765
793
if (status == AD_WAIT )
766
794
return ;
795
+ if (status == AD_NO_PROGRESS ) {
796
+ mpctx -> sleeptime = 0 ;
797
+ return ;
798
+ }
767
799
if (status == AD_NEW_FMT ) {
768
800
/* The format change isn't handled too gracefully. A more precise
769
801
* implementation would require draining buffered old-format audio
0 commit comments