[FFmpeg-devel] fix MSVC compilation errors

Submitted by Mateusz on Dec. 4, 2017, 8:03 a.m.

Details

Message ID 20171204080310.6484-1-mateuszb@poczta.onet.pl
State New
Headers show

Commit Message

Mateusz Dec. 4, 2017, 8:03 a.m.
After commit 3701d49 'error_resilience: remove avpriv_atomic usage'
we have included windows.h in much more files and we should
avoid conflicts with defines/function declarations.

Signed-off-by: Mateusz Brzostek <mateuszb@poczta.onet.pl>
---
 libavcodec/jpegls.h  | 4 ++++
 libavcodec/mss2.c    | 6 +++---
 libavformat/mxfenc.c | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

Comments

Derek Buitenhuis Dec. 4, 2017, 2:02 p.m.
On 12/4/2017 8:03 AM, Mateusz wrote:
> After commit 3701d49 'error_resilience: remove avpriv_atomic usage'
> we have included windows.h in much more files and we should
> avoid conflicts with defines/function declarations.
> 
> Signed-off-by: Mateusz Brzostek <mateuszb@poczta.onet.pl>
> ---
>  libavcodec/jpegls.h  | 4 ++++
>  libavcodec/mss2.c    | 6 +++---
>  libavformat/mxfenc.c | 2 +-
>  3 files changed, 8 insertions(+), 4 deletions(-)

Sprinkling these weird ifdefs and renames around is pretty ugly. Is there
some sort of canonical list on MSDN or something we can use globally-ish?

- Derek
Mateusz Dec. 4, 2017, 7:27 p.m.
W dniu 04.12.2017 o 15:02, Derek Buitenhuis pisze:
> On 12/4/2017 8:03 AM, Mateusz wrote:
>> After commit 3701d49 'error_resilience: remove avpriv_atomic usage'
>> we have included windows.h in much more files and we should
>> avoid conflicts with defines/function declarations.
>>
>> Signed-off-by: Mateusz Brzostek <mateuszb@poczta.onet.pl>
>> ---
>>  libavcodec/jpegls.h  | 4 ++++
>>  libavcodec/mss2.c    | 6 +++---
>>  libavformat/mxfenc.c | 2 +-
>>  3 files changed, 8 insertions(+), 4 deletions(-)
> 
> Sprinkling these weird ifdefs and renames around is pretty ugly. Is there
> some sort of canonical list on MSDN or something we can use globally-ish?
> 
> - Derek

There is a list of "Predefined Macros" in MSVC -- IMO there are OK
https://msdn.microsoft.com/en-us/library/b0084kay(v=vs.140).aspx

More danger are macros from windows.h -- there is a list of macros
to exclude some parts (from MSDN and windows.h):
Define WIN32_LEAN_AND_MEAN to exclude APIs such as
Cryptography, DDE, RPC, Shell, and Windows Sockets.

/*  If defined, the following flags inhibit definition
 *     of the indicated items.
 *
 *  NOGDICAPMASKS     - CC_*, LC_*, PC_*, CP_*, TC_*, RC_
 *  NOVIRTUALKEYCODES - VK_*
 *  NOWINMESSAGES     - WM_*, EM_*, LB_*, CB_*
 *  NOWINSTYLES       - WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
 *  NOSYSMETRICS      - SM_*
 *  NOMENUS           - MF_*
 *  NOICONS           - IDI_*
 *  NOKEYSTATES       - MK_*
 *  NOSYSCOMMANDS     - SC_*
 *  NORASTEROPS       - Binary and Tertiary raster ops
 *  NOSHOWWINDOW      - SW_*
 *  OEMRESOURCE       - OEM Resource values
 *  NOATOM            - Atom Manager routines
 *  NOCLIPBOARD       - Clipboard routines
 *  NOCOLOR           - Screen colors
 *  NOCTLMGR          - Control and Dialog routines
 *  NODRAWTEXT        - DrawText() and DT_*
 *  NOGDI             - All GDI defines and routines
 *  NOKERNEL          - All KERNEL defines and routines
 *  NOUSER            - All USER defines and routines
 *  NONLS             - All NLS defines and routines
 *  NOMB              - MB_* and MessageBox()
 *  NOMEMMGR          - GMEM_*, LMEM_*, GHND, LHND, associated routines
 *  NOMETAFILE        - typedef METAFILEPICT
 *  NOMINMAX          - Macros min(a,b) and max(a,b)
 *  NOMSG             - typedef MSG and associated routines
 *  NOOPENFILE        - OpenFile(), OemToAnsi, AnsiToOem, and OF_*
 *  NOSCROLL          - SB_* and scrolling routines
 *  NOSERVICE         - All Service Controller routines, SERVICE_ equates, etc.
 *  NOSOUND           - Sound driver routines
 *  NOTEXTMETRIC      - typedef TEXTMETRIC and associated routines
 *  NOWH              - SetWindowsHook and WH_*
 *  NOWINOFFSETS      - GWL_*, GCL_*, associated routines
 *  NOCOMM            - COMM driver routines
 *  NOKANJI           - Kanji support stuff.
 *  NOHELP            - Help engine interface.
 *  NOPROFILER        - Profiler interface.
 *  NODEFERWINDOWPOS  - DeferWindowPos routines
 *  NOMCX             - Modem Configuration Extensions
 */

The most danger are small caps macros defined as empty in minwindef.h:
far
near
pascal
cdecl

I think it is possible to make in ffmpeg's *.h files which include windows.h
something like this:
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#define NOGDI
#include <windows.h>
#undef far
#undef near
#undef pascal
#undef cdecl

I will make some test and write back.

Mateusz

Patch hide | download patch | download mbox

diff --git a/libavcodec/jpegls.h b/libavcodec/jpegls.h
index c8997c7861..69a57b9538 100644
--- a/libavcodec/jpegls.h
+++ b/libavcodec/jpegls.h
@@ -32,6 +32,10 @@ 
 #include "avcodec.h"
 #include "internal.h"
 
+#ifdef near
+#undef near
+#endif
+
 typedef struct JpeglsContext {
     AVCodecContext *avctx;
 } JpeglsContext;
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 9e7cc466de..3180af1d60 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -464,9 +464,9 @@  static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
     return 0;
 }
 
-typedef struct Rectangle {
+struct Rectangle {
     int coded, x, y, w, h;
-} Rectangle;
+};
 
 #define MAX_WMV9_RECTANGLES 20
 #define ARITH2_PADDING 2
@@ -485,7 +485,7 @@  static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
     int keyframe, has_wmv9, has_mv, is_rle, is_555, ret;
 
-    Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r;
+    struct Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r;
     int used_rects = 0, i, implicit_rect = 0, av_uninit(wmv9_mask);
 
     if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index ed6ecbf541..407acdcaaa 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -1444,7 +1444,7 @@  static int mxf_write_header_metadata_sets(AVFormatContext *s)
     AVStream *st = NULL;
     int i;
 
-    MXFPackage packages[2] = {};
+    MXFPackage packages[2] = {{NULL}};
     int package_count = 2;
     packages[0].type = MaterialPackage;
     packages[1].type = SourcePackage;