@@ -659,6 +659,8 @@ mtl_handle gst_mtl_common_init_handle(GeneralArgs* general_args,
659659 }
660660
661661 common_handle .mtl_handle_reference_count ++ ;
662+ GST_INFO ("MTL shared handle reference count incremented to: %d" ,
663+ common_handle .mtl_handle_reference_count );
662664 common_handle .mtl_handle = handle ;
663665 pthread_mutex_unlock (& common_handle .mutex );
664666 return common_handle .mtl_handle ;
@@ -669,11 +671,8 @@ mtl_handle gst_mtl_common_init_handle(GeneralArgs* general_args,
669671 * If the handle is the shared handle, the reference count is decremented.
670672 * If the reference count reaches zero, the handle is deinitialized.
671673 * If the handle is not the shared handle, it is deinitialized immediately.
672- *
673- * @param handle MTL handle to deinitialize (Null is an acceptable value then
674- * shared value will be used).
675674 */
676- gint gst_mtl_common_deinit_handle (mtl_handle handle ) {
675+ gint gst_mtl_common_deinit_handle (mtl_handle * handle ) {
677676 gint ret ;
678677
679678 if (!handle ) {
@@ -682,23 +681,33 @@ gint gst_mtl_common_deinit_handle(mtl_handle handle) {
682681 }
683682
684683 pthread_mutex_lock (& common_handle .mutex );
685- if (handle == common_handle .mtl_handle ) {
684+
685+ if (* handle == common_handle .mtl_handle ) {
686686 common_handle .mtl_handle_reference_count -- ;
687687
688688 if (common_handle .mtl_handle_reference_count > 0 ) {
689+ GST_INFO ("Shared handle is still in use, reference count: %d" ,
690+ common_handle .mtl_handle_reference_count );
689691 pthread_mutex_unlock (& common_handle .mutex );
690692 return 0 ;
693+ } else if (common_handle .mtl_handle_reference_count < 0 ) {
694+ GST_ERROR ("Invalid reference count: %d" , common_handle .mtl_handle_reference_count );
695+ pthread_mutex_unlock (& common_handle .mutex );
696+ return - EINVAL ;
691697 }
698+
699+ GST_INFO ("Deinitializing shared handle" );
692700 }
693701
694- ret = mtl_stop (handle );
702+ ret = mtl_stop (* handle );
695703 if (ret ) {
696704 GST_ERROR ("Failed to stop MTL library" );
697705 pthread_mutex_unlock (& common_handle .mutex );
698706 return ret ;
699707 }
700708
701- ret = mtl_uninit (handle );
709+ ret = mtl_uninit (* handle );
710+ * handle = NULL ;
702711 pthread_mutex_unlock (& common_handle .mutex );
703712 return ret ;
704713}
0 commit comments