提交 448ae26e 编写于 作者: J jp9000

obs-qsv11: Prevent more than one active QSV encoders

Currently, multiple QSV encoders cannot be active at the same time
(otherwise it will crash).  This is a temporary solution to prevent
crashes from occurring when more than one QSV encoder tries to start up
at the same time.

Additionally, in the future there should be a way for encoders to be
able to communicate with the front-end when an error such as this
occurs.
上级 6f02d336
......@@ -59,10 +59,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QSV_Encoder.h"
#include "QSV_Encoder_Internal.h"
#include <obs-module.h>
#include <string>
#include <mutex>
#define do_log(level, format, ...) \
blog(level, "[qsv encoder: '%s'] " format, \
"msdk_impl", ##__VA_ARGS__)
mfxIMPL impl = MFX_IMPL_HARDWARE_ANY;
mfxVersion ver = {{0, 1}}; // for backward compatibility
std::mutex active_mutex;
void qsv_encoder_version(unsigned short *major, unsigned short *minor)
{
......@@ -72,10 +79,18 @@ void qsv_encoder_version(unsigned short *major, unsigned short *minor)
qsv_t *qsv_encoder_open(qsv_param_t *pParams)
{
if (!active_mutex.try_lock()) {
do_log(LOG_ERROR, "Cannot have more than one encoder "
"active at a time");
return NULL;
}
QSV_Encoder_Internal *pEncoder = new QSV_Encoder_Internal(impl, ver);
mfxStatus sts = pEncoder->Open(pParams);
if (sts != MFX_ERR_NONE) {
delete pEncoder;
if (pEncoder)
active_mutex.unlock();
return NULL;
}
......@@ -115,6 +130,9 @@ int qsv_encoder_close(qsv_t *pContext)
QSV_Encoder_Internal *pEncoder = (QSV_Encoder_Internal *)pContext;
delete pEncoder;
if (pEncoder)
active_mutex.unlock();
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册