Pārlūkot izejas kodu

libobs: Account for filters in source dimensions

The obs_source_get_width and obs_source_get_height functions need to
account for filters that may change their width/height such as a crop
filter or something similar.

As a side effect of this commit, because these functions need to lock
the filter mutex, these functions can no longer be used with a
const-qualified obs_source_t pointer.
jp9000 10 gadi atpakaļ
vecāks
revīzija
3510e69121
2 mainītis faili ar 64 papildinājumiem un 10 dzēšanām
  1. 62 8
      libobs/obs-source.c
  2. 2 2
      libobs/obs.h

+ 62 - 8
libobs/obs-source.c

@@ -1165,24 +1165,78 @@ void obs_source_video_render(obs_source_t *source)
 		obs_source_render_async_video(source);
 		obs_source_render_async_video(source);
 }
 }
 
 
-uint32_t obs_source_get_width(const obs_source_t *source)
+static uint32_t get_base_width(const obs_source_t *source)
 {
 {
-	if (!source_valid(source)) return 0;
-
-	if (source->info.get_width)
+	if (source->info.get_width) {
 		return source->info.get_width(source->context.data);
 		return source->info.get_width(source->context.data);
+
+	} else if (source->info.type == OBS_SOURCE_TYPE_FILTER) {
+		return get_base_width(source->filter_target);
+	}
+
 	return source->async_width;
 	return source->async_width;
 }
 }
 
 
-uint32_t obs_source_get_height(const obs_source_t *source)
+static uint32_t get_base_height(const obs_source_t *source)
 {
 {
-	if (!source_valid(source)) return 0;
-
-	if (source->info.get_height)
+	if (source->info.get_height) {
 		return source->info.get_height(source->context.data);
 		return source->info.get_height(source->context.data);
+
+	} else if (source->info.type == OBS_SOURCE_TYPE_FILTER) {
+		return get_base_height(source->filter_target);
+	}
+
 	return source->async_height;
 	return source->async_height;
 }
 }
 
 
+static uint32_t get_recurse_width(obs_source_t *source)
+{
+	uint32_t width;
+
+	pthread_mutex_lock(&source->filter_mutex);
+
+	width = (source->filters.num) ?
+		get_base_width(source->filters.array[0]) :
+		get_base_width(source);
+
+	pthread_mutex_unlock(&source->filter_mutex);
+
+	return width;
+}
+
+static uint32_t get_recurse_height(obs_source_t *source)
+{
+	uint32_t height;
+
+	pthread_mutex_lock(&source->filter_mutex);
+
+	height = (source->filters.num) ?
+		get_base_height(source->filters.array[0]) :
+		get_base_height(source);
+
+	pthread_mutex_unlock(&source->filter_mutex);
+
+	return height;
+}
+
+uint32_t obs_source_get_width(obs_source_t *source)
+{
+	if (!source_valid(source)) return 0;
+
+	return (source->info.type == OBS_SOURCE_TYPE_INPUT) ?
+		get_recurse_width(source) :
+	        get_base_width(source);
+}
+
+uint32_t obs_source_get_height(obs_source_t *source)
+{
+	if (!source_valid(source)) return 0;
+
+	return (source->info.type == OBS_SOURCE_TYPE_INPUT) ?
+		get_recurse_height(source) :
+		get_base_height(source);
+}
+
 obs_source_t *obs_filter_get_parent(const obs_source_t *filter)
 obs_source_t *obs_filter_get_parent(const obs_source_t *filter)
 {
 {
 	return filter ? filter->filter_parent : NULL;
 	return filter ? filter->filter_parent : NULL;

+ 2 - 2
libobs/obs.h

@@ -660,10 +660,10 @@ EXPORT void obs_source_update(obs_source_t *source, obs_data_t *settings);
 EXPORT void obs_source_video_render(obs_source_t *source);
 EXPORT void obs_source_video_render(obs_source_t *source);
 
 
 /** Gets the width of a source (if it has video) */
 /** Gets the width of a source (if it has video) */
-EXPORT uint32_t obs_source_get_width(const obs_source_t *source);
+EXPORT uint32_t obs_source_get_width(obs_source_t *source);
 
 
 /** Gets the height of a source (if it has video) */
 /** Gets the height of a source (if it has video) */
-EXPORT uint32_t obs_source_get_height(const obs_source_t *source);
+EXPORT uint32_t obs_source_get_height(obs_source_t *source);
 
 
 /** If the source is a filter, returns the parent source of the filter */
 /** If the source is a filter, returns the parent source of the filter */
 EXPORT obs_source_t *obs_filter_get_parent(const obs_source_t *filter);
 EXPORT obs_source_t *obs_filter_get_parent(const obs_source_t *filter);