Browse Source

Merge pull request #959 from sorayuki/patch-1

obs-qsv11: change re-enter lock implementation
Jim 8 years ago
parent
commit
daaa2741a7
1 changed files with 6 additions and 5 deletions
  1. 6 5
      plugins/obs-qsv11/QSV_Encoder.cpp

+ 6 - 5
plugins/obs-qsv11/QSV_Encoder.cpp

@@ -61,7 +61,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "QSV_Encoder_Internal.h"
 #include <obs-module.h>
 #include <string>
-#include <mutex>
+#include <atomic>
 #include <intrin.h>
 
 #define do_log(level, format, ...) \
@@ -70,7 +70,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 mfxIMPL              impl = MFX_IMPL_HARDWARE_ANY;
 mfxVersion           ver = {{0, 1}}; // for backward compatibility
-std::mutex           active_mutex;
+std::atomic<bool>    is_active{false};
 
 void qsv_encoder_version(unsigned short *major, unsigned short *minor)
 {
@@ -80,7 +80,8 @@ void qsv_encoder_version(unsigned short *major, unsigned short *minor)
 
 qsv_t *qsv_encoder_open(qsv_param_t *pParams)
 {
-	if (!active_mutex.try_lock()) {
+	bool false_value = false;
+	if (!is_active.compare_exchange_strong(false_value, true)) {
 		do_log(LOG_ERROR, "Cannot have more than one encoder "
 				"active at a time");
 		return NULL;
@@ -91,7 +92,7 @@ qsv_t *qsv_encoder_open(qsv_param_t *pParams)
 	if (sts != MFX_ERR_NONE) {
 		delete pEncoder;
 		if (pEncoder)
-			active_mutex.unlock();
+			is_active.store(false);
 		return NULL;
 	}
 
@@ -132,7 +133,7 @@ int qsv_encoder_close(qsv_t *pContext)
 	delete pEncoder;
 
 	if (pEncoder)
-		active_mutex.unlock();
+		is_active.store(false);
 
 	return 0;
 }