From bba4f9e5d6af59cafd7b40a7adf645ee8d763b36 Mon Sep 17 00:00:00 2001 From: Andrey Morozov Date: Tue, 2 Aug 2011 14:27:21 +0000 Subject: [PATCH] removed property. added automatically define number of cpus for decoding video --- .../include/opencv2/highgui/highgui_c.h | 4 +- modules/highgui/src/cap_ffmpeg_api.hpp | 3 +- modules/highgui/src/cap_ffmpeg_impl.hpp | 62 ++++++++++++++----- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/modules/highgui/include/opencv2/highgui/highgui_c.h b/modules/highgui/include/opencv2/highgui/highgui_c.h index dbdb34db1b..7c030ae23e 100644 --- a/modules/highgui/include/opencv2/highgui/highgui_c.h +++ b/modules/highgui/include/opencv2/highgui/highgui_c.h @@ -372,9 +372,7 @@ enum // Properties of cameras available through GStreamer interface CV_CAP_GSTREAMER_QUEUE_LENGTH = 200, // default is 1 - CV_CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast - - CV_CAP_PROP_THREADS = 400 + CV_CAP_PROP_PVAPI_MULTICASTIP = 300 // ip for anable multicast master mode. 0 for disable multicast }; enum diff --git a/modules/highgui/src/cap_ffmpeg_api.hpp b/modules/highgui/src/cap_ffmpeg_api.hpp index 109049c2da..57d5f19395 100644 --- a/modules/highgui/src/cap_ffmpeg_api.hpp +++ b/modules/highgui/src/cap_ffmpeg_api.hpp @@ -21,8 +21,7 @@ enum CV_FFMPEG_CAP_PROP_FRAME_HEIGHT=4, CV_FFMPEG_CAP_PROP_FPS=5, CV_FFMPEG_CAP_PROP_FOURCC=6, - CV_FFMPEG_CAP_PROP_FRAME_COUNT=7, - CV_FFMPEG_CAP_PROP_THREADS=8 + CV_FFMPEG_CAP_PROP_FRAME_COUNT=7 }; diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index e2e678bbec..14ed8b750b 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -137,6 +137,52 @@ extern "C" { #define CALC_FFMPEG_VERSION(a,b,c) ( a<<16 | b<<8 | c ) +#if defined WIN32 || defined _WIN32 + #include +#elif defined __linux__ || defined __APPLE__ + #include + #include + #include + #include +#endif + +int get_number_of_cpus(void) +{ +#if defined WIN32 || defined _WIN32 + SYSTEM_INFO sysinfo; + GetSystemInfo( &sysinfo ); + + return (int)sysinfo.dwNumberOfProcessors; +#elif defined __linux__ + return (int)sysconf( _SC_NPROCESSORS_ONLN ); +#elif defined __APPLE__ + int numCPU=0; + int mib[4]; + size_t len = sizeof(numCPU); + + /* set the mib for hw.ncpu */ + mib[0] = CTL_HW; + mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU; + + /* get the number of CPUs from the system */ + sysctl(mib, 2, &numCPU, &len, NULL, 0); + + if( numCPU < 1 ) + { + mib[1] = HW_NCPU; + sysctl( mib, 2, &numCPU, &len, NULL, 0 ); + + if( numCPU < 1 ) + numCPU = 1; + } + + return (int)numCPU; +#else + return 1; +#endif +} + + char * FOURCC2str( int fourcc ) { char * mystr=(char*)malloc(5); @@ -365,7 +411,6 @@ struct CvCapture_FFMPEG and so the filename is needed to reopen the file on backward seeking. */ char * filename; - int count_threads; }; @@ -380,7 +425,6 @@ void CvCapture_FFMPEG::init() memset( &frame, 0, sizeof(frame) ); filename = 0; packet.data = NULL; - count_threads = 1; #if defined(HAVE_FFMPEG_SWSCALE) img_convert_ctx = 0; #endif @@ -447,7 +491,7 @@ bool CvCapture_FFMPEG::reopen() AVCodecContext *enc = &ic->streams[video_stream]->codec; #endif - avcodec_thread_init(enc, count_threads); + avcodec_thread_init(enc, get_number_of_cpus()); AVCodec *codec = avcodec_find_decoder(enc->codec_id); avcodec_open(enc, codec); @@ -494,7 +538,7 @@ bool CvCapture_FFMPEG::open( const char* _filename ) AVCodecContext *enc = &ic->streams[i]->codec; #endif - avcodec_thread_init(enc, count_threads); + avcodec_thread_init(enc, get_number_of_cpus()); #if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 4, 0) #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO @@ -717,9 +761,6 @@ double CvCapture_FFMPEG::getProperty( int property_id ) return (double)video_st->codec.codec_tag; #endif break; - case CV_CAP_PROP_THREADS: - return count_threads; - break; } return 0; @@ -804,13 +845,6 @@ bool CvCapture_FFMPEG::setProperty( int property_id, double value ) picture_pts=(int64_t)value; } break; - - case CV_CAP_PROP_THREADS: - { - count_threads = (int)value; - } - break; - default: return false; }