Web lists-archives.com

[MPlayer-dev-eng] [PATCH] vo and ao "exit" devices




Someone mentioned that they wanted mplayer to exit if it failed to open their
audio device, rather than continuing with no audio.  These (trivial but
harmless) output devices allow this to happen by putting them at the end of
the output chain (e.g., "-ao alsa,pulse,exit").  Apparently someone else
suggested this approach as well, a while ago.  I will readily admit that this
is silly, but it works.  I have no particular attachment to name, description,
or approach.
Index: DOCS/man/en/mplayer.1
===================================================================
--- DOCS/man/en/mplayer.1	(revision 37389)
+++ DOCS/man/en/mplayer.1	(working copy)
@@ -3285,6 +3285,11 @@
 Use \-nosound for benchmarking.
 .
 .TP
+.B "exit\ \ \ "
+Exits immediately upon use.
+Useful for placing as the last output device if you want mplayer to fail when no (other) output devices are available.
+.
+.TP
 .B "pcm\ \ \ \ "
 raw PCM/wave file writer audio output
 .PD 0
@@ -4509,6 +4514,11 @@
 Useful for benchmarking.
 .
 .TP
+.B "exit\ \ \ "
+Exits immediately upon use.
+Useful for placing as the last video device if you want mplayer to fail when no (other) output devices are available.
+.
+.TP
 .B "aa\ \ \ \ \ "
 ASCII art video output driver that works on a text console.
 .br
Index: Makefile
===================================================================
--- Makefile	(revision 37389)
+++ Makefile	(working copy)
@@ -608,6 +608,7 @@
                libao2/ao_mpegpes.c      \
                libao2/ao_null.c         \
                libao2/ao_pcm.c          \
+               libao2/ao_exit.c         \
                libao2/audio_out.c       \
                libvo/aspect.c           \
                libvo/geometry.c         \
@@ -614,6 +615,7 @@
                libvo/video_out.c        \
                libvo/vo_mpegpes.c       \
                libvo/vo_null.c          \
+               libvo/vo_exit.c          \
                sub/spuenc.c             \
                $(SRCS_MPLAYER-yes)
 
Index: help/help_mp-en.h
===================================================================
--- help/help_mp-en.h	(revision 37389)
+++ help/help_mp-en.h	(working copy)
@@ -892,6 +892,9 @@
 #define MSGTR_VO_SUB_Hue "Hue"
 #define MSGTR_VO_SUB_Balance "Balance"
 
+// ao_exit.c
+#define MSGTR_VO_EXIT "[VO EXIT] Failed to open any video driver, exiting\n"
+
 // vo_3dfx.c
 #define MSGTR_LIBVO_3DFX_Only16BppSupported "[VO_3DFX] Only 16bpp supported!"
 #define MSGTR_LIBVO_3DFX_VisualIdIs "[VO_3DFX] Visual ID is  %lx.\n"
@@ -1179,6 +1182,9 @@
 #define MSGTR_AO_NoSuchDriver "No such audio driver '%.*s'\n"
 #define MSGTR_AO_FailedInit "Failed to initialize audio driver '%s'\n"
 
+// ao_exit.c
+#define MSGTR_AO_EXIT "[AO EXIT] Failed to open any audio driver, exiting\n"
+
 // ao_oss.c
 #define MSGTR_AO_OSS_CantOpenMixer "[AO OSS] audio_setup: Can't open mixer device %s: %s\n"
 #define MSGTR_AO_OSS_ChanNotFound "[AO OSS] audio_setup: Audio card mixer does not have channel '%s', using default.\n"
Index: libao2/ao_exit.c
===================================================================
--- libao2/ao_exit.c	(revision 0)
+++ libao2/ao_exit.c	(working copy)
@@ -0,0 +1,39 @@
+/*
+ * exit audio output driver
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "mp_core.h"
+#include "help_mp.h"
+#include "audio_out.h"
+
+static const ao_info_t info =
+{
+	"Exiting audio output",
+	"exit",
+	"Dylan Simon <dylan-mplayer@xxxxxxxxx>",
+	"Exits immediately, for use as a final, failing output"
+};
+
+static int init(int rate,int channels,int format,int flags)
+{
+	mp_msg(MSGT_AO, MSGL_FATAL, MSGTR_AO_EXIT);
+	exit_player(EXIT_ERROR);
+}
+
+const ao_functions_t audio_out_exit = { &info, NULL, init };
Index: libao2/audio_out.c
===================================================================
--- libao2/audio_out.c	(revision 37389)
+++ libao2/audio_out.c	(working copy)
@@ -55,6 +55,7 @@
 extern const ao_functions_t audio_out_mpegpes;
 extern const ao_functions_t audio_out_pcm;
 extern const ao_functions_t audio_out_pss;
+extern const ao_functions_t audio_out_exit;
 
 const ao_functions_t* const audio_out_drivers[] =
 {
@@ -124,6 +125,7 @@
         &audio_out_null,
 // should not be auto-selected:
         &audio_out_pcm,
+        &audio_out_exit,
         NULL
 };
 
Index: libvo/video_out.c
===================================================================
--- libvo/video_out.c	(revision 37389)
+++ libvo/video_out.c	(working copy)
@@ -143,6 +143,7 @@
 extern const vo_functions_t video_out_pnm;
 extern const vo_functions_t video_out_md5sum;
 extern const vo_functions_t video_out_mng;
+extern const vo_functions_t video_out_exit;
 
 /* The following declarations are _not_ const because functions pointers
  * get overloaded during (re)initialization. */
@@ -304,6 +305,7 @@
 #ifdef CONFIG_MNG
         &video_out_mng,
 #endif
+        &video_out_exit,
         NULL
 };
 
Index: libvo/vo_exit.c
===================================================================
--- libvo/vo_exit.c	(revision 0)
+++ libvo/vo_exit.c	(working copy)
@@ -0,0 +1,39 @@
+/*
+ * exit video output driver
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "mp_core.h"
+#include "help_mp.h"
+#include "video_out.h"
+
+static const vo_info_t info =
+{
+	"Exiting video output",
+	"exit",
+	"Dylan Simon <dylan-mplayer@xxxxxxxxx>",
+	"Exits immediately, for use as a final, failing output"
+};
+
+static int preinit(const char *arg)
+{
+	mp_msg(MSGT_VO, MSGL_FATAL, MSGTR_VO_EXIT);
+	exit_player(EXIT_ERROR);
+}
+
+const vo_functions_t video_out_exit = { &info, preinit };
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng