libobs: Fix source type versioning system

(This also modifies image-source, obs-text, text-freetype2, and UI)

This improves source definition versioning.  To do this, it now stores
two identifier names.  One "unversioned" which is the original name, and
one "versioned" with the version number appended.

This fixes both backward compatibility with older OBS versions, and
fixes the inability to use "add existing" in OBS itself on sources
created from older version definitions.
This commit is contained in:
jp9000
2020-03-09 06:03:10 -07:00
parent ef0f21b273
commit b2302902a3
13 changed files with 122 additions and 20 deletions

View File

@@ -111,8 +111,8 @@ function script_properties()
local sources = obs.obs_enum_sources()
if sources ~= nil then
for _, source in ipairs(sources) do
source_id = obs.obs_source_get_id(source)
if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_gdiplus_v2" or source_id == "text_ft2_source_v2" then
source_id = obs.obs_source_get_unversioned_id(source)
if source_id == "text_gdiplus" or source_id == "text_ft2_source" then
local name = obs.obs_source_get_name(source)
obs.obs_property_list_add_string(p, name, name)
end

View File

@@ -66,8 +66,8 @@ def script_properties():
sources = obs.obs_enum_sources()
if sources is not None:
for source in sources:
source_id = obs.obs_source_get_id(source)
if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_gdiplus_v2" or source_id == "text_ft2_source_v2":
source_id = obs.obs_source_get_unversioned_id(source)
if source_id == "text_gdiplus" or source_id == "text_ft2_source":
name = obs.obs_source_get_name(source)
obs.obs_property_list_add_string(p, name, name)

View File

@@ -4719,6 +4719,7 @@ void OBSBasic::AddSource(const char *id)
QMenu *OBSBasic::CreateAddSourcePopupMenu()
{
const char *unversioned_type;
const char *type;
bool foundValues = false;
bool foundDeprecated = false;
@@ -4759,7 +4760,7 @@ QMenu *OBSBasic::CreateAddSourcePopupMenu()
popup->insertAction(after, popupItem);
};
while (obs_enum_input_types(idx++, &type)) {
while (obs_enum_input_types2(idx++, &type, &unversioned_type)) {
const char *name = obs_source_get_display_name(type);
uint32_t caps = obs_get_source_output_flags(type);
@@ -4767,9 +4768,9 @@ QMenu *OBSBasic::CreateAddSourcePopupMenu()
continue;
if ((caps & OBS_SOURCE_DEPRECATED) == 0) {
addSource(popup, type, name);
addSource(popup, unversioned_type, name);
} else {
addSource(deprecated, type, name);
addSource(deprecated, unversioned_type, name);
foundDeprecated = true;
}
foundValues = true;

View File

@@ -31,7 +31,7 @@ bool OBSBasicSourceSelect::EnumSources(void *data, obs_source_t *source)
OBSBasicSourceSelect *window =
static_cast<OBSBasicSourceSelect *>(data);
const char *name = obs_source_get_name(source);
const char *id = obs_source_get_id(source);
const char *id = obs_source_get_unversioned_id(source);
if (strcmp(id, window->id) == 0)
window->ui->sourceList->addItem(QT_UTF8(name));
@@ -44,7 +44,7 @@ bool OBSBasicSourceSelect::EnumGroups(void *data, obs_source_t *source)
OBSBasicSourceSelect *window =
static_cast<OBSBasicSourceSelect *>(data);
const char *name = obs_source_get_name(source);
const char *id = obs_source_get_id(source);
const char *id = obs_source_get_unversioned_id(source);
if (strcmp(id, window->id) == 0) {
OBSBasic *main =
@@ -82,7 +82,7 @@ void OBSBasicSourceSelect::OBSSourceRemoved(void *data, calldata_t *calldata)
void OBSBasicSourceSelect::SourceAdded(OBSSource source)
{
const char *name = obs_source_get_name(source);
const char *sourceId = obs_source_get_id(source);
const char *sourceId = obs_source_get_unversioned_id(source);
if (strcmp(sourceId, id) != 0)
return;
@@ -93,7 +93,7 @@ void OBSBasicSourceSelect::SourceAdded(OBSSource source)
void OBSBasicSourceSelect::SourceRemoved(OBSSource source)
{
const char *name = obs_source_get_name(source);
const char *sourceId = obs_source_get_id(source);
const char *sourceId = obs_source_get_unversioned_id(source);
if (strcmp(sourceId, id) != 0)
return;
@@ -184,7 +184,8 @@ bool AddNew(QWidget *parent, const char *id, const char *name,
QTStr("NameExists.Text"));
} else {
source = obs_source_create(id, name, NULL, nullptr);
const char *v_id = obs_get_latest_input_type_id(id);
source = obs_source_create(v_id, name, NULL, nullptr);
if (source) {
AddSourceData data;
@@ -249,7 +250,8 @@ static inline const char *GetSourceDisplayName(const char *id)
{
if (strcmp(id, "scene") == 0)
return Str("Basic.Scene");
return obs_source_get_display_name(id);
const char *v_id = obs_get_latest_input_type_id(id);
return obs_source_get_display_name(v_id);
}
Q_DECLARE_METATYPE(OBSScene);