@@ -2076,31 +2076,40 @@ int av_render_reset(av_render_handle_t h)
20762076 av_render_msg_t msg = {
20772077 .type = AV_RENDER_MSG_CLOSE ,
20782078 };
2079- int wait_bits = 0 ;
2080- // Wait for all thread to quit
2081- if (render -> adec_res && render -> adec_res -> thread_res .thread ) {
2082- wait_bits |= render -> adec_res -> thread_res .wait_bits ;
2083- send_msg_to_thread (& render -> adec_res -> thread_res , sizeof (av_render_audio_data_t ), & msg );
2084- }
2085- if (render -> vdec_res && render -> vdec_res -> thread_res .thread ) {
2086- wait_bits |= render -> vdec_res -> thread_res .wait_bits ;
2087- send_msg_to_thread (& render -> vdec_res -> thread_res , sizeof (av_render_video_data_t ), & msg );
2088- }
2089- if (render -> a_render_res && render -> a_render_res -> thread_res .thread ) {
2090- wait_bits |= render -> a_render_res -> thread_res .wait_bits ;
2091- send_msg_to_thread (& render -> a_render_res -> thread_res , sizeof (av_render_audio_frame_t ), & msg );
2092- }
2093- if (render -> v_render_res && render -> v_render_res -> thread_res .thread ) {
2094- wait_bits |= render -> v_render_res -> thread_res .wait_bits ;
2095- send_msg_to_thread (& render -> v_render_res -> thread_res , sizeof (av_render_video_frame_t ), & msg );
2096- }
2097-
2098- if (render -> adec_res && render -> adec_res -> thread_res .thread ) {
2099- wait_bits |= render -> adec_res -> thread_res .wait_bits ;
2100- }
2101- if (wait_bits ) {
2079+ int recv_bits = 0 ;
2080+ // Wait for all thread to quit, run 2 times to avoid render thread creating during closing
2081+ for (int i = 0 ; i < 2 ; i ++ ) {
2082+ int wait_bits = 0 ;
2083+ if (render -> adec_res && render -> adec_res -> thread_res .thread ) {
2084+ if ((recv_bits & render -> adec_res -> thread_res .wait_bits ) == 0 ) {
2085+ wait_bits |= render -> adec_res -> thread_res .wait_bits ;
2086+ send_msg_to_thread (& render -> adec_res -> thread_res , sizeof (av_render_audio_data_t ), & msg );
2087+ }
2088+ }
2089+ if (render -> vdec_res && render -> vdec_res -> thread_res .thread ) {
2090+ if ((recv_bits & render -> vdec_res -> thread_res .wait_bits ) == 0 ) {
2091+ wait_bits |= render -> vdec_res -> thread_res .wait_bits ;
2092+ send_msg_to_thread (& render -> vdec_res -> thread_res , sizeof (av_render_video_data_t ), & msg );
2093+ }
2094+ }
2095+ if (render -> a_render_res && render -> a_render_res -> thread_res .thread ) {
2096+ if ((recv_bits & render -> a_render_res -> thread_res .wait_bits ) == 0 ) {
2097+ wait_bits |= render -> a_render_res -> thread_res .wait_bits ;
2098+ send_msg_to_thread (& render -> a_render_res -> thread_res , sizeof (av_render_audio_frame_t ), & msg );
2099+ }
2100+ }
2101+ if (render -> v_render_res && render -> v_render_res -> thread_res .thread ) {
2102+ if ((recv_bits & render -> v_render_res -> thread_res .wait_bits ) == 0 ) {
2103+ wait_bits |= render -> v_render_res -> thread_res .wait_bits ;
2104+ send_msg_to_thread (& render -> v_render_res -> thread_res , sizeof (av_render_video_frame_t ), & msg );
2105+ }
2106+ }
2107+ if (wait_bits == 0 ) {
2108+ break ;
2109+ }
21022110 media_lib_event_group_wait_bits (render -> event_group , wait_bits , MEDIA_LIB_MAX_LOCK_TIME );
21032111 media_lib_event_group_clr_bits (render -> event_group , wait_bits );
2112+ recv_bits |= wait_bits ;
21042113 }
21052114 ESP_LOGI (TAG , "Close done" );
21062115 dump_data (AV_RENDER_DUMP_STOP_INDEX , NULL , 0 );
0 commit comments