0006-Make-the-qt-preview-work-in-debian.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. From 0327a137e069e0cfbdd775f7c40f03e088b765d6 Mon Sep 17 00:00:00 2001
  2. From: "zejian.su" <zejian.su@starfivetech.com>
  3. Date: Wed, 8 Nov 2023 09:23:01 +0800
  4. Subject: [PATCH 2/2] Make the qt preview work in debian. 1. Fill the NV12 data
  5. into the QT buffer. 2. For the low performance of QWidget, reduce the FPS to
  6. 15.
  7. Signed-off-by: zejian.su <zejian.su@starfivetech.com>
  8. ---
  9. preview/preview.cpp | 37 ++++++++++++++-----------------------
  10. preview/qt_preview.cpp | 20 ++++++++++++++++----
  11. 2 files changed, 30 insertions(+), 27 deletions(-)
  12. diff --git a/preview/preview.cpp b/preview/preview.cpp
  13. index b67edb3..d2c511a 100644
  14. --- a/preview/preview.cpp
  15. +++ b/preview/preview.cpp
  16. @@ -19,47 +19,38 @@ Preview *make_preview(Options const *options)
  17. if (options->nopreview)
  18. return make_null_preview(options);
  19. #if QT_PRESENT
  20. - else if (options->qt_preview)
  21. + else
  22. {
  23. Preview *p = make_qt_preview(options);
  24. if (p)
  25. LOG(1, "Made QT preview window");
  26. return p;
  27. }
  28. -#endif
  29. - else
  30. +#else
  31. + try
  32. + {
  33. + throw std::runtime_error("qt5 libraries unavailable.");
  34. + }
  35. + catch(std::exception const &e)
  36. {
  37. try
  38. {
  39. -#if LIBEGL_PRESENT
  40. - Preview *p = make_egl_preview(options);
  41. +#if LIBDRM_PRESENT
  42. + Preview *p = make_drm_preview(options);
  43. if (p)
  44. - LOG(1, "Made X/EGL preview window");
  45. + LOG(1, "Made DRM preview window");
  46. return p;
  47. #else
  48. - throw std::runtime_error("egl libraries unavailable.");
  49. + throw std::runtime_error("drm libraries unavailable.");
  50. #endif
  51. }
  52. catch (std::exception const &e)
  53. {
  54. - try
  55. - {
  56. -#if LIBDRM_PRESENT
  57. - Preview *p = make_drm_preview(options);
  58. - if (p)
  59. - LOG(1, "Made DRM preview window");
  60. - return p;
  61. -#else
  62. - throw std::runtime_error("drm libraries unavailable.");
  63. -#endif
  64. - }
  65. - catch (std::exception const &e)
  66. - {
  67. - LOG(1, "Preview window unavailable");
  68. - return make_null_preview(options);
  69. - }
  70. + LOG(1, "Preview window unavailable");
  71. + return make_null_preview(options);
  72. }
  73. }
  74. +#endif
  75. return nullptr; // prevents compiler warning in debug builds
  76. }
  77. diff --git a/preview/qt_preview.cpp b/preview/qt_preview.cpp
  78. index f595db7..8196a8e 100644
  79. --- a/preview/qt_preview.cpp
  80. +++ b/preview/qt_preview.cpp
  81. @@ -58,7 +58,7 @@ protected:
  82. class QtPreview : public Preview
  83. {
  84. public:
  85. - QtPreview(Options const *options) : Preview(options)
  86. + QtPreview(Options const *options) : Preview(options), frame_counter_(0)
  87. {
  88. window_width_ = options->preview_width;
  89. window_height_ = options->preview_height;
  90. @@ -83,6 +83,12 @@ public:
  91. void SetInfoText(const std::string &text) override { main_window_->setWindowTitle(QString::fromStdString(text)); }
  92. virtual void Show(int fd, libcamera::Span<uint8_t> span, StreamInfo const &info) override
  93. {
  94. + if((frame_counter_++) & 1) {
  95. + // Return the buffer to the camera system.
  96. + done_callback_(fd);
  97. + return;
  98. + }
  99. +
  100. // Quick and simple nearest-neighbour-ish resampling is used here.
  101. // We further share U,V samples between adjacent output pixel pairs
  102. // (even when downscaling) to speed up the conversion.
  103. @@ -131,6 +137,7 @@ public:
  104. // take a copy of each row used. This is a speedup provided memcpy() is vectorized.
  105. tmp_stripe_.resize(2 * info.stride);
  106. uint8_t const *Y_start = span.data();
  107. + uint8_t const *UV_start = Y_start + info.height * info.stride;
  108. uint8_t *Y_row = &tmp_stripe_[0];
  109. uint8_t *U_row = Y_row + info.stride;
  110. uint8_t *V_row = U_row + (info.stride >> 1);
  111. @@ -146,8 +153,11 @@ public:
  112. unsigned x_pos = x_step >> 1;
  113. memcpy(Y_row, Y_start + row * info.stride, info.stride);
  114. - memcpy(U_row, Y_start + ((4 * info.height + row) >> 1) * (info.stride >> 1), info.stride >> 1);
  115. - memcpy(V_row, Y_start + ((5 * info.height + row) >> 1) * (info.stride >> 1), info.stride >> 1);
  116. + //memcpy(U_row, Y_start + ((4 * info.height + row) >> 1) * (info.stride >> 1), info.stride >> 1);
  117. + //memcpy(V_row, Y_start + ((5 * info.height + row) >> 1) * (info.stride >> 1), info.stride >> 1);
  118. + uint8_t const *cur_uv = UV_start + (row >> 1) * info.width;
  119. + for(unsigned int uv_idx = 0; uv_idx < info.width >> 1; uv_idx++, cur_uv += 2)
  120. + U_row[uv_idx] = cur_uv[0], V_row[uv_idx] = cur_uv[1];
  121. for (unsigned int x = 0; x < window_width_; x += 2)
  122. {
  123. @@ -183,7 +193,7 @@ public:
  124. }
  125. // Reset the preview window, clearing the current buffers and being ready to
  126. // show new ones.
  127. - void Reset() override {}
  128. + void Reset() override {frame_counter_ = 0;}
  129. // Check if preview window has been shut down.
  130. bool Quit() override { return main_window_->quit; }
  131. // There is no particular limit to image sizes, though large images will be very slow.
  132. @@ -218,6 +228,8 @@ private:
  133. std::mutex mutex_;
  134. std::condition_variable cond_var_;
  135. std::vector<uint8_t> tmp_stripe_;
  136. +
  137. + unsigned int frame_counter_;
  138. };
  139. Preview *make_qt_preview(Options const *options)
  140. --
  141. 2.34.1