2013-11-22 15:20:02 -08:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2013-12-02 21:24:38 -08:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-11-22 15:20:02 -08:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-12-22 16:42:02 -08:00
|
|
|
/* Useful C++ classes and bindings for base obs data */
|
|
|
|
|
2013-11-22 15:20:02 -08:00
|
|
|
#pragma once
|
|
|
|
|
2013-12-22 16:42:02 -08:00
|
|
|
#include "obs.h"
|
2013-11-22 19:57:24 -08:00
|
|
|
|
2013-11-23 22:38:52 -08:00
|
|
|
/* RAII wrappers */
|
|
|
|
|
2014-02-02 20:39:14 -08:00
|
|
|
template<typename T, void addref(T), void release(T)>
|
|
|
|
class OBSRef {
|
2014-02-02 13:26:23 -08:00
|
|
|
T val;
|
2013-11-22 15:20:02 -08:00
|
|
|
|
2014-02-02 14:34:02 -08:00
|
|
|
inline OBSRef &Replace(T valIn)
|
|
|
|
{
|
2014-02-02 20:39:14 -08:00
|
|
|
addref(valIn);
|
|
|
|
release(val);
|
2014-02-02 14:34:02 -08:00
|
|
|
val = valIn;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-22 15:20:02 -08:00
|
|
|
public:
|
2014-02-02 13:26:23 -08:00
|
|
|
inline OBSRef() : val(nullptr) {}
|
2014-02-02 20:39:14 -08:00
|
|
|
inline OBSRef(T val_) : val(val_) {addref(val);}
|
|
|
|
inline OBSRef(const OBSRef &ref) : val(ref.val) {addref(val);}
|
2014-02-02 13:26:23 -08:00
|
|
|
inline OBSRef(OBSRef &&ref) : val(ref.val) {ref.val = nullptr;}
|
2013-11-22 15:20:02 -08:00
|
|
|
|
2014-02-02 20:39:14 -08:00
|
|
|
inline ~OBSRef() {release(val);}
|
2013-11-22 15:20:02 -08:00
|
|
|
|
2014-02-02 14:34:02 -08:00
|
|
|
inline OBSRef &operator=(T valIn) {return Replace(valIn);}
|
|
|
|
inline OBSRef &operator=(const OBSRef &ref) {return Replace(ref.val);}
|
2013-11-22 15:20:02 -08:00
|
|
|
|
2014-02-02 13:26:23 -08:00
|
|
|
inline OBSRef &operator=(OBSRef &&ref)
|
2013-11-22 15:20:02 -08:00
|
|
|
{
|
|
|
|
if (this != &ref) {
|
2014-02-02 13:26:23 -08:00
|
|
|
val = ref.val;
|
2014-02-02 14:34:02 -08:00
|
|
|
ref.val = nullptr;
|
2013-11-22 15:20:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-02-02 13:26:23 -08:00
|
|
|
inline operator T() const {return val;}
|
2013-11-22 15:20:02 -08:00
|
|
|
|
2014-02-02 13:26:23 -08:00
|
|
|
inline bool operator==(T p) const {return val == p;}
|
|
|
|
inline bool operator!=(T p) const {return val != p;}
|
2013-11-22 15:20:02 -08:00
|
|
|
};
|
2014-02-02 13:26:23 -08:00
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
using OBSSource = OBSRef<obs_source_t*, obs_source_addref, obs_source_release>;
|
|
|
|
using OBSScene = OBSRef<obs_scene_t*, obs_scene_addref, obs_scene_release>;
|
|
|
|
using OBSSceneItem = OBSRef<obs_sceneitem_t*, obs_sceneitem_addref,
|
2014-02-02 20:39:14 -08:00
|
|
|
obs_sceneitem_release>;
|
2014-09-25 17:44:05 -07:00
|
|
|
using OBSData = OBSRef<obs_data_t*, obs_data_addref, obs_data_release>;
|
|
|
|
using OBSDataArray = OBSRef<obs_data_array_t*, obs_data_array_addref,
|
2014-02-02 20:39:14 -08:00
|
|
|
obs_data_array_release>;
|
2014-03-23 01:07:54 -07:00
|
|
|
|
|
|
|
/* objects that are not meant to be instanced */
|
|
|
|
template<typename T, void destroy(T)> class OBSObj {
|
|
|
|
T obj;
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline OBSObj() : obj(nullptr) {}
|
|
|
|
inline OBSObj(T obj_) : obj(obj_) {}
|
|
|
|
|
|
|
|
inline ~OBSObj() {destroy(obj);}
|
|
|
|
|
|
|
|
inline OBSObj &operator=(T obj_)
|
|
|
|
{
|
|
|
|
if (obj_ != obj)
|
|
|
|
destroy(obj);
|
|
|
|
obj = obj_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline operator T() const {return obj;}
|
|
|
|
|
|
|
|
inline bool operator==(T p) const {return obj == p;}
|
|
|
|
inline bool operator!=(T p) const {return obj != p;}
|
|
|
|
};
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
using OBSDisplay = OBSObj<obs_display_t*, obs_display_destroy>;
|
|
|
|
using OBSEncoder = OBSObj<obs_encoder_t*, obs_encoder_destroy>;
|
|
|
|
using OBSView = OBSObj<obs_view_t*, obs_view_destroy>;
|
|
|
|
using OBSOutput = OBSObj<obs_output_t*, obs_output_destroy>;
|
2014-03-23 01:07:54 -07:00
|
|
|
|
|
|
|
/* signal handler connection */
|
|
|
|
class OBSSignal {
|
2014-09-25 17:44:05 -07:00
|
|
|
signal_handler_t *handler;
|
2014-03-23 01:07:54 -07:00
|
|
|
const char *signal;
|
|
|
|
signal_callback_t callback;
|
|
|
|
void *param;
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline OBSSignal()
|
|
|
|
: handler (nullptr),
|
|
|
|
signal (nullptr),
|
|
|
|
callback (nullptr),
|
|
|
|
param (nullptr)
|
|
|
|
{}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
inline OBSSignal(signal_handler_t *handler_,
|
2014-06-15 00:14:08 -07:00
|
|
|
const char *signal_,
|
2014-03-23 01:07:54 -07:00
|
|
|
signal_callback_t callback_,
|
2014-06-15 00:14:08 -07:00
|
|
|
void *param_)
|
2014-03-23 01:07:54 -07:00
|
|
|
: handler (handler_),
|
|
|
|
signal (signal_),
|
|
|
|
callback (callback_),
|
|
|
|
param (param_)
|
|
|
|
{
|
|
|
|
signal_handler_connect(handler, signal, callback, param);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Disconnect()
|
|
|
|
{
|
|
|
|
signal_handler_disconnect(handler, signal, callback, param);
|
|
|
|
handler = nullptr;
|
|
|
|
signal = nullptr;
|
|
|
|
callback = nullptr;
|
|
|
|
param = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ~OBSSignal() {Disconnect();}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
inline void Connect(signal_handler_t *handler_,
|
2014-03-23 01:07:54 -07:00
|
|
|
const char *signal_,
|
|
|
|
signal_callback_t callback_,
|
|
|
|
void *param_)
|
|
|
|
{
|
|
|
|
Disconnect();
|
|
|
|
|
|
|
|
handler = handler_;
|
|
|
|
signal = signal_;
|
|
|
|
callback = callback_;
|
|
|
|
param = param_;
|
|
|
|
signal_handler_connect(handler, signal, callback, param);
|
|
|
|
}
|
2014-10-28 15:49:20 -07:00
|
|
|
|
|
|
|
OBSSignal(const OBSSignal&) = delete;
|
|
|
|
OBSSignal(OBSSignal &&other)
|
|
|
|
: handler (other.handler),
|
|
|
|
signal (other.signal),
|
|
|
|
callback(other.callback),
|
|
|
|
param (other.param)
|
|
|
|
{
|
|
|
|
other.handler = nullptr;
|
|
|
|
other.signal = nullptr;
|
|
|
|
other.callback = nullptr;
|
|
|
|
other.param = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBSSignal &operator=(const OBSSignal &) = delete;
|
|
|
|
OBSSignal &operator=(OBSSignal &&other)
|
|
|
|
{
|
|
|
|
Disconnect();
|
|
|
|
|
|
|
|
handler = other.handler;
|
|
|
|
signal = other.signal;
|
|
|
|
callback = other.callback;
|
|
|
|
param = other.param;
|
|
|
|
|
|
|
|
other.handler = nullptr;
|
|
|
|
other.signal = nullptr;
|
|
|
|
other.callback = nullptr;
|
|
|
|
other.param = nullptr;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2014-03-23 01:07:54 -07:00
|
|
|
};
|