Skip to content

Commit

Permalink
Add Metal renderer for Mac and iOS (#3841)
Browse files Browse the repository at this point in the history
  • Loading branch information
sauwming authored Jan 29, 2024
1 parent e2b7d73 commit b3ea8a2
Show file tree
Hide file tree
Showing 11 changed files with 1,049 additions and 1 deletion.
31 changes: 31 additions & 0 deletions aconfigure
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ ac_pjmedia_video_has_qt
ac_darwin_cflags
ac_pjmedia_video_has_ios_opengl
ac_pjmedia_video_has_vtoolbox
ac_pjmedia_video_has_metal
ac_pjmedia_video_has_darwin
ac_dshow_ldflags
ac_dshow_cflags
Expand Down Expand Up @@ -7469,6 +7470,7 @@ printf "%s\n" "Checking if OpenGL ES 2 is available... no" >&6; }




SAVED_LIBS="$LIBS"
LIBS="-framework AVFoundation -framework CoreGraphics -framework QuartzCore -framework CoreVideo -framework CoreMedia"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
Expand Down Expand Up @@ -7508,6 +7510,26 @@ then :
else $as_nop
ac_pjmedia_video_has_vtoolbox=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext
LIBS="-framework Metal"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main (void)
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
then :
ac_pjmedia_video_has_metal=yes
else $as_nop
ac_pjmedia_video_has_metal=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext
LIBS="-framework OpenGLES"
Expand Down Expand Up @@ -7539,6 +7561,15 @@ printf "%s\n" "Checking if AVFoundation framework is available... yes" >&6; }
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Checking if AVFoundation framework is available... no" >&5
printf "%s\n" "Checking if AVFoundation framework is available... no" >&6; }
fi
if test "$ac_pjmedia_video_has_metal" = "yes"; then
ac_darwin_cflags+=" -DPJMEDIA_VIDEO_DEV_HAS_METAL=1"
LIBS="$LIBS -framework Metal -framework MetalKit"
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Checking if Metal framework is available... yes" >&5
printf "%s\n" "Checking if Metal framework is available... yes" >&6; }
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Checking if Metal framework is available... no" >&5
printf "%s\n" "Checking if Metal framework is available... no" >&6; }
fi
if test "$ac_pjmedia_video_has_vtoolbox" = "yes"; then
#ac_darwin_cflags+=" -DPJMEDIA_HAS_VID_TOOLBOX_CODEC=1"
Expand Down
12 changes: 12 additions & 0 deletions aconfigure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ else
*darwin*)
ac_pjmedia_video=darwin_os
AC_SUBST(ac_pjmedia_video_has_darwin)
AC_SUBST(ac_pjmedia_video_has_metal)
AC_SUBST(ac_pjmedia_video_has_vtoolbox)
AC_SUBST(ac_pjmedia_video_has_ios_opengl)
AC_SUBST(ac_darwin_cflags)
Expand All @@ -1059,6 +1060,10 @@ else
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [])],
[ac_pjmedia_video_has_vtoolbox=yes],
[ac_pjmedia_video_has_vtoolbox=no])
LIBS="-framework Metal"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [])],
[ac_pjmedia_video_has_metal=yes],
[ac_pjmedia_video_has_metal=no])
LIBS="-framework OpenGLES"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [])],
[ac_pjmedia_video_has_ios_opengl=yes],
Expand All @@ -1071,6 +1076,13 @@ else
else
AC_MSG_RESULT([Checking if AVFoundation framework is available... no])
fi
if test "$ac_pjmedia_video_has_metal" = "yes"; then
ac_darwin_cflags+=" -DPJMEDIA_VIDEO_DEV_HAS_METAL=1"
LIBS="$LIBS -framework Metal -framework MetalKit"
AC_MSG_RESULT([Checking if Metal framework is available... yes])
else
AC_MSG_RESULT([Checking if Metal framework is available... no])
fi
if test "$ac_pjmedia_video_has_vtoolbox" = "yes"; then
#ac_darwin_cflags+=" -DPJMEDIA_HAS_VID_TOOLBOX_CODEC=1"
LIBS="$LIBS -framework VideoToolbox"
Expand Down
1 change: 1 addition & 0 deletions build.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ AC_PJMEDIA_VIDEO_HAS_QT = @ac_pjmedia_video_has_qt@

# Darwin (Mac and iOS)
AC_PJMEDIA_VIDEO_HAS_DARWIN = @ac_pjmedia_video_has_darwin@
AC_PJMEDIA_VIDEO_HAS_METAL = @ac_pjmedia_video_has_metal@
AC_PJMEDIA_VIDEO_HAS_VTOOLBOX = @ac_pjmedia_video_has_vtoolbox@
AC_PJMEDIA_VIDEO_HAS_IOS_OPENGL = @ac_pjmedia_video_has_ios_opengl@
DARWIN_CFLAGS = @ac_darwin_cflags@
Expand Down
7 changes: 7 additions & 0 deletions pjmedia/build/os-auto.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ ifeq ($(AC_PJMEDIA_VIDEO_HAS_DARWIN),yes)
export PJMEDIA_VIDEODEV_OBJS += darwin_dev.o
endif

#
# Metal video device
#
ifeq ($(AC_PJMEDIA_VIDEO_HAS_METAL),yes)
export PJMEDIA_VIDEODEV_OBJS += metal_dev.o
endif

#
# VideoToolbox codec
#
Expand Down
5 changes: 5 additions & 0 deletions pjmedia/include/pjmedia/videodev.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ typedef enum pjmedia_vid_dev_hwnd_type
*/
PJMEDIA_VID_DEV_HWND_TYPE_WINDOWS,

/**
* Native view on Cocoa Mac.
*/
PJMEDIA_VID_DEV_HWND_TYPE_COCOA,

/**
* Native view on iOS.
*/
Expand Down
Loading

1 comment on commit b3ea8a2

@TechGuyVN
Copy link

Choose a reason for hiding this comment

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

why we don't have flag to enable this features, i pull and build have error in IOS, need add more framework

Please sign in to comment.