Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
obs-vst: Check hash before applying "chunk_data"
Browse files Browse the repository at this point in the history
  • Loading branch information
walker-WSH authored and jp9000 committed Jan 8, 2022
1 parent 425935a commit 9cdde97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions VSTPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ intptr_t VSTPlugin::hostCallback(AEffect *effect, int32_t opcode, int32_t index,
return result;
}

std::string VSTPlugin::getEffectPath()
{
return pluginPath;
}

std::string VSTPlugin::getChunk()
{
if (!effect) {
Expand Down
1 change: 1 addition & 0 deletions headers/VSTPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class VSTPlugin : public QObject {
~VSTPlugin();
void loadEffectFromPath(std::string path);
void unloadEffect();
std::string getEffectPath();
std::string getChunk();
void setChunk(std::string data);
void setProgram(const int programNumber);
Expand Down
19 changes: 17 additions & 2 deletions obs-vst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

#include "headers/VSTPlugin.h"
#include <QCryptographicHash>

#define OPEN_VST_SETTINGS "open_vst_settings"
#define CLOSE_VST_SETTINGS "close_vst_settings"
Expand Down Expand Up @@ -64,6 +65,18 @@ static bool close_editor_button_clicked(obs_properties_t *props, obs_property_t
return true;
}

std::string getFileMD5(const char *file)
{
QFile f(file);
if (f.open(QFile::ReadOnly)) {
QCryptographicHash hash(QCryptographicHash::Md5);
if (hash.addData(&f))
return std::string(hash.result().toHex());
}

return std::string();
}

static const char *vst_name(void *unused)
{
UNUSED_PARAMETER(unused);
Expand All @@ -90,8 +103,10 @@ static void vst_update(void *data, obs_data_t *settings)
}
vstPlugin->loadEffectFromPath(std::string(path));

std::string hash = getFileMD5(path);
const char *chunkHash = obs_data_get_string(settings, "chunk_hash");
const char *chunkData = obs_data_get_string(settings, "chunk_data");
if (chunkData && strlen(chunkData) > 0) {
if (chunkData && strlen(chunkData) > 0 && chunkHash && strlen(chunkHash) > 0 && 0 == hash.compare(chunkHash)) {
vstPlugin->setChunk(std::string(chunkData));
}
}
Expand All @@ -107,8 +122,8 @@ static void *vst_create(obs_data_t *settings, obs_source_t *filter)
static void vst_save(void *data, obs_data_t *settings)
{
VSTPlugin *vstPlugin = (VSTPlugin *)data;

obs_data_set_string(settings, "chunk_data", vstPlugin->getChunk().c_str());
obs_data_set_string(settings, "chunk_hash", getFileMD5(vstPlugin->getEffectPath().c_str()).c_str());
}

static struct obs_audio_data *vst_filter_audio(void *data, struct obs_audio_data *audio)
Expand Down

0 comments on commit 9cdde97

Please sign in to comment.