@@ -77,6 +77,7 @@ class DeckLinkConsumer : public IDeckLinkVideoOutputCallback, public IDeckLinkAu
7777 mlt_deque m_aqueue;
7878 pthread_mutex_t m_aqueue_lock;
7979 mlt_deque m_frames;
80+ pthread_mutex_t m_frames_lock;
8081
8182 pthread_mutex_t m_op_lock;
8283 pthread_mutex_t m_op_arg_mutex;
@@ -153,6 +154,7 @@ class DeckLinkConsumer : public IDeckLinkVideoOutputCallback, public IDeckLinkAu
153154 pthread_mutex_init (&m_op_lock, &mta);
154155 pthread_mutex_init (&m_op_arg_mutex, &mta);
155156 pthread_mutex_init (&m_aqueue_lock, &mta);
157+ pthread_mutex_init (&m_frames_lock, &mta);
156158 pthread_mutexattr_destroy (&mta);
157159 pthread_cond_init (&m_op_arg_cond, nullptr );
158160 pthread_create (&m_op_thread, nullptr , op_main, this );
@@ -178,6 +180,7 @@ class DeckLinkConsumer : public IDeckLinkVideoOutputCallback, public IDeckLinkAu
178180 mlt_log_debug (getConsumer (), " %s: finished op thread\n " , __FUNCTION__);
179181
180182 pthread_mutex_destroy (&m_aqueue_lock);
183+ pthread_mutex_destroy (&m_frames_lock);
181184 pthread_mutex_destroy (&m_op_lock);
182185 pthread_mutex_destroy (&m_op_arg_mutex);
183186 pthread_cond_destroy (&m_op_arg_cond);
@@ -500,7 +503,9 @@ class DeckLinkConsumer : public IDeckLinkVideoOutputCallback, public IDeckLinkAu
500503 return false ;
501504 }
502505
506+ pthread_mutex_lock (&m_frames_lock);
503507 mlt_deque_push_back (m_frames, frame);
508+ pthread_mutex_unlock (&m_frames_lock);
504509 }
505510
506511 pthread_mutex_lock (&m_refresh_mutex);
@@ -539,9 +544,11 @@ class DeckLinkConsumer : public IDeckLinkVideoOutputCallback, public IDeckLinkAu
539544 pthread_mutex_unlock (&m_aqueue_lock);
540545
541546 m_buffer = nullptr ;
547+ pthread_mutex_lock (&m_frames_lock);
542548 while (IDeckLinkMutableVideoFrame *frame
543549 = (IDeckLinkMutableVideoFrame *) mlt_deque_pop_back (m_frames))
544550 SAFE_RELEASE (frame);
551+ pthread_mutex_unlock (&m_frames_lock);
545552
546553 mlt_consumer_stopped (getConsumer ());
547554
@@ -576,8 +583,11 @@ class DeckLinkConsumer : public IDeckLinkVideoOutputCallback, public IDeckLinkAu
576583 mlt_properties consumer_properties = MLT_CONSUMER_PROPERTIES (getConsumer ());
577584 int stride = m_width * (m_isKeyer ? 4 : 2 );
578585 int height = m_height;
579- IDeckLinkMutableVideoFrame *decklinkFrame = static_cast <IDeckLinkMutableVideoFrame *>(
580- mlt_deque_pop_front (m_frames));
586+ IDeckLinkMutableVideoFrame *decklinkFrame = nullptr ;
587+
588+ pthread_mutex_lock (&m_frames_lock);
589+ decklinkFrame = static_cast <IDeckLinkMutableVideoFrame *>(mlt_deque_pop_front (m_frames));
590+ pthread_mutex_unlock (&m_frames_lock);
581591
582592 mlt_log_debug (getConsumer (), " %s: entering\n " , __FUNCTION__);
583593
@@ -971,7 +981,9 @@ class DeckLinkConsumer : public IDeckLinkVideoOutputCallback, public IDeckLinkAu
971981 {
972982 mlt_log_debug (getConsumer (), " %s: ENTERING\n " , __FUNCTION__);
973983
984+ pthread_mutex_lock (&m_frames_lock);
974985 mlt_deque_push_back (m_frames, completedFrame);
986+ pthread_mutex_unlock (&m_frames_lock);
975987
976988 // change priority of video callback thread
977989 reprio (1 );
0 commit comments