Imported Upstream version 0.13.2+dsfg1
This commit is contained in:
commit
fb3990e9e5
2036 changed files with 287360 additions and 0 deletions
10
test/CMakeLists.txt
Normal file
10
test/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
add_subdirectory(test-input)
|
||||
|
||||
if(WIN32)
|
||||
add_subdirectory(win)
|
||||
endif()
|
||||
|
||||
if(APPLE AND UNIX)
|
||||
add_subdirectory(osx)
|
||||
endif()
|
||||
18
test/osx/CMakeLists.txt
Normal file
18
test/osx/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
project(osx-text)
|
||||
|
||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
|
||||
|
||||
find_library(COCOA Cocoa)
|
||||
include_directories(${COCOA})
|
||||
|
||||
add_definitions(-fobjc-arc)
|
||||
|
||||
set(osx-test_SOURCES
|
||||
test.mm)
|
||||
|
||||
add_executable(osx_test
|
||||
${osx-test_SOURCES})
|
||||
target_link_libraries(osx_test
|
||||
libobs
|
||||
${COCOA})
|
||||
define_graphic_modules(osx_test)
|
||||
192
test/osx/test.mm
Normal file
192
test/osx/test.mm
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <OpenGL/OpenGL.h>
|
||||
|
||||
#include <util/base.h>
|
||||
#include <obs.h>
|
||||
|
||||
static const int cx = 800;
|
||||
static const int cy = 600;
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
template <typename T, typename D_T, D_T D>
|
||||
struct OBSUniqueHandle : std::unique_ptr<T, std::function<D_T>>
|
||||
{
|
||||
using base = std::unique_ptr<T, std::function<D_T>>;
|
||||
explicit OBSUniqueHandle(T *obj=nullptr) : base(obj, D) {}
|
||||
operator T*() { return base::get(); }
|
||||
};
|
||||
|
||||
#define DECLARE_DELETER(x) decltype(x), x
|
||||
|
||||
using SourceContext = OBSUniqueHandle<obs_source,
|
||||
DECLARE_DELETER(obs_source_release)>;
|
||||
|
||||
using SceneContext = OBSUniqueHandle<obs_scene,
|
||||
DECLARE_DELETER(obs_scene_release)>;
|
||||
|
||||
using DisplayContext = OBSUniqueHandle<obs_display,
|
||||
DECLARE_DELETER(obs_display_destroy)>;
|
||||
|
||||
#undef DECLARE_DELETER
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
static void CreateOBS()
|
||||
{
|
||||
if (!obs_startup("en", nullptr))
|
||||
throw "Couldn't create OBS";
|
||||
|
||||
struct obs_video_info ovi;
|
||||
ovi.adapter = 0;
|
||||
ovi.fps_num = 30000;
|
||||
ovi.fps_den = 1001;
|
||||
ovi.graphics_module = DL_OPENGL;
|
||||
ovi.output_format = VIDEO_FORMAT_RGBA;
|
||||
ovi.base_width = cx;
|
||||
ovi.base_height = cy;
|
||||
ovi.output_width = cx;
|
||||
ovi.output_height = cy;
|
||||
|
||||
if (obs_reset_video(&ovi) != 0)
|
||||
throw "Couldn't initialize video";
|
||||
}
|
||||
|
||||
static DisplayContext CreateDisplay(NSView *view)
|
||||
{
|
||||
gs_init_data info = {};
|
||||
info.cx = cx;
|
||||
info.cy = cy;
|
||||
info.format = GS_RGBA;
|
||||
info.zsformat = GS_ZS_NONE;
|
||||
info.window.view = view;
|
||||
|
||||
return DisplayContext{obs_display_create(&info)};
|
||||
}
|
||||
|
||||
static SceneContext SetupScene()
|
||||
{
|
||||
/* ------------------------------------------------------ */
|
||||
/* load modules */
|
||||
obs_load_all_modules();
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* create source */
|
||||
SourceContext source{obs_source_create("random", "a test source",
|
||||
nullptr, nullptr)};
|
||||
if (!source)
|
||||
throw "Couldn't create random test source";
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* create scene and add source to scene */
|
||||
SceneContext scene{obs_scene_create("test scene")};
|
||||
if (!scene)
|
||||
throw "Couldn't create scene";
|
||||
|
||||
obs_scene_add(scene, source);
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* set the scene as the primary draw source and go */
|
||||
obs_set_output_source(0, obs_scene_get_source(scene));
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
@interface OBSTest : NSObject<NSApplicationDelegate, NSWindowDelegate>
|
||||
{
|
||||
NSWindow *win;
|
||||
NSView *view;
|
||||
DisplayContext display;
|
||||
SceneContext scene;
|
||||
}
|
||||
- (void)applicationDidFinishLaunching:(NSNotification*)notification;
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)app;
|
||||
- (void)windowWillClose:(NSNotification*)notification;
|
||||
@end
|
||||
|
||||
@implementation OBSTest
|
||||
- (void)applicationDidFinishLaunching:(NSNotification*)notification
|
||||
{
|
||||
UNUSED_PARAMETER(notification);
|
||||
|
||||
try {
|
||||
NSRect content_rect = NSMakeRect(0, 0, cx, cy);
|
||||
win = [[NSWindow alloc]
|
||||
initWithContentRect:content_rect
|
||||
styleMask:NSTitledWindowMask | NSClosableWindowMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
if (!win)
|
||||
throw "Could not create window";
|
||||
|
||||
view = [[NSView alloc] initWithFrame:content_rect];
|
||||
if (!view)
|
||||
throw "Could not create view";
|
||||
|
||||
CreateOBS();
|
||||
|
||||
win.title = @"foo";
|
||||
win.delegate = self;
|
||||
win.contentView = view;
|
||||
|
||||
[win orderFrontRegardless];
|
||||
[win center];
|
||||
[win makeMainWindow];
|
||||
|
||||
display = CreateDisplay(view);
|
||||
|
||||
scene = SetupScene();
|
||||
|
||||
obs_display_add_draw_callback(display.get(),
|
||||
[](void *, uint32_t, uint32_t) {
|
||||
obs_render_main_view();
|
||||
}, nullptr);
|
||||
|
||||
} catch (char const *error) {
|
||||
NSLog(@"%s\n", error);
|
||||
|
||||
[NSApp terminate:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)app
|
||||
{
|
||||
UNUSED_PARAMETER(app);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)windowWillClose:(NSNotification*)notification
|
||||
{
|
||||
UNUSED_PARAMETER(notification);
|
||||
|
||||
obs_set_output_source(0, nullptr);
|
||||
scene.reset();
|
||||
display.reset();
|
||||
|
||||
obs_shutdown();
|
||||
NSLog(@"Number of memory leaks: %lu", bnum_allocs());
|
||||
}
|
||||
@end
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
int main()
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSApplication *app = [NSApplication sharedApplication];
|
||||
OBSTest *test = [[OBSTest alloc] init];
|
||||
app.delegate = test;
|
||||
|
||||
[app run];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
test/test-input/CMakeLists.txt
Normal file
24
test/test-input/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
project(test-input)
|
||||
|
||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
|
||||
|
||||
if(MSVC)
|
||||
set(test-input_PLATFORM_DEPS
|
||||
w32-pthreads)
|
||||
endif()
|
||||
|
||||
set(test-input_SOURCES
|
||||
${test-input_PLATFORM_SOURCES}
|
||||
test-filter.c
|
||||
test-input.c
|
||||
test-sinewave.c
|
||||
test-random.c)
|
||||
|
||||
add_library(test-input MODULE
|
||||
${test-input_SOURCES})
|
||||
|
||||
target_link_libraries(test-input
|
||||
${test-input_PLATFORM_DEPS}
|
||||
libobs)
|
||||
|
||||
install_obs_plugin_with_data(test-input data)
|
||||
35
test/test-input/data/draw.effect
Normal file
35
test/test-input/data/draw.effect
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform texture2d diffuse;
|
||||
|
||||
sampler_state texSampler {
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
Filter = Linear;
|
||||
};
|
||||
|
||||
struct VertexInOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertexInOut VShader(VertexInOut vert_in)
|
||||
{
|
||||
VertexInOut vert_out;
|
||||
vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = vert_in.uv;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PShader(VertexInOut fragment_in) : TARGET
|
||||
{
|
||||
return diffuse.Sample(texSampler, fragment_in.uv);
|
||||
}
|
||||
|
||||
technique Default
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VShader(vert_in);
|
||||
pixel_shader = PShader(fragment_in);
|
||||
}
|
||||
}
|
||||
37
test/test-input/data/test.effect
Normal file
37
test/test-input/data/test.effect
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform texture2d image;
|
||||
|
||||
uniform float4 color = {0.5, 1.0, 0.5, 1.0};
|
||||
|
||||
sampler_state texSampler {
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
Filter = Linear;
|
||||
};
|
||||
|
||||
struct VertexInOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertexInOut VShader(VertexInOut vert_in)
|
||||
{
|
||||
VertexInOut vert_out;
|
||||
vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = vert_in.uv;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PShader(VertexInOut fragment_in) : TARGET
|
||||
{
|
||||
return image.Sample(texSampler, fragment_in.uv) * color;
|
||||
}
|
||||
|
||||
technique Draw
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VShader(vert_in);
|
||||
pixel_shader = PShader(fragment_in);
|
||||
}
|
||||
}
|
||||
69
test/test-input/test-filter.c
Normal file
69
test/test-input/test-filter.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#include <obs-module.h>
|
||||
|
||||
struct test_filter {
|
||||
obs_source_t *source;
|
||||
gs_effect_t *whatever;
|
||||
};
|
||||
|
||||
static const char *filter_getname(void)
|
||||
{
|
||||
return "Test";
|
||||
}
|
||||
|
||||
static void filter_destroy(void *data)
|
||||
{
|
||||
struct test_filter *tf = data;
|
||||
|
||||
if (tf) {
|
||||
obs_enter_graphics();
|
||||
|
||||
gs_effect_destroy(tf->whatever);
|
||||
bfree(tf);
|
||||
|
||||
obs_leave_graphics();
|
||||
}
|
||||
}
|
||||
|
||||
static void *filter_create(obs_data_t *settings, obs_source_t *source)
|
||||
{
|
||||
struct test_filter *tf = bzalloc(sizeof(struct test_filter));
|
||||
char *effect_file;
|
||||
|
||||
obs_enter_graphics();
|
||||
|
||||
effect_file = obs_module_file("test.effect");
|
||||
|
||||
tf->source = source;
|
||||
tf->whatever = gs_effect_create_from_file(effect_file, NULL);
|
||||
bfree(effect_file);
|
||||
if (!tf->whatever) {
|
||||
filter_destroy(tf);
|
||||
tf = NULL;
|
||||
}
|
||||
|
||||
obs_leave_graphics();
|
||||
|
||||
UNUSED_PARAMETER(settings);
|
||||
return tf;
|
||||
}
|
||||
|
||||
static void filter_render(void *data, gs_effect_t *effect)
|
||||
{
|
||||
struct test_filter *tf = data;
|
||||
|
||||
obs_source_process_filter_begin(tf->source, GS_RGBA,
|
||||
OBS_ALLOW_DIRECT_RENDERING);
|
||||
obs_source_process_filter_end(tf->source, tf->whatever, 0, 0);
|
||||
|
||||
UNUSED_PARAMETER(effect);
|
||||
}
|
||||
|
||||
struct obs_source_info test_filter = {
|
||||
.id = "test_filter",
|
||||
.type = OBS_SOURCE_TYPE_FILTER,
|
||||
.output_flags = OBS_SOURCE_VIDEO,
|
||||
.get_name = filter_getname,
|
||||
.create = filter_create,
|
||||
.destroy = filter_destroy,
|
||||
.video_render = filter_render
|
||||
};
|
||||
15
test/test-input/test-input.c
Normal file
15
test/test-input/test-input.c
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <obs-module.h>
|
||||
|
||||
OBS_DECLARE_MODULE()
|
||||
|
||||
extern struct obs_source_info test_random;
|
||||
extern struct obs_source_info test_sinewave;
|
||||
extern struct obs_source_info test_filter;
|
||||
|
||||
bool obs_module_load(void)
|
||||
{
|
||||
obs_register_source(&test_random);
|
||||
obs_register_source(&test_sinewave);
|
||||
obs_register_source(&test_filter);
|
||||
return true;
|
||||
}
|
||||
106
test/test-input/test-random.c
Normal file
106
test/test-input/test-random.c
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#include <stdlib.h>
|
||||
#include <util/threading.h>
|
||||
#include <util/platform.h>
|
||||
#include <obs.h>
|
||||
|
||||
struct random_tex {
|
||||
obs_source_t *source;
|
||||
os_event_t *stop_signal;
|
||||
pthread_t thread;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
static const char *random_getname(void)
|
||||
{
|
||||
return "20x20 Random Pixel Texture Source (Test)";
|
||||
}
|
||||
|
||||
static void random_destroy(void *data)
|
||||
{
|
||||
struct random_tex *rt = data;
|
||||
|
||||
if (rt) {
|
||||
if (rt->initialized) {
|
||||
os_event_signal(rt->stop_signal);
|
||||
pthread_join(rt->thread, NULL);
|
||||
}
|
||||
|
||||
os_event_destroy(rt->stop_signal);
|
||||
bfree(rt);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void fill_texture(uint32_t *pixels)
|
||||
{
|
||||
size_t x, y;
|
||||
|
||||
for (y = 0; y < 20; y++) {
|
||||
for (x = 0; x < 20; x++) {
|
||||
uint32_t pixel = 0;
|
||||
pixel |= (rand()%256);
|
||||
pixel |= (rand()%256) << 8;
|
||||
pixel |= (rand()%256) << 16;
|
||||
//pixel |= (rand()%256) << 24;
|
||||
//pixel |= 0xFFFFFFFF;
|
||||
pixels[y*20 + x] = pixel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void *video_thread(void *data)
|
||||
{
|
||||
struct random_tex *rt = data;
|
||||
uint32_t pixels[20*20];
|
||||
uint64_t cur_time = os_gettime_ns();
|
||||
|
||||
struct obs_source_frame frame = {
|
||||
.data = {[0] = (uint8_t*)pixels},
|
||||
.linesize = {[0] = 20*4},
|
||||
.width = 20,
|
||||
.height = 20,
|
||||
.format = VIDEO_FORMAT_BGRX
|
||||
};
|
||||
|
||||
while (os_event_try(rt->stop_signal) == EAGAIN) {
|
||||
fill_texture(pixels);
|
||||
|
||||
frame.timestamp = cur_time;
|
||||
|
||||
obs_source_output_video(rt->source, &frame);
|
||||
|
||||
os_sleepto_ns(cur_time += 250000000);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *random_create(obs_data_t *settings, obs_source_t *source)
|
||||
{
|
||||
struct random_tex *rt = bzalloc(sizeof(struct random_tex));
|
||||
rt->source = source;
|
||||
|
||||
if (os_event_init(&rt->stop_signal, OS_EVENT_TYPE_MANUAL) != 0) {
|
||||
random_destroy(rt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pthread_create(&rt->thread, NULL, video_thread, rt) != 0) {
|
||||
random_destroy(rt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rt->initialized = true;
|
||||
|
||||
UNUSED_PARAMETER(settings);
|
||||
UNUSED_PARAMETER(source);
|
||||
return rt;
|
||||
}
|
||||
|
||||
struct obs_source_info test_random = {
|
||||
.id = "random",
|
||||
.type = OBS_SOURCE_TYPE_INPUT,
|
||||
.output_flags = OBS_SOURCE_ASYNC_VIDEO,
|
||||
.get_name = random_getname,
|
||||
.create = random_create,
|
||||
.destroy = random_destroy,
|
||||
};
|
||||
110
test/test-input/test-sinewave.c
Normal file
110
test/test-input/test-sinewave.c
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#include <math.h>
|
||||
#include <util/bmem.h>
|
||||
#include <util/threading.h>
|
||||
#include <util/platform.h>
|
||||
#include <obs.h>
|
||||
|
||||
struct sinewave_data {
|
||||
bool initialized_thread;
|
||||
pthread_t thread;
|
||||
os_event_t *event;
|
||||
obs_source_t *source;
|
||||
};
|
||||
|
||||
/* middle C */
|
||||
static const double rate = 261.63/48000.0;
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
#endif
|
||||
|
||||
#define M_PI_X2 M_PI*2
|
||||
|
||||
static void *sinewave_thread(void *pdata)
|
||||
{
|
||||
struct sinewave_data *swd = pdata;
|
||||
uint64_t last_time = os_gettime_ns();
|
||||
uint64_t ts = 0;
|
||||
double cos_val = 0.0;
|
||||
uint8_t bytes[480];
|
||||
|
||||
while (os_event_try(swd->event) == EAGAIN) {
|
||||
if (!os_sleepto_ns(last_time += 10000000))
|
||||
last_time = os_gettime_ns();
|
||||
|
||||
for (size_t i = 0; i < 480; i++) {
|
||||
cos_val += rate * M_PI_X2;
|
||||
if (cos_val > M_PI_X2)
|
||||
cos_val -= M_PI_X2;
|
||||
|
||||
double wave = cos(cos_val) * 0.5;
|
||||
bytes[i] = (uint8_t)((wave+1.0)*0.5 * 255.0);
|
||||
}
|
||||
|
||||
struct obs_source_audio data;
|
||||
data.data[0] = bytes;
|
||||
data.frames = 480;
|
||||
data.speakers = SPEAKERS_MONO;
|
||||
data.samples_per_sec = 48000;
|
||||
data.timestamp = ts;
|
||||
data.format = AUDIO_FORMAT_U8BIT;
|
||||
obs_source_output_audio(swd->source, &data);
|
||||
|
||||
ts += 10000000;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static const char *sinewave_getname(void)
|
||||
{
|
||||
return "Sinewave Sound Source (Test)";
|
||||
}
|
||||
|
||||
static void sinewave_destroy(void *data)
|
||||
{
|
||||
struct sinewave_data *swd = data;
|
||||
|
||||
if (swd) {
|
||||
if (swd->initialized_thread) {
|
||||
void *ret;
|
||||
os_event_signal(swd->event);
|
||||
pthread_join(swd->thread, &ret);
|
||||
}
|
||||
|
||||
os_event_destroy(swd->event);
|
||||
bfree(swd);
|
||||
}
|
||||
}
|
||||
|
||||
static void *sinewave_create(obs_data_t *settings,
|
||||
obs_source_t *source)
|
||||
{
|
||||
struct sinewave_data *swd = bzalloc(sizeof(struct sinewave_data));
|
||||
swd->source = source;
|
||||
|
||||
if (os_event_init(&swd->event, OS_EVENT_TYPE_MANUAL) != 0)
|
||||
goto fail;
|
||||
if (pthread_create(&swd->thread, NULL, sinewave_thread, swd) != 0)
|
||||
goto fail;
|
||||
|
||||
swd->initialized_thread = true;
|
||||
|
||||
UNUSED_PARAMETER(settings);
|
||||
return swd;
|
||||
|
||||
fail:
|
||||
sinewave_destroy(swd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct obs_source_info test_sinewave = {
|
||||
.id = "test_sinewave",
|
||||
.type = OBS_SOURCE_TYPE_INPUT,
|
||||
.output_flags = OBS_SOURCE_AUDIO,
|
||||
.get_name = sinewave_getname,
|
||||
.create = sinewave_create,
|
||||
.destroy = sinewave_destroy,
|
||||
};
|
||||
12
test/win/CMakeLists.txt
Normal file
12
test/win/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
project(win-test)
|
||||
|
||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
|
||||
|
||||
set(win-text_SOURCES
|
||||
test.cpp)
|
||||
|
||||
add_executable(win-test WIN32
|
||||
${win-text_SOURCES})
|
||||
target_link_libraries(win-test
|
||||
libobs)
|
||||
define_graphic_modules(win-test)
|
||||
232
test/win/test.cpp
Normal file
232
test/win/test.cpp
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <util/base.h>
|
||||
#include <graphics/vec2.h>
|
||||
#include <media-io/audio-resampler.h>
|
||||
#include <obs.h>
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
static const int cx = 800;
|
||||
static const int cy = 600;
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
class SourceContext {
|
||||
obs_source_t *source;
|
||||
|
||||
public:
|
||||
inline SourceContext(obs_source_t *source) : source(source) {}
|
||||
inline ~SourceContext() {obs_source_release(source);}
|
||||
inline operator obs_source_t*() {return source;}
|
||||
};
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
class SceneContext {
|
||||
obs_scene_t *scene;
|
||||
|
||||
public:
|
||||
inline SceneContext(obs_scene_t *scene) : scene(scene) {}
|
||||
inline ~SceneContext() {obs_scene_release(scene);}
|
||||
inline operator obs_scene_t*() {return scene;}
|
||||
};
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
class DisplayContext {
|
||||
obs_display_t *display;
|
||||
|
||||
public:
|
||||
inline DisplayContext(obs_display_t *display) : display(display) {}
|
||||
inline ~DisplayContext() {obs_display_destroy(display);}
|
||||
inline operator obs_display_t*() {return display;}
|
||||
};
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
static LRESULT CALLBACK sceneProc(HWND hwnd, UINT message, WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (message) {
|
||||
|
||||
case WM_CLOSE:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void do_log(int log_level, const char *msg, va_list args, void *param)
|
||||
{
|
||||
char bla[4096];
|
||||
vsnprintf(bla, 4095, msg, args);
|
||||
|
||||
OutputDebugStringA(bla);
|
||||
OutputDebugStringA("\n");
|
||||
|
||||
if (log_level < LOG_WARNING)
|
||||
__debugbreak();
|
||||
|
||||
UNUSED_PARAMETER(param);
|
||||
}
|
||||
|
||||
static void CreateOBS(HWND hwnd)
|
||||
{
|
||||
RECT rc;
|
||||
GetClientRect(hwnd, &rc);
|
||||
|
||||
if (!obs_startup("en-US", nullptr, nullptr))
|
||||
throw "Couldn't create OBS";
|
||||
|
||||
struct obs_video_info ovi;
|
||||
ovi.adapter = 0;
|
||||
ovi.base_width = rc.right;
|
||||
ovi.base_height = rc.bottom;
|
||||
ovi.fps_num = 30000;
|
||||
ovi.fps_den = 1001;
|
||||
ovi.graphics_module = DL_OPENGL;
|
||||
ovi.output_format = VIDEO_FORMAT_RGBA;
|
||||
ovi.output_width = rc.right;
|
||||
ovi.output_height = rc.bottom;
|
||||
|
||||
if (obs_reset_video(&ovi) != 0)
|
||||
throw "Couldn't initialize video";
|
||||
}
|
||||
|
||||
static DisplayContext CreateDisplay(HWND hwnd)
|
||||
{
|
||||
RECT rc;
|
||||
GetClientRect(hwnd, &rc);
|
||||
|
||||
gs_init_data info = {};
|
||||
info.cx = rc.right;
|
||||
info.cy = rc.bottom;
|
||||
info.format = GS_RGBA;
|
||||
info.zsformat = GS_ZS_NONE;
|
||||
info.window.hwnd = hwnd;
|
||||
|
||||
return obs_display_create(&info);
|
||||
}
|
||||
|
||||
static void AddTestItems(obs_scene_t *scene, obs_source_t *source)
|
||||
{
|
||||
obs_sceneitem_t *item = NULL;
|
||||
struct vec2 scale;
|
||||
|
||||
vec2_set(&scale, 20.0f, 20.0f);
|
||||
|
||||
item = obs_scene_add(scene, source);
|
||||
obs_sceneitem_set_scale(item, &scale);
|
||||
}
|
||||
|
||||
static HWND CreateTestWindow(HINSTANCE instance)
|
||||
{
|
||||
WNDCLASS wc;
|
||||
|
||||
memset(&wc, 0, sizeof(wc));
|
||||
wc.lpszClassName = TEXT("bla");
|
||||
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
|
||||
wc.hInstance = instance;
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.lpfnWndProc = (WNDPROC)sceneProc;
|
||||
|
||||
if (!RegisterClass(&wc))
|
||||
return 0;
|
||||
|
||||
return CreateWindow(TEXT("bla"), TEXT("bla"),
|
||||
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
|
||||
1920/2 - cx/2, 1080/2 - cy/2, cx, cy,
|
||||
NULL, NULL, instance, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
static void RenderWindow(void *data, uint32_t cx, uint32_t cy)
|
||||
{
|
||||
obs_render_main_view();
|
||||
|
||||
UNUSED_PARAMETER(data);
|
||||
UNUSED_PARAMETER(cx);
|
||||
UNUSED_PARAMETER(cy);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine,
|
||||
int numCmd)
|
||||
{
|
||||
HWND hwnd = NULL;
|
||||
base_set_log_handler(do_log, nullptr);
|
||||
|
||||
try {
|
||||
hwnd = CreateTestWindow(instance);
|
||||
if (!hwnd)
|
||||
throw "Couldn't create main window";
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* create OBS */
|
||||
CreateOBS(hwnd);
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* load modules */
|
||||
obs_load_all_modules();
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* create source */
|
||||
SourceContext source = obs_source_create("random",
|
||||
"some randon source", NULL, nullptr);
|
||||
if (!source)
|
||||
throw "Couldn't create random test source";
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* create filter */
|
||||
SourceContext filter = obs_source_create("test_filter",
|
||||
"a nice green filter", NULL, nullptr);
|
||||
if (!filter)
|
||||
throw "Couldn't create test filter";
|
||||
obs_source_filter_add(source, filter);
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* create scene and add source to scene (twice) */
|
||||
SceneContext scene = obs_scene_create("test scene");
|
||||
if (!scene)
|
||||
throw "Couldn't create scene";
|
||||
|
||||
AddTestItems(scene, source);
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* set the scene as the primary draw source and go */
|
||||
obs_set_output_source(0, obs_scene_get_source(scene));
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
/* create display for output and set the output render callback */
|
||||
DisplayContext display = CreateDisplay(hwnd);
|
||||
obs_display_add_draw_callback(display, RenderWindow, nullptr);
|
||||
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
} catch (char *error) {
|
||||
MessageBoxA(NULL, error, NULL, 0);
|
||||
}
|
||||
|
||||
obs_shutdown();
|
||||
|
||||
blog(LOG_INFO, "Number of memory leaks: %ld", bnum_allocs());
|
||||
DestroyWindow(hwnd);
|
||||
|
||||
UNUSED_PARAMETER(prevInstance);
|
||||
UNUSED_PARAMETER(cmdLine);
|
||||
UNUSED_PARAMETER(numCmd);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue