Imported Upstream version 0.13.2+dsfg1
This commit is contained in:
commit
fb3990e9e5
2036 changed files with 287360 additions and 0 deletions
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,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue