You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
3 months ago
|
#include "tools/clip/recorder/widget.h"
|
||
3 months ago
|
|
||
3 months ago
|
#include "tools/clip/recorder/ffmpeg.h"
|
||
3 months ago
|
|
||
3 months ago
|
Recorder::Recorder(QObject *parent) : QObject(parent) {
|
||
|
encoder = new FFmpegEncoder("/Users/trey/Desktop/out.mp4", DEVICE_SCREEN_SIZE.width(), DEVICE_SCREEN_SIZE.height(), UI_FREQ);
|
||
|
}
|
||
|
|
||
3 months ago
|
Recorder::~Recorder() {
|
||
3 months ago
|
delete encoder;
|
||
3 months ago
|
}
|
||
|
|
||
|
void Recorder::saveFrame(QImage *frame) {
|
||
|
QMutexLocker locker(&mutex);
|
||
|
frameQueue.enqueue(frame); // Add frame to queue
|
||
|
if (!isProcessing) {
|
||
|
isProcessing = true;
|
||
|
QMetaObject::invokeMethod(this, &Recorder::processQueue, Qt::QueuedConnection);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Recorder::processQueue() {
|
||
|
while (true) {
|
||
|
QImage *frame;
|
||
|
{
|
||
|
QMutexLocker locker(&mutex);
|
||
|
if (frameQueue.isEmpty() || !keepRunning) {
|
||
|
isProcessing = false;
|
||
|
return;
|
||
|
}
|
||
|
frame = frameQueue.dequeue();
|
||
|
}
|
||
3 months ago
|
|
||
3 months ago
|
if (!encoder->writeFrame(frame->convertToFormat(QImage::Format_ARGB32_Premultiplied))) {
|
||
3 months ago
|
fprintf(stderr, "did not write\n");
|
||
|
}
|
||
3 months ago
|
|
||
|
delete frame;
|
||
3 months ago
|
}
|
||
|
}
|
||
|
|
||
|
void Recorder::stop() {
|
||
|
QMutexLocker locker(&mutex);
|
||
|
keepRunning = false;
|
||
|
}
|
||
|
|