Browse Source

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 years ago
parent
commit
ab65df74e0
1 changed files with 8 additions and 0 deletions
  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);
 	}
 
+	os_atomic_inc_long(&new_frame->refs);
+
 	pthread_mutex_unlock(&source->async_mutex);
 
 	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;
 }