diff mbox series

[FFmpeg-devel,2/2] mfenc: Avoid including codecapi.h, fix building in UWP mode with clang

Message ID 20200525103358.11331-2-martin@martin.st
State Accepted
Commit 6c33a230e46a1434e32acf0004c6ffb983c2b566
Headers show
Series [FFmpeg-devel,1/2] mfenc: Remove an unused include | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Martin Storsjö May 25, 2020, 10:33 a.m. UTC
Including codecapi.h and uuids.h in UWP mode doesn't define all defines
properly, ending up with constructs that MSVC silently tolerates, but
that clang errors out on, like this:
    DEFINE_GUIDEX(CODECAPI_AVEncCommonFormatConstraint);

Just avoid including codecapi.h completely and hardcode the last few
enum values we use from there. We already use local versions of most
enums from there, due to older mingw-w64 headers being incomplete.
---
 libavcodec/mf_utils.h | 15 +++++++++++----
 libavcodec/mfenc.c    |  6 +++---
 2 files changed, 14 insertions(+), 7 deletions(-)

Comments

Martin Storsjö May 26, 2020, 7:14 p.m. UTC | #1
On Mon, 25 May 2020, Martin Storsjö wrote:

> Including codecapi.h and uuids.h in UWP mode doesn't define all defines
> properly, ending up with constructs that MSVC silently tolerates, but
> that clang errors out on, like this:
>    DEFINE_GUIDEX(CODECAPI_AVEncCommonFormatConstraint);
>
> Just avoid including codecapi.h completely and hardcode the last few
> enum values we use from there. We already use local versions of most
> enums from there, due to older mingw-w64 headers being incomplete.
> ---
> libavcodec/mf_utils.h | 15 +++++++++++----
> libavcodec/mfenc.c    |  6 +++---
> 2 files changed, 14 insertions(+), 7 deletions(-)

Will push these, to fix compilation with clang/msvc in UWP mode.

// Martin
diff mbox series

Patch

diff --git a/libavcodec/mf_utils.h b/libavcodec/mf_utils.h
index 4373e62ed2..d514723c3b 100644
--- a/libavcodec/mf_utils.h
+++ b/libavcodec/mf_utils.h
@@ -28,15 +28,12 @@ 
 // of including it though, through strmif.h via dshow.h. And on mingw, the
 // mf*.h headers below indirectly include strmif.h.)
 #include <icodecapi.h>
-// Clang in MSVC mode fails on codecapi.h if we haven't included uuids.h
-// before, while it seems to work fine with MSVC itself.
-#include <uuids.h>
 #else
 #include <dshow.h>
-#endif
 // Older versions of mingw-w64 need codecapi.h explicitly included, while newer
 // ones include it implicitly from dshow.h (via uuids.h).
 #include <codecapi.h>
+#endif
 #include <mfapi.h>
 #include <mferror.h>
 #include <mfobjects.h>
@@ -134,6 +131,16 @@  enum {
     ff_METransformMarker,
 };
 
+// These do exist in all supported headers, but are manually defined here
+// to avoid having to include codecapi.h, as there's problems including that
+// header when targeting UWP (where including it with MSVC seems to work,
+// but fails when built with clang in MSVC mode).
+enum ff_eAVEncH264VProfile {
+   ff_eAVEncH264VProfile_Base = 66,
+   ff_eAVEncH264VProfile_Main = 77,
+   ff_eAVEncH264VProfile_High = 100,
+};
+
 char *ff_hr_str_buf(char *buf, size_t size, HRESULT hr);
 #define ff_hr_str(hr) ff_hr_str_buf((char[80]){0}, 80, hr)
 
diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 3432d48f30..ee3c164e69 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -651,13 +651,13 @@  static int mf_encv_output_adjust(AVCodecContext *avctx, IMFMediaType *type)
 
     // (MS HEVC supports eAVEncH265VProfile_Main_420_8 only.)
     if (avctx->codec_id == AV_CODEC_ID_H264) {
-        UINT32 profile = eAVEncH264VProfile_Base;
+        UINT32 profile = ff_eAVEncH264VProfile_Base;
         switch (avctx->profile) {
         case FF_PROFILE_H264_MAIN:
-            profile = eAVEncH264VProfile_Main;
+            profile = ff_eAVEncH264VProfile_Main;
             break;
         case FF_PROFILE_H264_HIGH:
-            profile = eAVEncH264VProfile_High;
+            profile = ff_eAVEncH264VProfile_High;
             break;
         }
         IMFAttributes_SetUINT32(type, &MF_MT_MPEG2_PROFILE, profile);