mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-01 15:49:51 +08:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user