Sunday, December 15, 2024

Re: mplayer: use XShm 1.2

On Sun, Dec 15, 2024 at 07:08:23PM +0100, Matthieu Herrb wrote:
> Hi again.
>
> So mplayer is using the XShm extention to share memory with the X
> server. Unfortunatly, on OpenBSD the X server and the mplayer process
> don't run with the same uid, leading to the patches to set the shared
> memory segement permissions to 0777. (one can see them with `ipcs -m`
> while mplayer is running).
>
> A number of years ago the X.Org developpers provided a solution for
> this in XShm 1.2. Unfortunatly at this time they only implemented it
> in libxcb, considering that it would soon replace libX11 and libXext
> completely, and this has prevented many projects using XShm to upgrade
> their code.
>
> Here is a relarively crude patch to x11/mplayer to implement XShm 1.2
> support in vo_x11 and vo_xv backends. The configure bits in particular
> are not very nice and will probably require more work to be
> upstreamed.
>
> But at least there are no longer wide open shared memory segments
> containing the p0rn you're watching while running mplayer.
>
> ok, comments ?
>
> PS: this needs the p2 (add sdl-image bdep) patch I sent earlier to
> apply.
>

oops while doing the mpv patches I found a few issues left over. New
version below:

Index: Makefile
===================================================================
RCS file: /local/cvs/ports/x11/mplayer/Makefile,v
diff -u -p -u -r1.333 Makefile
--- Makefile 2 Dec 2024 06:14:53 -0000 1.333
+++ Makefile 15 Dec 2024 20:49:57 -0000
@@ -3,7 +3,7 @@ COMMENT= movie player supporting many fo
V= 20240803
FFMPEG_V= 6.1.2
DISTNAME= mplayer-${V}
-REVISION= 2
+REVISION= 3
CATEGORIES= x11 multimedia
SITES= https://comstyle.com/source/
EXTRACT_SUFX= .tar.xz
@@ -17,12 +17,12 @@ MAINTAINER= Brad Smith <brad@comstyle.co
# GPLv2
PERMIT_PACKAGE= Yes

-WANTLIB= EGL GL SDL X11 Xext Xinerama Xss Xv Xxf86dga Xxf86vm ass \
+WANTLIB= EGL GL SDL X11 X11-xcb Xext Xinerama Xss Xv Xxf86dga Xxf86vm ass \
avcodec avformat avutil bluray bs2b bz2 c cdda_interface \
cdda_paranoia crypto dv dvdnav dvdread enca fontconfig \
freetype fribidi gif iconv jpeg m mng mp3lame curses png \
postproc pthread sndio ssl swscale swresample util x264 \
- xvidcore z
+ xcb xcb-shm xvidcore z

COMPILER= base-clang ports-gcc
COMPILER_LANGS= c
Index: patches/patch-configure
===================================================================
RCS file: /local/cvs/ports/x11/mplayer/patches/patch-configure,v
diff -u -p -u -r1.97 patch-configure
--- patches/patch-configure 24 Nov 2024 08:50:45 -0000 1.97
+++ patches/patch-configure 15 Dec 2024 20:49:57 -0000
@@ -1,3 +1,5 @@
+Add support for xcb-shm
+
Index: configure
--- configure.orig
+++ configure
@@ -15,7 +17,24 @@ Index: configure
# Use this before starting a check
echocheck() {
echo "============ Checking for $@ ============" >> "$TMPLOG"
-@@ -1521,39 +1528,39 @@ echo configuration: $configuration > "$TMPLOG"
+@@ -694,6 +701,7 @@ _mplayer=yes
+ _x11=auto
+ _xshape=auto
+ _xss=auto
++_xcb_shm=auto
+ _dga1=auto
+ _dga2=auto
+ _xv=auto
+@@ -1042,6 +1050,8 @@ for ac_option do
+ --disable-xshape) _xshape=no ;;
+ --enable-xss) _xss=yes ;;
+ --disable-xss) _xss=no ;;
++ --enable-xcb_shm) _xcb_shm=yes ;;
++ --disable-xcb-shm) _xcb_shm=no ;;
+ --enable-xv) _xv=yes ;;
+ --disable-xv) _xv=no ;;
+ --enable-vda) _vda=yes ;;
+@@ -1521,39 +1531,39 @@ echo configuration: $configuration > "$TMPLOG"
echo >> "$TMPLOG"


@@ -87,7 +106,7 @@ Index: configure
list_subparts() {
test ! -e ffmpeg/libav${3} && return 1
pattern="s/^[^#]*${1}.*([^ ,]*, *\([^ ,)]*\).*/\1_${2}/p"
-@@ -1990,7 +1997,10 @@ fi
+@@ -1990,7 +2000,10 @@ fi
if arm ; then
cc_check && host_arch=aarch64 || host_arch=arm
fi
@@ -98,7 +117,7 @@ Index: configure

echo "Detected operating system: $system_name"
echo "Detected host architecture: $host_arch"
-@@ -2544,7 +2554,7 @@ case "$host_arch" in
+@@ -2544,7 +2557,7 @@ case "$host_arch" in
arch='sparc'
iproc='sparc'
if test "$host_arch" = "sparc64" ; then
@@ -107,7 +126,7 @@ Index: configure
proc='ultrasparc'
def_fast_64bit='#define HAVE_FAST_64BIT 1'
elif sunos ; then
-@@ -2846,7 +2856,14 @@ EOF
+@@ -2846,7 +2859,14 @@ EOF
arch='arc'
iproc='arc'
;;
@@ -122,7 +141,7 @@ Index: configure
*)
echo "The architecture of your CPU ($host_arch) is not supported by this configure script"
echo "It seems nobody has ported MPlayer to your OS or CPU type yet."
-@@ -2920,7 +2937,7 @@ cat > $TMPC << EOF
+@@ -2920,7 +2940,7 @@ cat > $TMPC << EOF
int ff_extern;
EOF
cc_check -c || die "Symbol mangling check failed."
@@ -131,7 +150,7 @@ Index: configure
extern_prefix=${sym%%ff_extern*}
def_extern_asm="#define EXTERN_ASM $extern_prefix"
def_extern_prefix="#define EXTERN_PREFIX \"$extern_prefix\""
-@@ -2985,7 +3002,7 @@ else
+@@ -2985,7 +3005,7 @@ else
fi

CFLAGS="-D_ISOC99_SOURCE -I. -Iffmpeg $CFLAGS"
@@ -140,7 +159,7 @@ Index: configure

# On glibc, add some more CPPFLAGS for enabling required functionality.
cpp_condition_check features.h "defined __GLIBC__" &&
-@@ -3066,7 +3083,7 @@ elif test $relocatable = "yes" ; then
+@@ -3066,7 +3086,7 @@ elif test $relocatable = "yes" ; then
fi
echores $relocatable

@@ -149,7 +168,27 @@ Index: configure
# Checking assembler (_as) compatibility...
# Added workaround for older as that reads from stdin by default - atmos
as_version=$(echo '' | $_as -version 2>&1 | sed -n 's/^.*assembler \(version \)*\([0-9.]*\).*$/\2/p')
-@@ -6338,12 +6355,16 @@ fi #if irix
+@@ -4982,6 +5002,19 @@ else
+ fi
+ echores "$_x11"
+
++echocheck "xcb shm extension"
++if test "$_xcb_shm" = auto ; then
++ _xcb_shm=no
++ statement_check "xcb/shm.h" 'xcb_shm_query_version(NULL)' -lX11-xcb -lxcb-shm -lxcb && _xcb_shm=yes
++fi
++if test "$_xcb_shm" = yes ; then
++ def_xcb_shm='#define CONFIG_XCB_SHM 1'
++ libs_mplayer="$libs_mplayer -lX11-xcb -lxcb-shm -lxcb"
++else
++ def_xcb_shm='#undef CONFIG_XCB_SHM'
++fi
++echores "$_xcb_shm"
++
+ echocheck "Xss screensaver extensions"
+ if test "$_xss" = auto ; then
+ _xss=no
+@@ -6338,12 +6371,16 @@ fi #if irix
echocheck "sndio audio"
if test "$_sndio" = auto ; then
_sndio=no
@@ -168,7 +207,7 @@ Index: configure
else
def_sndio='#undef CONFIG_SNDIO_AUDIO'
noaomodules="sndio $noaomodules"
-@@ -6526,7 +6547,7 @@ echocheck "cdparanoia"
+@@ -6526,7 +6563,7 @@ echocheck "cdparanoia"
if test "$_cdparanoia" = auto ; then
_cdparanoia=no
for inc_tmp in "" "-I/usr/include/cdda" "-I/usr/local/include/cdda" ; do
@@ -177,7 +216,7 @@ Index: configure
_cdparanoia=yes && extra_cflags="$extra_cflags $inc_tmp" && break
done
fi
-@@ -8417,6 +8438,7 @@ extra_ldflags="$extra_ldflags $libm"
+@@ -8417,6 +8454,7 @@ extra_ldflags="$extra_ldflags $libm"
# XML documentation tests
echocheck "XML catalogs"
for try_catalog in \
@@ -185,7 +224,7 @@ Index: configure
/etc/sgml/catalog \
/usr/share/xml/docbook/*/catalog.xml \
/opt/local/share/xml/docbook-xml/*/catalog.xml \
-@@ -8444,6 +8466,7 @@ fi
+@@ -8444,6 +8482,7 @@ fi

echocheck "XML chunked stylesheet"
for try_chunk_xsl in \
@@ -193,7 +232,7 @@ Index: configure
/usr/share/xml/docbook/*/html/chunk.xsl \
/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl \
/usr/share/sgml/docbook/yelp/docbook/html/chunk.xsl \
-@@ -8469,6 +8492,7 @@ fi
+@@ -8469,6 +8508,7 @@ fi

echocheck "XML monolithic stylesheet"
for try_docbook_xsl in \
@@ -201,7 +240,7 @@ Index: configure
/usr/share/xml/docbook/*/html/docbook.xsl \
/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl \
/usr/share/sgml/docbook/yelp/docbook/html/docbook.xsl \
-@@ -8522,6 +8546,7 @@ EOF
+@@ -8522,6 +8562,7 @@ EOF
echocheck "XML DTD"
#FIXME: This should prefer higher version numbers, not the other way around ..
for try_dtd in \
@@ -209,7 +248,15 @@ Index: configure
/usr/share/xml/docbook/*/dtd/4*/docbookx.dtd \
/usr/share/xml/docbook/*/docbookx.dtd \
/usr/share/sgml/docbook/*/docbookx.dtd \
-@@ -9732,9 +9757,6 @@ cmp -s "$TMPH" config.h || mv -f "$TMPH" config.h
+@@ -9433,6 +9474,7 @@ $def_xf86keysym
+ $def_xinerama
+ $def_xmga
+ $def_xss
++$def_xcb_shm
+ $def_xv
+ $def_xvr100
+ $def_yuv4mpeg
+@@ -9732,9 +9774,6 @@ cmp -s "$TMPH" config.h || mv -f "$TMPH" config.h

############################################################################

@@ -219,7 +266,7 @@ Index: configure
# Create avconfig.h for FFmpeg.
cat > "$TMPH" << EOF
/* Generated by mpconfigure */
-@@ -9827,8 +9849,6 @@ print_enabled_components libavformat/demuxer_list.c AV
+@@ -9827,8 +9866,6 @@ print_enabled_components libavformat/demuxer_list.c AV
print_enabled_components libavformat/muxer_list.c AVOutputFormat muxer_list $libavmuxers
print_enabled_components libavformat/protocol_list.c URLProtocol url_protocols $libavprotocols
print_enabled_filters libavfilter/filter_list.c AVFilter filter_list $libavfilters
Index: patches/patch-libvo_vo_x11_c
===================================================================
RCS file: /local/cvs/ports/x11/mplayer/patches/patch-libvo_vo_x11_c,v
diff -u -p -u -r1.1 patch-libvo_vo_x11_c
--- patches/patch-libvo_vo_x11_c 2 Dec 2024 06:14:53 -0000 1.1
+++ patches/patch-libvo_vo_x11_c 15 Dec 2024 20:49:57 -0000
@@ -1,15 +1,117 @@
-Revert "Use appropriate shared memory permissions."
-r38419
+Implement XShm 1.2

Index: libvo/vo_x11.c
--- libvo/vo_x11.c.orig
+++ libvo/vo_x11.c
-@@ -150,7 +150,7 @@ static void getMyXImage(void)
+@@ -38,7 +38,11 @@
+ #ifdef HAVE_SHM
+ #include <sys/ipc.h>
+ #include <sys/shm.h>
++#include <sys/mman.h>
+ #include <X11/extensions/XShm.h>
++#include <X11/Xlib-xcb.h>
++#include <xcb/shm.h>
++#include <unistd.h>
+
+ static int Shmem_Flag;
+
+@@ -78,7 +82,9 @@ static unsigned char *ImageDataOrig;
+ static XImage *myximage = NULL;
+ static int depth, bpp;
+ static XWindowAttributes attribs;
+-
++#ifdef HAVE_SHM
++static char myshmname[128];
++

No comments:

Post a Comment