Skip to content

Commit

Permalink
obs-browser: Update default size
Browse files Browse the repository at this point in the history
  • Loading branch information
cg2121 committed Feb 22, 2020
1 parent 8be8910 commit b631d4d
Showing 1 changed file with 116 additions and 1 deletion.
117 changes: 116 additions & 1 deletion obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ static void browser_source_get_defaults(obs_data_t *settings)
obs_data_set_default_bool(settings, "reroute_audio", false);
}

static void browser_source_get_defaults_v2(obs_data_t *settings)
{
struct obs_video_info ovi;
obs_get_video_info(&ovi);

obs_data_set_default_string(settings, "url",
"https://obsproject.com/browser-source");
obs_data_set_default_int(settings, "width", ovi.base_width);
obs_data_set_default_int(settings, "height", ovi.base_height);
obs_data_set_default_int(settings, "fps", 30);
#if EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED
obs_data_set_default_bool(settings, "fps_custom", false);
#else
obs_data_set_default_bool(settings, "fps_custom", true);
#endif
obs_data_set_default_bool(settings, "shutdown", false);
obs_data_set_default_bool(settings, "restart_when_active", false);
obs_data_set_default_string(settings, "css", default_css);
obs_data_set_default_bool(settings, "reroute_audio", false);
}

static bool is_local_file_modified(obs_properties_t *props, obs_property_t *,
obs_data_t *settings)
{
Expand Down Expand Up @@ -325,7 +346,8 @@ void RegisterBrowserSource()
OBS_SOURCE_AUDIO |
#endif
OBS_SOURCE_CUSTOM_DRAW | OBS_SOURCE_INTERACTION |
OBS_SOURCE_DO_NOT_DUPLICATE;
OBS_SOURCE_DO_NOT_DUPLICATE |
OBS_SOURCE_CAP_OBSOLETE;
info.get_properties = browser_source_get_properties;
info.get_defaults = browser_source_get_defaults;
info.icon_type = OBS_ICON_TYPE_BROWSER;
Expand Down Expand Up @@ -407,6 +429,98 @@ void RegisterBrowserSource()
obs_register_source(&info);
}

void RegisterBrowserSourceV2()
{
struct obs_source_info info = {};
info.id = "browser_source_v2";
info.type = OBS_SOURCE_TYPE_INPUT;
info.output_flags = OBS_SOURCE_VIDEO |
#if CHROME_VERSION_BUILD >= 3683
OBS_SOURCE_AUDIO |
#endif
OBS_SOURCE_CUSTOM_DRAW | OBS_SOURCE_INTERACTION |
OBS_SOURCE_DO_NOT_DUPLICATE;
info.get_properties = browser_source_get_properties;
info.get_defaults = browser_source_get_defaults_v2;
info.icon_type = OBS_ICON_TYPE_BROWSER;

info.get_name = [](void *) { return obs_module_text("BrowserSource"); };
info.create = [](obs_data_t *settings, obs_source_t *source) -> void * {
obs_browser_initialize();
return new BrowserSource(settings, source);
};
info.destroy = [](void *data) {
delete static_cast<BrowserSource *>(data);
};
info.update = [](void *data, obs_data_t *settings) {
static_cast<BrowserSource *>(data)->Update(settings);
};
info.get_width = [](void *data) {
return (uint32_t) static_cast<BrowserSource *>(data)->width;
};
info.get_height = [](void *data) {
return (uint32_t) static_cast<BrowserSource *>(data)->height;
};
info.video_tick = [](void *data, float) {
static_cast<BrowserSource *>(data)->Tick();
};
info.video_render = [](void *data, gs_effect_t *) {
static_cast<BrowserSource *>(data)->Render();
};
#if CHROME_VERSION_BUILD >= 3683
info.audio_mix = [](void *data, uint64_t *ts_out,
struct audio_output_data *audio_output,
size_t channels, size_t sample_rate) {
return static_cast<BrowserSource *>(data)->AudioMix(
ts_out, audio_output, channels, sample_rate);
};
info.enum_active_sources = [](void *data, obs_source_enum_proc_t cb,
void *param) {
static_cast<BrowserSource *>(data)->EnumAudioStreams(cb, param);
};
#endif
info.mouse_click = [](void *data, const struct obs_mouse_event *event,
int32_t type, bool mouse_up,
uint32_t click_count) {
static_cast<BrowserSource *>(data)->SendMouseClick(
event, type, mouse_up, click_count);
};
info.mouse_move = [](void *data, const struct obs_mouse_event *event,
bool mouse_leave) {
static_cast<BrowserSource *>(data)->SendMouseMove(event,
mouse_leave);
};
info.mouse_wheel = [](void *data, const struct obs_mouse_event *event,
int x_delta, int y_delta) {
static_cast<BrowserSource *>(data)->SendMouseWheel(
event, x_delta, y_delta);
};
info.focus = [](void *data, bool focus) {
static_cast<BrowserSource *>(data)->SendFocus(focus);
};
info.key_click = [](void *data, const struct obs_key_event *event,
bool key_up) {
static_cast<BrowserSource *>(data)->SendKeyClick(event, key_up);
};
info.show = [](void *data) {
static_cast<BrowserSource *>(data)->SetShowing(true);
};
info.hide = [](void *data) {
static_cast<BrowserSource *>(data)->SetShowing(false);
};
info.activate = [](void *data) {
BrowserSource *bs = static_cast<BrowserSource *>(data);
if (bs->restart)
bs->Refresh();
bs->SetActive(true);
};
info.deactivate = [](void *data) {
static_cast<BrowserSource *>(data)->SetActive(false);
};

obs_register_source(&info);
}

/* ========================================================================= */

extern void DispatchJSEvent(std::string eventName, std::string jsonString,
Expand Down Expand Up @@ -565,6 +679,7 @@ bool obs_module_load(void)
EnumAdapterCount();
#endif
RegisterBrowserSource();
RegisterBrowserSourceV2();
obs_frontend_add_event_callback(handle_obs_frontend_event, nullptr);

#if EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED
Expand Down

0 comments on commit b631d4d

Please sign in to comment.