libobs: Deprecate obs object addref functions

Deprecates:
obs_source_addref()
obs_output_addref()
obs_encoder_addref()
obs_service_addref()
obs_scene_addref()

These functions should be considered unsafe and not used. Instead, use:
obs_source_get_ref()
obs_output_get_ref()
obs_encoder_get_ref()
obs_service_get_ref()
obs_scene_get_ref()

These functions return a pointer to the incremented object only if the
object is still valid, otherwise they will return null, indicating that
the object is no longer valid or is unsafe to use.

The reason why this is being done is because certain third party plugins
seem to be using addref, and are somehow managing to call addref on
sources that have already been fully released. For the sake of safety,
almost all usage of these functions within OBS have also been replaced
as well.
master
Jim 2022-01-24 12:07:02 -08:00 committed by jp9000
parent 0523c2e5e9
commit 03d9bda387
10 changed files with 66 additions and 6 deletions

View File

@ -34,6 +34,7 @@
#define DEPRECATED_START
#define DEPRECATED_END
#define OBS_EXTERNAL_DEPRECATED
#define EXPORT
%rename(blog) wrap_blog;

View File

@ -34,6 +34,7 @@
#define DEPRECATED_START
#define DEPRECATED_END
#define OBS_EXTERNAL_DEPRECATED
#define EXPORT
%rename(blog) wrap_blog;

View File

@ -326,6 +326,16 @@ General Encoder Functions
Adds/releases a reference to an encoder. When the last reference is
released, the encoder is destroyed.
.. deprecated:: 27.2.0
Use :c:func:`obs_encoder_get_ref()` instead.
---------------------
.. function:: obs_encoder_t *obs_encoder_get_ref(obs_encoder_t *encoder)
Returns an incremented reference if still valid, otherwise returns
*NULL*.
---------------------
.. function:: obs_weak_encoder_t *obs_encoder_get_weak_encoder(obs_encoder_t *encoder)

View File

@ -339,6 +339,16 @@ General Output Functions
Adds/releases a reference to an output. When the last reference is
released, the output is destroyed.
.. deprecated:: 27.2.0
Use :c:func:`obs_output_get_ref()` instead.
---------------------
.. function:: obs_output_t *obs_output_get_ref(obs_output_t *output)
Returns an incremented reference if still valid, otherwise returns
*NULL*.
---------------------
.. function:: obs_weak_output_t *obs_output_get_weak_output(obs_output_t *output)

View File

@ -201,6 +201,16 @@ General Scene Functions
Adds/releases a reference to a scene.
.. deprecated:: 27.2.0
Use :c:func:`obs_scene_get_ref()` instead.
---------------------
.. function:: obs_scene_t *obs_scene_get_ref(obs_scene_t *scene)
Returns an incremented reference if still valid, otherwise returns
*NULL*.
---------------------
.. function:: obs_sceneitem_t *obs_scene_add(obs_scene_t *scene, obs_source_t *source)

View File

@ -185,6 +185,16 @@ General Service Functions
Adds/releases a reference to a service. When the last reference is
released, the service is destroyed.
.. deprecated:: 27.2.0
Use :c:func:`obs_service_get_ref()` instead.
---------------------
.. function:: obs_service_t *obs_service_get_ref(obs_service_t *service)
Returns an incremented reference if still valid, otherwise returns
*NULL*.
---------------------
.. function:: obs_weak_service_t *obs_service_get_weak_service(obs_service_t *service)

View File

@ -165,7 +165,7 @@ Source Definition Structure (obs_source_info)
- **OBS_SOURCE_SRGB** - Source understands SRGB rendering
- **OBS_SOURCE_CAP_DONT_SHOW_PROPERTIES** - Source type prefers not
to have its properties shown on creation (prefers to rely on
to have its properties shown on creation (prefers to rely on
defaults first)
.. member:: const char *(*obs_source_info.get_name)(void *type_data)
@ -737,6 +737,16 @@ General Source Functions
Adds/releases a reference to a source. When the last reference is
released, the source is destroyed.
.. deprecated:: 27.2.0
Use :c:func:`obs_source_get_ref()` instead.
---------------------
.. function:: obs_source_t *obs_source_get_ref(obs_source_t *source)
Returns an incremented reference if still valid, otherwise returns
*NULL*.
---------------------
.. function:: obs_weak_source_t *obs_source_get_weak_source(obs_source_t *source)

View File

@ -11,6 +11,8 @@ if (NOT "${FFMPEG_AVCODEC_LIBRARIES}" STREQUAL "")
list(REMOVE_ITEM FFMPEG_LIBRARIES ${FFMPEG_AVCODEC_LIBRARIES})
endif()
add_definitions(-DIS_LIBOBS=1)
if(DEBUG_FFMPEG_MUX)
add_definitions(-DSHOW_SUBPROCESSES)
endif()

View File

@ -919,7 +919,7 @@ EXPORT obs_source_t *obs_source_duplicate(obs_source_t *source,
* Adds/releases a reference to a source. When the last reference is
* released, the source is destroyed.
*/
EXPORT void obs_source_addref(obs_source_t *source);
OBS_EXTERNAL_DEPRECATED EXPORT void obs_source_addref(obs_source_t *source);
EXPORT void obs_source_release(obs_source_t *source);
EXPORT void obs_weak_source_addref(obs_weak_source_t *weak);
@ -1590,7 +1590,7 @@ enum obs_scene_duplicate_type {
EXPORT obs_scene_t *obs_scene_duplicate(obs_scene_t *scene, const char *name,
enum obs_scene_duplicate_type type);
EXPORT void obs_scene_addref(obs_scene_t *scene);
OBS_EXTERNAL_DEPRECATED EXPORT void obs_scene_addref(obs_scene_t *scene);
EXPORT void obs_scene_release(obs_scene_t *scene);
EXPORT obs_scene_t *obs_scene_get_ref(obs_scene_t *scene);
@ -1869,7 +1869,7 @@ EXPORT obs_output_t *obs_output_create(const char *id, const char *name,
* Adds/releases a reference to an output. When the last reference is
* released, the output is destroyed.
*/
EXPORT void obs_output_addref(obs_output_t *output);
OBS_EXTERNAL_DEPRECATED EXPORT void obs_output_addref(obs_output_t *output);
EXPORT void obs_output_release(obs_output_t *output);
EXPORT void obs_weak_output_addref(obs_weak_output_t *weak);
@ -2160,7 +2160,7 @@ EXPORT obs_encoder_t *obs_audio_encoder_create(const char *id, const char *name,
* Adds/releases a reference to an encoder. When the last reference is
* released, the encoder is destroyed.
*/
EXPORT void obs_encoder_addref(obs_encoder_t *encoder);
OBS_EXTERNAL_DEPRECATED EXPORT void obs_encoder_addref(obs_encoder_t *encoder);
EXPORT void obs_encoder_release(obs_encoder_t *encoder);
EXPORT void obs_weak_encoder_addref(obs_weak_encoder_t *weak);
@ -2319,7 +2319,7 @@ EXPORT obs_service_t *obs_service_create_private(const char *id,
* Adds/releases a reference to a service. When the last reference is
* released, the service is destroyed.
*/
EXPORT void obs_service_addref(obs_service_t *service);
OBS_EXTERNAL_DEPRECATED EXPORT void obs_service_addref(obs_service_t *service);
EXPORT void obs_service_release(obs_service_t *service);
EXPORT void obs_weak_service_addref(obs_weak_service_t *weak);

View File

@ -33,6 +33,12 @@
#define FORCE_INLINE inline __attribute__((always_inline))
#endif
#if defined(IS_LIBOBS) || defined(SWIG)
#define OBS_EXTERNAL_DEPRECATED
#else
#define OBS_EXTERNAL_DEPRECATED OBS_DEPRECATED
#endif
#ifdef _MSC_VER
#define EXPORT __declspec(dllexport)
#else