Commit 65e0387a authored by kalistratovag's avatar kalistratovag

Implementing parallel mjpeg encoder.

Fixed errors in parallel_for based on pthreads

Fixing compiler errore & removing whitespaces

Fixing prallel_for_pthreads error and warnings on win
parent eb4bd6b4
...@@ -80,25 +80,31 @@ struct work_load ...@@ -80,25 +80,31 @@ struct work_load
set(range, body, nstripes); set(range, body, nstripes);
} }
void set(const cv::Range& range, const cv::ParallelLoopBody& body, int nstripes) void set(const cv::Range& range, const cv::ParallelLoopBody& body, unsigned int nstripes)
{ {
m_body = &body; m_body = &body;
m_range = ⦥ m_range = ⦥
m_nstripes = nstripes;
m_blocks_count = ((m_range->end - m_range->start - 1)/m_nstripes) + 1; //ensure that nstripes not larger than range length
m_nstripes = std::min( unsigned(m_range->end - m_range->start) , nstripes);
m_block_size = ((m_range->end - m_range->start - 1)/m_nstripes) + 1;
//ensure that nstripes not larger than blocks count, so we would never go out of range
m_nstripes = std::min(m_nstripes, unsigned(((m_range->end - m_range->start - 1)/m_block_size) + 1) );
} }
const cv::ParallelLoopBody* m_body; const cv::ParallelLoopBody* m_body;
const cv::Range* m_range; const cv::Range* m_range;
int m_nstripes; unsigned int m_nstripes;
unsigned int m_blocks_count; int m_block_size;
void clear() void clear()
{ {
m_body = 0; m_body = 0;
m_range = 0; m_range = 0;
m_nstripes = 0; m_nstripes = 0;
m_blocks_count = 0; m_block_size = 0;
} }
}; };
...@@ -331,10 +337,10 @@ void ForThread::execute() ...@@ -331,10 +337,10 @@ void ForThread::execute()
work_load& load = m_parent->m_work_load; work_load& load = m_parent->m_work_load;
while(m_current_pos < load.m_blocks_count) while(m_current_pos < load.m_nstripes)
{ {
int start = load.m_range->start + m_current_pos*load.m_nstripes; int start = load.m_range->start + m_current_pos*load.m_block_size;
int end = std::min(start + load.m_nstripes, load.m_range->end); int end = std::min(start + load.m_block_size, load.m_range->end);
load.m_body->operator()(cv::Range(start, end)); load.m_body->operator()(cv::Range(start, end));
...@@ -417,9 +423,11 @@ void ThreadManager::run(const cv::Range& range, const cv::ParallelLoopBody& body ...@@ -417,9 +423,11 @@ void ThreadManager::run(const cv::Range& range, const cv::ParallelLoopBody& body
{ {
if(initPool()) if(initPool())
{ {
double min_stripes = double(range.end - range.start)/(4*m_threads.size()); if(nstripes < 1) nstripes = 4*m_threads.size();
double max_stripes = 4*m_threads.size();
nstripes = std::max(nstripes, min_stripes); nstripes = std::min(nstripes, max_stripes);
pthread_mutex_lock(&m_manager_task_mutex); pthread_mutex_lock(&m_manager_task_mutex);
...@@ -429,7 +437,7 @@ void ThreadManager::run(const cv::Range& range, const cv::ParallelLoopBody& body ...@@ -429,7 +437,7 @@ void ThreadManager::run(const cv::Range& range, const cv::ParallelLoopBody& body
m_task_complete = false; m_task_complete = false;
m_work_load.set(range, body, std::ceil(nstripes)); m_work_load.set(range, body, cvCeil(nstripes));
for(size_t i = 0; i < m_threads.size(); ++i) for(size_t i = 0; i < m_threads.size(); ++i)
{ {
......
...@@ -315,6 +315,7 @@ enum { CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integ ...@@ -315,6 +315,7 @@ enum { CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integ
enum { VIDEOWRITER_PROP_QUALITY = 1, // Quality (0..100%) of the videostream encoded enum { VIDEOWRITER_PROP_QUALITY = 1, // Quality (0..100%) of the videostream encoded
VIDEOWRITER_PROP_FRAMEBYTES = 2, // (Read-only): Size of just encoded video frame VIDEOWRITER_PROP_FRAMEBYTES = 2, // (Read-only): Size of just encoded video frame
VIDEOWRITER_PROP_NSTRIPES = 3 // Number of stripes for parallel encoding. -1 for auto detection
}; };
// gPhoto2 properties, if propertyId is less than 0 then work on widget with that __additive inversed__ camera setting ID // gPhoto2 properties, if propertyId is less than 0 then work on widget with that __additive inversed__ camera setting ID
...@@ -610,6 +611,7 @@ public: ...@@ -610,6 +611,7 @@ public:
@param propId Property identifier. It can be one of the following: @param propId Property identifier. It can be one of the following:
- **VIDEOWRITER_PROP_QUALITY** Quality (0..100%) of the videostream encoded. Can be adjusted dynamically in some codecs. - **VIDEOWRITER_PROP_QUALITY** Quality (0..100%) of the videostream encoded. Can be adjusted dynamically in some codecs.
- **VIDEOWRITER_PROP_NSTRIPES** Number of stripes for parallel encoding
@param value Value of the property. @param value Value of the property.
*/ */
CV_WRAP virtual bool set(int propId, double value); CV_WRAP virtual bool set(int propId, double value);
...@@ -619,6 +621,7 @@ public: ...@@ -619,6 +621,7 @@ public:
@param propId Property identifier. It can be one of the following: @param propId Property identifier. It can be one of the following:
- **VIDEOWRITER_PROP_QUALITY** Current quality of the encoded videostream. - **VIDEOWRITER_PROP_QUALITY** Current quality of the encoded videostream.
- **VIDEOWRITER_PROP_FRAMEBYTES** (Read-only) Size of just encoded video frame; note that the encoding order may be different from representation order. - **VIDEOWRITER_PROP_FRAMEBYTES** (Read-only) Size of just encoded video frame; note that the encoding order may be different from representation order.
- **VIDEOWRITER_PROP_NSTRIPES** Number of stripes for parallel encoding
@note When querying a property that is not supported by the backend used by the VideoWriter @note When querying a property that is not supported by the backend used by the VideoWriter
class, value 0 is returned. class, value 0 is returned.
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment