changeset 16721:bd815e9973f2

use subopt parser for arguments. change all printf to mp_msg. update man page gif89a example.
author joey
date Mon, 10 Oct 2005 12:59:36 +0000
parents f73adf296f1e
children 89f77f666120
files DOCS/man/en/mplayer.1 libvo/vo_gif89a.c
diffstat 2 files changed, 45 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Mon Oct 10 12:56:44 2005 +0000
+++ b/DOCS/man/en/mplayer.1	Mon Oct 10 12:59:36 2005 +0000
@@ -3165,7 +3165,7 @@
 .RE
 .PD 0
 .RSs
-mplayer video.nut \-vo gif89a:15.0:test.gif
+mplayer video.nut \-vo gif89a:fps=15.0:filename=test.gif
 .RE
 .PD 1
 .
--- a/libvo/vo_gif89a.c	Mon Oct 10 12:56:44 2005 +0000
+++ b/libvo/vo_gif89a.c	Mon Oct 10 12:59:36 2005 +0000
@@ -53,8 +53,10 @@
 #include <unistd.h>
 
 #include "config.h"
+#include "subopt-helper.h"
 #include "video_out.h"
 #include "video_out_internal.h"
+#include "mp_msg.h"
 
 #define MPLAYER_VERSION 0.90
 #define VO_GIF_REVISION 6
@@ -105,44 +107,37 @@
 // the default output filename
 #define DEFAULT_FILE "out.gif"
 
+static opt_t subopts[] = {
+  {"output",       OPT_ARG_MSTRZ, &gif_filename, NULL, 0},
+  {"fps",          OPT_ARG_FLOAT, &target_fps,   NULL, 0},
+  {NULL, 0, NULL, NULL, 0}
+};
+
 static int preinit(const char *arg)
 {
-	float fps;
-	if (verbose) printf("GIF89a: Preinit entered\n");
-		
 	target_fps = 0;
-	fps = 0;
-	
-	if (arg) {
-		char *temp = NULL;
-		if (sscanf(arg, "%f", &fps)) {
-			if (fps < 0) fps = 0;
-			// find the next argument
-			temp = strchr(arg, ':');
-			if (temp != NULL) temp++;
-		} else {
-			// find the first argument
-			temp = (char *)arg;
-		}
 
-		if (temp != NULL) {
-			if (*temp != '\0') {
-				gif_filename = strdup(temp);
-			}
-		}
+	if (subopt_parse(arg, subopts) != 0) {
+		mp_msg(MSGT_VO, MSGL_FATAL,
+			"\n-vo gif89a command line help:\n"
+			"Example: mplayer -vo gif89a:output=file.gif:fps=4.9\n"
+			"\nOptions:\n"
+			"  output=<filename>\n"
+			"    Specify the output file.  The default is out.gif.\n"
+			"  fps=<rate>\n"
+			"    Specify the target framerate.  The default is 5.0.\n"
+			"\n");
+		return -1;
 	}
 
-	if (fps > vo_fps)
-		fps = vo_fps; // i will not duplicate frames.
-	
-	if (fps <= 0) {
+	if (target_fps > vo_fps)
+		target_fps = vo_fps; // i will not duplicate frames.
+
+	if (target_fps <= 0) {
 		target_fps = default_fps;
-		if (verbose)
-			printf("GIF89a: default, %.2f fps\n", target_fps);
+		mp_msg(MSGT_VO, MSGL_V, "GIF89a: default, %.2f fps\n", target_fps);
 	} else {
-		target_fps = fps;
-		if (verbose)
-			printf("GIF89a: output fps forced to %.2f\n", target_fps);
+		mp_msg(MSGT_VO, MSGL_V, "GIF89a: output fps forced to %.2f\n", target_fps);
 	}
 	
 	ideal_delay = 100 / target_fps; // in centiseconds
@@ -151,15 +146,12 @@
 	
 	if (gif_filename == NULL) {
 		gif_filename = strdup(DEFAULT_FILE);
-		if (verbose)
-			printf("GIF89a: default, file \"%s\"\n", gif_filename);
+		mp_msg(MSGT_VO, MSGL_V, "GIF89a: default, file \"%s\"\n", gif_filename);
 	} else {
-		if (verbose)
-			printf("GIF89a: file forced to \"%s\"\n", gif_filename);
+		mp_msg(MSGT_VO, MSGL_V, "GIF89a: file forced to \"%s\"\n", gif_filename);
 	}
 	
-	if (verbose)
-		printf("GIF89a: Preinit OK\n");
+	mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: Preinit OK\n");
 	return 0;
 }
 
@@ -173,10 +165,8 @@
 	char LB2[] = { 1, 0, 0 };
 #endif
 
-	if (verbose) {
-		printf("GIF89a: Config entered [%ix%i]\n",s_width,s_height);
-		printf("GIF89a: With requested format: %s\n",vo_format_name(format));
-	}
+	mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: Config entered [%ldx%ld]\n", s_width,s_height);
+	mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: With requested format: %s\n", vo_format_name(format));
 	
 	// save these for later.
 	img_width = s_width;
@@ -185,8 +175,7 @@
 	// multiple configs without uninit are not allowed.
 	// this is because config opens a new gif file.
 	if (vo_config_count > 0) {
-		if (verbose)
-			printf("GIF89a: Reconfigure attempted.\n");
+		mp_msg(MSGT_VO, MSGL_V, "GIF89a: Reconfigure attempted.\n");
 		return 0;
 	}
 	// reconfigure need not be a fatal error, so return 0.
@@ -195,7 +184,7 @@
 	// gif will have the dimensions of the first movie.
 	
 	if (format != IMGFMT_RGB24) {
-		printf("GIF89a: Error - given unsupported colorspace.\n");
+		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Error - given unsupported colorspace.\n");
 		return 1;
 	}
 	
@@ -206,31 +195,34 @@
 #ifdef HAVE_GIF_4
 	EGifSetGifVersion("89a");
 #else
-	printf("GIF89a: Your version of libungif needs to be upgraded.\n");
-	printf("GIF89a: Some functionality has been disabled.\n");
+	mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Your version of libungif needs to be upgraded.\n");
+	mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Some functionality has been disabled.\n");
 #endif
 	
 	new_gif = EGifOpenFileName(gif_filename, 0);
 	if (new_gif == NULL) {
-		printf("GIF89a: error opening file \"%s\" for output.\n", gif_filename);
+		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: error opening file \"%s\" for output.\n", gif_filename);
 		return 1;
 	}
 
 	slice_data = malloc(img_width * img_height * 3);
 	if (slice_data == NULL) {
-		printf("GIF89a: malloc failed.\n");
+		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: malloc failed.\n");
 		return 1;
 	}
 
 	reduce_data = malloc(img_width * img_height);
 	if (reduce_data == NULL) {
-		printf("GIF89a: malloc failed.\n");
+		free(slice_data); slice_data = NULL;
+		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: malloc failed.\n");
 		return 1;
 	}
 
 	reduce_cmap = MakeMapObject(256, NULL);
 	if (reduce_cmap == NULL) {
-		printf("GIF89a: malloc failed.\n");
+		free(slice_data); slice_data = NULL;
+		free(reduce_data); reduce_data = NULL;
+		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: malloc failed.\n");
 		return 1;
 	}
 	
@@ -250,8 +242,7 @@
 	EGifPutExtensionLast(new_gif, 0, 3, LB2);
 #endif
 
-	if (verbose)
-		printf("GIF89a: Config finished.\n");
+	mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: Config finished.\n");
 	return 0;
 }
 
@@ -295,7 +286,7 @@
 	// quantize the image
 	ret = gif_reduce(img_width, img_height, slice_data, reduce_data, reduce_cmap->Colors);
 	if (ret == GIF_ERROR) {
-		printf("GIF89a: Quantize failed.\n");
+		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Quantize failed.\n");
 		return;
 	}
 
@@ -361,8 +352,7 @@
 
 static void uninit(void)
 {
-	if (verbose)
-		printf("GIF89a: Uninit entered\n");
+	mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: Uninit entered\n");
 	
 	if (new_gif != NULL) {
 		char temp[256];