Commit 656a4ccf authored by Tristan Matthews's avatar Tristan Matthews

* #17601: video: use atomic functions to modify shared variables while threads are running

parent 76a266f2
......@@ -33,7 +33,11 @@
#include "logger.h"
#define set_false_atomic(x) __sync_fetch_and_and(x, false)
#define atomic_increment(x) __sync_fetch_and_add(x, 1)
#define atomic_decrement(x) __sync_fetch_and_sub(x, 1)
// If condition A is false, print the error message in M and exit thread
#define EXIT_IF_FAIL(A, M, ...) if (!(A)) { ERROR(M, ##__VA_ARGS__); threadRunning_ = false; pthread_exit(NULL); }
#define EXIT_IF_FAIL(A, M, ...) if (!(A)) { ERROR(M, ##__VA_ARGS__); __sync_fetch_and_and(&threadRunning_, false); pthread_exit(NULL); }
#endif // CHECK_H_
......@@ -331,7 +331,7 @@ void VideoReceiveThread::run()
VideoReceiveThread::~VideoReceiveThread()
{
threadRunning_ = false;
set_false_atomic(&threadRunning_);
Manager::instance().getVideoControls()->stoppedDecoding(id_, sink_.openedName());
// waits for the run() method (in separate thread) to return
pthread_join(thread_, NULL);
......
......@@ -425,11 +425,8 @@ void VideoSendThread::run()
int ret = av_read_frame(inputCtx_, &inpacket);
if (ret == AVERROR(EAGAIN))
continue;
else if (ret < 0) {
ERROR("Could not read frame");
threadRunning_ = false;
break;
}
else if (ret < 0)
EXIT_IF_FAIL(false, "Could not read frame");
/* Guarantees that we free the packet allocated by av_read_frame */
PacketHandle inpacket_handle(inpacket);
......@@ -459,7 +456,7 @@ void VideoSendThread::run()
#else
scaledPicture_->pict_type = FF_I_TYPE;
#endif
__sync_fetch_and_sub(&forceKeyFrame_, 1);
atomic_decrement(&forceKeyFrame_);
}
const int encodedSize = avcodec_encode_video(encoderCtx_, outbuf_,
outbufSize_, scaledPicture_);
......@@ -496,14 +493,13 @@ void VideoSendThread::run()
VideoSendThread::~VideoSendThread()
{
// FIXME
threadRunning_ = false;
set_false_atomic(&threadRunning_);
pthread_join(thread_, NULL);
}
void VideoSendThread::forceKeyFrame()
{
__sync_fetch_and_add(&forceKeyFrame_, 1);
atomic_increment(&forceKeyFrame_);
}
} // end namespace sfl_video
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment