Skip to content

Compile windows _camera on MSVC only #2585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2023
Merged

Compile windows _camera on MSVC only #2585

merged 2 commits into from
Dec 3, 2023

Conversation

ankith26
Copy link
Member

The goal is to get pygame compiling on mingw (intended for pygame contributors on windows who would prefer it), and currently _camera is the only thing that doesn't compile under mingw. So take the easy route and not try to compile it (this shouldn't really affect anything, we should still be doing releases with MSVC)

@Starbuck5 requesting your review (oh and also, do you think we should also do a compiler version check, and if yes, to what?)

@ankith26 ankith26 requested a review from a team as a code owner November 22, 2023 12:13
@ankith26
Copy link
Member Author

Also if anyone is interested, here is the compiler error log while trying to compile _camera on windows

 FAILED: src_c/_camera.cp312-win_amd64.pyd.p/camera_windows.c.obj
  "ccache" "gcc" "-Isrc_c\_camera.cp312-win_amd64.pyd.p" "-Isrc_c" "-I..\src_c" "-IC:\Users\vboxuser\Downloads\ankith26-build-meson\pygame-ce\prebuilt-x64\SDL2-2.26.5\include" "-IC:\Users\vboxuser\Downloads\ankith26-build-meson\pygame-ce\prebuilt-x64\SDL2_image-2.0.5\include" "-IC:\Users\vboxuser\Downloads\ankith26-build-meson\pygame-ce\prebuilt-x64\SDL2_mixer-2.6.2\include" "-IC:\Users\vboxuser\Downloads\ankith26-build-meson\pygame-ce\prebuilt-x64\SDL2_ttf-2.20.2\include" "-IC:\Users\vboxuser\Downloads\ankith26-build-meson\pygame-ce\prebuilt-x64\include" "-IC:\Users\vboxuser\AppData\Local\Programs\Python\Python312\Include" "-fvisibility=hidden" "-fdiagnostics-color=always" "-DNDEBUG" "-D_FILE_OFFSET_BITS=64" "-O3" "-Wall" "-Wno-error=unknown-pragmas" -MD -MQ src_c/_camera.cp312-win_amd64.pyd.p/camera_windows.c.obj -MF "src_c\_camera.cp312-win_amd64.pyd.p\camera_windows.c.obj.d" -o src_c/_camera.cp312-win_amd64.pyd.p/camera_windows.c.obj "-c" ../src_c/camera_windows.c
  ../src_c/camera_windows.c: In function 'update_function':
  ../src_c/camera_windows.c:543:31: error: invalid use of incomplete typedef 'IMFVideoProcessorControl'
    543 |             hr = self->control->lpVtbl->SetMirror(self->control,
        |                               ^~
  ../src_c/camera_windows.c:544:51: error: 'MIRROR_HORIZONTAL' undeclared (first use in this function); did you mean 'MDITILE_HORIZONTAL'?
    544 |                                                   MIRROR_HORIZONTAL);
        |                                                   ^~~~~~~~~~~~~~~~~
        |                                                   MDITILE_HORIZONTAL
  ../src_c/camera_windows.c:544:51: note: each undeclared identifier is reported only once for each function it appears in
  ../src_c/camera_windows.c:548:31: error: invalid use of incomplete typedef 'IMFVideoProcessorControl'
    548 |             hr = self->control->lpVtbl->SetMirror(self->control, MIRROR_NONE);
        |                               ^~
  ../src_c/camera_windows.c:548:66: error: 'MIRROR_NONE' undeclared (first use in this function)
    548 |             hr = self->control->lpVtbl->SetMirror(self->control, MIRROR_NONE);
        |                                                                  ^~~~~~~~~~~
  ../src_c/camera_windows.c:557:53: warning: pointer targets in passing argument 3 of 'output_type->lpVtbl->GetUINT32' differ in signedness [-Wpointer-sign]
    557 |                 output_type, &MF_MT_DEFAULT_STRIDE, &stride);
        |                                                     ^~~~~~~
        |                                                     |
        |                                                     INT32 * {aka int *}
  ../src_c/camera_windows.c:557:53: note: expected 'UINT32 *' {aka 'unsigned int *'} but argument is of type 'INT32 *' {aka 'int *'}
  ../src_c/camera_windows.c: In function 'windows_open_device':
  ../src_c/camera_windows.c:631:64: warning: passing argument 3 of 'act->lpVtbl->ActivateObject' from incompatible pointer type [-Wincompatible-pointer-types]
    631 |     hr = act->lpVtbl->ActivateObject(act, &IID_IMFMediaSource, &source);
        |                                                                ^~~~~~~
        |                                                                |
        |                                                                IMFMediaSource **
  ../src_c/camera_windows.c:631:64: note: expected 'void **' but argument is of type 'IMFMediaSource **'
  ../src_c/camera_windows.c:663:28: error: 'CLSID_VideoProcessorMFT' undeclared (first use in this function)
    663 |     hr = CoCreateInstance(&CLSID_VideoProcessorMFT, NULL, CLSCTX_INPROC_SERVER,
        |                            ^~~~~~~~~~~~~~~~~~~~~~~
  ../src_c/camera_windows.c:664:46: warning: passing argument 5 of 'CoCreateInstance' from incompatible pointer type [-Wincompatible-pointer-types]
    664 |                           &IID_IMFTransform, &transform);
        |                                              ^~~~~~~~~~
        |                                              |
        |                                              IMFTransform **
  In file included from C:/mingw64/x86_64-w64-mingw32/include/objbase.h:14,
                   from C:/mingw64/x86_64-w64-mingw32/include/ole2.h:17,
                   from C:/mingw64/x86_64-w64-mingw32/include/wtypes.h:13,
                   from C:/mingw64/x86_64-w64-mingw32/include/winscard.h:10,
                   from C:/mingw64/x86_64-w64-mingw32/include/windows.h:97,
                   from C:/mingw64/x86_64-w64-mingw32/include/rpc.h:16,
                   from C:/mingw64/x86_64-w64-mingw32/include/mfobjects.h:7,
                   from C:/mingw64/x86_64-w64-mingw32/include/mfapi.h:11,
                   from ../src_c/camera.h:53,
                   from ../src_c/_camera.h:24,
                   from ../src_c/camera_windows.c:37:
  C:/mingw64/x86_64-w64-mingw32/include/combaseapi.h:258:108: note: expected 'void **' but argument is of type 'IMFTransform **'
    258 | WINOLEAPI CoCreateInstance (REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv);
        |                                                                                                    ~~~~~~~~^~~
  ../src_c/camera_windows.c:669:21: error: 'IID_IMFVideoProcessorControl' undeclared (first use in this function); did you mean 'IMFVideoProcessorControl'?
    669 |         transform, &IID_IMFVideoProcessorControl, &control);
        |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |                     IMFVideoProcessorControl
  ../src_c/camera_windows.c:669:51: warning: passing argument 3 of 'transform->lpVtbl->QueryInterface' from incompatible pointer type [-Wincompatible-pointer-types]
    669 |         transform, &IID_IMFVideoProcessorControl, &control);
        |                                                   ^~~~~~~~
        |                                                   |
        |                                                   IMFVideoProcessorControl **
  ../src_c/camera_windows.c:669:51: note: expected 'void **' but argument is of type 'IMFVideoProcessorControl **'
  ../src_c/camera_windows.c: In function 'windows_close_device':
  ../src_c/camera_windows.c:55:12: error: invalid use of incomplete typedef 'IMFVideoProcessorControl'
     55 |         obj->lpVtbl->Release(obj); \
        |            ^~
  ../src_c/camera_windows.c:712:5: note: in expansion of macro 'RELEASE'
    712 |     RELEASE(self->control);
        |     ^~~~~~~
  ../src_c/camera_windows.c: In function 'windows_read_raw':
  ../src_c/camera_windows.c:872:42: warning: pointer targets in passing argument 1 of 'PyBytes_FromStringAndSize' differ in signedness [-Wpointer-sign]
    872 |         data = PyBytes_FromStringAndSize(buf_data, buf_length);
        |                                          ^~~~~~~~
        |                                          |
        |                                          BYTE * {aka unsigned char *}
  In file included from C:\Users\vboxuser\AppData\Local\Programs\Python\Python312\Include/Python.h:50,
                   from ../src_c/_pygame.h:35,
                   from ../src_c/_camera.h:23:
  C:\Users\vboxuser\AppData\Local\Programs\Python\Python312\Include/bytesobject.h:34:50: note: expected 'const char *' but argument is of type 'BYTE *' {aka 'unsigned char *'}
     34 | PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
        |                                                  ^~~~~~~~~~~~
  ninja: build stopped: subcommand failed.

@ankith26 ankith26 requested a review from Starbuck5 November 22, 2023 12:18
@MyreMylar
Copy link
Member

What version of mingw-w64 is being used to generate these compile errors? I can see in the Github for MinGW-w64 that the stuff being mentioned as undefined was added in February last year. See:

mirror/mingw-w64@ca9adcf

So it looks like we'd need at least version v10.0.0 from April of last year for this to have a chance of working.

@MyreMylar
Copy link
Member

This seems like an interesting source of binaries for mingw:

https://github.com/niXman/mingw-builds-binaries/releases

@ankith26
Copy link
Member Author

I downloaded the latest from here https://winlibs.com/ and the exact one I downloaded is called
GCC 13.2.0 (with MCF threads) + MinGW-w64 11.0.1 (UCRT) - release 3

Maybe I should have downloaded some other configuration?

@MyreMylar
Copy link
Member

I tried building with what seems like a slightly more up to date mingw (via this installer) than the above but it still failed to compile the windows camera due to a lack of:

CLSID_VideoProcessorMFT

There is a patch here to add it - but it is not in yet, so I guess for now we comment out the windows camera module on mingw builds.
https://www.mail-archive.com/mingw-w64-public@lists.sourceforge.net/msg21200.html

I think this change needs a comment to explain why we've done it though as it may be confusing when we revisit this in two years and can't remember why it was done or what we need to do to make the camera work on mingw builds.

Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - though could use a comment mentioning mingw 👍

@MyreMylar MyreMylar added Windows build Compiling stuff labels Nov 26, 2023
Copy link
Member

@Starbuck5 Starbuck5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked it out locally, looks good.

@Starbuck5 Starbuck5 merged commit 939b94a into main Dec 3, 2023
@Starbuck5 Starbuck5 deleted the ankith26-msvc-cam branch December 3, 2023 19:21
@Starbuck5 Starbuck5 added this to the 2.4.0 milestone Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Compiling stuff Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants