|
61 | 61 | #ifdef __GNUC__
|
62 | 62 | # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
63 | 63 | #endif
|
| 64 | +#ifdef _MSC_VER |
| 65 | +#pragma warning(disable: 4996) // was declared deprecated |
| 66 | +#endif |
64 | 67 |
|
65 | 68 | #ifndef CV_UNUSED // Required for standalone compilation mode (OpenCV defines this in base.hpp)
|
66 | 69 | #define CV_UNUSED(name) (void)name
|
@@ -250,7 +253,7 @@ inline void get_monotonic_time(timespec *tv)
|
250 | 253 |
|
251 | 254 | t.QuadPart -= offset.QuadPart;
|
252 | 255 | microseconds = (double)t.QuadPart / frequencyToMicroseconds;
|
253 |
| - t.QuadPart = microseconds; |
| 256 | + t.QuadPart = (LONGLONG)microseconds; |
254 | 257 | tv->tv_sec = t.QuadPart / 1000000;
|
255 | 258 | tv->tv_nsec = (t.QuadPart % 1000000) * 1000;
|
256 | 259 | }
|
@@ -722,16 +725,6 @@ struct ImplMutex::Impl
|
722 | 725 | int refcount;
|
723 | 726 | };
|
724 | 727 |
|
725 |
| -#ifndef __GNUC__ |
726 |
| -static int _interlockedExchangeAdd(int* addr, int delta) |
727 |
| -{ |
728 |
| -#if defined _MSC_VER && _MSC_VER >= 1500 |
729 |
| - return (int)_InterlockedExchangeAdd((long volatile*)addr, delta); |
730 |
| -#else |
731 |
| - return (int)InterlockedExchangeAdd((long volatile*)addr, delta); |
732 |
| -#endif |
733 |
| -} |
734 |
| -#endif // __GNUC__ |
735 | 728 |
|
736 | 729 | #elif defined __APPLE__
|
737 | 730 |
|
@@ -859,51 +852,70 @@ static void ffmpeg_log_callback(void *ptr, int level, const char *fmt, va_list v
|
859 | 852 |
|
860 | 853 | class InternalFFMpegRegister
|
861 | 854 | {
|
862 |
| -public: |
863 |
| - InternalFFMpegRegister() |
| 855 | + static void init_() |
864 | 856 | {
|
865 |
| - AutoLock lock(_mutex); |
866 |
| - if (!_initialized) |
| 857 | + static InternalFFMpegRegister instance; |
| 858 | + } |
| 859 | + |
| 860 | + static void initLogger_() |
| 861 | + { |
| 862 | + #ifndef NO_GETENV |
| 863 | + char* debug_option = getenv("OPENCV_FFMPEG_DEBUG"); |
| 864 | + if (debug_option != NULL) |
867 | 865 | {
|
868 |
| - #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0) |
869 |
| - avformat_network_init(); |
| 866 | + av_log_set_level(AV_LOG_VERBOSE); |
| 867 | + av_log_set_callback(ffmpeg_log_callback); |
| 868 | + } |
| 869 | + else |
870 | 870 | #endif
|
| 871 | + { |
| 872 | + av_log_set_level(AV_LOG_ERROR); |
| 873 | + } |
| 874 | + } |
871 | 875 |
|
872 |
| - /* register all codecs, demux and protocols */ |
873 |
| - av_register_all(); |
874 |
| - |
875 |
| - /* register a callback function for synchronization */ |
876 |
| - av_lockmgr_register(&LockCallBack); |
877 |
| - |
878 |
| -#ifndef NO_GETENV |
879 |
| - char* debug_option = getenv("OPENCV_FFMPEG_DEBUG"); |
880 |
| - if (debug_option != NULL) |
| 876 | +public: |
| 877 | + static void init() |
| 878 | + { |
| 879 | + if (!_initialized) |
| 880 | + { |
| 881 | + AutoLock lock(_mutex); |
| 882 | + if (!_initialized) |
881 | 883 | {
|
882 |
| - av_log_set_level(AV_LOG_VERBOSE); |
883 |
| - av_log_set_callback(ffmpeg_log_callback); |
| 884 | + init_(); |
884 | 885 | }
|
885 |
| - else |
| 886 | + } |
| 887 | + initLogger_(); // update logger setup unconditionally (GStreamer's libav plugin may override these settings) |
| 888 | + } |
| 889 | + |
| 890 | + InternalFFMpegRegister() |
| 891 | + { |
| 892 | +#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0) |
| 893 | + avformat_network_init(); |
886 | 894 | #endif
|
887 |
| - { |
888 |
| - av_log_set_level(AV_LOG_ERROR); |
889 |
| - } |
890 | 895 |
|
891 |
| - _initialized = true; |
892 |
| - } |
| 896 | + /* register all codecs, demux and protocols */ |
| 897 | + av_register_all(); |
| 898 | + |
| 899 | + /* register a callback function for synchronization */ |
| 900 | + av_lockmgr_register(&LockCallBack); |
| 901 | + |
| 902 | + _initialized = true; |
893 | 903 | }
|
894 | 904 |
|
895 | 905 | ~InternalFFMpegRegister()
|
896 | 906 | {
|
897 | 907 | _initialized = false;
|
898 | 908 | av_lockmgr_register(NULL);
|
| 909 | + av_log_set_callback(NULL); |
899 | 910 | }
|
900 | 911 | };
|
901 | 912 |
|
902 |
| -static InternalFFMpegRegister _init; |
903 |
| - |
904 | 913 | bool CvCapture_FFMPEG::open( const char* _filename )
|
905 | 914 | {
|
| 915 | + InternalFFMpegRegister::init(); |
| 916 | + |
906 | 917 | AutoLock lock(_mutex);
|
| 918 | + |
907 | 919 | unsigned i;
|
908 | 920 | bool valid = false;
|
909 | 921 |
|
@@ -1416,9 +1428,9 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
|
1416 | 1428 | case CV_FFMPEG_CAP_PROP_FRAME_COUNT:
|
1417 | 1429 | return (double)get_total_frames();
|
1418 | 1430 | case CV_FFMPEG_CAP_PROP_FRAME_WIDTH:
|
1419 |
| - return (double)((rotation_auto && rotation_angle%180) ? frame.height : frame.width); |
| 1431 | + return (double)((rotation_auto && ((rotation_angle%180) != 0)) ? frame.height : frame.width); |
1420 | 1432 | case CV_FFMPEG_CAP_PROP_FRAME_HEIGHT:
|
1421 |
| - return (double)((rotation_auto && rotation_angle%180) ? frame.width : frame.height); |
| 1433 | + return (double)((rotation_auto && ((rotation_angle%180) != 0)) ? frame.width : frame.height); |
1422 | 1434 | case CV_FFMPEG_CAP_PROP_FPS:
|
1423 | 1435 | return get_fps();
|
1424 | 1436 | case CV_FFMPEG_CAP_PROP_FOURCC:
|
@@ -1658,10 +1670,10 @@ bool CvCapture_FFMPEG::setProperty( int property_id, double value )
|
1658 | 1670 | case CV_FFMPEG_CAP_PROP_ORIENTATION_AUTO:
|
1659 | 1671 | #if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \
|
1660 | 1672 | (LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100)))
|
1661 |
| - rotation_auto = static_cast<bool>(value); |
| 1673 | + rotation_auto = value != 0 ? true : false; |
1662 | 1674 | return true;
|
1663 | 1675 | #else
|
1664 |
| - rotation_auto = 0; |
| 1676 | + rotation_auto = false; |
1665 | 1677 | return false;
|
1666 | 1678 | #endif
|
1667 | 1679 | break;
|
@@ -2096,7 +2108,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
|
2096 | 2108 | // 2. (dataend - SIMD_SIZE) and (dataend + SIMD_SIZE) is from the same 4k page
|
2097 | 2109 | const int CV_STEP_ALIGNMENT = 32;
|
2098 | 2110 | const size_t CV_SIMD_SIZE = 32;
|
2099 |
| - const size_t CV_PAGE_MASK = ~(4096 - 1); |
| 2111 | + const size_t CV_PAGE_MASK = ~(size_t)(4096 - 1); |
2100 | 2112 | const unsigned char* dataend = data + ((size_t)height * step);
|
2101 | 2113 | if (step % CV_STEP_ALIGNMENT != 0 ||
|
2102 | 2114 | (((size_t)dataend - CV_SIMD_SIZE) & CV_PAGE_MASK) != (((size_t)dataend + CV_SIMD_SIZE) & CV_PAGE_MASK))
|
@@ -2295,6 +2307,10 @@ static inline void cv_ff_codec_tag_dump(const AVCodecTag *const *tags)
|
2295 | 2307 | bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
2296 | 2308 | double fps, int width, int height, bool is_color )
|
2297 | 2309 | {
|
| 2310 | + InternalFFMpegRegister::init(); |
| 2311 | + |
| 2312 | + AutoLock lock(_mutex); |
| 2313 | + |
2298 | 2314 | CV_CODEC_ID codec_id = CV_CODEC(CODEC_ID_NONE);
|
2299 | 2315 | int err, codec_pix_fmt;
|
2300 | 2316 | double bitrate_scale = 1;
|
@@ -2569,7 +2585,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
2569 | 2585 | }
|
2570 | 2586 |
|
2571 | 2587 | int64_t lbit_rate = (int64_t)c->bit_rate;
|
2572 |
| - lbit_rate += (bitrate / 2); |
| 2588 | + lbit_rate += (int64_t)(bitrate / 2); |
2573 | 2589 | lbit_rate = std::min(lbit_rate, (int64_t)INT_MAX);
|
2574 | 2590 | c->bit_rate_tolerance = (int)lbit_rate;
|
2575 | 2591 | c->bit_rate = (int)lbit_rate;
|
@@ -2962,7 +2978,7 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height,
|
2962 | 2978 | #endif
|
2963 | 2979 |
|
2964 | 2980 | c->codec_tag = MKTAG('H', '2', '6', '4');
|
2965 |
| - c->bit_rate_tolerance = c->bit_rate; |
| 2981 | + c->bit_rate_tolerance = (int)(c->bit_rate); |
2966 | 2982 |
|
2967 | 2983 | // open the output file, if needed
|
2968 | 2984 | if (!(fmt_->flags & AVFMT_NOFILE))
|
|
0 commit comments