videoio(mjpeg): disable parallel encoder
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Wed, 31 Mar 2021 12:16:42 +0000 (12:16 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Wed, 31 Mar 2021 12:35:12 +0000 (12:35 +0000)
modules/videoio/src/cap_mjpeg_encoder.cpp

index 7f4c8a6e9d4830abfb9dcd30fca17668bc64ee9c..96ec488bc0278b4652bdffe3c12352aa66680527 100644 (file)
@@ -1167,6 +1167,8 @@ public:
         fdct_qtab(_fdct_qtab),
         cat_table(_cat_table)
     {
+#if 0  // disable parallel processing due to buffer overrun bug: https://github.com/opencv/opencv/issues/19634
+
         //empirically found value. if number of pixels is less than that value there is no sense to parallelize it.
         const int min_pixels_count = 96*96;
 
@@ -1176,6 +1178,7 @@ public:
         {
             if(height*width > min_pixels_count)
             {
+                const int default_stripes_count = 4;
                 stripes_count = default_stripes_count;
             }
         }
@@ -1191,6 +1194,12 @@ public:
 
         stripes_count = std::min(stripes_count, max_stripes);
 
+#else
+        if (nstripes > 1)
+            CV_LOG_ONCE_WARNING(NULL, "VIDEOIO/MJPEG: parallel processing is disabled: https://github.com/opencv/opencv/issues/19634");
+        stripes_count = 1;
+#endif
+
         m_buffer_list.allocate_buffers(stripes_count, (height*width*2)/stripes_count);
     }
 
@@ -1370,11 +1379,8 @@ private:
     const short (&fdct_qtab)[2][64];
     const uchar* cat_table;
     int stripes_count;
-    static const int default_stripes_count;
 };
 
-const int MjpegEncoder::default_stripes_count = 4;
-
 void MotionJpegWriter::writeFrameData( const uchar* data, int step, int colorspace, int input_channels )
 {
     //double total_cvt = 0, total_dct = 0;