Skip to content

Commit

Permalink
refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Jul 29, 2023
1 parent 72fcf08 commit b8f19a9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE libcurl)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE vendor/nlohmann-json)

target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/plugin-main.c src/url-source.cpp src/ui/RequestBuilder.cpp
src/request-data.cpp src/ui/text-render-helper.cpp)
src/request-data.cpp src/ui/text-render-helper.cpp src/url-source-info.c)

set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name})
2 changes: 0 additions & 2 deletions src/request-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ struct request_data_handler_response request_data_handler(url_source_request_dat

std::string serialize_request_data(url_source_request_data *request_data)
{
obs_log(LOG_INFO, "Serializing request data");
// Serialize the request data to a string using JSON
nlohmann::json json;
json["url"] = request_data->url;
Expand All @@ -161,7 +160,6 @@ std::string serialize_request_data(url_source_request_data *request_data)

url_source_request_data unserialize_request_data(std::string serialized_request_data)
{
obs_log(LOG_INFO, "Unserializing request data");
// Unserialize the request data from a string using JSON
nlohmann::json json;
try {
Expand Down
11 changes: 11 additions & 0 deletions src/url-source-info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "url-source.h"

struct obs_source_info url_source = {.id = "url_source",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_ASYNC_VIDEO,
.get_name = url_source_name,
.create = url_source_create,
.destroy = url_source_destroy,
.get_defaults = url_source_defaults,
.get_properties = url_source_properties,
.update = url_source_update};
26 changes: 7 additions & 19 deletions src/url-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "ui/text-render-helper.h"
#include "request-data.h"
#include "plugin-support.h"
#include "url-source.h"

#include <stdlib.h>
#include <util/threading.h>
Expand All @@ -42,13 +43,13 @@ struct url_source_data {

std::mutex curl_mutex;

static const char *url_source_name(void *unused)
const char *url_source_name(void *unused)
{
UNUSED_PARAMETER(unused);
return "URL Source";
}

static void url_source_destroy(void *data)
void url_source_destroy(void *data)
{
struct url_source_data *usd = reinterpret_cast<struct url_source_data *>(data);

Expand Down Expand Up @@ -124,7 +125,7 @@ void save_request_info_on_settings(obs_data_t *settings,
obs_data_set_string(settings, "url", request_data->url.c_str());
}

static void *url_source_create(obs_data_t *settings, obs_source_t *source)
void *url_source_create(obs_data_t *settings, obs_source_t *source)
{
struct url_source_data *usd =
reinterpret_cast<struct url_source_data *>(bzalloc(sizeof(struct url_source_data)));
Expand Down Expand Up @@ -152,7 +153,7 @@ static void *url_source_create(obs_data_t *settings, obs_source_t *source)
return usd;
}

static void url_source_update(void *data, obs_data_t *settings)
void url_source_update(void *data, obs_data_t *settings)
{
obs_log(LOG_INFO, "Updating URL Source");
struct url_source_data *usd = reinterpret_cast<struct url_source_data *>(data);
Expand All @@ -162,7 +163,7 @@ static void url_source_update(void *data, obs_data_t *settings)
save_request_info_on_settings(settings, &(usd->request_data));
}

static void url_source_defaults(obs_data_t *s)
void url_source_defaults(obs_data_t *s)
{
// Default request data
struct url_source_request_data request_data;
Expand Down Expand Up @@ -197,7 +198,7 @@ bool setup_request_button_click(obs_properties_t *, obs_property_t *, void *butt
return true;
}

static obs_properties_t *url_source_properties(void *data)
obs_properties_t *url_source_properties(void *data)
{
struct url_source_data *usd = reinterpret_cast<struct url_source_data *>(data);

Expand All @@ -215,16 +216,3 @@ static obs_properties_t *url_source_properties(void *data)

return ppts;
}

static uint32_t url_source_size(void *data)
{
UNUSED_PARAMETER(data);
return 32;
}

struct obs_source_info url_source {
.id = "url_source", .type = OBS_SOURCE_TYPE_INPUT, .output_flags = OBS_SOURCE_ASYNC_VIDEO,
.get_name = url_source_name, .create = url_source_create, .destroy = url_source_destroy,
.get_defaults = url_source_defaults, .get_properties = url_source_properties,
.update = url_source_update
};
21 changes: 21 additions & 0 deletions src/url-source.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef URL_SOURCE_H
#define URL_SOURCE_H

#include <obs-module.h>

#ifdef __cplusplus
extern "C" {
#endif

obs_properties_t *url_source_properties(void *data);
void url_source_defaults(obs_data_t *s);
void *url_source_create(obs_data_t *settings, obs_source_t *source);
void url_source_destroy(void *data);
void url_source_update(void *data, obs_data_t *settings);
const char *url_source_name(void *unused);

#ifdef __cplusplus
}
#endif

#endif /* URL_SOURCE_H */

0 comments on commit b8f19a9

Please sign in to comment.