mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-22 17:43:47 +08:00
Screenrecorder cleanup and 1 minute clip (#83)
* Record from OnroadWindow * not from here * not needed * make it whole * Revert "make it whole" This reverts commit 318c28c1ac921b52672fdd4665d903c2bdf5ef41. * Revert "not needed" This reverts commit 45d9707736b942b3a671bf853333a35741beb079. * Revert "not from here" This reverts commit 1bb002ff86630f3b1f6c6171606e4f7a8922253b. * Revert "Record from OnroadWindow" This reverts commit f4ceab4d9f4f1be992ba447c1474fdd47063c41b. * cleaning * cleaning * 1 min per clip * remove * add back
This commit is contained in:
@@ -368,7 +368,7 @@ AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget* par
|
||||
#ifdef ENABLE_DASHCAM
|
||||
void AnnotatedCameraWidget::offroadTransition(bool offroad) {
|
||||
if (offroad && recorder) {
|
||||
recorder->stop(false);
|
||||
recorder->stop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
#include "system/hardware/hw.h"
|
||||
|
||||
static long long milliseconds(void) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,NULL);
|
||||
return (((long long)tv.tv_sec)*1000)+(tv.tv_usec/1000);
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,NULL);
|
||||
return (((long long)tv.tv_sec)*1000)+(tv.tv_usec/1000);
|
||||
}
|
||||
|
||||
ScreenRecoder::ScreenRecoder(QWidget *parent) : QPushButton(parent), image_queue(30)
|
||||
{
|
||||
|
||||
ScreenRecoder::ScreenRecoder(QWidget *parent) : QPushButton(parent), image_queue(30) {
|
||||
recording = false;
|
||||
started = 0;
|
||||
frame = 0;
|
||||
@@ -39,64 +37,30 @@ ScreenRecoder::ScreenRecoder(QWidget *parent) : QPushButton(parent), image_queue
|
||||
|
||||
dst_height = 720;
|
||||
dst_width = src_width * dst_height / src_height;
|
||||
if(dst_width % 2 != 0)
|
||||
dst_width += 1;
|
||||
if (dst_width % 2 != 0)
|
||||
dst_width += 1;
|
||||
|
||||
rgb_buffer = std::make_unique<uint8_t[]>(src_width*src_height*4);
|
||||
rgb_scale_buffer = std::make_unique<uint8_t[]>(dst_width*dst_height*4);
|
||||
encoder = std::make_unique<OmxEncoder>(path.c_str(), dst_width, dst_height, UI_FREQ, 2*1024*1024, false, false);
|
||||
|
||||
//soundStart.setSource(QUrl::fromLocalFile("../assets/sounds/rec_on.wav"));
|
||||
//soundStop.setSource(QUrl::fromLocalFile("../assets/sounds/rec_off.wav"));
|
||||
|
||||
//soundStart.setVolume(0.7f);
|
||||
//soundStop.setVolume(0.9f);
|
||||
}
|
||||
|
||||
ScreenRecoder::~ScreenRecoder() {
|
||||
stop(false);
|
||||
stop();
|
||||
}
|
||||
|
||||
void ScreenRecoder::applyColor() {
|
||||
|
||||
if(frame % (UI_FREQ/2) == 0) {
|
||||
|
||||
recording_color = QColor::fromRgbF(1, 0, 0, 0.4);
|
||||
//if(frame % UI_FREQ < (UI_FREQ/2))
|
||||
//recording_color = QColor::fromRgbF(1, 0, 0, 0.6);
|
||||
//else
|
||||
//recording_color = QColor::fromRgbF(0, 0, 0, 0.3);
|
||||
if (frame % (UI_FREQ / 2) == 0) {
|
||||
if (frame % UI_FREQ < (UI_FREQ / 2))
|
||||
recording_color = QColor::fromRgbF(1, 0, 0, 0.6);
|
||||
else
|
||||
recording_color = QColor::fromRgbF(0, 0, 0, 0.3);
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenRecoder::paintEvent(QPaintEvent *event) {
|
||||
/*
|
||||
QRect r = QRect(30, 0, width(), height());
|
||||
r -= QMargins(5, 5, 5, 5);
|
||||
|
||||
QPainter p(this);
|
||||
// its drwas outter circle.
|
||||
//p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
//p.setPen(QPen(QColor::fromRgbF(1, 1, 1, 0.4), 10, Qt::SolidLine, Qt::FlatCap));
|
||||
|
||||
//p.setBrush(QBrush(QColor::fromRgbF(0, 0, 0, 0)));
|
||||
//p.drawEllipse(r);
|
||||
|
||||
r -= QMargins(40, 40, 40, 40);
|
||||
p.setPen(Qt::NoPen);
|
||||
|
||||
//TODO: make it square?
|
||||
QColor bg = recording ? recording_color : QColor(252, 255, 253, 70);
|
||||
p.setBrush(QBrush(bg));
|
||||
p.drawEllipse(r);
|
||||
|
||||
//QPainter painter(this);
|
||||
p.setPen(Qt::white);
|
||||
p.setFont(QFont("Arial", 30));
|
||||
p.drawText(r,Qt::AlignCenter, "REC");
|
||||
*/
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
@@ -114,32 +78,30 @@ void ScreenRecoder::paintEvent(QPaintEvent *event) {
|
||||
}
|
||||
|
||||
void ScreenRecoder::btnReleased(void) {
|
||||
toggle();
|
||||
toggle();
|
||||
}
|
||||
|
||||
void ScreenRecoder::btnPressed(void) {
|
||||
}
|
||||
|
||||
void ScreenRecoder::openEncoder(const char* filename) {
|
||||
encoder->encoder_open(filename);
|
||||
encoder->encoder_open(filename);
|
||||
}
|
||||
|
||||
void ScreenRecoder::closeEncoder() {
|
||||
if(encoder)
|
||||
encoder->encoder_close();
|
||||
if (encoder)
|
||||
encoder->encoder_close();
|
||||
}
|
||||
|
||||
void ScreenRecoder::toggle() {
|
||||
|
||||
if(!recording)
|
||||
start(true);
|
||||
if (!recording)
|
||||
start();
|
||||
else
|
||||
stop(true);
|
||||
stop();
|
||||
}
|
||||
|
||||
void ScreenRecoder::start(bool sound) {
|
||||
|
||||
if(recording)
|
||||
void ScreenRecoder::start() {
|
||||
if (recording)
|
||||
return;
|
||||
|
||||
char filename[64];
|
||||
@@ -162,16 +124,14 @@ void ScreenRecoder::start(bool sound) {
|
||||
update();
|
||||
|
||||
started = milliseconds();
|
||||
|
||||
//if(sound)
|
||||
// soundStart.play();
|
||||
}
|
||||
|
||||
void ScreenRecoder::encoding_thread_func() {
|
||||
uint64_t start_time = nanos_since_boot() -1;
|
||||
while(recording && encoder) {
|
||||
|
||||
while (recording && encoder) {
|
||||
QImage popImage;
|
||||
if(image_queue.pop_wait_for(popImage, std::chrono::milliseconds(10))) {
|
||||
if (image_queue.pop_wait_for(popImage, std::chrono::milliseconds(10))) {
|
||||
|
||||
QImage image = popImage.convertToFormat(QImage::Format_RGBA8888);
|
||||
|
||||
@@ -186,35 +146,29 @@ void ScreenRecoder::encoding_thread_func() {
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenRecoder::stop(bool sound) {
|
||||
|
||||
if(recording) {
|
||||
void ScreenRecoder::stop() {
|
||||
if (recording) {
|
||||
recording = false;
|
||||
update();
|
||||
|
||||
closeEncoder();
|
||||
image_queue.clear();
|
||||
if(encoding_thread.joinable())
|
||||
encoding_thread.join();
|
||||
|
||||
//if(sound)
|
||||
// soundStop.play();
|
||||
closeEncoder();
|
||||
image_queue.clear();
|
||||
if (encoding_thread.joinable())
|
||||
encoding_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenRecoder::update_screen() {
|
||||
|
||||
if(recording) {
|
||||
|
||||
if(milliseconds() - started > 1000*60*3) {
|
||||
stop(false);
|
||||
start(false);
|
||||
if (recording) {
|
||||
if (milliseconds() - started > 1000*60*1) {
|
||||
stop();
|
||||
start();
|
||||
return;
|
||||
}
|
||||
|
||||
applyColor();
|
||||
|
||||
if(rootWidget != nullptr) {
|
||||
if (rootWidget != nullptr) {
|
||||
QPixmap pixmap = rootWidget->grab();
|
||||
image_queue.push(pixmap.toImage());
|
||||
}
|
||||
|
||||
@@ -35,9 +35,6 @@ private:
|
||||
QColor recording_color;
|
||||
int frame;
|
||||
|
||||
//QSoundEffect soundStart;
|
||||
//QSoundEffect soundStop;
|
||||
|
||||
void applyColor();
|
||||
|
||||
std::unique_ptr<OmxEncoder> encoder;
|
||||
@@ -52,9 +49,8 @@ private:
|
||||
void closeEncoder();
|
||||
|
||||
public:
|
||||
void start(bool sound);
|
||||
void stop(bool sound);
|
||||
void toggle();
|
||||
void update_screen();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
void toggle();
|
||||
void update_screen();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user