@@ -578,14 +578,26 @@ int cyanrip_send_pcm_to_encoders(cyanrip_ctx *ctx, cyanrip_enc_ctx **enc_ctx,
578
578
return ret ;
579
579
}
580
580
581
+ void cyanrip_immediate_stop_encoding (cyanrip_ctx * ctx , cyanrip_track * t )
582
+ {
583
+ for (int i = 0 ; i < ctx -> settings .outputs_num ; i ++ ) {
584
+ cyanrip_enc_ctx * s = t -> enc_ctx [i ];
585
+ if (s )
586
+ atomic_store (& s -> quit , 1 );
587
+ }
588
+ }
589
+
581
590
int cyanrip_reset_encoding (cyanrip_ctx * ctx , cyanrip_track * t )
582
591
{
592
+ cyanrip_immediate_stop_encoding (ctx , t );
593
+
583
594
for (int i = 0 ; i < ctx -> settings .outputs_num ; i ++ ) {
584
595
cyanrip_enc_ctx * s = t -> enc_ctx [i ];
585
596
586
- atomic_store (& s -> quit , 1 );
587
- pthread_mutex_unlock (& s -> lock );
588
- s -> mutex_held = 0 ;
597
+ if (s -> mutex_held ) {
598
+ pthread_mutex_unlock (& s -> lock );
599
+ s -> mutex_held = 0 ;
600
+ }
589
601
}
590
602
591
603
for (int i = 0 ; i < ctx -> settings .outputs_num ; i ++ )
@@ -808,13 +820,12 @@ int cyanrip_end_track_encoding(cyanrip_enc_ctx **s)
808
820
809
821
ctx = * s ;
810
822
811
- atomic_store (& ctx -> quit , 1 );
812
-
813
823
if (ctx -> mutex_held ) {
814
824
pthread_mutex_unlock (& ctx -> lock );
815
825
ctx -> mutex_held = 0 ;
816
826
}
817
827
828
+ /* Send EOF, needed in case we haven't sent it yet and the user cancels. */
818
829
cr_frame_fifo_push (ctx -> fifo , NULL );
819
830
pthread_join (ctx -> thread , NULL );
820
831
pthread_mutex_destroy (& ctx -> lock );
@@ -831,6 +842,8 @@ int cyanrip_end_track_encoding(cyanrip_enc_ctx **s)
831
842
av_buffer_unref (& ctx -> packet_fifo );
832
843
av_packet_free (& ctx -> cover_art_pkt );
833
844
845
+ atomic_store (& ctx -> quit , 0 );
846
+
834
847
int status = ctx -> status ;
835
848
av_freep (s );
836
849
return status ;
0 commit comments