From 129952a9e2a0ef6d1dd9c1f94324bedf642af36e Fri Oct 16 00:00:00 2015 From: Alexander Prikhodko Date: Fri, 16 Oct 2015 23:50:00 +0300 Subject: Revert using "numthreads" because for non POSIX (Win32) gcc threading model C++11 extension for "std::thread" not working. diff -uNrp src/Makefile.am src.new/Makefile.am --- src/Makefile.am 2015-10-16 22:44:46 +0300 +++ src.new/Makefile.am 2015-10-16 22:45:54 +0300 @@ -32,6 +32,8 @@ src_core_libffms2_la_SOURCES = \ src/core/lavfaudio.cpp \ src/core/lavfindexer.cpp \ src/core/lavfvideo.cpp \ + src/core/numthreads.cpp \ + src/core/numthreads.h \ src/core/track.cpp \ src/core/track.h \ src/core/utils.cpp \ diff -uNrp src/Makefile.in src.new/Makefile.in --- src/Makefile.in 2015-10-16 22:44:46 +0300 +++ src.new/Makefile.in 2015-10-16 22:47:24 +0300 @@ -145,7 +145,7 @@ am__dirstamp = $(am__leading_dot)dirstam am_src_core_libffms2_la_OBJECTS = src/core/audiosource.lo \ src/core/ffms.lo src/core/filehandle.lo src/core/indexing.lo \ src/core/lavfaudio.lo src/core/lavfindexer.lo \ - src/core/lavfvideo.lo src/core/track.lo src/core/utils.lo \ + src/core/lavfvideo.lo src/core/numthreads.lo src/core/track.lo src/core/utils.lo \ src/core/videosource.lo src/core/videoutils.lo \ src/core/wave64writer.lo src/core/zipfile.lo \ src/vapoursynth/vapoursource.lo src/vapoursynth/vapoursynth.lo @@ -430,6 +430,8 @@ src_core_libffms2_la_SOURCES = \ src/core/lavfaudio.cpp \ src/core/lavfindexer.cpp \ src/core/lavfvideo.cpp \ + src/core/numthreads.cpp \ + src/core/numthreads.h \ src/core/track.cpp \ src/core/track.h \ src/core/utils.cpp \ @@ -559,6 +561,8 @@ src/core/lavfindexer.lo: src/core/$(am__ src/core/$(DEPDIR)/$(am__dirstamp) src/core/lavfvideo.lo: src/core/$(am__dirstamp) \ src/core/$(DEPDIR)/$(am__dirstamp) +src/core/numthreads.lo: src/core/$(am__dirstamp) \ + src/core/$(DEPDIR)/$(am__dirstamp) src/core/track.lo: src/core/$(am__dirstamp) \ src/core/$(DEPDIR)/$(am__dirstamp) src/core/utils.lo: src/core/$(am__dirstamp) \ @@ -664,6 +668,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/core/$(DEPDIR)/lavfaudio.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/core/$(DEPDIR)/lavfindexer.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/core/$(DEPDIR)/lavfvideo.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@src/core/$(DEPDIR)/numthreads.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/core/$(DEPDIR)/track.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/core/$(DEPDIR)/utils.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/core/$(DEPDIR)/videosource.Plo@am__quote@ diff -uNrp src/src/core/numthreads.cpp src.new/src/core/numthreads.cpp --- src/src/core/numthreads.cpp 1970-01-01 03:00:00 +0300 +++ src.new/src/core/numthreads.cpp 2012-06-18 13:20:14 +0300 @@ -0,0 +1,80 @@ +// Copyright (c) 2011 Alexander Smith +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#define MAX_NUM_THREADS 16 //libav currently has bugs with > 16 threads +#include "numthreads.h" + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#endif +#ifdef __CYGWIN__ +#include +#endif +#ifdef __linux__ +#include +#endif +#if defined(__APPLE__) || defined(__FREEBSD__) +#include +#include +#endif +#ifdef __OPENBSD__ +#include +#include +#include +#endif + +int GetNumberOfLogicalCPUs() { + int threads = 1; + +#ifdef _WIN32 + SYSTEM_INFO SI; + GetSystemInfo(&SI); + threads = SI.dwNumberOfProcessors; + +#elif defined(__CYGWIN__) + threads = sysconf(_SC_NPROCESSORS_ONLN); + +#elif defined(__linux__) + cpu_set_t proc_affinity; + if (!sched_getaffinity(0, sizeof(proc_affinity), &proc_affinity)) + threads = CPU_COUNT(&proc_affinity); + +#elif defined(__APPLE__) || defined(__FREEBSD__) || defined(__OPENBSD__) + int num_cpu; + size_t length = sizeof(num_cpu); +#ifdef __OPENBSD__ + int mib[2] = {CTL_HW, HW_NCPU}; + if (!sysctl(mib, 2, &num_cpu, &length, NULL, 0)) +#else + if (!sysctlbyname("hw.ncpu", &num_cpu, &length, NULL, 0)) +#endif + threads = num_cpu; +#endif + + if (threads > MAX_NUM_THREADS) + return MAX_NUM_THREADS; + else + return threads; +} diff -uNrp src/src/core/numthreads.h src.new/src/core/numthreads.h --- src/src/core/numthreads.h 1970-01-01 03:00:00 +0300 +++ src.new/src/core/numthreads.h 2011-07-22 14:13:06 +0300 @@ -0,0 +1,21 @@ +// Copyright (c) 2011 Alexander Smith +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +int GetNumberOfLogicalCPUs(); diff -uNrp src/src/core/videosource.cpp src.new/src/core/videosource.cpp --- src/src/core/videosource.cpp 2015-10-16 22:44:46 +0300 +++ src.new/src/core/videosource.cpp 2015-10-16 22:58:27 +0300 @@ -21,10 +21,10 @@ #include "videosource.h" #include "indexing.h" +#include "numthreads.h" #include "videoutils.h" #include -#include namespace { void CopyAVPictureFields(AVPicture &Picture, FFMS_Frame &Dst) { @@ -150,7 +150,7 @@ FFMS_VideoSource::FFMS_VideoSource(const InputColorRange = AVCOL_RANGE_UNSPECIFIED; if (Threads < 1) // libav current has issues with greater than 16 threads - DecodingThreads = (std::min)(std::thread::hardware_concurrency(), 16u); + DecodingThreads = (std::min)((unsigned int) GetNumberOfLogicalCPUs(), 16u); else DecodingThreads = Threads; DecodeFrame = av_frame_alloc();