summaryrefslogtreecommitdiffstats
blob: 40d9bef962129d40f0f60db15d97921fd74e1c79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright (c) 2012 Yoann Blein
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <Swiften/ScreenSharing/VideoEncoder.h>

namespace Swift {

void VideoEncoder::addFrame(VideoFrame::ref frame)
{
	boost::mutex::scoped_lock lock(queueMutex);
	frames.push(frame);
	lock.unlock();
	queueCondVar.notify_one();
}

void VideoEncoder::startEncoding()
{
	stop = false;
	encodingThread = boost::thread(&VideoEncoder::encodingLoop, this);
}

void VideoEncoder::stopEncoding()
{
	stop = true;
	encodingThread.join();
}

VideoFrame::ref VideoEncoder::popWhenFrameIsAvailable()
{
	boost::mutex::scoped_lock lock(queueMutex);
	while (frames.empty()) {
		queueCondVar.wait(lock);
	}
	VideoFrame::ref popped = frames.front();
	frames.pop();
	return popped;
}

}