diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 6b4aa45475..7f5d0136eb 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -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 diff --git a/selfdrive/ui/qt/screenrecorder/screenrecorder.cc b/selfdrive/ui/qt/screenrecorder/screenrecorder.cc index df527c435c..da05ed32cb 100644 --- a/selfdrive/ui/qt/screenrecorder/screenrecorder.cc +++ b/selfdrive/ui/qt/screenrecorder/screenrecorder.cc @@ -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(src_width*src_height*4); rgb_scale_buffer = std::make_unique(dst_width*dst_height*4); encoder = std::make_unique(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()); } diff --git a/selfdrive/ui/qt/screenrecorder/screenrecorder.h b/selfdrive/ui/qt/screenrecorder/screenrecorder.h index bdf52bf148..c64cc856dd 100644 --- a/selfdrive/ui/qt/screenrecorder/screenrecorder.h +++ b/selfdrive/ui/qt/screenrecorder/screenrecorder.h @@ -35,9 +35,6 @@ private: QColor recording_color; int frame; - //QSoundEffect soundStart; - //QSoundEffect soundStop; - void applyColor(); std::unique_ptr 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(); };