Using libobs, segfault when calling obs_reset_video

tankyx

New Member
Hi,

Been trying to do my own front end of OBS, so I followed the documentation tips and the examples, but I still segfault on this call.

#include <obs/obs.hpp>
#include <string>
#include <iostream>

class OBSWrapper : public OBSContext {
public:
using OBSContext::OBSContext;

bool isInitialized(void);
void resetAV(struct obs_video_info *v, struct obs_audio_info *a);
int SwitchSource(const char*, const char* name, const char* addr);
void setCurrentSource(OBSSource newSource);
OBSSource getCurrentSource() const;

private:
OBSSource _currentSource = nullptr;
OBSScene _currentScene = nullptr;

OBSSource createSource(const char* id, const char* name, OBSData data);
OBSScene createScene(const char* name);
void deleteSource(OBSSource& old);
void deleteScene(OBSScene& old);
OBSSceneItem addSourceToScene(OBSSource src);
OBSData createDataForRTMPSource(const char* addr);
};

void OBSWrapper::resetAV(struct obs_video_info *v, struct obs_audio_info *a)
{
struct obs_video_info tmp_v;
struct obs_audio_info tmp_a;

tmp_v.graphics_module = "libobs-opengl.so.0";
tmp_v.fps_num = 30000;
tmp_v.fps_den = 1001; //30 fps
tmp_v.base_width = 1280;
tmp_v.base_height = 720;
tmp_v.output_width = 1280; //No scaling yet
tmp_v.output_height = 720; //No scaling yet
tmp_v.output_format = VIDEO_FORMAT_NV12; //YUV420
tmp_v.adapter = 0; //Video adapter id
tmp_v.gpu_conversion = true;
tmp_v.colorspace = VIDEO_CS_601;
tmp_v.range = VIDEO_RANGE_PARTIAL;
tmp_v.scale_type = OBS_SCALE_BICUBIC;

tmp_a.samples_per_sec = 44100; //Somewhat classic 44.1KHz
tmp_a.speakers = SPEAKERS_STEREO; //2.0: FL, FR

obs_reset_audio(&tmp_a);
obs_reset_video(&tmp_v);
//v = &tmp_v;
//a = &tmp_a;
}

int OBSWrapper::SwitchSource(const char* id, const char* name, const char* addr)
{
if (_currentScene == nullptr)
_currentScene = createScene("scene");

OBSData srcData = createDataForRTMPSource(addr);
OBSSource src = createSource("0", name, srcData);
OBSSceneItem scItem = addSourceToScene(src);

return 0;
}

int main()
{
OBSWrapper* ctx = new OBSWrapper(setlocale(LC_ALL,NULL), nullptr, nullptr);

std::cout << "Context initialized : ";
std::cout << std::boolalpha << ctx->isInitialized() << std::endl;
ctx->resetAV(nullptr, nullptr);
ctx->SwitchSource("0", "test",
"rtmp://184.72.239.149/vod/BigBuckBunny_115k.mov");
RunServer();
delete(ctx);
return 0;
}​

Here is the source code. Also, it segfaults when calling glxchoosefbconfig in gl-x11.c.

backtrace

#0 0x00007fffeeef6920 in ?? ()
#1 0x00007fffef3c3e6b in gl_context_create (plat=0x79e740) at /home/tanguy/Documents/obs-studio/libobs-opengl/gl-x11.c:226
#2 gl_platform_create (device=device@entry=0x7a0000, adapter=adapter@entry=0) at /home/tanguy/Documents/obs-studio/libobs-opengl/gl-x11.c:354
#3 0x00007fffef3ca9d5 in device_create (p_device=0x79eae8, adapter=0) at /home/tanguy/Documents/obs-studio/libobs-opengl/gl-subsystem.c:213
#4 0x00007ffff730a8a2 in gs_create (pgraphics=pgraphics@entry=0x798528, module=<optimized out>, adapter=0) at /home/tanguy/Documents/obs-studio/libobs/graphics/graphics.c:194
#5 0x00007ffff734a20e in obs_init_graphics (ovi=0x7fffffffdbb0, ovi=0x7fffffffdbb0) at /home/tanguy/Documents/obs-studio/libobs/obs.c:238
#6 obs_reset_video (ovi=0x7fffffffdbb0) at /home/tanguy/Documents/obs-studio/libobs/obs.c:951
#7 0x0000000000478776 in OBSWrapper::resetAV (this=0x795560, v=0x0, a=0x0) at src/OBSWrapper.cpp:32
#8 0x000000000046a883 in main () at src/main.cpp:14
 

kurufu

Member
From antou in the discord

I just found a work around for now, I added:
Code:
#include <QApplication>
#include <QPushButton>
and in my main(), before doing anything obs-related:
Code:
QApplication app(argc, argv);
QPushButton hello("Hello world!");
So initialzing QT (which probably initializes OpenGL internally ?) without actually showing any graphics seems to do the trick for me
 
Top