浏览代码

libobs: Increment new frame ref when first copying

When caching a new frame, keep a reference to the frame while copying to
ensure that the frame is not potentially destroyed for whatever reason
while that data is being copied.
jp9000 10 年之前
父节点
当前提交
ab65df74e0
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      libobs/obs-source.c

+ 8 - 0
libobs/obs-source.c

@@ -1687,9 +1687,17 @@ static inline struct obs_source_frame *cache_video(struct obs_source *source,
 		da_push_back(source->async_cache, &new_af);
 		da_push_back(source->async_cache, &new_af);
 	}
 	}
 
 
+	os_atomic_inc_long(&new_frame->refs);
+
 	pthread_mutex_unlock(&source->async_mutex);
 	pthread_mutex_unlock(&source->async_mutex);
 
 
 	copy_frame_data(new_frame, frame);
 	copy_frame_data(new_frame, frame);
+
+	if (os_atomic_dec_long(&new_frame->refs) == 0) {
+		obs_source_frame_destroy(new_frame);
+		new_frame = NULL;
+	}
+
 	return new_frame;
 	return new_frame;
 }
 }