9898#define SYSTEM_VSYNC 0xFE
9999#define SINGLE_BUF 0xFF // use single buffering instead of double
100100
101- #define CHECK_RC (cmd ) \
102- do { \
103- int rc = cmd; \
104- if (rc != 0) { \
105- MSG(ERROR, "%s:%d: " #cmd ": %s\n", __func__, \
106- __LINE__, ug_strerror(rc)); \
107- } \
108- } while (0)
109-
110101static const char * deinterlace_fp = STRINGIFY (
111102\043 version 110 \n
112103uniform sampler2D image ;
@@ -1365,11 +1356,8 @@ draw_pause()
13651356 gl_check_error_nonfatal ();
13661357}
13671358
1368- static void gl_process_frames (struct state_gl * s )
1369- {
1370- struct video_frame * frame ;
1371-
1372- struct message * msg ;
1359+ static void gl_process_msg_cursor (struct state_gl * s ) {
1360+ struct message * msg = nullptr ;
13731361 while ((msg = check_message (& s -> mod ))) {
13741362 struct msg_universal * msg_univ = (void * ) msg ;
13751363 log_msg (LOG_LEVEL_VERBOSE , MOD_NAME "Received message: %s\n" , msg_univ -> text );
@@ -1403,35 +1391,42 @@ static void gl_process_frames(struct state_gl *s)
14031391 }
14041392 }
14051393 }
1394+ }
14061395
1396+ static void
1397+ gl_process_frames (struct state_gl * s )
1398+ {
1399+ gl_process_msg_cursor (s );
1400+
1401+ struct video_frame * frame = nullptr ;
1402+
1403+ CHK_PTHR (pthread_mutex_lock (& s -> lock ));
14071404 {
1408- CHECK_RC (pthread_mutex_lock (& s -> lock ));
14091405 time_ns_t timeout_ns =
14101406 MIN (2.0 / s -> current_display_desc .fps , 0.1 ) * NS_IN_SEC ;
14111407 while (simple_linked_list_size (s -> frame_queue ) == 0 ) {
14121408 int rc = ug_pthread_cond_timedwait (& s -> new_frame_ready_cv ,
14131409 & s -> lock , & timeout_ns );
14141410 if (rc != 0 ) {
1415- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
1416- return ;
1411+ goto unlock ;
14171412 }
14181413 }
14191414 frame = (struct video_frame * ) simple_linked_list_pop (s -> frame_queue );
1420- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
1421- CHECK_RC (pthread_cond_signal (& s -> frame_consumed_cv ));
1415+ }
1416+ unlock :
1417+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
14221418
1423- if (!frame ) {
1424- return ;
1425- }
1419+ CHK_PTHR (pthread_cond_signal (& s -> frame_consumed_cv ));
14261420
1427- glfwMakeContextCurrent (s -> window );
1421+ if (!frame ) {
1422+ return ;
14281423 }
14291424
14301425 if (!video_desc_eq (video_desc_from_frame (frame ), s -> current_display_desc )) {
14311426 gl_reconfigure_screen (s , video_desc_from_frame (frame ));
14321427 }
14331428
1434- CHECK_RC (pthread_mutex_lock (& s -> lock ));
1429+ CHK_PTHR (pthread_mutex_lock (& s -> lock ));
14351430 if (s -> current_frame ) {
14361431 if (s -> paused ) {
14371432 SWAP_PTR (frame , s -> current_frame );
@@ -1441,7 +1436,7 @@ static void gl_process_frames(struct state_gl *s)
14411436 s -> current_frame );
14421437 }
14431438 s -> current_frame = frame ;
1444- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
1439+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
14451440
14461441 glBindTexture (GL_TEXTURE_2D , s -> texture_display );
14471442
@@ -1635,10 +1630,10 @@ display_gl_print_depth(GLFWmonitor *monitor)
16351630
16361631static void display_gl_render_last (GLFWwindow * win ) {
16371632 struct state_gl * s = glfwGetWindowUserPointer (win );
1638- CHECK_RC (pthread_mutex_lock (& s -> lock ));
1633+ CHK_PTHR (pthread_mutex_lock (& s -> lock ));
16391634 struct video_frame * f = s -> current_frame ;
16401635 s -> current_frame = nullptr ;
1641- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
1636+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
16421637 if (!f ) {
16431638 return ;
16441639 }
@@ -2346,9 +2341,9 @@ static void display_gl_done(void *state)
23462341 simple_linked_list_destroy (s -> frame_queue );
23472342 simple_linked_list_destroy (s -> free_frame_queue );
23482343
2349- CHECK_RC (pthread_cond_destroy (& s -> new_frame_ready_cv ));
2350- CHECK_RC (pthread_cond_destroy (& s -> frame_consumed_cv ));
2351- CHECK_RC (pthread_mutex_destroy (& s -> lock ));
2344+ CHK_PTHR (pthread_cond_destroy (& s -> new_frame_ready_cv ));
2345+ CHK_PTHR (pthread_cond_destroy (& s -> frame_consumed_cv ));
2346+ CHK_PTHR (pthread_mutex_destroy (& s -> lock ));
23522347
23532348 free (s );
23542349}
@@ -2358,7 +2353,7 @@ static struct video_frame * display_gl_getf(void *state)
23582353 struct state_gl * s = (struct state_gl * ) state ;
23592354 assert (s -> magic == MAGIC_GL );
23602355
2361- CHECK_RC (pthread_mutex_lock (& s -> lock ));
2356+ CHK_PTHR (pthread_mutex_lock (& s -> lock ));
23622357 while (simple_linked_list_size (s -> free_frame_queue ) > 0 ) {
23632358 struct video_frame * buffer =
23642359 simple_linked_list_pop (s -> free_frame_queue );
@@ -2368,7 +2363,7 @@ static struct video_frame * display_gl_getf(void *state)
23682363 }
23692364 vf_free (buffer );
23702365 }
2371- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
2366+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
23722367
23732368 struct video_frame * buffer = vf_alloc_desc_data (s -> current_desc );
23742369 vf_clear (buffer );
@@ -2383,24 +2378,24 @@ static bool display_gl_putf(void *state, struct video_frame *frame, long long ti
23832378
23842379 if (!frame ) {
23852380 glfwSetWindowShouldClose (s -> window , GLFW_TRUE );
2386- CHECK_RC (pthread_mutex_lock (& s -> lock ));
2381+ CHK_PTHR (pthread_mutex_lock (& s -> lock ));
23872382 simple_linked_list_append (s -> frame_queue , frame );
2388- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
2389- CHECK_RC (pthread_cond_signal (& s -> new_frame_ready_cv ));
2383+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
2384+ CHK_PTHR (pthread_cond_signal (& s -> new_frame_ready_cv ));
23902385 return true;
23912386 }
23922387
2393- CHECK_RC (pthread_mutex_lock (& s -> lock ));
2388+ CHK_PTHR (pthread_mutex_lock (& s -> lock ));
23942389 switch (timeout_ns ) {
23952390 case PUTF_DISCARD :
23962391 vf_recycle (frame );
23972392 simple_linked_list_append (s -> free_frame_queue , frame );
2398- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
2393+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
23992394 return 0 ;
24002395 case PUTF_BLOCKING :
24012396 while (simple_linked_list_size (s -> frame_queue ) >=
24022397 MAX_BUFFER_SIZE ) {
2403- CHECK_RC (pthread_cond_wait (
2398+ CHK_PTHR (pthread_cond_wait (
24042399 & s -> frame_consumed_cv , & s -> lock ));
24052400 }
24062401 break ;
@@ -2422,13 +2417,13 @@ static bool display_gl_putf(void *state, struct video_frame *frame, long long ti
24222417 MSG (VERBOSE , "1 frame(s) dropped!\n" );
24232418 vf_recycle (frame );
24242419 simple_linked_list_append (s -> free_frame_queue , frame );
2425- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
2420+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
24262421 return false;
24272422 }
24282423 simple_linked_list_append (s -> frame_queue , frame );
24292424
2430- CHECK_RC (pthread_mutex_unlock (& s -> lock ));
2431- CHECK_RC (pthread_cond_signal (& s -> new_frame_ready_cv ));
2425+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
2426+ CHK_PTHR (pthread_cond_signal (& s -> new_frame_ready_cv ));
24322427
24332428 return !s -> paused ;
24342429}
0 commit comments